changeset 1079:8d946965e46f

Added benchmarking output in AES encryption.
author Marcel Keller <mkeller@cs.au.dk>
date Tue, 13 Jan 2009 19:00:40 +0100
parents 395273e73571
children d0c7ced69d2d e3b5d98cdbda
files viff/aes.py
diffstat 1 files changed, 17 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/viff/aes.py	Mon Jan 12 19:22:37 2009 +0100
+++ b/viff/aes.py	Tue Jan 13 19:00:40 2009 +0100
@@ -227,18 +227,35 @@
         state = [cleartext[i::4] for i in xrange(4)]
         key = [key[4*i:4*i+4] for i in xrange(self.n_k)]
 
+        import time
+        start = time.time()
+
+        def progress(x, i):
+            print "Round %2d: %f" % (i, time.time() - start)
+            return x
+
         expanded_key = self.key_expansion(key)
 
+        print "Key expansion preparation: %f" % (time.time() - start)
+
         self.add_round_key(state, expanded_key[0:self.n_b])
 
+        state[0][0].addCallback(progress, 0)
+
         for i in xrange(1, self.rounds):
             self.byte_sub(state)
             self.shift_row(state)
             self.mix_column(state)
             self.add_round_key(state, expanded_key[i*self.n_b:(i+1)*self.n_b])
 
+            state[0][0].addCallback(progress, i)
+            print "Round %d preparation: %f" % (i, time.time() - start)
+
         self.byte_sub(state)
         self.shift_row(state)
         self.add_round_key(state, expanded_key[self.rounds*self.n_b:])
 
+        state[0][0].addCallback(progress, self.rounds)
+        print "Preparation: %f" % (time.time() - start)
+
         return [byte for word in zip(*state) for byte in word]