lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

commit 1870b1eadf3963f9ec5d52bed21f04e523933612
parent d7830279e9545b420e4cc0f4b810675df728e98f
Author: Kévin Le Gouguec <kevin.legouguec@airbus.com>
Date:   Wed, 13 Mar 2019 16:47:57 +0100

Changement de l'API de l'implémentation Python

Pour qu'on puisse plus facilement manipuler les entrées/sorties.

Pour le moment le round-trip chiffrement/déchiffrement marche.

    import lilliput

    message = 'Hello 🌐!'
    adata = 'Signed: Kévin'

    for mode in 1,2:
        for keylen in 128, 192, 256:
            ct, tag = lilliput.mainEnc(message, adata, mode, keylen)
            pt = lilliput.mainDec(ct, tag, adata, mode, keylen)
            assert message == pt

Diffstat:
Mpython/lilliput.py | 26++++++++++++++------------
1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/python/lilliput.py b/python/lilliput.py @@ -48,15 +48,17 @@ def ArrayToBlockbytesMatrix(array) : return matrix +def BlockbytesMatrixToBytes(matrix): + return bytes(byte for block in matrix for byte in block) + ############################################ -def mainEnc(mode = 1, length = 128) : +def mainEnc(plaintext, adata, mode=1, length=128): (key_bits, tweak_bits, rounds) = GetParameters(mode, length) - - A = [byte for byte in range(0, 16)] - M = [byte for byte in range(0, 17)] + A = adata.encode() + M = plaintext.encode() N = [0 for byte in range(0, N_BYTES)] key = [byte for byte in range(0, int(key_bits/8))] @@ -66,7 +68,6 @@ def mainEnc(mode = 1, length = 128) : A = ArrayToBlockbytesMatrix(A) M = ArrayToBlockbytesMatrix(M) - if(mode == 1) : (C, tag) = lilliput_ae_1.OCB3Enc(A, M, N, A_BITS, M_BITS, key, key_bits, tweak_bits, rounds) if(mode == 2) : @@ -78,18 +79,18 @@ def mainEnc(mode = 1, length = 128) : print("%02x "%(byte), end="") print() + return BlockbytesMatrixToBytes(C), bytes(tag) -def mainDec(mode = 1, length = 128) : - (key_bits, tweak_bits, rounds) = GetParameters(mode, length) +def mainDec(ciphertext, tag, adata, mode=1, length=128): + (key_bits, tweak_bits, rounds) = GetParameters(mode, length) - A = [byte for byte in range(0, 16)] - C = [byte for byte in range(0, 16)] + A = adata.encode() + C = ciphertext N = [0 for byte in range(0, N_BYTES)] key = [byte for byte in range(0, int(key_bits/8))] - tag = [] - + tag = list(tag) M_BITS = 8 * len(C) A_BITS = 8 * len(A) @@ -97,7 +98,6 @@ def mainDec(mode = 1, length = 128) : A = ArrayToBlockbytesMatrix(A) C = ArrayToBlockbytesMatrix(C) - if(mode == 1) : M = lilliput_ae_1.OCB3Dec(A, C, N, tag, A_BITS, M_BITS, key, key_bits, tweak_bits, rounds) if(mode == 2) : @@ -106,3 +106,5 @@ def mainDec(mode = 1, length = 128) : for byte in M[block] : print("%02x "%(byte), end="") print() + + return BlockbytesMatrixToBytes(M).decode()