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 27 #include "cryptotest.h" 28 #include "aes_cbc_pad.h" 29 30 int 31 main(void) 32 { 33 int errs = 0; 34 int i; 35 uint8_t N[1024]; 36 cryptotest_t args; 37 38 args.out = N; 39 40 args.outlen = sizeof (N); 41 args.plen = AES_BLOCK_LEN; 42 43 args.mechname = CBC_PAD; 44 args.updatelen = 1; 45 46 47 for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) { 48 args.in = DATA[i]; 49 args.key = KEY[i]; 50 args.param = IV[i]; 51 52 args.inlen = DATALEN[i]; 53 args.keylen = KEYLEN[i]; 54 55 errs += run_test(&args, RES[i], RESLEN[i], ENCR_FG); 56 (void) fprintf(stderr, "----------\n"); 57 } 58 59 (void) fprintf(stderr, "\t\t\t=== decrypt ===\n----------\n\n"); 60 61 for (i = 0; i < sizeof (RES) / sizeof (RES[0]); i++) { 62 args.in = RES[i]; 63 args.key = KEY[i]; 64 args.param = IV[i]; 65 66 args.inlen = RESLEN[i]; 67 args.keylen = KEYLEN[i]; 68 69 errs += run_test(&args, DATA[i], DATALEN[i], DECR_FG); 70 (void) fprintf(stderr, "----------\n"); 71 } 72 73 if (errs != 0) 74 (void) fprintf(stderr, "%d tests failed\n", errs); 75 76 return (errs); 77 } 78