Commit Graph

62 Commits

Author SHA1 Message Date
Serhiy Storchaka 9b8c2e7676
bpo-34922: Fix integer overflow in the digest() and hexdigest() methods (GH-9751)
for the SHAKE algorithm in the hashlib module.
2018-10-11 07:41:00 +03:00
Serhiy Storchaka f1d36d8efa
bpo-33729: Fix issues with arguments parsing in hashlib. (GH-8346)
* help(hashlib) didn't work because of incorrect module name in blake2b and
  blake2s classes.
* Constructors blake2*(), sha3_*(), shake_*() and keccak_*() incorrectly
  accepted keyword argument "string" for binary data, but documented as
  accepting the "data" keyword argument. Now this parameter is positional-only.
* Keyword-only parameters in blake2b() and blake2s() were not documented as
  keyword-only.
* Default value for some parameters of blake2b() and blake2s() was None,
  which is not acceptable value.
* The length argument for shake_*.digest() was wrapped out to 32 bits.
* The argument for shake_128.digest() and shake_128.hexdigest() was not
  positional-only as intended.
* TypeError messages for incorrect arguments in all constructors sha3_*(),
  shake_*() and keccak_*() incorrectly referred to sha3_224.

Also made the following enhancements:

* More accurately specified input and result types for strings, bytes and
  bytes-like objects.
* Unified positional parameter names for update() and constructors.
* Improved formatting.
2018-07-31 09:50:16 +03:00
Serhiy Storchaka 7cb7bcff20
bpo-20260: Implement non-bitwise unsigned int converters for Argument Clinic. (GH-8434) 2018-07-26 13:22:16 +03:00
INADA Naoki f0bc645dfe
bpo-31787: Skip refleak check when _hashlib is not available (GH-5660) 2018-02-13 23:41:19 +09:00
Oren Milman d019bc8319 bpo-31787: Prevent refleaks when calling __init__() more than once (GH-3995) 2018-02-13 19:28:33 +09:00
Benjamin Peterson 95441809ef
closes bpo-32721: do not fail test_hashlib if _md5 isn't available (GH-5441) 2018-01-29 22:14:17 -08:00
Benjamin Peterson 77526f05fa replace dynamic import with 'exec' with importlib.import_module (#5433) 2018-01-29 18:03:01 -08:00
Jack O'Connor dcfb0e3c04 bpo-31933: fix blake2 multi-byte params on big endian platforms (#4250)
All Blake2 params have to be encoded in little-endian byte order. For
the two multi-byte integer params, leaf_length and node_offset, that
means that assigning a native-endian integer to them appears to work on
little-endian platforms, but gives the wrong result on big-endian. The
current libb2 API doesn't make that very clear, and @sneves is working
on new API functions in the GH issue above. In the meantime, we can work
around the problem by explicitly assigning little-endian values to the
parameter block.

See https://github.com/BLAKE2/libb2/issues/12.
2017-11-03 20:02:41 +01:00
Victor Stinner 8dcf22f442 bpo-31234: Join threads in test_hashlib (#3573)
* bpo-31234: Join threads in test_hashlib

Use thread.join() to wait until the parallel hash tasks complete
rather than using events. Calling thread.join() prevent "dangling
thread" warnings.

* test_hashlib: minor PEP 8 coding style fixes
2017-09-14 08:43:22 -07:00
Antoine Pitrou a6a4dc816d bpo-31370: Remove support for threads-less builds (#3385)
* Remove Setup.config
* Always define WITH_THREAD for compatibility.
2017-09-07 18:56:24 +02:00
Christian Heimes e370409cb1 Add test cases for internal SHA3 helpers 2016-09-23 11:32:30 +02:00
Christian Heimes 81188246fa Issue 26798: fetch OSError and HTTPException like other tests that use open_urlresource. 2016-09-08 10:53:40 +02:00
Christian Heimes 6fe2a75b64 Issue #16113: Add SHA-3 and SHAKE support to hashlib module. 2016-09-07 11:58:24 +02:00
Christian Heimes 59a0464af4 Download hashlib test vectors from pythontest.net 2016-09-07 01:21:14 +02:00
Christian Heimes 121b9487d1 Issue #26798: Add BLAKE2 (blake2b and blake2s) to hashlib. 2016-09-06 22:03:25 +02:00
Christian Heimes 39093e9e68 Issue #27928: Add scrypt (password-based key derivation function) to hashlib module (requires OpenSSL 1.1.0). 2016-09-06 20:22:28 +02:00
Martin Panter 46f50726a0 Issue #27076: Doc, comment and tests spelling fixes
Most fixes to Doc/ and Lib/ directories by Ville Skyttä.
2016-05-26 05:35:26 +00:00
Martin Panter bc85e35fe6 Issue #26390: Fix and test pbkdf2_hmac() parameter names
Based on patch by Daan Bakker.
2016-02-22 09:21:49 +00:00
Ned Deily 153879075f Issue #16113: Also remove test_case_sha3_224_huge 2014-11-28 15:21:12 -08:00
Serhiy Storchaka 786ac7b27d Issue #19886: Use better estimated memory requirements for bigmem tests.
Incorrect requirements can cause memory swapping.
2014-01-10 13:39:27 +02:00
Serhiy Storchaka 4847e4e1f4 Issue #19886: Use better estimated memory requirements for bigmem tests.
Incorrect requirements can cause memory swapping.
2014-01-10 13:37:54 +02:00
Martin v. Löwis 24e43308b7 * Issue #16113: Remove sha3 module again.
Patch by Christian Heimes, with modifications.
2014-01-03 14:05:06 +01:00
Christian Heimes e53510726b Issue #18742: Rework the internal hashlib construtor to pave the road for ABCs. 2013-10-22 14:59:12 +02:00
Christian Heimes 0fbd94ced9 Issue #18582: skip test of _hashlib.pbkdf2_hmac if OpenSSL is not available or too old 2013-10-19 19:40:49 +02:00
Christian Heimes 3626a505db Issue #19254: Provide an optimized Python implementation of PBKDF2_HMAC 2013-10-19 14:12:02 +02:00
Christian Heimes e92ef13b0a Issue #18582: Add 'pbkdf2_hmac' to the hashlib module. 2013-10-13 00:52:43 +02:00
Christian Heimes 37d5cebb48 Change the builtin hash algorithms' names to lower case names
as promised by hashlib's documentation.
2013-08-15 18:31:48 +02:00
Gregory P. Smith 914061ab15 * Fix the assertions in hashlib to use unittest assertion methods instead of
evil assert statements.
* Add an additional assert to the new test_name_attribute test that actually
  confirms that a hash created using each h.name results in a new hash sharing
  the same name.
2013-08-05 13:14:37 -07:00
Jason R. Coombs b2aa6f4055 Issue 18532: Added tests and documentation to formally specify the .name attribute on hashlib objects. 2013-08-03 11:39:39 +02:00
Christian Heimes d49a371e91 Issue #18599: Fix name attribute of _sha1.sha1() object. It now returns
'SHA1' instead of 'SHA'.
Add more tests for hashlib and hash object attributes
2013-07-30 15:35:54 +02:00
Christian Heimes 65aa573082 Add more tests for hashlib and hash object attributes 2013-07-30 15:33:30 +02:00
Brett Cannon 3e9a9ae09d Update various test modules to use unittest.main() for test discovery
instead of manually listing tests for test.support.run_unittest().
2013-06-12 21:25:59 -04:00
Christian Heimes 4a0270d82b Issue #16113: integrade SHA-3 (Keccak) patch from http://hg.python.org/sandbox/cheimes 2012-10-06 02:23:36 +02:00
Gregory P. Smith 34fcafde16 Consistently raise a TypeError when a non str is passed to hashlib.new
regardless of which of the two implementations of new is used.
2012-07-21 21:20:44 -07:00
Gregory P. Smith 76c28f7ce2 Consistently raise a TypeError when a non str is passed to hashlib.new
regardless of which of the two implementations of new is used.
2012-07-21 21:19:53 -07:00
Amaury Forgeot d'Arc 3a3dc17fc9 Port tests from Issue #15219, and verify we don't have a reference leak. 2012-06-29 01:53:13 +02:00
Antoine Pitrou 019ff19c39 Issue #14693: Under non-Windows platforms, hashlib's fallback modules are always compiled, even if OpenSSL is present at build time. 2012-05-16 16:41:26 +02:00
Antoine Pitrou 94190bb6e7 Start fixing test_bigmem:
- bigmemtest is replaced by precisionbigmemtest
- add a poor man's watchdog thread to print memory consumption
2011-10-04 10:22:36 +02:00
Gregory P. Smith 12c9d028ed Fixes Issue #12059: Properly handle missing hash functions even when
the expected builtin modules are not present.

This includes a unittest for __get_builtin_constructor() in the face
of such an error.
2011-05-14 15:15:49 -07:00
Raymond Hettinger bf1d2bc7cb Make the type consistent for hashlib algorithm constants. (Reviewed by Benjamin). 2011-01-24 04:52:27 +00:00
Ezio Melotti b3aedd4862 #9424: Replace deprecated assert* methods in the Python test suite. 2010-11-20 19:04:17 +00:00
Antoine Pitrou d7ae299e4b Fix test_hashlib with the bigmem option 2010-11-08 20:36:57 +00:00
Gregory P. Smith 13b55291ac hashlib has two new constant attributes: algorithms_guaranteed and
algorithms_avaiable that respectively list the names of hash algorithms
guaranteed to exist in all Python implementations and the names of hash
algorithms available in the current process.

Renames the attribute new in 3.2a0 'algorithms' to 'algorithms_guaranteed'.
2010-09-06 08:30:23 +00:00
Victor Stinner 45df820591 Merged revisions 80552-80556,80564-80566,80568-80571 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r80552 | victor.stinner | 2010-04-27 23:46:03 +0200 (mar., 27 avril 2010) | 3 lines

  Issue #7449, part 1: fix test_support.py for Python compiled without thread
........
  r80553 | victor.stinner | 2010-04-27 23:47:01 +0200 (mar., 27 avril 2010) | 1 line

  Issue #7449, part 2: regrtest.py -j option requires thread support
........
  r80554 | victor.stinner | 2010-04-27 23:51:26 +0200 (mar., 27 avril 2010) | 9 lines

  Issue #7449 part 3, test_doctest: import trace module in test_coverage()

  Import trace module fail if the threading module is missing. test_coverage() is
  only used if test_doctest.py is used with the -c option. This commit allows to
  execute the test suite without thread support.

  Move "import trace" in test_coverage() and use
  test_support.import_module('trace').
........
  r80555 | victor.stinner | 2010-04-27 23:56:26 +0200 (mar., 27 avril 2010) | 6 lines

  Issue #7449, part 4: skip test_multiprocessing if thread support is disabled

  import threading after _multiprocessing to raise a more revelant error message:
  "No module named _multiprocessing". _multiprocessing is not compiled without
  thread support.
........
  r80556 | victor.stinner | 2010-04-28 00:01:24 +0200 (mer., 28 avril 2010) | 8 lines

  Issue #7449, part 5: split Test.test_open() of ctypes/test/test_errno.py

   * Split Test.test_open() in 2 functions: test_open() and test_thread_open()
   * Skip test_open() and test_thread_open() if we are unable to find the C
     library
   * Skip test_thread_open() if thread support is disabled
   * Use unittest.skipUnless(os.name == "nt", ...) on test_GetLastError()
........
  r80564 | victor.stinner | 2010-04-28 00:59:35 +0200 (mer., 28 avril 2010) | 4 lines

  Issue #7449, part 6: fix test_hashlib for missing threading module

  Move @test_support.reap_thread decorator from test_main() to test_threaded_hashing().
........
  r80565 | victor.stinner | 2010-04-28 01:01:29 +0200 (mer., 28 avril 2010) | 6 lines

  Issue #7449, part 7: simplify threading detection in test_capi

   * Skip TestPendingCalls if threading module is missing
   * Test if threading module is present or not, instead of test the presence of
     _testcapi._test_thread_state
........
  r80566 | victor.stinner | 2010-04-28 01:03:16 +0200 (mer., 28 avril 2010) | 4 lines

  Issue #7449, part 8: don't skip the whole test_asynchat if threading is missing

  TestFifo can be executed without the threading module
........
  r80568 | victor.stinner | 2010-04-28 01:14:58 +0200 (mer., 28 avril 2010) | 6 lines

  Issue #7449, part 9: fix test_xmlrpclib for missing threading module

   * Skip testcases using threads if threading module is missing
   * Use "http://" instead of URL in ServerProxyTestCase if threading is missing
     because URL is not set in this case
........
  r80569 | victor.stinner | 2010-04-28 01:33:58 +0200 (mer., 28 avril 2010) | 6 lines

  Partial revert of r80556 (Issue #7449, part 5, fix ctypes test)

  Rewrite r80556: the thread test have to be executed just after the test on
  libc_open() and so the test cannot be splitted in two functions (without
  duplicating code, and I don't want to duplicate code).
........
  r80570 | victor.stinner | 2010-04-28 01:51:16 +0200 (mer., 28 avril 2010) | 8 lines

  Issue #7449, part 10: test_cmd imports trace module using test_support.import_module()

  Use test_support.import_module() instead of import to raise a SkipTest
  exception if the import fail. Import trace fails if the threading module is
  missing.

  See also part 3: test_doctest: import trace module in test_coverage().
........
  r80571 | victor.stinner | 2010-04-28 01:55:59 +0200 (mer., 28 avril 2010) | 6 lines

  Issue #7449, last part (11): fix many tests if thread support is disabled

   * Use try/except ImportError or test_support.import_module() to import thread
     and threading modules
   * Add @unittest.skipUnless(threading, ...) to testcases using threads
........
2010-04-28 22:31:17 +00:00
Georg Brandl 1b37e8728c Merged revisions 78093 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78093 | georg.brandl | 2010-02-07 18:03:15 +0100 (So, 07 Feb 2010) | 1 line

  Remove unused imports in test modules.
........
2010-03-14 10:45:50 +00:00
Gregory P. Smith 86508cc88b Merged revisions 78528 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r78528 | gregory.p.smith | 2010-02-28 18:01:47 -0800 (Sun, 28 Feb 2010) | 2 lines

  Adds the hashlib.algorithms attribute.  See issue7418.
........
2010-03-01 02:05:26 +00:00
Benjamin Peterson a28e7028f9 Merged revisions 77185-77188,77262,77313,77317,77331-77333,77337-77338 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77185 | andrew.kuchling | 2009-12-31 10:17:05 -0600 (Thu, 31 Dec 2009) | 1 line

  Add some items
........
  r77186 | benjamin.peterson | 2009-12-31 10:28:24 -0600 (Thu, 31 Dec 2009) | 1 line

  update expat comment
........
  r77187 | andrew.kuchling | 2009-12-31 10:38:53 -0600 (Thu, 31 Dec 2009) | 1 line

  Add various items
........
  r77188 | benjamin.peterson | 2009-12-31 10:49:37 -0600 (Thu, 31 Dec 2009) | 1 line

  add another advancement
........
  r77262 | andrew.kuchling | 2010-01-02 19:15:21 -0600 (Sat, 02 Jan 2010) | 1 line

  Add a few items
........
  r77313 | benjamin.peterson | 2010-01-04 18:04:19 -0600 (Mon, 04 Jan 2010) | 1 line

  add a test about hashing array.array
........
  r77317 | georg.brandl | 2010-01-05 12:14:52 -0600 (Tue, 05 Jan 2010) | 1 line

  Add Stefan.
........
  r77331 | georg.brandl | 2010-01-06 11:43:06 -0600 (Wed, 06 Jan 2010) | 1 line

  Small fixes to test_cmd: fix signature of do_shell, remove duplicate import, add option to run the custom Cmd class.
........
  r77332 | georg.brandl | 2010-01-06 12:02:16 -0600 (Wed, 06 Jan 2010) | 7 lines

  #5991: let completion for the "help" command include help topics.

  This also simplifies the Cmd.get_names() method implementation; it was written
  at a time where dir() didn't consider base class attributes.
........
  r77333 | georg.brandl | 2010-01-06 12:26:08 -0600 (Wed, 06 Jan 2010) | 1 line

  #5950: document that zip files with comments are unsupported in zipimport.
........
  r77337 | r.david.murray | 2010-01-06 21:09:08 -0600 (Wed, 06 Jan 2010) | 3 lines

  Add -W to the 'basics', 'opt', and 'all' test runs so that we get verbose
  information if a failure happens.
........
  r77338 | r.david.murray | 2010-01-06 22:04:28 -0600 (Wed, 06 Jan 2010) | 2 lines

  Fix inadvertent checkin of debug line.
........
2010-01-09 18:53:06 +00:00
Benjamin Peterson 46a9900e09 Merged revisions 77209,77229,77359-77360,77371 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77209 | georg.brandl | 2010-01-01 07:07:05 -0600 (Fri, 01 Jan 2010) | 1 line

  More yearly updates.
........
  r77229 | georg.brandl | 2010-01-02 06:35:01 -0600 (Sat, 02 Jan 2010) | 1 line

  Fix casing.
........
  r77359 | georg.brandl | 2010-01-07 14:54:45 -0600 (Thu, 07 Jan 2010) | 1 line

  Fix description for Py_GetPath(); it sounded like it always returned sys.path.
........
  r77360 | georg.brandl | 2010-01-07 15:48:47 -0600 (Thu, 07 Jan 2010) | 1 line

  #7653: clarify how the PythonPath registry key should look like.
........
  r77371 | senthil.kumaran | 2010-01-08 13:20:25 -0600 (Fri, 08 Jan 2010) | 3 lines

  Fix for Issue7026. For the Error - RuntimeError: dictionary changed size during iteration
........
2010-01-09 18:45:30 +00:00
Gregory P. Smith b04ded4927 Also fixes test_hashlib for the different extension module names in py3k.
Merged revisions 77251 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77251 | gregory.p.smith | 2010-01-02 14:25:29 -0800 (Sat, 02 Jan 2010) | 6 lines

  Always compile the all versions of the hashlib algorithm modules when Python
  was compiled with Py_DEBUG defined.  Otherwise the builtins are not compiled by
  default for many developers due to OpenSSL being present, making it easier for
  bugs to slip by.  A future commit will add test code compare the behaviors of
  all implementations when they are all available.
........
2010-01-03 00:38:10 +00:00
Gregory P. Smith cd54e546bb Merged revisions 77257 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r77257 | gregory.p.smith | 2010-01-02 16:19:04 -0800 (Sat, 02 Jan 2010) | 8 lines

  Import all implementations of the hash algorithms (OpenSSL & builtin) and run
  the test suite across all that are available.  Warns about extension modules
  that could not be imported when python was compiled with Py_DEBUG.

  That warning could be made fatal but I didn't want to do that initially as
  I suspect non setup.py based build processes (windows, any others?) won't
  compile them all conditionally based on the Py_DEBUG setting today.
........
2010-01-03 00:29:15 +00:00