diff options
author | Niels Möller <nisse@lysator.liu.se> | 2010-07-24 18:10:47 +0200 |
---|---|---|
committer | Niels Möller <nisse@lysator.liu.se> | 2010-07-24 18:10:47 +0200 |
commit | ca7f0bb766364642933ed103c1153cae4b8d708b (patch) | |
tree | 9b396c18595a07736c88af4a74acea67dec00410 /testsuite/aes-test.c | |
parent | c0371ee1b4224c0dd58b9343a2f6163ed3dcbf8e (diff) | |
download | nettle-ca7f0bb766364642933ed103c1153cae4b8d708b.tar.gz |
* testsuite/camellia-test.c: New tests for camellia_invert_key.
* testsuite/aes-test.c: New tests for aes_invert_key.
Rev: nettle/testsuite/aes-test.c:1.2
Rev: nettle/testsuite/camellia-test.c:1.2
Diffstat (limited to 'testsuite/aes-test.c')
-rw-r--r-- | testsuite/aes-test.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/testsuite/aes-test.c b/testsuite/aes-test.c index f9916653..87be8063 100644 --- a/testsuite/aes-test.c +++ b/testsuite/aes-test.c @@ -1,6 +1,47 @@ #include "testutils.h" #include "aes.h" +static void +test_invert(unsigned key_length, const uint8_t *key, + unsigned length, const uint8_t *cleartext, + const uint8_t *ciphertext) +{ + struct aes_ctx encrypt; + struct aes_ctx decrypt; + uint8_t *data = xalloc(length); + + aes_set_encrypt_key (&encrypt, key_length, key); + aes_encrypt (&encrypt, length, data, cleartext); + + if (!MEMEQ(length, data, ciphertext)) + { + fprintf(stderr, "test_invert: Encrypt failed:\nInput:"); + print_hex(length, cleartext); + fprintf(stderr, "\nOutput: "); + print_hex(length, data); + fprintf(stderr, "\nExpected:"); + print_hex(length, ciphertext); + fprintf(stderr, "\n"); + FAIL(); + } + + aes_invert_key (&decrypt, &encrypt); + aes_decrypt (&decrypt, length, data, data); + + if (!MEMEQ(length, data, cleartext)) + { + fprintf(stderr, "test_invert: Decrypt failed:\nInput:"); + print_hex(length, ciphertext); + fprintf(stderr, "\nOutput: "); + print_hex(length, data); + fprintf(stderr, "\nExpected:"); + print_hex(length, cleartext); + fprintf(stderr, "\n"); + FAIL(); + } + free (data); +} + int test_main(void) { @@ -41,6 +82,7 @@ test_main(void) HL("834EADFCCAC7E1B30664B1ABA44815AB"), H("1946DABF6A03A2A2 C3D0B05080AED6FC")); + /* This test case has been problematic with the CBC test case */ test_cipher(&nettle_aes256, HL("8d ae 93 ff fc 78 c9 44" @@ -96,6 +138,19 @@ test_main(void) "b6ed21b99ca6f4f9f153e7b1beafed1d" "23304b7a39f9f3ff067d8d8f9e24ecc7")); + /* Test aes_invert_key with src != dst */ + test_invert(HL("0001020305060708 0A0B0C0D0F101112"), + HL("506812A45F08C889 B97F5980038B8359"), + H("D8F532538289EF7D 06B506A4FD5BE9C9")); + test_invert(HL("0001020305060708 0A0B0C0D0F101112" + "14151617191A1B1C"), + HL("2D33EEF2C0430A8A 9EBF45E809C40BB6"), + H("DFF4945E0336DF4C 1C56BC700EFF837F")); + test_invert(HL("0001020305060708 0A0B0C0D0F101112" + "14151617191A1B1C 1E1F202123242526"), + HL("834EADFCCAC7E1B30664B1ABA44815AB"), + H("1946DABF6A03A2A2 C3D0B05080AED6FC")); + SUCCESS(); } |