int HashFile(char **Return, const char *Type, const char *Path, int Encoding) { HASH *Hash; STREAM *S; char *Tempstr=NULL; int result; S=STREAMOpen(Path,"r"); if (! S) return(FALSE); Hash=HashInit(Type); if (! Hash) { STREAMClose(S); return(FALSE); } Tempstr=SetStrLen(Tempstr,4096); result=STREAMReadBytes(S,Tempstr,4096); while (result !=EOF) { Hash->Update(Hash, Tempstr, result); result=STREAMReadBytes(S,Tempstr,4096); } DestroyString(Tempstr); STREAMClose(S); result=HashFinish(Hash, Encoding, Return); return(result); }
int HashratCheckSignedFile(char *Path, HashratCtx *Ctx) { STREAM *S; char *Tempstr=NULL, *HashStr=NULL; THash *Hash, *tmpHash; int LineCount=0; S=STREAMOpenFile(Path, SF_RDWR); if (! S) return(FALSE); Hash=HashInit(Ctx->HashType); Tempstr=STREAMReadLine(Tempstr, S); while (Tempstr) { LineCount++; //hashrat-integrity-mark: 2014/10/29 21:05:19 md5:nTnlHmvVowFowmxXtm0uNw== if (strncmp(Tempstr, "hashrat-integrity-mark: ",24)==0) { tmpHash=Hash->Clone(Hash); HashFinish(tmpHash,ENCODE_BASE64,&HashStr); HashratOutputSigningCheck(Ctx, HashStr, Tempstr, LineCount); } Hash->Update(Hash ,Tempstr, StrLen(Tempstr)); Tempstr=STREAMReadLine(Tempstr, S); } DestroyString(Tempstr); DestroyString(HashStr); return(TRUE); }
int HashBytes(char **Return, const char *Type, const char *text, int len, int Encoding) { HASH *Hash; int result; Hash=HashInit(Type); if (! Hash) return(0); Hash->Update(Hash, text, len); result=HashFinish(Hash, Encoding, Return); return(result); }