1 /*
2  * SPDX-License-Identifier: ISC
3  *
4  * Copyright (c) 2018 Todd C. Miller <Todd.Miller@sudo.ws>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  *
18  * Sponsored in part by the Defense Advanced Research Projects
19  * Agency (DARPA) and Air Force Research Laboratory, Air Force
20  * Materiel Command, USAF, under agreement number F39502-99-1-0512.
21  */
22 
23 #ifndef SUDO_RAND_H
24 #define SUDO_RAND_H
25 
26 #include <stdlib.h>	/* For arc4random() on systems that have it */
27 
28 /*
29  * All libc replacements are prefixed with "sudo_" to avoid namespace issues.
30  */
31 
32 #ifndef HAVE_ARC4RANDOM
33 sudo_dso_public uint32_t sudo_arc4random(void);
34 # undef arc4random
35 # define arc4random() sudo_arc4random()
36 #endif /* ARC4RANDOM */
37 
38 #ifndef HAVE_ARC4RANDOM_BUF
39 sudo_dso_public void sudo_arc4random_buf(void *buf, size_t n);
40 # undef arc4random_buf
41 # define arc4random_buf(a, b) sudo_arc4random_buf((a), (b))
42 #endif /* ARC4RANDOM_BUF */
43 
44 #ifndef HAVE_ARC4RANDOM_UNIFORM
45 sudo_dso_public uint32_t sudo_arc4random_uniform(uint32_t upper_bound);
46 # undef arc4random_uniform
47 # define arc4random_uniform(_a) sudo_arc4random_uniform((_a))
48 #endif /* ARC4RANDOM_UNIFORM */
49 
50 #ifndef HAVE_GETENTROPY
51 /* Note: not exported by libutil. */
52 int sudo_getentropy(void *buf, size_t buflen);
53 # undef getentropy
54 # define getentropy(_a, _b) sudo_getentropy((_a), (_b))
55 #endif /* HAVE_GETENTROPY */
56 
57 #endif /* SUDO_RAND_H */
58