From bc2b75b527cd87c76a9cbe01e9500b8a2d4cc214 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Tue, 1 Oct 2002 20:10:19 +0000 Subject: [PATCH] updates. --- lib/silccrypt/tests/inst_aes | 4 +- lib/silccrypt/tests/test_aes.c | 68 ++++++++++++++++++++++++++++++---- 2 files changed, 63 insertions(+), 9 deletions(-) diff --git a/lib/silccrypt/tests/inst_aes b/lib/silccrypt/tests/inst_aes index 67855a35..e68d7620 100644 --- a/lib/silccrypt/tests/inst_aes +++ b/lib/silccrypt/tests/inst_aes @@ -1,7 +1,7 @@ gcc -I.. \ -I../../../includes -I../../silccore -I../../trq -I../../silcske \ -I../.. -I../../silccore -I../../silcmath -I../../silcutil \ --I../../silcmath/gmp -I../../silcske -I../../silcsim \ --Wall -finline-functions \ +-I../../silcmath/mpi -I../../silcske -I../../silcsim \ +-I../../silcsftp -Wall -finline-functions \ -o test_aes test_aes.c -L../.. -lsilc diff --git a/lib/silccrypt/tests/test_aes.c b/lib/silccrypt/tests/test_aes.c index 7f7d81bc..3a37d36c 100644 --- a/lib/silccrypt/tests/test_aes.c +++ b/lib/silccrypt/tests/test_aes.c @@ -13,6 +13,7 @@ int main() unsigned char cipher[256]; unsigned char iv[256]; void *context; + int len; memset(&key, 0, sizeof(key)); memset(&plain, 0, sizeof(plain)); @@ -23,25 +24,78 @@ int main() context = malloc(silc_aes_context_len()); fprintf(stderr, "\nKey:\n"); - for (i = 0; i < (sizeof(key) / 2); i += 2) { +#if 0 + len = 32; + + for (i = 0; i < len; i += 2) { fprintf(stderr, "%02x%02x ", key[i], key[i+1]); } fprintf(stderr, "\nSetting key\n"); - silc_aes_set_key(context, key, 256); + silc_aes_set_key(context, key, len * 8); fprintf(stderr, "\nPlaintext:\n"); - for (i = 0; i < (sizeof(plain) / 2); i += 2) { + for (i = 0; i < len; i += 2) { plain[i] = i; plain[i+1] = i+1; fprintf(stderr, "%02x%02x ", plain[i], plain[i+1]); } +#else + len = 16; + + key[0] = 0x2b; + key[1] = 0x7e; + key[2] = 0x15; + key[3] = 0x16; + key[4] = 0x28; + key[5] = 0xae; + key[6] = 0xd2; + key[7] = 0xa6; + key[8] = 0xab; + key[9] = 0xf7; + key[10] = 0x15; + key[11] = 0x88; + key[12] = 0x09; + key[13] = 0xcf; + key[14] = 0x4f; + key[15] = 0x3c; + for (i = 0; i < len ; i += 2) { + fprintf(stderr, "%02x%02x ", key[i], key[i+1]); + } + + fprintf(stderr, "\nSetting key\n"); + silc_aes_set_key(context, key, len * 8); + + plain[0] = 0x32; + plain[1] = 0x43; + plain[2] = 0xf6; + plain[3] = 0xa8; + plain[4] = 0x88; + plain[5] = 0x5a; + plain[6] = 0x30; + plain[7] = 0x8d; + plain[8] = 0x31; + plain[9] = 0x31; + plain[10] = 0x98; + plain[11] = 0xa2; + plain[12] = 0xe0; + plain[13] = 0x37; + plain[14] = 0x07; + plain[15] = 0x34; + + fprintf(stderr, "\nPlaintext:\n"); + for (i = 0; i < len; i += 2) { + fprintf(stderr, "%02x%02x ", plain[i], plain[i+1]); + } + +#endif + fprintf(stderr, "\n\nEncrypting\n"); - silc_aes_encrypt_cbc(context, plain, cipher, 256, iv); + silc_aes_encrypt_cbc(context, plain, cipher, len, iv); fprintf(stderr, "Ciphertext:\n"); - for (i = 0; i < (sizeof(cipher)/2); i += 2) { + for (i = 0; i < len; i += 2) { fprintf(stderr, "%02x", cipher[i]); fprintf(stderr, "%02x ", cipher[i+1]); } @@ -49,10 +103,10 @@ int main() memset(&iv, 0, sizeof(iv)); fprintf(stderr, "\n\nDecrypting\n"); - silc_aes_decrypt_cbc(context, cipher, plain2, 256, iv); + silc_aes_decrypt_cbc(context, cipher, plain2, len, iv); fprintf(stderr, "Decryptedtext:\n"); - for (i = 0; i < (sizeof(plain2)/2); i += 2) { + for (i = 0; i < len; i += 2) { fprintf(stderr, "%02x", plain2[i]); fprintf(stderr, "%02x ", plain2[i+1]); } -- 2.24.0