3535#include <wolfssl/wolfcrypt/random.h>
3636#include <wolfssl/wolfcrypt/sha256.h>
3737#include <wolfssl/wolfcrypt/integer.h>
38- #include <wolfssl/wolfcrypt/memory.h>
3938
4039#if defined(WOLFBOOT_HASH_SHA384 )
4140#include <wolfssl/wolfcrypt/sha512.h>
6867#define WOLFBOOT_DICE_ERR_HW -3
6968#define WOLFBOOT_DICE_ERR_CRYPTO -4
7069
70+ static NOINLINEFUNCTION void wolfboot_dice_zeroize (void * ptr , size_t len )
71+ {
72+ volatile uint8_t * p = (volatile uint8_t * )ptr ;
73+ while (len -- > 0U ) {
74+ * p ++ = 0U ;
75+ }
76+ }
77+
7178#define COSE_LABEL_ALG 1
7279#define COSE_ALG_ES256 (-7)
7380
@@ -621,7 +628,7 @@ static int wolfboot_dice_derive_attestation_key(ecc_key *key,
621628 goto cleanup ;
622629 }
623630 /* CDI is no longer needed once the seed has been derived. */
624- wc_ForceZero (cdi , sizeof (cdi ));
631+ wolfboot_dice_zeroize (cdi , sizeof (cdi ));
625632
626633 if (wolfboot_dice_hkdf (seed , sizeof (seed ),
627634 (const uint8_t * )"WOLFBOOT-IAK" , 12 ,
@@ -630,7 +637,7 @@ static int wolfboot_dice_derive_attestation_key(ecc_key *key,
630637 goto cleanup ;
631638 }
632639 /* Seed is no longer needed once the private key material is derived. */
633- wc_ForceZero (seed , sizeof (seed ));
640+ wolfboot_dice_zeroize (seed , sizeof (seed ));
634641
635642 if (wolfboot_dice_fixup_priv (priv , sizeof (priv )) != 0 ) {
636643 goto cleanup ;
@@ -644,9 +651,9 @@ static int wolfboot_dice_derive_attestation_key(ecc_key *key,
644651 ret = 0 ;
645652
646653cleanup :
647- wc_ForceZero (priv , sizeof (priv ));
648- wc_ForceZero (seed , sizeof (seed ));
649- wc_ForceZero (cdi , sizeof (cdi ));
654+ wolfboot_dice_zeroize (priv , sizeof (priv ));
655+ wolfboot_dice_zeroize (seed , sizeof (seed ));
656+ wolfboot_dice_zeroize (cdi , sizeof (cdi ));
650657 return ret ;
651658}
652659
@@ -675,7 +682,7 @@ static int wolfboot_attest_get_private_key(ecc_key *key,
675682 ret = 0 ;
676683
677684cleanup :
678- wc_ForceZero (priv , sizeof (priv ));
685+ wolfboot_dice_zeroize (priv , sizeof (priv ));
679686 return ret ;
680687 }
681688#else
@@ -684,7 +691,7 @@ static int wolfboot_attest_get_private_key(ecc_key *key,
684691 if (hal_uds_derive_key (uds , uds_len ) == 0 ) {
685692 ret = wolfboot_dice_derive_attestation_key (key , uds , uds_len , claims );
686693 }
687- wc_ForceZero (uds , sizeof (uds ));
694+ wolfboot_dice_zeroize (uds , sizeof (uds ));
688695 return ret ;
689696#endif
690697}
@@ -870,10 +877,10 @@ static int wolfboot_dice_sign_tbs(const uint8_t *tbs,
870877 }
871878 if (key_inited ) {
872879 wc_ecc_free (& key );
873- wc_ForceZero (& key , sizeof (key ));
880+ wolfboot_dice_zeroize (& key , sizeof (key ));
874881 }
875- wc_ForceZero (hash , sizeof (hash ));
876- wc_ForceZero (der_sig , sizeof (der_sig ));
882+ wolfboot_dice_zeroize (hash , sizeof (hash ));
883+ wolfboot_dice_zeroize (der_sig , sizeof (der_sig ));
877884 return ret ;
878885}
879886
0 commit comments