lilliput-ae-reference-implementation

Implementations of Lilliput-AE submitted to the NIST LWC standardization process
git clone https://git.kevinlegouguec.net/lilliput-ae-reference-implementation
Log | Files | Refs | README

commit fc64da017336c553a345fdb690a2e496a4aefff3
parent 5949f01e728c11990280f6b1d1a35c2153db4578
Author: Kévin Le Gouguec <kevin.legouguec@airbus.com>
Date:   Mon, 25 Mar 2019 10:59:24 +0100

[implem-python] Ajustements dans _tweak_message

Hopefully, le  résultat est  plus clair en  construisant le  tweak par
concaténations progressives.

Diffstat:
Msrc/add_python/lilliput/ae_mode_1.py | 26+++++++++++++++-----------
1 file 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 @@ -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):