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