]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/test/test-random-util.c
2 This file is part of systemd.
4 Copyright 2017 Zbigniew Jędrzejewski-Szmek
6 systemd is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 systemd is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License
17 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20 #include "hexdecoct.h"
21 #include "random-util.h"
24 static void test_acquire_random_bytes(bool high_quality_required
) {
28 log_info("/* %s */", __func__
);
30 for (i
= 1; i
< sizeof buf
; i
++) {
31 assert_se(acquire_random_bytes(buf
, i
, high_quality_required
) == 0);
32 if (i
+ 1 < sizeof buf
)
33 assert_se(buf
[i
] == 0);
35 hexdump(stdout
, buf
, i
);
39 static void test_pseudorandom_bytes(void) {
43 log_info("/* %s */", __func__
);
45 for (i
= 1; i
< sizeof buf
; i
++) {
46 pseudorandom_bytes(buf
, i
);
47 if (i
+ 1 < sizeof buf
)
48 assert_se(buf
[i
] == 0);
50 hexdump(stdout
, buf
, i
);
54 int main(int argc
, char **argv
) {
55 log_set_max_level(LOG_DEBUG
);
56 log_parse_environment();
59 test_acquire_random_bytes(false);
60 test_acquire_random_bytes(true);
62 test_pseudorandom_bytes();