Commit graph

69 commits

Author SHA1 Message Date
Legrandin
b8d07cbc24 Prepare docs for release 3.3 2015-10-28 21:35:55 +01:00
Legrandin
bdda4f9133 Updates to docs 2015-10-28 21:21:29 +01:00
Legrandin
1a5b9f5de5 Add SHAKE128 and SHAKE256 2015-10-28 18:01:48 +01:00
Legrandin
0cb9555d8b SHA3 object cannot be copied nor changed after digest 2015-10-28 18:01:47 +01:00
Legrandin
38ea6cba76 Keccak objects cannot be copied nor changed after digest
[skip ci]
2015-10-28 18:01:47 +01:00
Legrandin
50d9c6b035 Add Crypto.Hash.keccak module 2015-10-28 18:01:47 +01:00
Legrandin
354abdd4c7 Add digest size parameter to keccak_digest.
Also, some minor clean up to keccak C code.
2015-10-28 18:01:46 +01:00
Legrandin
7506698308 Use one native module for all 4 SHA3 variants 2015-10-28 18:01:46 +01:00
Legrandin
c8f9a58e83 Update link to final FIPS 202 (SHA-3) 2015-09-04 21:34:59 +02:00
Legrandin
7073325ff7 Update to documentation 2015-07-19 19:12:47 +00: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
46dc96c30d Formatting 2015-06-05 21:41:10 +02:00
Legrandin
fda457dbdb Raise exception if message is too long given block size 2015-06-05 21:41:10 +02:00
Legrandin
a3988bf260 Refactored CMAC to internally copy less data 2015-06-05 21:41:10 +02:00
Legrandin
d0311fb416 MAC checks are all performed with BLAKE2s 2015-04-16 14:11:50 +02:00
Legrandin
db6c6f8e5e Add support or BLAKE2s and BLAKE2b 2015-04-16 14:11:50 +02:00
Legrandin
72aff29a65 Update to API documentation. 2015-03-11 11:30:16 -04:00
Legrandin
0b76cd2168 Ensure that all data passed to C backend is byte strings 2015-02-10 22:29:40 +01:00
Legrandin
11a6d1dfa4 Flag explicitly certain arguments as of size_t type 2015-02-10 16:45:25 +01:00
Legrandin
b6321900a7 Cleaning up the Hash module 2015-01-30 22:38:51 +01:00
Legrandin
49d6e4488f SHA-3 uses raw interface 2015-01-30 22:26:34 +01:00
Legrandin
349cbbe513 MD4 uses raw interface 2015-01-29 22:37:28 +01:00
Legrandin
05f9f1ab03 MD2 uses raw interface 2015-01-29 22:22:01 +01:00
Legrandin
ce57f25f7d RIPEMD160 uses raw interface 2015-01-29 22:22:00 +01:00
Legrandin
3ee624b328 SHA-2 family uses raw libs 2015-01-28 22:27:27 +01:00
Legrandin
0e3320ed43 Galois module uses raw interface 2015-01-25 18:01:45 +01:00
Legrandin
af28deab82 Make benchmark script work again 2015-01-10 21:47:35 +01:00
Legrandin
e9adec93c7 Every cipher instance is a mode-specific type 2014-12-10 21:40:49 +01:00
Legrandin
aaeea1f33b Factor out CCM mode in a separate module 2014-12-08 21:07:14 +01:00
Legrandin
8675e6f03f Start licensing under BSD 2-Clause 2014-06-23 22:23:38 +02:00
Legrandin
6d11571e1a Replace HMAC code with public domain implementation 2014-06-16 20:38:26 +02:00
Legrandin
251fbd8e8c Hide private modules from documentation 2014-06-16 20:38:26 +02:00
Legrandin
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +02:00
Legrandin
ddca00943e Remove block_size attribute from SHA3 digests 2014-05-11 12:45:28 +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
Dwayne Litzenberger
0ae375d573 CMAC: raise TypeError instead of ValueError when ciphermod is missing or unusable
This makes the CMAC module behave more like most Python functions do
when a required argument is missing, and reserves ValueError for a MAC
failure.
2013-10-20 13:30:22 -07:00
Legrandin
5d7ab24c51 Add support for GCM mode (AES only).
The main change done by this commit is adding support
for MODE_GCM (NIST SP 800 38D). Test vectors are included.

The mode uses a C extension (Crypto.Util.galois._ghash)
to compute the GHASH step. The C implementation is the most
basic one and it is still significantly (5x times) slower than CTR.
Optimizations can be introduced using tables (CPU/memory trade-off)
or even AES NI instructions on newer x86 CPUs.

This patch also simplifies Crypto.Cipher.blockalgo.py by:
 * removing duplicated code previously shared by digest() and verify().
 * removing duplicated code previously shared by Crypto.Hash.CMAC
   and Crypto.Cipher.block_algo (management of internal buffers
   for MACs that can only operate on block aligned data, like
   CMAC, CBCMAC, and now also GHASH).

[dlitz@dlitz.net: Included changes from the following commits from the author's pull request:]
- [9c13f9c] Rename 'IV' parameter to 'nonce' for AEAD modes.
- [ca460a7] Made blockalgo.py more PEP-8 compliant;
            The second parameter of the _GHASH constructor
            is now the length of the block (block_size)
            and not the full module.
[dlitz@dlitz.net: Replaced MacMismatchError with ValueError]
[dlitz@dlitz.net: Replaced ApiUsageError with TypeError]
[dlitz@dlitz.net: Replaced renamed variable `ht` with original `h`]
[dlitz@dlitz.net: Whitespace fixed with "git rebase --whitespace=fix"]
2013-10-20 13:30:21 -07:00
Legrandin
da79b781af Add support for CMAC
This patch adds support for CMAC (RFC4493, NIST SP800-38B).

[dlitz@dlitz.net: Replaced MacMismatchError with ValueError]
[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
Dwayne Litzenberger
c82be67c1e Update RIPEMD documentation (deprecated; see RIPEMD160) 2013-07-14 20:29:52 -07:00
Fabrizio Tarizzo
24df7d3c5d Merge with upstream updates 2013-04-28 12:06:18 +02:00
Fabrizio Tarizzo
6c6e44e174 Correction in doc strings
modified:   lib/Crypto/Hash/SHA3_224.py
	modified:   lib/Crypto/Hash/SHA3_256.py
	modified:   lib/Crypto/Hash/SHA3_384.py
	modified:   lib/Crypto/Hash/SHA3_512.py
2013-04-28 11:35:39 +02:00
Fabrizio Tarizzo
7cce0ce5d5 Implementation of the SHA-3 (Keccak) family 2013-04-28 11:35:38 +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
Dwayne Litzenberger
18137d0e42 Hash: Rename SHA->SHA1 and RIPEMD->RIPEMD160 (2/2)
These algorithm names were confusing, because there are actually
algorithms called "SHA" (a.k.a. SHA-0) and "RIPEMD" (the original
version).

This commit adds backward-compatibility support for the old
Crypto.Hash.SHA and Crypto.Hash.RIPEMD modules.
2013-02-16 16:20:30 -08:00
Dwayne Litzenberger
755375bb7d Hash: Rename SHA->SHA1 and RIPEMD->RIPEMD160 (1/2)
These algorithm names were confusing, because there are actually
algorithms called "SHA" (a.k.a. SHA-0) and "RIPEMD" (the original
version).

This commit just renames the modules, with no backward-compatibility
support.
2013-02-16 16:20:23 -08:00
Dwayne C. Litzenberger
6ca6d21540 Fix typos in docs 2012-05-23 22:15:53 -04:00