X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=lib%2Fsilccrypt%2Ftests%2Ftest_aes.c;h=3a37d36c4901eddbc1ca5adc2cf1c8add85e56b2;hb=bc2b75b527cd87c76a9cbe01e9500b8a2d4cc214;hp=7f7d81bca056f7ecf3ff3b3abe6bdf8eb471585c;hpb=32038da9d4bbf1803fc501b2508b16e2d1e0759a;p=silc.git 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]); }