TinyCrypt Test: Adapt 'PK utils: ECKEY' test in PK test suite

This commit is contained in:
Hanno Becker 2019-08-21 13:28:44 +01:00
parent da77971ec8
commit 251d7523fe
2 changed files with 28 additions and 4 deletions

View file

@ -12,10 +12,14 @@ PK utils: RSA
depends_on:MBEDTLS_RSA_C:MBEDTLS_GENPRIME
pk_utils:MBEDTLS_PK_RSA:512:64:"RSA"
PK utils: ECKEY
depends_on:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED
PK utils: ECKEY (legacy)
depends_on:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED:!MBEDTLS_USE_TINYCRYPT
pk_utils:MBEDTLS_PK_ECKEY:192:24:"EC"
PK utils: ECKEY (TinyCrypt)
depends_on:MBEDTLS_USE_TINYCRYPT
pk_utils:MBEDTLS_PK_ECKEY:256:32:"EC"
PK utils: ECKEY_DH
depends_on:MBEDTLS_ECP_C:MBEDTLS_ECP_DP_SECP192R1_ENABLED
pk_utils:MBEDTLS_PK_ECKEY_DH:192:24:"EC_DH"

View file

@ -7,6 +7,10 @@
#include "mbedtls/ecp.h"
#include "mbedtls/rsa.h"
#if defined(MBEDTLS_USE_TINYCRYPT)
#include "tinycrypt/ecc_dh.h"
#endif /* MBEDTLS_USE_TINYCRYPT */
#include <limits.h>
#include <stdint.h>
@ -21,8 +25,24 @@ static int pk_genkey( mbedtls_pk_context *pk )
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_GENPRIME)
if( mbedtls_pk_get_type( pk ) == MBEDTLS_PK_RSA )
{
return mbedtls_rsa_gen_key( mbedtls_pk_rsa( *pk ), rnd_std_rand, NULL, RSA_KEY_SIZE, 3 );
} else
#endif
#if defined(MBEDTLS_USE_TINYCRYPT)
if( mbedtls_pk_get_type( pk ) == MBEDTLS_PK_ECKEY )
{
int ret;
ret = uECC_make_key( mbedtls_pk_uecc( *pk )->public_key,
mbedtls_pk_uecc( *pk )->private_key,
uECC_secp256r1() );
if( ret == 0 )
return( -1 );
return( 0 );
} else
#endif /* MBEDTLS_USE_TINYCRYPT */
#if defined(MBEDTLS_ECP_C)
if( mbedtls_pk_get_type( pk ) == MBEDTLS_PK_ECKEY ||
mbedtls_pk_get_type( pk ) == MBEDTLS_PK_ECKEY_DH ||
@ -35,7 +55,7 @@ static int pk_genkey( mbedtls_pk_context *pk )
return mbedtls_ecp_gen_keypair( &mbedtls_pk_ec( *pk )->grp, &mbedtls_pk_ec( *pk )->d,
&mbedtls_pk_ec( *pk )->Q, rnd_std_rand, NULL );
}
} else
#endif
return( -1 );
}