From 2cdc379dc0d4a260c5ca20619c892bdfbb6c0248 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Mon, 25 Mar 2019 09:30:23 +0100 Subject: [implem-python] Remplacement de _tweak_tag_end par une concaténation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/add_python/lilliput/ae_mode_2.py | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src/add_python/lilliput/ae_mode_2.py') diff --git a/src/add_python/lilliput/ae_mode_2.py b/src/add_python/lilliput/ae_mode_2.py index 91c53f3..bf09731 100644 --- a/src/add_python/lilliput/ae_mode_2.py +++ b/src/add_python/lilliput/ae_mode_2.py @@ -47,16 +47,6 @@ def _tweak_tag(j, padded): return tweak -def _tweak_tag_end(N): - tweak = [0 for byte in range(0, TWEAK_BYTES)] - - for byte in range(0, TWEAK_BYTES - 1): - tweak[byte] = N[byte] - tweak[TWEAK_BYTES - 1] = 0x10 - - return tweak - - def _add_tag_j(tag, j): array_j = [0 for byte in range(0, TWEAK_BYTES)] for byte in range(0, TWEAK_BYTES): @@ -87,7 +77,7 @@ def _message_auth_tag(M, N, Auth, key): encryption = tbc.encrypt(tweak, key, m_padded) tag = xor(tag, encryption) - tweak = _tweak_tag_end(N) + tweak = N + [0b00010000] encryption = tbc.encrypt(tweak, key, tag) tag = encryption @@ -103,13 +93,13 @@ def _message_encryption(M, N, tag, key): for j in range(0, l): tweak = _add_tag_j(tag, j) - padded_nonce = list(N) + [0x00] + padded_nonce = N + [0b00000000] encryption = tbc.encrypt(tweak, key, padded_nonce) C.append(xor(M[j], encryption)) if need_padding: tweak = _add_tag_j(tag, l) - padded_nonce = list(N) + [0x00] + padded_nonce = N + [0b00000000] encryption = tbc.encrypt(tweak, key, padded_nonce) C.append(xor(M[l], encryption)) @@ -119,6 +109,7 @@ def _message_encryption(M, N, tag, key): ################################################################################ def encrypt(A, M, N, key): K = list(key) + N = list(N) Auth = build_auth(TWEAK_BITS, A, K) tag = _message_auth_tag(M, N, Auth, K) @@ -129,6 +120,7 @@ def encrypt(A, M, N, key): def decrypt(A, C, N, tag, key): K = list(key) + N = list(N) tag = list(tag) M = block_matrix_to_bytes( -- cgit v1.2.3