summaryrefslogtreecommitdiff
path: root/src/add_python/lilliput/ae_mode_2.py
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@gmail.com>2019-03-24 14:17:25 +0100
committerKévin Le Gouguec <kevin.legouguec@gmail.com>2019-03-24 14:17:25 +0100
commit1b6e1eb38927633292e934ac314b10e7acc28e3d (patch)
tree6e1570adad2c1efac0dc60652644a1d90d04f9ac /src/add_python/lilliput/ae_mode_2.py
parentfad848887249da22a83e4f35dab3d80f8c590d4d (diff)
downloadlilliput-ae-implem-1b6e1eb38927633292e934ac314b10e7acc28e3d.tar.xz
[implem-python] Conformité PEP8
Surtout la capitalisation des noms de fonction. Retrait des lignes de '#' ; si il y a des séparations à faire, autant ajouter des modules. Correction de _MessageTweak.BLOCK en passant.
Diffstat (limited to 'src/add_python/lilliput/ae_mode_2.py')
-rw-r--r--src/add_python/lilliput/ae_mode_2.py62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/add_python/lilliput/ae_mode_2.py b/src/add_python/lilliput/ae_mode_2.py
index fb6feff..4d5e499 100644
--- a/src/add_python/lilliput/ae_mode_2.py
+++ b/src/add_python/lilliput/ae_mode_2.py
@@ -20,12 +20,12 @@ using Lilliput-AE's nonce-misuse-resistant mode based on SCT-2.
from .constants import BLOCK_BYTES
from .helpers import (
- ArrayToBlockbytesMatrix,
- BlockbytesMatrixToBytes,
- BuildAuth,
- Padding10LSB,
+ bytes_to_block_matrix,
+ block_matrix_to_bytes,
+ build_auth,
+ pad10,
TagValidationError,
- XorState
+ xor_state
)
from . import tbc
@@ -34,7 +34,7 @@ TWEAK_BITS = 128
TWEAK_BYTES = TWEAK_BITS//8
-def _TweakTag(j, padded):
+def _tweak_tag(j, padded):
tweak = [0 for byte in range(0, TWEAK_BYTES)]
tweak[TWEAK_BYTES - 1] |= ((j >> 120) & 0xf)
@@ -47,7 +47,7 @@ def _TweakTag(j, padded):
return tweak
-def _TweakTagEnd(N):
+def _tweak_tag_end(N):
tweak = [0 for byte in range(0, TWEAK_BYTES)]
for byte in range(0, TWEAK_BYTES - 1):
@@ -57,61 +57,61 @@ def _TweakTagEnd(N):
return tweak
-def _AddTagJ(tag, j):
+def _add_tag_j(tag, j):
array_j = [0 for byte in range(0, TWEAK_BYTES)]
for byte in range(0, TWEAK_BYTES):
array_j[byte] = (j >> (byte * 8))
- xorr = XorState(tag, array_j)
+ xorr = xor_state(tag, array_j)
xorr[TWEAK_BYTES - 1] |= 0x80
return xorr
-def _MesssageAuthTag(M, N, Auth, key):
+def _message_auth_tag(M, N, Auth, key):
l = len(M)//BLOCK_BYTES
need_padding = len(M)%BLOCK_BYTES > 0
tag = list(Auth)
- M = ArrayToBlockbytesMatrix(M)
+ M = bytes_to_block_matrix(M)
for j in range(0, l):
- tweak = _TweakTag(j, False)
+ tweak = _tweak_tag(j, False)
encryption = tbc.encrypt(tweak, key, M[j])
- tag = XorState(tag, encryption)
+ tag = xor_state(tag, encryption)
if need_padding:
- tweak = _TweakTag(l, True)
- m_padded = Padding10LSB(M[l])
+ tweak = _tweak_tag(l, True)
+ m_padded = pad10(M[l])
encryption = tbc.encrypt(tweak, key, m_padded)
- tag = XorState(tag, encryption)
+ tag = xor_state(tag, encryption)
- tweak = _TweakTagEnd(N)
+ tweak = _tweak_tag_end(N)
encryption = tbc.encrypt(tweak, key, tag)
tag = encryption
return tag
-def _MessageEncryption(M, N, tag, key):
+def _message_encryption(M, N, tag, key):
l = len(M)//BLOCK_BYTES
need_padding = len(M)%BLOCK_BYTES > 0
- M = ArrayToBlockbytesMatrix(M)
+ M = bytes_to_block_matrix(M)
C = []
for j in range(0, l):
- tweak = _AddTagJ(tag, j)
+ tweak = _add_tag_j(tag, j)
padded_nonce = list(N) + [0x00]
encryption = tbc.encrypt(tweak, key, padded_nonce)
- C.append(XorState(M[j], encryption))
+ C.append(xor_state(M[j], encryption))
if need_padding:
- tweak = _AddTagJ(tag, l)
+ tweak = _add_tag_j(tag, l)
padded_nonce = list(N) + [0x00]
encryption = tbc.encrypt(tweak, key, padded_nonce)
- C.append(XorState(M[l], encryption))
+ C.append(xor_state(M[l], encryption))
return C
@@ -120,22 +120,22 @@ def _MessageEncryption(M, N, tag, key):
def encrypt(A, M, N, key):
K = list(key)
- Auth = BuildAuth(TWEAK_BITS, A, K)
- tag = _MesssageAuthTag(M, N, Auth, K)
- C = _MessageEncryption(M, N, tag, K)
+ Auth = build_auth(TWEAK_BITS, A, K)
+ tag = _message_auth_tag(M, N, Auth, K)
+ C = _message_encryption(M, N, tag, K)
- return BlockbytesMatrixToBytes(C), bytes(tag)
+ return block_matrix_to_bytes(C), bytes(tag)
def decrypt(A, C, N, tag, key):
K = list(key)
tag = list(tag)
- M = BlockbytesMatrixToBytes(
- _MessageEncryption(C, N, tag, K)
+ M = block_matrix_to_bytes(
+ _message_encryption(C, N, tag, K)
)
- Auth = BuildAuth(TWEAK_BITS, A, K)
- tag2 = _MesssageAuthTag(M, N, Auth, K)
+ Auth = build_auth(TWEAK_BITS, A, K)
+ tag2 = _message_auth_tag(M, N, Auth, K)
if tag != tag2:
raise TagValidationError(tag, tag2)