Mercurial > dropbear
comparison libtomcrypt/src/encauth/gcm/gcm_test.c @ 1511:5916af64acd4 fuzz
merge from main
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Sat, 17 Feb 2018 19:29:51 +0800 |
parents | 6dba84798cd5 |
children |
comparison
equal
deleted
inserted
replaced
1457:32f990cc96b1 | 1511:5916af64acd4 |
---|---|
3 * LibTomCrypt is a library that provides various cryptographic | 3 * LibTomCrypt is a library that provides various cryptographic |
4 * algorithms in a highly modular and flexible manner. | 4 * algorithms in a highly modular and flexible manner. |
5 * | 5 * |
6 * The library is free for all purposes without any express | 6 * The library is free for all purposes without any express |
7 * guarantee it works. | 7 * guarantee it works. |
8 * | |
9 * Tom St Denis, [email protected], http://libtom.org | |
10 */ | 8 */ |
11 | 9 |
12 /** | 10 /** |
13 @file gcm_test.c | 11 @file gcm_test.c |
14 GCM implementation, testing, by Tom St Denis | 12 GCM implementation, testing, by Tom St Denis |
15 */ | 13 */ |
16 #include "tomcrypt.h" | 14 #include "tomcrypt.h" |
17 | 15 |
18 #ifdef LTC_GCM_MODE | 16 #ifdef LTC_GCM_MODE |
19 | 17 |
20 /** | 18 /** |
21 Test the GCM code | 19 Test the GCM code |
22 @return CRYPT_OK on success | 20 @return CRYPT_OK on success |
23 */ | 21 */ |
24 int gcm_test(void) | 22 int gcm_test(void) |
25 { | 23 { |
98 }, | 96 }, |
99 | 97 |
100 /* test case #3 */ | 98 /* test case #3 */ |
101 { | 99 { |
102 /* key */ | 100 /* key */ |
103 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | 101 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, |
104 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, | 102 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, |
105 16, | 103 16, |
106 | 104 |
107 /* PT */ | 105 /* PT */ |
108 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | 106 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, |
109 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | 107 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, |
110 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | 108 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, |
111 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | 109 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, |
112 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | 110 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, |
113 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | 111 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, |
114 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | 112 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, |
115 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, }, | 113 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55, }, |
116 64, | 114 64, |
117 | 115 |
118 /* ADATA */ | 116 /* ADATA */ |
119 { 0 }, | 117 { 0 }, |
120 0, | 118 0, |
121 | 119 |
122 /* IV */ | 120 /* IV */ |
123 { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | 121 { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, |
124 0xde, 0xca, 0xf8, 0x88, }, | 122 0xde, 0xca, 0xf8, 0x88, }, |
125 12, | 123 12, |
126 | 124 |
127 /* CT */ | 125 /* CT */ |
128 { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, | 126 { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, |
129 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, | 127 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, |
130 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, | 128 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, |
131 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, | 129 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, |
132 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, | 130 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, |
133 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, | 131 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, |
134 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, | 132 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, |
135 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85, }, | 133 0x3d, 0x58, 0xe0, 0x91, 0x47, 0x3f, 0x59, 0x85, }, |
136 | 134 |
137 /* TAG */ | 135 /* TAG */ |
138 { 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, | 136 { 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6, |
139 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4, } | 137 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4, } |
140 }, | 138 }, |
141 | 139 |
142 /* test case #4 */ | 140 /* test case #4 */ |
143 { | 141 { |
144 /* key */ | 142 /* key */ |
145 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | 143 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, |
146 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, | 144 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, |
147 16, | 145 16, |
148 | 146 |
149 /* PT */ | 147 /* PT */ |
150 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | 148 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, |
151 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | 149 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, |
152 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | 150 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, |
153 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | 151 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, |
154 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | 152 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, |
155 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | 153 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, |
156 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | 154 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, |
157 0xba, 0x63, 0x7b, 0x39, }, | 155 0xba, 0x63, 0x7b, 0x39, }, |
158 60, | 156 60, |
159 | 157 |
160 /* ADATA */ | 158 /* ADATA */ |
161 { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | 159 { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, |
162 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | 160 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, |
163 0xab, 0xad, 0xda, 0xd2, }, | 161 0xab, 0xad, 0xda, 0xd2, }, |
164 20, | 162 20, |
165 | 163 |
166 /* IV */ | 164 /* IV */ |
167 { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, | 165 { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, |
168 0xde, 0xca, 0xf8, 0x88, }, | 166 0xde, 0xca, 0xf8, 0x88, }, |
169 12, | 167 12, |
170 | 168 |
171 /* CT */ | 169 /* CT */ |
172 { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, | 170 { 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, |
173 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, | 171 0x4b, 0x72, 0x21, 0xb7, 0x84, 0xd0, 0xd4, 0x9c, |
174 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, | 172 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0, |
175 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, | 173 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, |
176 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, | 174 0x21, 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, |
177 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, | 175 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05, |
178 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, | 176 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, |
179 0x3d, 0x58, 0xe0, 0x91, }, | 177 0x3d, 0x58, 0xe0, 0x91, }, |
180 | 178 |
181 /* TAG */ | 179 /* TAG */ |
182 { 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, | 180 { 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21, 0xa5, 0xdb, |
183 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47, } | 181 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47, } |
184 | 182 |
185 }, | 183 }, |
186 | 184 |
187 /* test case #5 */ | 185 /* test case #5 */ |
188 { | 186 { |
189 /* key */ | 187 /* key */ |
190 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | 188 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, |
191 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, | 189 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, |
192 16, | 190 16, |
193 | 191 |
194 /* PT */ | 192 /* PT */ |
195 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | 193 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, |
196 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | 194 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, |
197 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | 195 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, |
198 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | 196 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, |
199 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | 197 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, |
200 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | 198 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, |
201 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | 199 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, |
202 0xba, 0x63, 0x7b, 0x39, }, | 200 0xba, 0x63, 0x7b, 0x39, }, |
203 60, | 201 60, |
204 | 202 |
205 /* ADATA */ | 203 /* ADATA */ |
206 { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | 204 { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, |
207 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | 205 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, |
208 0xab, 0xad, 0xda, 0xd2, }, | 206 0xab, 0xad, 0xda, 0xd2, }, |
209 20, | 207 20, |
210 | 208 |
211 /* IV */ | 209 /* IV */ |
212 { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, }, | 210 { 0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce, 0xdb, 0xad, }, |
213 8, | 211 8, |
214 | 212 |
215 /* CT */ | 213 /* CT */ |
216 { 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, | 214 { 0x61, 0x35, 0x3b, 0x4c, 0x28, 0x06, 0x93, 0x4a, |
217 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, | 215 0x77, 0x7f, 0xf5, 0x1f, 0xa2, 0x2a, 0x47, 0x55, |
218 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8, | 216 0x69, 0x9b, 0x2a, 0x71, 0x4f, 0xcd, 0xc6, 0xf8, |
219 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, | 217 0x37, 0x66, 0xe5, 0xf9, 0x7b, 0x6c, 0x74, 0x23, |
220 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, | 218 0x73, 0x80, 0x69, 0x00, 0xe4, 0x9f, 0x24, 0xb2, |
221 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, | 219 0x2b, 0x09, 0x75, 0x44, 0xd4, 0x89, 0x6b, 0x42, |
222 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, | 220 0x49, 0x89, 0xb5, 0xe1, 0xeb, 0xac, 0x0f, 0x07, |
223 0xc2, 0x3f, 0x45, 0x98, }, | 221 0xc2, 0x3f, 0x45, 0x98, }, |
224 | 222 |
225 /* TAG */ | 223 /* TAG */ |
226 { 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, | 224 { 0x36, 0x12, 0xd2, 0xe7, 0x9e, 0x3b, 0x07, 0x85, |
227 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb, } | 225 0x56, 0x1b, 0xe1, 0x4a, 0xac, 0xa2, 0xfc, 0xcb, } |
228 }, | 226 }, |
229 | 227 |
230 /* test case #6 */ | 228 /* test case #6 */ |
231 { | 229 { |
232 /* key */ | 230 /* key */ |
233 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, | 231 { 0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65, 0x73, 0x1c, |
234 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, | 232 0x6d, 0x6a, 0x8f, 0x94, 0x67, 0x30, 0x83, 0x08, }, |
235 16, | 233 16, |
236 | 234 |
237 /* PT */ | 235 /* PT */ |
238 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, | 236 { 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, |
239 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, | 237 0xa5, 0x59, 0x09, 0xc5, 0xaf, 0xf5, 0x26, 0x9a, |
240 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, | 238 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda, |
241 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, | 239 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, |
242 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, | 240 0x1c, 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, |
243 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, | 241 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25, |
244 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, | 242 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, |
245 0xba, 0x63, 0x7b, 0x39, }, | 243 0xba, 0x63, 0x7b, 0x39, }, |
246 60, | 244 60, |
247 | 245 |
248 /* ADATA */ | 246 /* ADATA */ |
249 { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | 247 { 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, |
250 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, | 248 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, |
251 0xab, 0xad, 0xda, 0xd2, }, | 249 0xab, 0xad, 0xda, 0xd2, }, |
252 20, | 250 20, |
253 | 251 |
254 /* IV */ | 252 /* IV */ |
255 { 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, | 253 { 0x93, 0x13, 0x22, 0x5d, 0xf8, 0x84, 0x06, 0xe5, |
256 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, | 254 0x55, 0x90, 0x9c, 0x5a, 0xff, 0x52, 0x69, 0xaa, |
257 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, | 255 0x6a, 0x7a, 0x95, 0x38, 0x53, 0x4f, 0x7d, 0xa1, |
258 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, | 256 0xe4, 0xc3, 0x03, 0xd2, 0xa3, 0x18, 0xa7, 0x28, |
259 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, | 257 0xc3, 0xc0, 0xc9, 0x51, 0x56, 0x80, 0x95, 0x39, |
260 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, | 258 0xfc, 0xf0, 0xe2, 0x42, 0x9a, 0x6b, 0x52, 0x54, |
261 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, | 259 0x16, 0xae, 0xdb, 0xf5, 0xa0, 0xde, 0x6a, 0x57, |
262 0xa6, 0x37, 0xb3, 0x9b, }, | 260 0xa6, 0x37, 0xb3, 0x9b, }, |
263 60, | 261 60, |
264 | 262 |
265 /* CT */ | 263 /* CT */ |
266 { 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, | 264 { 0x8c, 0xe2, 0x49, 0x98, 0x62, 0x56, 0x15, 0xb6, |
267 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, | 265 0x03, 0xa0, 0x33, 0xac, 0xa1, 0x3f, 0xb8, 0x94, |
268 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8, | 266 0xbe, 0x91, 0x12, 0xa5, 0xc3, 0xa2, 0x11, 0xa8, |
269 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, | 267 0xba, 0x26, 0x2a, 0x3c, 0xca, 0x7e, 0x2c, 0xa7, |
270 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, | 268 0x01, 0xe4, 0xa9, 0xa4, 0xfb, 0xa4, 0x3c, 0x90, |
271 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, | 269 0xcc, 0xdc, 0xb2, 0x81, 0xd4, 0x8c, 0x7c, 0x6f, |
272 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, | 270 0xd6, 0x28, 0x75, 0xd2, 0xac, 0xa4, 0x17, 0x03, |
273 0x4c, 0x34, 0xae, 0xe5, }, | 271 0x4c, 0x34, 0xae, 0xe5, }, |
274 | 272 |
275 /* TAG */ | 273 /* TAG */ |
276 { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, | 274 { 0x61, 0x9c, 0xc5, 0xae, 0xff, 0xfe, 0x0b, 0xfa, |
277 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, } | 275 0x46, 0x2a, 0xf4, 0x3c, 0x16, 0x99, 0xd0, 0x50, } |
278 }, | 276 }, |
279 | 277 |
280 /* test case #46 from BG (catches the LTC bug of v1.15) */ | 278 /* test case #46 from BG (catches the LTC bug of v1.15) */ |
281 { | 279 { |
282 /* key */ | 280 /* key */ |
283 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, | 281 { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
284 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, | 282 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }, |
285 16, | 283 16, |
286 | 284 |
287 /* PT */ | 285 /* PT */ |
288 { 0xa2, 0xaa, 0xb3, 0xad, 0x8b, 0x17, 0xac, 0xdd, | 286 { 0xa2, 0xaa, 0xb3, 0xad, 0x8b, 0x17, 0xac, 0xdd, |
289 0xa2, 0x88, 0x42, 0x6c, 0xd7, 0xc4, 0x29, 0xb7, | 287 0xa2, 0x88, 0x42, 0x6c, 0xd7, 0xc4, 0x29, 0xb7, |
290 0xca, 0x86, 0xb7, 0xac, 0xa0, 0x58, 0x09, 0xc7, | 288 0xca, 0x86, 0xb7, 0xac, 0xa0, 0x58, 0x09, 0xc7, |
291 0x0c, 0xe8, 0x2d, 0xb2, 0x57, 0x11, 0xcb, 0x53, | 289 0x0c, 0xe8, 0x2d, 0xb2, 0x57, 0x11, 0xcb, 0x53, |
292 0x02, 0xeb, 0x27, 0x43, 0xb0, 0x36, 0xf3, 0xd7, | 290 0x02, 0xeb, 0x27, 0x43, 0xb0, 0x36, 0xf3, 0xd7, |
293 0x50, 0xd6, 0xcf, 0x0d, 0xc0, 0xac, 0xb9, 0x29, | 291 0x50, 0xd6, 0xcf, 0x0d, 0xc0, 0xac, 0xb9, 0x29, |
294 0x50, 0xd5, 0x46, 0xdb, 0x30, 0x8f, 0x93, 0xb4, | 292 0x50, 0xd5, 0x46, 0xdb, 0x30, 0x8f, 0x93, 0xb4, |
295 0xff, 0x24, 0x4a, 0xfa, 0x9d, 0xc7, 0x2b, 0xcd, | 293 0xff, 0x24, 0x4a, 0xfa, 0x9d, 0xc7, 0x2b, 0xcd, |
296 0x75, 0x8d, 0x2c }, | 294 0x75, 0x8d, 0x2c }, |
297 67, | 295 67, |
298 | 296 |
299 /* ADATA */ | 297 /* ADATA */ |
300 { 0x68, 0x8e, 0x1a, 0xa9, 0x84, 0xde, 0x92, 0x6d, | 298 { 0x68, 0x8e, 0x1a, 0xa9, 0x84, 0xde, 0x92, 0x6d, |
301 0xc7, 0xb4, 0xc4, 0x7f, 0x44 }, | 299 0xc7, 0xb4, 0xc4, 0x7f, 0x44 }, |
302 13, | 300 13, |
303 | 301 |
304 /* IV */ | 302 /* IV */ |
305 { 0xb7, 0x21, 0x38, 0xb5, 0xa0, 0x5f, 0xf5, 0x07, | 303 { 0xb7, 0x21, 0x38, 0xb5, 0xa0, 0x5f, 0xf5, 0x07, |
306 0x0e, 0x8c, 0xd9, 0x41, 0x83, 0xf7, 0x61, 0xd8 }, | 304 0x0e, 0x8c, 0xd9, 0x41, 0x83, 0xf7, 0x61, 0xd8 }, |
307 16, | 305 16, |
308 | 306 |
309 /* CT */ | 307 /* CT */ |
310 { 0xcb, 0xc8, 0xd2, 0xf1, 0x54, 0x81, 0xa4, 0xcc, | 308 { 0xcb, 0xc8, 0xd2, 0xf1, 0x54, 0x81, 0xa4, 0xcc, |
311 0x7d, 0xd1, 0xe1, 0x9a, 0xaa, 0x83, 0xde, 0x56, | 309 0x7d, 0xd1, 0xe1, 0x9a, 0xaa, 0x83, 0xde, 0x56, |
312 0x78, 0x48, 0x3e, 0xc3, 0x59, 0xae, 0x7d, 0xec, | 310 0x78, 0x48, 0x3e, 0xc3, 0x59, 0xae, 0x7d, 0xec, |
313 0x2a, 0xb8, 0xd5, 0x34, 0xe0, 0x90, 0x6f, 0x4b, | 311 0x2a, 0xb8, 0xd5, 0x34, 0xe0, 0x90, 0x6f, 0x4b, |
314 0x46, 0x63, 0xfa, 0xff, 0x58, 0xa8, 0xb2, 0xd7, | 312 0x46, 0x63, 0xfa, 0xff, 0x58, 0xa8, 0xb2, 0xd7, |
315 0x33, 0xb8, 0x45, 0xee, 0xf7, 0xc9, 0xb3, 0x31, | 313 0x33, 0xb8, 0x45, 0xee, 0xf7, 0xc9, 0xb3, 0x31, |
316 0xe9, 0xe1, 0x0e, 0xb2, 0x61, 0x2c, 0x99, 0x5f, | 314 0xe9, 0xe1, 0x0e, 0xb2, 0x61, 0x2c, 0x99, 0x5f, |
317 0xeb, 0x1a, 0xc1, 0x5a, 0x62, 0x86, 0xcc, 0xe8, | 315 0xeb, 0x1a, 0xc1, 0x5a, 0x62, 0x86, 0xcc, 0xe8, |
318 0xb2, 0x97, 0xa8 }, | 316 0xb2, 0x97, 0xa8 }, |
319 | 317 |
320 /* TAG */ | 318 /* TAG */ |
321 { 0x8d, 0x2d, 0x2a, 0x93, 0x72, 0x62, 0x6f, 0x6b, | 319 { 0x8d, 0x2d, 0x2a, 0x93, 0x72, 0x62, 0x6f, 0x6b, |
322 0xee, 0x85, 0x80, 0x27, 0x6a, 0x63, 0x66, 0xbf } | 320 0xee, 0x85, 0x80, 0x27, 0x6a, 0x63, 0x66, 0xbf } |
323 } | 321 } |
324 | 322 |
325 /* rest of test cases are the same except AES key size changes... ignored... */ | 323 /* rest of test cases are the same except AES key size changes... ignored... */ |
326 }; | 324 }; |
327 int idx, err; | 325 int idx, err; |
328 unsigned long x, y; | 326 unsigned long x, y; |
329 unsigned char out[2][128], T[2][16]; | 327 unsigned char out[2][128], T[2][16]; |
328 gcm_state gcm; | |
330 | 329 |
331 /* find aes */ | 330 /* find aes */ |
332 idx = find_cipher("aes"); | 331 idx = find_cipher("aes"); |
333 if (idx == -1) { | 332 if (idx == -1) { |
334 idx = find_cipher("rijndael"); | 333 idx = find_cipher("rijndael"); |
335 if (idx == -1) { | 334 if (idx == -1) { |
336 return CRYPT_NOP; | 335 return CRYPT_NOP; |
337 } | 336 } |
338 } | 337 } |
339 | 338 |
339 /* Special test case for empty AAD + empty PT */ | |
340 y = sizeof(T[0]); | |
341 if ((err = gcm_init(&gcm, idx, tests[0].K, tests[0].keylen)) != CRYPT_OK) return err; | |
342 if ((err = gcm_add_iv(&gcm, tests[0].IV, tests[0].IVlen)) != CRYPT_OK) return err; | |
343 /* intentionally skip gcm_add_aad + gcm_process */ | |
344 if ((err = gcm_done(&gcm, T[0], &y)) != CRYPT_OK) return err; | |
345 if (compare_testvector(T[0], y, tests[0].T, 16, "GCM Encrypt Tag-special", 0)) return CRYPT_FAIL_TESTVECTOR; | |
346 | |
340 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { | 347 for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) { |
341 y = sizeof(T[0]); | 348 y = sizeof(T[0]); |
342 if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen, | 349 if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen, |
343 tests[x].IV, tests[x].IVlen, | 350 tests[x].IV, tests[x].IVlen, |
344 tests[x].A, tests[x].alen, | 351 tests[x].A, tests[x].alen, |
345 (unsigned char*)tests[x].P, tests[x].ptlen, | 352 (unsigned char*)tests[x].P, tests[x].ptlen, |
346 out[0], T[0], &y, GCM_ENCRYPT)) != CRYPT_OK) { | 353 out[0], T[0], &y, GCM_ENCRYPT)) != CRYPT_OK) { |
347 return err; | 354 return err; |
348 } | 355 } |
349 | 356 |
350 if (XMEMCMP(out[0], tests[x].C, tests[x].ptlen)) { | 357 if (compare_testvector(out[0], tests[x].ptlen, tests[x].C, tests[x].ptlen, "GCM CT", x)) { |
351 #if 0 | |
352 printf("\nCiphertext wrong %lu\n", x); | |
353 for (y = 0; y < tests[x].ptlen; y++) { | |
354 printf("%02x", out[0][y] & 255); | |
355 } | |
356 printf("\n"); | |
357 #endif | |
358 return CRYPT_FAIL_TESTVECTOR; | 358 return CRYPT_FAIL_TESTVECTOR; |
359 } | 359 } |
360 | 360 |
361 if (XMEMCMP(T[0], tests[x].T, 16)) { | 361 if (compare_testvector(T[0], y, tests[x].T, 16, "GCM Encrypt Tag", x)) { |
362 #if 0 | |
363 printf("\nTag on plaintext wrong %lu\n", x); | |
364 for (y = 0; y < 16; y++) { | |
365 printf("%02x", T[0][y] & 255); | |
366 } | |
367 printf("\n"); | |
368 #endif | |
369 return CRYPT_FAIL_TESTVECTOR; | 362 return CRYPT_FAIL_TESTVECTOR; |
370 } | 363 } |
371 | 364 |
372 y = sizeof(T[1]); | 365 y = sizeof(T[1]); |
373 if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen, | 366 if ((err = gcm_memory(idx, tests[x].K, tests[x].keylen, |
376 out[1], tests[x].ptlen, | 369 out[1], tests[x].ptlen, |
377 out[0], T[1], &y, GCM_DECRYPT)) != CRYPT_OK) { | 370 out[0], T[1], &y, GCM_DECRYPT)) != CRYPT_OK) { |
378 return err; | 371 return err; |
379 } | 372 } |
380 | 373 |
381 if (XMEMCMP(out[1], tests[x].P, tests[x].ptlen)) { | 374 if (compare_testvector(out[1], tests[x].ptlen, tests[x].P, tests[x].ptlen, "GCM PT", x)) { |
382 #if 0 | |
383 printf("\nplaintext wrong %lu\n", x); | |
384 for (y = 0; y < tests[x].ptlen; y++) { | |
385 printf("%02x", out[0][y] & 255); | |
386 } | |
387 printf("\n"); | |
388 #endif | |
389 return CRYPT_FAIL_TESTVECTOR; | 375 return CRYPT_FAIL_TESTVECTOR; |
390 } | 376 } |
391 | 377 |
392 if (XMEMCMP(T[1], tests[x].T, 16)) { | 378 if (compare_testvector(T[1], y, tests[x].T, 16, "GCM Decrypt Tag", x)) { |
393 #if 0 | |
394 printf("\nTag on ciphertext wrong %lu\n", x); | |
395 for (y = 0; y < 16; y++) { | |
396 printf("%02x", T[1][y] & 255); | |
397 } | |
398 printf("\n"); | |
399 #endif | |
400 return CRYPT_FAIL_TESTVECTOR; | 379 return CRYPT_FAIL_TESTVECTOR; |
401 } | 380 } |
402 | 381 |
403 } | 382 } |
404 return CRYPT_OK; | 383 return CRYPT_OK; |
406 } | 385 } |
407 | 386 |
408 #endif | 387 #endif |
409 | 388 |
410 | 389 |
411 /* $Source$ */ | 390 /* ref: $Format:%D$ */ |
412 /* $Revision$ */ | 391 /* git commit: $Format:%H$ */ |
413 /* $Date$ */ | 392 /* commit time: $Format:%ai$ */ |