Lua-hashings a Lua Hash Library

A while back I wrote lua-nums and said it was working on a project that needed its features. Well, this is that project!

lua-hashings is a pure Lua cryptographic hash library. This all started with crc32 and a work project. I was working with a third party API and they provided the ability to verify files using crc32 (only). At that time I wrote a crc32 calculation script. This got me thinking about Lua and hashing so I looked around to see what was out there. There isn’t much out there. A few simple hashes and they’re all one offs. Nothing like a true library.

Obviously I liked the challenge and decided to write a hash library that provides a large number of useful hashes. lua-hashings supports the following hashes:

  • adler32
  • blake2b
  • blake2s
  • crc32
  • md5
  • ripemd160
  • sha1
  • sha256
  • sha3_256
  • sha3_512
  • sha512
  • whirlpool

In addition to hashes I wrote implementations of some common hash related functions.

Additional hash functions

  • hmac
  • pbkdf2

All of the hashes use the same API so any can be used with these hash functions. Actually, anything that implements this API can be used.

new(data) or (data)
copy()
update(data)
digest()
hexdigest()

Also, I realize not everyone is going to want to use a full library when all they want is one hash so each file is self contained and can be used independently of the library. This does lead to some redundant code but I think it’s worth making the library more modular.

This ended up being just as fun to write as lua-nums was. I need to think about what else I could use lua-nums for…