Skip to content

Commit 262c008

Browse files
committed
man: clarify the 'random number generator must be seeded' requirement
The manual pages require for some API functions that the 'random number generator must be seeded' before calling the function. Initially, this was meant literally, i.e. the OpenSSL CSPRNG had to be seeded manually before calling these functions. Since version 1.1.1, the CSPRNG is seeded automatically on first use, so it's not the responsibility of the programmer anymore. Still, he needs to be aware that the seeding might fail. Reviewed-by: Paul Dale <[email protected]> Reviewed-by: Tomas Mraz <[email protected]> (Merged from openssl#9257)
1 parent 0588be2 commit 262c008

13 files changed

+63
-29
lines changed

doc/man3/BN_generate_prime.pod

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ L<openssl_user_macros(7)>:
5151
=head1 DESCRIPTION
5252

5353
BN_generate_prime_ex() generates a pseudo-random prime number of
54-
at least bit length B<bits>.
54+
at least bit length B<bits>. The returned number is probably prime
55+
with a negligible error.
56+
5557
If B<ret> is not B<NULL>, it will be used to store the number.
5658

5759
If B<cb> is not B<NULL>, it is used as follows:
@@ -89,8 +91,9 @@ generator.
8991
If B<safe> is true, it will be a safe prime (i.e. a prime p so
9092
that (p-1)/2 is also prime).
9193

92-
The PRNG must be seeded prior to calling BN_generate_prime_ex().
93-
The prime number generation has a negligible error probability.
94+
The random generator must be seeded prior to calling BN_generate_prime_ex().
95+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
96+
external circumstances (see L<RAND(7)>), the operation will fail.
9497

9598
BN_is_prime_ex() and BN_is_prime_fasttest_ex() test if the number B<p> is
9699
prime. The following tests are performed until one of them shows that
@@ -193,7 +196,8 @@ Instead applications should create a BN_GENCB structure using BN_GENCB_new:
193196
=head1 SEE ALSO
194197

195198
L<DH_generate_parameters(3)>, L<DSA_generate_parameters(3)>,
196-
L<RSA_generate_key(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>
199+
L<RSA_generate_key(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>,
200+
L<RAND(7)>
197201

198202
=head1 HISTORY
199203

doc/man3/DES_random_key.pod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,11 @@ consists of 8 bytes with odd parity. The least significant bit in
104104
each byte is the parity bit. The key schedule is an expanded form of
105105
the key; it is used to speed the encryption process.
106106

107-
DES_random_key() generates a random key. The PRNG must be seeded
108-
prior to using this function (see L<RAND_bytes(3)>). If the PRNG
109-
could not generate a secure key, 0 is returned.
107+
DES_random_key() generates a random key. The random generator must be
108+
seeded when calling this function.
109+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
110+
external circumstances (see L<RAND(7)>), the operation will fail.
111+
If the function fails, 0 is returned.
110112

111113
Before a DES key can be used, it must be converted into the
112114
architecture dependent I<DES_key_schedule> via the

doc/man3/DSA_generate_key.pod

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ DSA_generate_key - generate DSA key pair
1515
DSA_generate_key() expects B<a> to contain DSA parameters. It generates
1616
a new key pair and stores it in B<a-E<gt>pub_key> and B<a-E<gt>priv_key>.
1717

18-
The PRNG must be seeded prior to calling DSA_generate_key().
18+
The random generator must be seeded prior to calling DSA_generate_key().
19+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
20+
external circumstances (see L<RAND(7)>), the operation will fail.
1921

2022
=head1 RETURN VALUES
2123

doc/man3/DSA_sign.pod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,10 @@ B<dsa> is the signer's public key.
3636

3737
The B<type> parameter is ignored.
3838

39-
The PRNG must be seeded before DSA_sign() (or DSA_sign_setup())
39+
The random generator must be seeded when DSA_sign() (or DSA_sign_setup())
4040
is called.
41+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
42+
external circumstances (see L<RAND(7)>), the operation will fail.
4143

4244
=head1 RETURN VALUES
4345

@@ -54,7 +56,8 @@ Standard, DSS), ANSI X9.30
5456
=head1 SEE ALSO
5557

5658
L<DSA_new(3)>, L<ERR_get_error(3)>, L<RAND_bytes(3)>,
57-
L<DSA_do_sign(3)>
59+
L<DSA_do_sign(3)>,
60+
L<RAND(7)>
5861

5962
=head1 COPYRIGHT
6063

doc/man3/EVP_DigestSignInit.pod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,9 @@ and public key algorithms. This meant that "clone" digests such as EVP_dss1()
125125
needed to be used to sign using SHA1 and DSA. This is no longer necessary and
126126
the use of clone digest is now discouraged.
127127

128-
For some key types and parameters the random number generator must be seeded
129-
or the operation will fail.
128+
For some key types and parameters the random number generator must be seeded.
129+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
130+
external circumstances (see L<RAND(7)>), the operation will fail.
130131

131132
The call to EVP_DigestSignFinal() internally finalizes a copy of the digest
132133
context. This means that calls to EVP_DigestSignUpdate() and
@@ -147,7 +148,8 @@ L<EVP_DigestVerifyInit(3)>,
147148
L<EVP_DigestInit(3)>,
148149
L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
149150
L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
150-
L<SHA1(3)>, L<dgst(1)>
151+
L<SHA1(3)>, L<dgst(1)>,
152+
L<RAND(7)>
151153

152154
=head1 HISTORY
153155

doc/man3/EVP_DigestVerifyInit.pod

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,9 @@ and public key algorithms. This meant that "clone" digests such as EVP_dss1()
7676
needed to be used to sign using SHA1 and DSA. This is no longer necessary and
7777
the use of clone digest is now discouraged.
7878

79-
For some key types and parameters the random number generator must be seeded
80-
or the operation will fail.
79+
For some key types and parameters the random number generator must be seeded.
80+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
81+
external circumstances (see L<RAND(7)>), the operation will fail.
8182

8283
The call to EVP_DigestVerifyFinal() internally finalizes a copy of the digest
8384
context. This means that EVP_VerifyUpdate() and EVP_VerifyFinal() can
@@ -93,7 +94,8 @@ L<EVP_DigestSignInit(3)>,
9394
L<EVP_DigestInit(3)>,
9495
L<evp(7)>, L<HMAC(3)>, L<MD2(3)>,
9596
L<MD5(3)>, L<MDC2(3)>, L<RIPEMD160(3)>,
96-
L<SHA1(3)>, L<dgst(1)>
97+
L<SHA1(3)>, L<dgst(1)>,
98+
L<RAND(7)>
9799

98100
=head1 HISTORY
99101

doc/man3/EVP_SealInit.pod

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,9 @@ failure.
5555
=head1 NOTES
5656

5757
Because a random secret key is generated the random number generator
58-
must be seeded before calling EVP_SealInit().
58+
must be seeded when EVP_SealInit() is called.
59+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
60+
external circumstances (see L<RAND(7)>), the operation will fail.
5961

6062
The public key must be RSA because it is the only OpenSSL public key
6163
algorithm that supports key transport.
@@ -75,7 +77,8 @@ with B<type> set to NULL.
7577

7678
L<evp(7)>, L<RAND_bytes(3)>,
7779
L<EVP_EncryptInit(3)>,
78-
L<EVP_OpenInit(3)>
80+
L<EVP_OpenInit(3)>,
81+
L<RAND(7)>
7982

8083
=head1 COPYRIGHT
8184

doc/man3/EVP_SignInit.pod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,10 @@ The B<EVP> interface to digital signatures should almost always be used in
6666
preference to the low level interfaces. This is because the code then becomes
6767
transparent to the algorithm used and much more flexible.
6868

69-
When signing with DSA private keys the random number generator must be seeded
70-
or the operation will fail. The random number generator does not need to be
71-
seeded for RSA signatures.
69+
When signing with DSA private keys the random number generator must be seeded.
70+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
71+
external circumstances (see L<RAND(7)>), the operation will fail.
72+
This requirement does not hold for RSA signatures.
7273

7374
The call to EVP_SignFinal() internally finalizes a copy of the digest context.
7475
This means that calls to EVP_SignUpdate() and EVP_SignFinal() can be called

doc/man3/RSA_blinding_on.pod

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ must be used to protect the RSA operation from that attack.
2020

2121
RSA_blinding_on() turns blinding on for key B<rsa> and generates a
2222
random blinding factor. B<ctx> is B<NULL> or a pre-allocated and
23-
initialized B<BN_CTX>. The random number generator must be seeded
24-
prior to calling RSA_blinding_on().
23+
initialized B<BN_CTX>.
2524

2625
RSA_blinding_off() turns blinding off and frees the memory used for
2726
the blinding factor.

doc/man3/RSA_generate_key.pod

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,10 @@ be seeded prior to calling RSA_generate_key_ex().
2727

2828
RSA_generate_multi_prime_key() generates a multi-prime RSA key pair and stores
2929
it in the B<RSA> structure provided in B<rsa>. The number of primes is given by
30-
the B<primes> parameter. The pseudo-random number generator must be seeded prior
31-
to calling RSA_generate_multi_prime_key().
30+
the B<primes> parameter. The random number generator must be seeded when
31+
calling RSA_generate_multi_prime_key().
32+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
33+
external circumstances (see L<RAND(7)>), the operation will fail.
3234

3335
The modulus size will be of length B<bits>, the number of primes to form the
3436
modulus will be B<primes>, and the public exponent will be B<e>. Key sizes
@@ -88,7 +90,8 @@ B<BN_GENCB_call(cb, 2, x)> is used with two different meanings.
8890

8991
=head1 SEE ALSO
9092

91-
L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<BN_generate_prime(3)>
93+
L<ERR_get_error(3)>, L<RAND_bytes(3)>, L<BN_generate_prime(3)>,
94+
L<RAND(7)>
9295

9396
=head1 HISTORY
9497

doc/man3/RSA_padding_add_PKCS1_type_1.pod

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ simply copy the data
100100

101101
The random number generator must be seeded prior to calling
102102
RSA_padding_add_xxx().
103+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
104+
external circumstances (see L<RAND(7)>), the operation will fail.
103105

104106
RSA_padding_check_xxx() verifies that the B<fl> bytes at B<f> contain
105107
a valid encoding for a B<rsa_len> byte RSA key in the respective
@@ -143,7 +145,8 @@ including PKCS1_OAEP.
143145

144146
L<RSA_public_encrypt(3)>,
145147
L<RSA_private_decrypt(3)>,
146-
L<RSA_sign(3)>, L<RSA_verify(3)>
148+
L<RSA_sign(3)>, L<RSA_verify(3)>,
149+
L<RAND(7)>
147150

148151
=head1 COPYRIGHT
149152

doc/man3/RSA_sign_ASN1_OCTET_STRING.pod

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@ memory.
2626

2727
B<dummy> is ignored.
2828

29-
The random number generator must be seeded prior to calling RSA_sign_ASN1_OCTET_STRING().
29+
The random number generator must be seeded when calling
30+
RSA_sign_ASN1_OCTET_STRING().
31+
If the automatic seeding or reseeding of the OpenSSL CSPRNG fails due to
32+
external circumstances (see L<RAND(7)>), the operation will fail.
3033

3134
RSA_verify_ASN1_OCTET_STRING() verifies that the signature B<sigbuf>
3235
of size B<siglen> is the DER representation of a given octet string
@@ -49,7 +52,8 @@ These functions serve no recognizable purpose.
4952

5053
L<ERR_get_error(3)>,
5154
L<RAND_bytes(3)>, L<RSA_sign(3)>,
52-
L<RSA_verify(3)>
55+
L<RSA_verify(3)>,
56+
L<RAND(7)>
5357

5458
=head1 COPYRIGHT
5559

doc/man7/RAND.pod

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ As a normal application developer, you do not have to worry about any details,
2828
just use L<RAND_bytes(3)> to obtain random data.
2929
Having said that, there is one important rule to obey: Always check the error
3030
return value of L<RAND_bytes(3)> and do not take randomness for granted.
31+
Although (re-)seeding is automatic, it can fail because no trusted random source
32+
is available or the trusted source(s) temporarily fail to provide sufficient
33+
random seed material.
34+
In this case the CSPRNG enters an error state and ceases to provide output,
35+
until it is able to recover from the error by reseeding itself.
36+
For more details on reseeding and error recovery, see L<RAND_DRBG(7)>.
3137

3238
For values that should remain secret, you can use L<RAND_priv_bytes(3)>
3339
instead.

0 commit comments

Comments
 (0)