Skip to content

Commit de864c6

Browse files
TofMassilia13320Grom-
authored andcommitted
[api/core/services] Add device (STSAFE-A/L) & protocol (I2C/ST1WIRE) preprocessor check
1 parent 2c30afb commit de864c6

12 files changed

Lines changed: 239 additions & 188 deletions

api/stse_data_storage.c

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,12 @@
2323
stse_ReturnCode_t stse_data_storage_get_total_partition_count(
2424
stse_Handler_t *pSTSE,
2525
PLAT_UI8 *total_partition_count) {
26+
#ifdef STSE_CONF_STSAFE_L_SUPPORT
2627
/* - Check device type */
2728
if (pSTSE->device_type == STSAFE_L010) {
2829
return (STSE_API_INCOMPATIBLE_DEVICE_TYPE);
2930
}
31+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
3032

3133
return stsafea_get_total_partition_count(pSTSE, total_partition_count);
3234
}
@@ -36,10 +38,12 @@ stse_ReturnCode_t stse_data_storage_get_partitioning_table(
3638
PLAT_UI8 total_partition_count,
3739
stsafea_data_partition_record_t *pPartitioning_table,
3840
PLAT_UI16 Partitioning_table_length) {
41+
#ifdef STSE_CONF_STSAFE_L_SUPPORT
3942
/* - Check device type */
4043
if (pSTSE->device_type == STSAFE_L010) {
4144
return (STSE_API_INCOMPATIBLE_DEVICE_TYPE);
4245
}
46+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
4347

4448
return stsafea_get_data_partitions_configuration(
4549
pSTSE,
@@ -94,7 +98,7 @@ stse_ReturnCode_t stse_data_storage_read_data_zone(
9498
chunck_length,
9599
protection);
96100
break;
97-
#endif
101+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
98102
#ifdef STSE_CONF_STSAFE_A_SUPPORT
99103
case STSAFE_A100:
100104
case STSAFE_A110:
@@ -109,14 +113,14 @@ stse_ReturnCode_t stse_data_storage_read_data_zone(
109113
chunck_length,
110114
protection);
111115
break;
112-
#endif
116+
#endif /* STSE_CONF_STSAFE_A_SUPPORT */
113117
default:
114118
return STSE_API_INCOMPATIBLE_DEVICE_TYPE;
115119
}
116120
/* - Check if Transfer successful and format response data */
117121
if (ret != STSE_OK) {
118122
/* - (ERROR) Return communication error code */
119-
return (ret);
123+
return ret;
120124
}
121125

122126
/* - Decrement Length value */
@@ -126,7 +130,7 @@ stse_ReturnCode_t stse_data_storage_read_data_zone(
126130
} while (remaning_length > 0);
127131

128132
/* - Return STSE Status code */
129-
return (ret);
133+
return ret;
130134
}
131135

132136
stse_ReturnCode_t stse_data_storage_update_data_zone(
@@ -164,7 +168,7 @@ stse_ReturnCode_t stse_data_storage_update_data_zone(
164168
length,
165169
protection);
166170
break;
167-
#endif
171+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
168172
#ifdef STSE_CONF_STSAFE_A_SUPPORT
169173
case STSAFE_A100:
170174
case STSAFE_A110:
@@ -179,13 +183,13 @@ stse_ReturnCode_t stse_data_storage_update_data_zone(
179183
length,
180184
protection);
181185
break;
182-
#endif
186+
#endif /* STSE_CONF_STSAFE_A_SUPPORT */
183187
default:
184188
ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE;
185189
}
186190

187191
/* - Return STSE Status code */
188-
return (ret);
192+
return ret;
189193
}
190194

191195
stse_ReturnCode_t stse_data_storage_decrement_counter_zone(
@@ -225,7 +229,7 @@ stse_ReturnCode_t stse_data_storage_decrement_counter_zone(
225229
new_counter_value,
226230
protection);
227231
break;
228-
#endif
232+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
229233
#ifdef STSE_CONF_STSAFE_A_SUPPORT
230234
case STSAFE_A100:
231235
case STSAFE_A110:
@@ -242,13 +246,13 @@ stse_ReturnCode_t stse_data_storage_decrement_counter_zone(
242246
new_counter_value,
243247
protection);
244248
break;
245-
#endif
249+
#endif /* STSE_CONF_STSAFE_A_SUPPORT */
246250
default:
247251
ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE;
248252
}
249253

250254
/* - Return STSAFE Status code */
251-
return (ret);
255+
return ret;
252256
}
253257

254258
stse_ReturnCode_t stse_data_storage_read_counter_zone(
@@ -298,7 +302,7 @@ stse_ReturnCode_t stse_data_storage_read_counter_zone(
298302
pCounter_value,
299303
protection);
300304
break;
301-
#endif
305+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
302306
#ifdef STSE_CONF_STSAFE_A_SUPPORT
303307
case STSAFE_A100:
304308
case STSAFE_A110:
@@ -314,7 +318,7 @@ stse_ReturnCode_t stse_data_storage_read_counter_zone(
314318
pCounter_value,
315319
protection);
316320
break;
317-
#endif
321+
#endif /* STSE_CONF_STSAFE_A_SUPPORT */
318322
default:
319323
ret = STSE_API_INCOMPATIBLE_DEVICE_TYPE;
320324
}
@@ -324,7 +328,7 @@ stse_ReturnCode_t stse_data_storage_read_counter_zone(
324328
} while ((remaning_length > 0) && (ret == STSE_OK));
325329

326330
/* - Return STSAFE Status code */
327-
return (ret);
331+
return ret;
328332
}
329333

330334
stse_ReturnCode_t stse_data_storage_change_read_access_condition(
@@ -353,7 +357,7 @@ stse_ReturnCode_t stse_data_storage_change_read_access_condition(
353357
protection);
354358

355359
/* - Return STSE Status code */
356-
return (ret);
360+
return ret;
357361
}
358362

359363
stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handler_t *pSTSE,
@@ -386,7 +390,7 @@ stse_ReturnCode_t stse_data_storage_change_update_access_condition(stse_Handler_
386390
protection);
387391

388392
/* - Return STSE Status code */
389-
return (ret);
393+
return ret;
390394
}
391395

392396
stse_ReturnCode_t stse_data_storage_change_decrement_access_condition(stse_Handler_t *pSTSE,

api/stse_device_authentication.c

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*!
22
******************************************************************************
3-
* \file stse_device_authentication.c
3+
* \file stse_device_authentication.c
44
* \brief STSE uthentication API (sources)
55
* \author STMicroelectronics - CS application team
66
*
@@ -77,7 +77,7 @@ stse_ReturnCode_t stse_get_device_certificate_size(stse_Handler_t *pSTSE, PLAT_U
7777
STSE_NO_PROT); /* No protection */
7878

7979
if (ret != STSE_OK) {
80-
return (ret);
80+
return ret;
8181
}
8282

8383
*pCertificate_size = (((uint16_t)certificate_size_ui8[0]) << 8) + ((uint16_t)certificate_size_ui8[1]) + 4U;
@@ -107,7 +107,7 @@ stse_ReturnCode_t stse_get_device_certificate(stse_Handler_t *pSTSE, PLAT_UI8 ce
107107
STSE_NO_PROT); /* No protection */
108108

109109
if (ret != STSE_OK) {
110-
return (ret);
110+
return ret;
111111
}
112112

113113
return (STSE_OK);
@@ -160,7 +160,7 @@ stse_ReturnCode_t stse_device_authenticate(
160160
certificate_size,
161161
&leaf_certificate);
162162
if (ret != STSE_OK) {
163-
return (ret);
163+
return ret;
164164
}
165165

166166
/* - Get ECC key type from leaf certificate */
@@ -173,16 +173,20 @@ stse_ReturnCode_t stse_device_authenticate(
173173
PLAT_UI8 signature[signature_size];
174174

175175
PLAT_UI16 challenge_size;
176+
#ifdef STSE_CONF_STSAFE_L_SUPPORT
176177
if (pSTSE->device_type == STSAFE_L010) {
177178
challenge_size = STSAFEL_ECC_SIGNATURE_CHALLENGE_LENGTH;
178179
} else {
180+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
179181
challenge_size = stse_ecc_info_table[key_type].private_key_size;
180182
#ifdef STSE_CONF_ECC_NIST_P_521
181183
if (key_type == STSE_ECC_KT_NIST_P_521) {
182184
challenge_size -= 2;
183185
}
184-
#endif
186+
#endif /* STSE_CONF_ECC_NIST_P_521 */
187+
#ifdef STSE_CONF_STSAFE_L_SUPPORT
185188
}
189+
#endif /* STSE_CONF_STSAFE_L_SUPPORT */
186190
PLAT_UI8 challenge[challenge_size];
187191

188192
/* - Generate random challenge */
@@ -194,12 +198,12 @@ stse_ReturnCode_t stse_device_authenticate(
194198
ret = stse_ecc_generate_signature(
195199
pSTSE, /* STSE handler */
196200
priv_key_slot_number, /* Slot number */
197-
key_type,
198-
challenge, /* Random number to sign */
199-
challenge_size, /* random number size in bytes */
200-
signature); /* returned signature */
201+
key_type, /* Key type */
202+
challenge, /* Random number to sign */
203+
challenge_size, /* random number size in bytes */
204+
signature); /* returned signature */
201205
if (ret != STSE_OK) {
202-
return (ret);
206+
return ret;
203207
}
204208

205209
/* - Verify SE Challenge over leaf certificate public key*/

0 commit comments

Comments
 (0)