xref: /illumos-gate/usr/src/test/crypto-tests/tests/hmac/main.c (revision 9b664393d4fdda96221e6ea9ea95790d3c15be70)
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  */
16 
17 #include <stdio.h>
18 
19 #include "cryptotest.h"
20 
21 extern char *mechname;
22 extern uint8_t *KEY[];
23 extern size_t KEYLEN[];
24 extern uint8_t *DATA[];
25 extern size_t DATALEN[];
26 extern uint8_t *HMAC[];
27 extern size_t hmac_len;
28 extern size_t msgcount;
29 
30 static size_t updatelens[] = {
31 	1, 8, 33, 67, CTEST_UPDATELEN_WHOLE, CTEST_UPDATELEN_END
32 };
33 
34 int
35 main(void)
36 {
37 	int errs = 0;
38 	int i;
39 	uint8_t N[1024];
40 	cryptotest_t args = {
41 		.out = N,
42 		.outlen = sizeof (N),
43 		.plen = 0,
44 		.mechname = mechname,
45 		.updatelens = updatelens
46 	};
47 
48 	for (i = 0; i < msgcount; i++) {
49 		args.key = KEY[i];
50 		args.keylen = KEYLEN[i];
51 
52 		args.in = DATA[i];
53 		args.inlen = DATALEN[i];
54 
55 		errs += run_test(&args, HMAC[i], hmac_len, MAC_FG);
56 		(void) fprintf(stderr, "----------\n");
57 	}
58 	if (errs != 0)
59 		(void) fprintf(stderr, "%d tests failed\n", errs);
60 
61 	return (errs);
62 }
63