diff options
author | Legrandin <helderijs@gmail.com> | 2013-05-20 12:43:44 +0200 |
---|---|---|
committer | Dwayne Litzenberger <dlitz@dlitz.net> | 2013-10-20 13:30:21 -0700 |
commit | 8bdbdb8168511018d44ef014ae21da619ae73c24 (patch) | |
tree | 75d7a4c60d07dc0bb960705e71ac5f551d8631a9 /lib/Crypto/SelfTest | |
parent | 57104488faa9fc386ea1aee249bafb6e2a529a57 (diff) | |
download | pycrypto-8bdbdb8168511018d44ef014ae21da619ae73c24.tar.gz |
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]
Diffstat (limited to 'lib/Crypto/SelfTest')
-rw-r--r-- | lib/Crypto/SelfTest/Cipher/common.py | 18 | ||||
-rw-r--r-- | lib/Crypto/SelfTest/Cipher/test_AES.py | 80 |
2 files changed, 92 insertions, 6 deletions
diff --git a/lib/Crypto/SelfTest/Cipher/common.py b/lib/Crypto/SelfTest/Cipher/common.py index e52a781..603ab54 100644 --- a/lib/Crypto/SelfTest/Cipher/common.py +++ b/lib/Crypto/SelfTest/Cipher/common.py @@ -382,12 +382,12 @@ class CCMSplitEncryptionTest(unittest.TestCase): class AEADTests(unittest.TestCase): """Tests generic to all AEAD modes""" - def __init__(self, module, mode_name): + def __init__(self, module, mode_name, key_size): unittest.TestCase.__init__(self) self.module = module self.mode_name = mode_name self.mode = getattr(module, mode_name) - self.key = b('\xFF')*16 + self.key = b('\xFF')*key_size self.iv = b('\x00')*10 self.description = "AEAD Test" @@ -658,7 +658,7 @@ def make_block_tests(module, module_name, test_data, additional_params=dict()): extra_tests_added = 1 # Extract associated data and MAC for AEAD modes - if p_mode == 'CCM': + if p_mode in ('CCM', 'EAX'): assoc_data, params['plaintext'] = params['plaintext'].split('|') assoc_data2, params['ciphertext'], params['mac'] = params['ciphertext'].split('|') params['assoc_data'] = assoc_data @@ -687,10 +687,16 @@ def make_block_tests(module, module_name, test_data, additional_params=dict()): CCMMACLengthTest(module), CCMSplitEncryptionTest(module), ] - for aead_mode in ("MODE_CCM",): + for aead_mode in ("MODE_CCM","MODE_EAX"): if hasattr(module, aead_mode): - tests += [ - AEADTests(module, aead_mode), + key_sizes = [] + try: + key_sizes += module.key_size + except TypeError: + key_sizes = [ module.key_size ] + for ks in key_sizes: + tests += [ + AEADTests(module, aead_mode, ks), ] return tests diff --git a/lib/Crypto/SelfTest/Cipher/test_AES.py b/lib/Crypto/SelfTest/Cipher/test_AES.py index 878f56b..53d60c0 100644 --- a/lib/Crypto/SelfTest/Cipher/test_AES.py +++ b/lib/Crypto/SelfTest/Cipher/test_AES.py @@ -1679,6 +1679,86 @@ test_data = [ 'RFC3610 Packet Vector #24', dict(mode='CCM', nonce='008d493b30ae8b3c9696766cfa') ), + + # Test vectors for EAX taken from http://www.cs.ucdavis.edu/~rogaway/papers/eax.pdf + # This is a list of tuples with 5 items: + # + # 1. Header + '|' + plaintext + # 2. Header + '|' + ciphertext + '|' + MAC + # 3. AES-128 key + # 4. Description + # 5. Dictionary of parameters to be passed to AES.new(). It must + # include the nonce. + # + ( '6bfb914fd07eae6b|', + '6bfb914fd07eae6b||e037830e8389f27b025a2d6527e79d01', + '233952dee4d5ed5f9b9c6d6ff80ff478', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='62EC67F9C3A4A407FCB2A8C49031A8B3') + ), + + ( 'fa3bfd4806eb53fa|f7fb', + 'fa3bfd4806eb53fa|19dd|5c4c9331049d0bdab0277408f67967e5', + '91945d3f4dcbee0bf45ef52255f095a4', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='BECAF043B0A23D843194BA972C66DEBD') + ), + + ( '234a3463c1264ac6|1a47cb4933', + '234a3463c1264ac6|d851d5bae0|3a59f238a23e39199dc9266626c40f80', + '01f74ad64077f2e704c0f60ada3dd523', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='70C3DB4F0D26368400A10ED05D2BFF5E') + ), + + ( '33cce2eabff5a79d|481c9e39b1', + '33cce2eabff5a79d|632a9d131a|d4c168a4225d8e1ff755939974a7bede', + 'd07cf6cbb7f313bdde66b727afd3c5e8', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='8408DFFF3C1A2B1292DC199E46B7D617') + ), + + ( 'aeb96eaebe2970e9|40d0c07da5e4', + 'aeb96eaebe2970e9|071dfe16c675|cb0677e536f73afe6a14b74ee49844dd', + '35b6d0580005bbc12b0587124557d2c2', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='FDB6B06676EEDC5C61D74276E1F8E816') + ), + + ( 'd4482d1ca78dce0f|4de3b35c3fc039245bd1fb7d', + 'd4482d1ca78dce0f|835bb4f15d743e350e728414|abb8644fd6ccb86947c5e10590210a4f', + 'bd8e6e11475e60b268784c38c62feb22', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='6EAC5C93072D8E8513F750935E46DA1B') + ), + + ( '65d2017990d62528|8b0a79306c9ce7ed99dae4f87f8dd61636', + '65d2017990d62528|02083e3979da014812f59f11d52630da30|137327d10649b0aa6e1c181db617d7f2', + '7c77d6e813bed5ac98baa417477a2e7d', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='1A8C98DCD73D38393B2BF1569DEEFC19') + ), + + ( '54b9f04e6a09189a|1bda122bce8a8dbaf1877d962b8592dd2d56', + '54b9f04e6a09189a|2ec47b2c4954a489afc7ba4897edcdae8cc3|3b60450599bd02c96382902aef7f832a', + '5fff20cafab119ca2fc73549e20f5b0d', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='DDE59B97D722156D4D9AFF2BC7559826') + ), + + ( '899a175897561d7e|6cf36720872b8513f6eab1a8a44438d5ef11', + '899a175897561d7e|0de18fd0fdd91e7af19f1d8ee8733938b1e8|e7f6d2231618102fdb7fe55ff1991700', + 'a4a4782bcffd3ec5e7ef6d8c34a56123', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='B781FCF2F75FA5A8DE97A9CA48E522EC') + ), + + ( '126735fcc320d25a|ca40d7446e545ffaed3bd12a740a659ffbbb3ceab7', + '126735fcc320d25a|cb8920f87a6c75cff39627b56e3ed197c552d295a7|cfc46afc253b4652b1af3795b124ab6e', + '8395fcf1e95bebd697bd010bc766aac3', + 'EAX spec Appendix G', + dict(mode='EAX', nonce='22E7ADD93CFC6393C57EC0B3C17D6B44') + ), ] def get_tests(config={}): |