diff options
author | Legrandin <helderijs@gmail.com> | 2013-06-09 11:30:27 +0200 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-10-20 13:30:22 -0700 |
commit | c5787d70f52dc9e78b8e859bd4cae8e75ce2cf41 (patch) | |
tree | a5bba3a1f7ae318693dd97b1a3625a1583474116 /lib/Crypto | |
parent | 35be87837d1280688da72f294498c09af7f3e7e7 (diff) | |
download | pycrypto-c5787d70f52dc9e78b8e859bd4cae8e75ce2cf41.tar.gz |
GCM mode: Optimize GCM speed with pre-computed tables.
Tables take 64KByte per each key.
Encryption performance is more than doubled
(29 MBps vs 8MBps for AES128).
As a drawback, key setup is much slower (1300 key/s
on the same machine).
[dlitz@dlitz.net: Replaced MacMismatchError with ValueError]
[dlitz@dlitz.net: Replaced ApiUsageError with TypeError]
[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: Whitespace fixed with "git rebase --whitespace=fix"]
Diffstat (limited to 'lib/Crypto')
-rw-r--r-- | lib/Crypto/Cipher/blockalgo.py | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/lib/Crypto/Cipher/blockalgo.py b/lib/Crypto/Cipher/blockalgo.py index 7ab892a..9ac8710 100644 --- a/lib/Crypto/Cipher/blockalgo.py +++ b/lib/Crypto/Cipher/blockalgo.py @@ -37,7 +37,7 @@ from Crypto.Hash import CMAC from Crypto.Hash.CMAC import _SmoothMAC from Crypto.Protocol.KDF import S2V -from Crypto.Util.galois import _ghash +from Crypto.Util import galois #: *Electronic Code Book (ECB)*. #: This is the simplest encryption mode. Each of the plaintext blocks @@ -331,9 +331,9 @@ class _GHASH(_SmoothMAC): def __init__(self, hash_subkey, block_size): _SmoothMAC.__init__(self, block_size, None, 0) - self._hash_subkey = hash_subkey + self._hash_subkey = galois._ghash_expand(hash_subkey) self._last_y = bchr(0) * 16 - self._mac = _ghash + self._mac = galois._ghash def copy(self): clone = _GHASH(self._hash_subkey, self._bs) @@ -342,7 +342,8 @@ class _GHASH(_SmoothMAC): return clone def _update(self, block_data): - self._last_y = _ghash(block_data, self._last_y, self._hash_subkey) + self._last_y = galois._ghash(block_data, self._last_y, + self._hash_subkey) def _digest(self, left_data): return self._last_y |