mirror of
https://github.com/yuzu-emu/mbedtls.git
synced 2024-11-26 11:45:39 +01:00
Fixup: Impl. MBEDTLS_PK_ECKEY, not MBEDTLS_PK_ECDSA, via TinyCrypt
The PK-type MBEDTLS_PK_ECDSA isn't really used by the library. Especially, when parsing a generic EC key, a PK context of type MBEDTLS_PK_ECKEY will be requested. Hence, to drop in TinyCrypt for the legacy-ECC implementation, the PK type that TinyCrypt implements must be MBEDTLS_PK_ECKEY.
This commit is contained in:
parent
483fd66d21
commit
adf11e13a4
@ -132,7 +132,7 @@ extern const mbedtls_pk_info_t mbedtls_ecdsa_info;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_USE_TINYCRYPT)
|
||||
extern const mbedtls_pk_info_t mbedtls_uecc_ecdsa_info;
|
||||
extern const mbedtls_pk_info_t mbedtls_uecc_eckey_info;
|
||||
#endif
|
||||
|
||||
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
|
||||
|
14
library/pk.c
14
library/pk.c
@ -115,19 +115,21 @@ const mbedtls_pk_info_t * mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type )
|
||||
return( &mbedtls_rsa_info );
|
||||
#endif
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
case MBEDTLS_PK_ECKEY:
|
||||
return( &mbedtls_eckey_info );
|
||||
case MBEDTLS_PK_ECKEY_DH:
|
||||
return( &mbedtls_eckeydh_info );
|
||||
#endif
|
||||
#if defined(MBEDTLS_USE_TINYCRYPT)
|
||||
case MBEDTLS_PK_ECDSA:
|
||||
return( &mbedtls_uecc_ecdsa_info );
|
||||
#else
|
||||
#if defined(MBEDTLS_ECDSA_C)
|
||||
case MBEDTLS_PK_ECDSA:
|
||||
return( &mbedtls_ecdsa_info );
|
||||
#endif
|
||||
#if defined(MBEDTLS_USE_TINYCRYPT)
|
||||
case MBEDTLS_PK_ECKEY:
|
||||
return( &mbedtls_uecc_eckey_info );
|
||||
#else /* MBEDTLS_USE_TINYCRYPT */
|
||||
#if defined(MBEDTLS_ECP_C)
|
||||
case MBEDTLS_PK_ECKEY:
|
||||
return( &mbedtls_eckey_info );
|
||||
#endif
|
||||
#endif /* MBEDTLS_USE_TINYCRYPT */
|
||||
/* MBEDTLS_PK_RSA_ALT omitted on purpose */
|
||||
default:
|
||||
|
@ -528,18 +528,19 @@ static int extract_ecdsa_sig( unsigned char **p, const unsigned char *end,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static size_t uecc_ecdsa_get_bitlen( const void *ctx )
|
||||
static size_t uecc_eckey_get_bitlen( const void *ctx )
|
||||
{
|
||||
(void) ctx;
|
||||
return( (size_t) 2 * NUM_ECC_BYTES );
|
||||
}
|
||||
|
||||
static int uecc_ecdsa_can_do( mbedtls_pk_type_t type )
|
||||
static int uecc_eckey_can_do( mbedtls_pk_type_t type )
|
||||
{
|
||||
return( type == MBEDTLS_PK_ECDSA );
|
||||
return( type == MBEDTLS_PK_ECDSA ||
|
||||
type == MBEDTLS_PK_ECKEY );
|
||||
}
|
||||
|
||||
static int uecc_ecdsa_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
static int uecc_eckey_verify_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
const unsigned char *sig, size_t sig_len )
|
||||
{
|
||||
@ -642,7 +643,7 @@ static int pk_ecdsa_sig_asn1_from_psa( unsigned char *sig, size_t *sig_len,
|
||||
return( 0 );
|
||||
}
|
||||
|
||||
static int uecc_ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
static int uecc_eckey_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
const unsigned char *hash, size_t hash_len,
|
||||
unsigned char *sig, size_t *sig_len,
|
||||
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng )
|
||||
@ -660,7 +661,7 @@ static int uecc_ecdsa_sign_wrap( void *ctx, mbedtls_md_type_t md_alg,
|
||||
return( pk_ecdsa_sig_asn1_from_psa( sig, sig_len, 2*NUM_ECC_BYTES ) );
|
||||
}
|
||||
|
||||
static void *uecc_ecdsa_alloc_wrap( void )
|
||||
static void *uecc_eckey_alloc_wrap( void )
|
||||
{
|
||||
/*void *ctx = mbedtls_calloc( 1, sizeof( mbedtls_ecdsa_context ) );
|
||||
|
||||
@ -671,25 +672,25 @@ static void *uecc_ecdsa_alloc_wrap( void )
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void uecc_ecdsa_free_wrap( void *ctx )
|
||||
static void uecc_eckey_free_wrap( void *ctx )
|
||||
{
|
||||
(void) ctx;
|
||||
/*mbedtls_ecdsa_free( (mbedtls_ecdsa_context *) ctx );
|
||||
mbedtls_free( ctx );*/
|
||||
}
|
||||
|
||||
const mbedtls_pk_info_t mbedtls_uecc_ecdsa_info = {
|
||||
MBEDTLS_PK_ECDSA,
|
||||
"ECDSA",
|
||||
uecc_ecdsa_get_bitlen,
|
||||
uecc_ecdsa_can_do,
|
||||
uecc_ecdsa_verify_wrap,
|
||||
uecc_ecdsa_sign_wrap,
|
||||
const mbedtls_pk_info_t mbedtls_uecc_eckey_info = {
|
||||
MBEDTLS_PK_ECKEY,
|
||||
"EC",
|
||||
uecc_eckey_get_bitlen,
|
||||
uecc_eckey_can_do,
|
||||
uecc_eckey_verify_wrap,
|
||||
uecc_eckey_sign_wrap,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
uecc_ecdsa_alloc_wrap,
|
||||
uecc_ecdsa_free_wrap,
|
||||
uecc_eckey_alloc_wrap,
|
||||
uecc_eckey_free_wrap,
|
||||
NULL,
|
||||
};
|
||||
#else
|
||||
|
@ -1545,7 +1545,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
|
||||
#endif /* MBEDTLS_RSA_C */
|
||||
|
||||
#if defined(MBEDTLS_USE_TINYCRYPT)
|
||||
pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECDSA );
|
||||
pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY );
|
||||
if( mbedtls_pk_setup( pk, pk_info ) == 0 &&
|
||||
pk_parse_key_sec1_der( mbedtls_uecc_pk( *pk),
|
||||
key, keylen) == 0)
|
||||
|
Loading…
Reference in New Issue
Block a user