Skip to content

Commit bc85e35

Browse files
committed
Issue python#26390: Fix and test pbkdf2_hmac() parameter names
Based on patch by Daan Bakker.
1 parent 8c16cb9 commit bc85e35

2 files changed

Lines changed: 10 additions & 6 deletions

File tree

‎Doc/library/hashlib.rst‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,22 +185,23 @@ brute-force attacks. A good password hashing function must be tunable, slow, and
185185
include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
186186

187187

188-
.. function:: pbkdf2_hmac(name, password, salt, rounds, dklen=None)
188+
.. function:: pbkdf2_hmac(hash_name, password, salt, iterations, dklen=None)
189189

190190
The function provides PKCS#5 password-based key derivation function 2. It
191191
uses HMAC as pseudorandom function.
192192

193-
The string *name* is the desired name of the hash digest algorithm for
193+
The string *hash_name* is the desired name of the hash digest algorithm for
194194
HMAC, e.g. 'sha1' or 'sha256'. *password* and *salt* are interpreted as
195195
buffers of bytes. Applications and libraries should limit *password* to
196-
a sensible value (e.g. 1024). *salt* should be about 16 or more bytes from
196+
a sensible length (e.g. 1024). *salt* should be about 16 or more bytes from
197197
a proper source, e.g. :func:`os.urandom`.
198198

199-
The number of *rounds* should be chosen based on the hash algorithm and
200-
computing power. As of 2013, at least 100,000 rounds of SHA-256 is suggested.
199+
The number of *iterations* should be chosen based on the hash algorithm and
200+
computing power. As of 2013, at least 100,000 iterations of SHA-256 are
201+
suggested.
201202

202203
*dklen* is the length of the derived key. If *dklen* is ``None`` then the
203-
digest size of the hash algorithm *name* is used, e.g. 64 for SHA-512.
204+
digest size of the hash algorithm *hash_name* is used, e.g. 64 for SHA-512.
204205

205206
>>> import hashlib, binascii
206207
>>> dk = hashlib.pbkdf2_hmac('sha256', b'password', b'salt', 100000)

‎Lib/test/test_hashlib.py‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -513,6 +513,9 @@ def _test_pbkdf2_hmac(self, pbkdf2):
513513
self.assertRaises(ValueError, pbkdf2, 'sha1', b'pass', b'salt', 1, -1)
514514
with self.assertRaisesRegex(ValueError, 'unsupported hash type'):
515515
pbkdf2('unknown', b'pass', b'salt', 1)
516+
out = pbkdf2(hash_name='sha1', password=b'password', salt=b'salt',
517+
iterations=1, dklen=None)
518+
self.assertEqual(out, self.pbkdf2_results['sha1'][0][0])
516519

517520
def test_pbkdf2_hmac_py(self):
518521
self._test_pbkdf2_hmac(py_hashlib.pbkdf2_hmac)

0 commit comments

Comments
 (0)