From 95e1596db04fd55d777a1fccf031e86657ab1072 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Thu, 14 Mar 2019 11:06:41 +0100 Subject: [implem-python] Passage des clés et nonces par paramètres MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- python/lilliput.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'python/lilliput.py') diff --git a/python/lilliput.py b/python/lilliput.py index 92d8662..79f14e5 100644 --- a/python/lilliput.py +++ b/python/lilliput.py @@ -53,14 +53,22 @@ def BlockbytesMatrixToBytes(matrix): ############################################ -def mainEnc(plaintext, adata, mode=1, length=128): +def _checkInputs(key, length, nonce): + if len(key) != length//8: + raise ValueError('invalid key size: {} != {}'.format(len(key), length//8)) + + if len(nonce) != N_BYTES: + raise ValueError('nonce must be {}-byte long'.format(N_BYTES)) + + +def mainEnc(plaintext, adata, key, nonce, mode=1, length=128): + _checkInputs(key, length, nonce) (key_bits, tweak_bits, rounds) = GetParameters(mode, length) A = adata M = plaintext - N = [byte for byte in range(0, N_BYTES)] - key = [byte for byte in range(0, int(key_bits/8))] + N = nonce A_BITS = 8 * len(A) M_BITS = 8 * len(M) @@ -76,14 +84,14 @@ def mainEnc(plaintext, adata, mode=1, length=128): return BlockbytesMatrixToBytes(C), bytes(tag) -def mainDec(ciphertext, tag, adata, mode=1, length=128): +def mainDec(ciphertext, tag, adata, key, nonce, mode=1, length=128): + _checkInputs(key, length, nonce) (key_bits, tweak_bits, rounds) = GetParameters(mode, length) A = adata C = ciphertext - N = [byte for byte in range(0, N_BYTES)] - key = [byte for byte in range(0, int(key_bits/8))] + N = nonce tag = list(tag) M_BITS = 8 * len(C) -- cgit v1.2.3