summaryrefslogtreecommitdiff
path: root/python/lilliput_tbc.py
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-14 14:21:39 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-21 14:49:15 +0100
commitdc5efdfce750c02d4f3c4b35d5137342002fd78d (patch)
treec3695c51283e0d0b62063a57824d4bd54fd05102 /python/lilliput_tbc.py
parent864e0bc2a83297bbea069f3fcc6cb333dbc2de19 (diff)
downloadlilliput-ae-implem-dc5efdfce750c02d4f3c4b35d5137342002fd78d.tar.xz
[implem-python] Retrait des variables globales de lilliput_tbc
On peut tout déduire de len(tweak) / len(key) ; la seule raison d'utiliser autant de constantes en C est que les tableaux se dégradent en pointeurs, donc c'est où les constantes, où une tétrachiée d'arguments.
Diffstat (limited to 'python/lilliput_tbc.py')
-rw-r--r--python/lilliput_tbc.py61
1 files changed, 21 insertions, 40 deletions
diff --git a/python/lilliput_tbc.py b/python/lilliput_tbc.py
index 515a671..0dbfb31 100644
--- a/python/lilliput_tbc.py
+++ b/python/lilliput_tbc.py
@@ -4,17 +4,6 @@
from constants import BLOCK_BYTES, Sbox
import multiplications
-KEY_BITS = 128
-TWEAK_BITS = 192
-LANE_BITS = 64
-LANE_BYTES = LANE_BITS / 8
-LANES = int((TWEAK_BITS+KEY_BITS) / LANE_BITS)
-
-TWEAKEY_BITS = KEY_BITS + TWEAK_BITS
-KEY_BYTES = int(KEY_BITS / 8)
-TWEAK_BYTES = int(TWEAK_BITS / 8)
-TWEAKEY_BYTES = int(TWEAKEY_BITS / 8)
-
MultiplyM = multiplications.MultiplyM
MultiplyM2 = multiplications.MultiplyM2
MultiplyM3 = multiplications.MultiplyM3
@@ -28,46 +17,38 @@ permutationInv = [13, 9, 14, 8, 10, 11, 12, 15, 4, 5, 3, 1, 2, 6 ,0 ,7]
################################################################################
def BuildTweakey(tweak, key) :
-
- tweakey = [0 for byte in range(0, TWEAKEY_BYTES)]
- for byte in range(0, TWEAK_BYTES) :
- tweakey[byte] = tweak[byte]
-
- for byte in range(0, KEY_BYTES) :
- tweakey[byte + TWEAK_BYTES] = key[byte]
-
- return tweakey
+ return tweak+key
#############################
+def _lane(TK, j):
+ return TK[j*8:(j+1)*8]
+
def RoundTweakeySchedule(tweakey) :
+ p = len(tweakey)//8
# Multiplication
- lanes = [tweakey[word * 8:(word+1) * 8] for word in range(0, LANES)]
- tweakey_multiplied = []
- for word in range(0, LANES) :
- if word == 0 :
- tweakey_multiplied += list(lanes[0])
- elif word == 1 :
- tweakey_multiplied += MultiplyM(lanes[1])
- elif word == 2 :
- tweakey_multiplied += MultiplyM2(lanes[2])
- elif word == 3 :
- tweakey_multiplied += MultiplyM3(lanes[3])
- elif word == 4 :
- tweakey_multiplied += MultiplyMR(lanes[4])
- elif word == 5 :
- tweakey_multiplied += MultiplyMR2(lanes[5])
- elif word == 6 :
- tweakey_multiplied += MultiplyMR3(lanes[6])
-
- return tweakey_multiplied ;
+ alphas = (
+ list, # Identity.
+ MultiplyM,
+ MultiplyM2,
+ MultiplyM3,
+ MultiplyMR,
+ MultiplyMR2,
+ MultiplyMR3
+ )
+
+ return [
+ byte
+ for j in range(p)
+ for byte in alphas[j](_lane(tweakey, j))
+ ]
def SubTweakeyExtract(tweakey, Ci):
subtweakey = [0 for byte in range(0, 8)]
- for byte in range(0, TWEAKEY_BYTES) :
+ for byte in range(len(tweakey)):
subtweakey[byte % 8] ^= tweakey[byte]
subtweakey[0] ^= Ci