1 /*
2  * This file and its contents are supplied under the terms of the
3  * Common Development and Distribution License ("CDDL"), version 1.0.
4  * You may only use this file in accordance with the terms of version
5  * 1.0 of the CDDL.
6  *
7  * A full copy of the text of the CDDL should have accompanied this
8  * source.  A copy of the CDDL is also available via the Internet at
9  * http://www.illumos.org/license/CDDL.
10  */
11 
12 /*
13  * Copyright 2016 Nexenta Systems, Inc.  All rights reserved.
14  * Copyright 2019 Joyent, Inc.
15  */
16 
17 #include <aes/aes_impl.h>
18 #include <stdio.h>
19 #include "cryptotest.h"
20 #include "aes_ecb.h"
21 
22 static size_t updatelens[] = {
23 	1, AES_BLOCK_LEN, AES_BLOCK_LEN + 1, 2*AES_BLOCK_LEN,
24 	CTEST_UPDATELEN_WHOLE, CTEST_UPDATELEN_END
25 };
26 
27 int
main(void)28 main(void)
29 {
30 	int errs = 0;
31 	int i;
32 	uint8_t N[1024];
33 	cryptotest_t args = {
34 		.in = ECB_DATA,
35 		.inlen = sizeof (ECB_DATA),
36 		.out = N,
37 		.outlen = sizeof (N),
38 		.updatelens = updatelens,
39 		.mechname = SUN_CKM_AES_ECB
40 	};
41 
42 	for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) {
43 		args.key = KEY[i];
44 		args.keylen = KEYLEN[i];
45 		errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG);
46 		(void) fprintf(stderr, "----------\n");
47 	}
48 
49 	(void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n");
50 
51 	for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) {
52 		args.key = KEY[i];
53 		args.in = RES[i];
54 		args.keylen = KEYLEN[i];
55 		args.inlen = RESLEN[i];
56 		errs += run_test(&args, ECB_DATA, sizeof (ECB_DATA), DECR_FG);
57 		(void) fprintf(stderr, "----------\n");
58 	}
59 	if (errs != 0)
60 		(void) fprintf(stderr, "%d tests failed\n", errs);
61 
62 	return (errs);
63 }
64