Coverage Report

Created: 2024-08-17 11:05

/src/systemd/src/basic/random-util.h
Line
Count
Source (jump to first uncovered line)
1
/* SPDX-License-Identifier: LGPL-2.1-or-later */
2
#pragma once
3
4
#include <stdbool.h>
5
#include <stddef.h>
6
#include <stdint.h>
7
8
void random_bytes(void *p, size_t n); /* Returns random bytes suitable for most uses, but may be insecure sometimes. */
9
int crypto_random_bytes(void *p, size_t n); /* Returns secure random bytes after waiting for the RNG to initialize. */
10
11
0
static inline uint64_t random_u64(void) {
12
0
        uint64_t u;
13
0
        random_bytes(&u, sizeof(u));
14
0
        return u;
15
0
}
16
17
0
static inline uint32_t random_u32(void) {
18
0
        uint32_t u;
19
0
        random_bytes(&u, sizeof(u));
20
0
        return u;
21
0
}
22
23
/* Some limits on the pool sizes when we deal with the kernel random pool */
24
#define RANDOM_POOL_SIZE_MIN 32U
25
#define RANDOM_POOL_SIZE_MAX (10U*1024U*1024U)
26
27
size_t random_pool_size(void);
28
29
int random_write_entropy(int fd, const void *seed, size_t size, bool credit);
30
31
uint64_t random_u64_range(uint64_t max);