1 /*
2  * Copyright (C) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FILLP_HMAC_H
17 #define FILLP_HMAC_H
18 #include "sha256.h"
19 #include "spunge.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif
24 
25 
26 /* HMAC PAD value */
27 #define FILLP_HMAC_IPAD 0x36u
28 
29 /* HMAC PAD value */
30 #define FILLP_HMAC_OPAD 0x5Cu
31 
32 
33 #define FILLP_HMAC_SHA256_CTX_SIZE 208
34 
35 typedef struct {
36     FillpSha256Ctx hashki[1];
37     FillpSha256Ctx hashko[1];
38 } FillpHmacSha256Ctx;
39 
40 
41 /**
42 * @defgroup FillpHmacSha256
43 * @ingroup sec_cryptoStructures
44 * @par Prototype
45 * @code
46 * typedef struct
47 {
48     SEC_UCHAR data[FILLP_HMAC_SHA256_CTX_SIZE];
49 }FillHmacSha256CtxOld;
50 * @endcode
51 *
52 * @datastruct data[FILLP_HMAC_SHA256_CTX_SIZE] Represents the buffer for
53 * HMAC SHA256
54 * context.
55 */
56 
57 typedef struct {
58     FILLP_UINT8 data[FILLP_HMAC_SHA256_CTX_SIZE];
59 } FillpHmacSha256;
60 
61 
62 void FillpHmacSha256Init(OUT FillpHmacSha256 ctx[1], IN FILLP_UINT8 *key, FILLP_UINT32 klen,
63     struct SpungeInstance *pcbInst);
64 
65 void FillpHmacSha256Update(IO FillpHmacSha256 ctx[1], FILLP_CONST FILLP_UINT8 *data, FILLP_UINT32 dlen);
66 
67 void FillpHmacSha256Final(IO FillpHmacSha256 ctx[1], OUT FILLP_UINT8 digest[FILLP_SHA256_DIGEST_SIZE],
68     FILLP_UINT32 size);
69 
70 #ifdef __cplusplus
71 }
72 #endif
73 
74 #endif /* FILLP_HMAC_H */
75