Commit graph

46 commits

Author SHA1 Message Date
Helder Eijs
eda4f65718 Move test vectors in a separate package 2021-01-03 23:49:50 +01:00
Helder Eijs
b2482ffe65 Drop support for Python 2.6 and 3.4 2020-12-30 00:02:17 +01:00
Mickaël Schoentgen
564fb9d0a0 Fix all DeprecationWarning: invalid escape sequence
Signed-off-by: Mickaël Schoentgen <contact@tiger-222.fr>
2019-04-09 11:31:43 +02:00
Helder Eijs
dfb0b5840e GH#238: fix for incorrect CMAC after copying object 2018-11-17 10:07:31 +01:00
Helder Eijs
48b6a40be0 Refactor test cases for MAC 2018-11-15 22:13:08 +01:00
Helder Eijs
066b8969ee More cleanup 2018-10-16 22:09:53 +02:00
Helder Eijs
72cf31d409 Fix Python 3 2018-10-02 19:18:23 +02:00
Helder Eijs
03ba5a0c8e Fix test vectors from RFC7539 2018-10-02 19:18:23 +02:00
Helder Eijs
4fe8d18402 Add more tests from RFC7539 2018-10-02 19:18:23 +02:00
Helder Eijs
9187985e9e Add first unit test for Poly1305 2018-10-02 19:18:23 +02:00
Helder Eijs
839c8c3798 Add test vectors for SHA512/224 and /256 2018-04-05 22:00:55 +02:00
Helder Eijs
494cbccf43 Add support for SHA-512/224 and /256 2018-04-05 21:18:48 +02:00
Helder Eijs
935fada1b9 Add test on mutable data for hashes and MACs 2018-04-01 21:14:13 +02:00
Helder Eijs
f5aa2c1618 Hashes can consume memoryview objects 2018-03-30 21:49:43 +02:00
Helder Eijs
3b317be2a6 Add support for bytearray's in ciphers
[skip ci]
2018-03-06 08:25:42 +01:00
Helder Eijs
05cdfaed35 More MD5 tests 2018-02-24 17:15:30 +01:00
Helder Eijs
0a95ceb5a2 Remove test for docstring on Hash modules 2017-08-05 19:43:34 +02:00
Legrandin
46f525e316 Add hexlify/unhexlify to Crypto.Util.py3compat 2015-11-08 13:15:41 +01:00
Legrandin
67f5e195db Remove unused data from SHA-3 and Keccak test vector files 2015-10-29 14:36:34 +01:00
Legrandin
c85dfa7953 Add Crypto.Signature.pkcs1_v1_5 module with NIST test vectors
Crypto.Signature.PKCS1_v1_5 is reverted to old behavior it
had in PyCrypto (verify raises no exception; it only returns
True or False).
2015-07-10 19:19:13 +00:00
Legrandin
b6321900a7 Cleaning up the Hash module 2015-01-30 22:38:51 +01:00
Legrandin
2c75e264ec Fix byte string problem with Python3.2 2014-06-29 12:24:25 +02:00
Legrandin
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +02:00
Legrandin
79c8a18bbd Replace test vectors with FIPS 202 suite 2014-05-11 12:44:18 +02:00
Legrandin
be12a401f1 Merge branch 'sha3' of https://github.com/bluviolin/pycrypto 2014-05-05 21:31:19 +02:00
Dwayne Litzenberger
141eee1093 hexverify: Fix handling unicode strings on Python 3.2
We were getting this error on Python 3.2:

    ERROR: runTest (Crypto.SelfTest.Hash.common.MACSelfTest)
    CMAC #17: NIST SP 800 38B D.7 Example 17
    ----------------------------------------------------------------------
    Traceback (most recent call last):
      File "build/lib.linux-x86_64-3.2/Crypto/SelfTest/Hash/common.py", line 199, in runTest
        self.assertRaises(ValueError, h.hexverify, "4556")
      File "/home/dwon/py/pythons/python3.2/lib/python3.2/unittest/case.py", line 557, in assertRaises
        callableObj(*args, **kwargs)
      File "build/lib.linux-x86_64-3.2/Crypto/Hash/CMAC.py", line 323, in hexverify
        self.verify(unhexlify(hex_mac_tag))
    TypeError: 'str' does not support the buffer interface
2013-10-20 17:36:06 -07:00
Legrandin
af392459f6 MAC unit tests become independent of hashes
The MAC unit tests assume that the MAC algorithm is
based on hash functions (HMAC).
Additionally, a single test vector is quite complex
in that it includes result for multiple tests (each
performed on the same data, but with different
hashes).

This patch simplifies the MAC unit test so that it does
not depend on hashes and a test vector is simply made up by:
* 1 input
* 1 result
* All parameters to pass to the new() function

[dlitz@dlitz.net: Replaced custom MacMismatchError with ValueError.]
[dlitz@dlitz.net: Replaced 'import *' with appropriate imports.]
[dlitz@dlitz.net: Whitespace fixed with "git rebase --whitespace=fix"]
2013-10-20 13:30:21 -07:00
Legrandin
77b0b9123c Add HMAC.verify() and HMAC.hexverify() with constant-time comparison
In the current implementation, it is left up to the caller
to assess if the locally computed MAC matches the MAC associated
to the received message.

However, the most natural way to do that (use == operator)
is also deepy unsecure, see here:

http://seb.dbzteam.org/crypto/python-oauth-timing-hmac.pdf

With this patch, the new HMAC.verify() method accepts
the given MAC and perform the check on behalf of the caller.
The method will use constant-time code (still dependent on the length
of the MAC, but not on the actual content).

[dlitz@dlitz.net: Modified commit message subject line.]
[dlitz@dlitz.net: Whitespace fixed with "git rebase --whitespace=fix"]
2013-10-20 13:30:21 -07:00
Fabrizio Tarizzo
fb9ec47a46 Unit tests now pass on Python 3
modified:   lib/Crypto/SelfTest/Hash/common.py
2013-08-20 11:28:49 +02:00
Legrandin
90d6d3dbcf Added support for PKCS#8-encrypted private keys.
The patch contains the following changes:

- Private RSA keys can be imported/exported in encrypted form,
  protected according to PKCS#8 and:

  * PBKDF2WithHMAC-SHA1AndDES-EDE3-CBC.
  * PBKDF2WithHMAC-SHA1AndAES128-CBC
  * PBKDF2WithHMAC-SHA1AndAES192-CBC
  * PBKDF2WithHMAC-SHA1AndAES256-CBC

  In addition to that, it is possible to import keys i the
  following weak formats:

  * pbeWithMD5AndDES-CBC
  * pbeWithSHA1AndRC2-CBC
  * pbeWithMD5AndRC2-CBC
  * pbeWithSHA1AndDES-CBC

- The following new module (and 1 new package) are added:

  * Crypto.Util.Padding for simple padding/unpadding logic
  * Crypto.IO._PBES for PBE-related PKCS#5 logic
  * Crypto.IO.PEM for PEM wrapping/unwrapping
  * Crypto.IO.PKCS8 for PKCS#8 wrapping/unwrapping

- All Object ID (OIDs) are now in dotted form to increase
  readability.

- Add AES support to PEM format (decode only).
  The PEM module can decrypt messages protected with AES-CBC.

- Update RSA import test cases.

- Updated to PKCS8 test cases
2013-07-14 21:16:46 -07:00
Fabrizio Tarizzo
a6e5ee654a Added Monte Carlo Test for SHA-3
modified:   lib/Crypto/SelfTest/Hash/common.py
	modified:   lib/Crypto/SelfTest/Hash/test_SHA3_224.py
	modified:   lib/Crypto/SelfTest/Hash/test_SHA3_256.py
	modified:   lib/Crypto/SelfTest/Hash/test_SHA3_384.py
	modified:   lib/Crypto/SelfTest/Hash/test_SHA3_512.py
2013-04-28 11:39:04 +02:00
Dwayne Litzenberger
fd398a28e3 Hash: Speed up initialization by removing pure-Python wrappers
The pure Python wrappers around Crypto.Hash.* were convenient, but they
slowed down hash initialization by 4-7x.

There is a speed trade-off here: The MD5 and SHA1 objects are just
wrapped hashlib objects (or old-style md5/sha objects).  To maintain API
compatibility with the rest of PyCrypto, we still have to wrap them, so
they're slower to initialize than the rest of the hash functions.  If
hashlib ever adds a .new() method, we will automatically use hashlib
directly and gain the initialization speed-up.
2013-02-17 20:07:02 -08:00
Dwayne Litzenberger
0d8ea5ff16 Hash: Generic Crypto.Hash.new(algo, [data]) function
This allows us to instantiate a new hash given only an existing hash
object.
2013-02-17 19:18:29 -08:00
Dwayne Litzenberger
59018ff99c Hash: Remove "oid" attributes; add "name" attribute
In PyCrypto v2.5, the "oid" attribute was added to hash objects.  In
retrospect, this was not a good idea, since the OID is not really a
property of the hash algorithm, it's a protocol-specific identifer for
the hash functions.  PKCS#1 v1.5 uses it, but other protocols (e.g.
OpenPGP, DNSSEC, SSH, etc.) use different identifiers, and it doesn't make
sense to add these to Crypto.Hash.* every time a new algorithm is added.

This also has the benefit of being compatible with the Python standard
library's "hashlib" objects, which also have a name attribute.
2013-02-17 19:00:50 -08:00
Legrandin
c22fa18c0d Merged from upstream (py3k support) and modified so that all unit tests pass. 2011-10-18 23:20:26 +02:00
Legrandin
897b75983c Added Lorenz Quack's native C implementation of all SHA-2 algorithm
(as submitted here https://bugs.launchpad.net/pycrypto/+bug/544792)
so that they are available also in Python 2.1, 2.2, 2.3 and 2.4.

Regardless where the implementation comes from (Python standard
library or our native modules, depending on the Python version),
all Crypto.Hash objects are always used as front-ends.
2011-10-16 22:41:21 +02:00
Dwayne C. Litzenberger
25a055334e Don't abuse __builtins__
According to Jean-Paul Calderone at https://bugs.launchpad.net/pycrypto/+bug/785150:

    `__builtins__` is an implementation detail of CPython. It takes on
    inconsistent values at various times. The use in `common.py` happens to
    work on recent version of CPython, but it doesn't work on PyPy. The only
    thing you should ever do, when you're doing this sort of thing, is "import
    __builtin__; __builtin__.foo".
2011-10-10 23:59:37 -04:00
Dwayne C. Litzenberger
1bd6ef6294 Py3k compatibility: tests 2011-10-10 16:05:23 -04:00
Anders Sundman
28f8bd25da Unwraping byte conversion on test vectors.
Doing the wraping later, at the point of use instead.
2011-04-24 17:35:12 +02:00
Legrandin
07e9e97e9d Add new() method to all remaining hash algorithms, so as to make them to work with PKCS#1 PSS. Add also test cases for it for every hash. 2011-02-07 22:32:49 +01:00
Legrandin
b2c5880538 Make tests compatible to Python 2.1 2011-02-03 19:34:47 +01:00
Legrandin
3082d19c39 Add test routines to validate OID in hash algorithms. 2011-02-03 01:35:58 +01:00
Thorsten Behrens
cb48387f66 PY3K _fastmath support
o _fastmath now builds and runs on PY3K
o Changes to setup.py to allow /usr/include for gmp.h
o Changes to setup.py to allow linking fastmath w/ static mpir
  on Windows without warning messages
o Changes to test_DSA/test_RSA to throw an exception if _fastmath
  is present but cannot be imported (due to an issue building
  _fastmath or the shared gmp/mpir libraries not being reachable)
o number.py has the code to flag a failing _fastmath, but that
  code is commented out for a better runtime experience
o Clean up the if for py21compat import - should have been == not is
o Clean up some '== None' occurences, now 'is None' instead
2010-12-29 13:21:05 -05:00
Thorsten Behrens
295ce314d9 Changes to allow pycrpyto to work on Python 3.x as well as 2.1 through 2.7 2010-12-28 16:26:52 -05:00
Dwayne C. Litzenberger
386de1947b Legal: Dedicate my files to the public domain.
In an attempt to simplify the copyright status of PyCrypto, I'm placing my
code into the public domain, and encouraging other contributors to do the
same.

I have used a public domain dedication that was recommended in a book on FOSS legal
issues[1], followed by the warranty disclaimer boilerplate from the MIT license.

[1] _Intellectual Property and Open Source: A Practical Guide to Protecting
    Code_, a book written by Van Lindberg and published by O'Reilly Media.
    (ISBN 978-0-596-51796-0)
2009-03-01 10:22:51 -05:00
Dwayne C. Litzenberger
ff8a657a8d cleanup: Move modules to "lib/Crypto" subdirectory.
This will avoid the previous situation where scripts like the old "test.py"
get included accidentally in a release.  It also frees us to put additional
build scripts in the top-level directory of the source tree.
2009-02-28 13:14:53 -05:00
Renamed from SelfTest/Hash/common.py (Browse further)