Signature wrapper for uECC

This commit is contained in:
Jarno Lamsa 2019-04-23 09:15:54 +03:00 committed by Hanno Becker
parent 9c9e77a8ad
commit ad78931fb3
2 changed files with 14 additions and 8 deletions

View File

@ -613,7 +613,7 @@ static int asn1_write_mpibuf( unsigned char **p, unsigned char *start,
return( (int) len ); return( (int) len );
} }
/* Transcode signature from PSA format to ASN.1 sequence. /* Transcode signature from uECC format to ASN.1 sequence.
* See ecdsa_signature_to_asn1 in ecdsa.c, but with byte buffers instead of * See ecdsa_signature_to_asn1 in ecdsa.c, but with byte buffers instead of
* MPIs, and in-place. * MPIs, and in-place.
* *
@ -647,16 +647,17 @@ static int uecc_ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
unsigned char *sig, size_t *sig_len, unsigned char *sig, size_t *sig_len,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng ) int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
{ {
(void) ctx; const mbedtls_uecc_keypair *keypair = (const mbedtls_uecc_keypair *) ctx;
(void) md_alg; const struct uECC_Curve_t * uecc_curve = uECC_secp256r1();
(void) hash;
(void) hash_len; uECC_sign(keypair->private_key, hash, hash_len, sig, uecc_curve);
(void) sig;
(void) sig_len; /* uECC owns its rng function pointer */
(void) f_rng; (void) f_rng;
(void) p_rng; (void) p_rng;
(void) md_alg;
return( 0 ); return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, 2*NUM_ECC_BYTES ) );
} }
static void *uecc_ecdsa_alloc_wrap( void ) static void *uecc_ecdsa_alloc_wrap( void )

View File

@ -3973,6 +3973,11 @@ sign:
rs_ctx = &ssl->handshake->ecrs_ctx.pk; rs_ctx = &ssl->handshake->ecrs_ctx.pk;
#endif #endif
#if defined(MBEDTLS_USE_TINYCRYPT)
if ( uECC_get_rng() == 0 )
uECC_set_rng(&mbetls_uecc_rng_wrapper);
#endif
if( ( ret = mbedtls_pk_sign_restartable( mbedtls_ssl_own_key( ssl ), if( ( ret = mbedtls_pk_sign_restartable( mbedtls_ssl_own_key( ssl ),
md_alg, hash_start, hashlen, md_alg, hash_start, hashlen,
ssl->out_msg + 6 + offset, &n, ssl->out_msg + 6 + offset, &n,