commit 2cdc379dc0d4a260c5ca20619c892bdfbb6c0248
parent 0d0ecee46d6e5d47ff390cbaa254bf0d560d504f
Author: Kévin Le Gouguec <kevin.legouguec@airbus.com>
Date: Mon, 25 Mar 2019 09:30:23 +0100
[implem-python] Remplacement de _tweak_tag_end par une concaténation
Diffstat:
1 file changed, 5 insertions(+), 13 deletions(-)
diff --git 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(