You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

101 lines
4.0 KiB

  1. #include "aes.h"
  2. #include <stdio.h>
  3. #include <string.h>
  4. const unsigned char msg[48] = "The quick brown fox jumps over the lazy dog!!!!";
  5. const unsigned char stream128[67] = {
  6. 0x36, 0x88, 0x7b, 0x28, 0x99, 0x8f, 0x4d, 0x2b, 0x37, 0xff, 0x06, 0x63, 0xfc, 0x5c, 0xef, 0x2f,
  7. 0x43, 0xeb, 0xeb, 0x7e, 0xc1, 0x58, 0xe4, 0xb4, 0x27, 0x78, 0x2e, 0xa7, 0x90, 0x00, 0x09, 0x91,
  8. 0xcd, 0x0e, 0x40, 0x18, 0x8b, 0x2b, 0x52, 0x1e, 0x8d, 0xfb, 0x0e, 0x7b, 0x80, 0xe7, 0xb6, 0xd4,
  9. 0xba, 0x48, 0xf5, 0x19, 0xb4, 0xbf, 0xbf, 0xb1, 0x52, 0x6f, 0x12, 0xe2, 0x7b, 0x61, 0x90, 0x0d,
  10. 0x95, 0x83, 0x84};
  11. const unsigned char stream192[67] = {
  12. 0xb0, 0x13, 0x08, 0x01, 0xfa, 0x88, 0x28, 0x98, 0xac, 0x77, 0x72, 0xaf, 0x2a, 0x8d, 0x17, 0xf3,
  13. 0xba, 0x37, 0xd6, 0x8e, 0x01, 0x5b, 0x25, 0xb5, 0x51, 0x40, 0xf9, 0x55, 0x73, 0x89, 0xbe, 0xd3,
  14. 0x5f, 0x3c, 0xde, 0xc2, 0x6b, 0xf6, 0xfc, 0x26, 0x97, 0x22, 0xfa, 0x8e, 0xcb, 0x62, 0xe8, 0xa5,
  15. 0x03, 0xd2, 0x8a, 0x7e, 0xaf, 0xe3, 0xe5, 0x63, 0x2e, 0xb8, 0x48, 0x20, 0x1c, 0x48, 0xd5, 0xc2,
  16. 0x27, 0x1e, 0x1e};
  17. const unsigned char stream256[67] = {
  18. 0x12, 0x39, 0x28, 0xd0, 0xda, 0xd1, 0xfd, 0xe7, 0x64, 0x74, 0x10, 0x5a, 0x29, 0x17, 0x3c, 0x62,
  19. 0x05, 0xde, 0x4c, 0x98, 0x22, 0x9b, 0xad, 0x16, 0x32, 0x75, 0xbf, 0x26, 0xe5, 0x84, 0x7e, 0xc8,
  20. 0x4e, 0x73, 0x68, 0xce, 0x9a, 0x11, 0xb6, 0x55, 0x53, 0x05, 0x39, 0xa1, 0xa7, 0x1f, 0x16, 0x55,
  21. 0x4a, 0xd3, 0x6c, 0xc6, 0x2c, 0xb4, 0x55, 0x9f, 0x5f, 0xa3, 0xe8, 0x39, 0xfa, 0x9d, 0x96, 0xb6,
  22. 0xb7, 0xc9, 0xc5};
  23. const unsigned char ct128[48] = {
  24. 0x10, 0xdc, 0x43, 0x2b, 0x15, 0x11, 0x81, 0x36, 0x3f, 0x00, 0x51, 0x74, 0x81, 0x7c, 0x22, 0x87,
  25. 0x3a, 0x3b, 0xfe, 0xd7, 0xb9, 0xa6, 0xf2, 0x3c, 0x81, 0x00, 0x63, 0xef, 0xe5, 0xb8, 0xbd, 0x36,
  26. 0x11, 0xcc, 0xc9, 0xdf, 0x2b, 0xea, 0xbc, 0xe6, 0x11, 0x1c, 0x34, 0x79, 0xf9, 0x6b, 0x47, 0x7b};
  27. const unsigned char ct192[48] = {
  28. 0x63, 0xc6, 0xde, 0x28, 0x36, 0xb4, 0x29, 0xbf, 0xbe, 0x9d, 0x15, 0x8e, 0x83, 0x04, 0xa3, 0x18,
  29. 0x34, 0x79, 0xe8, 0x02, 0x8a, 0x34, 0x50, 0x7c, 0xa9, 0x08, 0x48, 0x47, 0xee, 0x90, 0x79, 0x13,
  30. 0x66, 0x2d, 0xa4, 0xf1, 0x3e, 0x8b, 0x76, 0xa9, 0x50, 0xf7, 0x6e, 0xa8, 0xbf, 0x29, 0xaf, 0x84};
  31. const unsigned char ct256[48] = {
  32. 0xdb, 0xb5, 0x44, 0x70, 0x68, 0xe6, 0xad, 0x6a, 0x09, 0xdf, 0xa6, 0xef, 0x85, 0x73, 0xff, 0xc0,
  33. 0xc2, 0x91, 0x38, 0xbd, 0xd7, 0xd0, 0x22, 0x7e, 0x79, 0x71, 0xa1, 0x98, 0x6f, 0xd5, 0x80, 0xa8,
  34. 0x1e, 0x97, 0xd7, 0x6d, 0xd2, 0x6b, 0x0e, 0x7b, 0x79, 0x76, 0x75, 0x86, 0xa5, 0x2f, 0x76, 0x0b};
  35. const unsigned char key[AES256_KEYBYTES] = {
  36. 0x66, 0xd9, 0xb7, 0x60, 0x0e, 0xda, 0xaa, 0x81, 0x42, 0xa2, 0xd6, 0x3d, 0x8f, 0x51, 0x6c, 0x6f,
  37. 0xb6, 0xdf, 0x5b, 0x97, 0xf3, 0xf1, 0xf7, 0x0e, 0xeb, 0xe0, 0x40, 0x4d, 0xc5, 0x24, 0xa1, 0xfa};
  38. const unsigned char nonce[AESCTR_NONCEBYTES] = {
  39. 0x9d, 0x2d, 0x3e, 0x6e, 0x48, 0x5c, 0xf6, 0x6b, 0xb2, 0xb9, 0x25, 0xf4};
  40. int main(void)
  41. {
  42. unsigned char ct[67];
  43. int r = 0;
  44. aes128ctx ctx128;
  45. aes192ctx ctx192;
  46. aes256ctx ctx256;
  47. aes128_keyexp(&ctx128, key);
  48. aes192_keyexp(&ctx192, key);
  49. aes256_keyexp(&ctx256, key);
  50. aes128_ctr(ct, 67, nonce, &ctx128);
  51. if(memcmp(ct, stream128, 67)) {
  52. printf("ERROR AES128CTR output does not match test vector.\n");
  53. r = 1;
  54. }
  55. aes192_ctr(ct, 67, nonce, &ctx192);
  56. if(memcmp(ct, stream192, 67)) {
  57. printf("ERROR AES192CTR output does not match test vector.\n");
  58. r = 1;
  59. }
  60. aes256_ctr(ct, 67, nonce, &ctx256);
  61. if(memcmp(ct, stream256, 67)) {
  62. printf("ERROR AES256CTR output does not match test vector.\n");
  63. r = 1;
  64. }
  65. aes128_ecb(ct, msg, sizeof(msg) / AES_BLOCKBYTES, &ctx128);
  66. if(memcmp(ct, ct128, 48)) {
  67. printf("ERROR AES128ECB output does not match test vector.\n");
  68. r = 1;
  69. }
  70. aes192_ecb(ct, msg, sizeof(msg) / AES_BLOCKBYTES, &ctx192);
  71. if(memcmp(ct, ct192, 48)) {
  72. printf("ERROR AES192ECB output does not match test vector.\n");
  73. r = 1;
  74. }
  75. aes256_ecb(ct, msg, sizeof(msg) / AES_BLOCKBYTES, &ctx256);
  76. if(memcmp(ct, ct256, 48)) {
  77. printf("ERROR AES256ECB output does not match test vector.\n");
  78. r = 1;
  79. }
  80. return r;
  81. }