Debian Codegraph @

debian/rust-vendor/aws-lc-sys/aws-lc/include/openssl/rand.h

raw
1 // Copyright (c) 2014, Google Inc.
2 // SPDX-License-Identifier: ISC
3
4 #ifndef OPENSSL_HEADER_RAND_H
5 #define OPENSSL_HEADER_RAND_H
6
7 #include <openssl/base.h>
8
9 #if defined(__cplusplus)
10 extern "C" {
11 #endif
12
13
14 // Random number generation.
15
16
17 #define RAND_PRED_RESISTANCE_LEN (32)
18
19 // RAND_bytes writes |len| bytes of random data to |buf| and returns one. In the
20 // event that sufficient random data can not be obtained, |abort| is called.
21 OPENSSL_EXPORT int RAND_bytes(uint8_t *buf, size_t len);
22
23 // RAND_priv_bytes is a wrapper around |RAND_bytes| provided for compatibility.
24 // Consumers should call |RAND_bytes| directly.
25 OPENSSL_EXPORT int RAND_priv_bytes(uint8_t *buf, size_t len);
26
27 // RAND_public_bytes writes |len| bytes of random data to |buf| and returns one.
28 // In the event that sufficient random data can not be obtained, |abort| is
29 // called. |RAND_public_bytes| and |RAND_bytes| do not use the same state to
30 // generate output.
31 OPENSSL_EXPORT int RAND_public_bytes(uint8_t *out, size_t out_len);
32
33 // RAND_bytes_with_user_prediction_resistance is functionally equivalent to
34 // |RAND_bytes| but also provides a way for the caller to inject prediction
35 // resistance material using the argument |user_pred_resistance|.
36 // |user_pred_resistance| must not be NULL and |user_pred_resistance| must be
37 // filled with |RAND_PRED_RESISTANCE_LEN| bytes.
38 OPENSSL_EXPORT int RAND_bytes_with_user_prediction_resistance(uint8_t *out,
39 size_t out_len, const uint8_t user_pred_resistance[RAND_PRED_RESISTANCE_LEN]);
40
41 // Obscure functions.
42
43 #if defined(BORINGSSL_UNSAFE_DETERMINISTIC_MODE)
44 // RAND_reset_for_fuzzing resets the fuzzer-only deterministic RNG. This
45 // function is only defined in the fuzzer-only build configuration.
46 OPENSSL_EXPORT void RAND_reset_for_fuzzing(void);
47 #endif
48
49
50 // Deprecated functions
51
52 // RAND_pseudo_bytes is a wrapper around |RAND_bytes|.
53 OPENSSL_EXPORT int RAND_pseudo_bytes(uint8_t *buf, size_t len);
54
55 // RAND_seed reads a single byte of random data to ensure that any file
56 // descriptors etc are opened.
57 OPENSSL_EXPORT void RAND_seed(const void *buf, int num);
58
59
60 // General No-op Functions [Deprecated].
61 //
62 // OpenSSL historically allowed applications to do various operations to gather
63 // entropy and mix them into the entropy pool. AWS-LC sources entropy for the
64 // consuming application and the following functions have been deprecated as
65 // no-ops. Consumers should call |RAND_bytes| directly.
66 //
67 // TODO (CryptoAlg-2398): Add |OPENSSL_DEPRECATED| to the ones that are missing.
68 // curl and tpm2-tss defines -Wnerror and depend on them.
69
70 // RAND_load_file returns a nonnegative number.
71 OPENSSL_EXPORT OPENSSL_DEPRECATED int RAND_load_file(const char *path,
72 long num);
73
74 // RAND_write_file does nothing and returns negative 1.
75 OPENSSL_EXPORT OPENSSL_DEPRECATED int RAND_write_file(const char *file);
76
77 // RAND_file_name returns NULL.
78 OPENSSL_EXPORT OPENSSL_DEPRECATED const char *RAND_file_name(char *buf,
79 size_t num);
80
81 // RAND_add does nothing.
82 OPENSSL_EXPORT OPENSSL_DEPRECATED void RAND_add(const void *buf, int num,
83 double entropy);
84
85 // RAND_egd returns 255.
86 OPENSSL_EXPORT OPENSSL_DEPRECATED int RAND_egd(const char *);
87
88 // RAND_egd_bytes returns |bytes|.
89 OPENSSL_EXPORT OPENSSL_DEPRECATED int RAND_egd_bytes(const char *, int bytes);
90
91 // RAND_poll returns one.
92 OPENSSL_EXPORT OPENSSL_DEPRECATED int RAND_poll(void);
93
94 // RAND_status returns one.
95 OPENSSL_EXPORT int RAND_status(void);
96
97 // RAND_cleanup does nothing.
98 OPENSSL_EXPORT OPENSSL_DEPRECATED void RAND_cleanup(void);
99
100 // rand_meth_st is typedefed to |RAND_METHOD| in base.h. It isn't used; it
101 // exists only to be the return type of |RAND_SSLeay|. It's
102 // external so that variables of this type can be initialized.
103 struct rand_meth_st {
104 void (*seed)(const void *buf, int num);
105 int (*bytes)(uint8_t *buf, size_t num);
106 void (*cleanup)(void);
107 void (*add)(const void *buf, int num, double entropy);
108 int (*pseudorand)(uint8_t *buf, size_t num);
109 int (*status)(void);
110 };
111
112 // RAND_SSLeay returns a pointer to a dummy |RAND_METHOD|.
113 OPENSSL_EXPORT OPENSSL_DEPRECATED RAND_METHOD *RAND_SSLeay(void);
114
115 // RAND_OpenSSL returns a pointer to a dummy |RAND_METHOD|.
116 OPENSSL_EXPORT RAND_METHOD *RAND_OpenSSL(void);
117
118 // RAND_get_rand_method returns |RAND_SSLeay()|.
119 OPENSSL_EXPORT const RAND_METHOD *RAND_get_rand_method(void);
120
121 // RAND_set_rand_method returns one.
122 OPENSSL_EXPORT int RAND_set_rand_method(const RAND_METHOD *);
123
124 // RAND_keep_random_devices_open does nothing.
125 OPENSSL_EXPORT OPENSSL_DEPRECATED void RAND_keep_random_devices_open(int a);
126
127
128 #if defined(__cplusplus)
129 } // extern C
130 #endif
131
132 #endif // OPENSSL_HEADER_RAND_H