changeset 1097:50056a810951

Optimization: Use lin_comb() instead of Matrix class in mix_column().
author Marcel Keller <mkeller@cs.au.dk>
date Fri, 30 Jan 2009 14:50:47 +0100
parents 072920ec7f69
children 54a68af0a945 006bdec768e6 87f37eb25159 56d259ed2a3d
files viff/aes.py
diffstat 1 files changed, 9 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/viff/aes.py	Fri Jan 30 14:19:54 2009 +0100
+++ b/viff/aes.py	Fri Jan 30 14:50:47 2009 +0100
@@ -202,14 +202,21 @@
 
     C = Matrix(C)
 
-    def mix_column(self, state):
+    def mix_column(self, state, use_lin_comb=True):
         """Rijndael MixColumn.
 
         Input should be a list of 4 rows."""
 
         assert len(state) == 4, "Wrong state size."
 
-        state[:] = (AES.C * Matrix(state)).rows
+        if (use_lin_comb):
+            columns = zip(*state)
+
+            for i, row in enumerate(state):
+                row[:] = [self.runtime.lin_comb(AES.C.rows[i], column)
+                          for column in columns]
+        else:
+            state[:] = (AES.C * Matrix(state)).rows
 
     def add_round_key(self, state, round_key):
         """Rijndael AddRoundKey.