summaryrefslogtreecommitdiff
path: root/python/lilliput_ae_1.py
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-14 12:38:36 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-21 14:49:15 +0100
commit02eb0c9f257435595889d15577e4641b2242d0a1 (patch)
treed919592bd4632d23a8d13ec291a0812d4d0b93d7 /python/lilliput_ae_1.py
parentd8eeb99d9106b93c0a30e3ab8849d7687d2a6f29 (diff)
downloadlilliput-ae-implem-02eb0c9f257435595889d15577e4641b2242d0a1.tar.xz
[implem-python] Suppression de paramètres redondants
Création d'un nouveau module "helpers" qui contiendra les fonctions utilisées par les deux modes.
Diffstat (limited to 'python/lilliput_ae_1.py')
-rw-r--r--python/lilliput_ae_1.py28
1 files changed, 18 insertions, 10 deletions
diff --git a/python/lilliput_ae_1.py b/python/lilliput_ae_1.py
index cd7fc82..3629fec 100644
--- a/python/lilliput_ae_1.py
+++ b/python/lilliput_ae_1.py
@@ -3,6 +3,8 @@
"""
import lilliput_tbc as ltbc
+from helpers import ArrayToBlockbytesMatrix, BlockbytesMatrixToBytes
+
BLOCK_BITS = 128
KEY_BITS = 128
@@ -219,14 +221,17 @@ def TreatMessageDec(C, N, key) :
################################################################################
-def OCB3Enc(A, M, N, associated_data_length_bit, message_length_bit, key, key_bits, tweak_bits, rounds) :
- InitParameters(key_bits, tweak_bits, rounds)
+def OCB3Enc(A, M, N, key, tweak_bits, rounds) :
+ InitParameters(len(key)*8, tweak_bits, rounds)
global A_BITS
global M_BITS
- A_BITS = associated_data_length_bit
- M_BITS = message_length_bit
+ A_BITS = len(A)*8
+ M_BITS = len(M)*8
+
+ A = ArrayToBlockbytesMatrix(A)
+ M = ArrayToBlockbytesMatrix(M)
ltbc.KEY_BITS = KEY_BITS
ltbc.ROUNDS = ROUNDS
@@ -247,17 +252,20 @@ def OCB3Enc(A, M, N, associated_data_length_bit, message_length_bit, key, key_bi
(Final, C) = TreatMessageEnc(M, N, key)
tag = XorState(Auth, Final)
- return (C, tag)
+ return BlockbytesMatrixToBytes(C), bytes(tag)
-def OCB3Dec(A, C, N, tag, associated_data_length_bit, message_length_bit, key, key_bits, tweak_bits, rounds) :
- InitParameters(key_bits, tweak_bits, rounds)
+def OCB3Dec(A, C, N, tag, key, tweak_bits, rounds) :
+ InitParameters(len(key)*8, tweak_bits, rounds)
global A_BITS
global M_BITS
- A_BITS = associated_data_length_bit
- M_BITS = message_length_bit
+ A_BITS = len(A)*8
+ M_BITS = len(C)*8
+
+ A = ArrayToBlockbytesMatrix(A)
+ C = ArrayToBlockbytesMatrix(C)
ltbc.KEY_BITS = KEY_BITS
ltbc.ROUNDS = ROUNDS
@@ -278,4 +286,4 @@ def OCB3Dec(A, C, N, tag, associated_data_length_bit, message_length_bit, key, k
tag2 = XorState(Auth, Final)
if(tag == tag2) :
- return M
+ return BlockbytesMatrixToBytes(M)