OpenSSL upstream: no more SHA256 public function :/, skip in Windows CI
This commit is contained in:
parent
7c7290115f
commit
fb594c5938
|
@ -29,15 +29,30 @@ else:
|
|||
# OpenSSL wrapper
|
||||
# --------------------------------------------------------------------
|
||||
|
||||
proc SHA256[T: byte|char](
|
||||
# OpenSSL removed direct use of their SHA256 function. https://github.com/openssl/openssl/commit/4d49b68504cc494e552bce8e0b82ec8b501d5abe
|
||||
# It isn't accessible anymore in Windows CI on Github Action.
|
||||
# But the new API isn't expose on Linux :/
|
||||
|
||||
# TODO: fix Windows
|
||||
when not defined(Windows):
|
||||
proc SHA256[T: byte|char](
|
||||
msg: openarray[T],
|
||||
digest: ptr array[32, byte] = nil
|
||||
): ptr array[32, byte] {.cdecl, dynlib: DLLSSLName, importc.}
|
||||
|
||||
proc SHA256_OpenSSL[T: byte|char](
|
||||
# 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 {.cdecl, dynlib: DLLSSLName, importc.}
|
||||
|
||||
proc SHA256_OpenSSL[T: byte|char](
|
||||
digest: var array[32, byte],
|
||||
s: openarray[T]) =
|
||||
discard SHA256(s, digest.addr)
|
||||
# discard EVP_Q_digest(nil, "SHA256", nil, s, digest, nil)
|
||||
|
||||
# Test
|
||||
# --------------------------------------------------------------------
|
||||
|
@ -70,7 +85,8 @@ proc sanityABC2 =
|
|||
|
||||
doAssert bufCt == hashed
|
||||
|
||||
proc innerTest(rng: var RngState, sizeRange: Slice[int]) =
|
||||
when not defined(windows):
|
||||
proc innerTest(rng: var RngState, sizeRange: Slice[int]) =
|
||||
let size = rng.random_unsafe(sizeRange)
|
||||
let msg = rng.random_byte_seq(size)
|
||||
|
||||
|
@ -78,7 +94,7 @@ proc innerTest(rng: var RngState, sizeRange: Slice[int]) =
|
|||
|
||||
sha256.hash(bufCt, msg)
|
||||
SHA256_OpenSSL(bufOssl, msg)
|
||||
doAssert bufCt == bufOssl
|
||||
doAssert bufCt == bufOssl, "Test failed with message of length " & $size
|
||||
|
||||
proc chunkTest(rng: var RngState, sizeRange: Slice[int]) =
|
||||
let size = rng.random_unsafe(sizeRange)
|
||||
|
@ -116,26 +132,33 @@ proc main() =
|
|||
var rng: RngState
|
||||
rng.seed(0xFACADE)
|
||||
|
||||
when not defined(windows):
|
||||
echo "SHA256 - 0 <= size < 64 - exhaustive"
|
||||
for i in 0 ..< 64:
|
||||
rng.innerTest(i .. i)
|
||||
else:
|
||||
echo "SHA256 - 0 <= size < 64 - exhaustive [SKIPPED]"
|
||||
|
||||
echo "SHA256 - 0 <= size < 64 - exhaustive chunked"
|
||||
for i in 0 ..< 64:
|
||||
rng.chunkTest(i .. i)
|
||||
|
||||
echo "SHA256 - 64 <= size < 1024B"
|
||||
for _ in 0 ..< SmallSizeIters:
|
||||
rng.innerTest(0 ..< 1024)
|
||||
|
||||
echo "SHA256 - 64 <= size < 1024B - chunked"
|
||||
for _ in 0 ..< SmallSizeIters:
|
||||
rng.chunkTest(0 ..< 1024)
|
||||
|
||||
when not defined(windows):
|
||||
echo "SHA256 - 64 <= size < 1024B"
|
||||
for _ in 0 ..< SmallSizeIters:
|
||||
rng.innerTest(0 ..< 1024)
|
||||
|
||||
echo "SHA256 - 1MB <= size < 50MB"
|
||||
for _ in 0 ..< LargeSizeIters:
|
||||
rng.innerTest(1_000_000 ..< 50_000_000)
|
||||
|
||||
echo "SHA256 - Differential testing vs OpenSSL - SUCCESS"
|
||||
|
||||
else:
|
||||
echo "SHA256 - Differential testing vs OpenSSL - [SKIPPED]"
|
||||
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue