1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2017 Red Hat, Inc.
*/
#ifndef __NM_RANDOM_UTILS_H__
#define __NM_RANDOM_UTILS_H__
void nm_random_get_bytes_full(void *p, size_t n, gboolean *out_high_quality);
static inline void
nm_random_get_bytes(void *p, size_t n)
{
nm_random_get_bytes_full(p, n, NULL);
}
int nm_random_get_crypto_bytes(void *p, size_t n);
static inline guint32
nm_random_u32(void)
{
guint32 v;
nm_random_get_bytes(&v, sizeof(v));
return v;
}
static inline guint64
nm_random_u64(void)
{
guint64 v;
nm_random_get_bytes(&v, sizeof(v));
return v;
}
static inline bool
nm_random_bool(void)
{
guint8 ch;
nm_random_get_bytes(&ch, sizeof(ch));
return ch % 2u;
}
guint64 nm_random_u64_range_full(guint64 begin, guint64 end, gboolean crypto_bytes);
static inline guint64
nm_random_u64_range(guint64 end)
{
return nm_random_u64_range_full(0, end, FALSE);
}
#endif /* __NM_RANDOM_UTILS_H__ */
|