diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-14 16:45:35 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-21 14:49:15 +0100 |
| commit | 12585a5a0f2faca9c6ab2490bb50b34450876538 (patch) | |
| tree | cfc1b9156571b2fd2c8964334e62e7ef316508ae /python | |
| parent | 57ccbe8a1589a275d44c0c1de1fe7122f70b105c (diff) | |
| download | lilliput-ae-implem-12585a5a0f2faca9c6ab2490bb50b34450876538.tar.xz | |
[implem-python] Retrait des constantes globales
Et des fonctions d'initialisation. Et d'une fonction non-utilisée dans
le mode SCT-2.
Diffstat (limited to 'python')
| -rw-r--r-- | python/lilliput_ae_1.py | 35 | ||||
| -rw-r--r-- | python/lilliput_ae_2.py | 53 |
2 files changed, 2 insertions, 86 deletions
diff --git a/python/lilliput_ae_1.py b/python/lilliput_ae_1.py index 8cf55bb..9de753c 100644 --- a/python/lilliput_ae_1.py +++ b/python/lilliput_ae_1.py @@ -15,32 +15,9 @@ from helpers import ( ) -KEY_BITS = 128 TWEAK_BITS = 192 -TWEAKEY_BITS = KEY_BITS + TWEAK_BITS -LANE_BITS = 64 -LANES = int((TWEAKEY_BITS) / LANE_BITS) +TWEAK_BYTES = TWEAK_BITS//8 -KEY_BYTES = int(KEY_BITS / 8) -TWEAK_BYTES = int(TWEAK_BITS / 8) -TWEAKEY_BYTES = int(TWEAKEY_BITS / 8) - - -def InitParameters(key_bits) : - global KEY_BITS - global KEY_BYTES - global TWEAKEY_BITS - global TWEAKEY_BYTES - global LANES - - KEY_BITS = key_bits - TWEAKEY_BITS = KEY_BITS + TWEAK_BITS - LANES = int((TWEAKEY_BITS) / LANE_BITS) - KEY_BYTES = int(KEY_BITS / 8) - TWEAKEY_BYTES = int(TWEAKEY_BITS / 8) - - -############################################################################### def LowPart(array, number_bits) : shifted = 0 @@ -64,11 +41,6 @@ def LowPart(array, number_bits) : return lower_part_byte -############################################################################### - - - -################################################################################ class _MessageTweak(Enum): BLOCK = 0b000 @@ -156,11 +128,8 @@ def TreatMessageDec(C, N, key) : return (Final, M) - ################################################################################ def OCB3Enc(A, M, N, key) : - InitParameters(len(key)*8) - K = list(key) Auth = BuildAuth(TWEAK_BITS, A, K) @@ -171,8 +140,6 @@ def OCB3Enc(A, M, N, key) : def OCB3Dec(A, C, N, tag, key) : - InitParameters(len(key)*8) - K = list(key) Auth = BuildAuth(TWEAK_BITS, A, K) diff --git a/python/lilliput_ae_2.py b/python/lilliput_ae_2.py index 720e1aa..cb1d1c4 100644 --- a/python/lilliput_ae_2.py +++ b/python/lilliput_ae_2.py @@ -13,56 +13,9 @@ from helpers import ( ) -KEY_BITS = 128 TWEAK_BITS = 128 -TWEAKEY_BITS = KEY_BITS + TWEAK_BITS -LANE_BITS = 64 -LANES = int((TWEAKEY_BITS) / LANE_BITS) +TWEAK_BYTES = TWEAK_BITS//8 -KEY_BYTES = int(KEY_BITS / 8) -TWEAK_BYTES = int(TWEAK_BITS / 8) -TWEAKEY_BYTES = int(TWEAKEY_BITS / 8) - - -def InitParameters(key_bits) : - global KEY_BITS - global KEY_BYTES - global TWEAKEY_BITS - global TWEAKEY_BYTES - global LANES - - KEY_BITS = key_bits - TWEAKEY_BITS = KEY_BITS + TWEAK_BITS - LANES = int((TWEAKEY_BITS) / LANE_BITS) - KEY_BYTES = int(KEY_BITS / 8) - TWEAKEY_BYTES = int(TWEAKEY_BITS / 8) - - -############################################################################### - -def LowPart(array, number_bits) : - shifted = 0 - for byte in range(0, len(array)) : - shifted |= (array[byte] << (8 * byte)) - - mask = 0 - for bit in range(0, number_bits) : - mask |= (0x1 << bit) - - lower_part = shifted & mask - - will_padd = 0 - if (number_bits % 8) != 0 : - will_padd = 1 - - lower_part_byte = [0 for byte in range(0, int(number_bits / 8) + will_padd)] - for byte in range(0, int(number_bits / 8) + will_padd) : - lower_part_byte[byte] = lower_part & 0xff - lower_part = lower_part >> 8 - - return lower_part_byte - -################################################################################ def TweakTag(j, padded): tweak = [0 for byte in range(0, TWEAK_BYTES)] @@ -146,8 +99,6 @@ def MessageEncryption(M, N, tag, key) : ################################################################################ def SCT2Enc(A, M, N, key) : - InitParameters(len(key)*8) - K = list(key) Auth = BuildAuth(TWEAK_BITS, A, K) @@ -158,8 +109,6 @@ def SCT2Enc(A, M, N, key) : def SCT2Dec(A, C, N, tag, key) : - InitParameters(len(key)*8) - K = list(key) M = BlockbytesMatrixToBytes( |
