[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Trouble with sha1 and bitlib
- From: Choonster TheMage <choonster.2010@...>
- Date: Sun, 14 Apr 2013 21:17:33 +1000
On Sun, Apr 14, 2013 at 8:00 AM, Choonster TheMage
> I'm currently modifying a pure Lua sha1 and hmac_sha1 library I found
> a while back to use existing bitwise library functions instead of
> its pure Lua versions when possible.
> All of the bitwise arithmetic tests at the end of the file pass on all
> of the platforms I tested, except for the ones that print "nullop"
> followed by a series of zeroes (those tests aren't supported by all
> three bitwise libraries).
> Three of the four platforms pass all the validation tests, but for
> some reason Lua 5.1.5 with bitlib fails on the first one if bitlib's
> functions are used instead of the pure Lua equivalents (which pass all
> the tests).
> Would anyone with 5.1.5 and bitlib be willing to test the code and/or
> point out any obvious errors on my part? It can be run directly from
> the command line or with dofile.
>  https://github.com/Choonster/luabnet_tools/blob/master/lua/bnet/tools/external/sha1.lua
>  I've tested it on Lua 5.1.4 with Lua BitOp from LuaForWindows,
> Lua 5.1.5 with bitlib from the LuaDist repo, LuaJIT 2.0.1 with
> built-in Lua BitOp and Lua 5.2.2 with built-in bit32
>  https://github.com/LuaDist/bitlib
It turns out the problem was with the w32_rot function (left bitwise
rotation), which was giving a value off by 1 when used with bitlib's
XOR function. Re-implementing w32_rot using left and right shifts with
XOR according to the first example in  solved the problem.
The new w32_rot function can be found at  if anyone's interested.