Add test vectors to the cipher test suite
Ensures the selected cipher/mode/padding is actually used and padding and tag are actually checked.
This commit is contained in:
parent
43a4780b03
commit
8eccab5077
3 changed files with 99 additions and 0 deletions
|
@ -764,3 +764,31 @@ enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:17:6:
|
|||
AES Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
depends_on:POLARSSL_AES_C
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_256_CBC:256:16:16:
|
||||
|
||||
AES Decrypt test vector #0
|
||||
depends_on:POLARSSL_AES_C:POLARSSL_CIPHER_PADDING_PKCS7
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_128_CBC:POLARSSL_PADDING_PKCS7:"ffffffffe00000000000000000000000":"00000000000000000000000000000000":"23f710842b9bb9c32f26648c786807ca":"00000000000000000000000000000000":"":"":POLARSSL_ERR_CIPHER_INVALID_PADDING:0
|
||||
|
||||
AES Decrypt test vector #1
|
||||
depends_on:POLARSSL_AES_C
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_128_CBC:POLARSSL_PADDING_NONE:"ffffffffe00000000000000000000000":"00000000000000000000000000000000":"23f710842b9bb9c32f26648c786807ca":"00000000000000000000000000000000":"":"":0:0
|
||||
|
||||
AES Decrypt test vector #2
|
||||
depends_on:POLARSSL_AES_C
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_192_CBC:POLARSSL_PADDING_NONE:"000000000000000000000000000000000000000000000000":"00000000000000000000000000000000":"707b1dbb0ffa40ef7d95def421233fae":"fffffffff80000000000000000000000":"":"":0:0
|
||||
|
||||
AES Decrypt test vector #3
|
||||
depends_on:POLARSSL_AES_C
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_256_CBC:POLARSSL_PADDING_NONE:"0000000000000000000000000000000000000000000000000000000000000000":"00000000000000000000000000000000":"49af6b372135acef10132e548f217b17":"ff000000000000000000000000000000":"":"":0:0
|
||||
|
||||
AES Decrypt test vector #4
|
||||
depends_on:POLARSSL_AES_C:POLARSSL_CIPHER_MODE_CFB
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_128_CFB128:-1:"fffffffe000000000000000000000000":"00000000000000000000000000000000":"1114bc2028009b923f0b01915ce5e7c4":"00000000000000000000000000000000":"":"":0:0:
|
||||
|
||||
AES Decrypt test vector #5
|
||||
depends_on:POLARSSL_AES_C:POLARSSL_CIPHER_MODE_CFB
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_192_CFB128:-1:"ffffffffffffffffffffffffffffffffffffffffffe00000":"00000000000000000000000000000000":"60136703374f64e860b48ce31f930716":"00000000000000000000000000000000":"":"":0:0
|
||||
|
||||
AES Decrypt test vector #6
|
||||
depends_on:POLARSSL_AES_C:POLARSSL_CIPHER_MODE_CFB
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_128_CFB128:-1:"ffffffffff800000000000000000000000000000000000000000000000000000":"00000000000000000000000000000000":"be66cfea2fecd6bf0ec7b4352c99bcaa":"00000000000000000000000000000000":"":"":0:0
|
||||
|
|
|
@ -301,6 +301,73 @@ void enc_dec_buf_multipart( int cipher_id, int key_len, int first_length_val,
|
|||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void decrypt_test_vec( int cipher_id, int pad_mode,
|
||||
char *hex_key, char *hex_iv,
|
||||
char *hex_cipher, char *hex_clear,
|
||||
char *hex_ad, char *hex_tag,
|
||||
int finish_result, int tag_result )
|
||||
{
|
||||
unsigned char key[100];
|
||||
unsigned char iv[100];
|
||||
unsigned char cipher[100];
|
||||
unsigned char clear[100];
|
||||
unsigned char ad[100];
|
||||
unsigned char tag[100];
|
||||
size_t key_len, iv_len, cipher_len, clear_len, ad_len, tag_len;
|
||||
cipher_context_t ctx;
|
||||
unsigned char output[100];
|
||||
size_t outlen, total_len;
|
||||
|
||||
memset( key, 0x00, sizeof( key ) );
|
||||
memset( iv, 0x00, sizeof( iv ) );
|
||||
memset( cipher, 0x00, sizeof( cipher ) );
|
||||
memset( clear, 0x00, sizeof( clear ) );
|
||||
memset( ad, 0x00, sizeof( ad ) );
|
||||
memset( tag, 0x00, sizeof( tag ) );
|
||||
memset( output, 0x00, sizeof( output ) );
|
||||
|
||||
key_len = unhexify( key, hex_key );
|
||||
iv_len = unhexify( iv, hex_iv );
|
||||
cipher_len = unhexify( cipher, hex_cipher );
|
||||
clear_len = unhexify( clear, hex_clear );
|
||||
ad_len = unhexify( ad, hex_ad );
|
||||
tag_len = unhexify( tag, hex_tag );
|
||||
|
||||
/* Prepare context */
|
||||
TEST_ASSERT( 0 == cipher_init_ctx( &ctx,
|
||||
cipher_info_from_type( cipher_id ) ) );
|
||||
TEST_ASSERT( 0 == cipher_setkey( &ctx, key, 8 * key_len, POLARSSL_DECRYPT ) );
|
||||
if( pad_mode != -1 )
|
||||
TEST_ASSERT( 0 == cipher_set_padding_mode( &ctx, pad_mode ) );
|
||||
TEST_ASSERT( 0 == cipher_set_iv( &ctx, iv, iv_len ) );
|
||||
TEST_ASSERT( 0 == cipher_reset( &ctx ) );
|
||||
#if defined(POLARSSL_CIPHER_MODE_AEAD)
|
||||
TEST_ASSERT( 0 == cipher_update_ad( &ctx, ad, ad_len ) );
|
||||
#endif /* POLARSSL_CIPHER_MODE_AEAD */
|
||||
|
||||
/* decode buffer and check tag */
|
||||
total_len = 0;
|
||||
TEST_ASSERT( 0 == cipher_update( &ctx, cipher, cipher_len, output, &outlen ) );
|
||||
total_len += outlen;
|
||||
TEST_ASSERT( finish_result == cipher_finish( &ctx, output + outlen,
|
||||
&outlen ) );
|
||||
total_len += outlen;
|
||||
#if defined(POLARSSL_CIPHER_MODE_AEAD)
|
||||
TEST_ASSERT( tag_result == cipher_check_tag( &ctx, tag, tag_len ) );
|
||||
#endif /* POLARSSL_CIPHER_MODE_AEAD */
|
||||
|
||||
/* check plaintext only if everything went fine */
|
||||
if( 0 == finish_result && 0 == tag_result )
|
||||
{
|
||||
TEST_ASSERT( total_len == clear_len );
|
||||
TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) );
|
||||
}
|
||||
|
||||
cipher_free_ctx( &ctx );
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void set_padding( int cipher_id, int pad_mode, int ret )
|
||||
{
|
||||
|
|
|
@ -108,3 +108,7 @@ enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_GCM:128:17:6
|
|||
AES 128 GCM Encrypt and decrypt 32 bytes in multiple parts 1
|
||||
depends_on:POLARSSL_AES_C:POLARSSL_GCM_C
|
||||
enc_dec_buf_multipart:POLARSSL_CIPHER_AES_128_GCM:128:16:16
|
||||
|
||||
AES 128 GCM Decrypt test vector #1
|
||||
depends_on:POLARSSL_AES_C:POLARSSL_GCM_C
|
||||
decrypt_test_vec:POLARSSL_CIPHER_AES_128_CBC:-1:"d785dafea3e966731ef6fc6202262584":"d91a46205ee94058b3b8403997592dd2":"":"":"3b92a17c1b9c3578a68cffea5a5b6245":0:0
|
||||
|
|
Loading…
Reference in a new issue