1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-08-08 17:42:09 +03:00

Split mbedtls_gcm_init() -> gcm_setkey()

This commit is contained in:
Manuel Pégourié-Gonnard
2015-04-28 21:42:17 +02:00
parent 6963ff0969
commit c34e8dd265
6 changed files with 43 additions and 13 deletions

View File

@@ -26,6 +26,8 @@ void gcm_encrypt_and_tag( int cipher_id,
unsigned int key_len;
size_t pt_len, iv_len, add_len, tag_len = tag_len_bits / 8;
mbedtls_gcm_init( &ctx );
memset(key_str, 0x00, 128);
memset(src_str, 0x00, 128);
memset(dst_str, 0x00, 257);
@@ -40,7 +42,7 @@ void gcm_encrypt_and_tag( int cipher_id,
iv_len = unhexify( iv_str, hex_iv_string );
add_len = unhexify( add_str, hex_add_string );
TEST_ASSERT( mbedtls_gcm_init( &ctx, cipher_id, key_str, key_len * 8 ) == init_result );
TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str, key_len * 8 ) == init_result );
if( init_result == 0 )
{
TEST_ASSERT( mbedtls_gcm_crypt_and_tag( &ctx, MBEDTLS_GCM_ENCRYPT, pt_len, iv_str, iv_len, add_str, add_len, src_str, output, tag_len, tag_output ) == 0 );
@@ -75,6 +77,8 @@ void gcm_decrypt_and_verify( int cipher_id,
size_t pt_len, iv_len, add_len, tag_len = tag_len_bits / 8;
int ret;
mbedtls_gcm_init( &ctx );
memset(key_str, 0x00, 128);
memset(src_str, 0x00, 128);
memset(dst_str, 0x00, 257);
@@ -89,7 +93,7 @@ void gcm_decrypt_and_verify( int cipher_id,
add_len = unhexify( add_str, hex_add_string );
unhexify( tag_str, hex_tag_string );
TEST_ASSERT( mbedtls_gcm_init( &ctx, cipher_id, key_str, key_len * 8 ) == init_result );
TEST_ASSERT( mbedtls_gcm_setkey( &ctx, cipher_id, key_str, key_len * 8 ) == init_result );
if( init_result == 0 )
{
ret = mbedtls_gcm_auth_decrypt( &ctx, pt_len, iv_str, iv_len, add_str, add_len, tag_str, tag_len, src_str, output );