Skip to content

Commit

Permalink
bench: Comment out OpenSSL Keccak bench due to OpenSSL/LibreSSL versi…
Browse files Browse the repository at this point in the history
…oning issues
  • Loading branch information
mratsim committed Jan 16, 2025
1 parent 3e8cfa7 commit 429eb4c
Showing 1 changed file with 23 additions and 33 deletions.
56 changes: 23 additions & 33 deletions benchmarks/bench_h_keccak.nim
Original file line number Diff line number Diff line change
Expand Up @@ -9,39 +9,27 @@ proc separator*() = separator(69)

# Deal with platform mess
# --------------------------------------------------------------------
when defined(windows):
when sizeof(int) == 8:
const DLLSSLName* = "(libssl-1_1-x64|ssleay64|libssl64).dll"
else:
const DLLSSLName* = "(libssl-1_1|ssleay32|libssl32).dll"
else:
when defined(macosx) or defined(macos) or defined(ios):
const versions = "(.1.1|.38|.39|.41|.43|.44|.45|.46|.47|.48|.10|.1.0.2|.1.0.1|.1.0.0|.0.9.9|.0.9.8|)"
else:
const versions = "(.1.1|.1.0.2|.1.0.1|.1.0.0|.0.9.9|.0.9.8|.48|.47|.46|.45|.44|.43|.41|.39|.38|.10|)"

when defined(macosx) or defined(macos) or defined(ios):
const DLLSSLName* = "libssl" & versions & ".dylib"
elif defined(genode):
const DLLSSLName* = "libssl.lib.so"
else:
const DLLSSLName* = "libssl.so" & versions
when false:
include ./openssl_wrapper

# OpenSSL wrapper
# --------------------------------------------------------------------
# Only supported on OpenSSL 3.3, and even then it might have been removed in OpenSSL 3.4
# On MacOS the default libssl is actually LibreSSL which doesn't provide the new mandatory (for Keccak) EVP API

proc EVP_Q_digest[T: byte|char](
ossl_libctx: pointer,
algoName: cstring,
propq: cstring,
data: openArray[T],
digest: var array[32, byte],
size: ptr uint): int32 {.noconv, dynlib: DLLSSLName, importc.}
when false:
proc EVP_Q_digest[T: byte|char](
ossl_libctx: pointer,
algoName: cstring,
propq: cstring,
data: openArray[T],
digest: var array[32, byte],
size: ptr uint): int32 {.noconv, dynlib: DLLSSLName, importc.}

proc SHA3_256_OpenSSL[T: byte|char](
digest: var array[32, byte],
s: openArray[T]) =
discard EVP_Q_digest(nil, "SHA3-256", nil, s, digest, nil)
proc SHA3_256_OpenSSL[T: byte|char](
digest: var array[32, byte],
s: openArray[T]) =
discard EVP_Q_digest(nil, "SHA3-256", nil, s, digest, nil)

# --------------------------------------------------------------------

Expand All @@ -64,10 +52,11 @@ proc benchKeccak256_constantine[T](msg: openarray[T], msgComment: string, iters:
bench("Keccak256 - Constantine - " & msgComment, msg.len, iters):
keccak256.hash(digest, msg)

proc benchSHA3_256_openssl[T](msg: openarray[T], msgComment: string, iters: int) =
var digest: array[32, byte]
bench("SHA3-256 - OpenSSL - " & msgComment, msg.len, iters):
SHA3_256_OpenSSL(digest, msg)
when false:
proc benchSHA3_256_openssl[T](msg: openarray[T], msgComment: string, iters: int) =
var digest: array[32, byte]
bench("SHA3-256 - OpenSSL - " & msgComment, msg.len, iters):
SHA3_256_OpenSSL(digest, msg)

when isMainModule:
proc main() =
Expand All @@ -83,7 +72,8 @@ when isMainModule:
let msg = rng.random_byte_seq(s)
let iters = int(target_cycles div (s.int64 * worst_cycles_per_bytes))
benchKeccak256_constantine(msg, $s & "B", iters)
benchSHA3_256_openssl(msg, $s & "B", iters)
when false:
benchSHA3_256_openssl(msg, $s & "B", iters)
echo "----"

main()

0 comments on commit 429eb4c

Please sign in to comment.