From 2dac8b2a14c421ab9e56b7e77faf211dd801482e Mon Sep 17 00:00:00 2001 From: 4DBug Date: Sun, 1 Nov 2026 19:37:20 -0600 Subject: [PATCH] perf: MD5 runs its four rounds as four loops (no per-step round test) --- src/Rosetta/core/Md5.luau | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/Rosetta/core/Md5.luau b/src/Rosetta/core/Md5.luau index a6aa141..c1452eb 100644 --- a/src/Rosetta/core/Md5.luau +++ b/src/Rosetta/core/Md5.luau @@ -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