summaryrefslogtreecommitdiff
path: root/src/add_python/lilliput/helpers.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/helpers.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/helpers.py')
-rw-r--r--src/add_python/lilliput/helpers.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/src/add_python/lilliput/helpers.py b/src/add_python/lilliput/helpers.py
index 8677f06..65989d0 100644
--- a/src/add_python/lilliput/helpers.py
+++ b/src/add_python/lilliput/helpers.py
@@ -2,7 +2,7 @@ from .constants import BLOCK_BITS, BLOCK_BYTES
from . import tbc
-def ArrayToBlockbytesMatrix(array):
+def bytes_to_block_matrix(array):
vector = list(array)
blocks_nb = len(vector)//BLOCK_BYTES
@@ -24,20 +24,20 @@ def ArrayToBlockbytesMatrix(array):
return matrix
-def BlockbytesMatrixToBytes(matrix):
+def block_matrix_to_bytes(matrix):
return bytes(byte for block in matrix for byte in block)
-def XorState(state1, state2):
+def xor_state(state1, state2):
return [s1^s2 for (s1, s2) in zip(state1, state2)]
-def Padding10LSB(X):
+def pad10(X):
zeroes = [0] * (BLOCK_BYTES-len(X)-1)
return zeroes + [0b10000000] + X
-def _tweakAssociatedData(t, i, padded):
+def _tweak_associated_data(t, i, padded):
t_bytes = t//8
tweak = [0]*(t_bytes)
@@ -56,25 +56,25 @@ def _tweakAssociatedData(t, i, padded):
return tweak
-def BuildAuth(t, A, key):
+def build_auth(t, A, key):
Auth = [0 for byte in range(0, BLOCK_BYTES)]
l_a = len(A)//BLOCK_BYTES
need_padding = len(A)%BLOCK_BYTES > 0
- A = ArrayToBlockbytesMatrix(A)
+ A = bytes_to_block_matrix(A)
for i in range(0, l_a):
- tweak = _tweakAssociatedData(t, i, padded=False)
+ tweak = _tweak_associated_data(t, i, padded=False)
enc = tbc.encrypt(tweak, key, A[i])
- Auth = XorState(Auth, enc)
+ Auth = xor_state(Auth, enc)
if not need_padding:
return Auth
- tweak = _tweakAssociatedData(t, l_a, padded=True)
- ad_padded = Padding10LSB(A[l_a])
+ tweak = _tweak_associated_data(t, l_a, padded=True)
+ ad_padded = pad10(A[l_a])
enc = tbc.encrypt(tweak, key, ad_padded)
- Auth = XorState(Auth, enc)
+ Auth = xor_state(Auth, enc)
return Auth