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 
20 #include "cryptotest.h"
21 #include "aes_cbc.h"
22 
23 static size_t updatelens[] = {
24 	1, AES_BLOCK_LEN, AES_BLOCK_LEN + 1, 2*AES_BLOCK_LEN,
25 	CTEST_UPDATELEN_WHOLE, CTEST_UPDATELEN_END
26 };
27 
28 int
main(void)29 main(void)
30 {
31 	int errs = 0;
32 	int i;
33 	uint8_t N[1024];
34 	cryptotest_t args = {
35 		.out = N,
36 		.outlen = sizeof (N),
37 		.plen = AES_BLOCK_LEN,
38 		.mechname = SUN_CKM_AES_CBC,
39 		.updatelens = updatelens
40 	};
41 
42 	for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) {
43 		args.in = DATA[i];
44 		args.key = KEY[i];
45 		args.param = IV[i];
46 
47 		args.inlen = DATALEN[i];
48 		args.keylen = KEYLEN[i];
49 
50 		errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG);
51 		(void) fprintf(stderr, "----------\n");
52 	}
53 
54 	(void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n");
55 
56 	for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) {
57 		args.in = RES[i];
58 		args.key = KEY[i];
59 		args.param = IV[i];
60 
61 		args.inlen = RESLEN[i];
62 		args.keylen = KEYLEN[i];
63 
64 		errs += run_test(&args, DATA[i], DATALEN[i], DECR_FG);
65 		(void) fprintf(stderr, "----------\n");
66 	}
67 
68 	if (errs != 0)
69 		(void) fprintf(stderr, "%d tests failed\n", errs);
70 
71 	return (errs);
72 }
73