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
74cca70c
Commit
74cca70c
authored
Sep 28, 2012
by
Nick Coghlan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now that it's possible, avoid timing attacks in the crypt module examples)
parent
2246aa8a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
3 deletions
+8
-3
Doc/library/crypt.rst
Doc/library/crypt.rst
+7
-3
Doc/library/crypto.rst
Doc/library/crypto.rst
+1
-0
No files found.
Doc/library/crypt.rst
View file @
74cca70c
...
...
@@ -121,11 +121,14 @@ The :mod:`crypt` module defines the following functions:
Examples
--------
A simple example illustrating typical use::
A simple example illustrating typical use (a constant-time comparison
operation is needed to limit exposure to timing attacks.
:func:`hmac.compare_digest` is suitable for this purpose)::
import pwd
import crypt
import getpass
from hmac import compare_digest as compare_hash
def login():
username = input('Python login: ')
...
...
@@ -134,7 +137,7 @@ A simple example illustrating typical use::
if cryptedpasswd == 'x' or cryptedpasswd == '*':
raise ValueError('no support for shadow passwords')
cleartext = getpass.getpass()
return c
rypt.crypt(cleartext, cryptedpasswd) == cryptedpasswd
return c
ompare_hash(crypt.crypt(cleartext, cryptedpasswd), cryptedpasswd)
else:
return True
...
...
@@ -142,7 +145,8 @@ To generate a hash of a password using the strongest available method and
check it against the original::
import crypt
from hmac import compare_digest as compare_hash
hashed = crypt.crypt(plaintext)
if
hashed != crypt.crypt(plaintext, hashed
):
if
not compare_hash(hashed, crypt.crypt(plaintext, hashed)
):
raise ValueError("hashed version doesn't validate against original")
Doc/library/crypto.rst
View file @
74cca70c
...
...
@@ -8,6 +8,7 @@ Cryptographic Services
The modules described in this chapter implement various algorithms of a
cryptographic nature. They are available at the discretion of the installation.
On Unix systems, the :mod:`crypt` module may also be available.
Here's an overview:
...
...
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