diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-13 16:47:57 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-13 16:47:57 +0100 |
| commit | 1870b1eadf3963f9ec5d52bed21f04e523933612 (patch) | |
| tree | bebd3e59ba12904014fb7a052f651f6339e9eda0 /python/lilliput.py | |
| parent | d7830279e9545b420e4cc0f4b810675df728e98f (diff) | |
| download | lilliput-ae-implem-1870b1eadf3963f9ec5d52bed21f04e523933612.tar.xz | |
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 (limited to 'python/lilliput.py')
| -rw-r--r-- | python/lilliput.py | 26 |
1 files changed, 14 insertions, 12 deletions
diff --git a/python/lilliput.py b/python/lilliput.py index e090a10..6a2aae4 100644 --- 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() |
