mirror of
https://github.com/Legrandin/pycryptodome.git
synced 2025-12-08 05:19:46 +00:00
Add GCM test for messages between 0 and 159 bytes
This commit is contained in:
parent
256f946544
commit
a98fa382ba
1 changed files with 24 additions and 1 deletions
|
|
@ -36,7 +36,7 @@ from Crypto.SelfTest.loader import load_tests
|
||||||
|
|
||||||
from Crypto.Util.py3compat import unhexlify, tobytes, bchr, b, _memoryview
|
from Crypto.Util.py3compat import unhexlify, tobytes, bchr, b, _memoryview
|
||||||
from Crypto.Cipher import AES
|
from Crypto.Cipher import AES
|
||||||
from Crypto.Hash import SHAKE128
|
from Crypto.Hash import SHAKE128, SHA256
|
||||||
|
|
||||||
from Crypto.Util._file_system import pycryptodome_filename
|
from Crypto.Util._file_system import pycryptodome_filename
|
||||||
from Crypto.Util.strxor import strxor
|
from Crypto.Util.strxor import strxor
|
||||||
|
|
@ -852,6 +852,27 @@ class TestVectorsWycheproof(unittest.TestCase):
|
||||||
self.test_corrupt_decrypt(tv)
|
self.test_corrupt_decrypt(tv)
|
||||||
|
|
||||||
|
|
||||||
|
class TestVariableLength(unittest.TestCase):
|
||||||
|
|
||||||
|
def __init__(self, **extra_params):
|
||||||
|
unittest.TestCase.__init__(self)
|
||||||
|
self._extra_params = extra_params
|
||||||
|
|
||||||
|
def runTest(self):
|
||||||
|
key = b'0' * 16
|
||||||
|
h = SHA256.new()
|
||||||
|
|
||||||
|
for length in range(160):
|
||||||
|
nonce = '{0:04d}'.format(length).encode('utf-8')
|
||||||
|
data = bchr(length) * length
|
||||||
|
cipher = AES.new(key, AES.MODE_GCM, nonce=nonce, **self._extra_params)
|
||||||
|
ct, tag = cipher.encrypt_and_digest(data)
|
||||||
|
h.update(ct)
|
||||||
|
h.update(tag)
|
||||||
|
|
||||||
|
self.assertEqual(h.hexdigest(), '1057d9559f55227fd4e36bab8716ebcfe6671b5603fdceb046a33591175ee5e4')
|
||||||
|
|
||||||
|
|
||||||
def get_tests(config={}):
|
def get_tests(config={}):
|
||||||
from Crypto.Util import _cpuid
|
from Crypto.Util import _cpuid
|
||||||
|
|
||||||
|
|
@ -863,11 +884,13 @@ def get_tests(config={}):
|
||||||
tests += [ TestVectors() ]
|
tests += [ TestVectors() ]
|
||||||
tests += [ TestVectorsWycheproof(wycheproof_warnings) ]
|
tests += [ TestVectorsWycheproof(wycheproof_warnings) ]
|
||||||
tests += list_test_cases(TestVectorsGueronKrasnov)
|
tests += list_test_cases(TestVectorsGueronKrasnov)
|
||||||
|
tests += [ TestVariableLength() ]
|
||||||
if config.get('slow_tests'):
|
if config.get('slow_tests'):
|
||||||
tests += list_test_cases(NISTTestVectorsGCM)
|
tests += list_test_cases(NISTTestVectorsGCM)
|
||||||
|
|
||||||
if _cpuid.have_clmul():
|
if _cpuid.have_clmul():
|
||||||
tests += [ TestVectorsWycheproof(wycheproof_warnings, use_clmul=False) ]
|
tests += [ TestVectorsWycheproof(wycheproof_warnings, use_clmul=False) ]
|
||||||
|
tests += [ TestVariableLength(use_clmul = False) ]
|
||||||
if config.get('slow_tests'):
|
if config.get('slow_tests'):
|
||||||
tests += list_test_cases(NISTTestVectorsGCM_no_clmul)
|
tests += list_test_cases(NISTTestVectorsGCM_no_clmul)
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue