## viff

### changeset 1081:e3b5d98cdbda

Compute every round directly after its preparation in AES encryption.
author Marcel Keller Wed, 14 Jan 2009 18:16:47 +0100 8d946965e46f c1b3ced5bf05 viff/aes.py 1 files changed, 38 insertions(+), 10 deletions(-) [+]
line diff
```     1.1 --- a/viff/aes.py	Tue Jan 13 19:00:40 2009 +0100
1.2 +++ b/viff/aes.py	Wed Jan 14 18:16:47 2009 +0100
1.3 @@ -231,7 +231,7 @@
1.4          start = time.time()
1.5
1.6          def progress(x, i):
1.7 -            print "Round %2d: %f" % (i, time.time() - start)
1.8 +            print "Round %d: %f" % (i, time.time() - start)
1.9              return x
1.10
1.11          expanded_key = self.key_expansion(key)
1.12 @@ -240,22 +240,50 @@
1.13
1.15
1.17 +        def get_trigger(state):
1.18 +            return state[3][self.n_b-1]
1.19
1.20 -        for i in xrange(1, self.rounds):
1.22 +
1.23 +        def round(_, state, i):
1.24              self.byte_sub(state)
1.25              self.shift_row(state)
1.26              self.mix_column(state)
1.28
1.31 +
1.32 +            if (i < self.rounds - 1):
1.33 +                get_trigger(state).addCallback(round, state, i + 1)
1.34 +            else:
1.36 +
1.37              print "Round %d preparation: %f" % (i, time.time() - start)
1.38
1.39 -        self.byte_sub(state)
1.40 -        self.shift_row(state)
1.42 +            return _
1.43
1.45 -        print "Preparation: %f" % (time.time() - start)
1.46 +        def final_round(_, state):
1.47 +            self.byte_sub(state)
1.48 +            self.shift_row(state)
1.50
1.51 -        return [byte for word in zip(*state) for byte in word]
1.53 +
1.55 +
1.56 +            print "Round %d preparation: %f" % (self.rounds, time.time() - start)
1.57 +
1.58 +            return _
1.59 +
1.60 +        def finish(_, state):
1.61 +            actual_result = [byte for word in zip(*state) for byte in word]
1.62 +
1.63 +            for a, b in zip(actual_result, result):