# 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