• 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 
11 #ifndef GMSSL_HMAC_H
12 #define GMSSL_HMAC_H
13 
14 #include <string.h>
15 #include <gmssl/digest.h>
16 
17 
18 #ifdef  __cplusplus
19 extern "C" {
20 #endif
21 
22 #define HMAC_MAX_SIZE	(DIGEST_MAX_SIZE)
23 
24 
25 typedef struct hmac_ctx_st {
26 	const DIGEST *digest;
27 	DIGEST_CTX digest_ctx;
28 	DIGEST_CTX i_ctx;
29 	DIGEST_CTX o_ctx;
30 } HMAC_CTX;
31 
32 
33 size_t hmac_size(const HMAC_CTX *ctx);
34 
35 int hmac_init(HMAC_CTX *ctx, const DIGEST *digest, const uint8_t *key, size_t keylen);
36 int hmac_update(HMAC_CTX *ctx, const uint8_t *data, size_t datalen);
37 int hmac_finish(HMAC_CTX *ctx, uint8_t *mac, size_t *maclen);
38 
39 int hmac(const DIGEST *md, const uint8_t *key, size_t keylen,
40 	const uint8_t *data, size_t dlen,
41 	uint8_t *mac, size_t *maclen);
42 
43 
44 #ifdef  __cplusplus
45 }
46 #endif
47 #endif
48