xref: /illumos-gate/usr/src/test/crypto-tests/tests/modes/aes/ecb/aes_ecb.c (revision 300fdee27f8b59b381c1a0316bdee52fdfdb9213)
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  */
15 
16 #include <stdio.h>
17 #include "cryptotest.h"
18 #include "aes_ecb.h"
19 
20 int
21 main(void)
22 {
23 	int errs = 0;
24 	int i;
25 	uint8_t N[1024];
26 	cryptotest_t args;
27 
28 	args.in = ECB_DATA;
29 	args.out = N;
30 	args.param = NULL;
31 
32 	args.inlen = sizeof (ECB_DATA);
33 	args.outlen = sizeof (N);
34 	args.plen = 0;
35 
36 	args.mechname = SUN_CKM_AES_ECB;
37 	args.updatelen = 1;
38 
39 	for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) {
40 		args.key = KEY[i];
41 		args.keylen = KEYLEN[i];
42 		errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG);
43 		(void) fprintf(stderr, "----------\n");
44 	}
45 
46 	(void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n");
47 
48 	for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) {
49 		args.key = KEY[i];
50 		args.in = RES[i];
51 		args.keylen = KEYLEN[i];
52 		args.inlen = RESLEN[i];
53 		errs += run_test(&args, ECB_DATA, sizeof (ECB_DATA), DECR_FG);
54 		(void) fprintf(stderr, "----------\n");
55 	}
56 	if (errs != 0)
57 		(void) fprintf(stderr, "%d tests failed\n", errs);
58 
59 	return (errs);
60 }
61