5869 Need AES CMAC support in KCF+PKCS11
[unleashed.git] / usr / src / test / crypto-tests / tests / modes / aes / ccm / aes_ccm.c
bloba01129547ed876543392808ecb2a848c03642af2
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.
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.
13 * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
16 #include <strings.h>
17 #include <stdio.h>
19 #include "cryptotest.h"
20 #include "aes_ccm.h"
22 int
23 main(void)
25 int errs = 0;
26 int i;
27 uint8_t N[1024];
28 CK_AES_CCM_PARAMS param;
29 cryptotest_t args;
31 bzero(&param, sizeof (param));
33 args.out = N;
34 args.param = &param;
36 args.outlen = sizeof (N);
37 args.plen = sizeof (param);
39 args.mechname = SUN_CKM_AES_CCM;
40 args.updatelen = 1;
42 param.authData = CCM_DATA1;
43 args.key = CCM_KEY1;
44 args.keylen = sizeof (CCM_KEY1);
45 for (i = 0; i < 12; i++) {
46 param.ulMACSize = MACLEN[i];
47 param.ulNonceSize = NONCELEN[i];
48 param.ulAuthDataSize = AUTHLEN[i];
49 param.ulDataSize = DATALEN[i] - AUTHLEN[i];
50 param.nonce = NONCE[i];
52 args.in = CCM_DATA1 + AUTHLEN[i];
53 args.inlen = DATALEN[i] - AUTHLEN[i];
55 errs += run_test(&args, RES[i] + AUTHLEN[i],
56 RESLEN[i] - AUTHLEN[i], ENCR_FG);
57 (void) fprintf(stderr, "----------\n");
60 args.key = CCM_KEY2;
61 args.keylen = sizeof (CCM_KEY2);
62 for (i = 12; i < 24; i++) {
63 param.ulMACSize = MACLEN[i];
64 param.ulNonceSize = NONCELEN[i];
65 param.ulAuthDataSize = AUTHLEN[i];
66 param.ulDataSize = DATALEN[i] - AUTHLEN[i];
67 param.nonce = NONCE[i];
68 param.authData = DATA_2[i-12];
70 args.in = DATA_2[i-12] + AUTHLEN[i];
71 args.inlen = DATALEN[i] - AUTHLEN[i];
73 errs += run_test(&args, RES[i] + AUTHLEN[i],
74 RESLEN[i] - AUTHLEN[i], ENCR_FG);
75 (void) fprintf(stderr, "----------\n");
78 (void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n");
80 param.authData = CCM_DATA1;
81 args.key = CCM_KEY1;
82 args.keylen = sizeof (CCM_KEY1);
83 for (i = 0; i < 12; i++) {
84 param.ulMACSize = MACLEN[i];
85 param.ulNonceSize = NONCELEN[i];
86 param.ulAuthDataSize = AUTHLEN[i];
87 param.ulDataSize = RESLEN[i] - AUTHLEN[i];
88 param.nonce = NONCE[i];
90 args.in = RES[i] + AUTHLEN[i];
91 args.inlen = RESLEN[i] - AUTHLEN[i];
93 errs += run_test(&args, CCM_DATA1 + AUTHLEN[i],
94 DATALEN[i] - AUTHLEN[i], DECR_FG);
95 (void) fprintf(stderr, "----------\n");
98 args.key = CCM_KEY2;
99 args.keylen = sizeof (CCM_KEY2);
100 for (i = 12; i < 24; i++) {
101 param.ulMACSize = MACLEN[i];
102 param.ulNonceSize = NONCELEN[i];
103 param.ulAuthDataSize = AUTHLEN[i];
104 param.ulDataSize = RESLEN[i] - AUTHLEN[i];
105 param.nonce = NONCE[i];
106 param.authData = DATA_2[i-12];
108 args.in = RES[i] + AUTHLEN[i];
109 args.inlen = RESLEN[i] - AUTHLEN[i];
111 errs += run_test(&args, DATA_2[i-12] + AUTHLEN[i],
112 DATALEN[i] - AUTHLEN[i], ENCR_FG);
113 (void) fprintf(stderr, "----------\n");
116 if (errs != 0)
117 (void) fprintf(stderr, "%d tests failed\n", errs);
119 return (errs);