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 2015 Nexenta Systems, Inc. All rights reserved. 14 * Copyright 2019 Joyent, Inc. 15 * Copyright 2023 RackTop Systems, Inc. 16 */ 17 18 #include <stdio.h> 19 #include <strings.h> 20 21 #include "cryptotest.h" 22 23 /* 24 * These are all supplied by the specific test. See; 25 * hmac_sha1.c hmac_sha1_gen.c ... 26 */ 27 extern char *mechname; 28 extern uint8_t *KEY[]; 29 extern size_t KEYLEN[]; 30 extern uint8_t *DATA[]; 31 extern size_t DATALEN[]; 32 extern uint8_t *HMAC[]; 33 extern size_t hmac_len; 34 extern size_t msgcount; 35 36 static size_t updatelens[] = { 37 1, 8, 33, 67, CTEST_UPDATELEN_WHOLE, CTEST_UPDATELEN_END 38 }; 39 40 int 41 main(void) 42 { 43 int errs = 0; 44 int i; 45 ulong_t param_len = hmac_len; 46 uint8_t N[1024]; 47 cryptotest_t args = { 48 .out = N, 49 .outlen = sizeof (N), 50 .plen = 0, 51 .mechname = mechname, 52 .updatelens = updatelens 53 }; 54 55 /* 56 * When running eg. SUN_CKM_SHA1_HMAC_GENERAL 57 * we need to provide a parameter that speifies 58 * the length of the hash result, which may be 59 * shorter than what the mech. can compute. 60 */ 61 if (strstr(mechname, "GENERAL") != NULL) { 62 args.param = ¶m_len; 63 args.plen = sizeof (param_len); 64 } 65 for (i = 0; i < msgcount; i++) { 66 args.key = KEY[i]; 67 args.keylen = KEYLEN[i]; 68 69 args.in = DATA[i]; 70 args.inlen = DATALEN[i]; 71 72 errs += run_test(&args, HMAC[i], hmac_len, MAC_FG); 73 (void) fprintf(stderr, "----------\n"); 74 } 75 if (errs != 0) 76 (void) fprintf(stderr, "%d tests failed\n", errs); 77 78 return (errs); 79 } 80