xref: /openssl/doc/man3/RAND_get0_primary.pod (revision 7ed6de99)
1=pod
2
3=head1 NAME
4
5RAND_get0_primary,
6RAND_get0_public,
7RAND_get0_private,
8RAND_set0_public,
9RAND_set0_private
10- get access to the global EVP_RAND_CTX instances
11
12=head1 SYNOPSIS
13
14 #include <openssl/rand.h>
15
16 EVP_RAND_CTX *RAND_get0_primary(OSSL_LIB_CTX *ctx);
17 EVP_RAND_CTX *RAND_get0_public(OSSL_LIB_CTX *ctx);
18 EVP_RAND_CTX *RAND_get0_private(OSSL_LIB_CTX *ctx);
19 int RAND_set0_public(OSSL_LIB_CTX *ctx, EVP_RAND_CTX *rand);
20 int RAND_set0_private(OSSL_LIB_CTX *ctx, EVP_RAND_CTX *rand);
21
22=head1 DESCRIPTION
23
24The default RAND API implementation (RAND_OpenSSL()) utilizes three
25shared DRBG instances which are accessed via the RAND API:
26
27The I<public> and I<private> DRBG are thread-local instances, which are used
28by RAND_bytes() and RAND_priv_bytes(), respectively.
29The I<primary> DRBG is a global instance, which is not intended to be used
30directly, but is used internally to reseed the other two instances.
31
32The three get functions provide access to the shared DRBG instances.
33
34The two set functions allow the public and private DRBG instances to be
35replaced by another random number generator.
36
37=head1 RETURN VALUES
38
39RAND_get0_primary() returns a pointer to the I<primary> DRBG instance
40for the given OSSL_LIB_CTX B<ctx>.
41
42RAND_get0_public() returns a pointer to the I<public> DRBG instance
43for the given OSSL_LIB_CTX B<ctx>.
44
45RAND_get0_private() returns a pointer to the I<private> DRBG instance
46for the given OSSL_LIB_CTX B<ctx>.
47
48RAND_set0_public() and RAND_set0_private() return 1 on success and 0
49on error.
50
51=head1 NOTES
52
53It is not thread-safe to access the I<primary> DRBG instance.
54The I<public> and I<private> DRBG instance can be accessed safely, because
55they are thread-local. Note however, that changes to these two instances
56apply only to the current thread.
57
58For that reason it is recommended not to change the settings of these
59three instances directly.
60Instead, an application should change the default settings for new DRBG instances
61at initialization time, before creating additional threads.
62
63During initialization, it is possible to change the reseed interval
64and reseed time interval.
65It is also possible to exchange the reseeding callbacks entirely.
66
67To set the type of DRBG that will be instantiated, use the
68L<RAND_set_DRBG_type(3)> call before accessing the random number generation
69infrastructure.
70
71The two set functions, operate on the current thread.  If you want to
72use the same random number generator across all threads, each thread
73must individually call the set functions.
74
75=head1 SEE ALSO
76
77L<EVP_RAND(3)>,
78L<RAND_set_DRBG_type(3)>
79
80=head1 HISTORY
81
82RAND_set0_public() and RAND_set0_private() were added in OpenSSL 3.1.
83
84The remaining functions were added in OpenSSL 3.0.
85
86=head1 COPYRIGHT
87
88Copyright 2020-2024 The OpenSSL Project Authors. All Rights Reserved.
89
90Licensed under the Apache License 2.0 (the "License").  You may not use
91this file except in compliance with the License.  You can obtain a copy
92in the file LICENSE in the source distribution or at
93L<https://www.openssl.org/source/license.html>.
94
95=cut
96