2 * Copyright the NTPsec project contributors
3 * SPDX-License-Identifier: BSD-2-Clause
8 #include <openssl/opensslv.h>
9 #include <openssl/rand.h>
14 /* NB: RAND_bytes comes from OpenSSL
15 * Starting in version 1.1.1, it reseeds itself occasionally.
16 * That may need access to /dev/urandom which may be blocked by chroot jails.
17 * getrandom(2) is used when available. It was added to Linux kernel 3.17
18 * so this won't be a problem on newer Linux systems.
21 void ntp_RAND_bytes(unsigned char *buf
, int num
) {
23 err
= RAND_bytes(buf
, num
);
25 msyslog(LOG_ERR
, "ERR: RAND_bytes failed");
30 void ntp_RAND_priv_bytes(unsigned char *buf
, int num
) {
32 #if (OPENSSL_VERSION_NUMBER > 0x1010100fL) && !defined(LIBRESSL_VERSION_NUMBER)
33 err
= RAND_priv_bytes(buf
, num
);
35 err
= RAND_bytes(buf
, num
);
38 msyslog(LOG_ERR
, "ERR: RAND_priv_bytes failed");