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_SM3_H 17 #define CRYPT_SM3_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_CRYPTO_SM3 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 #define CRYPT_SM3_BLOCKSIZE 64 32 #define CRYPT_SM3_DIGESTSIZE 32 33 34 typedef struct CryptSm3Ctx CRYPT_SM3_Ctx; 35 36 /** 37 * @ingroup SM3 38 * @brief Generate md context. 39 * 40 * @retval Success: cipher ctx. 41 * Fails: NULL. 42 */ 43 CRYPT_SM3_Ctx *CRYPT_SM3_NewCtx(void); 44 45 /** 46 * @ingroup SM3 47 * @brief free md context. 48 * 49 * @param ctx [IN] md handle 50 */ 51 void CRYPT_SM3_FreeCtx(CRYPT_SM3_Ctx *ctx); 52 53 /** 54 * @ingroup SM3 55 * @brief This API is used to initialize the SM3 context. 56 * 57 * @param ctx [in,out] SM3 context pointer. 58 * @param *param [in] Pointer to the parameter. 59 * 60 * @retval #CRYPT_SUCCESS initialization succeeded. 61 * @retval #CRYPT_NULL_INPUT Pointer ctx is NULL 62 */ 63 int32_t CRYPT_SM3_Init(CRYPT_SM3_Ctx *ctx, BSL_Param *param); 64 65 /** 66 * @ingroup SM3 67 * @brief Encode the text and update the message digest. 68 * 69 * @param ctx [in,out] SM3 context pointer. 70 * @param in [in] Pointer to the data to be calculated 71 * @param len [in] Length of the data to be calculated 72 * 73 * @retval #CRYPT_SUCCESS succeeded in updating the internal status of the digest. 74 * @retval #CRYPT_NULL_INPUT The input parameter is NULL. 75 * @retval #CRYPT_SM3_INPUT_OVERFLOW Accumulated input data length exceeds the maximum (2^64 bits). 76 */ 77 int32_t CRYPT_SM3_Update(CRYPT_SM3_Ctx *ctx, const uint8_t *in, uint32_t len); 78 79 /** 80 * @ingroup SM3 81 * @brief Obtain the message digest based on the passed SM3 text. 82 * 83 * @param ctx [in,out] SM3 context pointer. 84 * @param out [in] digest buffer 85 * @param outLen [in,out] digest buffer size 86 * 87 * @retval #CRYPT_SUCCESS succeeded in updating the internal status of the digest. 88 * @retval #CRYPT_NULL_INPUT The input parameter is NULL. 89 * @retval #CRYPT_SM3_OUT_BUFF_LEN_NOT_ENOUGH The output buffer is insufficient. 90 */ 91 int32_t CRYPT_SM3_Final(CRYPT_SM3_Ctx *ctx, uint8_t *out, uint32_t *outLen); 92 93 /** 94 * @ingroup SM3 95 * @brief SM3 Deinitialization API 96 * @param ctx [in,out] SM3 context pointer. 97 */ 98 void CRYPT_SM3_Deinit(CRYPT_SM3_Ctx *ctx); 99 100 /** 101 * @ingroup SM3 102 * @brief Copy SM3 CTX function 103 * @param dst [out] SM3 context pointer. 104 * @param src [in] Pointer to the original SM3 context. 105 */ 106 int32_t CRYPT_SM3_CopyCtx(CRYPT_SM3_Ctx *dst, const CRYPT_SM3_Ctx *src); 107 108 /** 109 * @ingroup SM3 110 * @brief Dup SM3 CTX function 111 * @param src [in] Pointer to the original SM3 context. 112 */ 113 CRYPT_SM3_Ctx *CRYPT_SM3_DupCtx(const CRYPT_SM3_Ctx *src); 114 115 #ifdef __cplusplus 116 } 117 #endif /* __cpluscplus */ 118 119 #endif // HITLS_CRYPTO_SM3 120 121 #endif // CRYPT_SM3_H 122