/*
//	file:			md5.h
//	discription:	md5 function declare
//	author:			nianll
//	date:			2004-3-17 create
                    2004-12-16 modify        
//	copyright:		Beijing Senselock corp
*/
#ifndef _MD5_H_
#define _MD5_H_

#include "..\..\inc\hardware\ses_v3.h"

/*
//	type name:		MD5_HASH_CONTEXT
//	discription:	HASH context structure
*/
typedef struct _MD5_HASH_CONTEXT
{
	DWORD		pdwState[4];							/* store the result of the each block calculation	*/
	DWORD		pdwCount[2];							/* store the bit length of data					*/
	BYTE		pbBuffer[64];						/* store the remain data of the last block		*/
} MD5_HASH_CONTEXT;
#define	ECC_HASH_CONTEXT_LENGTH						sizeof(MD5_HASH_CONTEXT)

typedef union _MD5_HASH_DATA_BLOCK
{
	BYTE	pbBlock[40];
	DWORD	pdwBlock[16];
} MD5_HASH_DATA_BLOCK;

#define hash_rl(x, n)									(((x) << (n)) | ((x) >> (32-(n))))


/*
// C prorotype	:	void MD5Init(MD5_HASH_CONTEXT* pCtx)
// parameter(s)	:	[IN/OUT]	pbCtx		- input the hash context
// return value	:	none
// memory used	:	none
// remarks		:	init hash context for MD5
*/
void MD5Init(MD5_HASH_CONTEXT* pCtx);

/*
// C prorotype	:	void MD5Update(MD5_HASH_CONTEXT* pCtx, BYTE* pbIn, BYTE bLen)
// parameter(s)	:	[IN/OUT]	pCtx		- input the hash context pointer
//					[IN]		pbIn		- the buffer of data to be hash
//					[IN]		bLen		- length of input data
// return value	:	no return value
// memory used	:	none
// remarks		:	hash the input data using MD5 algorithm
*/
void MD5Update(MD5_HASH_CONTEXT* pCtx, BYTE* pbIn, BYTE bLen);

/*
// C prorotype	:	void MD5Final(MD5_HASH_CONTEXT* pCtx, BYTE* pbOut)
// parameter(s)	:	[IN/OUT]	pCtx		- input the hash context pointer
//					[IN]		pbOut		- return the result of hash
// return value	:	no return value
// memory used	:	none
// remarks		:	finish the MD5 calculate, and get the result
*/
void MD5Final(MD5_HASH_CONTEXT* pCtx, BYTE* pbOut);

#endif //_MD5_H_
