Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
de9b27d9
Commit
de9b27d9
authored
Feb 26, 2016
by
Martin Panter
Browse files
Options
Browse Files
Download
Plain Diff
Issue #26390: Merge pbkdf2_hmac() doc from 3.5
parents
6d6dd73a
bc85e35f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
6 deletions
+10
-6
Doc/library/hashlib.rst
Doc/library/hashlib.rst
+7
-6
Lib/test/test_hashlib.py
Lib/test/test_hashlib.py
+3
-0
No files found.
Doc/library/hashlib.rst
View file @
de9b27d9
...
...
@@ -185,22 +185,23 @@ brute-force attacks. A good password hashing function must be tunable, slow, and
include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
.. function:: pbkdf2_hmac(
name, password, salt, round
s, dklen=None)
.. function:: pbkdf2_hmac(
hash_name, password, salt, iteration
s, dklen=None)
The function provides PKCS#5 password-based key derivation function 2. It
uses HMAC as pseudorandom function.
The string *name* is the desired name of the hash digest algorithm for
The string *
hash_
name* is the desired name of the hash digest algorithm for
HMAC, e.g. 'sha1' or 'sha256'. *password* and *salt* are interpreted as
buffers of bytes. Applications and libraries should limit *password* to
a sensible
value
(e.g. 1024). *salt* should be about 16 or more bytes from
a sensible
length
(e.g. 1024). *salt* should be about 16 or more bytes from
a proper source, e.g. :func:`os.urandom`.
The number of *rounds* should be chosen based on the hash algorithm and
computing power. As of 2013, at least 100,000 rounds of SHA-256 is suggested.
The number of *iterations* should be chosen based on the hash algorithm and
computing power. As of 2013, at least 100,000 iterations of SHA-256 are
suggested.
*dklen* is the length of the derived key. If *dklen* is ``None`` then the
digest size of the hash algorithm *name* is used, e.g. 64 for SHA-512.
digest size of the hash algorithm *
hash_
name* is used, e.g. 64 for SHA-512.
>>> import hashlib, binascii
>>> dk = hashlib.pbkdf2_hmac('sha256', b'password', b'salt', 100000)
...
...
Lib/test/test_hashlib.py
View file @
de9b27d9
...
...
@@ -513,6 +513,9 @@ class KDFTests(unittest.TestCase):
self
.
assertRaises
(
ValueError
,
pbkdf2
,
'sha1'
,
b'pass'
,
b'salt'
,
1
,
-
1
)
with
self
.
assertRaisesRegex
(
ValueError
,
'unsupported hash type'
):
pbkdf2
(
'unknown'
,
b'pass'
,
b'salt'
,
1
)
out
=
pbkdf2
(
hash_name
=
'sha1'
,
password
=
b'password'
,
salt
=
b'salt'
,
iterations
=
1
,
dklen
=
None
)
self
.
assertEqual
(
out
,
self
.
pbkdf2_results
[
'sha1'
][
0
][
0
])
def
test_pbkdf2_hmac_py
(
self
):
self
.
_test_pbkdf2_hmac
(
py_hashlib
.
pbkdf2_hmac
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment