xref: /illumos-gate/usr/src/test/crypto-tests/tests/hmac/main.c (revision 5328fc53d11d7151861fa272e4fb0248b8f0e145)
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 int
31 main(void)
32 {
33 	int errs = 0;
34 	int i;
35 	uint8_t N[1024];
36 	cryptotest_t args = {
37 		.out = N,
38 		.outlen = sizeof (N),
39 		.plen = 0,
40 		.mechname = mechname,
41 		.updatelen = 1
42 	};
43 
44 	for (i = 0; i < msgcount; i++) {
45 		args.key = KEY[i];
46 		args.keylen = KEYLEN[i];
47 
48 		args.in = DATA[i];
49 		args.inlen = DATALEN[i];
50 
51 		errs += run_test(&args, HMAC[i], hmac_len, MAC_FG);
52 		(void) fprintf(stderr, "----------\n");
53 	}
54 	if (errs != 0)
55 		(void) fprintf(stderr, "%d tests failed\n", errs);
56 
57 	return (errs);
58 }
59