lua-users home
lua-l archive

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




On 9 September 2011 14:57, waspoza <waspoza@gmail.com> wrote:
On Fri, Sep 9, 2011 at 3:45 PM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> > In digestblock function there is a line: H[1] = band(H[1] + a).
>
>> I'm not sure about this, but I've heard of people doing similar things
>> in _javascript_ to force the native Number type to a 32-bit integer,
>> taking overflow into account correctly, etc.
>
> That's what the comment says:
>        -- Add (mod 2^32) this chunk's hash to result so far:

Yes, but on http://en.wikipedia.org/wiki/SHA-2 pseudocode says:

 Add this chunk's hash to result so far:
   h0 := h0 + a

So in pseudocode this line is no different from other additions. And
in lua code there is a difference. Why?

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.

-Lee