diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2022-12-17 22:50:24 +0100 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2022-12-17 22:50:24 +0100 |
commit | 243d191aafdec9e11edea857f93b8ca6c6c7d318 (patch) | |
tree | b3a88307c32b6f96618330e9497e84912f79c547 /source/test | |
parent | 3729638138e3154e6672ade78d177d0b098b8236 (diff) | |
download | kit-243d191aafdec9e11edea857f93b8ca6c6c7d318.zip |
secure random
Diffstat (limited to 'source/test')
-rw-r--r-- | source/test/unittests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | source/test/unittests/secure_random.test.c | 22 |
2 files changed, 24 insertions, 2 deletions
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 <string.h> + +#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); +} |