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