Skip to content

Commit d435a18

Browse files
authored
gh-94199: Remove ssl.RAND_pseudo_bytes() function (#94202)
Remove the ssl.RAND_pseudo_bytes() function, deprecated in Python 3.6: use os.urandom() or ssl.RAND_bytes() instead.
1 parent 6e33ba1 commit d435a18

File tree

7 files changed

+11
-81
lines changed

7 files changed

+11
-81
lines changed

Diff for: Doc/library/ssl.rst

+2-23
Original file line numberDiff line numberDiff line change
@@ -311,27 +311,6 @@ Random generation
311311

312312
.. versionadded:: 3.3
313313

314-
.. function:: RAND_pseudo_bytes(num)
315-
316-
Return (bytes, is_cryptographic): bytes are *num* pseudo-random bytes,
317-
is_cryptographic is ``True`` if the bytes generated are cryptographically
318-
strong. Raises an :class:`SSLError` if the operation is not supported by the
319-
current RAND method.
320-
321-
Generated pseudo-random byte sequences will be unique if they are of
322-
sufficient length, but are not necessarily unpredictable. They can be used
323-
for non-cryptographic purposes and for certain purposes in cryptographic
324-
protocols, but usually not for key generation etc.
325-
326-
For almost all applications :func:`os.urandom` is preferable.
327-
328-
.. versionadded:: 3.3
329-
330-
.. deprecated:: 3.6
331-
332-
OpenSSL has deprecated :func:`ssl.RAND_pseudo_bytes`, use
333-
:func:`ssl.RAND_bytes` instead.
334-
335314
.. function:: RAND_status()
336315

337316
Return ``True`` if the SSL pseudo-random number generator has been seeded
@@ -2717,8 +2696,8 @@ for example the :mod:`multiprocessing` or :mod:`concurrent.futures` modules),
27172696
be aware that OpenSSL's internal random number generator does not properly
27182697
handle forked processes. Applications must change the PRNG state of the
27192698
parent process if they use any SSL feature with :func:`os.fork`. Any
2720-
successful call of :func:`~ssl.RAND_add`, :func:`~ssl.RAND_bytes` or
2721-
:func:`~ssl.RAND_pseudo_bytes` is sufficient.
2699+
successful call of :func:`~ssl.RAND_add` or :func:`~ssl.RAND_bytes` is
2700+
sufficient.
27222701

27232702

27242703
.. _ssl-tlsv1_3:

Diff for: Doc/whatsnew/3.12.rst

+4
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ Removed
214214
also a static method.
215215
(Contributed by Victor Stinner in :gh:`94169`.)
216216

217+
* Remove the :func:`ssl.RAND_pseudo_bytes` function, deprecated in Python 3.6:
218+
use :func:`os.urandom` or :func:`ssl.RAND_bytes` instead.
219+
(Contributed by Victor Stinner in :gh:`94199`.)
220+
217221

218222
Porting to Python 3.12
219223
======================

Diff for: Lib/ssl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
SSLSyscallError, SSLEOFError, SSLCertVerificationError
107107
)
108108
from _ssl import txt2obj as _txt2obj, nid2obj as _nid2obj
109-
from _ssl import RAND_status, RAND_add, RAND_bytes, RAND_pseudo_bytes
109+
from _ssl import RAND_status, RAND_add, RAND_bytes
110110
try:
111111
from _ssl import RAND_egd
112112
except ImportError:

Diff for: Lib/test/test_ssl.py

-6
Original file line numberDiff line numberDiff line change
@@ -382,10 +382,6 @@ def test_random(self):
382382
% (v, (v and "sufficient randomness") or
383383
"insufficient randomness"))
384384

385-
with warnings_helper.check_warnings():
386-
data, is_cryptographic = ssl.RAND_pseudo_bytes(16)
387-
self.assertEqual(len(data), 16)
388-
self.assertEqual(is_cryptographic, v == 1)
389385
if v:
390386
data = ssl.RAND_bytes(16)
391387
self.assertEqual(len(data), 16)
@@ -394,8 +390,6 @@ def test_random(self):
394390

395391
# negative num is invalid
396392
self.assertRaises(ValueError, ssl.RAND_bytes, -5)
397-
with warnings_helper.check_warnings():
398-
self.assertRaises(ValueError, ssl.RAND_pseudo_bytes, -5)
399393

400394
ssl.RAND_add("this is a random string", 75.0)
401395
ssl.RAND_add(b"this is a random bytes object", 75.0)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Remove the :func:`ssl.RAND_pseudo_bytes` function, deprecated in Python 3.6:
2+
use :func:`os.urandom` or :func:`ssl.RAND_bytes` instead. Patch by Victor
3+
Stinner.

Diff for: Modules/_ssl.c

-19
Original file line numberDiff line numberDiff line change
@@ -5158,24 +5158,6 @@ _ssl_RAND_bytes_impl(PyObject *module, int n)
51585158
return PySSL_RAND(module, n, 0);
51595159
}
51605160

5161-
/*[clinic input]
5162-
_ssl.RAND_pseudo_bytes
5163-
n: int
5164-
/
5165-
5166-
Generate n pseudo-random bytes.
5167-
5168-
Return a pair (bytes, is_cryptographic). is_cryptographic is True
5169-
if the bytes generated are cryptographically strong.
5170-
[clinic start generated code]*/
5171-
5172-
static PyObject *
5173-
_ssl_RAND_pseudo_bytes_impl(PyObject *module, int n)
5174-
/*[clinic end generated code: output=b1509e937000e52d input=58312bd53f9bbdd0]*/
5175-
{
5176-
PY_SSL_DEPRECATED("ssl.RAND_pseudo_bytes() is deprecated", 1, NULL);
5177-
return PySSL_RAND(module, n, 1);
5178-
}
51795161

51805162
/*[clinic input]
51815163
_ssl.RAND_status
@@ -5634,7 +5616,6 @@ static PyMethodDef PySSL_methods[] = {
56345616
_SSL__TEST_DECODE_CERT_METHODDEF
56355617
_SSL_RAND_ADD_METHODDEF
56365618
_SSL_RAND_BYTES_METHODDEF
5637-
_SSL_RAND_PSEUDO_BYTES_METHODDEF
56385619
_SSL_RAND_STATUS_METHODDEF
56395620
_SSL_GET_DEFAULT_VERIFY_PATHS_METHODDEF
56405621
_SSL_ENUM_CERTIFICATES_METHODDEF

Diff for: Modules/clinic/_ssl.c.h

+1-32
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)