cpython: e73627483d2f (original) (raw)

Mercurial > cpython

changeset 86467:e73627483d2f

Issue #19254: Provide an optimized Python implementation of PBKDF2_HMAC [#19254]

Christian Heimes christian@cheimes.de
date Sat, 19 Oct 2013 14:12:02 +0200
parents 47618b00405b
children b8987863f74d
files Doc/library/hashlib.rst Lib/hashlib.py Lib/test/test_hashlib.py Misc/NEWS
diffstat 4 files changed, 86 insertions(+), 11 deletions(-)[+] [-] Doc/library/hashlib.rst 6 Lib/hashlib.py 69 Lib/test/test_hashlib.py 20 Misc/NEWS 2

line wrap: on

line diff

--- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -212,7 +212,11 @@ slow and include a salt. .. versionadded:: 3.4

.. seealso::

--- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -1,4 +1,4 @@ -# Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org) +#. Copyright (C) 2005-2010 Gregory P. Smith (greg@krypto.org)

Licensed to PSF under a Contributor Agreement.

# @@ -61,7 +61,7 @@ algorithms_guaranteed = set(__always_sup algorithms_available = set(__always_supported) all = __always_supported + ('new', 'algorithms_guaranteed',

def __get_builtin_constructor(name): @@ -147,13 +147,70 @@ except ImportError: new = __py_new __get_hash = __get_builtin_constructor -# PBKDF2 requires OpenSSL 1.0+ with HMAC and SHA try:

-else:

+

+

+

+

+

+

+

+

+ for __func_name in __always_supported: # try them all, some may not work due to the OpenSSL

--- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -18,11 +18,13 @@ except ImportError: import unittest import warnings from test import support -from test.support import _4G, bigmemtest +from test.support import _4G, bigmemtest, import_fresh_module

Were we compiled --with-pydebug or with #define Py_DEBUG?

COMPILED_WITH_PYDEBUG = hasattr(sys, 'gettotalrefcount') +c_hashlib = import_fresh_module('hashlib', fresh=['_hashlib']) +py_hashlib = import_fresh_module('hashlib', blocked=['_hashlib']) def hexstr(s): assert isinstance(s, bytes), repr(s) @@ -545,6 +547,10 @@ class HashLibTestCase(unittest.TestCase) self.assertEqual(expected_hash, hasher.hexdigest()) + +class KDFTests:

+ pbkdf2_test_vectors = [ (b'password', b'salt', 1, None), (b'password', b'salt', 2, None), @@ -594,10 +600,8 @@ class HashLibTestCase(unittest.TestCase) (bytes.fromhex('9d9e9c4cd21fe4be24d5b8244c759665'), None),], }

for digest_name, results in self.pbkdf2_results.items(): for i, vector in enumerate(self.pbkdf2_test_vectors): @@ -628,5 +632,13 @@ class HashLibTestCase(unittest.TestCase) pbkdf2('unknown', b'pass', b'salt', 1) +class PyKDFTests(KDFTests, unittest.TestCase):

+ + +class CKDFTests(KDFTests, unittest.TestCase):

+ + if name == "main": unittest.main()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -57,6 +57,8 @@ Core and Builtins Library ------- +- Issue #19254: Provide an optimized Python implementation of PBKDF2_HMAC. +