changeset 1081:e3b5d98cdbda

Compute every round directly after its preparation in AES encryption.
author Marcel Keller Wed, 14 Jan 2009 18:16:47 +0100 8d946965e46f c1b3ced5bf05 viff/aes.py 1 files changed, 38 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
```--- a/viff/aes.py	Tue Jan 13 19:00:40 2009 +0100
+++ b/viff/aes.py	Wed Jan 14 18:16:47 2009 +0100
@@ -231,7 +231,7 @@
start = time.time()

def progress(x, i):
-            print "Round %2d: %f" % (i, time.time() - start)
+            print "Round %d: %f" % (i, time.time() - start)
return x

expanded_key = self.key_expansion(key)
@@ -240,22 +240,50 @@

+        def get_trigger(state):
+            return state[3][self.n_b-1]

-        for i in xrange(1, self.rounds):
+
+        def round(_, state, i):
self.byte_sub(state)
self.shift_row(state)
self.mix_column(state)

+
+            if (i < self.rounds - 1):
+                get_trigger(state).addCallback(round, state, i + 1)
+            else:
+
print "Round %d preparation: %f" % (i, time.time() - start)

-        self.byte_sub(state)
-        self.shift_row(state)
+            return _

-        print "Preparation: %f" % (time.time() - start)
+        def final_round(_, state):
+            self.byte_sub(state)
+            self.shift_row(state)

-        return [byte for word in zip(*state) for byte in word]
+
+
+            print "Round %d preparation: %f" % (self.rounds, time.time() - start)
+
+            return _
+
+        def finish(_, state):
+            actual_result = [byte for word in zip(*state) for byte in word]
+
+            for a, b in zip(actual_result, result):