diff --git a/include/mbedtls/cipher.h b/include/mbedtls/cipher.h index 084175d0f..58c974bd3 100644 --- a/include/mbedtls/cipher.h +++ b/include/mbedtls/cipher.h @@ -320,7 +320,7 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ); * MBEDTLS_ERR_CIPHER_ALLOC_FAILED if allocation of the * cipher-specific context failed. */ -int mbedtls_cipher_init_ctx( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ); +int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ); /** * \brief Returns the block size of the given cipher. diff --git a/include/mbedtls/compat-1.3.h b/include/mbedtls/compat-1.3.h index ae3e14e2b..9276eaee4 100644 --- a/include/mbedtls/compat-1.3.h +++ b/include/mbedtls/compat-1.3.h @@ -1871,7 +1871,7 @@ #define cipher_info_from_values mbedtls_cipher_info_from_values #define cipher_info_t mbedtls_cipher_info_t #define cipher_init mbedtls_cipher_init -#define cipher_init_ctx mbedtls_cipher_init_ctx +#define cipher_init_ctx mbedtls_cipher_setup #define cipher_list mbedtls_cipher_list #define cipher_mode_t mbedtls_cipher_mode_t #define cipher_padding_t mbedtls_cipher_padding_t diff --git a/library/ccm.c b/library/ccm.c index 109927e4c..75de8cb5b 100644 --- a/library/ccm.c +++ b/library/ccm.c @@ -81,7 +81,7 @@ int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx, if( cipher_info->block_size != 16 ) return( MBEDTLS_ERR_CCM_BAD_INPUT ); - if( ( ret = mbedtls_cipher_init_ctx( &ctx->cipher_ctx, cipher_info ) ) != 0 ) + if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) return( ret ); if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keysize, diff --git a/library/cipher.c b/library/cipher.c index d16893b8d..a55857537 100644 --- a/library/cipher.c +++ b/library/cipher.c @@ -139,7 +139,7 @@ void mbedtls_cipher_free( mbedtls_cipher_context_t *ctx ) mbedtls_zeroize( ctx, sizeof(mbedtls_cipher_context_t) ); } -int mbedtls_cipher_init_ctx( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ) +int mbedtls_cipher_setup( mbedtls_cipher_context_t *ctx, const mbedtls_cipher_info_t *cipher_info ) { if( NULL == cipher_info || NULL == ctx ) return( MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); diff --git a/library/gcm.c b/library/gcm.c index 39648b4c6..79d433a17 100644 --- a/library/gcm.c +++ b/library/gcm.c @@ -174,7 +174,7 @@ int mbedtls_gcm_setkey( mbedtls_gcm_context *ctx, if( cipher_info->block_size != 16 ) return( MBEDTLS_ERR_GCM_BAD_INPUT ); - if( ( ret = mbedtls_cipher_init_ctx( &ctx->cipher_ctx, cipher_info ) ) != 0 ) + if( ( ret = mbedtls_cipher_setup( &ctx->cipher_ctx, cipher_info ) ) != 0 ) return( ret ); if( ( ret = mbedtls_cipher_setkey( &ctx->cipher_ctx, key, keysize, diff --git a/library/pkcs12.c b/library/pkcs12.c index e3ca99506..1baa95c2b 100644 --- a/library/pkcs12.c +++ b/library/pkcs12.c @@ -195,7 +195,7 @@ int mbedtls_pkcs12_pbe( mbedtls_asn1_buf *pbe_params, int mode, mbedtls_cipher_init( &cipher_ctx ); - if( ( ret = mbedtls_cipher_init_ctx( &cipher_ctx, cipher_info ) ) != 0 ) + if( ( ret = mbedtls_cipher_setup( &cipher_ctx, cipher_info ) ) != 0 ) goto exit; if( ( ret = mbedtls_cipher_setkey( &cipher_ctx, key, 8 * keylen, (mbedtls_operation_t) mode ) ) != 0 ) diff --git a/library/pkcs5.c b/library/pkcs5.c index 6163e9aa0..756473348 100644 --- a/library/pkcs5.c +++ b/library/pkcs5.c @@ -198,7 +198,7 @@ int mbedtls_pkcs5_pbes2( const mbedtls_asn1_buf *pbe_params, int mode, goto exit; } - if( ( ret = mbedtls_cipher_init_ctx( &cipher_ctx, cipher_info ) ) != 0 ) + if( ( ret = mbedtls_cipher_setup( &cipher_ctx, cipher_info ) ) != 0 ) goto exit; if( ( ret = mbedtls_cipher_setkey( &cipher_ctx, key, 8 * keylen, (mbedtls_operation_t) mode ) ) != 0 ) diff --git a/library/ssl_tls.c b/library/ssl_tls.c index 19d359ad1..6cf9b7471 100644 --- a/library/ssl_tls.c +++ b/library/ssl_tls.c @@ -867,17 +867,17 @@ int mbedtls_ssl_derive_keys( mbedtls_ssl_context *ssl ) } #endif /* MBEDTLS_SSL_HW_RECORD_ACCEL */ - if( ( ret = mbedtls_cipher_init_ctx( &transform->cipher_ctx_enc, + if( ( ret = mbedtls_cipher_setup( &transform->cipher_ctx_enc, cipher_info ) ) != 0 ) { - MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_init_ctx", ret ); + MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_setup", ret ); return( ret ); } - if( ( ret = mbedtls_cipher_init_ctx( &transform->cipher_ctx_dec, + if( ( ret = mbedtls_cipher_setup( &transform->cipher_ctx_dec, cipher_info ) ) != 0 ) { - MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_init_ctx", ret ); + MBEDTLS_SSL_DEBUG_RET( 1, "mbedtls_cipher_setup", ret ); return( ret ); } diff --git a/programs/aes/crypt_and_hash.c b/programs/aes/crypt_and_hash.c index 67f47c270..f64c34170 100644 --- a/programs/aes/crypt_and_hash.c +++ b/programs/aes/crypt_and_hash.c @@ -173,9 +173,9 @@ int main( int argc, char *argv[] ) mbedtls_fprintf( stderr, "Cipher '%s' not found\n", argv[4] ); goto exit; } - if( ( ret = mbedtls_cipher_init_ctx( &cipher_ctx, cipher_info) ) != 0 ) + if( ( ret = mbedtls_cipher_setup( &cipher_ctx, cipher_info) ) != 0 ) { - mbedtls_fprintf( stderr, "mbedtls_cipher_init_ctx failed\n" ); + mbedtls_fprintf( stderr, "mbedtls_cipher_setup failed\n" ); goto exit; } diff --git a/scripts/data_files/rename-1.3-2.0.txt b/scripts/data_files/rename-1.3-2.0.txt index c5c5d002c..1bd8c3c58 100644 --- a/scripts/data_files/rename-1.3-2.0.txt +++ b/scripts/data_files/rename-1.3-2.0.txt @@ -1400,7 +1400,7 @@ cipher_info_from_type mbedtls_cipher_info_from_type cipher_info_from_values mbedtls_cipher_info_from_values cipher_info_t mbedtls_cipher_info_t cipher_init mbedtls_cipher_init -cipher_init_ctx mbedtls_cipher_init_ctx +cipher_init_ctx mbedtls_cipher_setup cipher_list mbedtls_cipher_list cipher_mode_t mbedtls_cipher_mode_t cipher_padding_t mbedtls_cipher_padding_t diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function index 2d51019bf..30f154c62 100644 --- a/tests/suites/test_suite_cipher.function +++ b/tests/suites/test_suite_cipher.function @@ -42,9 +42,9 @@ void cipher_null_args( ) TEST_ASSERT( mbedtls_cipher_info_from_string( NULL ) == NULL ); - TEST_ASSERT( mbedtls_cipher_init_ctx( &ctx, NULL ) + TEST_ASSERT( mbedtls_cipher_setup( &ctx, NULL ) == MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); - TEST_ASSERT( mbedtls_cipher_init_ctx( NULL, info ) + TEST_ASSERT( mbedtls_cipher_setup( NULL, info ) == MBEDTLS_ERR_CIPHER_BAD_INPUT_DATA ); TEST_ASSERT( mbedtls_cipher_setkey( NULL, buf, 0, MBEDTLS_ENCRYPT ) @@ -122,8 +122,8 @@ void enc_dec_buf( int cipher_id, char *cipher_string, int key_len, TEST_ASSERT( mbedtls_cipher_info_from_string( cipher_string ) == cipher_info ); /* Initialise enc and dec contexts */ - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx_dec, cipher_info ) ); - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx_enc, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_enc, cipher_info ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_dec, key, key_len, MBEDTLS_DECRYPT ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_enc, key, key_len, MBEDTLS_ENCRYPT ) ); @@ -242,7 +242,7 @@ void enc_fail( int cipher_id, int pad_mode, int key_len, TEST_ASSERT( NULL != cipher_info ); /* Initialise context */ - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, cipher_info ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, key_len, MBEDTLS_ENCRYPT ) ); #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) TEST_ASSERT( 0 == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) ); @@ -291,7 +291,7 @@ void dec_empty_buf() cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_CBC ); TEST_ASSERT( NULL != cipher_info); - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx_dec, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_dec, key, 128, MBEDTLS_DECRYPT ) ); @@ -350,8 +350,8 @@ void enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val, cipher_info = mbedtls_cipher_info_from_type( cipher_id ); TEST_ASSERT( NULL != cipher_info); - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx_dec, cipher_info ) ); - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx_enc, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_dec, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx_enc, cipher_info ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_dec, key, key_len, MBEDTLS_DECRYPT ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx_enc, key, key_len, MBEDTLS_ENCRYPT ) ); @@ -450,7 +450,7 @@ void decrypt_test_vec( int cipher_id, int pad_mode, #endif /* Prepare context */ - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx, + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, mbedtls_cipher_info_from_type( cipher_id ) ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, MBEDTLS_DECRYPT ) ); #if defined(MBEDTLS_CIPHER_MODE_WITH_PADDING) @@ -524,7 +524,7 @@ void auth_crypt_tv( int cipher_id, char *hex_key, char *hex_iv, tag_len = unhexify( tag, hex_tag ); /* Prepare context */ - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx, + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, mbedtls_cipher_info_from_type( cipher_id ) ) ); TEST_ASSERT( 0 == mbedtls_cipher_setkey( &ctx, key, 8 * key_len, MBEDTLS_DECRYPT ) ); @@ -597,7 +597,7 @@ void test_vec_ecb( int cipher_id, int operation, char *hex_key, memset( output, 0x00, sizeof( output ) ); /* Prepare context */ - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx, + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, mbedtls_cipher_info_from_type( cipher_id ) ) ); key_len = unhexify( key, hex_key ); @@ -636,7 +636,7 @@ void set_padding( int cipher_id, int pad_mode, int ret ) cipher_info = mbedtls_cipher_info_from_type( cipher_id ); TEST_ASSERT( NULL != cipher_info ); - TEST_ASSERT( 0 == mbedtls_cipher_init_ctx( &ctx, cipher_info ) ); + TEST_ASSERT( 0 == mbedtls_cipher_setup( &ctx, cipher_info ) ); TEST_ASSERT( ret == mbedtls_cipher_set_padding_mode( &ctx, pad_mode ) );