Skip to content

Commit cb7bbd2

Browse files
TofMassilia13320Grom-
authored andcommitted
[services/stsafea] Fix stsafea_sign_for_generic_public_key_slot
1 parent 5ec7172 commit cb7bbd2

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

services/stsafea/stsafea_asymmetric_key_slots.c

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -298,19 +298,22 @@ stse_ReturnCode_t stsafea_sign_for_generic_public_key_slot(
298298
defined(STSE_CONF_USE_SYMMETRIC_KEY_PROVISIONING_WRAPPED_AUTHENTICATED)
299299

300300
stse_ReturnCode_t ret;
301-
PLAT_UI8 tbs_data[payload_length];
302301
PLAT_UI32 hash_length = stsafea_hash_info_table[hash_algo].length;
302+
PLAT_UI8 hash_data[hash_length];
303+
304+
if (pPrivate_key == NULL || pPayload == NULL || pSignature == NULL ||
305+
private_key_type == STSE_ECC_KT_INVALID || hash_algo == STSE_SHA_INVALID) {
306+
return STSE_SERVICE_INVALID_PARAMETER;
307+
}
303308

304309
#ifdef STSE_CONF_ECC_EDWARD_25519
305-
if (private_key_type == STSE_ECC_KT_ED25519) {
306-
memcpy(tbs_data, pPayload, payload_length);
307-
} else {
310+
if (private_key_type != STSE_ECC_KT_ED25519) {
308311
#endif /* STSE_CONF_ECC_EDWARD_25519 */
309312
/* - Hash the payload */
310313
ret = stse_platform_hash_compute(
311314
hash_algo,
312315
pPayload, payload_length,
313-
tbs_data, &hash_length);
316+
hash_data, &hash_length);
314317

315318
if (ret != STSE_OK) {
316319
return (ret);
@@ -320,16 +323,21 @@ stse_ReturnCode_t stsafea_sign_for_generic_public_key_slot(
320323
#endif /* STSE_CONF_ECC_EDWARD_25519 */
321324

322325
/* - Sign the hash of concatenation of pub keys */
326+
#ifdef STSE_CONF_ECC_EDWARD_25519
323327
ret = stse_platform_ecc_sign(
324328
private_key_type,
325329
pPrivate_key,
326-
tbs_data,
327-
#ifdef STSE_CONF_ECC_EDWARD_25519
330+
(private_key_type == STSE_ECC_KT_ED25519) ? pPayload : hash_data,
328331
(private_key_type == STSE_ECC_KT_ED25519) ? payload_length : hash_length,
332+
pSignature);
329333
#else
334+
ret = stse_platform_ecc_sign(
335+
private_key_type,
336+
pPrivate_key,
337+
hash_data,
330338
hash_length,
331-
#endif
332339
pSignature);
340+
#endif /* STSE_CONF_ECC_EDWARD_25519 */
333341

334342
return (ret);
335343
#else

0 commit comments

Comments
 (0)