summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--python/constants.py1
-rw-r--r--python/lilliput.py6
-rw-r--r--python/lilliput_ae_1.py15
-rw-r--r--python/lilliput_ae_2.py2
4 files changed, 10 insertions, 14 deletions
diff --git a/python/constants.py b/python/constants.py
index 94a3e0e..02bbc1f 100644
--- a/python/constants.py
+++ b/python/constants.py
@@ -1,4 +1,5 @@
BLOCK_BYTES = 16
+NONCE_BYTES = 15
def rounds(key_bits):
diff --git a/python/lilliput.py b/python/lilliput.py
index f6679a8..e92ed5f 100644
--- a/python/lilliput.py
+++ b/python/lilliput.py
@@ -1,8 +1,6 @@
import lilliput_ae_1
import lilliput_ae_2
-
-
-N_BYTES = 15
+from constants import NONCE_BYTES
def _checkInputs(key, nonce):
@@ -11,7 +9,7 @@ def _checkInputs(key, nonce):
if len(key)*8 not in valid_key_lengths:
raise ValueError('invalid key size: {} not in {}'.format(len(key)*8, valid_key_lengths))
- if len(nonce) != N_BYTES:
+ if len(nonce) != NONCE_BYTES:
raise ValueError('nonce must be {}-byte long'.format(N_BYTES))
diff --git a/python/lilliput_ae_1.py b/python/lilliput_ae_1.py
index 688148f..92cfa6e 100644
--- a/python/lilliput_ae_1.py
+++ b/python/lilliput_ae_1.py
@@ -3,7 +3,7 @@
"""
import lilliput_tbc as ltbc
-from constants import rounds
+from constants import NONCE_BYTES, rounds
from helpers import ArrayToBlockbytesMatrix, BlockbytesMatrixToBytes
@@ -22,8 +22,7 @@ TWEAKEY_BYTES = int(TWEAKEY_BITS / 8)
A_BITS = BLOCK_BITS
M_BITS = BLOCK_BITS
-N_BITS = 120
-N_BYTES = int(N_BITS / 8)
+
def InitParameters(key_bits) :
global KEY_BITS
@@ -131,12 +130,12 @@ def BuildAuth(A, key) :
def TweakMessage(N, j, null = 0, padded = 0, final_padded = 0) :
tweak = [0 for byte in range(0, TWEAK_BYTES)]
- for byte in range(N_BYTES - 1, -1, -1) :
- tweak[byte + (TWEAK_BYTES - N_BYTES)] |= (N[byte] & 0xf0) >> 4
- tweak[byte + (TWEAK_BYTES - N_BYTES - 1)] |= (N[byte] & 0x0f) << 4
+ for byte in range(NONCE_BYTES-1, -1, -1) :
+ tweak[byte + (TWEAK_BYTES-NONCE_BYTES)] |= (N[byte] & 0xf0) >> 4
+ tweak[byte + (TWEAK_BYTES-NONCE_BYTES-1)] |= (N[byte] & 0x0f) << 4
- tweak[TWEAK_BYTES - N_BYTES - 1] |= ((j >> 64) & 0xf)
- for byte in range(TWEAK_BYTES - N_BYTES - 2, -1, -1) :
+ tweak[TWEAK_BYTES-NONCE_BYTES-1] |= ((j >> 64) & 0xf)
+ for byte in range(TWEAK_BYTES-NONCE_BYTES-2, -1, -1) :
tweak[byte] = (j >> (8 * byte)) & 0xff
if null == 1 :
diff --git a/python/lilliput_ae_2.py b/python/lilliput_ae_2.py
index d333be2..d072935 100644
--- a/python/lilliput_ae_2.py
+++ b/python/lilliput_ae_2.py
@@ -22,8 +22,6 @@ TWEAKEY_BYTES = int(TWEAKEY_BITS / 8)
A_BITS = BLOCK_BITS
M_BITS = BLOCK_BITS
-N_BITS = 120
-N_BYTES = int(N_BITS / 8)
def InitParameters(key_bits) :