lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


>>> From that same wikipedia page and in reference to the pseudocode:
>>> Note 1: All variables are unsigned 32 bits and wrap modulo 232 when
>>> calculating
>>> So, band(H[1] + a) is achieving that.
>>
>> So why there is no 'and' here:
>>
>> local t2 = s0 + maj
>>
>> And not here:
>>
>> local t1 = h + s1 + ch + k[i] + w[i]
>
> There are two possibilities. Either that was a mistake in the code
> (those other cases *should* be using it), or it is not logically
> necessary to do it for these temporary values in order to get the same
> final result, which is all that really matters.

Yes, this code is probably with errors. It does correct checksums for
text files, but incorrect for binary files:

~/lua$ lua sha256.lua test.txt -
3c4ba860b4917a85b075f5e0c8cebe65bd1646d0d5ac3326a974ae965a44a5e1

~/lua$ sha256sum test.txt
3c4ba860b4917a85b075f5e0c8cebe65bd1646d0d5ac3326a974ae965a44a5e1  test.txt

~/lua$ lua sha256.lua test.jpg -
969906c25ee94d6c14aca4edb9b48a1fb350331bd244781d5046699e02d2654c

~/lua$ sha256sum test.jpg
fba5916247f503d4792f36af35f1356337e97073ba08b373059e33ab795b035e  test.jpg

This is on Debian squeeze 64 bit.