380
|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis |
|
2 * |
|
3 * LibTomCrypt is a library that provides various cryptographic |
|
4 * algorithms in a highly modular and flexible manner. |
|
5 * |
|
6 * The library is free for all purposes without any express |
|
7 * guarantee it works. |
|
8 * |
|
9 * Tom St Denis, [email protected], http://libtomcrypt.com |
|
10 */ |
|
11 #include "tomcrypt.h" |
|
12 |
|
13 /** |
|
14 @file ctr_test.c |
|
15 CTR implementation, Tests again RFC 3686, Tom St Denis |
|
16 */ |
|
17 |
|
18 #ifdef LTC_CTR_MODE |
|
19 |
|
20 int ctr_test(void) |
|
21 { |
|
22 #ifdef LTC_NO_TEST |
|
23 return CRYPT_NOP; |
|
24 #else |
|
25 static const struct { |
|
26 int keylen, msglen; |
|
27 unsigned char key[32], IV[16], pt[64], ct[64]; |
|
28 } tests[] = { |
|
29 /* 128-bit key, 16-byte pt */ |
|
30 { |
|
31 16, 16, |
|
32 {0xAE,0x68,0x52,0xF8,0x12,0x10,0x67,0xCC,0x4B,0xF7,0xA5,0x76,0x55,0x77,0xF3,0x9E }, |
|
33 {0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, |
|
34 {0x53,0x69,0x6E,0x67,0x6C,0x65,0x20,0x62,0x6C,0x6F,0x63,0x6B,0x20,0x6D,0x73,0x67 }, |
|
35 {0xE4,0x09,0x5D,0x4F,0xB7,0xA7,0xB3,0x79,0x2D,0x61,0x75,0xA3,0x26,0x13,0x11,0xB8 }, |
|
36 }, |
|
37 |
|
38 /* 128-bit key, 36-byte pt */ |
|
39 { |
|
40 16, 36, |
|
41 {0x76,0x91,0xBE,0x03,0x5E,0x50,0x20,0xA8,0xAC,0x6E,0x61,0x85,0x29,0xF9,0xA0,0xDC }, |
|
42 {0x00,0xE0,0x01,0x7B,0x27,0x77,0x7F,0x3F,0x4A,0x17,0x86,0xF0,0x00,0x00,0x00,0x00 }, |
|
43 {0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F, |
|
44 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F, |
|
45 0x20,0x21,0x22,0x23}, |
|
46 {0xC1,0xCF,0x48,0xA8,0x9F,0x2F,0xFD,0xD9,0xCF,0x46,0x52,0xE9,0xEF,0xDB,0x72,0xD7, |
|
47 0x45,0x40,0xA4,0x2B,0xDE,0x6D,0x78,0x36,0xD5,0x9A,0x5C,0xEA,0xAE,0xF3,0x10,0x53, |
|
48 0x25,0xB2,0x07,0x2F }, |
|
49 }, |
|
50 }; |
|
51 int idx, err, x; |
|
52 unsigned char buf[64]; |
|
53 symmetric_CTR ctr; |
|
54 |
|
55 /* AES can be under rijndael or aes... try to find it */ |
|
56 if ((idx = find_cipher("aes")) == -1) { |
|
57 if ((idx = find_cipher("rijndael")) == -1) { |
|
58 return CRYPT_NOP; |
|
59 } |
|
60 } |
|
61 |
|
62 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { |
|
63 if ((err = ctr_start(idx, tests[x].IV, tests[x].key, tests[x].keylen, 0, CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686, &ctr)) != CRYPT_OK) { |
|
64 return err; |
|
65 } |
|
66 if ((err = ctr_encrypt(tests[x].pt, buf, tests[x].msglen, &ctr)) != CRYPT_OK) { |
|
67 return err; |
|
68 } |
|
69 ctr_done(&ctr); |
|
70 if (XMEMCMP(buf, tests[x].ct, tests[x].msglen)) { |
|
71 return CRYPT_FAIL_TESTVECTOR; |
|
72 } |
|
73 } |
|
74 return CRYPT_OK; |
|
75 #endif |
|
76 } |
|
77 |
|
78 #endif |
|
79 |
|
80 /* $Source: /cvs/libtom/libtomcrypt/src/modes/ctr/ctr_test.c,v $ */ |
|
81 /* $Revision: 1.3 $ */ |
|
82 /* $Date: 2006/11/05 02:06:49 $ */ |
|
83 |
|
84 |
|
85 |