viff

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 diff
     1.1 --- a/viff/aes.py	Wed Jan 14 18:16:47 2009 +0100
     1.2 +++ b/viff/aes.py	Wed Jan 14 18:33:33 2009 +0100
     1.3 @@ -212,7 +212,7 @@
     1.4                      "or of shares thereof."
     1.5              return input
     1.6  
     1.7 -    def encrypt(self, cleartext, key):
     1.8 +    def encrypt(self, cleartext, key, benchmark=False):
     1.9          """Rijndael encryption.
    1.10  
    1.11          Cleartext and key should be either a string or a list of bytes 
    1.12 @@ -227,16 +227,20 @@
    1.13          state = [cleartext[i::4] for i in xrange(4)]
    1.14          key = [key[4*i:4*i+4] for i in xrange(self.n_k)]
    1.15  
    1.16 -        import time
    1.17 -        start = time.time()
    1.18 +        if (benchmark):
    1.19 +            import time
    1.20 +            start = time.time()
    1.21  
    1.22 -        def progress(x, i):
    1.23 -            print "Round %d: %f" % (i, time.time() - start)
    1.24 -            return x
    1.25 +            def progress(x, i):
    1.26 +                print "Round %2d: %f" % (i, time.time() - start)
    1.27 +                return x
    1.28 +        else:
    1.29 +            progress = lambda x, i: x
    1.30  
    1.31          expanded_key = self.key_expansion(key)
    1.32  
    1.33 -        print "Key expansion preparation: %f" % (time.time() - start)
    1.34 +        if (benchmark):
    1.35 +            print "Key expansion preparation: %f" % (time.time() - start)
    1.36  
    1.37          self.add_round_key(state, expanded_key[0:self.n_b])
    1.38  
    1.39 @@ -258,7 +262,8 @@
    1.40              else:
    1.41                  get_trigger(state).addCallback(final_round, state)
    1.42  
    1.43 -            print "Round %d preparation: %f" % (i, time.time() - start)
    1.44 +            if (benchmark):
    1.45 +                print "Round %2d preparation: %f" % (i, time.time() - start)
    1.46  
    1.47              return _
    1.48  
    1.49 @@ -271,7 +276,9 @@
    1.50  
    1.51              get_trigger(state).addCallback(finish, state)
    1.52  
    1.53 -            print "Round %d preparation: %f" % (self.rounds, time.time() - start)
    1.54 +            if (benchmark):
    1.55 +                print "Round %2d preparation: %f" % (self.rounds, 
    1.56 +                                                     time.time() - start)
    1.57  
    1.58              return _
    1.59