http://hg.viff.dk/viff/rev/d0c7ced69d2d
changeset: 1080:d0c7ced69d2d
user:      Marcel Keller <[email protected]>
date:      Wed Jan 14 17:39:31 2009 +0100
summary:   Added option to control benchmarking to AES encryption.

diffstat:

1 file changed, 17 insertions(+), 12 deletions(-)
viff/aes.py |   29 +++++++++++++++++------------

diffs (64 lines):

diff -r 8d946965e46f -r d0c7ced69d2d viff/aes.py
--- a/viff/aes.py       Tue Jan 13 19:00:40 2009 +0100
+++ b/viff/aes.py       Wed Jan 14 17:39:31 2009 +0100
@@ -212,7 +212,7 @@
                     "or of shares thereof."
             return input
 
-    def encrypt(self, cleartext, key):
+    def encrypt(self, cleartext, key, benchmark=False):
         """Rijndael encryption.
 
         Cleartext and key should be either a string or a list of bytes 
@@ -227,20 +227,23 @@
         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()
+        if (benchmark):
+            import time
+            start = time.time()
 
-        def progress(x, i):
-            print "Round %2d: %f" % (i, time.time() - start)
-            return x
+            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)
+        if (benchmark):
+            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)
+        if (benchmark):
+            state[0][0].addCallback(progress, 0)
 
         for i in xrange(1, self.rounds):
             self.byte_sub(state)
@@ -248,14 +251,16 @@
             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)
+            if (benchmark):
+                state[0][0].addCallback(progress, i)
+                print "Round %2d 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)
+        if (benchmark):
+            state[0][0].addCallback(progress, self.rounds)
+            print "Preparation: %f" % (time.time() - start)
 
         return [byte for word in zip(*state) for byte in word]
_______________________________________________
viff-commits mailing list
[email protected]
http://lists.viff.dk/listinfo.cgi/viff-commits-viff.dk

Reply via email to