/rev/71f205befbbb
changeset: 1321:71f205befbbb
user: Marcel Keller <[email protected]>
date: Tue Oct 06 14:18:55 2009 +0200
summary: Optimized local operations in S-box.
diffstat:
viff/aes.py | 36 ++++++++++++++++++------------------
1 files changed, 18 insertions(+), 18 deletions(-)
diffs (58 lines):
diff -r fb09cb799cc8 -r 71f205befbbb viff/aes.py
--- a/viff/aes.py Fri Oct 02 16:39:19 2009 +0200
+++ b/viff/aes.py Tue Oct 06 14:18:55 2009 +0200
@@ -219,14 +219,19 @@
return byte_254
# matrix for byte_sub, the last column is the translation vector
- A = Matrix([[1,0,0,0,1,1,1,1, 1],
- [1,1,0,0,0,1,1,1, 1],
- [1,1,1,0,0,0,1,1, 0],
- [1,1,1,1,0,0,0,1, 0],
- [1,1,1,1,1,0,0,0, 0],
- [0,1,1,1,1,1,0,0, 1],
- [0,0,1,1,1,1,1,0, 1],
- [0,0,0,1,1,1,1,1, 0]])
+ A = Matrix([[1,0,0,0,1,1,1,1],
+ [1,1,0,0,0,1,1,1],
+ [1,1,1,0,0,0,1,1],
+ [1,1,1,1,0,0,0,1],
+ [1,1,1,1,1,0,0,0],
+ [0,1,1,1,1,1,0,0],
+ [0,0,1,1,1,1,1,0],
+ [0,0,0,1,1,1,1,1]])
+
+ # anticipate bit recombination
+ for i, row in enumerate(A.rows):
+ for j in range(len(row)):
+ row[j] *= 2 ** i
def byte_sub(self, state, use_lin_comb=True):
"""ByteSub operation of Rijndael.
@@ -240,21 +245,16 @@
for i in range(len(row)):
bits = bit_decompose(self.invert(row[i]))
- # include the translation in the matrix multiplication
- # (see definition of AES.A)
- bits.append(Share(self.runtime, GF256, GF256(1)))
-
if (use_lin_comb):
- bits = [self.runtime.lin_comb(AES.A.rows[j], bits)
- for j in range(len(bits) - 1)]
- row[i] = self.runtime.lin_comb(
- [2**j for j in range(len(bits))], bits)
+ row[i] = self.runtime.lin_comb(sum(AES.A.rows, []),
+ bits * len(AES.A.rows))
else:
# caution: order is lsb first
vector = AES.A * Matrix(zip(bits))
bits = zip(*vector.rows)[0]
- row[i] = reduce(lambda x,y: x + y,
- [bits[j] * 2**j for j in range(len(bits))])
+ row[i] = sum(bits)
+
+ row[i].addCallback(lambda x: 0x63 + x)
def shift_row(self, state):
"""Rijndael ShiftRow.
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk