Skip to content

Commit

Permalink
Add second argument to bit32.bor
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Nov 6, 2023
1 parent f1a7b54 commit 4d9dbd1
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 68 deletions.
10 changes: 5 additions & 5 deletions modules/sha1/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ local function processBlocks(digest: { number }, message: string, start: number,
e, d, c, b, a = d, c, bit32.lrotate(b, 30), a, temp
end

d1 = bit32.bor(a + d1)
d2 = bit32.bor(b + d2)
d3 = bit32.bor(c + d3)
d4 = bit32.bor(d + d4)
d5 = bit32.bor(e + d5)
d1 = bit32.bor(a + d1, 0)
d2 = bit32.bor(b + d2, 0)
d3 = bit32.bor(c + d3, 0)
d4 = bit32.bor(d + d4, 0)
d5 = bit32.bor(e + d5, 0)
end

-- Only update the digest once for the vine
Expand Down
16 changes: 8 additions & 8 deletions modules/sha224/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ local function processBlocks(digest: { number }, message: string, start: number,
a = temp1 + temp2
end

d1 = bit32.bor(a + d1)
d2 = bit32.bor(b + d2)
d3 = bit32.bor(c + d3)
d4 = bit32.bor(d + d4)
d5 = bit32.bor(e + d5)
d6 = bit32.bor(f + d6)
d7 = bit32.bor(g + d7)
d8 = bit32.bor(h + d8)
d1 = bit32.bor(a + d1, 0)
d2 = bit32.bor(b + d2, 0)
d3 = bit32.bor(c + d3, 0)
d4 = bit32.bor(d + d4, 0)
d5 = bit32.bor(e + d5, 0)
d6 = bit32.bor(f + d6, 0)
d7 = bit32.bor(g + d7, 0)
d8 = bit32.bor(h + d8, 0)
end

digest[1] = d1
Expand Down
16 changes: 8 additions & 8 deletions modules/sha256/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ local function processBlocks(digest: { number }, message: string, start: number,
a = temp1 + temp2
end

d1 = bit32.bor(a + d1)
d2 = bit32.bor(b + d2)
d3 = bit32.bor(c + d3)
d4 = bit32.bor(d + d4)
d5 = bit32.bor(e + d5)
d6 = bit32.bor(f + d6)
d7 = bit32.bor(g + d7)
d8 = bit32.bor(h + d8)
d1 = bit32.bor(a + d1, 0)
d2 = bit32.bor(b + d2, 0)
d3 = bit32.bor(c + d3, 0)
d4 = bit32.bor(d + d4, 0)
d5 = bit32.bor(e + d5, 0)
d6 = bit32.bor(f + d6, 0)
d7 = bit32.bor(g + d7, 0)
d8 = bit32.bor(h + d8, 0)
end

digest[1] = d1
Expand Down
44 changes: 22 additions & 22 deletions modules/sha384/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ local function processBlocks(
-- properly carrying bits. So, we have to simulate that.
-- This is the equivalent to temp & 0xFFFF_FFFF, which
-- truncates the integer for us.
block_back[t] = temp % 2 ^ 32
block_back[t] = bit32.bor(temp, 0)

block_front[t] = block_front[t - 16]
+ s0_front
Expand All @@ -187,9 +187,9 @@ local function processBlocks(

--stylua: ignore start
-- h + S1 + Ch(e, f, g) + K[t] + W[t]
local temp1_back = h_back + s1_back + bit32.bor(bit32.band(e_back, f_back), bit32.band(-1 - e_back, g_back)) + K_BACK[t] + block_back[t]
local temp1_front = h_front + s1_front + bit32.bor(bit32.band(e_front, f_front), bit32.band(-1 - e_front, g_front)) + K_FRONT[t] + block_front[t] + math.floor(temp1_back / 2 ^ 32)
temp1_back = bit32.bor(temp1_back)
local temp1_back = h_back + s1_back + bit32.bor(bit32.band(e_back, f_back), bit32.band(-1 - e_back, g_back), 0) + K_BACK[t] + block_back[t]
local temp1_front = h_front + s1_front + bit32.bor(bit32.band(e_front, f_front), bit32.band(-1 - e_front, g_front), 0) + K_FRONT[t] + block_front[t] + math.floor(temp1_back / 2 ^ 32)
temp1_back = bit32.bor(temp1_back, 0)

-- S0 + Maj
local temp2_back = s0_back + bit32.band(c_back, b_back) + bit32.band(a_back, bit32.bxor(c_back, b_back))
Expand All @@ -202,48 +202,48 @@ local function processBlocks(

e_back = temp1_back + d_back
e_front = temp1_front + d_front + math.floor(e_back / 2 ^ 32) -- -- TODO replace with integer division
e_back = bit32.bor(e_back)
e_back = bit32.bor(e_back, 0)

d_front, d_back = c_front, c_back
c_front, c_back = b_front, b_back
b_front, b_back = a_front, a_back

a_back = temp1_back + temp2_back
a_front = temp1_front + temp2_front + math.floor(a_back / 2 ^ 32)
a_back = bit32.bor(a_back)
a_back = bit32.bor(a_back, 0)
end

d1_back = d1_back + a_back
d1_front = bit32.bor(d1_front + a_front + math.floor(d1_back / 2 ^ 32))
d1_back = bit32.bor(d1_back)
d1_front = bit32.bor(d1_front + a_front + math.floor(d1_back / 2 ^ 32), 0)
d1_back = bit32.bor(d1_back, 0)

d2_back = d2_back + b_back
d2_front = bit32.bor(d2_front + b_front + math.floor(d2_back / 2 ^ 32))
d2_back = bit32.bor(d2_back)
d2_front = bit32.bor(d2_front + b_front + math.floor(d2_back / 2 ^ 32), 0)
d2_back = bit32.bor(d2_back, 0)

d3_back = d3_back + c_back
d3_front = bit32.bor(d3_front + c_front + math.floor(d3_back / 2 ^ 32))
d3_back = bit32.bor(d3_back)
d3_front = bit32.bor(d3_front + c_front + math.floor(d3_back / 2 ^ 32), 0)
d3_back = bit32.bor(d3_back, 0)

d4_back = d4_back + d_back
d4_front = bit32.bor(d4_front + d_front + math.floor(d4_back / 2 ^ 32))
d4_back = bit32.bor(d4_back)
d4_front = bit32.bor(d4_front + d_front + math.floor(d4_back / 2 ^ 32), 0)
d4_back = bit32.bor(d4_back, 0)

d5_back = d5_back + e_back
d5_front = bit32.bor(d5_front + e_front + math.floor(d5_back / 2 ^ 32))
d5_back = bit32.bor(d5_back)
d5_front = bit32.bor(d5_front + e_front + math.floor(d5_back / 2 ^ 32), 0)
d5_back = bit32.bor(d5_back, 0)

d6_back = d6_back + f_back
d6_front = bit32.bor(d6_front + f_front + math.floor(d6_back / 2 ^ 32))
d6_back = bit32.bor(d6_back)
d6_front = bit32.bor(d6_front + f_front + math.floor(d6_back / 2 ^ 32), 0)
d6_back = bit32.bor(d6_back, 0)

d7_back = d7_back + g_back
d7_front = bit32.bor(d7_front + g_front + math.floor(d7_back / 2 ^ 32))
d7_back = bit32.bor(d7_back)
d7_front = bit32.bor(d7_front + g_front + math.floor(d7_back / 2 ^ 32), 0)
d7_back = bit32.bor(d7_back, 0)

d8_back = d8_back + h_back
d8_front = bit32.bor(d8_front + h_front + math.floor(d8_back / 2 ^ 32))
d8_back = bit32.bor(d8_back)
d8_front = bit32.bor(d8_front + h_front + math.floor(d8_back / 2 ^ 32), 0)
d8_back = bit32.bor(d8_back, 0)
end

digestFront[1], digestBack[1] = d1_front, d1_back
Expand Down
44 changes: 22 additions & 22 deletions modules/sha512/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ local function processBlocks(
-- properly carrying bits. So, we have to simulate that.
-- This is the equivalent to temp & 0xFFFF_FFFF, which
-- truncates the integer for us.
block_back[t] = bit32.bor(temp)
block_back[t] = bit32.bor(temp, 0)

block_front[t] = block_front[t - 16]
+ s0_front
Expand All @@ -187,9 +187,9 @@ local function processBlocks(

--stylua: ignore start
-- h + S1 + Ch(e, f, g) + K[t] + W[t]
local temp1_back = h_back + s1_back + bit32.bor(bit32.band(e_back, f_back), bit32.band(-1 - e_back, g_back)) + K_BACK[t] + block_back[t]
local temp1_front = h_front + s1_front + bit32.bor(bit32.band(e_front, f_front), bit32.band(-1 - e_front, g_front)) + K_FRONT[t] + block_front[t] + math.floor(temp1_back / 2 ^ 32)
temp1_back = bit32.bor(temp1_back)
local temp1_back = h_back + s1_back + bit32.bor(bit32.band(e_back, f_back), bit32.band(-1 - e_back, g_back), 0) + K_BACK[t] + block_back[t]
local temp1_front = h_front + s1_front + bit32.bor(bit32.band(e_front, f_front), bit32.band(-1 - e_front, g_front), 0) + K_FRONT[t] + block_front[t] + math.floor(temp1_back / 2 ^ 32)
temp1_back = bit32.bor(temp1_back, 0)

-- S0 + Maj
local temp2_back = s0_back + bit32.band(c_back, b_back) + bit32.band(a_back, bit32.bxor(c_back, b_back))
Expand All @@ -202,48 +202,48 @@ local function processBlocks(

e_back = temp1_back + d_back
e_front = temp1_front + d_front + math.floor(e_back / 2 ^ 32) -- -- TODO replace with integer division
e_back = bit32.bor(e_back)
e_back = bit32.bor(e_back, 0)

d_front, d_back = c_front, c_back
c_front, c_back = b_front, b_back
b_front, b_back = a_front, a_back

a_back = temp1_back + temp2_back
a_front = temp1_front + temp2_front + math.floor(a_back / 2 ^ 32)
a_back = bit32.bor(a_back)
a_back = bit32.bor(a_back, 0)
end

d1_back = d1_back + a_back
d1_front = bit32.bor(d1_front + a_front + math.floor(d1_back / 2 ^ 32))
d1_back = bit32.bor(d1_back)
d1_front = bit32.bor(d1_front + a_front + math.floor(d1_back / 2 ^ 32), 0)
d1_back = bit32.bor(d1_back, 0)

d2_back = d2_back + b_back
d2_front = bit32.bor(d2_front + b_front + math.floor(d2_back / 2 ^ 32))
d2_back = bit32.bor(d2_back)
d2_front = bit32.bor(d2_front + b_front + math.floor(d2_back / 2 ^ 32), 0)
d2_back = bit32.bor(d2_back, 0)

d3_back = d3_back + c_back
d3_front = bit32.bor(d3_front + c_front + math.floor(d3_back / 2 ^ 32))
d3_back = bit32.bor(d3_back)
d3_front = bit32.bor(d3_front + c_front + math.floor(d3_back / 2 ^ 32), 0)
d3_back = bit32.bor(d3_back, 0)

d4_back = d4_back + d_back
d4_front = bit32.bor(d4_front + d_front + math.floor(d4_back / 2 ^ 32))
d4_back = bit32.bor(d4_back)
d4_front = bit32.bor(d4_front + d_front + math.floor(d4_back / 2 ^ 32), 0)
d4_back = bit32.bor(d4_back, 0)

d5_back = d5_back + e_back
d5_front = bit32.bor(d5_front + e_front + math.floor(d5_back / 2 ^ 32))
d5_back = bit32.bor(d5_back)
d5_front = bit32.bor(d5_front + e_front + math.floor(d5_back / 2 ^ 32), 0)
d5_back = bit32.bor(d5_back, 0)

d6_back = d6_back + f_back
d6_front = bit32.bor(d6_front + f_front + math.floor(d6_back / 2 ^ 32))
d6_back = bit32.bor(d6_back)
d6_front = bit32.bor(d6_front + f_front + math.floor(d6_back / 2 ^ 32), 0)
d6_back = bit32.bor(d6_back, 0)

d7_back = d7_back + g_back
d7_front = bit32.bor(d7_front + g_front + math.floor(d7_back / 2 ^ 32))
d7_back = bit32.bor(d7_back)
d7_front = bit32.bor(d7_front + g_front + math.floor(d7_back / 2 ^ 32), 0)
d7_back = bit32.bor(d7_back, 0)

d8_back = d8_back + h_back
d8_front = bit32.bor(d8_front + h_front + math.floor(d8_back / 2 ^ 32))
d8_back = bit32.bor(d8_back)
d8_front = bit32.bor(d8_front + h_front + math.floor(d8_back / 2 ^ 32), 0)
d8_back = bit32.bor(d8_back, 0)
end

digestFront[1], digestBack[1] = d1_front, d1_back
Expand Down
6 changes: 3 additions & 3 deletions modules/xxhash32/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ end
@param seed -- The seed to use for the hashing algorithm (defaults to `0`)
]=]
local function xxhash32(message: string, seed: number?): number
local rSeed = if seed == nil then 0 else bit32.bor(seed)
local rSeed = if seed == nil then 0 else bit32.bor(seed, 0)
local messageLen = #message

local wordC = 1
Expand Down Expand Up @@ -58,9 +58,9 @@ local function xxhash32(message: string, seed: number?): number
+ bit32.lrotate(accum3, 12)
+ bit32.lrotate(accum4, 18)
else
digest = bit32.bor(rSeed + PRIME_5)
digest = bit32.bor(rSeed + PRIME_5, 0)
end
digest = bit32.bor(digest + messageLen)
digest = bit32.bor(digest + messageLen, 0)

for _ = wordC, math.floor(messageLen / 4) do
local d, c, b, a = string.byte(message, i, i + 3)
Expand Down

0 comments on commit 4d9dbd1

Please sign in to comment.