#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)
{
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"
"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();
}
#include "testutils.h"
#include "camellia.h"
+static void
+test_invert(unsigned key_length, const uint8_t *key,
+ unsigned length, const uint8_t *cleartext,
+ const uint8_t *ciphertext)
+{
+ struct camellia_ctx encrypt;
+ struct camellia_ctx decrypt;
+ uint8_t *data = xalloc(length);
+
+ camellia_set_encrypt_key (&encrypt, key_length, key);
+ camellia_crypt (&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();
+ }
+
+ camellia_invert_key (&decrypt, &encrypt);
+ camellia_crypt (&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)
{
HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
H("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09"));
+ /* Test camellia_invert_key with src != dst */
+ test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
+ HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
+ H("67 67 31 38 54 96 69 73 08 57 06 56 48 ea be 43"));
+
+ test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
+ "00 11 22 33 44 55 66 77"),
+ HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
+ H("b4 99 34 01 b3 e9 96 f8 4e e5 ce e7 d7 9b 09 b9"));
+
+ test_invert(HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"
+ "00 11 22 33 44 55 66 77 88 99 aa bb cc dd ee ff"),
+ HL("01 23 45 67 89 ab cd ef fe dc ba 98 76 54 32 10"),
+ H("9a cc 23 7d ff 16 d7 6c 20 ef 7c 91 9e 3a 75 09"));
SUCCESS();
}