changeset 1093:af545b802fd8

Small optimization: Use lin_comb() in byte_sub().
author Marcel Keller <mkeller@cs.au.dk>
date Tue, 27 Jan 2009 14:26:49 +0100
parents d20cb1435966
children bdab6f30511a
files viff/aes.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/viff/aes.py	Mon Jan 26 10:58:27 2009 +0100
+++ b/viff/aes.py	Tue Jan 27 14:26:49 2009 +0100
@@ -86,7 +86,7 @@
                 [0,0,1,1,1,1,1,0],
                 [0,0,0,1,1,1,1,1]])
 
-    def byte_sub(self, state):
+    def byte_sub(self, state, use_lin_comb=True):
         """ByteSub operation of Rijndael.
 
         The first argument should be a matrix consisting of elements
@@ -150,8 +150,12 @@
                 vector = AES.A * Matrix(zip(bits)) + Matrix(zip([1,1,0,0,0,1,1,0]))
                 bits = zip(*vector.rows)[0]
 
-                row[i] = reduce(lambda x,y: x + y, 
-                                [bits[j] * 2**j for j in range(len(bits))])
+                if (use_lin_comb):
+                    row[i] = self.runtime.lin_comb(
+                        [2**j for j in range(len(bits))], bits)
+                else:
+                    row[i] = reduce(lambda x,y: x + y, 
+                                    [bits[j] * 2**j for j in range(len(bits))])
 
     def shift_row(self, state):
         """AES ShiftRow.