Commit graph

33 commits

Author SHA1 Message Date
Legrandin
7073325ff7 Update to documentation 2015-07-19 19:12:47 +00:00
Legrandin
03b14b6a0c Simplify C code by moving caches under Python 2015-05-29 09:06:49 -04:00
Legrandin
a24f0fb534 First draft of OCB
[skip ci]
2015-05-24 15:29:26 -04: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
5d5a709811 Make modules to compile again with MSVC 2015-02-02 21:40:34 +01:00
Legrandin
c36fdefd24 cpuid uses the raw interface too 2015-01-23 15:24:21 +00:00
Legrandin
e934e4135d Symmetric ciphers use cffi too (when available). 2015-01-22 09:35:44 +01:00
Legrandin
cb844d8292 More reliable way to infer module extension 2015-01-05 23:06:22 +01:00
Legrandin
08baea4cb4 Break up block_template.c (AES only) 2015-01-05 23:06:21 +01:00
Legrandin
e9adec93c7 Every cipher instance is a mode-specific type 2014-12-10 21:40:49 +01:00
Legrandin
546912f61d Factor out GCM code into separate module 2014-12-09 21:33:41 +01:00
Legrandin
350935d855 Factor out EAX mode into separate module 2014-12-08 22:15:50 +01:00
Legrandin
774d28d441 Factor out OpenPGP cipher mode in separate module 2014-12-08 21:53:14 +01:00
Legrandin
aaeea1f33b Factor out CCM mode in a separate module 2014-12-08 21:07:14 +01:00
Legrandin
9e4d71df58 Factor out SIV cipher mode into a separate module 2014-12-08 11:49:38 +01:00
Legrandin
465d0391ac ECB is not the default mode for a new cipher.
The expression AES.new(key) used to be equivalent
to AES.new(key, AES.MODE_ECB). The same applies to
any other algorithm beside AES.

Since the ECB mode is not a secure default,
the expression AES.new(key) will now raise an exception.

NOTE: this change sets breaks compatibility with PyCrypto
2014-06-16 20:36:36 +02:00
Legrandin
d83380a048 Removed support for Python<2.4 2014-06-16 20:36:35 +02:00
Legrandin
7c5a1ebb99 Fixed sentence in CCM example 2014-02-21 23:59:53 -08: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
199a9741a1 Add support for SIV (Synthetic IV) mode
This patch add supports for SIV, an AEAD block cipher
mode defined in RFC5297. SIV is only valid for AES.

The PRF of SIV (S2V) is factored out in the Protocol.KDF module.

See the following example to get a feeling of the API (slightly
different than other AEAD mode, during decryption).

Encryption (Python 2):

	>>> from Crypto.Cipher import AES
	>>> key = b'0'*32
	>>> siv = AES.new(key, AES.MODE_SIV)
	>>> ct  = siv.encrypt(b'Message')
	>>> mac = siv.digest()

Decryption (Python 2):

	>>> from Crypto.Cipher import AES, MacMismatchError
	>>> key = b'0'*32
	>>> siv = AES.new(key, AES.MODE_SIV)
	>>> pt  = siv.decrypt(ct + mac)
	>>> try:
	>>>	siv.verify(mac)
	>>>	print "Plaintext", pt
	>>> except MacMismatchError:
	>>>     print "Error"

This change also fixes the description/design of AEAD API.

With SIV (RFC5297), decryption can only start when the MAC is known.
The original AEAD API did not support that.

For SIV the MAC is now exceptionally passed together with the ciphertext
to the decrypt() method.

[dlitz@dlitz.net: Included changes from the following commits from the author's pull request:]
- [9c13f9c] Rename 'IV' parameter to 'nonce' for AEAD modes.
- [d7727fb] Fix description/design of AEAD API.
- [fb62fae] ApiUsageError becomes TypeError [whitespace]
- [4ec64d8] Removed last references to ApiUsageError [whitespace]
- [ee46922] Removed most 'import *' statements
- [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: A conflict that was not resolved in the previous
                  commit was originally resolved here.  Moved the
                  resolution to the previous commit.]
[dlitz@dlitz.net: Replaced MacMismatchError with ValueError]
[dlitz@dlitz.net: Replaced ApiUsageError with TypeError]
[dlitz@dlitz.net: Whitespace fixed with "git rebase --whitespace=fix"]
2013-10-20 13:30:21 -07:00
Legrandin
8bdbdb8168 Add EAX authenticated encryption mode
[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: Fixed unresolved conflict in lib/Crypto/Cipher/blockalgo.py]
2013-10-20 13:30:21 -07:00
Legrandin
57104488fa Add support for CCM mode (AES only).
[dlitz@dlitz.net: Included changes from the following commits from the author's pull request:]
- [5306cf3] Added support for CCM mode (AES cipher only)
- [9abe301] Added CCM tests
- [f0c1395] Add MacMismatchError and ApiUsageError
- [fb62fae] ApiUsageError becomes TypeError
- [9c13f9c] Rename 'IV' parameter to 'nonce' for AEAD modes.
- [4ec64d8] Removed last references to ApiUsageError
- [80bfd35] Corrected AES-CCM examples
[dlitz@dlitz.net: Removed unrelated documentation change]
[dlitz@dlitz.net: Renamed 'targs' back to 'args']
[dlitz@dlitz.net: Whitespace fixed with "git rebase --whitespace=fix"]
2013-10-20 13:30:21 -07:00
Dwayne Litzenberger
cce74edc6c AES-NI support: Python 2.1 Backward compatibility
- METH_NOARGS was introduced in Python 2.2.
- Python 2.1 doesn't have True and False builtins.
2013-04-21 20:41:18 -07:00
Sebastian Ramacher
e1ce77b167 Initial AES-NI support 2013-04-21 20:41:18 -07:00
Stefano Rivera
cbc13b3f42 Update docstring. IVs are no longer optional 2012-05-27 17:41:46 +01:00
Legrandin
62f2c4154c Added OpenPGP mode 2012-05-17 22:17:38 +02:00
Legrandin
1eec0099f3 Fixed 2 typos in documentation 2012-05-17 21:05:01 +02:00
Legrandin
c3aadee360 Added example for all symmetric ciphers 2012-05-14 23:50:40 +02:00
Legrandin
d0863eabfb Minor fixes for documentation of ciphers
Fixed key lengths described with xrange()
Removed unnecessary imports.
Removed documentation for compiled modules starting with '_'.
2012-05-14 19:03:39 +02:00
Legrandin
4ce6b8d7f1 Fixes to make test suite pass for Python 2.1 and Python 3 2012-05-11 22:57:49 +02:00
Legrandin
6f9fe103a5 Added documentation for AES and DES.
A new module (blockalgo) has been added. It contains a class (BlockAlgo)
all ciphers derive from. The only purpose of such base class
is to centralize all general documentation applicable to all block
ciphers (e.g. modes) into a single file.
2012-05-10 19:16:50 +02:00