mirror of
https://github.com/Mbed-TLS/mbedtls.git
synced 2025-02-04 15:39:53 +00:00
AES context copy test: clean up
Don't use hexcmp to compare binary data. Improve readability. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
parent
148cad134a
commit
d50cfddfd7
@ -468,32 +468,38 @@ void aes_misc_params()
|
||||
/* END_CASE */
|
||||
|
||||
/* BEGIN_CASE */
|
||||
void aes_ecb_copy_context(data_t *key_str, data_t *src_str)
|
||||
void aes_ecb_copy_context(data_t *key, data_t *src)
|
||||
{
|
||||
unsigned char output1[16], output2[16], plain[16];
|
||||
mbedtls_aes_context ctx1, ctx2, ctx3;
|
||||
|
||||
TEST_EQUAL(src->len, 16);
|
||||
|
||||
// Set key and encrypt with original context
|
||||
mbedtls_aes_init(&ctx1);
|
||||
TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx1, key_str->x,
|
||||
key_str->len * 8) == 0);
|
||||
TEST_ASSERT(mbedtls_aes_setkey_enc(&ctx1, key->x,
|
||||
key->len * 8) == 0);
|
||||
TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx1, MBEDTLS_AES_ENCRYPT,
|
||||
src_str->x, output1) == 0);
|
||||
|
||||
src->x, output1) == 0);
|
||||
ctx2 = ctx1;
|
||||
TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx1, key_str->x,
|
||||
key_str->len * 8) == 0);
|
||||
|
||||
// Set key for decryption with original context
|
||||
TEST_ASSERT(mbedtls_aes_setkey_dec(&ctx1, key->x,
|
||||
key->len * 8) == 0);
|
||||
ctx3 = ctx1;
|
||||
|
||||
// Wipe the original context to make sure nothing from it is used
|
||||
memset(&ctx1, 0, sizeof(ctx1));
|
||||
|
||||
// Encrypt and decrypt with copied context
|
||||
// Encrypt with copied context
|
||||
TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx2, MBEDTLS_AES_ENCRYPT,
|
||||
src_str->x, output2) == 0);
|
||||
src->x, output2) == 0);
|
||||
ASSERT_COMPARE(output1, 16, output2, 16);
|
||||
|
||||
// Decrypt with copied context
|
||||
TEST_ASSERT(mbedtls_aes_crypt_ecb(&ctx3, MBEDTLS_AES_DECRYPT,
|
||||
output1, plain) == 0);
|
||||
|
||||
TEST_ASSERT(mbedtls_test_hexcmp(output1, output2, 16, 16) == 0);
|
||||
TEST_ASSERT(mbedtls_test_hexcmp(src_str->x, plain, src_str->len, 16) == 0);
|
||||
ASSERT_COMPARE(src->x, 16, plain, 16);
|
||||
}
|
||||
/* END_CASE */
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user