CCM*: Add minimal tests
This commit is contained in:
parent
b5734a28d9
commit
95ab93d417
@ -41,6 +41,15 @@ ccm_lengths:5:10:65281:8:MBEDTLS_ERR_CCM_BAD_INPUT
|
||||
CCM lengths #8 msg too long for this IV length (2^16, q = 2)
|
||||
ccm_lengths:65536:13:5:8:MBEDTLS_ERR_CCM_BAD_INPUT
|
||||
|
||||
CCM lengths #9 tag length 0
|
||||
ccm_lengths:5:10:5:0:MBEDTLS_ERR_CCM_BAD_INPUT
|
||||
|
||||
CCM* fixed tag lengths #1 all OK
|
||||
ccm_star_lengths:5:10:5:8:0
|
||||
|
||||
CCM* fixed tag lengths #2 all OK - tag length 0
|
||||
ccm_star_lengths:5:10:5:0:0
|
||||
|
||||
CCM encrypt and tag RFC 3610 #1
|
||||
depends_on:MBEDTLS_AES_C
|
||||
mbedtls_ccm_encrypt_and_tag:MBEDTLS_CIPHER_ID_AES:"C0C1C2C3C4C5C6C7C8C9CACBCCCDCECF":"08090A0B0C0D0E0F101112131415161718191A1B1C1D1E":"00000003020100A0A1A2A3A4A5":"0001020304050607":"588C979A61C663D2F066D0C2C0F989806D5F6B61DAC38417E8D12CFDF926E0"
|
||||
|
@ -74,6 +74,47 @@ exit:
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE depends_on:MBEDTLS_AES_C */
|
||||
void ccm_star_lengths( int msg_len, int iv_len, int add_len, int tag_len,
|
||||
int res )
|
||||
{
|
||||
mbedtls_ccm_context ctx;
|
||||
unsigned char key[16];
|
||||
unsigned char msg[10];
|
||||
unsigned char iv[14];
|
||||
unsigned char add[10];
|
||||
unsigned char out[10];
|
||||
unsigned char tag[18];
|
||||
int decrypt_ret;
|
||||
|
||||
mbedtls_ccm_init( &ctx );
|
||||
|
||||
memset( key, 0, sizeof( key ) );
|
||||
memset( msg, 0, sizeof( msg ) );
|
||||
memset( iv, 0, sizeof( iv ) );
|
||||
memset( add, 0, sizeof( add ) );
|
||||
memset( out, 0, sizeof( out ) );
|
||||
memset( tag, 0, sizeof( tag ) );
|
||||
|
||||
TEST_ASSERT( mbedtls_ccm_setkey( &ctx, MBEDTLS_CIPHER_ID_AES,
|
||||
key, 8 * sizeof( key ) ) == 0 );
|
||||
|
||||
TEST_ASSERT( mbedtls_ccm_star_encrypt_and_tag( &ctx, msg_len, iv, iv_len,
|
||||
add, add_len, msg, out, tag, tag_len ) == res );
|
||||
|
||||
decrypt_ret = mbedtls_ccm_star_auth_decrypt( &ctx, msg_len, iv, iv_len, add,
|
||||
add_len, msg, out, tag, tag_len );
|
||||
|
||||
if( res == 0 && tag_len != 0 )
|
||||
TEST_ASSERT( decrypt_ret == MBEDTLS_ERR_CCM_AUTH_FAILED );
|
||||
else
|
||||
TEST_ASSERT( decrypt_ret == res );
|
||||
|
||||
exit:
|
||||
mbedtls_ccm_free( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void mbedtls_ccm_encrypt_and_tag( int cipher_id,
|
||||
char *key_hex, char *msg_hex,
|
||||
|
Loading…
Reference in New Issue
Block a user