perf: MD5 runs its four rounds as four loops (no per-step round test)

This commit is contained in:
4DBug committed 2026-11-01 19:37:20 -06:00
1 parent ddc5dd101f
commit 2dac8b2a14
1 file changed
+15 -16
+15 -16
View File
@@ -51,22 +51,21 @@ local function compress(st: State, blk: buffer, o: number)
M[i + 1] = readu32(blk, o + i * 4)
end
local a, b, c, d = st.a, st.b, st.c, st.d
for i = 0, 63 do
local f
if i < 16 then
f = bor(band(b, c), band(bnot(b), d))
elseif i < 32 then
f = bor(band(d, b), band(bnot(d), c))
elseif i < 48 then
f = bxor(b, c, d)
else
f = bxor(c, bor(b, bnot(d)))
end
local tmp = d
d = c
c = b
b = (b + lrotate((a + f + K[i + 1] + M[G[i + 1] + 1]) % 4294967296, S[i + 1])) % 4294967296
a = tmp
for i = 1, 16 do
local f = bor(band(b, c), band(bnot(b), d))
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
end
for i = 17, 32 do
local f = bor(band(d, b), band(bnot(d), c))
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
end
for i = 33, 48 do
local f = bxor(b, c, d)
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
end
for i = 49, 64 do
local f = bxor(c, bor(b, bnot(d)))
a, b, c, d = d, (b + lrotate(a + f + K[i] + M[G[i] + 1], S[i])) % 4294967296, b, c
end
st.a = (st.a + a) % 4294967296
st.b = (st.b + b) % 4294967296