@@ -104,6 +104,16 @@ static otError getKeyRef(otCryptoKeyRef *aInputKeyRef, psa_key_attributes_t *aAt
104104 if (psa_get_key_algorithm (aAttributes ) == 0 ) {
105105 psa_set_key_algorithm (aAttributes , PSA_ALG_HMAC (PSA_ALG_SHA_256 ));
106106 }
107+
108+ /* KMU does not support deterministic ECDSA, so we need to set it to
109+ * PSA_ALG_ECDSA(PSA_ALG_SHA_256).
110+ * To keep backward compatibility with the previous functionality we must
111+ * leave PSA_ALG_DETERMINISTIC_ECDSA(PSA_ALG_SHA_256) for the ITS purposes.
112+ */
113+ if (psa_get_key_algorithm (aAttributes ) ==
114+ PSA_ALG_DETERMINISTIC_ECDSA (PSA_ALG_SHA_256 )) {
115+ psa_set_key_algorithm (aAttributes , PSA_ALG_ECDSA (PSA_ALG_SHA_256 ));
116+ }
107117 }
108118#endif /* CONFIG_OPENTHREAD_PSA_NVM_BACKEND */
109119
@@ -680,9 +690,14 @@ otError otPlatCryptoEcdsaSignUsingKeyRef(otCryptoKeyRef aKeyRef,
680690
681691 GET_KEY_REF (& aKeyRef , NULL );
682692
683- status = psa_sign_hash (aKeyRef , PSA_ALG_ECDSA (PSA_ALG_SHA_256 ), aHash -> m8 ,
684- OT_CRYPTO_SHA256_HASH_SIZE , aSignature -> m8 ,
685- OT_CRYPTO_ECDSA_SIGNATURE_SIZE , & signature_length );
693+ #if defined(CONFIG_OPENTHREAD_PSA_NVM_BACKEND_KMU )
694+ psa_algorithm_t algorithm = PSA_ALG_ECDSA (PSA_ALG_SHA_256 );
695+ #else
696+ psa_algorithm_t algorithm = PSA_ALG_DETERMINISTIC_ECDSA (PSA_ALG_SHA_256 );
697+ #endif
698+
699+ status = psa_sign_hash (aKeyRef , algorithm , aHash -> m8 , OT_CRYPTO_SHA256_HASH_SIZE ,
700+ aSignature -> m8 , OT_CRYPTO_ECDSA_SIGNATURE_SIZE , & signature_length );
686701 if (status != PSA_SUCCESS ) {
687702 goto out ;
688703 }
@@ -700,7 +715,13 @@ otError otPlatCryptoEcdsaVerifyUsingKeyRef(otCryptoKeyRef aKeyRef,
700715
701716 GET_KEY_REF (& aKeyRef , NULL );
702717
703- status = psa_verify_hash (aKeyRef , PSA_ALG_ECDSA (PSA_ALG_SHA_256 ), aHash -> m8 ,
718+ #if defined(CONFIG_OPENTHREAD_PSA_NVM_BACKEND_KMU )
719+ psa_algorithm_t algorithm = PSA_ALG_ECDSA (PSA_ALG_SHA_256 );
720+ #else
721+ psa_algorithm_t algorithm = PSA_ALG_DETERMINISTIC_ECDSA (PSA_ALG_SHA_256 );
722+ #endif
723+
724+ status = psa_verify_hash (aKeyRef , algorithm , aHash -> m8 ,
704725 OT_CRYPTO_SHA256_HASH_SIZE , aSignature -> m8 ,
705726 OT_CRYPTO_ECDSA_SIGNATURE_SIZE );
706727 if (status != PSA_SUCCESS ) {
@@ -739,14 +760,15 @@ otError otPlatCryptoEcdsaGenerateAndImportKey(otCryptoKeyRef aKeyRef)
739760 psa_key_id_t key_id = (psa_key_id_t )aKeyRef ;
740761
741762 psa_set_key_usage_flags (& attributes , PSA_KEY_USAGE_VERIFY_HASH | PSA_KEY_USAGE_SIGN_HASH );
742- psa_set_key_algorithm (& attributes , PSA_ALG_ECDSA (PSA_ALG_SHA_256 ));
763+ psa_set_key_algorithm (& attributes , PSA_ALG_DETERMINISTIC_ECDSA (PSA_ALG_SHA_256 ));
743764 psa_set_key_type (& attributes , PSA_KEY_TYPE_ECC_KEY_PAIR (PSA_ECC_FAMILY_SECP_R1 ));
744765 psa_set_key_lifetime (& attributes , PSA_KEY_LIFETIME_PERSISTENT );
745766 psa_set_key_bits (& attributes , 256 );
746767
747768 GET_KEY_REF (& key_id , & attributes );
748769
749770 psa_set_key_id (& attributes , key_id );
771+
750772 status = psa_generate_key (& attributes , & key_id );
751773 if (status != PSA_SUCCESS ) {
752774 goto out ;
0 commit comments