src/vsl_test_aes.c

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006, Internet2
00003  * Legal conditions are in file LICENSE
00004  * (MD5 = c434f2e53b8089d8b4d0172c7ce07360).
00005  */
00006 
00007 /**
00008  * @file   vsl_test_aes.c
00009  * @author Nikolaus Rath
00010  * @brief  Test AES CTR mode
00011  *
00012  **/
00013 
00014 
00015 #include "vsl_util.h"
00016 #include "vfer_tests.h"
00017 
00018 /**
00019  * main
00020  */
00021 int main (int argc, char** argv) {
00022 
00023     unsigned char plaintext[] = "This is the plaintext.";
00024     unsigned char key[] = "123456789012345";
00025 
00026     TEST_INIT("VSL_TEST_AES", "vsl_test_aes.c", stdout, stdout);
00027 
00028     /* Encrypt */
00029     uint64_t msgnr = htonll(42);
00030     unsigned char ctr[16];
00031     memset((void*) ctr, 0, 16);
00032     memcpy((void*) ctr, (void*) &msgnr, 8);
00033     unsigned char buf[sizeof(plaintext)];
00034     memcpy((void*) buf, (void*) &plaintext, sizeof(plaintext));
00035     aes_ctr(ctr, key, buf, sizeof(plaintext));
00036 
00037     /* Decrypt */
00038     memset((void*) ctr, 0, 16);
00039     memcpy((void*) ctr, (void*) &msgnr, 8);
00040     aes_ctr(ctr, key, buf, sizeof(plaintext));
00041 
00042     TEST_CHECK( (memcmp( (void*) &buf, (void*) &plaintext, sizeof(plaintext)) == 0),
00043                 "decrypted text doesn't agree with plaintext.");
00044 
00045     TEST_SUMMARY();
00046 }
00047 
00048 
00049 /*
00050  * Local Variables:
00051  * compile-command: "cd ..; make vsl_test_aes"
00052  * compilation-search-path: ("..")
00053  * End:
00054  */

Generated on Tue Aug 8 16:07:20 2006 for VFER by  doxygen 1.4.7