diff options
| author | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-21 17:16:21 +0100 |
|---|---|---|
| committer | Kévin Le Gouguec <kevin.legouguec@airbus.com> | 2019-03-21 17:30:38 +0100 |
| commit | 7350fbb6583236b929235a8be7f17f149901f004 (patch) | |
| tree | 77874e80069cd9d29ea3bb00ca172974aec8b026 /python/helpers.py | |
| parent | a3663b7b3bdc092fb0667ea6c16b8e9a6cf4cf73 (diff) | |
| download | lilliput-ae-implem-7350fbb6583236b929235a8be7f17f149901f004.tar.xz | |
[implem-python] Simplification de pad10*
Dans le cadre d'une croisade contre les range(len(…)).
Suppression d'un paramètre inutile dans la foulée.
Diffstat (limited to 'python/helpers.py')
| -rw-r--r-- | python/helpers.py | 23 |
1 files changed, 6 insertions, 17 deletions
diff --git a/python/helpers.py b/python/helpers.py index 07affa9..be4b406 100644 --- a/python/helpers.py +++ b/python/helpers.py @@ -32,19 +32,9 @@ def XorState(state1, state2): return [s1^s2 for (s1, s2) in zip(state1, state2)] -def Padding10LSB(array, number_bits): - shifted = 0 - for byte in range(0, len(array)): - shifted |= (array[byte] << (8 * byte)) - shifted = (shifted << (BLOCK_BITS - number_bits)) & 0xffffffffffffffffffffffffffffffff - - padded = shifted | (0x1 << (BLOCK_BITS - number_bits - 1)) - - array_padded = [0 for byte in range(0, BLOCK_BYTES)] - for byte in range(0, BLOCK_BYTES): - array_padded[byte] = (padded & (0xff << (8 * byte))) >> (8 * byte) - - return array_padded +def Padding10LSB(X): + zeroes = [0] * (BLOCK_BYTES-len(X)-1) + return zeroes + [0b10000000] + X def _tweakAssociatedData(t, i, padded): @@ -69,8 +59,7 @@ def _tweakAssociatedData(t, i, padded): def BuildAuth(t, A, key): Auth = [0 for byte in range(0, BLOCK_BYTES)] l_a = len(A)//BLOCK_BYTES - - padding_bytes = len(A)%BLOCK_BYTES + need_padding = len(A)%BLOCK_BYTES > 0 A = ArrayToBlockbytesMatrix(A) @@ -79,11 +68,11 @@ def BuildAuth(t, A, key): enc = LilliputTBCEnc(tweak, key, A[i]) Auth = XorState(Auth, enc) - if padding_bytes == 0: + if not need_padding: return Auth tweak = _tweakAssociatedData(t, l_a, padded=True) - ad_padded = Padding10LSB(A[l_a], padding_bytes*8) + ad_padded = Padding10LSB(A[l_a]) enc = LilliputTBCEnc(tweak, key, ad_padded) Auth = XorState(Auth, enc) |
