Jump to content

Strange bug in SHA256 script


2 replies to this topic

#1 toxicwolf

  • Members
  • 201 posts
  • LocationUnited Kingdom

Posted 01 July 2012 - 01: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

#2 RoD

  • Members
  • 313 posts

Posted 21 June 2013 - 11:09 AM

The dropbox external link isn't working.


  • Members
  • 42 posts
  • LocationGermany

Posted 21 June 2013 - 02: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.

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users