X-Git-Url: http://www.lcore.org/git/lcore.git/blobdiff_plain/e27ef2c6aab3a2a8051314bd37bb3b2386775f36..refs/heads/master:/fastmd5.pas?ds=inline diff --git a/fastmd5.pas b/fastmd5.pas index 6455e5c..ad19876 100644 --- a/fastmd5.pas +++ b/fastmd5.pas @@ -39,7 +39,7 @@ type {$i uint32.inc} type - dvar=array[0..0] of byte; + dvar=array[0..65535] of byte; Tmd5state=record buf:array[0..63] of byte; H:array[0..3] of uint32; @@ -57,6 +57,8 @@ procedure getmd5(const data;len:longint;var result); function md5tostr(const md5:tmd5):ansistring; +function md5selftest:boolean; + implementation function inttohex(val,bits:integer):ansistring; @@ -211,7 +213,7 @@ begin b := state.msglen and 63; inc(state.msglen,len); - while (state.msglen > $20000000) do begin + while (state.msglen >= $20000000) do begin dec(state.msglen,$20000000); inc(state.msglenhi); end; @@ -294,4 +296,18 @@ begin md5tostr := s; end; +function md5selftest; +const + teststring:ansistring='The quick brown fox jumps over the lazy dog'; + testresult:array[0..15] of byte=($9e,$10,$7d,$9d,$37,$2b,$b6,$82,$6b,$d8,$1d,$35,$42,$a4,$19,$d6); +var + h:tmd5; + a:integer; +begin + getmd5(teststring[1],length(teststring),h); + result := true; + for a := 0 to 15 do if h[a] <> ord(testresult[a]) then result := false; +end; + + end.