RTU_ALL_AI/release/inc/myMd5.h

59 lines
1.6 KiB
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* @file myMd5.h
* @brief MD5 消息摘要算法接口RFC 1321
* @details 计算 128 位哈希值,支持流式输入。
* 提供单次调用便捷函数 md5_string()。
*/
#ifndef _MY_MD5_H_
#define _MY_MD5_H_
#include <stdint.h>
#ifdef __cplusplus
extern "C"
{
#endif
/**
* @brief MD5 计算上下文(状态 + 计数 + 待处理缓冲区)
*/
typedef struct
{
uint32_t state[4]; /* A, B, C, D 四个 32 位状态寄存器 */
uint32_t count[2]; /* 位计数(低 32 位, 高 32 位) */
unsigned char buf[64]; /* 待处理数据缓冲区64 字节) */
} stru_md5_ctx;
/**
* @brief 初始化 MD5 上下文
* @param ctx 上下文指针(设置魔数 A=0x67452301 B=0xefcdab89 C=0x98badcfe D=0x10325476
*/
void md5_start(stru_md5_ctx *ctx);
/**
* @brief 输入待计算数据(可多次调用,支持流式处理)
* @param ctx 上下文指针
* @param data 数据缓冲区
* @param len 数据长度(字节)
*/
void md5_update(stru_md5_ctx *ctx, const unsigned char *data, int len);
/**
* @brief 完成计算,输出 16 字节 MD5 摘要
* @param ctx 上下文指针
* @param result 输出缓冲区(至少 16 字节)
*/
void md5_final(stru_md5_ctx *ctx, unsigned char result[16]);
/**
* @brief 单次调用便捷函数:计算字符串的 MD5返回大写十六进制字符串
* @param input 输入字符串(以 '\0' 结尾)
* @param output 输出缓冲区(至少 33 字节,含结尾 '\0'
*/
void md5_string(const char *input, char output[33]);
#ifdef __cplusplus
}
#endif
#endif