#include "ckconfig.h"
#if CRYPTKIT_MD5_ENABLE
#include "feeTypes.h"
#include "feeHash.h"
#include "ckMD5.h"
#include "falloc.h"
#include "platform.h"
typedef struct {
MD5Context context;
int isDone;
unsigned char digest[MD5_DIGEST_SIZE];
} hashInst;
feeHash feeHashAlloc(void)
{
hashInst *hinst;
hinst = (hashInst *) fmalloc(sizeof(hashInst));
MD5Init(&hinst->context);
hinst->isDone = 0;
return hinst;
}
void feeHashReinit(feeHash hash)
{
hashInst *hinst = (hashInst *) hash;
MD5Init(&hinst->context);
hinst->isDone = 0;
}
void feeHashFree(feeHash hash)
{
hashInst *hinst = (hashInst *) hash;
memset(hinst, 0, sizeof(hashInst));
ffree(hinst);
}
void feeHashAddData(feeHash hash,
const unsigned char *data,
unsigned dataLen)
{
hashInst *hinst = (hashInst *) hash;
if(hinst->isDone) {
return;
}
MD5Update(&hinst->context, data, dataLen);
}
unsigned char *feeHashDigest(feeHash hash)
{
hashInst *hinst = (hashInst *) hash;
if(!hinst->isDone) {
MD5Final(&hinst->context, hinst->digest);
hinst->isDone = 1;
}
return hinst->digest;
}
unsigned feeHashDigestLen(void)
{
return MD5_DIGEST_SIZE;
}
#endif