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 /*
18  * The illumos KCF does not currently support CKM_AES_CBC_PAD (it
19  * requires the consumer to explicitly add/remove padding), so there is
20  * no SUN_CKM_xxx symbol.
21  */
22 #define	CBC_PAD	"CKM_AES_CBC_PAD"
23 
24 #include <aes/aes_impl.h>
25 #include <stdio.h>
26 #include <sys/sysmacros.h>
27 
28 #include "cryptotest.h"
29 #include "aes_cbc_pad.h"
30 
31 static size_t updatelens[] = {
32 	1, AES_BLOCK_LEN, AES_BLOCK_LEN + 1, 2*AES_BLOCK_LEN,
33 	CTEST_UPDATELEN_WHOLE, CTEST_UPDATELEN_END
34 };
35 
36 int
main(void)37 main(void)
38 {
39 	int errs = 0;
40 	int i;
41 	uint8_t N[1024];
42 	cryptotest_t args = {
43 		.out = N,
44 		.outlen = sizeof (N),
45 		.plen = AES_BLOCK_LEN,
46 		.mechname = CBC_PAD,
47 		.updatelens = updatelens
48 	};
49 
50 	for (i = 0; i < ARRAY_SIZE(RES); i++) {
51 		args.in = DATA[i];
52 		args.key = KEY[i];
53 		args.param = IV[i];
54 
55 		args.inlen = DATALEN[i];
56 		args.keylen = KEYLEN[i];
57 
58 		errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG);
59 		(void) fprintf(stderr, "----------\n");
60 	}
61 
62 	(void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n");
63 
64 	for (i = 0; i < ARRAY_SIZE(RES); i++) {
65 		args.in = RES[i];
66 		args.key = KEY[i];
67 		args.param = IV[i];
68 
69 		args.inlen = RESLEN[i];
70 		args.keylen = KEYLEN[i];
71 
72 		errs += run_test(&args, DATA[i], DATALEN[i], DECR_FG);
73 		(void) fprintf(stderr, "----------\n");
74 	}
75 
76 	if (errs != 0)
77 		(void) fprintf(stderr, "%d tests failed\n", errs);
78 
79 	return (errs);
80 }
81