Skip to content

Commit

Permalink
Merge pull request JuliaCrypto#9 from oxinabox/nogen
Browse files Browse the repository at this point in the history
use @eval instead of @generated
  • Loading branch information
oxinabox authored Dec 28, 2019
2 parents 5abd681 + d647d77 commit 9674e17
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
3 changes: 2 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
julia = "1"

[extras]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Nettle = "49dea1ee-f6fa-5aa6-9a11-8816cee7d4b9"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "Random", "Nettle"]
test = ["Test", "Random", "Nettle", "BenchmarkTools"]
19 changes: 9 additions & 10 deletions src/core.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
@generated function transform!(context::MD5_CTX)
ret = quote
pbuf = buffer_pointer(context)
end
let body = quote end
ex = quote
pbuf = buffer_pointer(context)
@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)
push!(body.args, ex)
for i in 0:63
if 0 i 15
ex = :(F = (B & C) | ((~B) & D))
Expand All @@ -23,7 +21,7 @@
ex = :(F = C (B | (~D)))
g = 7i
end
push!(ret.args, ex)
push!(body.args, ex)
g = (g % 16) + 1
ex = quote
temp = D
Expand All @@ -34,7 +32,7 @@
B = B + rot_inner
A = temp
end
push!(ret.args, ex)
push!(body.args, ex)
end

ex = quote
Expand All @@ -43,9 +41,10 @@
@inbounds context.state[3] += C
@inbounds context.state[4] += D
end
push!(ret.args, ex)
quote
$ret
push!(body.args, ex)

@eval function transform!(context::MD5_CTX)
$body
end
end

Expand Down
12 changes: 5 additions & 7 deletions test/perf.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
import MD5
using MD5: MD5
using Nettle: Nettle
using BenchmarkTools

data = randstring(10^4)

if Pkg.installed("Nettle") != nothing
import Nettle
@show Nettle.hexdigest("md5", data)
display(@benchmark Nettle.hexdigest("md5", data))
println()
end
display(@btime Nettle.hexdigest("md5", data))
println()

@show bytes2hex(MD5.md5(data))
display(@benchmark MD5.md5(data))
display(@btime MD5.md5(data))
println()

1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ end
end

include("nettle.jl")
include("perf.jl")

0 comments on commit 9674e17

Please sign in to comment.