summaryrefslogtreecommitdiff
path: root/src/add_python
diff options
context:
space:
mode:
authorKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-02 17:12:10 +0200
committerKévin Le Gouguec <kevin.legouguec@airbus.com>2019-07-02 17:12:10 +0200
commitf501e900de666e13abd552b41d228666f3cdad35 (patch)
tree5b3850bd0862c228afae47d7917470b7cd0f809e /src/add_python
parent2a05449541c783716437403c44b416eb35b38d96 (diff)
downloadlilliput-ae-implem-f501e900de666e13abd552b41d228666f3cdad35.tar.xz
Réécriture de M_R en Python
Diffstat (limited to 'src/add_python')
-rw-r--r--src/add_python/lilliput/multiplications.py41
1 files changed, 26 insertions, 15 deletions
diff --git a/src/add_python/lilliput/multiplications.py b/src/add_python/lilliput/multiplications.py
index c5abdfc..8ca8c7f 100644
--- a/src/add_python/lilliput/multiplications.py
+++ b/src/add_python/lilliput/multiplications.py
@@ -76,24 +76,35 @@ M3 = (
)
-def _multiplication(m):
- def _multiply(x):
- return list(reversed([
- reduce(xor, (mj[i](xi) for i, xi in enumerate(reversed(x))))
- for mj in m
- ]))
-
- return _multiply
+# NB: shift directions are reversed with respect to the specification
+# for powers of M_R, since the specification reverses the byte order
+# for those matrices.
+
+MR = (
+ ( _0, _Id, _0, _0, _0, _0, _0, _0),
+ ( _0, _0, _Id, _0, _0, _0, _0, _0),
+ ( _0, _0, _0, _Id, _Sr(3), _0, _0, _0),
+ ( _0, _0, _0, _0, _Id, _0, _0, _0),
+ ( _0, _0, _0, _0, _0, _Id, _Sl(3), _0),
+ ( _0, _0, _0, _Sl(2), _0, _0, _Id, _0),
+ ( _0, _0, _0, _0, _0, _0, _0, _Id),
+ (_Id, _0, _0, _0, _0, _0, _0, _0),
+)
-def _multiply_MR(lane):
- multiplied_lane = [lane[(byte+1) % 8] for byte in range(0, 8)]
+def _multiplication(m, reverse=True):
+ def ordered(l):
+ if reverse:
+ return list(reversed(list(l)))
+ return l
- multiplied_lane[2] ^= ((lane[4] >> 3) & 0xff)
- multiplied_lane[4] ^= ((lane[6] << 3) & 0xff)
- multiplied_lane[5] ^= ((lane[3] << 2) & 0xff)
+ def _multiply(x):
+ return ordered(
+ reduce(xor, (mj[i](xi) for i, xi in enumerate(ordered(x))))
+ for mj in m
+ )
- return multiplied_lane
+ return _multiply
def _multiply_MR2(lane):
@@ -181,7 +192,7 @@ ALPHAS = (
_multiplication(M),
_multiplication(M2),
_multiplication(M3),
- _multiply_MR,
+ _multiplication(MR, reverse=False),
_multiply_MR2,
_multiply_MR3
)