Split mbedtls_ccm_init() -> setkey()
diff --git a/library/ccm.c b/library/ccm.c
index 72eed38..957fda9 100644
--- a/library/ccm.c
+++ b/library/ccm.c
@@ -61,8 +61,15 @@
/*
* Initialize context
*/
-int mbedtls_ccm_init( mbedtls_ccm_context *ctx, mbedtls_cipher_id_t cipher,
- const unsigned char *key, unsigned int keysize )
+void mbedtls_ccm_init( mbedtls_ccm_context *ctx )
+{
+ memset( ctx, 0, sizeof( mbedtls_ccm_context ) );
+}
+
+int mbedtls_ccm_setkey( mbedtls_ccm_context *ctx,
+ mbedtls_cipher_id_t cipher,
+ const unsigned char *key,
+ unsigned int keysize )
{
int ret;
const mbedtls_cipher_info_t *cipher_info;
@@ -398,7 +405,9 @@
size_t i;
int ret;
- if( mbedtls_ccm_init( &ctx, MBEDTLS_CIPHER_ID_AES, key, 8 * sizeof key ) != 0 )
+ mbedtls_ccm_init( &ctx );
+
+ if( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES, key, 8 * sizeof key ) != 0 )
{
if( verbose != 0 )
mbedtls_printf( " CCM: setup failed" );
diff --git a/library/cipher_wrap.c b/library/cipher_wrap.c
index ebc3c4f..eb291b6 100644
--- a/library/cipher_wrap.c
+++ b/library/cipher_wrap.c
@@ -395,7 +395,7 @@
static int ccm_aes_setkey_wrap( void *ctx, const unsigned char *key,
unsigned int key_length )
{
- return mbedtls_ccm_init( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
+ return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_AES,
key, key_length );
}
@@ -752,7 +752,7 @@
static int ccm_camellia_setkey_wrap( void *ctx, const unsigned char *key,
unsigned int key_length )
{
- return mbedtls_ccm_init( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
+ return mbedtls_ccm_setkey( (mbedtls_ccm_context *) ctx, MBEDTLS_CIPHER_ID_CAMELLIA,
key, key_length );
}