5869 Need AES CMAC support in KCF+PKCS11
[unleashed.git] / usr / src / test / crypto-tests / tests / modes / aes / gcm / aes_gcm.c
blob764cbba3857cb34821e5a160555433b7e78fde9d
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 2016 Nexenta Systems, Inc. All rights reserved.
16 #include <strings.h>
17 #include <stdio.h>
18 #include "cryptotest.h"
19 #include "aes_gcm.h"
21 const size_t GCM_SPEC_TAG_LEN = 16;
22 int
23 main(void)
25 int errs = 0;
26 int i;
27 uint8_t N[1024];
28 size_t taglen = GCM_SPEC_TAG_LEN;
30 CK_AES_GCM_PARAMS param;
31 cryptotest_t args;
33 bzero(&param, sizeof (param));
34 param.ulTagBits = taglen*8;
36 args.out = N;
37 args.param = &param;
39 args.outlen = sizeof (N);
40 args.plen = sizeof (param);
42 args.mechname = SUN_CKM_AES_GCM;
43 args.updatelen = 1;
45 for (i = 0; i < sizeof (DATA) / sizeof (DATA[0]); i++) {
46 args.in = DATA[i];
47 args.key = KEY[i];
49 args.inlen = DATALEN[i];
50 args.keylen = KEYLEN[i];
52 param.pIv = IV[i];
53 param.ulIvLen = IVLEN[i];
54 param.ulIvBits = IVLEN[i]*8;
55 param.pAAD = AUTH[i];
56 param.ulAADLen = AUTHLEN[i];
59 errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG);
60 (void) fprintf(stderr, "----------\n");
63 (void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n");
65 for (i = 0; i < sizeof (DATA) / sizeof (DATA[0]); i++) {
66 args.in = RES[i];
67 args.key = KEY[i];
69 args.inlen = RESLEN[i];
70 args.keylen = KEYLEN[i];
72 param.pIv = IV[i];
73 param.ulIvLen = IVLEN[i];
74 param.ulIvBits = IVLEN[i]*8;
75 param.pAAD = AUTH[i];
76 param.ulAADLen = AUTHLEN[i];
79 errs += run_test(&args, DATA[i], DATALEN[i], DECR_FG);
80 (void) fprintf(stderr, "----------\n");
83 if (errs != 0)
84 (void) fprintf(stderr, "%d tests failed\n", errs);
86 return (errs);