From 142383e25b4330ad7e77f2aab2166bc7c8e6337c Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Thu, 31 May 2018 10:40:34 +0100 Subject: [PATCH] aes: xts: Add tests for invalid key sizes Test that we get the error we expect when using various valid and invalid keysizes with mbedtls_aes_xts_setkey_enc() and mbedtls_aes_xts_setkey_dec(). --- tests/suites/test_suite_aes.function | 15 +++++++++++++++ tests/suites/test_suite_aes.xts.data | 15 +++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function index aec4a493d..e346dc7c3 100644 --- a/tests/suites/test_suite_aes.function +++ b/tests/suites/test_suite_aes.function @@ -258,6 +258,21 @@ void aes_crypt_xts_size( int size, int retval ) } /* END_CASE */ +/* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_XTS */ +void aes_crypt_xts_keysize( int size, int retval ) +{ + mbedtls_aes_xts_context ctx; + const unsigned char *key = NULL; + size_t key_len = size; + + mbedtls_aes_xts_init( &ctx ); + + TEST_ASSERT( mbedtls_aes_xts_setkey_enc( &ctx, key, key_len * 8 ) == retval ); + TEST_ASSERT( mbedtls_aes_xts_setkey_dec( &ctx, key, key_len * 8 ) == retval ); +exit: + mbedtls_aes_xts_free( &ctx ); +} +/* END_CASE */ /* BEGIN_CASE depends_on:MBEDTLS_CIPHER_MODE_CFB */ diff --git a/tests/suites/test_suite_aes.xts.data b/tests/suites/test_suite_aes.xts.data index a0a662685..6af5227d9 100644 --- a/tests/suites/test_suite_aes.xts.data +++ b/tests/suites/test_suite_aes.xts.data @@ -13,6 +13,21 @@ aes_crypt_xts_size:16777217:MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH AES-128-XTS Encrypt Fail Sector Too Large (by 1 block) aes_crypt_xts_size:16777232:MBEDTLS_ERR_AES_INVALID_INPUT_LENGTH +AES-0-XTS Setkey Fail Invalid Key Length +aes_crypt_xts_keysize:0:MBEDTLS_ERR_AES_INVALID_KEY_LENGTH + +AES-4-XTS Setkey Fail Invalid Key Length +aes_crypt_xts_keysize:1:MBEDTLS_ERR_AES_INVALID_KEY_LENGTH + +AES-64-XTS Setkey Fail Invalid Key Length +aes_crypt_xts_keysize:16:MBEDTLS_ERR_AES_INVALID_KEY_LENGTH + +AES-192-XTS Setkey Fail Invalid Key Length +aes_crypt_xts_keysize:48:MBEDTLS_ERR_AES_INVALID_KEY_LENGTH + +AES-384-XTS Setkey Fail Invalid Key Length +aes_crypt_xts_keysize:96:MBEDTLS_ERR_AES_INVALID_KEY_LENGTH + AES-128-XTS Encrypt NIST XTSTestVectors #1 aes_encrypt_xts:"a1b90cba3f06ac353b2c343876081762090923026e91771815f29dab01932f2f":"4faef7117cda59c66e4b92013e768ad5":"ebabce95b14d3c8d6fb350390790311c":"778ae8b43cb98d5a825081d5be471c63"