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 <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22
23 #include <grpc/support/alloc.h>
24 #include <grpc/support/log.h>
25
26 #include "src/core/tsi/alts/frame_protector/alts_crypter.h"
27 #include "test/core/tsi/alts/crypt/gsec_test_util.h"
28
alts_crypter_test_random_seal_unseal(alts_crypter * server_seal,alts_crypter * server_unseal,alts_crypter * client_seal,alts_crypter * client_unseal)29 static void alts_crypter_test_random_seal_unseal(alts_crypter* server_seal,
30 alts_crypter* server_unseal,
31 alts_crypter* client_seal,
32 alts_crypter* client_unseal) {
33 size_t data_size = gsec_test_bias_random_uint32(1024) + 1;
34 size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal);
35 size_t protected_data_size = data_size + num_overhead_bytes;
36 uint8_t* data_buffer = static_cast<uint8_t*>(gpr_malloc(protected_data_size));
37 gsec_test_random_bytes(data_buffer, data_size);
38 uint8_t* duplicate_buffer = nullptr;
39 gsec_test_copy(data_buffer, &duplicate_buffer, data_size);
40
41 /* Client seal and server unseal */
42 size_t size = data_size;
43 grpc_status_code status = alts_crypter_process_in_place(
44 client_seal, data_buffer, protected_data_size, size, &size, nullptr);
45 GPR_ASSERT(status == GRPC_STATUS_OK);
46 GPR_ASSERT(size == protected_data_size);
47 status = alts_crypter_process_in_place(
48 server_unseal, data_buffer, protected_data_size, size, &size, nullptr);
49 GPR_ASSERT(status == GRPC_STATUS_OK);
50 GPR_ASSERT(memcmp(data_buffer, duplicate_buffer, data_size) == 0);
51 GPR_ASSERT(size == data_size);
52 /* Server seal and client unseal */
53 status = alts_crypter_process_in_place(
54 server_seal, data_buffer, protected_data_size, size, &size, nullptr);
55 GPR_ASSERT(status == GRPC_STATUS_OK);
56 GPR_ASSERT(size == protected_data_size);
57 status = alts_crypter_process_in_place(
58 client_unseal, data_buffer, protected_data_size, size, &size, nullptr);
59 GPR_ASSERT(status == GRPC_STATUS_OK);
60 GPR_ASSERT(memcmp(data_buffer, duplicate_buffer, data_size) == 0);
61 GPR_ASSERT(size == data_size);
62 gpr_free(data_buffer);
63 gpr_free(duplicate_buffer);
64 }
65
alts_crypter_test_multiple_random_seal_unseal(alts_crypter * server_seal,alts_crypter * server_unseal,alts_crypter * client_seal,alts_crypter * client_unseal)66 static void alts_crypter_test_multiple_random_seal_unseal(
67 alts_crypter* server_seal, alts_crypter* server_unseal,
68 alts_crypter* client_seal, alts_crypter* client_unseal) {
69 size_t data_size = gsec_test_bias_random_uint32(1024) + 1;
70 size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal);
71 size_t protected_data_size = data_size + num_overhead_bytes;
72
73 uint8_t* data_buffer1 =
74 static_cast<uint8_t*>(gpr_malloc(protected_data_size));
75 uint8_t* data_buffer2 =
76 static_cast<uint8_t*>(gpr_malloc(protected_data_size));
77 uint8_t* duplicate_buffer1 = nullptr;
78 uint8_t* duplicate_buffer2 = nullptr;
79 gsec_test_random_bytes(data_buffer1, data_size);
80 gsec_test_random_bytes(data_buffer2, data_size);
81 gsec_test_copy(data_buffer1, &duplicate_buffer1, data_size);
82 gsec_test_copy(data_buffer2, &duplicate_buffer2, data_size);
83
84 /* Client seal and server unseal */
85 size_t size1 = data_size, size2 = data_size;
86 grpc_status_code status = alts_crypter_process_in_place(
87 client_seal, data_buffer1, protected_data_size, size1, &size1, nullptr);
88 GPR_ASSERT(status == GRPC_STATUS_OK);
89 GPR_ASSERT(size1 == protected_data_size);
90 status = alts_crypter_process_in_place(
91 client_seal, data_buffer2, protected_data_size, size2, &size2, nullptr);
92 GPR_ASSERT(status == GRPC_STATUS_OK);
93 GPR_ASSERT(size2 == protected_data_size);
94 status = alts_crypter_process_in_place(
95 server_unseal, data_buffer1, protected_data_size, size1, &size1, nullptr);
96 GPR_ASSERT(status == GRPC_STATUS_OK);
97 GPR_ASSERT(memcmp(data_buffer1, duplicate_buffer1, data_size) == 0);
98 GPR_ASSERT(size1 == data_size);
99 status = alts_crypter_process_in_place(
100 server_unseal, data_buffer2, protected_data_size, size2, &size2, nullptr);
101 GPR_ASSERT(status == GRPC_STATUS_OK);
102 GPR_ASSERT(memcmp(data_buffer2, duplicate_buffer2, data_size) == 0);
103 GPR_ASSERT(size2 == data_size);
104
105 /* Server seal and client unseal */
106 status = alts_crypter_process_in_place(
107 server_seal, data_buffer1, protected_data_size, size1, &size1, nullptr);
108 GPR_ASSERT(status == GRPC_STATUS_OK);
109 GPR_ASSERT(size1 == protected_data_size);
110 status = alts_crypter_process_in_place(
111 server_seal, data_buffer2, protected_data_size, size2, &size2, nullptr);
112 GPR_ASSERT(status == GRPC_STATUS_OK);
113 GPR_ASSERT(size2 == protected_data_size);
114 status = alts_crypter_process_in_place(
115 client_unseal, data_buffer1, protected_data_size, size1, &size1, nullptr);
116 GPR_ASSERT(status == GRPC_STATUS_OK);
117 GPR_ASSERT(memcmp(data_buffer1, duplicate_buffer1, data_size) == 0);
118 GPR_ASSERT(size1 == data_size);
119 status = alts_crypter_process_in_place(
120 client_unseal, data_buffer2, protected_data_size, size2, &size2, nullptr);
121 GPR_ASSERT(status == GRPC_STATUS_OK);
122 GPR_ASSERT(memcmp(data_buffer2, duplicate_buffer2, data_size) == 0);
123 GPR_ASSERT(size2 == data_size);
124
125 gpr_free(data_buffer1);
126 gpr_free(data_buffer2);
127 gpr_free(duplicate_buffer1);
128 gpr_free(duplicate_buffer2);
129 }
130
alts_crypter_test_corrupted_unseal(alts_crypter * server_seal,alts_crypter * server_unseal,alts_crypter * client_seal,alts_crypter * client_unseal)131 static void alts_crypter_test_corrupted_unseal(alts_crypter* server_seal,
132 alts_crypter* server_unseal,
133 alts_crypter* client_seal,
134 alts_crypter* client_unseal) {
135 size_t data_size = gsec_test_bias_random_uint32(1024) + 1;
136 size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal);
137 size_t protected_data_size = data_size + num_overhead_bytes;
138 auto* data_buffer = static_cast<uint8_t*>(gpr_malloc(protected_data_size));
139 auto* zero_buffer = static_cast<uint8_t*>(gpr_zalloc(data_size));
140
141 /* Corrupt a random byte in protected data. */
142 size_t size = data_size;
143 gsec_test_random_bytes(data_buffer, data_size);
144 grpc_status_code status = alts_crypter_process_in_place(
145 client_seal, data_buffer, protected_data_size, size, &size, nullptr);
146 GPR_ASSERT(status == GRPC_STATUS_OK);
147 GPR_ASSERT(size == protected_data_size);
148 uint8_t* corrupted_data_buffer;
149 char* error_message = nullptr;
150 gsec_test_copy_and_alter_random_byte(data_buffer, &corrupted_data_buffer,
151 protected_data_size);
152 status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer,
153 protected_data_size, size, &size,
154 &error_message);
155 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
156 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
157 "Checking tag failed"));
158 GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0);
159 gpr_free(corrupted_data_buffer);
160 gpr_free(error_message);
161
162 /* Corrupt the beginning of protected data. */
163 size = data_size;
164 gsec_test_random_bytes(data_buffer, data_size);
165 status = alts_crypter_process_in_place(
166 client_seal, data_buffer, protected_data_size, size, &size, nullptr);
167 GPR_ASSERT(status == GRPC_STATUS_OK);
168 GPR_ASSERT(size == protected_data_size);
169 gsec_test_copy(data_buffer, &corrupted_data_buffer, protected_data_size);
170 (*corrupted_data_buffer)++;
171 status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer,
172 protected_data_size, size, &size,
173 &error_message);
174 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
175 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
176 "Checking tag failed"));
177 GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0);
178 gpr_free(corrupted_data_buffer);
179 gpr_free(error_message);
180
181 /* Corrupt the end of protected data. */
182 size = data_size;
183 gsec_test_random_bytes(data_buffer, data_size);
184 status = alts_crypter_process_in_place(
185 client_seal, data_buffer, protected_data_size, size, &size, nullptr);
186 GPR_ASSERT(status == GRPC_STATUS_OK);
187 GPR_ASSERT(size == protected_data_size);
188 gsec_test_copy(data_buffer, &corrupted_data_buffer, protected_data_size);
189 (*(corrupted_data_buffer + protected_data_size - 1))++;
190 status = alts_crypter_process_in_place(server_unseal, corrupted_data_buffer,
191 protected_data_size, size, &size,
192 &error_message);
193 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
194 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
195 "Checking tag failed"));
196 GPR_ASSERT(memcmp(corrupted_data_buffer, zero_buffer, data_size) == 0);
197 gpr_free(corrupted_data_buffer);
198 gpr_free(error_message);
199
200 gpr_free(data_buffer);
201 gpr_free(zero_buffer);
202 }
203
alts_crypter_test_unsync_seal_unseal(alts_crypter * server_seal,alts_crypter * server_unseal,alts_crypter * client_seal,alts_crypter * client_unseal)204 static void alts_crypter_test_unsync_seal_unseal(alts_crypter* server_seal,
205 alts_crypter* server_unseal,
206 alts_crypter* client_seal,
207 alts_crypter* client_unseal) {
208 size_t data_size = gsec_test_bias_random_uint32(1024) + 1;
209 size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(server_seal);
210 size_t protected_data_size = data_size + num_overhead_bytes;
211 auto* data_buffer = static_cast<uint8_t*>(gpr_malloc(protected_data_size));
212 auto* zero_buffer = static_cast<uint8_t*>(gpr_zalloc(data_size));
213
214 /* Perform two seals at client, one unseal at server. */
215 size_t size = data_size;
216 gsec_test_random_bytes(data_buffer, data_size);
217 grpc_status_code status = alts_crypter_process_in_place(
218 client_seal, data_buffer, protected_data_size, size, &size, nullptr);
219 GPR_ASSERT(status == GRPC_STATUS_OK);
220 GPR_ASSERT(size == protected_data_size);
221
222 size = data_size;
223 gsec_test_random_bytes(data_buffer, data_size);
224 status = alts_crypter_process_in_place(
225 client_seal, data_buffer, protected_data_size, size, &size, nullptr);
226 GPR_ASSERT(status == GRPC_STATUS_OK);
227 GPR_ASSERT(size == protected_data_size);
228
229 char* error_message = nullptr;
230 status = alts_crypter_process_in_place(server_unseal, data_buffer,
231 protected_data_size, size, &size,
232 &error_message);
233 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
234 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
235 "Checking tag failed"));
236 GPR_ASSERT(memcmp(data_buffer, zero_buffer, data_size) == 0);
237 gpr_free(error_message);
238
239 /* Perform two seals at server, one unseal at client. */
240 size = data_size;
241 gsec_test_random_bytes(data_buffer, data_size);
242 status = alts_crypter_process_in_place(
243 server_seal, data_buffer, protected_data_size, size, &size, nullptr);
244 GPR_ASSERT(status == GRPC_STATUS_OK);
245 GPR_ASSERT(size == protected_data_size);
246
247 size = data_size;
248 gsec_test_random_bytes(data_buffer, data_size);
249 status = alts_crypter_process_in_place(
250 server_seal, data_buffer, protected_data_size, size, &size, nullptr);
251 GPR_ASSERT(status == GRPC_STATUS_OK);
252 GPR_ASSERT(size == protected_data_size);
253
254 status = alts_crypter_process_in_place(client_unseal, data_buffer,
255 protected_data_size, size, &size,
256 &error_message);
257 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
258 status, GRPC_STATUS_FAILED_PRECONDITION, error_message,
259 "Checking tag failed"));
260 GPR_ASSERT(memcmp(data_buffer, zero_buffer, data_size) == 0);
261 gpr_free(error_message);
262 gpr_free(data_buffer);
263 gpr_free(zero_buffer);
264 }
265
alts_crypter_test_input_sanity_check(alts_crypter * crypter_seal,alts_crypter * crypter_unseal)266 static void alts_crypter_test_input_sanity_check(alts_crypter* crypter_seal,
267 alts_crypter* crypter_unseal) {
268 size_t data_size = gsec_test_bias_random_uint32(1024) + 1;
269 size_t num_overhead_bytes = alts_crypter_num_overhead_bytes(crypter_seal);
270 size_t protected_data_size = data_size + num_overhead_bytes;
271 auto* data_buffer = static_cast<uint8_t*>(gpr_malloc(protected_data_size));
272 gsec_test_random_bytes(data_buffer, data_size);
273 char* error_message = nullptr;
274 size_t size = data_size;
275
276 /* Crypter is nullptr. */
277 grpc_status_code status = alts_crypter_process_in_place(
278 nullptr, data_buffer, protected_data_size, size, &size, &error_message);
279 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
280 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
281 "crypter or crypter->vtable has not been initialized properly."));
282 gpr_free(error_message);
283
284 /* Seal data is nullptr. */
285 size = data_size;
286 status = alts_crypter_process_in_place(
287 crypter_seal, nullptr, protected_data_size, size, &size, &error_message);
288 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
289 status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "data is nullptr."));
290 gpr_free(error_message);
291
292 /* Seal data size is 0. */
293 size = 0;
294 status = alts_crypter_process_in_place(crypter_seal, data_buffer,
295 protected_data_size, size, &size,
296 &error_message);
297 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
298 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
299 "data_size is zero."));
300 gpr_free(error_message);
301
302 /* Seal data buffer has a size smaller than the required. */
303 size = data_size;
304 status = alts_crypter_process_in_place(crypter_seal, data_buffer,
305 protected_data_size - 1, size, &size,
306 &error_message);
307 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
308 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
309 "data_allocated_size is smaller than sum of data_size and "
310 "num_overhead_bytes."));
311 gpr_free(error_message);
312
313 /* Unseal data is nullptr. */
314 size = data_size;
315 status = alts_crypter_process_in_place(crypter_unseal, nullptr,
316 protected_data_size, size, &size,
317 &error_message);
318 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
319 status, GRPC_STATUS_INVALID_ARGUMENT, error_message, "data is nullptr."));
320 gpr_free(error_message);
321
322 /* Unseal data size is 0. */
323 size = 0;
324 status = alts_crypter_process_in_place(crypter_unseal, data_buffer,
325 protected_data_size, size, &size,
326 &error_message);
327 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
328 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
329 "data_size is smaller than num_overhead_bytes."));
330 gpr_free(error_message);
331
332 /* Unseal data size is smaller than number of overhead bytes. */
333 size = num_overhead_bytes - 1;
334 status = alts_crypter_process_in_place(crypter_unseal, data_buffer,
335 protected_data_size, size, &size,
336 &error_message);
337 GPR_ASSERT(gsec_test_expect_compare_code_and_substr(
338 status, GRPC_STATUS_INVALID_ARGUMENT, error_message,
339 "data_size is smaller than num_overhead_bytes."));
340 gpr_free(error_message);
341 gpr_free(data_buffer);
342 }
343
create_random_alts_seal_crypter(alts_crypter ** server_seal,alts_crypter ** server_unseal,alts_crypter ** client_seal,alts_crypter ** client_unseal,gsec_aead_crypter ** server_crypter_seal,gsec_aead_crypter ** server_crypter_unseal,gsec_aead_crypter ** client_crypter_seal,gsec_aead_crypter ** client_crypter_unseal,bool rekey)344 static void create_random_alts_seal_crypter(
345 alts_crypter** server_seal, alts_crypter** server_unseal,
346 alts_crypter** client_seal, alts_crypter** client_unseal,
347 gsec_aead_crypter** server_crypter_seal,
348 gsec_aead_crypter** server_crypter_unseal,
349 gsec_aead_crypter** client_crypter_seal,
350 gsec_aead_crypter** client_crypter_unseal, bool rekey) {
351 size_t key_length = rekey ? kAes128GcmRekeyKeyLength : kAes128GcmKeyLength;
352 uint8_t* key;
353 gsec_test_random_array(&key, key_length);
354 gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength,
355 kAesGcmTagLength, rekey, server_crypter_seal,
356 nullptr);
357 gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength,
358 kAesGcmTagLength, rekey,
359 server_crypter_unseal, nullptr);
360 gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength,
361 kAesGcmTagLength, rekey, client_crypter_seal,
362 nullptr);
363 gsec_aes_gcm_aead_crypter_create(key, key_length, kAesGcmNonceLength,
364 kAesGcmTagLength, rekey,
365 client_crypter_unseal, nullptr);
366
367 size_t overflow_size = rekey ? 8 : 5;
368 alts_seal_crypter_create(*client_crypter_seal, /*is_client=*/true,
369 overflow_size, client_seal, nullptr);
370 alts_unseal_crypter_create(*client_crypter_unseal, /*is_client=*/true,
371 overflow_size, client_unseal, nullptr);
372 alts_seal_crypter_create(*server_crypter_seal, /*is_client=*/false,
373 overflow_size, server_seal, nullptr);
374 alts_unseal_crypter_create(*server_crypter_unseal, /*is_client=*/false,
375 overflow_size, server_unseal, nullptr);
376 gpr_free(key);
377 }
378
destroy_random_alts_seal_crypter(alts_crypter * server_seal,alts_crypter * server_unseal,alts_crypter * client_seal,alts_crypter * client_unseal)379 static void destroy_random_alts_seal_crypter(alts_crypter* server_seal,
380 alts_crypter* server_unseal,
381 alts_crypter* client_seal,
382 alts_crypter* client_unseal) {
383 alts_crypter_destroy(server_seal);
384 alts_crypter_destroy(server_unseal);
385 alts_crypter_destroy(client_seal);
386 alts_crypter_destroy(client_unseal);
387 }
388
alts_crypter_do_generic_tests()389 static void alts_crypter_do_generic_tests() {
390 alts_crypter *server_seal = nullptr, *server_unseal = nullptr,
391 *client_seal = nullptr, *client_unseal = nullptr;
392 gsec_aead_crypter *server_crypter_seal = nullptr,
393 *server_crypter_unseal = nullptr,
394 *client_crypter_seal = nullptr,
395 *client_crypter_unseal = nullptr;
396 /* Random seal and unseal tests */
397 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
398 &client_unseal, &server_crypter_seal,
399 &server_crypter_unseal, &client_crypter_seal,
400 &client_crypter_unseal, /*rekey=*/false);
401 alts_crypter_test_random_seal_unseal(server_seal, server_unseal, client_seal,
402 client_unseal);
403 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
404 client_unseal);
405
406 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
407 &client_unseal, &server_crypter_seal,
408 &server_crypter_unseal, &client_crypter_seal,
409 &client_crypter_unseal, /*rekey=*/true);
410 alts_crypter_test_random_seal_unseal(server_seal, server_unseal, client_seal,
411 client_unseal);
412 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
413 client_unseal);
414
415 /* Multiple random seal and unseal tests */
416 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
417 &client_unseal, &server_crypter_seal,
418 &server_crypter_unseal, &client_crypter_seal,
419 &client_crypter_unseal, /*rekey=*/false);
420 alts_crypter_test_multiple_random_seal_unseal(server_seal, server_unseal,
421 client_seal, client_unseal);
422 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
423 client_unseal);
424
425 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
426 &client_unseal, &server_crypter_seal,
427 &server_crypter_unseal, &client_crypter_seal,
428 &client_crypter_unseal, /*rekey=*/true);
429 alts_crypter_test_multiple_random_seal_unseal(server_seal, server_unseal,
430 client_seal, client_unseal);
431 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
432 client_unseal);
433
434 /* Corrupted unseal tests */
435 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
436 &client_unseal, &server_crypter_seal,
437 &server_crypter_unseal, &client_crypter_seal,
438 &client_crypter_unseal, /*rekey=*/false);
439 alts_crypter_test_corrupted_unseal(server_seal, server_unseal, client_seal,
440 client_unseal);
441 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
442 client_unseal);
443
444 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
445 &client_unseal, &server_crypter_seal,
446 &server_crypter_unseal, &client_crypter_seal,
447 &client_crypter_unseal, /*rekey=*/true);
448 alts_crypter_test_corrupted_unseal(server_seal, server_unseal, client_seal,
449 client_unseal);
450 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
451 client_unseal);
452
453 /* Unsync seal and unseal tests */
454 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
455 &client_unseal, &server_crypter_seal,
456 &server_crypter_unseal, &client_crypter_seal,
457 &client_crypter_unseal, /*rekey=*/false);
458 alts_crypter_test_unsync_seal_unseal(server_seal, server_unseal, client_seal,
459 client_unseal);
460 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
461 client_unseal);
462
463 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
464 &client_unseal, &server_crypter_seal,
465 &server_crypter_unseal, &client_crypter_seal,
466 &client_crypter_unseal, /*rekey=*/true);
467 alts_crypter_test_unsync_seal_unseal(server_seal, server_unseal, client_seal,
468 client_unseal);
469 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
470 client_unseal);
471
472 /* Input sanity check tests */
473 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
474 &client_unseal, &server_crypter_seal,
475 &server_crypter_unseal, &client_crypter_seal,
476 &client_crypter_unseal, /*rekey=*/false);
477 alts_crypter_test_input_sanity_check(server_seal, server_unseal);
478 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
479 client_unseal);
480
481 create_random_alts_seal_crypter(&server_seal, &server_unseal, &client_seal,
482 &client_unseal, &server_crypter_seal,
483 &server_crypter_unseal, &client_crypter_seal,
484 &client_crypter_unseal, /*rekey=*/true);
485 alts_crypter_test_input_sanity_check(server_seal, server_unseal);
486 destroy_random_alts_seal_crypter(server_seal, server_unseal, client_seal,
487 client_unseal);
488 }
489
main(int argc,char ** argv)490 int main(int argc, char** argv) {
491 alts_crypter_do_generic_tests();
492 return 0;
493 }
494