diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-14 12:38:36 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-21 14:49:15 +0100 |
| commit | 02eb0c9f257435595889d15577e4641b2242d0a1 (patch) | |
| tree | d919592bd4632d23a8d13ec291a0812d4d0b93d7 /python/lilliput_ae_2.py | |
| parent | d8eeb99d9106b93c0a30e3ab8849d7687d2a6f29 (diff) | |
| download | lilliput-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_2.py')
| -rw-r--r-- | python/lilliput_ae_2.py | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/python/lilliput_ae_2.py b/python/lilliput_ae_2.py index 40ee485..757088d 100644 --- a/python/lilliput_ae_2.py +++ b/python/lilliput_ae_2.py @@ -3,6 +3,8 @@ """ import lilliput_tbc as ltbc +from helpers import ArrayToBlockbytesMatrix, BlockbytesMatrixToBytes + BLOCK_BITS = 128 KEY_BITS = 128 @@ -215,14 +217,17 @@ def MessageEncryption(M, N, tag, key) : return C ################################################################################ -def SCT2Enc(A, M, N, associated_data_length_bit, message_length_bit, key, key_bits, tweak_bits, rounds) : - InitParameters(key_bits, tweak_bits, rounds) +def SCT2Enc(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 @@ -243,16 +248,20 @@ def SCT2Enc(A, M, N, associated_data_length_bit, message_length_bit, key, key_bi tag = MesssageAuthTag(M, N, Auth, key) C = MessageEncryption(M, N, tag, key) - return (C, tag) + return BlockbytesMatrixToBytes(C), bytes(tag) -def SCT2Dec(A, C, N, tag, associated_data_length_bit, message_length_bit, key, key_bits, tweak_bits, rounds) : - InitParameters(key_bits, tweak_bits, rounds) + +def SCT2Dec(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 @@ -274,4 +283,4 @@ def SCT2Dec(A, C, N, tag, associated_data_length_bit, message_length_bit, key, k tag2 = MesssageAuthTag(M, N, Auth, key) if(tag == tag2) : - return M + return BlockbytesMatrixToBytes(M) |
