From 243d191aafdec9e11edea857f93b8ca6c6c7d318 Mon Sep 17 00:00:00 2001 From: Mitya Selivanov Date: Sat, 17 Dec 2022 22:50:24 +0100 Subject: secure random --- source/test/unittests/CMakeLists.txt | 4 ++-- source/test/unittests/secure_random.test.c | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 source/test/unittests/secure_random.test.c (limited to 'source/test/unittests') diff --git a/source/test/unittests/CMakeLists.txt b/source/test/unittests/CMakeLists.txt index 261b69e..b2ef480 100644 --- a/source/test/unittests/CMakeLists.txt +++ b/source/test/unittests/CMakeLists.txt @@ -4,5 +4,5 @@ target_sources( async_function.test.c bigint.test.c mutex.test.c test_duration.test.c main.test.c string_ref.test.c atomic.test.c thread.test.c array_ref.test.c input_stream.test.c lower_bound.test.c - condition_variable.test.c mersenne_twister_64.test.c input_buffer.test.c - move_back.test.c dynamic_array.test.c file.test.c) + secure_random.test.c condition_variable.test.c mersenne_twister_64.test.c + input_buffer.test.c move_back.test.c dynamic_array.test.c file.test.c) diff --git a/source/test/unittests/secure_random.test.c b/source/test/unittests/secure_random.test.c new file mode 100644 index 0000000..ec0a7b2 --- /dev/null +++ b/source/test/unittests/secure_random.test.c @@ -0,0 +1,22 @@ +#include "../../kit/secure_random.h" +#include + +#define KIT_TEST_FILE secure_random +#include "../../kit_test/test.h" + +TEST("secure random") { + int v[20]; + memset(v, 0, sizeof v); + + secure_random(40, v); + secure_random(40, v + 10); + + int repeats = 0; + + for (int i = 1; i < sizeof v / sizeof *v; i++) + for (int j = 0; j < i; j++) + if (v[i] == v[j]) + repeats++; + + REQUIRE(repeats == 0); +} -- cgit v1.2.3