diff options
author | Legrandin <helderijs@gmail.com> | 2013-05-13 08:40:46 +0200 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-10-20 13:30:21 -0700 |
commit | da79b781af41ff815b812c49d9be434f5de52aa4 (patch) | |
tree | 16c3d6251bfafaeb7bd96743d2be3e5d4fbec439 /pct-speedtest.py | |
parent | 92fea1b6065c6ca75381b465f846843494372c4d (diff) | |
download | pycrypto-da79b781af41ff815b812c49d9be434f5de52aa4.tar.gz |
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"]
Diffstat (limited to 'pct-speedtest.py')
-rw-r--r-- | pct-speedtest.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/pct-speedtest.py b/pct-speedtest.py index 365eca2..e84cf81 100644 --- a/pct-speedtest.py +++ b/pct-speedtest.py @@ -31,7 +31,7 @@ from Crypto.PublicKey import RSA from Crypto.Cipher import PKCS1_OAEP, PKCS1_v1_5 as RSAES_PKCS1_v1_5 from Crypto.Signature import PKCS1_PSS, PKCS1_v1_5 as RSASSA_PKCS1_v1_5 from Crypto.Cipher import AES, ARC2, ARC4, Blowfish, CAST, DES3, DES, XOR -from Crypto.Hash import HMAC, MD2, MD4, MD5, SHA224, SHA256, SHA384, SHA512 +from Crypto.Hash import HMAC, MD2, MD4, MD5, SHA224, SHA256, SHA384, SHA512, CMAC from Crypto.Random import get_random_bytes import Crypto.Util.Counter from Crypto.Util.number import bytes_to_long @@ -227,6 +227,19 @@ class Benchmark: mac_constructor = lambda data=None: hmac_constructor(key, data, digestmod) self.test_hash_large(mac_name, mac_constructor, digest_size) + def test_cmac_small(self, mac_name, cmac_constructor, ciphermod, key_size): + keys = iter(self.random_keys(key_size)) + if sys.version_info[0] == 2: + mac_constructor = lambda data=None: cmac_constructor(keys.next(), data, ciphermod) + else: + mac_constructor = lambda data=None: cmac_constructor(keys.__next__(), data, ciphermod) + self.test_hash_small(mac_name, mac_constructor, ciphermod.block_size) + + def test_cmac_large(self, mac_name, cmac_constructor, ciphermod, key_size): + key = self.random_keys(key_size)[0] + mac_constructor = lambda data=None: cmac_constructor(key, data, ciphermod) + self.test_hash_large(mac_name, mac_constructor, ciphermod.block_size) + def test_pkcs1_sign(self, scheme_name, scheme_constructor, hash_name, hash_constructor, digest_size): self.announce_start("%s signing %s (%d-byte inputs)" % (scheme_name, hash_name, digest_size)) @@ -372,6 +385,11 @@ class Benchmark: self.test_hmac_small("hmac+"+hash_name, hmac.HMAC, func, func().digest_size) self.test_hmac_large("hmac+"+hash_name, hmac.HMAC, func, func().digest_size) + # CMAC + for cipher_name, module, key_size in (("AES128", AES, 16),): + self.test_cmac_small(cipher_name+"-CMAC", CMAC.new, module, key_size) + self.test_cmac_large(cipher_name+"-CMAC", CMAC.new, module, key_size) + # PKCS1_v1_5 (sign) + Crypto.Hash for hash_name, module in hash_specs: self.test_pkcs1_sign("PKCS#1-v1.5", RSASSA_PKCS1_v1_5.new, hash_name, module.new, module.digest_size) |