diff options
Diffstat (limited to 'python')
| -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() |
