rand.h
Go to the documentation of this file.
1 /* Copyright (c) 2014, Google Inc.
2  *
3  * Permission to use, copy, modify, and/or distribute this software for any
4  * purpose with or without fee is hereby granted, provided that the above
5  * copyright notice and this permission notice appear in all copies.
6  *
7  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
8  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
9  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
10  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
11  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
12  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
13  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */
14 
15 #ifndef OPENSSL_HEADER_RAND_H
16 #define OPENSSL_HEADER_RAND_H
17 
18 #include <openssl/base.h>
19 
20 #if defined(__cplusplus)
21 extern "C" {
22 #endif
23 
24 
25 // Random number generation.
26 
27 
28 // RAND_bytes writes |len| bytes of random data to |buf| and returns one.
30 
31 // RAND_cleanup frees any resources used by the RNG. This is not safe if other
32 // threads might still be calling |RAND_bytes|.
33 OPENSSL_EXPORT void RAND_cleanup(void);
34 
35 
36 // Obscure functions.
37 
38 #if !defined(OPENSSL_WINDOWS)
39 // RAND_enable_fork_unsafe_buffering enables efficient buffered reading of
40 // /dev/urandom. It adds an overhead of a few KB of memory per thread. It must
41 // be called before the first call to |RAND_bytes|.
42 //
43 // |fd| must be -1. We no longer support setting the file descriptor with this
44 // function.
45 //
46 // It has an unusual name because the buffer is unsafe across calls to |fork|.
47 // Hence, this function should never be called by libraries.
49 #endif
50 
51 #if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
52 // RAND_reset_for_fuzzing resets the fuzzer-only deterministic RNG. This
53 // function is only defined in the fuzzer-only build configuration.
54 OPENSSL_EXPORT void RAND_reset_for_fuzzing(void);
55 #endif
56 
57 
58 // Deprecated functions
59 
60 // RAND_pseudo_bytes is a wrapper around |RAND_bytes|.
62 
63 // RAND_seed reads a single byte of random data to ensure that any file
64 // descriptors etc are opened.
65 OPENSSL_EXPORT void RAND_seed(const void *buf, int num);
66 
67 // RAND_load_file returns a nonnegative number.
68 OPENSSL_EXPORT int RAND_load_file(const char *path, long num);
69 
70 // RAND_file_name returns NULL.
71 OPENSSL_EXPORT const char *RAND_file_name(char *buf, size_t num);
72 
73 // RAND_add does nothing.
74 OPENSSL_EXPORT void RAND_add(const void *buf, int num, double entropy);
75 
76 // RAND_egd returns 255.
77 OPENSSL_EXPORT int RAND_egd(const char *);
78 
79 // RAND_poll returns one.
80 OPENSSL_EXPORT int RAND_poll(void);
81 
82 // RAND_status returns one.
83 OPENSSL_EXPORT int RAND_status(void);
84 
85 // rand_meth_st is typedefed to |RAND_METHOD| in base.h. It isn't used; it
86 // exists only to be the return type of |RAND_SSLeay|. It's
87 // external so that variables of this type can be initialized.
88 struct rand_meth_st {
89  void (*seed) (const void *buf, int num);
90  int (*bytes) (uint8_t *buf, size_t num);
91  void (*cleanup) (void);
92  void (*add) (const void *buf, int num, double entropy);
93  int (*pseudorand) (uint8_t *buf, size_t num);
94  int (*status) (void);
95 };
96 
97 // RAND_SSLeay returns a pointer to a dummy |RAND_METHOD|.
99 
100 // RAND_OpenSSL returns a pointer to a dummy |RAND_METHOD|.
102 
103 // RAND_get_rand_method returns |RAND_SSLeay()|.
105 
106 // RAND_set_rand_method returns one.
108 
109 
110 #if defined(__cplusplus)
111 } // extern C
112 #endif
113 
114 #endif // OPENSSL_HEADER_RAND_H
RAND_get_rand_method
const OPENSSL_EXPORT RAND_METHOD * RAND_get_rand_method(void)
Definition: rand_extra.c:70
RAND_cleanup
OPENSSL_EXPORT void RAND_cleanup(void)
Definition: rand_extra.c:74
RAND_enable_fork_unsafe_buffering
OPENSSL_EXPORT void RAND_enable_fork_unsafe_buffering(int fd)
Definition: forkunsafe.c:29
buf
voidpf void * buf
Definition: bloaty/third_party/zlib/contrib/minizip/ioapi.h:136
rand_meth_st::seed
void(* seed)(const void *buf, int num)
Definition: rand.h:89
check_documentation.path
path
Definition: check_documentation.py:57
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
RAND_file_name
const OPENSSL_EXPORT char * RAND_file_name(char *buf, size_t num)
Definition: rand_extra.c:37
RAND_egd
OPENSSL_EXPORT int RAND_egd(const char *)
Definition: rand_extra.c:41
base.h
rand_meth_st::pseudorand
int(* pseudorand)(uint8_t *buf, size_t num)
Definition: rand.h:93
rand_meth_st
Definition: rand.h:88
RAND_add
OPENSSL_EXPORT void RAND_add(const void *buf, int num, double entropy)
Definition: rand_extra.c:39
xds_interop_client.int
int
Definition: xds_interop_client.py:113
RAND_load_file
OPENSSL_EXPORT int RAND_load_file(const char *path, long num)
Definition: rand_extra.c:27
rand_meth_st::add
void(* add)(const void *buf, int num, double entropy)
Definition: rand.h:92
RAND_set_rand_method
OPENSSL_EXPORT int RAND_set_rand_method(const RAND_METHOD *)
Definition: rand_extra.c:72
RAND_pseudo_bytes
OPENSSL_EXPORT int RAND_pseudo_bytes(uint8_t *buf, size_t len)
Definition: rand.c:455
RAND_poll
OPENSSL_EXPORT int RAND_poll(void)
Definition: rand_extra.c:45
RAND_OpenSSL
OPENSSL_EXPORT RAND_METHOD * RAND_OpenSSL(void)
Definition: rand_extra.c:66
RAND_SSLeay
OPENSSL_EXPORT RAND_METHOD * RAND_SSLeay(void)
Definition: rand_extra.c:62
xds_manager.num
num
Definition: xds_manager.py:56
OPENSSL_EXPORT
#define OPENSSL_EXPORT
Definition: base.h:222
RAND_bytes
OPENSSL_EXPORT int RAND_bytes(uint8_t *buf, size_t len)
Definition: rand.c:449
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
cleanup
Definition: cleanup.py:1
rand_meth_st::bytes
int(* bytes)(uint8_t *buf, size_t num)
Definition: rand.h:90
RAND_status
OPENSSL_EXPORT int RAND_status(void)
Definition: rand_extra.c:49
RAND_seed
OPENSSL_EXPORT void RAND_seed(const void *buf, int num)
Definition: rand_extra.c:20
rand_meth_st::status
int(* status)(void)
Definition: rand.h:94


grpc
Author(s):
autogenerated on Thu Mar 13 2025 03:00:59