]> granicus.if.org Git - python/commitdiff
Issue #12049: improve RAND_bytes() and RAND_pseudo_bytes() documentation
authorVictor Stinner <victor.stinner@haypocalc.com>
Tue, 24 May 2011 19:32:40 +0000 (21:32 +0200)
committerVictor Stinner <victor.stinner@haypocalc.com>
Tue, 24 May 2011 19:32:40 +0000 (21:32 +0200)
Add also a security warning in the module random pointing to ssl.RAND_bytes().

Doc/library/random.rst
Doc/library/ssl.rst

index f0c4add61a19c0f2868565207c5740375fb9d286..52419a1f2553885080004a6269fdbdedf84a6a61 100644 (file)
@@ -43,6 +43,12 @@ The :mod:`random` module also provides the :class:`SystemRandom` class which
 uses the system function :func:`os.urandom` to generate random numbers
 from sources provided by the operating system.
 
+.. warning::
+
+   The generators of the :mod:`random` module should not be used for security
+   purposes, they are not cryptographic. Use :func:`ssl.RAND_bytes` if you
+   require a cryptographically secure pseudorandom number generator.
+
 
 Bookkeeping functions:
 
index a528a03f985f9927ff9724cb393e10647c3ac941..295d007f067be6f1a7e36195a647b3fedb6edddb 100644 (file)
@@ -166,6 +166,11 @@ Random generation
 
    Returns *num* cryptographically strong pseudo-random bytes.
 
+   Read the Wikipedia article, `Cryptographically secure pseudorandom number
+   generator
+   <http://en.wikipedia.org/wiki/Cryptographically_secure_pseudorandom_number_generator>`_,
+   to get the requirements of a cryptographically generator.
+
    .. versionadded:: 3.3
 
 .. function:: RAND_pseudo_bytes(num)
@@ -174,6 +179,11 @@ Random generation
    is_cryptographic is True if the bytes generated are cryptographically
    strong.
 
+   Generated pseudo-random byte sequences will be unique if they are of
+   sufficient length, but are not necessarily unpredictable. They can be used
+   for non-cryptographic purposes and for certain purposes in cryptographic
+   protocols, but usually not for key generation etc.
+
    .. versionadded:: 3.3
 
 .. function:: RAND_status()