Skip to content

Commit

Permalink
deal with DLL mess for OpenSSL test
Browse files Browse the repository at this point in the history
  • Loading branch information
mratsim committed Jan 3, 2021
1 parent e89429e commit a5c1d07
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion tests/t_hash_sha256_vs_openssl.nim
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,42 @@ import
# Third-party
stew/byteutils

# 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):
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):
const DLLSSLName* = "libssl" & versions & ".dylib"
elif defined(genode):
const DLLSSLName* = "libssl.lib.so"
else:
const DLLSSLName* = "libssl.so" & versions

# OpenSSL wrapper
# --------------------------------------------------------------------

proc SHA256[T: byte|char](
msg: openarray[T],
digest: ptr array[32, byte] = nil
): ptr array[32, byte] {.cdecl, dynlib: "libssl.so", importc.}
): ptr array[32, byte] {.cdecl, dynlib: DLLSSLName, importc.}

proc SHA256_OpenSSL[T: byte|char](
digest: var array[32, byte],
s: openarray[T]) =
discard SHA256(s, digest.addr)

# Test
# --------------------------------------------------------------------

echo "\n------------------------------------------------------\n"
const SmallSizeIters = 128
const LargeSizeIters = 10
Expand Down

0 comments on commit a5c1d07

Please sign in to comment.