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_MD5_H 17 #define CRYPT_MD5_H 18 19 #include "hitls_build.h" 20 #ifdef HITLS_CRYPTO_MD5 21 22 #include <stdlib.h> 23 #include <stdint.h> 24 #include "crypt_types.h" 25 #include "bsl_params.h" 26 27 #ifdef __cplusplus 28 extern "C" { 29 #endif 30 31 #define CRYPT_MD5_DIGESTSIZE 16 32 #define CRYPT_MD5_BLOCKSIZE 64 33 34 typedef struct CryptMdCtx CRYPT_MD5_Ctx; 35 /** 36 * @ingroup MD5 37 * @brief Generate md context. 38 * 39 * @retval Success: cipher ctx. 40 * Fails: NULL. 41 */ 42 CRYPT_MD5_Ctx *CRYPT_MD5_NewCtx(void); 43 44 /** 45 * @ingroup MD5 46 * @brief free md context. 47 * 48 * @param ctx [IN] md handle 49 */ 50 void CRYPT_MD5_FreeCtx(CRYPT_MD5_Ctx *ctx); 51 /** 52 * @ingroup MD5 53 * @brief This API is used to initialize the MD5 context. 54 * 55 * @param ctx [in,out] Pointer to the MD5 context. 56 * @param param [in] Pointer to the parameter. 57 * 58 * @retval #CRYPT_SUCCESS Initialization succeeded. 59 * @retval #CRYPT_NULL_INPUT Pointer ctx is NULL 60 */ 61 int32_t CRYPT_MD5_Init(CRYPT_MD5_Ctx *ctx, BSL_Param *param); 62 63 /** 64 * @ingroup MD5 65 * @brief MD5 deinitialization API 66 * @param ctx [in,out] Pointer to the MD5 context. 67 */ 68 void CRYPT_MD5_Deinit(CRYPT_MD5_Ctx *ctx); 69 70 /** 71 * @ingroup MD5 72 * @brief Encode the input text and update the message digest. 73 * 74 * @param ctx [in,out] Pointer to the MD5 context. 75 * @param in [in] Pointer to the data to be calculated 76 * @param len [in] Length of the data to be calculated 77 * 78 * @retval #CRYPT_SUCCESS Succeeded in updating the internal status of the digest. 79 * @retval #CRYPT_NULL_INPUT The input parameter is NULL. 80 * @retval #CRYPT_MD5_INPUT_OVERFLOW The accumulated length of the input data exceeds the maximum (2^64 bits). 81 */ 82 int32_t CRYPT_MD5_Update(CRYPT_MD5_Ctx *ctx, const uint8_t *in, uint32_t len); 83 84 /** 85 * @ingroup MD5 86 * @brief Obtain the message digest based on the passed MD5 context. 87 * 88 * @param ctx [in,out] Pointer to the MD5 context. 89 * @param out [in] Digest buffer 90 * @param outLen [in,out] Digest buffer size 91 * 92 * @retval #CRYPT_SUCCESS succeeded in updating the internal status of the digest. 93 * @retval #CRYPT_NULL_INPUT The input parameter is NULL. 94 * @retval #CRYPT_MD5_OUT_BUFF_LEN_NOT_ENOUGH The output buffer length is insufficient. 95 */ 96 int32_t CRYPT_MD5_Final(CRYPT_MD5_Ctx *ctx, uint8_t *out, uint32_t *outLen); 97 98 /** 99 * @ingroup MD5 100 * @brief MD5 copy CTX function 101 * @param dst [out] Pointer to the new MD5 context. 102 * @param src [in] Pointer to the original MD5 context. 103 */ 104 int32_t CRYPT_MD5_CopyCtx(CRYPT_MD5_Ctx *dst, const CRYPT_MD5_Ctx *src); 105 106 /** 107 * @ingroup MD5 108 * @brief MD5 dup CTX function 109 * @param src [in] Pointer to the original MD5 context. 110 */ 111 CRYPT_MD5_Ctx *CRYPT_MD5_DupCtx(const CRYPT_MD5_Ctx *src); 112 113 #ifdef __cplusplus 114 } 115 #endif 116 117 #endif // HITLS_CRYPTO_MD5 118 119 #endif // CRYPT_MD5_H 120