• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 HKS_OPENSSL_HMAC_H
17 #define HKS_OPENSSL_HMAC_H
18 
19 #include <stdint.h>
20 
21 #include "hks_crypto_hal.h"
22 #include "hks_type.h"
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 #define HKS_DIGEST_SHA1_LEN 20
29 #define HKS_DIGEST_SHA224_LEN 28
30 #define HKS_DIGEST_SHA256_LEN 32
31 #define HKS_DIGEST_SHA384_LEN 48
32 #define HKS_DIGEST_SHA512_LEN 64
33 #define HKS_DIGEST_SM3_LEN 32
34 
35 #ifdef HKS_SUPPORT_HMAC_C
36 #ifdef HKS_SUPPORT_HMAC_GENERATE_KEY
37 int32_t HksOpensslHmacGenerateKey(const struct HksKeySpec *spec, struct HksBlob *key);
38 #endif /* HKS_SUPPORT_HMAC_GENERATE_KEY */
39 
40 #if defined(HKS_SUPPORT_HMAC_SHA1) || defined(HKS_SUPPORT_HMAC_SHA224) || defined(HKS_SUPPORT_HMAC_SHA256) || \
41     defined(HKS_SUPPORT_HMAC_SHA384) || defined(HKS_SUPPORT_HMAC_SHA512) || defined(HKS_SUPPORT_HMAC_SM3)
42 int32_t HksOpensslHmac(const struct HksBlob *key, uint32_t digestAlg, const struct HksBlob *msg, struct HksBlob *mac);
43 
44 int32_t HksOpensslHmacInit(void **cryptoCtx, const struct HksBlob *key, uint32_t digestAlg);
45 
46 int32_t HksOpensslHmacUpdate(void *cryptoCtx, const struct HksBlob *msg);
47 
48 int32_t HksOpensslHmacFinal(void **cryptoCtx, struct HksBlob *msg, struct HksBlob *mac);
49 
50 void HksOpensslHmacHalFreeCtx(void **cryptoCtx);
51 #endif /* HKS_SUPPORT_HMAC_SHA1 */
52 #endif /* HKS_SUPPORT_HMAC_C */
53 
54 #ifdef __cplusplus
55 }
56 #endif
57 
58 #endif /* HKS_OPENSSL_HMAC_H */
59