1 /*
2 *
3 * Copyright 2018 gRPC authors.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 */
18
19 #include "src/core/tsi/alts/crypt/gsec.h"
20 #include "test/core/tsi/alts/crypt/gsec_test_util.h"
21
22 #include <grpc/support/alloc.h>
23 #include <grpc/support/log.h>
24
25 const size_t kTestMinTagLengthForCorruption = 8;
26 const size_t kTestNumCrypters = 3;
27 const size_t kTestMaxSlices = 5;
28 const size_t kTestMaxLength = 1024;
29 const size_t kTestNumEncryptions = 100;
30
31 /* Struct for pre-generated test vector */
32 typedef struct gsec_aead_test_vector {
33 uint8_t* nonce;
34 uint8_t* aad;
35 uint8_t* key;
36 uint8_t* plaintext;
37 uint8_t* ciphertext_and_tag;
38 size_t nonce_length;
39 size_t aad_length;
40 size_t key_length;
41 size_t plaintext_length;
42 size_t ciphertext_and_tag_length;
43 } gsec_aead_test_vector;
44
gsec_randomly_slice(uint8_t * input,size_t input_length,struct iovec ** output,size_t * output_length)45 static void gsec_randomly_slice(uint8_t* input, size_t input_length,
46 struct iovec** output, size_t* output_length) {
47 if (input_length == 0) {
48 *output = nullptr;
49 *output_length = 0;
50 return;
51 }
52 *output_length = gsec_test_bias_random_uint32(kTestMaxSlices) + 1;
53 *output =
54 static_cast<struct iovec*>(malloc(*output_length * sizeof(**output)));
55 size_t i;
56 for (i = 0; i < *output_length - 1; i++) {
57 size_t slice_length =
58 gsec_test_bias_random_uint32(static_cast<uint32_t>(input_length));
59 struct iovec slice = {input, slice_length};
60 (*output)[i] = slice;
61 input += slice_length;
62 input_length -= slice_length;
63 }
64 struct iovec slice = {input, input_length};
65 (*output)[*output_length - 1] = slice;
66 }
67
gsec_assert_ok(grpc_status_code status,const char * error_detail)68 static void gsec_assert_ok(grpc_status_code status, const char* error_detail) {
69 char empty_string[] = "";
70 if (error_detail == nullptr) {
71 error_detail = empty_string;
72 }
73 if (status != GRPC_STATUS_OK) {
74 fprintf(stderr, "Status is not ok: %s\n", error_detail);
75 }
76 GPR_ASSERT(status == GRPC_STATUS_OK);
77 }
78
gsec_test_random_encrypt_decrypt(gsec_aead_crypter * crypter,size_t aad_length,size_t message_length)79 static void gsec_test_random_encrypt_decrypt(gsec_aead_crypter* crypter,
80 size_t aad_length,
81 size_t message_length) {
82 GPR_ASSERT(crypter != nullptr);
83 size_t nonce_length, tag_length;
84 uint8_t *nonce, *aad, *message;
85 gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr);
86 gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr);
87
88 gsec_test_random_array(&nonce, nonce_length);
89 gsec_test_random_array(&aad, aad_length);
90 gsec_test_random_array(&message, message_length);
91
92 /* Test encryption */
93 size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0;
94 gsec_aead_crypter_max_ciphertext_and_tag_length(
95 crypter, message_length, &ciphertext_and_tag_length, nullptr);
96
97 uint8_t* ciphertext_and_tag =
98 static_cast<uint8_t*>(gpr_malloc(ciphertext_and_tag_length));
99
100 char* error_buffer = nullptr;
101 gsec_assert_ok(
102 gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, aad, aad_length,
103 message, message_length, ciphertext_and_tag,
104 ciphertext_and_tag_length,
105 &ciphertext_bytes_written, &error_buffer),
106 error_buffer);
107 GPR_ASSERT(message_length + tag_length == ciphertext_and_tag_length);
108 GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length);
109
110 /* Test decryption */
111 size_t plaintext_length, plaintext_bytes_written = 0;
112 gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_bytes_written,
113 &plaintext_length, nullptr);
114 uint8_t* plaintext = static_cast<uint8_t*>(gpr_malloc(plaintext_length));
115 grpc_status_code status = gsec_aead_crypter_decrypt(
116 crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag,
117 ciphertext_bytes_written, plaintext, plaintext_length,
118 &plaintext_bytes_written, nullptr);
119
120 GPR_ASSERT(status == GRPC_STATUS_OK);
121 GPR_ASSERT(message_length == plaintext_bytes_written);
122 GPR_ASSERT(memcmp(message, plaintext, message_length) == 0);
123
124 /**
125 * The returned plaintext will be zeroed if there was an authentication error.
126 */
127 uint8_t* zero_message = static_cast<uint8_t*>(gpr_zalloc(plaintext_length));
128 if (tag_length >= kTestMinTagLengthForCorruption) {
129 char* error_message;
130 /* Corrupt nonce */
131 if (nonce_length > 0) {
132 plaintext_bytes_written = 0;
133 uint8_t* corrupt_nonce;
134 gsec_test_copy_and_alter_random_byte(nonce, &corrupt_nonce, nonce_length);
135 status = gsec_aead_crypter_decrypt(
136 crypter, corrupt_nonce, nonce_length, aad, aad_length,
137 ciphertext_and_tag, ciphertext_bytes_written, plaintext,
138 plaintext_length, &plaintext_bytes_written, &error_message);
139
140 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
141 status, GRPC_STATUS_FAILED_PRECONDITION, "Checking tag failed.",
142 error_message));
143 GPR_ASSERT(plaintext_bytes_written == 0);
144 GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0);
145 gpr_free(corrupt_nonce);
146 gpr_free(error_message);
147 }
148
149 /* Corrupt ciphertext_and_tag */
150 plaintext_bytes_written = 0;
151 uint8_t* corrupt_ciphertext_and_tag;
152 gsec_test_copy_and_alter_random_byte(ciphertext_and_tag,
153 &corrupt_ciphertext_and_tag,
154 ciphertext_and_tag_length);
155 status = gsec_aead_crypter_decrypt(
156 crypter, nonce, nonce_length, aad, aad_length,
157 corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext,
158 plaintext_length, &plaintext_bytes_written, &error_message);
159
160 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
161 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
162 "Checking tag failed"));
163 GPR_ASSERT(plaintext_bytes_written == 0);
164 GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0);
165 gpr_free(error_message);
166 gpr_free(corrupt_ciphertext_and_tag);
167
168 /* Corrupt start of ciphertext_and_tag */
169 plaintext_bytes_written = 0;
170 gsec_test_copy(ciphertext_and_tag, &corrupt_ciphertext_and_tag,
171 ciphertext_and_tag_length);
172 (*corrupt_ciphertext_and_tag)++;
173 status = gsec_aead_crypter_decrypt(
174 crypter, nonce, nonce_length, aad, aad_length,
175 corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext,
176 plaintext_length, &plaintext_bytes_written, &error_message);
177 GPR_ASSERT(plaintext_bytes_written == 0);
178 GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0);
179 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
180 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
181 "Checking tag failed"));
182 gpr_free(error_message);
183 gpr_free(corrupt_ciphertext_and_tag);
184
185 /* Corrupt end of ciphertext_and_tag */
186 plaintext_bytes_written = 0;
187 gsec_test_copy(ciphertext_and_tag, &corrupt_ciphertext_and_tag,
188 ciphertext_and_tag_length);
189 (*(corrupt_ciphertext_and_tag + ciphertext_and_tag_length - 1))++;
190
191 status = gsec_aead_crypter_decrypt(
192 crypter, nonce, nonce_length, aad, aad_length,
193 corrupt_ciphertext_and_tag, ciphertext_bytes_written, plaintext,
194 plaintext_length, &plaintext_bytes_written, &error_message);
195
196 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
197 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
198 "Checking tag failed"));
199 GPR_ASSERT(plaintext_bytes_written == 0);
200 GPR_ASSERT(memcmp(zero_message, plaintext, plaintext_length) == 0);
201 gpr_free(error_message);
202 gpr_free(corrupt_ciphertext_and_tag);
203 }
204
205 gpr_free(zero_message);
206 gpr_free(nonce);
207 gpr_free(aad);
208 gpr_free(message);
209 gpr_free(plaintext);
210 gpr_free(ciphertext_and_tag);
211 }
212
gsec_test_encrypt_decrypt(gsec_aead_crypter * crypter)213 static void gsec_test_encrypt_decrypt(gsec_aead_crypter* crypter) {
214 GPR_ASSERT(crypter != nullptr);
215 size_t aad_length, message_length;
216 aad_length = gsec_test_bias_random_uint32(kTestMaxLength);
217 message_length = gsec_test_bias_random_uint32(kTestMaxLength);
218 gsec_test_random_encrypt_decrypt(crypter, aad_length, message_length);
219 gsec_test_random_encrypt_decrypt(crypter, 0, message_length);
220 gsec_test_random_encrypt_decrypt(crypter, aad_length, 0);
221 }
222
gsec_test_multiple_random_encrypt_decrypt(gsec_aead_crypter * crypter,size_t * aad_lengths,size_t * message_lengths,size_t count)223 static void gsec_test_multiple_random_encrypt_decrypt(
224 gsec_aead_crypter* crypter, size_t* aad_lengths, size_t* message_lengths,
225 size_t count) {
226 GPR_ASSERT(crypter != nullptr);
227 size_t nonce_length, tag_length;
228 uint8_t **nonces, **aads, **messages;
229 nonces = static_cast<uint8_t**>(gpr_malloc(sizeof(uint8_t*) * count));
230 aads = static_cast<uint8_t**>(gpr_malloc(sizeof(uint8_t*) * count));
231 messages = static_cast<uint8_t**>(gpr_malloc(sizeof(uint8_t*) * count));
232
233 gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr);
234 gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr);
235
236 size_t ind;
237 for (ind = 0; ind < count; ind++) {
238 size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind];
239 size_t message_length =
240 (message_lengths == nullptr) ? 0 : message_lengths[ind];
241 gsec_test_random_array(&(nonces[ind]), nonce_length);
242 gsec_test_random_array(&(aads[ind]), aad_length);
243 gsec_test_random_array(&(messages[ind]), message_length);
244 }
245
246 size_t* ciphertext_and_tag_lengths =
247 static_cast<size_t*>(gpr_malloc(sizeof(size_t) * count));
248 size_t* ciphertext_bytes_writtens =
249 static_cast<size_t*>(gpr_malloc(sizeof(size_t) * count));
250 size_t* plaintext_lengths =
251 static_cast<size_t*>(gpr_malloc(sizeof(size_t) * count));
252 size_t* plaintext_bytes_writtens =
253 static_cast<size_t*>(gpr_malloc(sizeof(size_t) * count));
254 uint8_t** ciphertext_and_tags =
255 static_cast<uint8_t**>(gpr_malloc(sizeof(uint8_t*) * count));
256 uint8_t** plaintexts =
257 static_cast<uint8_t**>(gpr_malloc(sizeof(uint8_t*) * count));
258
259 /* Do encryption */
260 for (ind = 0; ind < count; ind++) {
261 size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind];
262 size_t message_length =
263 (message_lengths == nullptr) ? 0 : message_lengths[ind];
264 gsec_aead_crypter_max_ciphertext_and_tag_length(
265 crypter, message_length, &(ciphertext_and_tag_lengths[ind]), nullptr);
266 ciphertext_and_tags[ind] =
267 static_cast<uint8_t*>(gpr_malloc(ciphertext_and_tag_lengths[ind]));
268 grpc_status_code status = gsec_aead_crypter_encrypt(
269 crypter, nonces[ind], nonce_length, aads[ind], aad_length,
270 messages[ind], message_length, ciphertext_and_tags[ind],
271 ciphertext_and_tag_lengths[ind], &(ciphertext_bytes_writtens[ind]),
272 nullptr);
273 GPR_ASSERT(status == GRPC_STATUS_OK);
274 GPR_ASSERT(message_length + tag_length == ciphertext_and_tag_lengths[ind]);
275 GPR_ASSERT(ciphertext_bytes_writtens[ind] ==
276 ciphertext_and_tag_lengths[ind]);
277 }
278 /* Do Decryption */
279 for (ind = 0; ind < count; ind++) {
280 size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind];
281 size_t message_length =
282 (message_lengths == nullptr) ? 0 : message_lengths[ind];
283 gsec_aead_crypter_max_plaintext_length(crypter,
284 ciphertext_bytes_writtens[ind],
285 &(plaintext_lengths[ind]), nullptr);
286 plaintexts[ind] = static_cast<uint8_t*>(gpr_malloc(plaintext_lengths[ind]));
287 grpc_status_code status = gsec_aead_crypter_decrypt(
288 crypter, nonces[ind], nonce_length, aads[ind], aad_length,
289 ciphertext_and_tags[ind], ciphertext_bytes_writtens[ind],
290 plaintexts[ind], plaintext_lengths[ind],
291 &(plaintext_bytes_writtens[ind]), nullptr);
292 GPR_ASSERT(status == GRPC_STATUS_OK);
293 GPR_ASSERT(message_length == plaintext_bytes_writtens[ind]);
294 GPR_ASSERT(memcmp(messages[ind], plaintexts[ind], message_length) == 0);
295 }
296
297 /* Slice the plaintext and encrypt with iovecs */
298 for (ind = 0; ind < count; ind++) {
299 size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind];
300 struct iovec* aad_vecs = nullptr;
301 size_t aad_vecs_length = 0;
302 gsec_randomly_slice(aads[ind], aad_length, &aad_vecs, &aad_vecs_length);
303 size_t message_length =
304 (message_lengths == nullptr) ? 0 : message_lengths[ind];
305 struct iovec* message_vecs = nullptr;
306 size_t message_vecs_length = 0;
307 gsec_randomly_slice(messages[ind], message_length, &message_vecs,
308 &message_vecs_length);
309
310 size_t ciphertext_length = ciphertext_and_tag_lengths[ind];
311 uint8_t* another_ciphertext =
312 static_cast<uint8_t*>(malloc(ciphertext_length));
313 struct iovec another_ciphertext_vec = {another_ciphertext,
314 ciphertext_length};
315
316 char* error_details = nullptr;
317 size_t ciphertext_bytes_written = 0;
318 gsec_assert_ok(
319 gsec_aead_crypter_encrypt_iovec(
320 crypter, nonces[ind], nonce_length, aad_vecs, aad_vecs_length,
321 message_vecs, message_vecs_length, another_ciphertext_vec,
322 &ciphertext_bytes_written, &error_details),
323 error_details);
324 GPR_ASSERT(memcmp(ciphertext_and_tags[ind], another_ciphertext_vec.iov_base,
325 ciphertext_length) == 0);
326 free(another_ciphertext);
327 free(aad_vecs);
328 free(message_vecs);
329 }
330
331 /* Slice the ciphertext and decrypt with iovecs */
332 for (ind = 0; ind < count; ind++) {
333 size_t message_length =
334 (message_lengths == nullptr) ? 0 : message_lengths[ind];
335 message_length = message_length + 0;
336
337 size_t aad_length = (aad_lengths == nullptr) ? 0 : aad_lengths[ind];
338
339 struct iovec* aad_vecs = nullptr;
340 size_t aad_vecs_length = 0;
341 gsec_randomly_slice(aads[ind], aad_length, &aad_vecs, &aad_vecs_length);
342
343 struct iovec* ciphertext_vecs = nullptr;
344 size_t ciphertext_vecs_length = 0;
345 gsec_randomly_slice(ciphertext_and_tags[ind],
346 ciphertext_bytes_writtens[ind], &ciphertext_vecs,
347 &ciphertext_vecs_length);
348
349 size_t decrypted_length = plaintext_lengths[ind];
350 uint8_t* decrypted = static_cast<uint8_t*>(malloc(decrypted_length));
351 struct iovec decrypted_vec = {decrypted, decrypted_length};
352
353 char* error_details = nullptr;
354 gsec_assert_ok(gsec_aead_crypter_decrypt_iovec(
355 crypter, nonces[ind], nonce_length, aad_vecs,
356 aad_vecs_length, ciphertext_vecs, ciphertext_vecs_length,
357 decrypted_vec, &decrypted_length, &error_details),
358 error_details);
359 GPR_ASSERT(decrypted_vec.iov_len == message_length);
360 GPR_ASSERT(memcmp(decrypted_vec.iov_base, messages[ind], message_length) ==
361 0);
362 free(decrypted);
363 free(aad_vecs);
364 free(ciphertext_vecs);
365 }
366
367 for (ind = 0; ind < count; ind++) {
368 gpr_free(nonces[ind]);
369 gpr_free(aads[ind]);
370 gpr_free(messages[ind]);
371 gpr_free(ciphertext_and_tags[ind]);
372 gpr_free(plaintexts[ind]);
373 }
374 gpr_free(nonces);
375 gpr_free(aads);
376 gpr_free(messages);
377 gpr_free(ciphertext_and_tag_lengths);
378 gpr_free(ciphertext_bytes_writtens);
379 gpr_free(plaintext_lengths);
380 gpr_free(plaintext_bytes_writtens);
381 gpr_free(ciphertext_and_tags);
382 gpr_free(plaintexts);
383 }
384
gsec_test_multiple_encrypt_decrypt(gsec_aead_crypter * crypter)385 static void gsec_test_multiple_encrypt_decrypt(gsec_aead_crypter* crypter) {
386 GPR_ASSERT(crypter != nullptr);
387 size_t count = kTestNumEncryptions;
388 size_t* aad_lengths =
389 static_cast<size_t*>(gpr_malloc(sizeof(size_t) * count));
390 size_t* message_lengths =
391 static_cast<size_t*>(gpr_malloc(sizeof(size_t) * count));
392 size_t ind;
393 for (ind = 0; ind < count; ind++) {
394 aad_lengths[ind] = gsec_test_bias_random_uint32(kTestMaxLength);
395 message_lengths[ind] = gsec_test_bias_random_uint32(kTestMaxLength);
396 }
397 gsec_test_multiple_random_encrypt_decrypt(crypter, aad_lengths,
398 message_lengths, count);
399 gsec_test_multiple_random_encrypt_decrypt(crypter, aad_lengths, nullptr,
400 count);
401 gsec_test_multiple_random_encrypt_decrypt(crypter, nullptr, message_lengths,
402 count);
403 gpr_free(aad_lengths);
404 gpr_free(message_lengths);
405 }
406
gsec_test_encryption_failure(gsec_aead_crypter * crypter)407 static void gsec_test_encryption_failure(gsec_aead_crypter* crypter) {
408 GPR_ASSERT(crypter != nullptr);
409 size_t aad_length = kTestMaxLength;
410 size_t message_length = kTestMaxLength;
411 size_t nonce_length;
412
413 char* error_message;
414 uint8_t *nonce, *aad, *message;
415
416 gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr);
417 gsec_test_random_array(&nonce, nonce_length);
418 gsec_test_random_array(&aad, aad_length);
419 gsec_test_random_array(&message, message_length);
420
421 size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0;
422 gsec_aead_crypter_max_ciphertext_and_tag_length(
423 crypter, message_length, &ciphertext_and_tag_length, nullptr);
424 uint8_t* ciphertext_and_tag =
425 static_cast<uint8_t*>(gpr_malloc(ciphertext_and_tag_length));
426
427 /* nullptr nonce */
428 grpc_status_code status = gsec_aead_crypter_encrypt(
429 crypter, nullptr, nonce_length, aad, aad_length, message, message_length,
430 ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written,
431 &error_message);
432 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
433 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
434 "Nonce buffer is nullptr."));
435 gpr_free(error_message);
436
437 /* Big nonce */
438 status = gsec_aead_crypter_encrypt(
439 crypter, nonce, nonce_length + 1, aad, aad_length, message,
440 message_length, ciphertext_and_tag, ciphertext_and_tag_length,
441 &ciphertext_bytes_written, &error_message);
442 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
443 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
444 "Nonce buffer has the wrong length."));
445 gpr_free(error_message);
446
447 /* Small nonce */
448 status = gsec_aead_crypter_encrypt(
449 crypter, nonce, nonce_length - 1, aad, aad_length, message,
450 message_length, ciphertext_and_tag, ciphertext_and_tag_length,
451 &ciphertext_bytes_written, &error_message);
452 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
453 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
454 "Nonce buffer has the wrong length."));
455 gpr_free(error_message);
456
457 /* nullptr aad */
458 status = gsec_aead_crypter_encrypt(
459 crypter, nonce, nonce_length, nullptr, aad_length, message,
460 message_length, ciphertext_and_tag, ciphertext_and_tag_length,
461 &ciphertext_bytes_written, &error_message);
462 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
463 status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "aad is nullptr."));
464 gpr_free(error_message);
465
466 /* nullptr aad with zero length */
467 gsec_assert_ok(
468 gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, nullptr, 0,
469 message, message_length, ciphertext_and_tag,
470 ciphertext_and_tag_length,
471 &ciphertext_bytes_written, &error_message),
472 error_message);
473
474 /* nullptr plaintext */
475 status = gsec_aead_crypter_encrypt(
476 crypter, nonce, nonce_length, aad, aad_length, nullptr, message_length,
477 ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written,
478 &error_message);
479 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
480 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
481 "plaintext is nullptr."));
482 gpr_free(error_message);
483
484 /* nullptr ciphertext */
485 status = gsec_aead_crypter_encrypt(crypter, nonce, nonce_length, aad,
486 aad_length, message, message_length,
487 nullptr, ciphertext_and_tag_length,
488 &ciphertext_bytes_written, &error_message);
489 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
490 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
491 "ciphertext is nullptr."));
492 gpr_free(error_message);
493
494 /* Short ciphertext */
495 status = gsec_aead_crypter_encrypt(
496 crypter, nonce, nonce_length, aad, aad_length, message, message_length,
497 ciphertext_and_tag, ciphertext_and_tag_length - 1,
498 &ciphertext_bytes_written, &error_message);
499 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
500 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
501 "ciphertext is too small to hold a tag."));
502 gpr_free(error_message);
503
504 /* nullptr ciphertext_bytes_written */
505 status = gsec_aead_crypter_encrypt(
506 crypter, nonce, nonce_length, aad, aad_length, message, message_length,
507 ciphertext_and_tag, ciphertext_and_tag_length, nullptr, &error_message);
508 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
509 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
510 "bytes_written is nullptr."));
511 gpr_free(error_message);
512
513 /* nullptr plaintext/ciphertext encrypt with zero length */
514 gsec_assert_ok(gsec_aead_crypter_encrypt(
515 crypter, nonce, nonce_length, aad, aad_length, nullptr, 0,
516 ciphertext_and_tag, ciphertext_and_tag_length,
517 &ciphertext_bytes_written, &error_message),
518 error_message);
519
520 /* Success */
521 status = gsec_aead_crypter_encrypt(
522 crypter, nonce, nonce_length, aad, aad_length, message, message_length,
523 ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written,
524 &error_message);
525 GPR_ASSERT(status == GRPC_STATUS_OK);
526
527 gpr_free(message);
528 gpr_free(aad);
529 gpr_free(nonce);
530 gpr_free(ciphertext_and_tag);
531 }
532
gsec_test_decryption_failure(gsec_aead_crypter * crypter)533 static void gsec_test_decryption_failure(gsec_aead_crypter* crypter) {
534 GPR_ASSERT(crypter != nullptr);
535 size_t aad_length = kTestMaxLength;
536 size_t message_length = kTestMaxLength;
537 size_t nonce_length, tag_length;
538 uint8_t *nonce, *aad, *message;
539
540 gsec_aead_crypter_nonce_length(crypter, &nonce_length, nullptr);
541 gsec_aead_crypter_tag_length(crypter, &tag_length, nullptr);
542 gsec_test_random_array(&nonce, nonce_length);
543 gsec_test_random_array(&aad, aad_length);
544 gsec_test_random_array(&message, message_length);
545
546 /* Test encryption */
547 size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0;
548 gsec_aead_crypter_max_ciphertext_and_tag_length(
549 crypter, message_length, &ciphertext_and_tag_length, nullptr);
550 uint8_t* ciphertext_and_tag =
551 static_cast<uint8_t*>(gpr_malloc(ciphertext_and_tag_length));
552
553 grpc_status_code status = gsec_aead_crypter_encrypt(
554 crypter, nonce, nonce_length, aad, aad_length, message, message_length,
555 ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written,
556 nullptr);
557 GPR_ASSERT(status == GRPC_STATUS_OK);
558 GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length);
559
560 size_t plaintext_length, plaintext_bytes_written = 0;
561 gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_bytes_written,
562 &plaintext_length, nullptr);
563 uint8_t* plaintext = static_cast<uint8_t*>(gpr_malloc(plaintext_length));
564
565 char* error_message;
566 /* nullptr nonce */
567 status = gsec_aead_crypter_decrypt(
568 crypter, nullptr, nonce_length, aad, aad_length, ciphertext_and_tag,
569 ciphertext_and_tag_length, plaintext, plaintext_length,
570 &plaintext_bytes_written, &error_message);
571 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
572 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
573 "Nonce buffer is nullptr."));
574 gpr_free(error_message);
575
576 /* Big nonce */
577 status = gsec_aead_crypter_decrypt(
578 crypter, nonce, nonce_length + 1, aad, aad_length, ciphertext_and_tag,
579 ciphertext_and_tag_length, plaintext, plaintext_length,
580 &plaintext_bytes_written, &error_message);
581 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
582 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
583 "Nonce buffer has the wrong length."));
584 gpr_free(error_message);
585
586 /* Small nonce */
587 status = gsec_aead_crypter_decrypt(
588 crypter, nonce, nonce_length - 1, aad, aad_length, ciphertext_and_tag,
589 ciphertext_and_tag_length, plaintext, plaintext_length,
590 &plaintext_bytes_written, &error_message);
591 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
592 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
593 "Nonce buffer has the wrong length."));
594 gpr_free(error_message);
595
596 /* nullptr aad */
597 status = gsec_aead_crypter_decrypt(
598 crypter, nonce, nonce_length, nullptr, aad_length, ciphertext_and_tag,
599 ciphertext_and_tag_length, plaintext, plaintext_length,
600 &plaintext_bytes_written, &error_message);
601 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
602 status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "aad is nullptr."));
603 gpr_free(error_message);
604
605 /* nullptr aad with zero length */
606 status = gsec_aead_crypter_encrypt(
607 crypter, nonce, nonce_length, nullptr, 0, message, message_length,
608 ciphertext_and_tag, ciphertext_and_tag_length, &ciphertext_bytes_written,
609 &error_message);
610 GPR_ASSERT(status == GRPC_STATUS_OK);
611
612 status = gsec_aead_crypter_decrypt(
613 crypter, nonce, nonce_length, nullptr, 0, ciphertext_and_tag,
614 ciphertext_and_tag_length, plaintext, plaintext_length,
615 &plaintext_bytes_written, &error_message);
616 GPR_ASSERT(status == GRPC_STATUS_OK);
617
618 /* Small ciphertext */
619 if (tag_length > 0) {
620 status = gsec_aead_crypter_decrypt(
621 crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag,
622 tag_length - 1, plaintext, plaintext_length, &plaintext_bytes_written,
623 &error_message);
624
625 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
626 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
627 "ciphertext is too small to hold a tag."));
628 gpr_free(error_message);
629 }
630
631 /* nullptr ciphertext */
632 status = gsec_aead_crypter_decrypt(
633 crypter, nonce, nonce_length, aad, aad_length, nullptr,
634 ciphertext_and_tag_length, plaintext, plaintext_length,
635 &plaintext_bytes_written, &error_message);
636
637 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
638 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
639 "ciphertext is nullptr."));
640 gpr_free(error_message);
641
642 /* nullptr plaintext */
643 status = gsec_aead_crypter_decrypt(
644 crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag,
645 ciphertext_and_tag_length, nullptr, plaintext_length,
646 &plaintext_bytes_written, &error_message);
647
648 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
649 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
650 "plaintext is nullptr, but plaintext_length is positive."));
651 gpr_free(error_message);
652
653 /* Short plaintext */
654 status = gsec_aead_crypter_decrypt(
655 crypter, nonce, nonce_length, aad, aad_length, ciphertext_and_tag,
656 ciphertext_and_tag_length, plaintext, plaintext_length - 1,
657 &plaintext_bytes_written, &error_message);
658
659 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
660 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
661 "Not enough plaintext buffer to hold encrypted ciphertext."));
662 gpr_free(error_message);
663
664 /* nullptr plaintext_bytes_written */
665 status = gsec_aead_crypter_decrypt(crypter, nonce, nonce_length, aad,
666 aad_length, ciphertext_and_tag,
667 ciphertext_and_tag_length, plaintext,
668 plaintext_length, nullptr, &error_message);
669
670 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
671 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
672 "bytes_written is nullptr."));
673 gpr_free(error_message);
674
675 gpr_free(message);
676 gpr_free(plaintext);
677 gpr_free(ciphertext_and_tag);
678 gpr_free(aad);
679 gpr_free(nonce);
680 }
681
gsec_test_encrypt_decrypt_test_vector(gsec_aead_crypter * crypter,gsec_aead_test_vector * test_vector)682 static void gsec_test_encrypt_decrypt_test_vector(
683 gsec_aead_crypter* crypter, gsec_aead_test_vector* test_vector) {
684 GPR_ASSERT(crypter != nullptr);
685 /* Test byte-based encryption interface. */
686 size_t ciphertext_and_tag_length, ciphertext_bytes_written = 0;
687 gsec_aead_crypter_max_ciphertext_and_tag_length(
688 crypter, test_vector->plaintext_length, &ciphertext_and_tag_length,
689 nullptr);
690 uint8_t* ciphertext_and_tag_bytes =
691 static_cast<uint8_t*>(gpr_malloc(ciphertext_and_tag_length));
692 grpc_status_code status = gsec_aead_crypter_encrypt(
693 crypter, test_vector->nonce, test_vector->nonce_length, test_vector->aad,
694 test_vector->aad_length, test_vector->plaintext,
695 test_vector->plaintext_length, ciphertext_and_tag_bytes,
696 ciphertext_and_tag_length, &ciphertext_bytes_written, nullptr);
697
698 GPR_ASSERT(status == GRPC_STATUS_OK);
699 GPR_ASSERT(ciphertext_bytes_written == ciphertext_and_tag_length);
700 GPR_ASSERT(memcmp(test_vector->ciphertext_and_tag, ciphertext_and_tag_bytes,
701 ciphertext_and_tag_length) == 0);
702
703 /* Test byte-based decryption interface */
704 size_t plaintext_length, plaintext_bytes_written = 0;
705 gsec_aead_crypter_max_plaintext_length(crypter, ciphertext_and_tag_length,
706 &plaintext_length, nullptr);
707 uint8_t* plaintext_bytes =
708 static_cast<uint8_t*>(gpr_malloc(plaintext_length));
709 status = gsec_aead_crypter_decrypt(
710 crypter, test_vector->nonce, test_vector->nonce_length, test_vector->aad,
711 test_vector->aad_length, test_vector->ciphertext_and_tag,
712 test_vector->ciphertext_and_tag_length, plaintext_bytes, plaintext_length,
713 &plaintext_bytes_written, nullptr);
714 GPR_ASSERT(status == GRPC_STATUS_OK);
715 GPR_ASSERT(memcmp(test_vector->plaintext, plaintext_bytes,
716 plaintext_bytes_written) == 0);
717
718 gpr_free(ciphertext_and_tag_bytes);
719 gpr_free(plaintext_bytes);
720 }
721
gsec_test_get_crypter_from_test_vector(gsec_aead_crypter ** crypter,gsec_aead_test_vector * test_vector,bool rekey=false)722 static void gsec_test_get_crypter_from_test_vector(
723 gsec_aead_crypter** crypter, gsec_aead_test_vector* test_vector,
724 bool rekey = false) {
725 size_t key_length = test_vector->key_length;
726 GPR_ASSERT(key_length == kAes128GcmKeyLength ||
727 key_length == kAes256GcmKeyLength ||
728 key_length == kAes128GcmRekeyKeyLength);
729 size_t nonce_length = test_vector->nonce_length;
730 GPR_ASSERT(nonce_length == kAesGcmNonceLength);
731 size_t plaintext_length = test_vector->plaintext_length;
732 size_t ciphertext_and_tag_length = test_vector->ciphertext_and_tag_length;
733 GPR_ASSERT(ciphertext_and_tag_length == plaintext_length + kAesGcmTagLength);
734 size_t tag_length = ciphertext_and_tag_length - plaintext_length;
735 gsec_aes_gcm_aead_crypter_create(test_vector->key, key_length, nonce_length,
736 tag_length, rekey, crypter, nullptr);
737 }
738
gsec_test_verify_crypter_on_test_vector(gsec_aead_test_vector * test_vector,bool rekey=false)739 static void gsec_test_verify_crypter_on_test_vector(
740 gsec_aead_test_vector* test_vector, bool rekey = false) {
741 gsec_aead_crypter* crypter;
742 gsec_test_get_crypter_from_test_vector(&crypter, test_vector, rekey);
743 gsec_test_encrypt_decrypt_test_vector(crypter, test_vector);
744 gsec_aead_crypter_destroy(crypter);
745 }
746
gsec_aead_malloc_test_vector(gsec_aead_test_vector ** test_vector,const uint8_t * key,size_t key_length,const uint8_t * nonce,size_t nonce_length,const uint8_t * aad,size_t aad_length,const uint8_t * plaintext,size_t plaintext_length,const uint8_t * ciphertext_and_tag,size_t ciphertext_and_tag_length)747 static void gsec_aead_malloc_test_vector(
748 gsec_aead_test_vector** test_vector, const uint8_t* key, size_t key_length,
749 const uint8_t* nonce, size_t nonce_length, const uint8_t* aad,
750 size_t aad_length, const uint8_t* plaintext, size_t plaintext_length,
751 const uint8_t* ciphertext_and_tag, size_t ciphertext_and_tag_length) {
752 *test_vector = static_cast<gsec_aead_test_vector*>(
753 gpr_malloc(sizeof(gsec_aead_test_vector)));
754 (*test_vector)->key_length = key_length;
755 (*test_vector)->nonce_length = nonce_length;
756 (*test_vector)->aad_length = aad_length;
757 (*test_vector)->plaintext_length = plaintext_length;
758 (*test_vector)->ciphertext_and_tag_length = ciphertext_and_tag_length;
759 gsec_test_copy(key, &((*test_vector)->key), key_length);
760 gsec_test_copy(nonce, &((*test_vector)->nonce), nonce_length);
761 gsec_test_copy(aad, &((*test_vector)->aad), aad_length);
762 gsec_test_copy(plaintext, &((*test_vector)->plaintext), plaintext_length);
763 gsec_test_copy(ciphertext_and_tag, &((*test_vector)->ciphertext_and_tag),
764 ciphertext_and_tag_length);
765 }
766
gsec_aead_free_test_vector(gsec_aead_test_vector * test_vector)767 static void gsec_aead_free_test_vector(gsec_aead_test_vector* test_vector) {
768 gpr_free(test_vector->key);
769 gpr_free(test_vector->nonce);
770 gpr_free(test_vector->aad);
771 gpr_free(test_vector->plaintext);
772 gpr_free(test_vector->ciphertext_and_tag);
773 gpr_free(test_vector);
774 }
775
gsec_test_create_random_aes_gcm_crypter(gsec_aead_crypter ** crypter,size_t key_length,size_t nonce_length,size_t tag_length,bool rekey)776 static void gsec_test_create_random_aes_gcm_crypter(gsec_aead_crypter** crypter,
777 size_t key_length,
778 size_t nonce_length,
779 size_t tag_length,
780 bool rekey) {
781 uint8_t* key;
782 gsec_test_random_array(&key, key_length);
783 gsec_aes_gcm_aead_crypter_create(key, key_length, nonce_length, tag_length,
784 rekey, crypter, nullptr);
785 gpr_free(key);
786 }
787
gsec_test_get_random_aes_gcm_crypters(gsec_aead_crypter *** crypters)788 static void gsec_test_get_random_aes_gcm_crypters(
789 gsec_aead_crypter*** crypters) {
790 *crypters = static_cast<gsec_aead_crypter**>(
791 gpr_malloc(sizeof(gsec_aead_crypter*) * kTestNumCrypters));
792 gsec_test_create_random_aes_gcm_crypter(
793 &((*crypters)[0]), kAes128GcmKeyLength, kAesGcmNonceLength,
794 kAesGcmTagLength, /*rekey=*/false);
795 gsec_test_create_random_aes_gcm_crypter(
796 &((*crypters)[1]), kAes256GcmKeyLength, kAesGcmNonceLength,
797 kAesGcmTagLength, /*rekey=*/false);
798 gsec_test_create_random_aes_gcm_crypter(
799 &((*crypters)[2]), kAes128GcmRekeyKeyLength, kAesGcmNonceLength,
800 kAesGcmTagLength, /*rekey=*/true);
801 }
802
gsec_test_do_generic_crypter_tests()803 static void gsec_test_do_generic_crypter_tests() {
804 gsec_aead_crypter** crypters;
805 gsec_test_get_random_aes_gcm_crypters(&crypters);
806 size_t ind;
807 for (ind = 0; ind < kTestNumCrypters; ind++) {
808 gsec_test_encrypt_decrypt(crypters[ind]);
809 gsec_test_multiple_encrypt_decrypt(crypters[ind]);
810 gsec_test_encryption_failure(crypters[ind]);
811 gsec_test_decryption_failure(crypters[ind]);
812 }
813 for (ind = 0; ind < kTestNumCrypters; ind++) {
814 gsec_aead_crypter_destroy(crypters[ind]);
815 }
816 gpr_free(crypters);
817 }
818
gsec_test_do_vector_tests_rekey_nist()819 static void gsec_test_do_vector_tests_rekey_nist() {
820 // NIST vectors from:
821 // http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf
822 //
823 // IEEE vectors from:
824 // http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf
825 //
826 // Key expanded by setting expandedKey = (key||(key ^ {0x01, .., 0x01})||key ^
827 // {0x02,..,0x02}))[0:44].
828
829 gsec_aead_test_vector vec;
830
831 // Derived from NIST test vector 1
832 uint8_t nonce_0[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
833 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
834 uint8_t aad_0[1] = {};
835 uint8_t key_0[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
836 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
837 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2,
838 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2};
839 uint8_t plaintext_0[1] = {};
840 uint8_t ciphertext_0[] = {0x85, 0xE8, 0x73, 0xE0, 0x2, 0xF6, 0xEB, 0xDC,
841 0x40, 0x60, 0x95, 0x4E, 0xB8, 0x67, 0x55, 0x8};
842 vec = {nonce_0, aad_0, key_0, plaintext_0, ciphertext_0, 12, 0, 44, 0, 16};
843 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
844
845 // Derived from NIST test vector 2
846 uint8_t nonce_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
847 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
848 uint8_t aad_1[1] = {};
849 uint8_t key_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
850 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1,
851 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x1, 0x2,
852 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2, 0x2};
853 uint8_t plaintext_1[] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0,
854 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0};
855 uint8_t ciphertext_1[] = {0x51, 0xE9, 0xA8, 0xCB, 0x23, 0xCA, 0x25, 0x12,
856 0xC8, 0x25, 0x6A, 0xFF, 0xF8, 0xE7, 0x2D, 0x68,
857 0x1A, 0xCA, 0x19, 0xA1, 0x14, 0x8A, 0xC1, 0x15,
858 0xE8, 0x3D, 0xF4, 0x88, 0x8C, 0xC0, 0xD, 0x11};
859 vec = {nonce_1, aad_1, key_1, plaintext_1, ciphertext_1, 12, 0, 44, 16, 32};
860 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
861
862 // Derived from NIST test vector 3
863 uint8_t nonce_2[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE,
864 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88};
865 uint8_t aad_2[1] = {};
866 uint8_t key_2[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D,
867 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE,
868 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E,
869 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90,
870 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96};
871 uint8_t plaintext_2[] = {
872 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9,
873 0xC5, 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34,
874 0xF7, 0xDA, 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C,
875 0x3C, 0xC, 0x95, 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24,
876 0x49, 0xA6, 0xB5, 0x25, 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6,
877 0x57, 0xBA, 0x63, 0x7B, 0x39, 0x1A, 0xAF, 0xD2, 0x55};
878 uint8_t ciphertext_2[] = {
879 0x10, 0x18, 0xED, 0x5A, 0x14, 0x2, 0xA8, 0x65, 0x16, 0xD6, 0x57, 0x6D,
880 0x70, 0xB2, 0xFF, 0xCC, 0xCA, 0x26, 0x1B, 0x94, 0xDF, 0x88, 0xB5, 0x8F,
881 0x53, 0xB6, 0x4D, 0xFB, 0xA4, 0x35, 0xD1, 0x8B, 0x2F, 0x6E, 0x3B, 0x78,
882 0x69, 0xF9, 0x35, 0x3D, 0x4A, 0xC8, 0xCF, 0x9, 0xAF, 0xB1, 0x66, 0x3D,
883 0xAA, 0x7B, 0x40, 0x17, 0xE6, 0xFC, 0x2C, 0x17, 0x7C, 0xC, 0x8, 0x7C,
884 0xD, 0xF1, 0x16, 0x21, 0x29, 0x95, 0x22, 0x13, 0xCE, 0xE1, 0xBC, 0x6E,
885 0x9C, 0x84, 0x95, 0xDD, 0x70, 0x5E, 0x1F, 0x3D};
886 vec = {nonce_2, aad_2, key_2, plaintext_2, ciphertext_2, 12, 0, 44, 64, 80};
887 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
888
889 // Derived from NIST test vector 4
890 uint8_t nonce_3[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE,
891 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88};
892 uint8_t aad_3[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE,
893 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD,
894 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2};
895 uint8_t key_3[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D,
896 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE,
897 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E,
898 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90,
899 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96};
900 uint8_t plaintext_3[] = {
901 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5,
902 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA,
903 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95,
904 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25,
905 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39};
906 uint8_t ciphertext_3[] = {
907 0x10, 0x18, 0xED, 0x5A, 0x14, 0x2, 0xA8, 0x65, 0x16, 0xD6, 0x57,
908 0x6D, 0x70, 0xB2, 0xFF, 0xCC, 0xCA, 0x26, 0x1B, 0x94, 0xDF, 0x88,
909 0xB5, 0x8F, 0x53, 0xB6, 0x4D, 0xFB, 0xA4, 0x35, 0xD1, 0x8B, 0x2F,
910 0x6E, 0x3B, 0x78, 0x69, 0xF9, 0x35, 0x3D, 0x4A, 0xC8, 0xCF, 0x9,
911 0xAF, 0xB1, 0x66, 0x3D, 0xAA, 0x7B, 0x40, 0x17, 0xE6, 0xFC, 0x2C,
912 0x17, 0x7C, 0xC, 0x8, 0x7C, 0x47, 0x64, 0x56, 0x5D, 0x7, 0x7E,
913 0x91, 0x24, 0x0, 0x1D, 0xDB, 0x27, 0xFC, 0x8, 0x48, 0xC5};
914 vec = {nonce_3, aad_3, key_3, plaintext_3, ciphertext_3, 12, 20, 44, 60, 76};
915 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
916
917 // Derived from adapted NIST test vector 4 for KDF counter boundary (flip
918 // nonce bit 15)
919 uint8_t nonce_4[] = {0xCA, 0x7E, 0xBA, 0xBE, 0xFA, 0xCE,
920 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88};
921 uint8_t aad_4[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE,
922 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD,
923 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2};
924 uint8_t key_4[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D,
925 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE,
926 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E,
927 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90,
928 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96};
929 uint8_t plaintext_4[] = {
930 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5,
931 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA,
932 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95,
933 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25,
934 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39};
935 uint8_t ciphertext_4[] = {
936 0xE6, 0x50, 0xD3, 0xC0, 0xFB, 0x87, 0x93, 0x27, 0xF2, 0xD0, 0x32,
937 0x87, 0xFA, 0x93, 0xCD, 0x7, 0x34, 0x2B, 0x13, 0x62, 0x15, 0xAD,
938 0xBC, 0xA0, 0xC, 0x3B, 0xD5, 0x9, 0x9E, 0xC4, 0x18, 0x32, 0xB1,
939 0xD1, 0x8E, 0x4, 0x23, 0xED, 0x26, 0xBB, 0x12, 0xC6, 0xCD, 0x9,
940 0xDE, 0xBB, 0x29, 0x23, 0xA, 0x94, 0xC0, 0xCE, 0xE1, 0x59, 0x3,
941 0x65, 0x6F, 0x85, 0xED, 0xB6, 0xFC, 0x50, 0x9B, 0x1B, 0x28, 0x21,
942 0x63, 0x82, 0x17, 0x2E, 0xCB, 0xCC, 0x31, 0xE1, 0xE9, 0xB1};
943 vec = {nonce_4, aad_4, key_4, plaintext_4, ciphertext_4, 12, 20, 44, 60, 76};
944 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
945
946 // Derived from adapted NIST test vector 4 for KDF counter boundary (flip
947 // nonce bit 16)
948 uint8_t nonce_5[] = {0xCA, 0xFE, 0xBB, 0xBE, 0xFA, 0xCE,
949 0xDB, 0xAD, 0xDE, 0xCA, 0xF8, 0x88};
950 uint8_t aad_5[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE,
951 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD,
952 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2};
953 uint8_t key_5[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D,
954 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE,
955 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E,
956 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90,
957 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96};
958 uint8_t plaintext_5[] = {
959 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5,
960 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA,
961 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95,
962 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25,
963 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39};
964 uint8_t ciphertext_5[] = {
965 0xC0, 0x12, 0x1E, 0x6C, 0x95, 0x4D, 0x7, 0x67, 0xF9, 0x66, 0x30,
966 0xC3, 0x34, 0x50, 0x99, 0x97, 0x91, 0xB2, 0xDA, 0x2A, 0xD0, 0x5C,
967 0x41, 0x90, 0x16, 0x9C, 0xCA, 0xD9, 0xAC, 0x86, 0xFF, 0x1C, 0x72,
968 0x1E, 0x3D, 0x82, 0xF2, 0xAD, 0x22, 0xAB, 0x46, 0x3B, 0xAB, 0x4A,
969 0x7, 0x54, 0xB7, 0xDD, 0x68, 0xCA, 0x4D, 0xE7, 0xEA, 0x25, 0x31,
970 0xB6, 0x25, 0xED, 0xA0, 0x1F, 0x89, 0x31, 0x2B, 0x2A, 0xB9, 0x57,
971 0xD5, 0xC7, 0xF8, 0x56, 0x8D, 0xD9, 0x5F, 0xCD, 0xCD, 0x1F};
972 vec = {nonce_5, aad_5, key_5, plaintext_5, ciphertext_5, 12, 20, 44, 60, 76};
973 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
974
975 // Derived from adapted NIST test vector 4 for KDF counter boundary (flip
976 // nonce bit 63)
977 uint8_t nonce_6[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE,
978 0xDB, 0x2D, 0xDE, 0xCA, 0xF8, 0x88};
979 uint8_t aad_6[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE,
980 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD,
981 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2};
982 uint8_t key_6[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D,
983 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE,
984 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E,
985 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90,
986 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96};
987 uint8_t plaintext_6[] = {
988 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5,
989 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA,
990 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95,
991 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25,
992 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39};
993 uint8_t ciphertext_6[] = {
994 0x8A, 0xF3, 0x7E, 0xA5, 0x68, 0x4A, 0x4D, 0x81, 0xD4, 0xFD, 0x81,
995 0x72, 0x61, 0xFD, 0x97, 0x43, 0x9, 0x9E, 0x7E, 0x6A, 0x2, 0x5E,
996 0xAA, 0xCF, 0x8E, 0x54, 0xB1, 0x24, 0xFB, 0x57, 0x43, 0x14, 0x9E,
997 0x5, 0xCB, 0x89, 0xF4, 0xA4, 0x94, 0x67, 0xFE, 0x2E, 0x5E, 0x59,
998 0x65, 0xF2, 0x9A, 0x19, 0xF9, 0x94, 0x16, 0xB0, 0x1, 0x6B, 0x54,
999 0x58, 0x5D, 0x12, 0x55, 0x37, 0x83, 0xBA, 0x59, 0xE9, 0xF7, 0x82,
1000 0xE8, 0x2E, 0x9, 0x7C, 0x33, 0x6B, 0xF7, 0x98, 0x9F, 0x8};
1001 vec = {nonce_6, aad_6, key_6, plaintext_6, ciphertext_6, 12, 20, 44, 60, 76};
1002 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1003
1004 // Derived from adapted NIST test vector 4 for KDF counter boundary (flip
1005 // nonce bit 64)
1006 uint8_t nonce_7[] = {0xCA, 0xFE, 0xBA, 0xBE, 0xFA, 0xCE,
1007 0xDB, 0xAD, 0xDF, 0xCA, 0xF8, 0x88};
1008 uint8_t aad_7[] = {0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD, 0xBE,
1009 0xEF, 0xFE, 0xED, 0xFA, 0xCE, 0xDE, 0xAD,
1010 0xBE, 0xEF, 0xAB, 0xAD, 0xDA, 0xD2};
1011 uint8_t key_7[] = {0xFE, 0xFF, 0xE9, 0x92, 0x86, 0x65, 0x73, 0x1C, 0x6D,
1012 0x6A, 0x8F, 0x94, 0x67, 0x30, 0x83, 0x8, 0xFF, 0xFE,
1013 0xE8, 0x93, 0x87, 0x64, 0x72, 0x1D, 0x6C, 0x6B, 0x8E,
1014 0x95, 0x66, 0x31, 0x82, 0x9, 0xFC, 0xFD, 0xEB, 0x90,
1015 0x84, 0x67, 0x71, 0x1E, 0x6F, 0x68, 0x8D, 0x96};
1016 uint8_t plaintext_7[] = {
1017 0xD9, 0x31, 0x32, 0x25, 0xF8, 0x84, 0x6, 0xE5, 0xA5, 0x59, 0x9, 0xC5,
1018 0xAF, 0xF5, 0x26, 0x9A, 0x86, 0xA7, 0xA9, 0x53, 0x15, 0x34, 0xF7, 0xDA,
1019 0x2E, 0x4C, 0x30, 0x3D, 0x8A, 0x31, 0x8A, 0x72, 0x1C, 0x3C, 0xC, 0x95,
1020 0x95, 0x68, 0x9, 0x53, 0x2F, 0xCF, 0xE, 0x24, 0x49, 0xA6, 0xB5, 0x25,
1021 0xB1, 0x6A, 0xED, 0xF5, 0xAA, 0xD, 0xE6, 0x57, 0xBA, 0x63, 0x7B, 0x39};
1022 uint8_t ciphertext_7[] = {
1023 0xFB, 0xD5, 0x28, 0x44, 0x8D, 0x3, 0x46, 0xBF, 0xA8, 0x78, 0x63,
1024 0x48, 0x64, 0xD4, 0x7, 0xA3, 0x5A, 0x3, 0x9D, 0xE9, 0xDB, 0x2F,
1025 0x1F, 0xEB, 0x8E, 0x96, 0x5B, 0x3A, 0xE9, 0x35, 0x6C, 0xE6, 0x28,
1026 0x94, 0x41, 0xD7, 0x7F, 0x8F, 0xD, 0xF2, 0x94, 0x89, 0x1F, 0x37,
1027 0xEA, 0x43, 0x8B, 0x22, 0x3E, 0x3B, 0xF2, 0xBD, 0xC5, 0x3D, 0x4C,
1028 0x5A, 0x74, 0xFB, 0x68, 0xB, 0xB3, 0x12, 0xA8, 0xDE, 0xC6, 0xF7,
1029 0x25, 0x2C, 0xBC, 0xD7, 0xF5, 0x79, 0x97, 0x50, 0xAD, 0x78};
1030 vec = {nonce_7, aad_7, key_7, plaintext_7, ciphertext_7, 12, 20, 44, 60, 76};
1031 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1032 }
1033
gsec_test_do_vector_tests_rekey_ieee()1034 static void gsec_test_do_vector_tests_rekey_ieee() {
1035 // IEEE vectors from:
1036 // http://www.ieee802.org/1/files/public/docs2011/bn-randall-test-vectors-0511-v1.pdf
1037 //
1038 // Key expanded by setting expandedKey = (key||(key ^ {0x01, .., 0x01})||key ^
1039 // {0x02,..,0x02}))[0:44].
1040
1041 gsec_aead_test_vector vec;
1042
1043 // Derived from IEEE 2.1.1 54-byte auth
1044 uint8_t nonce_8[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89,
1045 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65};
1046 uint8_t aad_8[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, 0xD, 0x46, 0xDF,
1047 0x99, 0x8D, 0x88, 0xE5, 0x22, 0x2A, 0xB2, 0xC2, 0x84, 0x65,
1048 0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81, 0x8, 0x0,
1049 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
1050 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
1051 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
1052 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x1};
1053 uint8_t key_8[] = {0xAD, 0x7A, 0x2B, 0xD0, 0x3E, 0xAC, 0x83, 0x5A, 0x6F,
1054 0x62, 0xF, 0xDC, 0xB5, 0x6, 0xB3, 0x45, 0xAC, 0x7B,
1055 0x2A, 0xD1, 0x3F, 0xAD, 0x82, 0x5B, 0x6E, 0x63, 0xE,
1056 0xDD, 0xB4, 0x7, 0xB2, 0x44, 0xAF, 0x78, 0x29, 0xD2,
1057 0x3C, 0xAE, 0x81, 0x58, 0x6D, 0x60, 0xD, 0xDE};
1058 uint8_t plaintext_8[1] = {};
1059 uint8_t ciphertext_8[] = {0x3E, 0xA0, 0xB5, 0x84, 0xF3, 0xC8, 0x5E, 0x93,
1060 0xF9, 0x32, 0xE, 0xA5, 0x91, 0x69, 0x9E, 0xFB};
1061 vec = {nonce_8, aad_8, key_8, plaintext_8, ciphertext_8, 12, 70, 44, 0, 16};
1062 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1063
1064 // Derived from IEEE 2.1.2 54-byte auth
1065 uint8_t nonce_9[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89,
1066 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65};
1067 uint8_t aad_9[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A, 0xD, 0x46, 0xDF,
1068 0x99, 0x8D, 0x88, 0xE5, 0x22, 0x2A, 0xB2, 0xC2, 0x84, 0x65,
1069 0x12, 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81, 0x8, 0x0,
1070 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
1071 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
1072 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
1073 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x1};
1074 uint8_t key_9[] = {0xE3, 0xC0, 0x8A, 0x8F, 0x6, 0xC6, 0xE3, 0xAD, 0x95,
1075 0xA7, 0x5, 0x57, 0xB2, 0x3F, 0x75, 0x48, 0x3C, 0xE3,
1076 0x30, 0x21, 0xA9, 0xC7, 0x2B, 0x70, 0x25, 0x66, 0x62,
1077 0x4, 0xC6, 0x9C, 0xB, 0x72, 0xE1, 0xC2, 0x88, 0x8D,
1078 0x4, 0xC4, 0xE1, 0xAF, 0x97, 0xA5, 0x7, 0x55};
1079 uint8_t plaintext_9[1] = {};
1080 uint8_t ciphertext_9[] = {0x29, 0x4E, 0x2, 0x8B, 0xF1, 0xFE, 0x6F, 0x14,
1081 0xC4, 0xE8, 0xF7, 0x30, 0x5C, 0x93, 0x3E, 0xB5};
1082 vec = {nonce_9, aad_9, key_9, plaintext_9, ciphertext_9, 12, 70, 44, 0, 16};
1083 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1084
1085 // Derived from IEEE 2.2.1 60-byte crypt
1086 uint8_t nonce_10[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89,
1087 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65};
1088 uint8_t aad_10[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A,
1089 0xD, 0x46, 0xDF, 0x99, 0x8D, 0x88, 0xE5,
1090 0x2E, 0x0, 0xB2, 0xC2, 0x84, 0x65, 0x12,
1091 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81};
1092 uint8_t key_10[] = {0xAD, 0x7A, 0x2B, 0xD0, 0x3E, 0xAC, 0x83, 0x5A, 0x6F,
1093 0x62, 0xF, 0xDC, 0xB5, 0x6, 0xB3, 0x45, 0xAC, 0x7B,
1094 0x2A, 0xD1, 0x3F, 0xAD, 0x82, 0x5B, 0x6E, 0x63, 0xE,
1095 0xDD, 0xB4, 0x7, 0xB2, 0x44, 0xAF, 0x78, 0x29, 0xD2,
1096 0x3C, 0xAE, 0x81, 0x58, 0x6D, 0x60, 0xD, 0xDE};
1097 uint8_t plaintext_10[] = {
1098 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
1099 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
1100 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
1101 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x2};
1102 uint8_t ciphertext_10[] = {
1103 0xDB, 0x3D, 0x25, 0x71, 0x9C, 0x6B, 0xA, 0x3C, 0xA6, 0x14, 0x5C,
1104 0x15, 0x9D, 0x5C, 0x6E, 0xD9, 0xAF, 0xF9, 0xC6, 0xE0, 0xB7, 0x9F,
1105 0x17, 0x1, 0x9E, 0xA9, 0x23, 0xB8, 0x66, 0x5D, 0xDF, 0x52, 0x13,
1106 0x7A, 0xD6, 0x11, 0xF0, 0xD1, 0xBF, 0x41, 0x7A, 0x7C, 0xA8, 0x5E,
1107 0x45, 0xAF, 0xE1, 0x6, 0xFF, 0x9C, 0x75, 0x69, 0xD3, 0x35, 0xD0,
1108 0x86, 0xAE, 0x6C, 0x3, 0xF0, 0x9, 0x87, 0xCC, 0xD6};
1109 vec = {nonce_10, aad_10, key_10, plaintext_10, ciphertext_10,
1110 12, 28, 44, 48, 64};
1111 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1112
1113 // Derived from IEEE 2.2.2 60-byte crypt
1114 uint8_t nonce_11[] = {0x12, 0x15, 0x35, 0x24, 0xC0, 0x89,
1115 0x5E, 0x81, 0xB2, 0xC2, 0x84, 0x65};
1116 uint8_t aad_11[] = {0xD6, 0x9, 0xB1, 0xF0, 0x56, 0x63, 0x7A,
1117 0xD, 0x46, 0xDF, 0x99, 0x8D, 0x88, 0xE5,
1118 0x2E, 0x0, 0xB2, 0xC2, 0x84, 0x65, 0x12,
1119 0x15, 0x35, 0x24, 0xC0, 0x89, 0x5E, 0x81};
1120 uint8_t key_11[] = {0xE3, 0xC0, 0x8A, 0x8F, 0x6, 0xC6, 0xE3, 0xAD, 0x95,
1121 0xA7, 0x5, 0x57, 0xB2, 0x3F, 0x75, 0x48, 0x3C, 0xE3,
1122 0x30, 0x21, 0xA9, 0xC7, 0x2B, 0x70, 0x25, 0x66, 0x62,
1123 0x4, 0xC6, 0x9C, 0xB, 0x72, 0xE1, 0xC2, 0x88, 0x8D,
1124 0x4, 0xC4, 0xE1, 0xAF, 0x97, 0xA5, 0x7, 0x55};
1125 uint8_t plaintext_11[] = {
1126 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
1127 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
1128 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30,
1129 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x2};
1130 uint8_t ciphertext_11[] = {
1131 0x16, 0x41, 0xF2, 0x8E, 0xC1, 0x3A, 0xFC, 0xC8, 0xF7, 0x90, 0x33,
1132 0x89, 0x78, 0x72, 0x1, 0x5, 0x16, 0x44, 0x91, 0x49, 0x33, 0xE9,
1133 0x20, 0x2B, 0xB9, 0xD0, 0x6A, 0xA0, 0x20, 0xC2, 0xA6, 0x7E, 0xF5,
1134 0x1D, 0xFE, 0x7B, 0xC0, 0xA, 0x85, 0x6C, 0x55, 0xB8, 0xF8, 0x13,
1135 0x3E, 0x77, 0xF6, 0x59, 0x13, 0x25, 0x2, 0xBA, 0xD6, 0x3F, 0x57,
1136 0x13, 0xD5, 0x7D, 0xC, 0x11, 0xE0, 0xF8, 0x71, 0xED};
1137 vec = {nonce_11, aad_11, key_11, plaintext_11, ciphertext_11,
1138 12, 28, 44, 48, 64};
1139 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1140
1141 // Derived from IEEE 2.3.1 60-byte auth
1142 uint8_t nonce_12[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D,
1143 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED};
1144 uint8_t aad_12[] = {
1145 0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D,
1146 0x88, 0xE5, 0x40, 0x0, 0x76, 0xD4, 0x57, 0xED, 0x8, 0x0, 0xF, 0x10,
1147 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
1148 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
1149 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34,
1150 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x3};
1151 uint8_t key_12[] = {0x7, 0x1B, 0x11, 0x3B, 0xC, 0xA7, 0x43, 0xFE, 0xCC,
1152 0xCF, 0x3D, 0x5, 0x1F, 0x73, 0x73, 0x82, 0x6, 0x1A,
1153 0x10, 0x3A, 0xD, 0xA6, 0x42, 0xFF, 0xCD, 0xCE, 0x3C,
1154 0x4, 0x1E, 0x72, 0x72, 0x83, 0x5, 0x19, 0x13, 0x39,
1155 0xE, 0xA5, 0x41, 0xFC, 0xCE, 0xCD, 0x3F, 0x7};
1156 uint8_t plaintext_12[1] = {};
1157 uint8_t ciphertext_12[] = {0x58, 0x83, 0x7A, 0x10, 0x56, 0x2B, 0xF, 0x1F,
1158 0x8E, 0xDB, 0xE5, 0x8C, 0xA5, 0x58, 0x11, 0xD3};
1159 vec = {nonce_12, aad_12, key_12, plaintext_12, ciphertext_12, 12, 68,
1160 44, 0, 16};
1161 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1162
1163 // Derived from IEEE 2.3.2 60-byte auth
1164 uint8_t nonce_13[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D,
1165 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED};
1166 uint8_t aad_13[] = {
1167 0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D,
1168 0x88, 0xE5, 0x40, 0x0, 0x76, 0xD4, 0x57, 0xED, 0x8, 0x0, 0xF, 0x10,
1169 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C,
1170 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
1171 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34,
1172 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x0, 0x3};
1173 uint8_t key_13[] = {0x69, 0x1D, 0x3E, 0xE9, 0x9, 0xD7, 0xF5, 0x41, 0x67,
1174 0xFD, 0x1C, 0xA0, 0xB5, 0xD7, 0x69, 0x8, 0x1F, 0x2B,
1175 0xDE, 0x1A, 0xEE, 0x65, 0x5F, 0xDB, 0xAB, 0x80, 0xBD,
1176 0x52, 0x95, 0xAE, 0x6B, 0xE7, 0x6B, 0x1F, 0x3C, 0xEB,
1177 0xB, 0xD5, 0xF7, 0x43, 0x65, 0xFF, 0x1E, 0xA2};
1178 uint8_t plaintext_13[1] = {};
1179 uint8_t ciphertext_13[] = {0xC2, 0x72, 0x2F, 0xF6, 0xCA, 0x29, 0xA2, 0x57,
1180 0x71, 0x8A, 0x52, 0x9D, 0x1F, 0xC, 0x6A, 0x3B};
1181 vec = {nonce_13, aad_13, key_13, plaintext_13, ciphertext_13, 12, 68,
1182 44, 0, 16};
1183 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1184
1185 // Derived from IEEE 2.4.1 54-byte crypt
1186 uint8_t nonce_14[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D,
1187 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED};
1188 uint8_t aad_14[] = {0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0,
1189 0x76, 0x1E, 0x8D, 0xCD, 0x3D, 0x88, 0xE5,
1190 0x4C, 0x2A, 0x76, 0xD4, 0x57, 0xED};
1191 uint8_t key_14[] = {0x7, 0x1B, 0x11, 0x3B, 0xC, 0xA7, 0x43, 0xFE, 0xCC,
1192 0xCF, 0x3D, 0x5, 0x1F, 0x73, 0x73, 0x82, 0x6, 0x1A,
1193 0x10, 0x3A, 0xD, 0xA6, 0x42, 0xFF, 0xCD, 0xCE, 0x3C,
1194 0x4, 0x1E, 0x72, 0x72, 0x83, 0x5, 0x19, 0x13, 0x39,
1195 0xE, 0xA5, 0x41, 0xFC, 0xCE, 0xCD, 0x3F, 0x7};
1196 uint8_t plaintext_14[] = {
1197 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1198 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
1199 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
1200 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x4};
1201 uint8_t ciphertext_14[] = {
1202 0xFD, 0x96, 0xB7, 0x15, 0xB9, 0x3A, 0x13, 0x34, 0x6A, 0xF5, 0x1E, 0x8A,
1203 0xCD, 0xF7, 0x92, 0xCD, 0xC7, 0xB2, 0x68, 0x6F, 0x85, 0x74, 0xC7, 0xE,
1204 0x6B, 0xC, 0xBF, 0x16, 0x29, 0x1D, 0xED, 0x42, 0x7A, 0xD7, 0x3F, 0xEC,
1205 0x48, 0xCD, 0x29, 0x8E, 0x5, 0x28, 0xA1, 0xF4, 0xC6, 0x44, 0xA9, 0x49,
1206 0xFC, 0x31, 0xDC, 0x92, 0x79, 0x70, 0x6D, 0xDB, 0xA3, 0x3F};
1207 vec = {nonce_14, aad_14, key_14, plaintext_14, ciphertext_14,
1208 12, 20, 44, 42, 58};
1209 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1210
1211 // Derived from IEEE 2.4.2 54-byte crypt
1212 uint8_t nonce_15[] = {0xF0, 0x76, 0x1E, 0x8D, 0xCD, 0x3D,
1213 0x0, 0x1, 0x76, 0xD4, 0x57, 0xED};
1214 uint8_t aad_15[] = {0xE2, 0x1, 0x6, 0xD7, 0xCD, 0xD, 0xF0,
1215 0x76, 0x1E, 0x8D, 0xCD, 0x3D, 0x88, 0xE5,
1216 0x4C, 0x2A, 0x76, 0xD4, 0x57, 0xED};
1217 uint8_t key_15[] = {0x69, 0x1D, 0x3E, 0xE9, 0x9, 0xD7, 0xF5, 0x41, 0x67,
1218 0xFD, 0x1C, 0xA0, 0xB5, 0xD7, 0x69, 0x8, 0x1F, 0x2B,
1219 0xDE, 0x1A, 0xEE, 0x65, 0x5F, 0xDB, 0xAB, 0x80, 0xBD,
1220 0x52, 0x95, 0xAE, 0x6B, 0xE7, 0x6B, 0x1F, 0x3C, 0xEB,
1221 0xB, 0xD5, 0xF7, 0x43, 0x65, 0xFF, 0x1E, 0xA2};
1222 uint8_t plaintext_15[] = {
1223 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1224 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
1225 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
1226 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x0, 0x4};
1227 uint8_t ciphertext_15[] = {
1228 0xB6, 0x8F, 0x63, 0x0, 0xC2, 0xE9, 0xAE, 0x83, 0x3B, 0xDC, 0x7, 0xE,
1229 0x24, 0x2, 0x1A, 0x34, 0x77, 0x11, 0x8E, 0x78, 0xCC, 0xF8, 0x4E, 0x11,
1230 0xA4, 0x85, 0xD8, 0x61, 0x47, 0x6C, 0x30, 0xF, 0x17, 0x53, 0x53, 0xD5,
1231 0xCD, 0xF9, 0x20, 0x8, 0xA4, 0xF8, 0x78, 0xE6, 0xCC, 0x35, 0x77, 0x76,
1232 0x80, 0x85, 0xC5, 0xA, 0xE, 0x98, 0xFD, 0xA6, 0xCB, 0xB8};
1233 vec = {nonce_15, aad_15, key_15, plaintext_15, ciphertext_15,
1234 12, 20, 44, 42, 58};
1235 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1236
1237 // Derived from IEEE 2.5.1 65-byte auth
1238 uint8_t nonce_16[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37,
1239 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12};
1240 uint8_t aad_16[] = {
1241 0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, 0xE5, 0xBB, 0xD2, 0x72, 0x77,
1242 0x88, 0xE5, 0x23, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, 0xFD, 0xE9, 0xF9,
1243 0xE3, 0x37, 0x24, 0xC6, 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14,
1244 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
1245 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
1246 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1247 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x0, 0x5};
1248 uint8_t key_16[] = {0x1, 0x3F, 0xE0, 0xB, 0x5F, 0x11, 0xBE, 0x7F, 0x86,
1249 0x6D, 0xC, 0xBB, 0xC5, 0x5A, 0x7A, 0x90, 0x0, 0x3E,
1250 0xE1, 0xA, 0x5E, 0x10, 0xBF, 0x7E, 0x87, 0x6C, 0xD,
1251 0xBA, 0xC4, 0x5B, 0x7B, 0x91, 0x3, 0x3D, 0xE2, 0x9,
1252 0x5D, 0x13, 0xBC, 0x7D, 0x84, 0x6F, 0xE, 0xB9};
1253 uint8_t plaintext_16[1] = {};
1254 uint8_t ciphertext_16[] = {0xCC, 0xA2, 0xE, 0xEC, 0xDA, 0x62, 0x83, 0xF0,
1255 0x9B, 0xB3, 0x54, 0x3D, 0xD9, 0x9E, 0xDB, 0x9B};
1256 vec = {nonce_16, aad_16, key_16, plaintext_16, ciphertext_16, 12, 81,
1257 44, 0, 16};
1258 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1259
1260 // Derived from IEEE 2.5.2 65-byte auth
1261 uint8_t nonce_17[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37,
1262 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12};
1263 uint8_t aad_17[] = {
1264 0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6, 0xE5, 0xBB, 0xD2, 0x72, 0x77,
1265 0x88, 0xE5, 0x23, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C, 0xFD, 0xE9, 0xF9,
1266 0xE3, 0x37, 0x24, 0xC6, 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14,
1267 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
1268 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C,
1269 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1270 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x0, 0x5};
1271 uint8_t key_17[] = {0x83, 0xC0, 0x93, 0xB5, 0x8D, 0xE7, 0xFF, 0xE1, 0xC0,
1272 0xDA, 0x92, 0x6A, 0xC4, 0x3F, 0xB3, 0x60, 0x9A, 0xC1,
1273 0xC8, 0xF, 0xEE, 0x1B, 0x62, 0x44, 0x97, 0xEF, 0x94,
1274 0x2E, 0x2F, 0x79, 0xA8, 0x23, 0x81, 0xC2, 0x91, 0xB7,
1275 0x8F, 0xE5, 0xFD, 0xE3, 0xC2, 0xD8, 0x90, 0x68};
1276 uint8_t plaintext_17[1] = {};
1277 uint8_t ciphertext_17[] = {0xB2, 0x32, 0xCC, 0x1D, 0xA5, 0x11, 0x7B, 0xF1,
1278 0x50, 0x3, 0x73, 0x4F, 0xA5, 0x99, 0xD2, 0x71};
1279 vec = {nonce_17, aad_17, key_17, plaintext_17, ciphertext_17, 12, 81,
1280 44, 0, 16};
1281 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1282
1283 // Derived from IEEE 2.6.1 61-byte crypt
1284 uint8_t nonce_18[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37,
1285 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12};
1286 uint8_t aad_18[] = {0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6,
1287 0xE5, 0xBB, 0xD2, 0x72, 0x77, 0x88, 0xE5,
1288 0x2F, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C,
1289 0xFD, 0xE9, 0xF9, 0xE3, 0x37, 0x24, 0xC6};
1290 uint8_t key_18[] = {0x1, 0x3F, 0xE0, 0xB, 0x5F, 0x11, 0xBE, 0x7F, 0x86,
1291 0x6D, 0xC, 0xBB, 0xC5, 0x5A, 0x7A, 0x90, 0x0, 0x3E,
1292 0xE1, 0xA, 0x5E, 0x10, 0xBF, 0x7E, 0x87, 0x6C, 0xD,
1293 0xBA, 0xC4, 0x5B, 0x7B, 0x91, 0x3, 0x3D, 0xE2, 0x9,
1294 0x5D, 0x13, 0xBC, 0x7D, 0x84, 0x6F, 0xE, 0xB9};
1295 uint8_t plaintext_18[] = {
1296 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
1297 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
1298 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
1299 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34,
1300 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x0, 0x6};
1301 uint8_t ciphertext_18[] = {
1302 0xFF, 0x19, 0x10, 0xD3, 0x5A, 0xD7, 0xE5, 0x65, 0x78, 0x90, 0xC7,
1303 0xC5, 0x60, 0x14, 0x6F, 0xD0, 0x38, 0x70, 0x7F, 0x20, 0x4B, 0x66,
1304 0xED, 0xBC, 0x3D, 0x16, 0x1F, 0x8A, 0xCE, 0x24, 0x4B, 0x98, 0x59,
1305 0x21, 0x2, 0x3C, 0x43, 0x6E, 0x3A, 0x1C, 0x35, 0x32, 0xEC, 0xD5,
1306 0xD0, 0x9A, 0x5, 0x6D, 0x70, 0xBE, 0x58, 0x3F, 0xD, 0x10, 0x82,
1307 0x9D, 0x93, 0x87, 0xD0, 0x7D, 0x33, 0xD8, 0x72, 0xE4, 0x90};
1308 vec = {nonce_18, aad_18, key_18, plaintext_18, ciphertext_18,
1309 12, 28, 44, 49, 65};
1310 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1311
1312 // Derived from IEEE 2.6.2 61-byte crypt
1313 uint8_t nonce_19[] = {0x7C, 0xFD, 0xE9, 0xF9, 0xE3, 0x37,
1314 0x24, 0xC6, 0x89, 0x32, 0xD6, 0x12};
1315 uint8_t aad_19[] = {0x84, 0xC5, 0xD5, 0x13, 0xD2, 0xAA, 0xF6,
1316 0xE5, 0xBB, 0xD2, 0x72, 0x77, 0x88, 0xE5,
1317 0x2F, 0x0, 0x89, 0x32, 0xD6, 0x12, 0x7C,
1318 0xFD, 0xE9, 0xF9, 0xE3, 0x37, 0x24, 0xC6};
1319 uint8_t key_19[] = {0x83, 0xC0, 0x93, 0xB5, 0x8D, 0xE7, 0xFF, 0xE1, 0xC0,
1320 0xDA, 0x92, 0x6A, 0xC4, 0x3F, 0xB3, 0x60, 0x9A, 0xC1,
1321 0xC8, 0xF, 0xEE, 0x1B, 0x62, 0x44, 0x97, 0xEF, 0x94,
1322 0x2E, 0x2F, 0x79, 0xA8, 0x23, 0x81, 0xC2, 0x91, 0xB7,
1323 0x8F, 0xE5, 0xFD, 0xE3, 0xC2, 0xD8, 0x90, 0x68};
1324 uint8_t plaintext_19[] = {
1325 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
1326 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20,
1327 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A,
1328 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34,
1329 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x0, 0x6};
1330 uint8_t ciphertext_19[] = {
1331 0xD, 0xB4, 0xCF, 0x95, 0x6B, 0x5F, 0x97, 0xEC, 0xA4, 0xEA, 0xB8,
1332 0x2A, 0x69, 0x55, 0x30, 0x7F, 0x9A, 0xE0, 0x2A, 0x32, 0xDD, 0x7D,
1333 0x93, 0xF8, 0x3D, 0x66, 0xAD, 0x4, 0xE1, 0xCF, 0xDC, 0x51, 0x82,
1334 0xAD, 0x12, 0xAB, 0xDE, 0xA5, 0xBB, 0xB6, 0x19, 0xA1, 0xBD, 0x5F,
1335 0xB9, 0xA5, 0x73, 0x59, 0xF, 0xBA, 0x90, 0x8E, 0x9C, 0x7A, 0x46,
1336 0xC1, 0xF7, 0xBA, 0x9, 0x5, 0xD1, 0xB5, 0x5F, 0xFD, 0xA4};
1337 vec = {nonce_19, aad_19, key_19, plaintext_19, ciphertext_19,
1338 12, 28, 44, 49, 65};
1339 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1340
1341 // Derived from IEEE 2.7.1 79-byte crypt
1342 uint8_t nonce_20[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5,
1343 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C};
1344 uint8_t aad_20[] = {
1345 0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, 0xE8, 0xE2, 0xCA, 0x4E,
1346 0xC5, 0x88, 0xE5, 0x41, 0x0, 0x2E, 0x58, 0x49, 0x5C, 0x8, 0x0,
1347 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
1348 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
1349 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
1350 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
1351 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
1352 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x0, 0x7};
1353 uint8_t key_20[] = {0x88, 0xEE, 0x8, 0x7F, 0xD9, 0x5D, 0xA9, 0xFB, 0xF6,
1354 0x72, 0x5A, 0xA9, 0xD7, 0x57, 0xB0, 0xCD, 0x89, 0xEF,
1355 0x9, 0x7E, 0xD8, 0x5C, 0xA8, 0xFA, 0xF7, 0x73, 0x5B,
1356 0xA8, 0xD6, 0x56, 0xB1, 0xCC, 0x8A, 0xEC, 0xA, 0x7D,
1357 0xDB, 0x5F, 0xAB, 0xF9, 0xF4, 0x70, 0x58, 0xAB};
1358 uint8_t plaintext_20[1] = {};
1359 uint8_t ciphertext_20[] = {0x81, 0x3F, 0xE, 0x63, 0xF, 0x96, 0xFB, 0x2D,
1360 0x3, 0xF, 0x58, 0xD8, 0x3F, 0x5C, 0xDF, 0xD0};
1361 vec = {nonce_20, aad_20, key_20, plaintext_20, ciphertext_20, 12, 87,
1362 44, 0, 16};
1363 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1364
1365 // Derived from IEEE 2.7.2 79-byte crypt
1366 uint8_t nonce_21[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5,
1367 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C};
1368 uint8_t aad_21[] = {
1369 0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A, 0xE8, 0xE2, 0xCA, 0x4E,
1370 0xC5, 0x88, 0xE5, 0x41, 0x0, 0x2E, 0x58, 0x49, 0x5C, 0x8, 0x0,
1371 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
1372 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24,
1373 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
1374 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A,
1375 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
1376 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x0, 0x7};
1377 uint8_t key_21[] = {0x4C, 0x97, 0x3D, 0xBC, 0x73, 0x64, 0x62, 0x16, 0x74,
1378 0xF8, 0xB5, 0xB8, 0x9E, 0x5C, 0x15, 0x51, 0x1F, 0xCE,
1379 0xD9, 0x21, 0x64, 0x90, 0xFB, 0x1C, 0x1A, 0x2C, 0xAA,
1380 0xF, 0xFE, 0x4, 0x7, 0xE5, 0x4E, 0x95, 0x3F, 0xBE,
1381 0x71, 0x66, 0x60, 0x14, 0x76, 0xFA, 0xB7, 0xBA};
1382 uint8_t plaintext_21[1] = {};
1383 uint8_t ciphertext_21[] = {0x77, 0xE5, 0xA4, 0x4C, 0x21, 0xEB, 0x7, 0x18,
1384 0x8A, 0xAC, 0xBD, 0x74, 0xD1, 0x98, 0xE, 0x97};
1385 vec = {nonce_21, aad_21, key_21, plaintext_21, ciphertext_21, 12, 87,
1386 44, 0, 16};
1387 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1388
1389 // Derived from IEEE 2.8.1 61-byte crypt
1390 uint8_t nonce_22[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5,
1391 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C};
1392 uint8_t aad_22[] = {0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A,
1393 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, 0x88, 0xE5,
1394 0x4D, 0x0, 0x2E, 0x58, 0x49, 0x5C};
1395 uint8_t key_22[] = {0x88, 0xEE, 0x8, 0x7F, 0xD9, 0x5D, 0xA9, 0xFB, 0xF6,
1396 0x72, 0x5A, 0xA9, 0xD7, 0x57, 0xB0, 0xCD, 0x89, 0xEF,
1397 0x9, 0x7E, 0xD8, 0x5C, 0xA8, 0xFA, 0xF7, 0x73, 0x5B,
1398 0xA8, 0xD6, 0x56, 0xB1, 0xCC, 0x8A, 0xEC, 0xA, 0x7D,
1399 0xDB, 0x5F, 0xAB, 0xF9, 0xF4, 0x70, 0x58, 0xAB};
1400 uint8_t plaintext_22[] = {
1401 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1402 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
1403 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
1404 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1405 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43,
1406 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x0, 0x8};
1407 uint8_t ciphertext_22[] = {
1408 0x95, 0x8E, 0xC3, 0xF6, 0xD6, 0xA, 0xFE, 0xDA, 0x99, 0xEF, 0xD8, 0x88,
1409 0xF1, 0x75, 0xE5, 0xFC, 0xD4, 0xC8, 0x7B, 0x9B, 0xCC, 0x5C, 0x2F, 0x54,
1410 0x26, 0x25, 0x3A, 0x8B, 0x50, 0x62, 0x96, 0xC8, 0xC4, 0x33, 0x9, 0xAB,
1411 0x2A, 0xDB, 0x59, 0x39, 0x46, 0x25, 0x41, 0xD9, 0x5E, 0x80, 0x81, 0x1E,
1412 0x4, 0xE7, 0x6, 0xB1, 0x49, 0x8F, 0x2C, 0x40, 0x7C, 0x7F, 0xB2, 0x34,
1413 0xF8, 0xCC, 0x1, 0xA6, 0x47, 0x55, 0xE, 0xE6, 0xB5, 0x57, 0xB3, 0x5A,
1414 0x7E, 0x39, 0x45, 0x38, 0x18, 0x21, 0xF4};
1415 vec = {nonce_22, aad_22, key_22, plaintext_22, ciphertext_22,
1416 12, 20, 44, 63, 79};
1417 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1418
1419 // Derived from IEEE 2.8.2 61-byte crypt
1420 uint8_t nonce_23[] = {0x7A, 0xE8, 0xE2, 0xCA, 0x4E, 0xC5,
1421 0x0, 0x1, 0x2E, 0x58, 0x49, 0x5C};
1422 uint8_t aad_23[] = {0x68, 0xF2, 0xE7, 0x76, 0x96, 0xCE, 0x7A,
1423 0xE8, 0xE2, 0xCA, 0x4E, 0xC5, 0x88, 0xE5,
1424 0x4D, 0x0, 0x2E, 0x58, 0x49, 0x5C};
1425 uint8_t key_23[] = {0x4C, 0x97, 0x3D, 0xBC, 0x73, 0x64, 0x62, 0x16, 0x74,
1426 0xF8, 0xB5, 0xB8, 0x9E, 0x5C, 0x15, 0x51, 0x1F, 0xCE,
1427 0xD9, 0x21, 0x64, 0x90, 0xFB, 0x1C, 0x1A, 0x2C, 0xAA,
1428 0xF, 0xFE, 0x4, 0x7, 0xE5, 0x4E, 0x95, 0x3F, 0xBE,
1429 0x71, 0x66, 0x60, 0x14, 0x76, 0xFA, 0xB7, 0xBA};
1430 uint8_t plaintext_23[] = {
1431 0x8, 0x0, 0xF, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1432 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22,
1433 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D,
1434 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1435 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F, 0x40, 0x41, 0x42, 0x43,
1436 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x0, 0x8};
1437 uint8_t ciphertext_23[] = {
1438 0xB4, 0x4D, 0x7, 0x20, 0x11, 0xCD, 0x36, 0xD2, 0x72, 0xA9, 0xB7, 0xA9,
1439 0x8D, 0xB9, 0xAA, 0x90, 0xCB, 0xC5, 0xC6, 0x7B, 0x93, 0xDD, 0xCE, 0x67,
1440 0xC8, 0x54, 0x50, 0x32, 0x14, 0xE2, 0xE8, 0x96, 0xEC, 0x7E, 0x9D, 0xB6,
1441 0x49, 0xED, 0x4B, 0xCF, 0x6F, 0x85, 0xA, 0xAC, 0x2, 0x23, 0xD0, 0xCF,
1442 0x92, 0xC8, 0x3D, 0xB8, 0x7, 0x95, 0xC3, 0xA1, 0x7E, 0xCC, 0x12, 0x48,
1443 0xBB, 0x0, 0x59, 0x17, 0x12, 0xB1, 0xAE, 0x71, 0xE2, 0x68, 0x16, 0x41,
1444 0x96, 0x25, 0x21, 0x62, 0x81, 0xB, 0x0};
1445 vec = {nonce_23, aad_23, key_23, plaintext_23, ciphertext_23,
1446 12, 20, 44, 63, 79};
1447 gsec_test_verify_crypter_on_test_vector(&vec, /*rekey=*/true);
1448 }
1449
gsec_test_do_vector_tests_nist()1450 static void gsec_test_do_vector_tests_nist() {
1451 /**
1452 * From:
1453 * http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/
1454 * gcm-revised-spec.pdf
1455 */
1456
1457 /* Test vector 1 */
1458 gsec_aead_test_vector* test_vector_1;
1459 const uint8_t test_vector_1_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1460 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1461 0x00, 0x00, 0x00, 0x00};
1462 const uint8_t test_vector_1_nonce[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1463 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1464 const uint8_t test_vector_1_aad[1] = {};
1465 const uint8_t test_vector_1_plaintext[1] = {};
1466 const uint8_t test_vector_1_ciphertext_and_tag[] = {
1467 0x58, 0xe2, 0xfc, 0xce, 0xfa, 0x7e, 0x30, 0x61,
1468 0x36, 0x7f, 0x1d, 0x57, 0xa4, 0xe7, 0x45, 0x5a};
1469 gsec_aead_malloc_test_vector(
1470 &test_vector_1, test_vector_1_key,
1471 sizeof(test_vector_1_key) / sizeof(uint8_t), test_vector_1_nonce,
1472 sizeof(test_vector_1_nonce) / sizeof(uint8_t), test_vector_1_aad, 0,
1473 test_vector_1_plaintext, 0, test_vector_1_ciphertext_and_tag,
1474 sizeof(test_vector_1_ciphertext_and_tag) / sizeof(uint8_t));
1475 gsec_test_verify_crypter_on_test_vector(test_vector_1);
1476 gsec_aead_free_test_vector(test_vector_1);
1477
1478 /* Test vector 2 */
1479 gsec_aead_test_vector* test_vector_2;
1480 const uint8_t test_vector_2_key[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1481 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1482 0x00, 0x00, 0x00, 0x00};
1483 const uint8_t test_vector_2_nonce[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1484 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
1485 const uint8_t test_vector_2_aad[1] = {};
1486 const uint8_t test_vector_2_plaintext[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1487 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
1488 0x00, 0x00, 0x00, 0x00};
1489 const uint8_t test_vector_2_ciphertext_and_tag[] = {
1490 0x03, 0x88, 0xda, 0xce, 0x60, 0xb6, 0xa3, 0x92, 0xf3, 0x28, 0xc2,
1491 0xb9, 0x71, 0xb2, 0xfe, 0x78, 0xab, 0x6e, 0x47, 0xd4, 0x2c, 0xec,
1492 0x13, 0xbd, 0xf5, 0x3a, 0x67, 0xb2, 0x12, 0x57, 0xbd, 0xdf};
1493 gsec_aead_malloc_test_vector(
1494 &test_vector_2, test_vector_2_key,
1495 sizeof(test_vector_2_key) / sizeof(uint8_t), test_vector_2_nonce,
1496 sizeof(test_vector_2_nonce) / sizeof(uint8_t), test_vector_2_aad, 0,
1497 test_vector_2_plaintext,
1498 sizeof(test_vector_2_plaintext) / sizeof(uint8_t),
1499 test_vector_2_ciphertext_and_tag,
1500 sizeof(test_vector_2_ciphertext_and_tag) / sizeof(uint8_t));
1501 gsec_test_verify_crypter_on_test_vector(test_vector_2);
1502 gsec_aead_free_test_vector(test_vector_2);
1503
1504 /* Test vector 3 */
1505 gsec_aead_test_vector* test_vector_3;
1506 const uint8_t test_vector_3_key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65,
1507 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94,
1508 0x67, 0x30, 0x83, 0x08};
1509 const uint8_t test_vector_3_nonce[] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce,
1510 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88};
1511 const uint8_t test_vector_3_aad[1] = {};
1512 const uint8_t test_vector_3_plaintext[] = {
1513 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09,
1514 0xc5, 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34,
1515 0xf7, 0xda, 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c,
1516 0x3c, 0x0c, 0x95, 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24,
1517 0x49, 0xa6, 0xb5, 0x25, 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6,
1518 0x57, 0xba, 0x63, 0x7b, 0x39, 0x1a, 0xaf, 0xd2, 0x55};
1519 const uint8_t test_vector_3_ciphertext_and_tag[] = {
1520 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21, 0xb7,
1521 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02, 0xa4, 0xe0,
1522 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21, 0xd5, 0x14, 0xb2,
1523 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a, 0xac, 0x84, 0xaa, 0x05,
1524 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac, 0x97, 0x3d, 0x58, 0xe0, 0x91,
1525 0x47, 0x3f, 0x59, 0x85, 0x4d, 0x5c, 0x2a, 0xf3, 0x27, 0xcd, 0x64, 0xa6,
1526 0x2c, 0xf3, 0x5a, 0xbd, 0x2b, 0xa6, 0xfa, 0xb4};
1527 gsec_aead_malloc_test_vector(
1528 &test_vector_3, test_vector_3_key,
1529 sizeof(test_vector_3_key) / sizeof(uint8_t), test_vector_3_nonce,
1530 sizeof(test_vector_3_nonce) / sizeof(uint8_t), test_vector_3_aad, 0,
1531 test_vector_3_plaintext,
1532 sizeof(test_vector_3_plaintext) / sizeof(uint8_t),
1533 test_vector_3_ciphertext_and_tag,
1534 sizeof(test_vector_3_ciphertext_and_tag) / sizeof(uint8_t));
1535 gsec_test_verify_crypter_on_test_vector(test_vector_3);
1536 gsec_aead_free_test_vector(test_vector_3);
1537
1538 /* Test vector 4 */
1539 gsec_aead_test_vector* test_vector_4;
1540 const uint8_t test_vector_4_key[] = {0xfe, 0xff, 0xe9, 0x92, 0x86, 0x65,
1541 0x73, 0x1c, 0x6d, 0x6a, 0x8f, 0x94,
1542 0x67, 0x30, 0x83, 0x08};
1543 const uint8_t test_vector_4_nonce[] = {0xca, 0xfe, 0xba, 0xbe, 0xfa, 0xce,
1544 0xdb, 0xad, 0xde, 0xca, 0xf8, 0x88};
1545 const uint8_t test_vector_4_aad[] = {0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad, 0xbe,
1546 0xef, 0xfe, 0xed, 0xfa, 0xce, 0xde, 0xad,
1547 0xbe, 0xef, 0xab, 0xad, 0xda, 0xd2};
1548 const uint8_t test_vector_4_plaintext[] = {
1549 0xd9, 0x31, 0x32, 0x25, 0xf8, 0x84, 0x06, 0xe5, 0xa5, 0x59, 0x09, 0xc5,
1550 0xaf, 0xf5, 0x26, 0x9a, 0x86, 0xa7, 0xa9, 0x53, 0x15, 0x34, 0xf7, 0xda,
1551 0x2e, 0x4c, 0x30, 0x3d, 0x8a, 0x31, 0x8a, 0x72, 0x1c, 0x3c, 0x0c, 0x95,
1552 0x95, 0x68, 0x09, 0x53, 0x2f, 0xcf, 0x0e, 0x24, 0x49, 0xa6, 0xb5, 0x25,
1553 0xb1, 0x6a, 0xed, 0xf5, 0xaa, 0x0d, 0xe6, 0x57, 0xba, 0x63, 0x7b, 0x39};
1554 const uint8_t test_vector_4_ciphertext_and_tag[] = {
1555 0x42, 0x83, 0x1e, 0xc2, 0x21, 0x77, 0x74, 0x24, 0x4b, 0x72, 0x21,
1556 0xb7, 0x84, 0xd0, 0xd4, 0x9c, 0xe3, 0xaa, 0x21, 0x2f, 0x2c, 0x02,
1557 0xa4, 0xe0, 0x35, 0xc1, 0x7e, 0x23, 0x29, 0xac, 0xa1, 0x2e, 0x21,
1558 0xd5, 0x14, 0xb2, 0x54, 0x66, 0x93, 0x1c, 0x7d, 0x8f, 0x6a, 0x5a,
1559 0xac, 0x84, 0xaa, 0x05, 0x1b, 0xa3, 0x0b, 0x39, 0x6a, 0x0a, 0xac,
1560 0x97, 0x3d, 0x58, 0xe0, 0x91, 0x5b, 0xc9, 0x4f, 0xbc, 0x32, 0x21,
1561 0xa5, 0xdb, 0x94, 0xfa, 0xe9, 0x5a, 0xe7, 0x12, 0x1a, 0x47};
1562 gsec_aead_malloc_test_vector(
1563 &test_vector_4, test_vector_4_key,
1564 sizeof(test_vector_4_key) / sizeof(uint8_t), test_vector_4_nonce,
1565 sizeof(test_vector_4_nonce) / sizeof(uint8_t), test_vector_4_aad,
1566 sizeof(test_vector_4_aad) / sizeof(uint8_t), test_vector_4_plaintext,
1567 sizeof(test_vector_4_plaintext) / sizeof(uint8_t),
1568 test_vector_4_ciphertext_and_tag,
1569 sizeof(test_vector_4_ciphertext_and_tag) / sizeof(uint8_t));
1570 gsec_test_verify_crypter_on_test_vector(test_vector_4);
1571 gsec_aead_free_test_vector(test_vector_4);
1572 }
1573
gsec_test_do_vector_tests_ieee()1574 static void gsec_test_do_vector_tests_ieee() {
1575 /**
1576 * From:
1577 * http://www.ieee802.org/1/files/public/docs2011/
1578 * bn-randall-test-vectors-0511-v1.pdf
1579 */
1580
1581 /* 2.1.1 54-byte auth */
1582 gsec_aead_test_vector* test_vector_5;
1583 const uint8_t test_vector_5_key[] = {0xad, 0x7a, 0x2b, 0xd0, 0x3e, 0xac,
1584 0x83, 0x5a, 0x6f, 0x62, 0x0f, 0xdc,
1585 0xb5, 0x06, 0xb3, 0x45};
1586 const uint8_t test_vector_5_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89,
1587 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65};
1588 const uint8_t test_vector_5_aad[] = {
1589 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, 0x99, 0x8d,
1590 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, 0x12, 0x15, 0x35, 0x24,
1591 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
1592 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
1593 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c,
1594 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x01};
1595 const uint8_t test_vector_5_plaintext[1] = {};
1596 const uint8_t test_vector_5_ciphertext_and_tag[] = {
1597 0xf0, 0x94, 0x78, 0xa9, 0xb0, 0x90, 0x07, 0xd0,
1598 0x6f, 0x46, 0xe9, 0xb6, 0xa1, 0xda, 0x25, 0xdd};
1599 gsec_aead_malloc_test_vector(
1600 &test_vector_5, test_vector_5_key,
1601 sizeof(test_vector_5_key) / sizeof(uint8_t), test_vector_5_nonce,
1602 sizeof(test_vector_5_nonce) / sizeof(uint8_t), test_vector_5_aad,
1603 sizeof(test_vector_5_aad) / sizeof(uint8_t), test_vector_5_plaintext, 0,
1604 test_vector_5_ciphertext_and_tag,
1605 sizeof(test_vector_5_ciphertext_and_tag) / sizeof(uint8_t));
1606 gsec_test_verify_crypter_on_test_vector(test_vector_5);
1607 gsec_aead_free_test_vector(test_vector_5);
1608
1609 /* 2.1.2 54-byte auth */
1610 gsec_aead_test_vector* test_vector_6;
1611 const uint8_t test_vector_6_key[] = {
1612 0xe3, 0xc0, 0x8a, 0x8f, 0x06, 0xc6, 0xe3, 0xad, 0x95, 0xa7, 0x05,
1613 0x57, 0xb2, 0x3f, 0x75, 0x48, 0x3c, 0xe3, 0x30, 0x21, 0xa9, 0xc7,
1614 0x2b, 0x70, 0x25, 0x66, 0x62, 0x04, 0xc6, 0x9c, 0x0b, 0x72};
1615
1616 const uint8_t test_vector_6_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89,
1617 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65};
1618 const uint8_t test_vector_6_aad[] = {
1619 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf, 0x99, 0x8d,
1620 0x88, 0xe5, 0x22, 0x2a, 0xb2, 0xc2, 0x84, 0x65, 0x12, 0x15, 0x35, 0x24,
1621 0xc0, 0x89, 0x5e, 0x81, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
1622 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
1623 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c,
1624 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x01};
1625 const uint8_t test_vector_6_plaintext[1] = {};
1626 const uint8_t test_vector_6_ciphertext_and_tag[] = {
1627 0x2f, 0x0b, 0xc5, 0xaf, 0x40, 0x9e, 0x06, 0xd6,
1628 0x09, 0xea, 0x8b, 0x7d, 0x0f, 0xa5, 0xea, 0x50};
1629 gsec_aead_malloc_test_vector(
1630 &test_vector_6, test_vector_6_key,
1631 sizeof(test_vector_6_key) / sizeof(uint8_t), test_vector_6_nonce,
1632 sizeof(test_vector_6_nonce) / sizeof(uint8_t), test_vector_6_aad,
1633 sizeof(test_vector_6_aad) / sizeof(uint8_t), test_vector_6_plaintext, 0,
1634 test_vector_6_ciphertext_and_tag,
1635 sizeof(test_vector_6_ciphertext_and_tag) / sizeof(uint8_t));
1636 gsec_test_verify_crypter_on_test_vector(test_vector_6);
1637 gsec_aead_free_test_vector(test_vector_6);
1638
1639 /* 2.2.1 60-byte crypt */
1640 gsec_aead_test_vector* test_vector_7;
1641 const uint8_t test_vector_7_key[] = {0xad, 0x7a, 0x2b, 0xd0, 0x3e, 0xac,
1642 0x83, 0x5a, 0x6f, 0x62, 0x0f, 0xdc,
1643 0xb5, 0x06, 0xb3, 0x45};
1644
1645 const uint8_t test_vector_7_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89,
1646 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65};
1647 const uint8_t test_vector_7_aad[] = {
1648 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf,
1649 0x99, 0x8d, 0x88, 0xe5, 0x2e, 0x00, 0xb2, 0xc2, 0x84, 0x65,
1650 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81};
1651 const uint8_t test_vector_7_plaintext[] = {
1652 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
1653 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
1654 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
1655 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x02};
1656 const uint8_t test_vector_7_ciphertext_and_tag[] = {
1657 0x70, 0x1a, 0xfa, 0x1c, 0xc0, 0x39, 0xc0, 0xd7, 0x65, 0x12, 0x8a,
1658 0x66, 0x5d, 0xab, 0x69, 0x24, 0x38, 0x99, 0xbf, 0x73, 0x18, 0xcc,
1659 0xdc, 0x81, 0xc9, 0x93, 0x1d, 0xa1, 0x7f, 0xbe, 0x8e, 0xdd, 0x7d,
1660 0x17, 0xcb, 0x8b, 0x4c, 0x26, 0xfc, 0x81, 0xe3, 0x28, 0x4f, 0x2b,
1661 0x7f, 0xba, 0x71, 0x3d, 0x4f, 0x8d, 0x55, 0xe7, 0xd3, 0xf0, 0x6f,
1662 0xd5, 0xa1, 0x3c, 0x0c, 0x29, 0xb9, 0xd5, 0xb8, 0x80};
1663 gsec_aead_malloc_test_vector(
1664 &test_vector_7, test_vector_7_key,
1665 sizeof(test_vector_7_key) / sizeof(uint8_t), test_vector_7_nonce,
1666 sizeof(test_vector_7_nonce) / sizeof(uint8_t), test_vector_7_aad,
1667 sizeof(test_vector_7_aad) / sizeof(uint8_t), test_vector_7_plaintext,
1668 sizeof(test_vector_7_plaintext) / sizeof(uint8_t),
1669 test_vector_7_ciphertext_and_tag,
1670 sizeof(test_vector_7_ciphertext_and_tag) / sizeof(uint8_t));
1671 gsec_test_verify_crypter_on_test_vector(test_vector_7);
1672 gsec_aead_free_test_vector(test_vector_7);
1673
1674 /* 2.2.2 60-byte crypt */
1675 gsec_aead_test_vector* test_vector_8;
1676 const uint8_t test_vector_8_key[] = {
1677 0xe3, 0xc0, 0x8a, 0x8f, 0x06, 0xc6, 0xe3, 0xad, 0x95, 0xa7, 0x05,
1678 0x57, 0xb2, 0x3f, 0x75, 0x48, 0x3c, 0xe3, 0x30, 0x21, 0xa9, 0xc7,
1679 0x2b, 0x70, 0x25, 0x66, 0x62, 0x04, 0xc6, 0x9c, 0x0b, 0x72};
1680 const uint8_t test_vector_8_nonce[] = {0x12, 0x15, 0x35, 0x24, 0xc0, 0x89,
1681 0x5e, 0x81, 0xb2, 0xc2, 0x84, 0x65};
1682 const uint8_t test_vector_8_aad[] = {
1683 0xd6, 0x09, 0xb1, 0xf0, 0x56, 0x63, 0x7a, 0x0d, 0x46, 0xdf,
1684 0x99, 0x8d, 0x88, 0xe5, 0x2e, 0x00, 0xb2, 0xc2, 0x84, 0x65,
1685 0x12, 0x15, 0x35, 0x24, 0xc0, 0x89, 0x5e, 0x81};
1686 const uint8_t test_vector_8_plaintext[] = {
1687 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18,
1688 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
1689 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30,
1690 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x02};
1691 const uint8_t test_vector_8_ciphertext_and_tag[] = {
1692 0xe2, 0x00, 0x6e, 0xb4, 0x2f, 0x52, 0x77, 0x02, 0x2d, 0x9b, 0x19,
1693 0x92, 0x5b, 0xc4, 0x19, 0xd7, 0xa5, 0x92, 0x66, 0x6c, 0x92, 0x5f,
1694 0xe2, 0xef, 0x71, 0x8e, 0xb4, 0xe3, 0x08, 0xef, 0xea, 0xa7, 0xc5,
1695 0x27, 0x3b, 0x39, 0x41, 0x18, 0x86, 0x0a, 0x5b, 0xe2, 0xa9, 0x7f,
1696 0x56, 0xab, 0x78, 0x36, 0x5c, 0xa5, 0x97, 0xcd, 0xbb, 0x3e, 0xdb,
1697 0x8d, 0x1a, 0x11, 0x51, 0xea, 0x0a, 0xf7, 0xb4, 0x36};
1698 gsec_aead_malloc_test_vector(
1699 &test_vector_8, test_vector_8_key,
1700 sizeof(test_vector_8_key) / sizeof(uint8_t), test_vector_8_nonce,
1701 sizeof(test_vector_8_nonce) / sizeof(uint8_t), test_vector_8_aad,
1702 sizeof(test_vector_8_aad) / sizeof(uint8_t), test_vector_8_plaintext,
1703 sizeof(test_vector_8_plaintext) / sizeof(uint8_t),
1704 test_vector_8_ciphertext_and_tag,
1705 sizeof(test_vector_8_ciphertext_and_tag) / sizeof(uint8_t));
1706 gsec_test_verify_crypter_on_test_vector(test_vector_8);
1707 gsec_aead_free_test_vector(test_vector_8);
1708
1709 /* 2.3.1 60-byte auth */
1710 gsec_aead_test_vector* test_vector_9;
1711 const uint8_t test_vector_9_key[] = {0x07, 0x1b, 0x11, 0x3b, 0x0c, 0xa7,
1712 0x43, 0xfe, 0xcc, 0xcf, 0x3d, 0x05,
1713 0x1f, 0x73, 0x73, 0x82};
1714 const uint8_t test_vector_9_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d,
1715 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed};
1716 const uint8_t test_vector_9_aad[] = {
1717 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d,
1718 0x88, 0xe5, 0x40, 0x00, 0x76, 0xd4, 0x57, 0xed, 0x08, 0x00, 0x0f, 0x10,
1719 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
1720 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
1721 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34,
1722 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x03};
1723 const uint8_t test_vector_9_plaintext[1] = {};
1724 const uint8_t test_vector_9_ciphertext_and_tag[] = {
1725 0x0c, 0x01, 0x7b, 0xc7, 0x3b, 0x22, 0x7d, 0xfc,
1726 0xc9, 0xba, 0xfa, 0x1c, 0x41, 0xac, 0xc3, 0x53};
1727 gsec_aead_malloc_test_vector(
1728 &test_vector_9, test_vector_9_key,
1729 sizeof(test_vector_9_key) / sizeof(uint8_t), test_vector_9_nonce,
1730 sizeof(test_vector_9_nonce) / sizeof(uint8_t), test_vector_9_aad,
1731 sizeof(test_vector_9_aad) / sizeof(uint8_t), test_vector_9_plaintext, 0,
1732 test_vector_9_ciphertext_and_tag,
1733 sizeof(test_vector_9_ciphertext_and_tag) / sizeof(uint8_t));
1734 gsec_test_verify_crypter_on_test_vector(test_vector_9);
1735 gsec_aead_free_test_vector(test_vector_9);
1736
1737 /* 2.3.2 60-byte auth */
1738 gsec_aead_test_vector* test_vector_10;
1739 const uint8_t test_vector_10_key[] = {
1740 0x69, 0x1d, 0x3e, 0xe9, 0x09, 0xd7, 0xf5, 0x41, 0x67, 0xfd, 0x1c,
1741 0xa0, 0xb5, 0xd7, 0x69, 0x08, 0x1f, 0x2b, 0xde, 0x1a, 0xee, 0x65,
1742 0x5f, 0xdb, 0xab, 0x80, 0xbd, 0x52, 0x95, 0xae, 0x6b, 0xe7};
1743 const uint8_t test_vector_10_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d,
1744 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed};
1745 const uint8_t test_vector_10_aad[] = {
1746 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d,
1747 0x88, 0xe5, 0x40, 0x00, 0x76, 0xd4, 0x57, 0xed, 0x08, 0x00, 0x0f, 0x10,
1748 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c,
1749 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
1750 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34,
1751 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x00, 0x03};
1752 const uint8_t test_vector_10_plaintext[1] = {};
1753 const uint8_t test_vector_10_ciphertext_and_tag[] = {
1754 0x35, 0x21, 0x7c, 0x77, 0x4b, 0xbc, 0x31, 0xb6,
1755 0x31, 0x66, 0xbc, 0xf9, 0xd4, 0xab, 0xed, 0x07};
1756 gsec_aead_malloc_test_vector(
1757 &test_vector_10, test_vector_10_key,
1758 sizeof(test_vector_10_key) / sizeof(uint8_t), test_vector_10_nonce,
1759 sizeof(test_vector_10_nonce) / sizeof(uint8_t), test_vector_10_aad,
1760 sizeof(test_vector_10_aad) / sizeof(uint8_t), test_vector_10_plaintext, 0,
1761 test_vector_10_ciphertext_and_tag,
1762 sizeof(test_vector_10_ciphertext_and_tag) / sizeof(uint8_t));
1763 gsec_test_verify_crypter_on_test_vector(test_vector_10);
1764 gsec_aead_free_test_vector(test_vector_10);
1765
1766 /* 2.4.1 54-byte crypt */
1767 gsec_aead_test_vector* test_vector_11;
1768 const uint8_t test_vector_11_key[] = {0x07, 0x1b, 0x11, 0x3b, 0x0c, 0xa7,
1769 0x43, 0xfe, 0xcc, 0xcf, 0x3d, 0x05,
1770 0x1f, 0x73, 0x73, 0x82};
1771 const uint8_t test_vector_11_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d,
1772 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed};
1773 const uint8_t test_vector_11_aad[] = {
1774 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d,
1775 0xcd, 0x3d, 0x88, 0xe5, 0x4c, 0x2a, 0x76, 0xd4, 0x57, 0xed};
1776 const uint8_t test_vector_11_plaintext[] = {
1777 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1778 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
1779 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
1780 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x04};
1781 const uint8_t test_vector_11_ciphertext_and_tag[] = {
1782 0x13, 0xb4, 0xc7, 0x2b, 0x38, 0x9d, 0xc5, 0x01, 0x8e, 0x72, 0xa1, 0x71,
1783 0xdd, 0x85, 0xa5, 0xd3, 0x75, 0x22, 0x74, 0xd3, 0xa0, 0x19, 0xfb, 0xca,
1784 0xed, 0x09, 0xa4, 0x25, 0xcd, 0x9b, 0x2e, 0x1c, 0x9b, 0x72, 0xee, 0xe7,
1785 0xc9, 0xde, 0x7d, 0x52, 0xb3, 0xf3, 0xd6, 0xa5, 0x28, 0x4f, 0x4a, 0x6d,
1786 0x3f, 0xe2, 0x2a, 0x5d, 0x6c, 0x2b, 0x96, 0x04, 0x94, 0xc3};
1787 gsec_aead_malloc_test_vector(
1788 &test_vector_11, test_vector_11_key,
1789 sizeof(test_vector_11_key) / sizeof(uint8_t), test_vector_11_nonce,
1790 sizeof(test_vector_11_nonce) / sizeof(uint8_t), test_vector_11_aad,
1791 sizeof(test_vector_11_aad) / sizeof(uint8_t), test_vector_11_plaintext,
1792 sizeof(test_vector_11_plaintext) / sizeof(uint8_t),
1793 test_vector_11_ciphertext_and_tag,
1794 sizeof(test_vector_11_ciphertext_and_tag) / sizeof(uint8_t));
1795 gsec_test_verify_crypter_on_test_vector(test_vector_11);
1796 gsec_aead_free_test_vector(test_vector_11);
1797
1798 /* 2.4.2 54-byte crypt */
1799 gsec_aead_test_vector* test_vector_12;
1800 const uint8_t test_vector_12_key[] = {
1801 0x69, 0x1d, 0x3e, 0xe9, 0x09, 0xd7, 0xf5, 0x41, 0x67, 0xfd, 0x1c,
1802 0xa0, 0xb5, 0xd7, 0x69, 0x08, 0x1f, 0x2b, 0xde, 0x1a, 0xee, 0x65,
1803 0x5f, 0xdb, 0xab, 0x80, 0xbd, 0x52, 0x95, 0xae, 0x6b, 0xe7};
1804 const uint8_t test_vector_12_nonce[] = {0xf0, 0x76, 0x1e, 0x8d, 0xcd, 0x3d,
1805 0x00, 0x01, 0x76, 0xd4, 0x57, 0xed};
1806 const uint8_t test_vector_12_aad[] = {
1807 0xe2, 0x01, 0x06, 0xd7, 0xcd, 0x0d, 0xf0, 0x76, 0x1e, 0x8d,
1808 0xcd, 0x3d, 0x88, 0xe5, 0x4c, 0x2a, 0x76, 0xd4, 0x57, 0xed};
1809 const uint8_t test_vector_12_plaintext[] = {
1810 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
1811 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
1812 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
1813 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x00, 0x04};
1814 const uint8_t test_vector_12_ciphertext_and_tag[] = {
1815 0xc1, 0x62, 0x3f, 0x55, 0x73, 0x0c, 0x93, 0x53, 0x30, 0x97, 0xad, 0xda,
1816 0xd2, 0x56, 0x64, 0x96, 0x61, 0x25, 0x35, 0x2b, 0x43, 0xad, 0xac, 0xbd,
1817 0x61, 0xc5, 0xef, 0x3a, 0xc9, 0x0b, 0x5b, 0xee, 0x92, 0x9c, 0xe4, 0x63,
1818 0x0e, 0xa7, 0x9f, 0x6c, 0xe5, 0x19, 0x12, 0xaf, 0x39, 0xc2, 0xd1, 0xfd,
1819 0xc2, 0x05, 0x1f, 0x8b, 0x7b, 0x3c, 0x9d, 0x39, 0x7e, 0xf2};
1820 gsec_aead_malloc_test_vector(
1821 &test_vector_12, test_vector_12_key,
1822 sizeof(test_vector_12_key) / sizeof(uint8_t), test_vector_12_nonce,
1823 sizeof(test_vector_12_nonce) / sizeof(uint8_t), test_vector_12_aad,
1824 sizeof(test_vector_12_aad) / sizeof(uint8_t), test_vector_12_plaintext,
1825 sizeof(test_vector_12_plaintext) / sizeof(uint8_t),
1826 test_vector_12_ciphertext_and_tag,
1827 sizeof(test_vector_12_ciphertext_and_tag) / sizeof(uint8_t));
1828 gsec_test_verify_crypter_on_test_vector(test_vector_12);
1829 gsec_aead_free_test_vector(test_vector_12);
1830
1831 /* 2.5.1 65-byte auth */
1832 gsec_aead_test_vector* test_vector_13;
1833 const uint8_t test_vector_13_key[] = {0x01, 0x3f, 0xe0, 0x0b, 0x5f, 0x11,
1834 0xbe, 0x7f, 0x86, 0x6d, 0x0c, 0xbb,
1835 0xc5, 0x5a, 0x7a, 0x90};
1836 const uint8_t test_vector_13_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37,
1837 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12};
1838 const uint8_t test_vector_13_aad[] = {
1839 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, 0x72, 0x77,
1840 0x88, 0xe5, 0x23, 0x00, 0x89, 0x32, 0xd6, 0x12, 0x7c, 0xfd, 0xe9, 0xf9,
1841 0xe3, 0x37, 0x24, 0xc6, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
1842 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
1843 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c,
1844 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1845 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x05};
1846 const uint8_t test_vector_13_plaintext[1] = {};
1847 const uint8_t test_vector_13_ciphertext_and_tag[] = {
1848 0x21, 0x78, 0x67, 0xe5, 0x0c, 0x2d, 0xad, 0x74,
1849 0xc2, 0x8c, 0x3b, 0x50, 0xab, 0xdf, 0x69, 0x5a};
1850 gsec_aead_malloc_test_vector(
1851 &test_vector_13, test_vector_13_key,
1852 sizeof(test_vector_13_key) / sizeof(uint8_t), test_vector_13_nonce,
1853 sizeof(test_vector_13_nonce) / sizeof(uint8_t), test_vector_13_aad,
1854 sizeof(test_vector_13_aad) / sizeof(uint8_t), test_vector_13_plaintext, 0,
1855 test_vector_13_ciphertext_and_tag,
1856 sizeof(test_vector_13_ciphertext_and_tag) / sizeof(uint8_t));
1857 gsec_test_verify_crypter_on_test_vector(test_vector_13);
1858 gsec_aead_free_test_vector(test_vector_13);
1859
1860 /* 2.5.2 65-byte auth */
1861 gsec_aead_test_vector* test_vector_14;
1862 const uint8_t test_vector_14_key[] = {
1863 0x83, 0xc0, 0x93, 0xb5, 0x8d, 0xe7, 0xff, 0xe1, 0xc0, 0xda, 0x92,
1864 0x6a, 0xc4, 0x3f, 0xb3, 0x60, 0x9a, 0xc1, 0xc8, 0x0f, 0xee, 0x1b,
1865 0x62, 0x44, 0x97, 0xef, 0x94, 0x2e, 0x2f, 0x79, 0xa8, 0x23};
1866 const uint8_t test_vector_14_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37,
1867 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12};
1868 const uint8_t test_vector_14_aad[] = {
1869 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2, 0x72, 0x77,
1870 0x88, 0xe5, 0x23, 0x00, 0x89, 0x32, 0xd6, 0x12, 0x7c, 0xfd, 0xe9, 0xf9,
1871 0xe3, 0x37, 0x24, 0xc6, 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14,
1872 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
1873 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c,
1874 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
1875 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x00, 0x05};
1876 const uint8_t test_vector_14_plaintext[1] = {};
1877 const uint8_t test_vector_14_ciphertext_and_tag[] = {
1878 0x6e, 0xe1, 0x60, 0xe8, 0xfa, 0xec, 0xa4, 0xb3,
1879 0x6c, 0x86, 0xb2, 0x34, 0x92, 0x0c, 0xa9, 0x75};
1880 gsec_aead_malloc_test_vector(
1881 &test_vector_14, test_vector_14_key,
1882 sizeof(test_vector_14_key) / sizeof(uint8_t), test_vector_14_nonce,
1883 sizeof(test_vector_14_nonce) / sizeof(uint8_t), test_vector_14_aad,
1884 sizeof(test_vector_14_aad) / sizeof(uint8_t), test_vector_14_plaintext, 0,
1885 test_vector_14_ciphertext_and_tag,
1886 sizeof(test_vector_14_ciphertext_and_tag) / sizeof(uint8_t));
1887 gsec_test_verify_crypter_on_test_vector(test_vector_14);
1888 gsec_aead_free_test_vector(test_vector_14);
1889
1890 /* 2.6.1 61-byte crypt */
1891 gsec_aead_test_vector* test_vector_15;
1892 const uint8_t test_vector_15_key[] = {0x01, 0x3f, 0xe0, 0x0b, 0x5f, 0x11,
1893 0xbe, 0x7f, 0x86, 0x6d, 0x0c, 0xbb,
1894 0xc5, 0x5a, 0x7a, 0x90};
1895 const uint8_t test_vector_15_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37,
1896 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12};
1897 const uint8_t test_vector_15_aad[] = {
1898 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2,
1899 0x72, 0x77, 0x88, 0xe5, 0x2f, 0x00, 0x89, 0x32, 0xd6, 0x12,
1900 0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, 0x24, 0xc6};
1901 const uint8_t test_vector_15_plaintext[] = {
1902 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
1903 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
1904 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
1905 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34,
1906 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x00, 0x06};
1907 const uint8_t test_vector_15_ciphertext_and_tag[] = {
1908 0x3a, 0x4d, 0xe6, 0xfa, 0x32, 0x19, 0x10, 0x14, 0xdb, 0xb3, 0x03,
1909 0xd9, 0x2e, 0xe3, 0xa9, 0xe8, 0xa1, 0xb5, 0x99, 0xc1, 0x4d, 0x22,
1910 0xfb, 0x08, 0x00, 0x96, 0xe1, 0x38, 0x11, 0x81, 0x6a, 0x3c, 0x9c,
1911 0x9b, 0xcf, 0x7c, 0x1b, 0x9b, 0x96, 0xda, 0x80, 0x92, 0x04, 0xe2,
1912 0x9d, 0x0e, 0x2a, 0x76, 0x42, 0xbf, 0xd3, 0x10, 0xa4, 0x83, 0x7c,
1913 0x81, 0x6c, 0xcf, 0xa5, 0xac, 0x23, 0xab, 0x00, 0x39, 0x88};
1914 gsec_aead_malloc_test_vector(
1915 &test_vector_15, test_vector_15_key,
1916 sizeof(test_vector_15_key) / sizeof(uint8_t), test_vector_15_nonce,
1917 sizeof(test_vector_15_nonce) / sizeof(uint8_t), test_vector_15_aad,
1918 sizeof(test_vector_15_aad) / sizeof(uint8_t), test_vector_15_plaintext,
1919 sizeof(test_vector_15_plaintext) / sizeof(uint8_t),
1920 test_vector_15_ciphertext_and_tag,
1921 sizeof(test_vector_15_ciphertext_and_tag) / sizeof(uint8_t));
1922 gsec_test_verify_crypter_on_test_vector(test_vector_15);
1923 gsec_aead_free_test_vector(test_vector_15);
1924
1925 /* 2.6.2 61-byte crypt */
1926 gsec_aead_test_vector* test_vector_16;
1927 const uint8_t test_vector_16_key[] = {
1928 0x83, 0xc0, 0x93, 0xb5, 0x8d, 0xe7, 0xff, 0xe1, 0xc0, 0xda, 0x92,
1929 0x6a, 0xc4, 0x3f, 0xb3, 0x60, 0x9a, 0xc1, 0xc8, 0x0f, 0xee, 0x1b,
1930 0x62, 0x44, 0x97, 0xef, 0x94, 0x2e, 0x2f, 0x79, 0xa8, 0x23};
1931 const uint8_t test_vector_16_nonce[] = {0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37,
1932 0x24, 0xc6, 0x89, 0x32, 0xd6, 0x12};
1933 const uint8_t test_vector_16_aad[] = {
1934 0x84, 0xc5, 0xd5, 0x13, 0xd2, 0xaa, 0xf6, 0xe5, 0xbb, 0xd2,
1935 0x72, 0x77, 0x88, 0xe5, 0x2f, 0x00, 0x89, 0x32, 0xd6, 0x12,
1936 0x7c, 0xfd, 0xe9, 0xf9, 0xe3, 0x37, 0x24, 0xc6};
1937 const uint8_t test_vector_16_plaintext[] = {
1938 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16,
1939 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20,
1940 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a,
1941 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34,
1942 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x00, 0x06};
1943 const uint8_t test_vector_16_ciphertext_and_tag[] = {
1944 0x11, 0x02, 0x22, 0xff, 0x80, 0x50, 0xcb, 0xec, 0xe6, 0x6a, 0x81,
1945 0x3a, 0xd0, 0x9a, 0x73, 0xed, 0x7a, 0x9a, 0x08, 0x9c, 0x10, 0x6b,
1946 0x95, 0x93, 0x89, 0x16, 0x8e, 0xd6, 0xe8, 0x69, 0x8e, 0xa9, 0x02,
1947 0xeb, 0x12, 0x77, 0xdb, 0xec, 0x2e, 0x68, 0xe4, 0x73, 0x15, 0x5a,
1948 0x15, 0xa7, 0xda, 0xee, 0xd4, 0xa1, 0x0f, 0x4e, 0x05, 0x13, 0x9c,
1949 0x23, 0xdf, 0x00, 0xb3, 0xaa, 0xdc, 0x71, 0xf0, 0x59, 0x6a};
1950 gsec_aead_malloc_test_vector(
1951 &test_vector_16, test_vector_16_key,
1952 sizeof(test_vector_16_key) / sizeof(uint8_t), test_vector_16_nonce,
1953 sizeof(test_vector_16_nonce) / sizeof(uint8_t), test_vector_16_aad,
1954 sizeof(test_vector_16_aad) / sizeof(uint8_t), test_vector_16_plaintext,
1955 sizeof(test_vector_16_plaintext) / sizeof(uint8_t),
1956 test_vector_16_ciphertext_and_tag,
1957 sizeof(test_vector_16_ciphertext_and_tag) / sizeof(uint8_t));
1958 gsec_test_verify_crypter_on_test_vector(test_vector_16);
1959 gsec_aead_free_test_vector(test_vector_16);
1960
1961 /* 2.7.1 79-byte crypt */
1962 gsec_aead_test_vector* test_vector_17;
1963 const uint8_t test_vector_17_key[] = {0x88, 0xee, 0x08, 0x7f, 0xd9, 0x5d,
1964 0xa9, 0xfb, 0xf6, 0x72, 0x5a, 0xa9,
1965 0xd7, 0x57, 0xb0, 0xcd};
1966 const uint8_t test_vector_17_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5,
1967 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c};
1968 const uint8_t test_vector_17_aad[] = {
1969 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, 0x4e,
1970 0xc5, 0x88, 0xe5, 0x41, 0x00, 0x2e, 0x58, 0x49, 0x5c, 0x08, 0x00,
1971 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
1972 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
1973 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
1974 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
1975 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
1976 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x07};
1977 const uint8_t test_vector_17_plaintext[1] = {};
1978 const uint8_t test_vector_17_ciphertext_and_tag[] = {
1979 0x07, 0x92, 0x2b, 0x8e, 0xbc, 0xf1, 0x0b, 0xb2,
1980 0x29, 0x75, 0x88, 0xca, 0x4c, 0x61, 0x45, 0x23};
1981 gsec_aead_malloc_test_vector(
1982 &test_vector_17, test_vector_17_key,
1983 sizeof(test_vector_17_key) / sizeof(uint8_t), test_vector_17_nonce,
1984 sizeof(test_vector_17_nonce) / sizeof(uint8_t), test_vector_17_aad,
1985 sizeof(test_vector_17_aad) / sizeof(uint8_t), test_vector_17_plaintext, 0,
1986 test_vector_17_ciphertext_and_tag,
1987 sizeof(test_vector_17_ciphertext_and_tag) / sizeof(uint8_t));
1988 gsec_test_verify_crypter_on_test_vector(test_vector_17);
1989 gsec_aead_free_test_vector(test_vector_17);
1990
1991 /* 2.7.2 79-byte crypt */
1992 gsec_aead_test_vector* test_vector_18;
1993 const uint8_t test_vector_18_key[] = {
1994 0x4c, 0x97, 0x3d, 0xbc, 0x73, 0x64, 0x62, 0x16, 0x74, 0xf8, 0xb5,
1995 0xb8, 0x9e, 0x5c, 0x15, 0x51, 0x1f, 0xce, 0xd9, 0x21, 0x64, 0x90,
1996 0xfb, 0x1c, 0x1a, 0x2c, 0xaa, 0x0f, 0xfe, 0x04, 0x07, 0xe5};
1997 const uint8_t test_vector_18_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5,
1998 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c};
1999 const uint8_t test_vector_18_aad[] = {
2000 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca, 0x4e,
2001 0xc5, 0x88, 0xe5, 0x41, 0x00, 0x2e, 0x58, 0x49, 0x5c, 0x08, 0x00,
2002 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19,
2003 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24,
2004 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
2005 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3a,
2006 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43, 0x44, 0x45,
2007 0x46, 0x47, 0x48, 0x49, 0x4a, 0x4b, 0x4c, 0x4d, 0x00, 0x07};
2008 const uint8_t test_vector_18_plaintext[1] = {};
2009 const uint8_t test_vector_18_ciphertext_and_tag[] = {
2010 0x00, 0xbd, 0xa1, 0xb7, 0xe8, 0x76, 0x08, 0xbc,
2011 0xbf, 0x47, 0x0f, 0x12, 0x15, 0x7f, 0x4c, 0x07};
2012 gsec_aead_malloc_test_vector(
2013 &test_vector_18, test_vector_18_key,
2014 sizeof(test_vector_18_key) / sizeof(uint8_t), test_vector_18_nonce,
2015 sizeof(test_vector_18_nonce) / sizeof(uint8_t), test_vector_18_aad,
2016 sizeof(test_vector_18_aad) / sizeof(uint8_t), test_vector_18_plaintext, 0,
2017 test_vector_18_ciphertext_and_tag,
2018 sizeof(test_vector_18_ciphertext_and_tag) / sizeof(uint8_t));
2019 gsec_test_verify_crypter_on_test_vector(test_vector_18);
2020 gsec_aead_free_test_vector(test_vector_18);
2021
2022 /* 2.8.1 61-byte crypt */
2023 gsec_aead_test_vector* test_vector_19;
2024 const uint8_t test_vector_19_key[] = {0x88, 0xee, 0x08, 0x7f, 0xd9, 0x5d,
2025 0xa9, 0xfb, 0xf6, 0x72, 0x5a, 0xa9,
2026 0xd7, 0x57, 0xb0, 0xcd};
2027 const uint8_t test_vector_19_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5,
2028 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c};
2029 const uint8_t test_vector_19_aad[] = {
2030 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca,
2031 0x4e, 0xc5, 0x88, 0xe5, 0x4d, 0x00, 0x2e, 0x58, 0x49, 0x5c};
2032 const uint8_t test_vector_19_plaintext[] = {
2033 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2034 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
2035 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
2036 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
2037 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
2038 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x00, 0x08};
2039 const uint8_t test_vector_19_ciphertext_and_tag[] = {
2040 0xc3, 0x1f, 0x53, 0xd9, 0x9e, 0x56, 0x87, 0xf7, 0x36, 0x51, 0x19, 0xb8,
2041 0x32, 0xd2, 0xaa, 0xe7, 0x07, 0x41, 0xd5, 0x93, 0xf1, 0xf9, 0xe2, 0xab,
2042 0x34, 0x55, 0x77, 0x9b, 0x07, 0x8e, 0xb8, 0xfe, 0xac, 0xdf, 0xec, 0x1f,
2043 0x8e, 0x3e, 0x52, 0x77, 0xf8, 0x18, 0x0b, 0x43, 0x36, 0x1f, 0x65, 0x12,
2044 0xad, 0xb1, 0x6d, 0x2e, 0x38, 0x54, 0x8a, 0x2c, 0x71, 0x9d, 0xba, 0x72,
2045 0x28, 0xd8, 0x40, 0x88, 0xf8, 0x75, 0x7a, 0xdb, 0x8a, 0xa7, 0x88, 0xd8,
2046 0xf6, 0x5a, 0xd6, 0x68, 0xbe, 0x70, 0xe7};
2047 gsec_aead_malloc_test_vector(
2048 &test_vector_19, test_vector_19_key,
2049 sizeof(test_vector_19_key) / sizeof(uint8_t), test_vector_19_nonce,
2050 sizeof(test_vector_19_nonce) / sizeof(uint8_t), test_vector_19_aad,
2051 sizeof(test_vector_19_aad) / sizeof(uint8_t), test_vector_19_plaintext,
2052 sizeof(test_vector_19_plaintext) / sizeof(uint8_t),
2053 test_vector_19_ciphertext_and_tag,
2054 sizeof(test_vector_19_ciphertext_and_tag) / sizeof(uint8_t));
2055 gsec_test_verify_crypter_on_test_vector(test_vector_19);
2056 gsec_aead_free_test_vector(test_vector_19);
2057
2058 /* 2.8.2 61-byte crypt */
2059 gsec_aead_test_vector* test_vector_20;
2060 const uint8_t test_vector_20_key[] = {
2061 0x4c, 0x97, 0x3d, 0xbc, 0x73, 0x64, 0x62, 0x16, 0x74, 0xf8, 0xb5,
2062 0xb8, 0x9e, 0x5c, 0x15, 0x51, 0x1f, 0xce, 0xd9, 0x21, 0x64, 0x90,
2063 0xfb, 0x1c, 0x1a, 0x2c, 0xaa, 0x0f, 0xfe, 0x04, 0x07, 0xe5};
2064 const uint8_t test_vector_20_nonce[] = {0x7a, 0xe8, 0xe2, 0xca, 0x4e, 0xc5,
2065 0x00, 0x01, 0x2e, 0x58, 0x49, 0x5c};
2066 const uint8_t test_vector_20_aad[] = {
2067 0x68, 0xf2, 0xe7, 0x76, 0x96, 0xce, 0x7a, 0xe8, 0xe2, 0xca,
2068 0x4e, 0xc5, 0x88, 0xe5, 0x4d, 0x00, 0x2e, 0x58, 0x49, 0x5c};
2069 const uint8_t test_vector_20_plaintext[] = {
2070 0x08, 0x00, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
2071 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22,
2072 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d,
2073 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38,
2074 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f, 0x40, 0x41, 0x42, 0x43,
2075 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x00, 0x08};
2076 const uint8_t test_vector_20_ciphertext_and_tag[] = {
2077 0xba, 0x8a, 0xe3, 0x1b, 0xc5, 0x06, 0x48, 0x6d, 0x68, 0x73, 0xe4, 0xfc,
2078 0xe4, 0x60, 0xe7, 0xdc, 0x57, 0x59, 0x1f, 0xf0, 0x06, 0x11, 0xf3, 0x1c,
2079 0x38, 0x34, 0xfe, 0x1c, 0x04, 0xad, 0x80, 0xb6, 0x68, 0x03, 0xaf, 0xcf,
2080 0x5b, 0x27, 0xe6, 0x33, 0x3f, 0xa6, 0x7c, 0x99, 0xda, 0x47, 0xc2, 0xf0,
2081 0xce, 0xd6, 0x8d, 0x53, 0x1b, 0xd7, 0x41, 0xa9, 0x43, 0xcf, 0xf7, 0xa6,
2082 0x71, 0x3b, 0xd0, 0x26, 0x11, 0xcd, 0x7d, 0xaa, 0x01, 0xd6, 0x1c, 0x5c,
2083 0x88, 0x6d, 0xc1, 0xa8, 0x17, 0x01, 0x07};
2084 gsec_aead_malloc_test_vector(
2085 &test_vector_20, test_vector_20_key,
2086 sizeof(test_vector_20_key) / sizeof(uint8_t), test_vector_20_nonce,
2087 sizeof(test_vector_20_nonce) / sizeof(uint8_t), test_vector_20_aad,
2088 sizeof(test_vector_20_aad) / sizeof(uint8_t), test_vector_20_plaintext,
2089 sizeof(test_vector_20_plaintext) / sizeof(uint8_t),
2090 test_vector_20_ciphertext_and_tag,
2091 sizeof(test_vector_20_ciphertext_and_tag) / sizeof(uint8_t));
2092 gsec_test_verify_crypter_on_test_vector(test_vector_20);
2093 gsec_aead_free_test_vector(test_vector_20);
2094 }
2095
main(int argc,char ** argv)2096 int main(int argc, char** argv) {
2097 grpc_init();
2098 gsec_test_do_generic_crypter_tests();
2099 gsec_test_do_vector_tests_nist();
2100 gsec_test_do_vector_tests_ieee();
2101 gsec_test_do_vector_tests_rekey_nist();
2102 gsec_test_do_vector_tests_rekey_ieee();
2103 grpc_shutdown();
2104 return 0;
2105 }
2106