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 <strings.h> 19 #include <stdio.h> 20 #include "cryptotest.h" 21 #include "aes_gcm.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 const size_t GCM_SPEC_TAG_LEN = 16; 29 30 int 31 main(void) 32 { 33 int errs = 0; 34 int i; 35 uint8_t N[1024]; 36 size_t taglen = GCM_SPEC_TAG_LEN; 37 38 CK_AES_GCM_PARAMS param = { 39 .ulTagBits = taglen * 8 40 }; 41 cryptotest_t args = { 42 .out = N, 43 .outlen = sizeof (N), 44 .param = ¶m, 45 .plen = sizeof (param), 46 .mechname = SUN_CKM_AES_GCM, 47 .updatelens = updatelens 48 }; 49 50 for (i = 0; i < sizeof (DATA) / sizeof (DATA[0]); i++) { 51 args.in = DATA[i]; 52 args.key = KEY[i]; 53 54 args.inlen = DATALEN[i]; 55 args.keylen = KEYLEN[i]; 56 57 param.pIv = IV[i]; 58 param.ulIvLen = IVLEN[i]; 59 param.ulIvBits = IVLEN[i]*8; 60 param.pAAD = AUTH[i]; 61 param.ulAADLen = AUTHLEN[i]; 62 63 64 errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG); 65 (void) fprintf(stderr, "----------\n"); 66 } 67 68 (void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n"); 69 70 for (i = 0; i < sizeof (DATA) / sizeof (DATA[0]); i++) { 71 args.in = RES[i]; 72 args.key = KEY[i]; 73 74 args.inlen = RESLEN[i]; 75 args.keylen = KEYLEN[i]; 76 77 param.pIv = IV[i]; 78 param.ulIvLen = IVLEN[i]; 79 param.ulIvBits = IVLEN[i]*8; 80 param.pAAD = AUTH[i]; 81 param.ulAADLen = AUTHLEN[i]; 82 83 84 errs += run_test(&args, DATA[i], DATALEN[i], DECR_FG); 85 (void) fprintf(stderr, "----------\n"); 86 } 87 88 if (errs != 0) 89 (void) fprintf(stderr, "%d tests failed\n", errs); 90 91 return (errs); 92 } 93