yoy.be "Why-o-Why"

md5.pas

2012-02-16 20:26  md5  coding delphi freeware  [permalink]

This is odd, it looks like there isn't an open source md5.pas unit. And by open source I mean under a permissive license or without copyright or licensing. So I set out to write my own and share it here. I based it on the original RFC, and even more the description than the reference implementation, because it uses a few of those C tricks I don't like. I hope it's performant enough, in case you're demanding performance of it. I've done some testing myself, but if you detect any kind of issue, please let me know.

md5.pas with MD5Hash for strings, sometimes used with passwords

md5Stream.pas with MD5HashFromStream which takes any kind of stream (TFileStream, TMemoryStream...), and optionally a preset number of bytes to take from the stream (from the current position!).

Enjoy. 

md5.zip (25KB)

Update: since MD5 and SHA1 are really similar, I've done the same for SHA1 and added sha1.pas and sha1Stream.pas.
Update 2: since I needed it for something else, I've added RIPEMD160 as well. And while I'm at it SHA256 as well
Update 3: added MurMurHash3...
Important:
though the headers state "License: no license, free for any use" it also implies no warranties are made. No warranty of a fitness for a purpose or merchantability, and non-infringement and all. No liability for claims or damages with all your contracts and torts and otherwise arising connection dealings you know who you are. I expect I'm sufficiently covered by the laws of my home country (not the U.S.).
Also: in the spirit of this warning (Act 3 second image) I make no guarantees whatsoever about robustness against side-channel attacks or anything else for that matter.

Update 4: I've also included the files in a github repo here.

twitter reddit linkedin facebook