Rename pk_init_ctx() -> pk_setup()

This commit is contained in:
Manuel Pégourié-Gonnard 2015-05-14 19:41:36 +02:00
parent d4f04dba42
commit d9e6a3ac10
7 changed files with 29 additions and 29 deletions

View File

@ -2230,8 +2230,8 @@
#define pk_info_from_type mbedtls_pk_info_from_type #define pk_info_from_type mbedtls_pk_info_from_type
#define pk_info_t mbedtls_pk_info_t #define pk_info_t mbedtls_pk_info_t
#define pk_init mbedtls_pk_init #define pk_init mbedtls_pk_init
#define pk_init_ctx mbedtls_pk_init_ctx #define pk_init_ctx mbedtls_pk_setup
#define pk_init_ctx_rsa_alt mbedtls_pk_init_ctx_rsa_alt #define pk_init_ctx_rsa_alt mbedtls_pk_setup_rsa_alt
#define pk_load_file mbedtls_pk_load_file #define pk_load_file mbedtls_pk_load_file
#define pk_parse_key mbedtls_pk_parse_key #define pk_parse_key mbedtls_pk_parse_key
#define pk_parse_keyfile mbedtls_pk_parse_keyfile #define pk_parse_keyfile mbedtls_pk_parse_keyfile

View File

@ -197,9 +197,9 @@ void mbedtls_pk_free( mbedtls_pk_context *ctx );
* MBEDTLS_ERR_PK_MALLOC_FAILED on allocation failure. * MBEDTLS_ERR_PK_MALLOC_FAILED on allocation failure.
* *
* \note For contexts holding an RSA-alt key, use * \note For contexts holding an RSA-alt key, use
* \c mbedtls_pk_init_ctx_rsa_alt() instead. * \c mbedtls_pk_setup_rsa_alt() instead.
*/ */
int mbedtls_pk_init_ctx( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ); int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info );
#if defined(MBEDTLS_PK_RSA_ALT_SUPPORT) #if defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
/** /**
@ -214,9 +214,9 @@ int mbedtls_pk_init_ctx( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info
* \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the * \return 0 on success, or MBEDTLS_ERR_PK_BAD_INPUT_DATA if the
* context wasn't already initialized as RSA_ALT. * context wasn't already initialized as RSA_ALT.
* *
* \note This function replaces \c mbedtls_pk_init_ctx() for RSA-alt. * \note This function replaces \c mbedtls_pk_setup() for RSA-alt.
*/ */
int mbedtls_pk_init_ctx_rsa_alt( mbedtls_pk_context *ctx, void * key, int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key,
mbedtls_pk_rsa_alt_decrypt_func decrypt_func, mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
mbedtls_pk_rsa_alt_sign_func sign_func, mbedtls_pk_rsa_alt_sign_func sign_func,
mbedtls_pk_rsa_alt_key_len_func key_len_func ); mbedtls_pk_rsa_alt_key_len_func key_len_func );

View File

@ -99,7 +99,7 @@ const mbedtls_pk_info_t * mbedtls_pk_info_from_type( mbedtls_pk_type_t pk_type )
/* /*
* Initialise context * Initialise context
*/ */
int mbedtls_pk_init_ctx( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info ) int mbedtls_pk_setup( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info )
{ {
if( ctx == NULL || info == NULL || ctx->pk_info != NULL ) if( ctx == NULL || info == NULL || ctx->pk_info != NULL )
return( MBEDTLS_ERR_PK_BAD_INPUT_DATA ); return( MBEDTLS_ERR_PK_BAD_INPUT_DATA );
@ -116,7 +116,7 @@ int mbedtls_pk_init_ctx( mbedtls_pk_context *ctx, const mbedtls_pk_info_t *info
/* /*
* Initialize an RSA-alt context * Initialize an RSA-alt context
*/ */
int mbedtls_pk_init_ctx_rsa_alt( mbedtls_pk_context *ctx, void * key, int mbedtls_pk_setup_rsa_alt( mbedtls_pk_context *ctx, void * key,
mbedtls_pk_rsa_alt_decrypt_func decrypt_func, mbedtls_pk_rsa_alt_decrypt_func decrypt_func,
mbedtls_pk_rsa_alt_sign_func sign_func, mbedtls_pk_rsa_alt_sign_func sign_func,
mbedtls_pk_rsa_alt_key_len_func key_len_func ) mbedtls_pk_rsa_alt_key_len_func key_len_func )

View File

@ -607,7 +607,7 @@ int mbedtls_pk_parse_subpubkey( unsigned char **p, const unsigned char *end,
if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_init_ctx( pk, pk_info ) ) != 0 ) if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 )
return( ret ); return( ret );
#if defined(MBEDTLS_RSA_C) #if defined(MBEDTLS_RSA_C)
@ -902,7 +902,7 @@ static int pk_parse_key_pkcs8_unencrypted_der(
if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( pk_alg ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_init_ctx( pk, pk_info ) ) != 0 ) if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 )
return( ret ); return( ret );
#if defined(MBEDTLS_RSA_C) #if defined(MBEDTLS_RSA_C)
@ -1085,7 +1085,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_init_ctx( pk, pk_info ) ) != 0 || if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ),
pem.buf, pem.buflen ) ) != 0 ) pem.buf, pem.buflen ) ) != 0 )
{ {
@ -1117,7 +1117,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_init_ctx( pk, pk_info ) ) != 0 || if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ),
pem.buf, pem.buflen ) ) != 0 ) pem.buf, pem.buflen ) ) != 0 )
{ {
@ -1217,7 +1217,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_init_ctx( pk, pk_info ) ) != 0 || if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), key, keylen ) ) == 0 ) ( ret = pk_parse_key_pkcs1_der( mbedtls_pk_rsa( *pk ), key, keylen ) ) == 0 )
{ {
return( 0 ); return( 0 );
@ -1230,7 +1230,7 @@ int mbedtls_pk_parse_key( mbedtls_pk_context *pk,
if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == NULL ) if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_ECKEY ) ) == NULL )
return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG );
if( ( ret = mbedtls_pk_init_ctx( pk, pk_info ) ) != 0 || if( ( ret = mbedtls_pk_setup( pk, pk_info ) ) != 0 ||
( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), key, keylen ) ) == 0 ) ( ret = pk_parse_key_sec1_der( mbedtls_pk_ec( *pk ), key, keylen ) ) == 0 )
{ {
return( 0 ); return( 0 );

View File

@ -311,9 +311,9 @@ int main( int argc, char *argv[] )
mbedtls_printf( "\n . Generating the private key ..." ); mbedtls_printf( "\n . Generating the private key ..." );
fflush( stdout ); fflush( stdout );
if( ( ret = mbedtls_pk_init_ctx( &key, mbedtls_pk_info_from_type( opt.type ) ) ) != 0 ) if( ( ret = mbedtls_pk_setup( &key, mbedtls_pk_info_from_type( opt.type ) ) ) != 0 )
{ {
mbedtls_printf( " failed\n ! mbedtls_pk_init_ctx returned -0x%04x", -ret ); mbedtls_printf( " failed\n ! mbedtls_pk_setup returned -0x%04x", -ret );
goto exit; goto exit;
} }

View File

@ -1757,8 +1757,8 @@ pk_get_type mbedtls_pk_get_type
pk_info_from_type mbedtls_pk_info_from_type pk_info_from_type mbedtls_pk_info_from_type
pk_info_t mbedtls_pk_info_t pk_info_t mbedtls_pk_info_t
pk_init mbedtls_pk_init pk_init mbedtls_pk_init
pk_init_ctx mbedtls_pk_init_ctx pk_init_ctx mbedtls_pk_setup
pk_init_ctx_rsa_alt mbedtls_pk_init_ctx_rsa_alt pk_init_ctx_rsa_alt mbedtls_pk_setup_rsa_alt
pk_load_file mbedtls_pk_load_file pk_load_file mbedtls_pk_load_file
pk_parse_key mbedtls_pk_parse_key pk_parse_key mbedtls_pk_parse_key
pk_parse_keyfile mbedtls_pk_parse_keyfile pk_parse_keyfile mbedtls_pk_parse_keyfile

View File

@ -70,7 +70,7 @@ void pk_utils( int type, int size, int len, char *name )
mbedtls_pk_init( &pk ); mbedtls_pk_init( &pk );
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( type ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
TEST_ASSERT( pk_genkey( &pk ) == 0 ); TEST_ASSERT( pk_genkey( &pk ) == 0 );
TEST_ASSERT( (int) mbedtls_pk_get_type( &pk ) == type ); TEST_ASSERT( (int) mbedtls_pk_get_type( &pk ) == type );
@ -101,7 +101,7 @@ void mbedtls_pk_check_pair( char *pub_file, char *prv_file, int ret )
#if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PK_RSA_ALT_SUPPORT) #if defined(MBEDTLS_RSA_C) && defined(MBEDTLS_PK_RSA_ALT_SUPPORT)
if( mbedtls_pk_get_type( &prv ) == MBEDTLS_PK_RSA ) if( mbedtls_pk_get_type( &prv ) == MBEDTLS_PK_RSA )
{ {
TEST_ASSERT( mbedtls_pk_init_ctx_rsa_alt( &alt, mbedtls_pk_rsa( prv ), TEST_ASSERT( mbedtls_pk_setup_rsa_alt( &alt, mbedtls_pk_rsa( prv ),
mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func, mbedtls_rsa_key_len_func ) == 0 ); mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func, mbedtls_rsa_key_len_func ) == 0 );
TEST_ASSERT( mbedtls_pk_check_pair( &pub, &alt ) == ret ); TEST_ASSERT( mbedtls_pk_check_pair( &pub, &alt ) == ret );
} }
@ -131,7 +131,7 @@ void pk_rsa_verify_test_vec( char *message_hex_string, int digest,
memset( hash_result, 0x00, 1000 ); memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 ); memset( result_str, 0x00, 1000 );
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
rsa = mbedtls_pk_rsa( pk ); rsa = mbedtls_pk_rsa( pk );
rsa->len = mod / 8; rsa->len = mod / 8;
@ -175,7 +175,7 @@ void pk_rsa_verify_ext_test_vec( char *message_hex_string, int digest,
memset( hash_result, 0x00, 1000 ); memset( hash_result, 0x00, 1000 );
memset( result_str, 0x00, 1000 ); memset( result_str, 0x00, 1000 );
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
rsa = mbedtls_pk_rsa( pk ); rsa = mbedtls_pk_rsa( pk );
rsa->len = mod / 8; rsa->len = mod / 8;
@ -233,7 +233,7 @@ void pk_ec_test_vec( int type, int id, char *key_str,
memset( sig, 0, sizeof( sig ) ); sig_len = unhexify(sig, sig_str); memset( sig, 0, sizeof( sig ) ); sig_len = unhexify(sig, sig_str);
memset( key, 0, sizeof( key ) ); key_len = unhexify(key, key_str); memset( key, 0, sizeof( key ) ); key_len = unhexify(key, key_str);
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( type ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECDSA ) ); TEST_ASSERT( mbedtls_pk_can_do( &pk, MBEDTLS_PK_ECDSA ) );
eckey = mbedtls_pk_ec( pk ); eckey = mbedtls_pk_ec( pk );
@ -262,7 +262,7 @@ void pk_sign_verify( int type, int sign_ret, int verify_ret )
memset( hash, 0x2a, sizeof hash ); memset( hash, 0x2a, sizeof hash );
memset( sig, 0, sizeof sig ); memset( sig, 0, sizeof sig );
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( type ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
TEST_ASSERT( pk_genkey( &pk ) == 0 ); TEST_ASSERT( pk_genkey( &pk ) == 0 );
TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, sizeof hash, TEST_ASSERT( mbedtls_pk_sign( &pk, MBEDTLS_MD_SHA256, hash, sizeof hash,
@ -299,7 +299,7 @@ void pk_rsa_encrypt_test_vec( char *message_hex, int mod,
res_len = unhexify( result, result_hex ); res_len = unhexify( result, result_hex );
mbedtls_pk_init( &pk ); mbedtls_pk_init( &pk );
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
rsa = mbedtls_pk_rsa( pk ); rsa = mbedtls_pk_rsa( pk );
rsa->len = mod / 8; rsa->len = mod / 8;
@ -345,7 +345,7 @@ void pk_rsa_decrypt_test_vec( char *cipher_hex, int mod,
cipher_len = unhexify( cipher, cipher_hex ); cipher_len = unhexify( cipher, cipher_hex );
/* init pk-rsa context */ /* init pk-rsa context */
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
rsa = mbedtls_pk_rsa( pk ); rsa = mbedtls_pk_rsa( pk );
/* load public key */ /* load public key */
@ -399,7 +399,7 @@ void pk_ec_nocrypt( int type )
memset( output, 0, sizeof( output ) ); memset( output, 0, sizeof( output ) );
memset( input, 0, sizeof( input ) ); memset( input, 0, sizeof( input ) );
TEST_ASSERT( mbedtls_pk_init_ctx( &pk, mbedtls_pk_info_from_type( type ) ) == 0 ); TEST_ASSERT( mbedtls_pk_setup( &pk, mbedtls_pk_info_from_type( type ) ) == 0 );
TEST_ASSERT( mbedtls_pk_encrypt( &pk, input, sizeof( input ), TEST_ASSERT( mbedtls_pk_encrypt( &pk, input, sizeof( input ),
output, &olen, sizeof( output ), output, &olen, sizeof( output ),
@ -440,7 +440,7 @@ void pk_rsa_alt( )
memset( test, 0, sizeof test ); memset( test, 0, sizeof test );
/* Initiliaze PK RSA context with random key */ /* Initiliaze PK RSA context with random key */
TEST_ASSERT( mbedtls_pk_init_ctx( &rsa, TEST_ASSERT( mbedtls_pk_setup( &rsa,
mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 ); mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == 0 );
TEST_ASSERT( pk_genkey( &rsa ) == 0 ); TEST_ASSERT( pk_genkey( &rsa ) == 0 );
@ -448,7 +448,7 @@ void pk_rsa_alt( )
TEST_ASSERT( mbedtls_rsa_copy( &raw, mbedtls_pk_rsa( rsa ) ) == 0 ); TEST_ASSERT( mbedtls_rsa_copy( &raw, mbedtls_pk_rsa( rsa ) ) == 0 );
/* Initialize PK RSA_ALT context */ /* Initialize PK RSA_ALT context */
TEST_ASSERT( mbedtls_pk_init_ctx_rsa_alt( &alt, (void *) &raw, TEST_ASSERT( mbedtls_pk_setup_rsa_alt( &alt, (void *) &raw,
mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func, mbedtls_rsa_key_len_func ) == 0 ); mbedtls_rsa_decrypt_func, mbedtls_rsa_sign_func, mbedtls_rsa_key_len_func ) == 0 );
/* Test administrative functions */ /* Test administrative functions */