commit b34ff4d15c914b726dd3fee77eaff95fa54eb61f
parent e97de0e2c0fe92048185fa5ea1f3e23db1fa2b85
Author: Kévin Le Gouguec <kevin.legouguec@airbus.com>
Date: Tue, 2 Jul 2019 17:12:10 +0200
Réécriture de M_R en Python
Diffstat:
1 file changed, 26 insertions(+), 15 deletions(-)
diff --git 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
)