mpeterv / sha1

Implementation of SHA-1 and HMAC-SHA-1 in pure Lua.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feature: support stream ?

tst2005 opened this issue · comments

commented

Hello,

I create this issue to continue the discuss started here

commented

For the fun and just for the fun
I made a funny ugly hack to create a fake string from file-descriptor
The sha1 require #str, string.byte(str, i, j) and a concat operation.
See https://github.com/tst2005/lua-fd2string

Yeah that seems somewhat suboptimal...

Copying interface draft:

local state = sha1.new()
state:add(some_input) -- Not necessarily a multiple of block size
state:add(some_input)
...
local hex_sha1 = state.sha1()) -- sha1 of all collected inputs in hex
local bin_sha1 = state.binary() -- sha1 of all collected inputs in binary
state:add(some_input) -- Can keep adding inputs

Python's hashlib uses update instead of add.

commented

I don't know if you already know lockbox.
My current standalone sha1sum module built with lockbox

I run your tests and see your optimised sha1 is really faster than my sha1sum/lockbox current solution.

I've heard of lockbox before, looks like it doesn't really try to optimize for performance, and it doesn't provide a pure Lua version for Lua 5.1 itself either.

commented

http://lua-users.org/lists/lua-l/2018-11/msg00114.html
Thanks for all work you done.
Rest in pease my friend.