This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
toxicwolf's profile picture

Strange bug in SHA256 script

Started by toxicwolf, 01 July 2012 - 12:54 PM
toxicwolf #1
Posted 01 July 2012 - 02:54 PM
Hi all, I found a SHA256 Lua implementation a little while ago, but when using it, it causes the 'bit' CC api to throw an error complaining that it expected a number and received a nil value.

This is the source code. I've managed to track the error down to line 135, where it says:

H[1] = band(H[1], a)
Yet, it is giving the function two numbers, since I checked this by adding type() checks for both 'H[1]' and 'a', and then again actually at the beginning of the band function in the bit api.
So I have no idea what the problem is, hopefully someone can help…

Thanks in advance,
Toxic Wolf
RoD #2
Posted 21 June 2013 - 12:09 PM
The dropbox external link isn't working.
KFAFSP #3
Posted 21 June 2013 - 03:32 PM
I just finished my own SHA-1 and SHA-256 implementation and had to do alot of fixing concerning the bit api. It just doesnt want to work correctly with DWORD values. Anyway, there actually was not any problem with ANDs. Are you sure this line is even correct, shouldn't it rather be something like :


H[1] = (H[1] + A) % (2 ^ 32)

Because it looks like the round-end hash adding operation to me, that you process after each digested chunk. Anyways, I had problems with bit.brshift (adding 1's on the left side…) and A + B exceeding 32bit value (fix is given in example, just do modulo). I cannot help you with the current problem, as I don't see a solution either. However, maybe you should take a closer look at the Library itself and maybe find another workaround.