changeset 1082:c1b3ced5bf05

Merged.
author Marcel Keller <mkeller@cs.au.dk>
date Wed, 14 Jan 2009 18:33:33 +0100
parents e3b5d98cdbda d0c7ced69d2d
children e530dfcb40cd
files viff/aes.py
diffstat 1 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/viff/aes.py	Wed Jan 14 18:16:47 2009 +0100
+++ b/viff/aes.py	Wed Jan 14 18:33:33 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,16 +227,20 @@
         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 %d: %f" % (i, time.time() - start)
-            return x
+            def progress(x, i):
+                print "Round %2d: %f" % (i, time.time() - start)
+                return x
+        else:
+            progress = lambda x, i: 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])
 
@@ -258,7 +262,8 @@
             else:
                 get_trigger(state).addCallback(final_round, state)
 
-            print "Round %d preparation: %f" % (i, time.time() - start)
+            if (benchmark):
+                print "Round %2d preparation: %f" % (i, time.time() - start)
 
             return _
 
@@ -271,7 +276,9 @@
 
             get_trigger(state).addCallback(finish, state)
 
-            print "Round %d preparation: %f" % (self.rounds, time.time() - start)
+            if (benchmark):
+                print "Round %2d preparation: %f" % (self.rounds, 
+                                                     time.time() - start)
 
             return _