• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright 2014-2022 The GmSSL Project. All Rights Reserved.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the License); you may
5  *  not use this file except in compliance with the License.
6  *
7  *  http://www.apache.org/licenses/LICENSE-2.0
8  */
9 
10 #include <stdio.h>
11 #include <string.h>
12 #include <stdlib.h>
13 #include <gmssl/sm3.h>
14 
15 
main(void)16 int main(void)
17 {
18 	SM3_HMAC_CTX hmac_ctx;
19 	unsigned char key[16] = {
20 		0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,
21 		0x01,0xf2,0x03,0x04,0x05,0x06,0x07,0x08,
22 	};
23 	unsigned char mbuf[16] = {
24 		0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
25 		0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,
26 	};
27 	unsigned char hmac[32] = {0};
28 	int i;
29 
30 
31 	sm3_hmac_init(&hmac_ctx, key, sizeof(key));
32 	sm3_hmac_update(&hmac_ctx, mbuf, sizeof(mbuf));
33 	sm3_hmac_finish(&hmac_ctx, hmac);
34 
35 	printf("hmac: ");
36 	for (i = 0; i < sizeof(hmac); i++) {
37 		printf("%02X", hmac[i]);
38 	}
39 	printf("\n");
40 
41 	memset(hmac, 0, sizeof(hmac));
42 	sm3_hmac(key, sizeof(key), mbuf, sizeof(mbuf), hmac);
43 
44 	printf("hmac: ");
45 	for (i = 0; i < sizeof(hmac); i++) {
46 		printf("%02X", hmac[i]);
47 	}
48 	printf("\n");
49 
50 	return 0;
51 }
52