summaryrefslogtreecommitdiff
path: root/pct-speedtest.py
diff options
context:
space:
mode:
Diffstat (limited to 'pct-speedtest.py')
-rw-r--r--pct-speedtest.py20
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)