Commit graph

12 commits

Author SHA1 Message Date
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
0e3320ed43 Galois module uses raw interface 2015-01-25 18:01:45 +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
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +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