summaryrefslogtreecommitdiff
path: root/test/python
diff options
context:
space:
mode:
Diffstat (limited to 'test/python')
-rwxr-xr-xtest/python/genkat_aead.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/test/python/genkat_aead.py b/test/python/genkat_aead.py
index 01bed6f..5e953c4 100755
--- a/test/python/genkat_aead.py
+++ b/test/python/genkat_aead.py
@@ -3,8 +3,13 @@
import crypto_aead
+class DecryptionError(Exception):
+ def __init__(self):
+ super().__init__('crypto_aead_decrypt did not recover the plaintext')
+
+
MAX_MESSAGE_LENGTH = 32
-MAX_ADATA_LENGTH = 32
+MAX_ASSOCIATED_DATA_LENGTH = 32
def print_bstr(output, label, buf):
@@ -12,23 +17,25 @@ def print_bstr(output, label, buf):
def generate_test_vectors():
- output_path = 'LWC_AEAD_KAT_{key}_{npub}.txt'.format(
+ count = 1
+ filename = 'LWC_AEAD_KAT_{key}_{npub}.txt'.format(
key=crypto_aead.KEYBYTES*8, npub=crypto_aead.NPUBBYTES*8
)
npub = bytes(range(crypto_aead.NPUBBYTES))
key = bytes(range(crypto_aead.KEYBYTES))
- with open(output_path, 'w') as output:
+ with open(filename, 'w') as output:
- count = 1
for mlen in range(MAX_MESSAGE_LENGTH+1):
- for adlen in range(MAX_ADATA_LENGTH+1):
- print('Count = {c}'.format(c=count), file=output)
+ for adlen in range(MAX_ASSOCIATED_DATA_LENGTH+1):
msg = bytes(range(mlen))
ad = bytes(range(adlen))
+ print('Count = {c}'.format(c=count), file=output)
+ count += 1
+
print_bstr(output, 'Key', key)
print_bstr(output, 'Nonce', npub)
print_bstr(output, 'PT', msg)
@@ -38,9 +45,10 @@ def generate_test_vectors():
print_bstr(output, 'CT', ct)
- crypto_aead.decrypt(ct, ad, npub, key)
+ msg2 = crypto_aead.decrypt(ct, ad, npub, key)
- count += 1
+ if msg != msg2:
+ raise DecryptionError()
print(file=output)