constantine/tests/t_csprngs.nim
Mamy Ratsimbazafy ad04e6ea57
Expose OS-provided cryptographically secure RNG (#257)
* Expose OS-provided cryptographically secure RNG

* small fixes

* some more csprngs fixes
2023-08-27 20:50:09 +02:00

31 lines
962 B
Nim

# Constantine
# Copyright (c) 2018-2019 Status Research & Development GmbH
# Copyright (c) 2020-Present Mamy André-Ratsimbazafy
# Licensed and distributed under either of
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
# at your option. This file may not be copied, modified, or distributed except according to those terms.
import
std/unittest,
../constantine/csprngs/sysrand
suite "[CSPRNG] sysrand":
test "Non-nil initialization":
# Initializing to full 0 has a chance of 2^-256
proc checkNonNil() =
var buf: array[32, byte] # zero-init
doAssert sysrand(buf)
var nonNil = false
for b in buf:
nonNil = nonNil or (b != byte 0)
doAssert nonNil
checkNonNil()
# TODO:
# - Hamming weight average 50%
# - statistics/hypothesis tests