1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2017 Zbigniew Jędrzejewski-Szmek
9 #include "random-util.h"
12 static void test_acquire_random_bytes(bool high_quality_required) {
16 log_info("/* %s */", __func__);
18 for (i = 1; i < sizeof buf; i++) {
19 assert_se(acquire_random_bytes(buf, i, high_quality_required) == 0);
20 if (i + 1 < sizeof buf)
21 assert_se(buf[i] == 0);
23 hexdump(stdout, buf, i);
27 static void test_pseudorandom_bytes(void) {
31 log_info("/* %s */", __func__);
33 for (i = 1; i < sizeof buf; i++) {
34 pseudorandom_bytes(buf, i);
35 if (i + 1 < sizeof buf)
36 assert_se(buf[i] == 0);
38 hexdump(stdout, buf, i);
42 int main(int argc, char **argv) {
43 log_set_max_level(LOG_DEBUG);
44 log_parse_environment();
47 test_acquire_random_bytes(false);
48 test_acquire_random_bytes(true);
50 test_pseudorandom_bytes();