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