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