summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-25 10:59:24 +0100
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-03-25 10:59:24 +0100
commitfc64da017336c553a345fdb690a2e496a4aefff3 (patch)
tree6a27a2d6bcedf0ca75bab1b8bcbc11c20d5f199a /src
parent5949f01e728c11990280f6b1d1a35c2153db4578 (diff)
downloadlilliput-ae-implem-fc64da017336c553a345fdb690a2e496a4aefff3.tar.xz
[implem-python] Ajustements dans _tweak_message
Hopefully, le résultat est plus clair en construisant le tweak par concaténations progressives.
Diffstat (limited to 'src')
-rw-r--r--src/add_python/lilliput/ae_mode_1.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/add_python/lilliput/ae_mode_1.py b/src/add_python/lilliput/ae_mode_1.py
index 23f4c7b..4a40b78 100644
--- a/src/add_python/lilliput/ae_mode_1.py
+++ b/src/add_python/lilliput/ae_mode_1.py
@@ -56,21 +56,25 @@ def _byte_from_nibbles(lower, upper):
return upper<<4 | lower
-def _tweak_message(N, j, padding):
- j = integer_to_byte_array(j, (TWEAK_BITS-NONCE_BITS-4)//8+1)
-
- middle_byte = _byte_from_nibbles(
- _lower_nibble(j[-1]), _lower_nibble(N[0])
- )
-
- shifted_N = [
+def _tweak_message(N, j, prefix):
+ # j is encoded on 68 bits; get 72 and clear the upper 4.
+ j_len = (TWEAK_BITS-NONCE_BITS-4)//8 + 1
+ tweak = integer_to_byte_array(j, j_len)
+ tweak[-1] &= 0b00001111
+
+ # Add nonce.
+ tweak[-1] |= _lower_nibble(N[0]) << 4
+ tweak.extend(
_byte_from_nibbles(_upper_nibble(N[i-1]), _lower_nibble(N[i]))
for i in range(1, NONCE_BITS//8)
- ]
+ )
- last_byte = _byte_from_nibbles(_upper_nibble(N[-1]), padding.value)
+ # Add last nibble from nonce and prefix.
+ tweak.append(
+ _byte_from_nibbles(_upper_nibble(N[-1]), prefix.value)
+ )
- return j[:-1] + [middle_byte] + shifted_N + [last_byte]
+ return tweak
def _treat_message_enc(M, N, key):