changeset 1134:56d259ed2a3d

Added option to do AES encryption at once instead of in rounds.
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 16 Feb 2009 19:32:31 +0100
parents 50056a810951
children c47c7f119808
files viff/aes.py
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/viff/aes.py	Fri Jan 30 14:50:47 2009 +0100
+++ b/viff/aes.py	Mon Feb 16 19:32:31 2009 +0100
@@ -269,7 +269,7 @@
                     "or of shares thereof."
             return input
 
-    def encrypt(self, cleartext, key, benchmark=False):
+    def encrypt(self, cleartext, key, benchmark=False, prepare_at_once=False):
         """Rijndael encryption.
 
         Cleartext and key should be either a string or a list of bytes 
@@ -329,12 +329,13 @@
             self.mix_column(state)
             self.add_round_key(state, expanded_key[i*self.n_b:(i+1)*self.n_b])
 
-            get_last(state).addCallback(progress, i, time.time())
+            if (not prepare_at_once):
+                get_last(state).addCallback(progress, i, time.time())
 
-            if (i < self.rounds - 1):
-                get_trigger(state).addCallback(round, state, i + 1)
-            else:
-                get_trigger(state).addCallback(final_round, state)
+                if (i < self.rounds - 1):
+                    get_trigger(state).addCallback(round, state, i + 1)
+                else:
+                    get_trigger(state).addCallback(final_round, state)
 
             prep_progress(i, start_round)
 
@@ -367,7 +368,14 @@
 
             return _
 
-        round(None, state, 1)
+        result = [Share(self.runtime, GF256) for i in xrange(4 * self.n_b)]
 
-        result = [Share(self.runtime, GF256) for i in xrange(4 * self.n_b)]
+        if (prepare_at_once):
+            for i in range(1, self.rounds):
+                round(None, state, i)
+
+            final_round(None, state)
+        else:
+            round(None, state, 1)
+
         return result