Skip to content

Commit b48a9f2

Browse files
Update hal_dice_sign_hash
1 parent e46f0a7 commit b48a9f2

1 file changed

Lines changed: 43 additions & 22 deletions

File tree

hal/mcxn.c

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -655,28 +655,49 @@ int hal_dice_create_attest_key(void)
655655
int hal_dice_sign_hash(const uint8_t *hash, size_t hash_len,
656656
uint8_t *sig, size_t *sig_len)
657657
{
658-
/*
659-
* Sign pre-hashed TBS using ELS ECSIGN with the IAK slot.
660-
* Output MUST be 64-byte raw R||S (big-endian), NOT DER-encoded.
661-
* This matches WOLFBOOT_DICE_SIG_LEN and is used directly in COSE_Sign1.
662-
*
663-
* TODO: Implement using mcuxClEls_EccSign_Async:
664-
* static uint8_t sig_buf[64] __attribute__((aligned(4)));
665-
* mcuxClEls_EccSignOption_t opts = {0};
666-
* opts.bits.echashchl = 0; // pre-hashed input (not plain message)
667-
* MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(...,
668-
* mcuxClEls_EccSign_Async(opts,
669-
* MCXN_ELS_DICE_IAK_KEYSLOT,
670-
* hash, NULL, 0, sig_buf));
671-
* mcuxClEls_WaitForOperation(MCUXCLELS_ERROR_FLAGS_CLEAR);
672-
* memcpy(sig, sig_buf, 64);
673-
* *sig_len = 64;
674-
*/
675-
(void)hash;
676-
(void)hash_len;
677-
(void)sig;
678-
(void)sig_len;
679-
return -1; /* placeholder */
658+
mcuxClEls_EccSignOption_t opts = {0};
659+
uint8_t sig_buf[MCUXCLELS_ECC_SIGNATURE_SIZE] __attribute__((aligned(4)));
660+
int ret = 0;
661+
662+
if (hash == NULL || sig == NULL || sig_len == NULL || hash_len != SHA256_DIGEST_SIZE) {
663+
ret = -1;
664+
}
665+
666+
if (ret == 0) {
667+
/* Set options */
668+
opts.bits.echashchl = MCUXCLELS_ECC_HASHED;
669+
670+
/* Trigger the ECC Sign command.
671+
* We just give the names of token and return value
672+
* since it's declared within the macro */
673+
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(res_sign, tok_sign,
674+
mcuxClEls_EccSign_Async(opts,
675+
MCXN_ELS_DICE_IAK_KEYSLOT,
676+
hash, NULL, 0, sig_buf));
677+
678+
if ((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEls_EccSign_Async) != tok_sign) ||
679+
(MCUXCLELS_STATUS_OK_WAIT != res_sign))
680+
ret = -1;
681+
682+
MCUX_CSSL_FP_FUNCTION_CALL_END();
683+
684+
/* Wait for hardware to finish */
685+
MCUX_CSSL_FP_FUNCTION_CALL_BEGIN(res_w, tok_w,
686+
mcuxClEls_WaitForOperation(MCUXCLELS_ERROR_FLAGS_CLEAR));
687+
688+
if ((MCUX_CSSL_FP_FUNCTION_CALLED(mcuxClEls_WaitForOperation) != tok_w) ||
689+
(MCUXCLELS_STATUS_OK != res_w))
690+
ret = -1;
691+
692+
MCUX_CSSL_FP_FUNCTION_CALL_END();
693+
}
694+
695+
if (ret == 0) {
696+
XMEMCPY(sig, sig_buf, MCUXCLELS_ECC_SIGNATURE_SIZE);
697+
*sig_len = MCUXCLELS_ECC_SIGNATURE_SIZE;
698+
}
699+
700+
return ret;
680701
}
681702

682703
#endif /* WOLFCRYPT_TZ_PSA && WOLFBOOT_DICE_HW && __WOLFBOOT */

0 commit comments

Comments
 (0)