Skip to content

Commit 5d5e90a

Browse files
author
Hanno Becker
committed
Adapt ecdsa_verify_wrap() to new EC public key format
Previously, PSA used SubjectPublicKeyInfo structures to serialize EC public keys. This has recently been changed to using ECPoint structures instead, but the wrapper making PSA ECDSA verification available through Mbed TLS' PK API hasn't yet been adapted accordingly - which is what this commit does. Luckily, Mbed TLS' PK API offers two functions mbedtls_pk_write_pubkey() and mbedtls_pk_write_pubkey_der(), the latter exporting a SubjectPublicKeyInfo structure and the former exporting an ECPoint structure in case of EC public keys. For the adaptation of the ECDSA wrapper ecdsa_verify_wrap() it is therefore sufficient to use mbedtls_pk_write_pubkey() instead of mbedtls_pk_write_pubkey_der().
1 parent 37a8c0c commit 5d5e90a

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/pk_wrap.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
553553
int key_len;
554554
/* see ECP_PUB_DER_MAX_BYTES in pkwrite.c */
555555
unsigned char buf[30 + 2 * MBEDTLS_ECP_MAX_BYTES];
556-
unsigned char *p = (unsigned char*) sig;
556+
unsigned char *p;
557557
mbedtls_pk_info_t pk_info = mbedtls_eckey_info;
558558
psa_algorithm_t psa_sig_md, psa_md;
559559
psa_ecc_curve_t curve = mbedtls_psa_translate_ecc_group(
@@ -567,7 +567,8 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
567567
* re-construct one to make it happy */
568568
key.pk_info = &pk_info;
569569
key.pk_ctx = ctx;
570-
key_len = mbedtls_pk_write_pubkey_der( &key, buf, sizeof( buf ) );
570+
p = buf + sizeof( buf );
571+
key_len = mbedtls_pk_write_pubkey( &p, buf, &key );
571572
if( key_len <= 0 )
572573
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
573574

@@ -603,6 +604,7 @@ static int ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
603604
goto cleanup;
604605
}
605606

607+
p = (unsigned char*) sig;
606608
if( ( ret = extract_ecdsa_sig( &p, sig + sig_len, buf,
607609
signature_part_size ) ) != 0 )
608610
{

0 commit comments

Comments
 (0)