Skip to content

Commit ace0aa2

Browse files
authored
bpo-42982: update pbkdf2 example & add another link (GH-30966)
Automerge-Triggered-By: GH:gpshead
1 parent 26b0482 commit ace0aa2

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Doc/library/hashlib.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -251,15 +251,17 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
251251
The number of *iterations* should be chosen based on the hash algorithm and
252252
computing power. As of 2022, hundreds of thousands of iterations of SHA-256
253253
are suggested. For rationale as to why and how to choose what is best for
254-
your application, read *Appendix A.2.2* of NIST-SP-800-132_.
254+
your application, read *Appendix A.2.2* of NIST-SP-800-132_. The answers
255+
on the `stackexchange pbkdf2 iterations question`_ explain in detail.
255256

256257
*dklen* is the length of the derived key. If *dklen* is ``None`` then the
257258
digest size of the hash algorithm *hash_name* is used, e.g. 64 for SHA-512.
258259

259-
>>> import hashlib
260-
>>> dk = hashlib.pbkdf2_hmac('sha256', b'password', b'salt', 100000)
260+
>>> from hashlib import pbkdf2_hmac
261+
>>> our_app_iters = 500_000 # Application specific, read above.
262+
>>> dk = pbkdf2_hmac('sha256', b'password', b'bad salt'*2, our_app_iters)
261263
>>> dk.hex()
262-
'0394a2ede332c9a13eb82e9b24631604c31df978b4e2f0fbd2c549944f9d79a5'
264+
'15530bba69924174860db778f2c6f8104d3aaf9d26241840c8c4a641c8d000a9'
263265

264266
.. versionadded:: 3.4
265267

@@ -733,7 +735,7 @@ Domain Dedication 1.0 Universal:
733735
.. _ChaCha: https://cr.yp.to/chacha.html
734736
.. _pyblake2: https://pythonhosted.org/pyblake2/
735737
.. _NIST-SP-800-132: https://nvlpubs.nist.gov/nistpubs/Legacy/SP/nistspecialpublication800-132.pdf
736-
738+
.. _stackexchange pbkdf2 iterations question: https://security.stackexchange.com/questions/3959/recommended-of-iterations-when-using-pbkdf2-sha256/
737739

738740

739741
.. seealso::

0 commit comments

Comments
 (0)