Skip to content

Commit 866b609

Browse files
committed
[stsafea][core] Update data partition accesses protection param
1 parent 926a019 commit 866b609

2 files changed

Lines changed: 86 additions & 9 deletions

File tree

core/stse_generic_typedef.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,11 @@ typedef enum {
155155
* \brief STSE Command Protection enumeration
156156
*/
157157
typedef enum stse_cmd_protection_t {
158-
STSE_NO_PROT = 0, /*!< No command / response payload protection */
158+
STSE_NO_PROT = 0, /*!< No command / response payload protection */
159+
STSE_HOST_C_MAC_R_MAC, /*!< Authenticated command and response using HOST MAC Key */
160+
STSE_HOST_C_WRAP, /*!< Encrypted and authenticated command using HOST MAC and cipher Keys*/
161+
STSE_HOST_R_WRAP, /*!< Encrypted and authenticated response using HOST MAC and cipher Keys*/
162+
STSE_HOST_C_WRAP_R_WRAP /*!< Encrypted and authenticated command and response using HOST MAC and cipher Keys*/
159163
} stse_cmd_protection_t;
160164

161165
/*!

services/stsafea/stsafea_data_partition.c

Lines changed: 81 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,26 @@
2727
#define STSAFEA_INC_DEC_AMOUT_SIZE 4U
2828
#define STSAFEA_ZONE_ACCESS_LENGTH_SIZE 2U
2929

30+
stse_ReturnCode_t stsafea_switch_data_partition_access_protection (stse_Handler_t *pSTSE, PLAT_UI8 command_code, stse_cmd_protection_t protection)
31+
{
32+
switch (protection)
33+
{
34+
35+
case STSE_HOST_C_MAC_R_MAC :
36+
stsafea_perso_info_set_cmd_AC(&pSTSE->perso_info, command_code, STSE_CMD_AC_HOST);
37+
case STSE_NO_PROT:
38+
break;
39+
40+
case STSE_HOST_C_WRAP:
41+
case STSE_HOST_R_WRAP:
42+
case STSE_HOST_C_WRAP_R_WRAP:
43+
default :
44+
return STSE_SERVICE_INVALID_PARAMETER;
45+
break;
46+
}
47+
return STSE_OK;
48+
}
49+
3050
stse_ReturnCode_t stsafea_get_total_partition_count(stse_Handler_t *pSTSE,
3151
PLAT_UI8 *pTotal_partition_count) {
3252
PLAT_UI8 cmd_header = STSAFEA_CMD_QUERY;
@@ -121,9 +141,8 @@ stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE,
121141
PLAT_UI8 data_length,
122142
PLAT_UI32 *pNew_counter_value,
123143
stse_cmd_protection_t protection) {
124-
(void)protection;
125-
volatile stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER;
126144

145+
volatile stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER;
127146
PLAT_UI8 cmd_header = STSAFEA_CMD_DECREMENT;
128147
PLAT_UI8 rsp_header;
129148

@@ -135,6 +154,15 @@ stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE,
135154
return STSE_SERVICE_INVALID_PARAMETER;
136155
}
137156

157+
#ifdef STSE_CONF_USE_HOST_SESSION
158+
stse_perso_info_t perso_info_backup = pSTSE->perso_info;
159+
ret = stsafea_switch_data_partition_access_protection(pSTSE,cmd_header,protection);
160+
if (ret != STSE_OK)
161+
{
162+
return ret;
163+
}
164+
#endif
165+
138166
/*- Create CMD frame and populate elements */
139167
stse_frame_allocate(CmdFrame);
140168
stse_frame_element_allocate_push(&CmdFrame, eCmdHeader, STSAFEA_HEADER_SIZE, &cmd_header);
@@ -169,6 +197,10 @@ stse_ReturnCode_t stsafea_decrement_counter_zone(stse_Handler_t *pSTSE,
169197
/*- Swap New Counter value byte order before sending*/
170198
stse_frame_element_swap_byte_order(&eNewCounterVal);
171199

200+
#ifdef STSE_CONF_USE_HOST_SESSION
201+
pSTSE->perso_info = perso_info_backup;
202+
#endif
203+
172204
return (ret);
173205
}
174206

@@ -180,9 +212,8 @@ stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE,
180212
PLAT_UI16 Associated_data_length,
181213
PLAT_UI32 *pCounter_value,
182214
stse_cmd_protection_t protection) {
183-
(void)protection;
184-
volatile stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER;
185215

216+
volatile stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER;
186217
PLAT_UI8 cmd_header = STSAFEA_CMD_READ;
187218
PLAT_UI8 rsp_header;
188219

@@ -194,6 +225,15 @@ stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE,
194225
return STSE_SERVICE_INVALID_PARAMETER;
195226
}
196227

228+
#ifdef STSE_CONF_USE_HOST_SESSION
229+
stse_perso_info_t perso_info_backup = pSTSE->perso_info;
230+
ret = stsafea_switch_data_partition_access_protection(pSTSE,cmd_header,protection);
231+
if (ret != STSE_OK)
232+
{
233+
return ret;
234+
}
235+
#endif
236+
197237
/*- Create CMD frame and populate elements */
198238
stse_frame_allocate(CmdFrame);
199239
stse_frame_element_allocate_push(&CmdFrame, eCmdHeader, STSAFEA_HEADER_SIZE, &cmd_header);
@@ -228,6 +268,10 @@ stse_ReturnCode_t stsafea_read_counter_zone(stse_Handler_t *pSTSE,
228268
stse_frame_element_swap_byte_order(&eOffset);
229269
stse_frame_element_swap_byte_order(&eLength);
230270

271+
#ifdef STSE_CONF_USE_HOST_SESSION
272+
pSTSE->perso_info = perso_info_backup;
273+
#endif
274+
231275
return (ret);
232276
}
233277

@@ -238,9 +282,7 @@ stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE,
238282
PLAT_UI8 *pReadBuffer,
239283
PLAT_UI16 read_length,
240284
stse_cmd_protection_t protection) {
241-
(void)protection;
242285
volatile stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER;
243-
244286
PLAT_UI8 cmd_header = STSAFEA_CMD_READ;
245287
PLAT_UI8 rsp_header;
246288

@@ -252,6 +294,15 @@ stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE,
252294
return STSE_SERVICE_INVALID_PARAMETER;
253295
}
254296

297+
#ifdef STSE_CONF_USE_HOST_SESSION
298+
stse_perso_info_t perso_info_backup = pSTSE->perso_info;
299+
ret = stsafea_switch_data_partition_access_protection(pSTSE,cmd_header,protection);
300+
if (ret != STSE_OK)
301+
{
302+
return ret;
303+
}
304+
#endif
305+
255306
/*- Create CMD frame and populate elements */
256307
stse_frame_allocate(CmdFrame);
257308
stse_frame_element_allocate_push(&CmdFrame, eCmdHeader, STSAFEA_HEADER_SIZE, &cmd_header);
@@ -282,6 +333,10 @@ stse_ReturnCode_t stsafea_read_data_zone(stse_Handler_t *pSTSE,
282333
stse_frame_element_swap_byte_order(&eOffset);
283334
stse_frame_element_swap_byte_order(&eLength);
284335

336+
#ifdef STSE_CONF_USE_HOST_SESSION
337+
pSTSE->perso_info = perso_info_backup;
338+
#endif
339+
285340
return (ret);
286341
}
287342

@@ -292,7 +347,9 @@ stse_ReturnCode_t stsafea_update_data_zone(stse_Handler_t *pSTSE,
292347
PLAT_UI8 *pData,
293348
PLAT_UI32 data_length,
294349
stse_cmd_protection_t protection) {
295-
PLAT_UI8 cmd_header = STSAFEA_CMD_UPDATE;
350+
351+
volatile stse_ReturnCode_t ret = STSE_SERVICE_INVALID_PARAMETER;
352+
PLAT_UI8 cmd_header = STSAFEA_CMD_UPDATE;
296353
PLAT_UI8 rsp_header;
297354

298355
/* - Check stsafe handler initialization */
@@ -304,6 +361,15 @@ stse_ReturnCode_t stsafea_update_data_zone(stse_Handler_t *pSTSE,
304361
return STSE_SERVICE_INVALID_PARAMETER;
305362
}
306363

364+
#ifdef STSE_CONF_USE_HOST_SESSION
365+
stse_perso_info_t perso_info_backup = pSTSE->perso_info;
366+
ret = stsafea_switch_data_partition_access_protection(pSTSE,cmd_header,protection);
367+
if (ret != STSE_OK)
368+
{
369+
return ret;
370+
}
371+
#endif
372+
307373
/*- Create CMD frame and populate elements */
308374
stse_frame_allocate(CmdFrame);
309375
stse_frame_element_allocate_push(&CmdFrame, eCmdHeader, STSAFEA_HEADER_SIZE, &cmd_header);
@@ -324,9 +390,16 @@ stse_ReturnCode_t stsafea_update_data_zone(stse_Handler_t *pSTSE,
324390
stse_frame_element_swap_byte_order(&eOffset);
325391

326392
/*- Perform Transfer*/
327-
return stsafea_frame_transfer(pSTSE,
393+
ret = stsafea_frame_transfer(pSTSE,
328394
&CmdFrame,
329395
&RspFrame);
396+
397+
#ifdef STSE_CONF_USE_HOST_SESSION
398+
pSTSE->perso_info = perso_info_backup;
399+
#endif
400+
401+
return ret ;
402+
330403
}
331404

332405
#endif /* STSE_CONF_STSAFE_A_SUPPORT */

0 commit comments

Comments
 (0)