Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jw3126 committed Jan 11, 2018
1 parent 8ea7b87 commit c310e5b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 64 deletions.
2 changes: 1 addition & 1 deletion LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MD5.jl package is licensed under the MIT "Expat" License:

> Copyright (c) 2018: Lyndon White.
> Copyright (c) 2018: Lyndon White and Jan Weidner.
> Copyright (c) 2014: Elliot Saba. (SHA.jl)
> Derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm, Copyright (C) 1991-2
>
Expand Down
73 changes: 10 additions & 63 deletions src/core.jl
Original file line number Diff line number Diff line change
@@ -1,65 +1,12 @@
# Nonlinear functions, in order to encourage inlining, these sadly are not an array of lambdas
f_round0(b,c,d) = SHA.Round0(b,c,d) #UInt32((b & c) | (~b & d))
f_round1(b,c,d) = UInt32((b & d) | (c & ~d))
f_round2(b,c,d) = SHA.Round1And3(b,c,d) # return UInt32(b ⊻ c ⊻ d) #xors
f_round3(b,c,d) = UInt32(c (b | ~d))

g_round0(i) = i
g_round1(i) = (5i+1) % 16
g_round2(i) = (3i + 5) % 16
g_round3(i) = 7i % 16


function conclude_round(a,b,c,d,f,g,pbuf,i)
@inbounds s = ss[i+1]
@inbounds k = kk[i+1]
@inbounds m = unsafe_load(pbuf, g+1)
f = f + a + k + m
a = d
d = c
c = b
b = b + lrot(s,f, 32)
a,b,c,d
end

transform!(ctx::MD5_CTX) = transform_unrolled!(ctx)

function transform_baseline!(context::MD5_CTX)
pbuf = buffer_pointer(context)
a,b,c,d = context.state

for i in 0:15
f = f_round0(b,c,d)
g = g_round0(i)
a,b,c,d = conclude_round(a, b, c, d, f, g, pbuf, i)
end
for i in 16:31
f = f_round1(b,c,d)
g = g_round1(i)
a,b,c,d = conclude_round(a, b, c, d, f, g, pbuf, i)
end
for i in 32:47
f = f_round2(b,c,d)
g = g_round2(i)
a,b,c,d = conclude_round(a, b, c, d, f, g, pbuf, i)
end
for i in 48:63
f = f_round3(b,c,d)
g = g_round3(i)
a,b,c,d = conclude_round(a, b, c, d, f, g, pbuf, i)
end
@inbounds context.state .+= [a,b,c,d]
end

@generated function transform_unrolled!(context::MD5_CTX)
@generated function transform!(context::MD5_CTX)
ret = quote
pbuf = buffer_pointer(context)
end
ex = quote
A = context.state[1]
B = context.state[2]
C = context.state[3]
D = context.state[4]
@inbounds A = context.state[1]
@inbounds B = context.state[2]
@inbounds C = context.state[3]
@inbounds D = context.state[4]
end
push!(ret.args, ex)
for i in 0:63
Expand Down Expand Up @@ -91,14 +38,14 @@ end
end

ex = quote
context.state[1] += A
context.state[2] += B
context.state[3] += C
context.state[4] += D
@inbounds context.state[1] += A
@inbounds context.state[2] += B
@inbounds context.state[3] += C
@inbounds context.state[4] += D
end
push!(ret.args, ex)
quote
@inbounds $ret
$ret
end
end

Expand Down

0 comments on commit c310e5b

Please sign in to comment.