updates.
authorPekka Riikonen <priikone@silcnet.org>
Tue, 1 Oct 2002 20:10:19 +0000 (20:10 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Tue, 1 Oct 2002 20:10:19 +0000 (20:10 +0000)
lib/silccrypt/tests/inst_aes
lib/silccrypt/tests/test_aes.c

index 67855a35cf02c7fd38527706c0c638c4554482fb..e68d7620b4df25a883d68794f994988a92b90d2a 100644 (file)
@@ -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
 
index 7f7d81bca056f7ecf3ff3b3abe6bdf8eb471585c..3a37d36c4901eddbc1ca5adc2cf1c8add85e56b2 100644 (file)
@@ -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]);
        }