Resource icon

[Reusable] Bastardized SHA-1 and HMAC-SHA1 Routines in Pure Lua 2021-04-24

This thread contains content that may be reused, modified, or ported by anyone.


WR 102
Borrowed from this blog post:

Updated to fit the constraints of SRB2. - Ie. Bastardized*
This is more of a utility WAD than anything.

Utilize Lua's asserts to verify your sha1 or hmac_sha1 text hashes.
Pass sha1() a string, and it returns a hash as a 40-character hex string. For example, calling the following:
local hash = sha1("test")

puts the 40-character string into the hash variable

Pass sha1_hmac() a key and a message, and it returns the signature as a 40-byte hex string.

There are also 2 "*_binary" versions which do the same, but return the 20-byte string of raw data that the 40-byte hex strings represent.

* This is a bastardized version of SHA-1 and HMAC-SHA1 routines. Meaning that these SHA1 and HMAC-SHA1 routines are only compatible with checking hashes within SRB2 itself. Actual SHA1 and HMAC-SHA1 routines will give different results.
With the the lack of math.modf Library, measurements are done with the FRACUNIT (65536) unit of measurement instead.

Supporters / CoAuthors



    37.6 KB · Views: 147
Last edited by a moderator:

Who is viewing this thread (Total: 1, Members: 0, Guests: 1)