/*
 * @Description: 工具模块-MD5子模块
 * @Author: yangsw
 * @Date: 2021-06-22 12:17:44
 * @LastEditTime: 2021-07-13 14:58:36
 * @LastEditors: yangsw
 * @Reference: 
 */

#ifndef H_UTIL_MD5_H
#define H_UTIL_MD5_H

#include "../com/bsp/bsp_com.h"

typedef struct{
    gw_u32 count[2]; 
    gw_u32 state[4]; 
    gw_u8 buffer[64]; 
}MD5_CTX;                      
#define F(x,y,z) ((x & y) | (~x & z))
#define G(x,y,z) ((x & z) | (y & ~z))
#define H(x,y,z) (x^y^z)
#define I(x,y,z) (y ^ (x | ~z))
#define ROTATE_LEFT(x,n) ((x << n) | (x >> (32-n)))
#define FF(a,b,c,d,x,s,ac)    {a += F(b,c,d) + x + ac; a = ROTATE_LEFT(a,s); a += b;}
#define GG(a,b,c,d,x,s,ac) {a += G(b,c,d) + x + ac;a = ROTATE_LEFT(a,s); a += b;}
#define HH(a,b,c,d,x,s,ac) {a += H(b,c,d) + x + ac; a = ROTATE_LEFT(a,s); a += b;}
#define II(a,b,c,d,x,s,ac)   {  a += I(b,c,d) + x + ac; a = ROTATE_LEFT(a,s); a += b;}   

//private function
void Md5_Transform(gw_u32 state[4],gw_u8 block[64]);
void Md5_Encode(gw_u8 *output,gw_u32 *input,gw_u32 len);
void Md5_Decode(gw_u32 *output,gw_u8 *input,gw_u32 len); 

//public function
void Util_Md5_Init(MD5_CTX *context);
void Util_Md5_Update(MD5_CTX *context,gw_u8 *input,gw_u32 inputlen);
void Util_Md5_Final(MD5_CTX *context,gw_u8 digest[16]);


#endif

