• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #ifndef CRYPT_SHA1_H
17 #define CRYPT_SHA1_H
18 
19 #include "hitls_build.h"
20 #ifdef HITLS_CRYPTO_SHA1
21 
22 #include <stdint.h>
23 #include <stdlib.h>
24 #include "crypt_types.h"
25 #include "bsl_params.h"
26 
27 #ifdef __cplusplus
28 extern "C" {
29 #endif /* __cpluscplus */
30 
31 /* Length of the message digest buffer. */
32 #define CRYPT_SHA1_DIGESTSIZE 20
33 
34 /* Message processing block size */
35 #define CRYPT_SHA1_BLOCKSIZE   64
36 
37 typedef struct CryptSha1Ctx CRYPT_SHA1_Ctx;
38 /**
39  * @ingroup SHA1
40  * @brief Generate md context.
41  *
42  * @retval Success: cipher ctx.
43  *         Fails: NULL.
44  */
45 CRYPT_SHA1_Ctx *CRYPT_SHA1_NewCtx(void);
46 
47 /**
48  * @ingroup SHA1
49  * @brief free md context.
50  *
51  * @param ctx [IN] md handle
52  */
53 void CRYPT_SHA1_FreeCtx(CRYPT_SHA1_Ctx *ctx);
54 
55 /**
56  * @ingroup SHA1
57  * @brief This API is invoked to initialize the SHA-1 context.
58  *
59  * @param *ctx [in,out] Pointer to the SHA-1 context.
60  * @param *param [in] Pointer to the parameter.
61  *
62  * @retval #CRYPT_SUCCESS       initialization succeeded.
63  * @retval #CRYPT_NULL_INPUT    Pointer ctx is NULL
64  */
65 int32_t CRYPT_SHA1_Init(CRYPT_SHA1_Ctx *ctx, BSL_Param *param);
66 
67 /**
68  * @ingroup SHA1
69  * @brief Encode the input text and update the message digest.
70  *
71  * @param *ctx [in,out] Pointer to the SHA-1 context.
72  * @param *in [in] Pointer to the data to be calculated
73  * @param len [in] Length of the data to be calculated
74  *
75  * @retval #CRYPT_SUCCESS               succeeded in updating the internal status of the digest.
76  * @retval #CRYPT_NULL_INPUT            The input parameter is NULL.
77  * @retval #CRYPT_SHA1_ERR_OVERFLOW     input data length exceeds the maximum (2^64 bits)
78  */
79 int32_t CRYPT_SHA1_Update(CRYPT_SHA1_Ctx *ctx, const uint8_t *in, uint32_t len);
80 
81 /**
82  * @ingroup SHA1
83  * @brief Obtain the message digest based on the passed SHA-1 text.
84  *
85  * @param *ctx [in,out] Pointer to the SHA-1 context.
86  * @param *out [in] Digest buffer
87  * @param *len [in,out] Digest buffer size
88  *
89  * @retval #CRYPT_SUCCESS                       succeeded in obtaining the computed digest.
90  * @retval #CRYPT_NULL_INPUT                    The input parameter is NULL.
91  * @retval #CRYPT_SHA1_ERR_OVERFLOW             Input data length exceeds the maximum (2^64 bits).
92  * @retval #CRYPT_SHA1_OUT_BUFF_LEN_NOT_ENOUGH  The output buffer is insufficient.
93  */
94 int32_t CRYPT_SHA1_Final(CRYPT_SHA1_Ctx *ctx, uint8_t *out, uint32_t *len);
95 
96 /**
97  * @ingroup SHA1
98  * @brief SHA1 deinitialization API
99  * @param *ctx [in,out]     Pointer to the SHA-1 context.
100  */
101 void CRYPT_SHA1_Deinit(CRYPT_SHA1_Ctx *ctx);
102 
103 /**
104  * @ingroup SHA1
105  * @brief SHA1 copy CTX function
106  * @param dest [out]  Pointer to the dest SHA1 context.
107  * @param src [in]   Pointer to the original SHA1 context.
108  */
109 int32_t CRYPT_SHA1_CopyCtx(CRYPT_SHA1_Ctx *dst, const CRYPT_SHA1_Ctx *src);
110 
111 /**
112  * @ingroup SHA1
113  * @brief SHA1 dup CTX function
114  * @param src [in]   Pointer to the original SHA1 context.
115  */
116 CRYPT_SHA1_Ctx *CRYPT_SHA1_DupCtx(const CRYPT_SHA1_Ctx *src);
117 
118 #ifdef __cplusplus
119 }
120 #endif /* __cpluscplus */
121 
122 #endif // HITLS_CRYPTO_SHA1
123 
124 #endif // CRYPT_SHA1_H
125