From 80c311262daf19f796a190cc99e850d199315c0a Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Fri, 22 Mar 2019 16:53:43 +0100 Subject: [WIP][implem-python] Intégration à la soumission MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- nist/make-package.sh | 2 ++ nist/package-python.sh | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100755 nist/package-python.sh (limited to 'nist') diff --git a/nist/make-package.sh b/nist/make-package.sh index 234532a..c3bbd32 100755 --- a/nist/make-package.sh +++ b/nist/make-package.sh @@ -116,3 +116,5 @@ done cp -r ${TMP_DIR}/crypto_aead . cleanup + +${NIST_DIR}/package-python.sh diff --git a/nist/package-python.sh b/nist/package-python.sh new file mode 100755 index 0000000..4813dc7 --- /dev/null +++ b/nist/package-python.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +set -eu + +NIST_DIR=$(dirname $0) +ROOT=${NIST_DIR}/.. +ADD_PYTHON=${ROOT}/src/add_python +CRYPTO_AEAD=${ROOT}/crypto_aead + + +add-variant () +{ + local mode=$1 + local keylen=$2 + + local -A names=([1]=lilliputaei [2]=lilliputaeii) + + variant_dir=${CRYPTO_AEAD}/${names[${mode}]}${keylen}v1 + + cp -r ${ADD_PYTHON} ${variant_dir} + + cat < ${variant_dir}/add_python/parameters.py +MODE = ${mode} +KEYBYTES = $((keylen/8)) +EOF +} + + +for mode in 1 2 +do + for keylen in 128 192 256 + do + add-variant ${mode} ${keylen} + done +done -- cgit v1.2.3 From c0d7ffb343d38a301773ea49975de6c54c91e264 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Sat, 23 Mar 2019 19:31:06 +0100 Subject: [implem-python] Intégration à la soumission (suite et fin) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit En plus du paquet Python "lilliput", chaque dossier embarque - un script "genkat_aead.py" qui génère les vecteurs de test via l'API du module "crypto_aead", - un module "crypto_aead" servant de point d'entrée générique, - un module "parameters", qui permet à crypto_aead d'instancier Lilliput-AE avec le bon mode et la bonne taille de clé. Livraison dans ./crypto_aead sans se soucier de l'arborescence du dépôt, par homogénéité avec make-package.sh. Quelques ajustement dans genkat_aead.py pour que le lien avec genkat_aead.c soit plus évident. --- nist/package-python.sh | 7 +++++-- test/python/genkat_aead.py | 24 ++++++++++++++++-------- 2 files changed, 21 insertions(+), 10 deletions(-) (limited to 'nist') diff --git a/nist/package-python.sh b/nist/package-python.sh index 4813dc7..88c4ef1 100755 --- a/nist/package-python.sh +++ b/nist/package-python.sh @@ -5,7 +5,7 @@ set -eu NIST_DIR=$(dirname $0) ROOT=${NIST_DIR}/.. ADD_PYTHON=${ROOT}/src/add_python -CRYPTO_AEAD=${ROOT}/crypto_aead +PYTHON_RESOURCES=${ROOT}/test/python/ add-variant () @@ -15,7 +15,7 @@ add-variant () local -A names=([1]=lilliputaei [2]=lilliputaeii) - variant_dir=${CRYPTO_AEAD}/${names[${mode}]}${keylen}v1 + variant_dir=crypto_aead/${names[${mode}]}${keylen}v1 cp -r ${ADD_PYTHON} ${variant_dir} @@ -23,6 +23,9 @@ add-variant () MODE = ${mode} KEYBYTES = $((keylen/8)) EOF + + cp ${PYTHON_RESOURCES}/{crypto_aead.py,genkat_aead.py} \ + ${variant_dir}/add_python } 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) -- cgit v1.2.3