Mercurial > dropbear
comparison libtomcrypt/src/encauth/ccm/ccm_test.c @ 285:1b9e69c058d2
propagate from branch 'au.asn.ucc.matt.ltc.dropbear' (head 20dccfc09627970a312d77fb41dc2970b62689c3)
to branch 'au.asn.ucc.matt.dropbear' (head fdf4a7a3b97ae5046139915de7e40399cceb2c01)
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 08 Mar 2006 13:23:58 +0000 |
parents | |
children | 0cbe8f6dbf9e |
comparison
equal
deleted
inserted
replaced
281:997e6f7dc01e | 285:1b9e69c058d2 |
---|---|
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.org | |
10 */ | |
11 #include "tomcrypt.h" | |
12 | |
13 /** | |
14 @file ccm_test.c | |
15 CCM support, process a block of memory, Tom St Denis | |
16 */ | |
17 | |
18 #ifdef CCM_MODE | |
19 | |
20 int ccm_test(void) | |
21 { | |
22 #ifndef LTC_TEST | |
23 return CRYPT_NOP; | |
24 #else | |
25 static const struct { | |
26 unsigned char key[16]; | |
27 unsigned char nonce[16]; | |
28 int noncelen; | |
29 unsigned char header[64]; | |
30 int headerlen; | |
31 unsigned char pt[64]; | |
32 int ptlen; | |
33 unsigned char ct[64]; | |
34 unsigned char tag[16]; | |
35 int taglen; | |
36 } tests[] = { | |
37 | |
38 /* 13 byte nonce, 8 byte auth, 23 byte pt */ | |
39 { | |
40 { 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, | |
41 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF }, | |
42 { 0x00, 0x00, 0x00, 0x03, 0x02, 0x01, 0x00, 0xA0, | |
43 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }, | |
44 13, | |
45 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, | |
46 8, | |
47 { 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, | |
48 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, | |
49 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E }, | |
50 23, | |
51 { 0x58, 0x8C, 0x97, 0x9A, 0x61, 0xC6, 0x63, 0xD2, | |
52 0xF0, 0x66, 0xD0, 0xC2, 0xC0, 0xF9, 0x89, 0x80, | |
53 0x6D, 0x5F, 0x6B, 0x61, 0xDA, 0xC3, 0x84 }, | |
54 { 0x17, 0xe8, 0xd1, 0x2c, 0xfd, 0xf9, 0x26, 0xe0 }, | |
55 8 | |
56 }, | |
57 | |
58 /* 13 byte nonce, 12 byte header, 19 byte pt */ | |
59 { | |
60 { 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, | |
61 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF }, | |
62 { 0x00, 0x00, 0x00, 0x06, 0x05, 0x04, 0x03, 0xA0, | |
63 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }, | |
64 13, | |
65 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, | |
66 0x08, 0x09, 0x0A, 0x0B }, | |
67 12, | |
68 { 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, | |
69 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, | |
70 0x1C, 0x1D, 0x1E }, | |
71 19, | |
72 { 0xA2, 0x8C, 0x68, 0x65, 0x93, 0x9A, 0x9A, 0x79, | |
73 0xFA, 0xAA, 0x5C, 0x4C, 0x2A, 0x9D, 0x4A, 0x91, | |
74 0xCD, 0xAC, 0x8C }, | |
75 { 0x96, 0xC8, 0x61, 0xB9, 0xC9, 0xE6, 0x1E, 0xF1 }, | |
76 8 | |
77 }, | |
78 | |
79 /* supplied by Brian Gladman */ | |
80 { | |
81 { 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, | |
82 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f }, | |
83 { 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16 }, | |
84 7, | |
85 { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07 }, | |
86 8, | |
87 { 0x20, 0x21, 0x22, 0x23 }, | |
88 4, | |
89 { 0x71, 0x62, 0x01, 0x5b }, | |
90 { 0x4d, 0xac, 0x25, 0x5d }, | |
91 4 | |
92 }, | |
93 | |
94 { | |
95 { 0xc9, 0x7c, 0x1f, 0x67, 0xce, 0x37, 0x11, 0x85, | |
96 0x51, 0x4a, 0x8a, 0x19, 0xf2, 0xbd, 0xd5, 0x2f }, | |
97 { 0x00, 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0xb5, | |
98 0x03, 0x97, 0x76, 0xe7, 0x0c }, | |
99 13, | |
100 { 0x08, 0x40, 0x0f, 0xd2, 0xe1, 0x28, 0xa5, 0x7c, | |
101 0x50, 0x30, 0xf1, 0x84, 0x44, 0x08, 0xab, 0xae, | |
102 0xa5, 0xb8, 0xfc, 0xba, 0x00, 0x00 }, | |
103 22, | |
104 { 0xf8, 0xba, 0x1a, 0x55, 0xd0, 0x2f, 0x85, 0xae, | |
105 0x96, 0x7b, 0xb6, 0x2f, 0xb6, 0xcd, 0xa8, 0xeb, | |
106 0x7e, 0x78, 0xa0, 0x50 }, | |
107 20, | |
108 { 0xf3, 0xd0, 0xa2, 0xfe, 0x9a, 0x3d, 0xbf, 0x23, | |
109 0x42, 0xa6, 0x43, 0xe4, 0x32, 0x46, 0xe8, 0x0c, | |
110 0x3c, 0x04, 0xd0, 0x19 }, | |
111 { 0x78, 0x45, 0xce, 0x0b, 0x16, 0xf9, 0x76, 0x23 }, | |
112 8 | |
113 }, | |
114 | |
115 }; | |
116 unsigned long taglen, x; | |
117 unsigned char buf[64], buf2[64], tag2[16], tag[16]; | |
118 int err, idx; | |
119 | |
120 idx = find_cipher("aes"); | |
121 if (idx == -1) { | |
122 idx = find_cipher("rijndael"); | |
123 if (idx == -1) { | |
124 return CRYPT_NOP; | |
125 } | |
126 } | |
127 | |
128 for (x = 0; x < (sizeof(tests)/sizeof(tests[0])); x++) { | |
129 taglen = tests[x].taglen; | |
130 if ((err = ccm_memory(idx, | |
131 tests[x].key, 16, | |
132 tests[x].nonce, tests[x].noncelen, | |
133 tests[x].header, tests[x].headerlen, | |
134 (unsigned char*)tests[x].pt, tests[x].ptlen, | |
135 buf, | |
136 tag, &taglen, 0)) != CRYPT_OK) { | |
137 return err; | |
138 } | |
139 | |
140 if (memcmp(buf, tests[x].ct, tests[x].ptlen)) { | |
141 return CRYPT_FAIL_TESTVECTOR; | |
142 } | |
143 if (memcmp(tag, tests[x].tag, tests[x].taglen)) { | |
144 return CRYPT_FAIL_TESTVECTOR; | |
145 } | |
146 | |
147 if ((err = ccm_memory(idx, | |
148 tests[x].key, 16, | |
149 tests[x].nonce, tests[x].noncelen, | |
150 tests[x].header, tests[x].headerlen, | |
151 buf2, tests[x].ptlen, | |
152 buf, | |
153 tag2, &taglen, 1 )) != CRYPT_OK) { | |
154 return err; | |
155 } | |
156 | |
157 if (memcmp(buf2, tests[x].pt, tests[x].ptlen)) { | |
158 return CRYPT_FAIL_TESTVECTOR; | |
159 } | |
160 if (memcmp(tag2, tests[x].tag, tests[x].taglen)) { | |
161 return CRYPT_FAIL_TESTVECTOR; | |
162 } | |
163 | |
164 | |
165 } | |
166 return CRYPT_OK; | |
167 #endif | |
168 } | |
169 | |
170 #endif | |
171 | |
172 /* $Source: /cvs/libtom/libtomcrypt/src/encauth/ccm/ccm_test.c,v $ */ | |
173 /* $Revision: 1.4 $ */ | |
174 /* $Date: 2005/05/05 14:35:58 $ */ |