@@ -726,12 +726,9 @@ static int ecdsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
726
726
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT ;
727
727
mbedtls_svc_key_id_t key_id = MBEDTLS_SVC_KEY_ID_INIT ;
728
728
psa_status_t status ;
729
- size_t key_len ;
730
- /* This buffer will initially contain the public key and then the signature
731
- * but at different points in time. For all curves except secp224k1, which
732
- * is not currently supported in PSA, the public key is one byte longer
733
- * (header byte + 2 numbers, while the signature is only 2 numbers),
734
- * so use that as the buffer size. */
729
+ /* For all curves except secp224k1, which is not currently supported in PSA,
730
+ * the public key is one byte longer (header byte + 2 numbers, while the
731
+ * signature is only 2 numbers), so use that as the buffer size. */
735
732
unsigned char buf [MBEDTLS_PSA_MAX_EC_PUBKEY_LENGTH ];
736
733
unsigned char * p ;
737
734
psa_algorithm_t psa_sig_md = PSA_ALG_ECDSA_ANY ;
@@ -740,7 +737,8 @@ static int ecdsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
740
737
size_t signature_part_size ;
741
738
((void ) md_alg );
742
739
743
- if (mbedtls_pk_get_ec_public_key_props (pk , & curve , & curve_bits ) != 0 ) {
740
+ if ((mbedtls_pk_get_ec_public_key_props (pk , & curve , & curve_bits ) != 0 ) ||
741
+ (pk -> pk_raw_len == 0 )) {
744
742
return MBEDTLS_ERR_PK_BAD_INPUT_DATA ;
745
743
}
746
744
signature_part_size = PSA_BITS_TO_BYTES (curve_bits );
@@ -749,13 +747,8 @@ static int ecdsa_verify_wrap(mbedtls_pk_context *pk, mbedtls_md_type_t md_alg,
749
747
psa_set_key_usage_flags (& attributes , PSA_KEY_USAGE_VERIFY_HASH );
750
748
psa_set_key_algorithm (& attributes , psa_sig_md );
751
749
752
- ret = mbedtls_pk_get_public_key (pk , buf , sizeof (buf ), & key_len );
753
- if (ret != 0 ) {
754
- goto cleanup ;
755
- }
756
-
757
750
status = psa_import_key (& attributes ,
758
- buf , key_len ,
751
+ pk -> pk_raw , pk -> pk_raw_len ,
759
752
& key_id );
760
753
if (status != PSA_SUCCESS ) {
761
754
ret = PSA_PK_TO_MBEDTLS_ERR (status );
0 commit comments