viff

changeset 1134:56d259ed2a3d

Added option to do AES encryption at once instead of in rounds.
author Marcel Keller <mkeller@cs.au.dk>
date Mon, 16 Feb 2009 19:32:31 +0100
parents 50056a810951
children c47c7f119808
files viff/aes.py
diffstat 1 files changed, 16 insertions(+), 8 deletions(-) [+]
line diff
     1.1 --- a/viff/aes.py	Fri Jan 30 14:50:47 2009 +0100
     1.2 +++ b/viff/aes.py	Mon Feb 16 19:32:31 2009 +0100
     1.3 @@ -269,7 +269,7 @@
     1.4                      "or of shares thereof."
     1.5              return input
     1.6  
     1.7 -    def encrypt(self, cleartext, key, benchmark=False):
     1.8 +    def encrypt(self, cleartext, key, benchmark=False, prepare_at_once=False):
     1.9          """Rijndael encryption.
    1.10  
    1.11          Cleartext and key should be either a string or a list of bytes 
    1.12 @@ -329,12 +329,13 @@
    1.13              self.mix_column(state)
    1.14              self.add_round_key(state, expanded_key[i*self.n_b:(i+1)*self.n_b])
    1.15  
    1.16 -            get_last(state).addCallback(progress, i, time.time())
    1.17 +            if (not prepare_at_once):
    1.18 +                get_last(state).addCallback(progress, i, time.time())
    1.19  
    1.20 -            if (i < self.rounds - 1):
    1.21 -                get_trigger(state).addCallback(round, state, i + 1)
    1.22 -            else:
    1.23 -                get_trigger(state).addCallback(final_round, state)
    1.24 +                if (i < self.rounds - 1):
    1.25 +                    get_trigger(state).addCallback(round, state, i + 1)
    1.26 +                else:
    1.27 +                    get_trigger(state).addCallback(final_round, state)
    1.28  
    1.29              prep_progress(i, start_round)
    1.30  
    1.31 @@ -367,7 +368,14 @@
    1.32  
    1.33              return _
    1.34  
    1.35 -        round(None, state, 1)
    1.36 +        result = [Share(self.runtime, GF256) for i in xrange(4 * self.n_b)]
    1.37  
    1.38 -        result = [Share(self.runtime, GF256) for i in xrange(4 * self.n_b)]
    1.39 +        if (prepare_at_once):
    1.40 +            for i in range(1, self.rounds):
    1.41 +                round(None, state, i)
    1.42 +
    1.43 +            final_round(None, state)
    1.44 +        else:
    1.45 +            round(None, state, 1)
    1.46 +
    1.47          return result