1 /* 2 * Copyright (C) 2015-2018 Alibaba Group Holding Limited 3 */ 4 5 #ifndef _INFRA_MD5_H_ 6 #define _INFRA_MD5_H_ 7 8 #include "linkkit/infra/infra_types.h" 9 10 typedef struct { 11 uint32_t total[2]; /*!< number of bytes processed */ 12 uint32_t state[4]; /*!< intermediate digest state */ 13 unsigned char buffer[64]; /*!< data block being processed */ 14 } iot_md5_context; 15 16 /** 17 * \brief Initialize MD5 context 18 * 19 * \param ctx MD5 context to be initialized 20 */ 21 void utils_md5_init(iot_md5_context *ctx); 22 23 /** 24 * \brief Clear MD5 context 25 * 26 * \param ctx MD5 context to be cleared 27 */ 28 void utils_md5_free(iot_md5_context *ctx); 29 30 /** 31 * \brief Clone (the state of) an MD5 context 32 * 33 * \param dst The destination context 34 * \param src The context to be cloned 35 */ 36 void utils_md5_clone(iot_md5_context *dst, const iot_md5_context *src); 37 38 /** 39 * \brief MD5 context setup 40 * 41 * \param ctx context to be initialized 42 */ 43 void utils_md5_starts(iot_md5_context *ctx); 44 45 /** 46 * \brief MD5 process buffer 47 * 48 * \param ctx MD5 context 49 * \param input buffer holding the data 50 * \param ilen length of the input data 51 */ 52 void utils_md5_update(iot_md5_context *ctx, const unsigned char *input, 53 uint32_t ilen); 54 55 /** 56 * \brief MD5 final digest 57 * 58 * \param ctx MD5 context 59 * \param output MD5 checksum result 60 */ 61 void utils_md5_finish(iot_md5_context *ctx, unsigned char output[16]); 62 63 /* Internal use */ 64 void utils_md5_process(iot_md5_context *ctx, const unsigned char data[64]); 65 66 /** 67 * \brief Output = MD5( input buffer ) 68 * 69 * \param input buffer holding the data 70 * \param ilen length of the input data 71 * \param output MD5 checksum result 72 */ 73 void utils_md5(const unsigned char *input, uint32_t ilen, 74 unsigned char output[16]); 75 76 void utils_hmac_md5(const char *msg, int msg_len, char *digest, const char *key, 77 int key_len); 78 79 #endif 80