viff

changeset 1299:050decea7ad4

aes: removed unnecessary if-statement parenthesis
author Martin Geisler <mg@cs.au.dk>
date Fri, 16 Oct 2009 23:54:38 +0200
parents 2e11e0366d58
children c03b8fbef478
files apps/aes.py viff/aes.py
diffstat 2 files changed, 22 insertions(+), 22 deletions(-) [+]
line diff
     1.1 --- a/apps/aes.py	Fri Oct 16 23:45:59 2009 +0200
     1.2 +++ b/apps/aes.py	Fri Oct 16 23:54:38 2009 +0200
     1.3 @@ -111,7 +111,7 @@
     1.4  
     1.5      for i in range(options.keylength / 8):
     1.6          inputter = i % 3 + 1
     1.7 -        if (inputter == id):
     1.8 +        if inputter == id:
     1.9              key.append(rt.input([inputter], GF256, ord("b")))
    1.10          else:
    1.11              key.append(rt.input([inputter], GF256))
     2.1 --- a/viff/aes.py	Fri Oct 16 23:45:59 2009 +0200
     2.2 +++ b/viff/aes.py	Fri Oct 16 23:54:38 2009 +0200
     2.3 @@ -36,7 +36,7 @@
     2.4  
     2.5      r_bits = share.runtime.prss_share_random_multi(GF256, 8, binary=True)
     2.6  
     2.7 -    if (use_lin_comb):
     2.8 +    if use_lin_comb:
     2.9          r = share.runtime.lin_comb([2 ** i for i in range(8)], r_bits)
    2.10      else:
    2.11          r = reduce(lambda x,y: x + y,
    2.12 @@ -90,32 +90,32 @@
    2.13          self.rounds = max(self.n_k, self.n_b) + 6
    2.14          self.runtime = runtime
    2.15  
    2.16 -        if (use_exponentiation is not False):
    2.17 +        if use_exponentiation is not False:
    2.18              if (isinstance(use_exponentiation, int) and
    2.19                  use_exponentiation < len(AES.exponentiation_variants)):
    2.20                  use_exponentiation = \
    2.21                      AES.exponentiation_variants[use_exponentiation]
    2.22 -            elif (use_exponentiation not in AES.exponentation_variants):
    2.23 +            elif use_exponentiation not in AES.exponentation_variants:
    2.24                  use_exponentiation = "shortest_sequential_chain"
    2.25  
    2.26 -            if (not quiet):
    2.27 +            if not quiet:
    2.28                  print "Use %s for inversion by exponentiation." % \
    2.29                      use_exponentiation
    2.30  
    2.31 -            if (use_exponentiation == "standard_square_and_multiply"):
    2.32 +            if use_exponentiation == "standard_square_and_multiply":
    2.33                  self.invert = lambda byte: byte ** 254
    2.34 -            elif (use_exponentiation == "shortest_chain_with_least_rounds"):
    2.35 +            elif use_exponentiation == "shortest_chain_with_least_rounds":
    2.36                  self.invert = self.invert_by_exponentiation_with_less_rounds
    2.37 -            elif (use_exponentiation == "chain_with_least_rounds"):
    2.38 +            elif use_exponentiation == "chain_with_least_rounds":
    2.39                  self.invert = self.invert_by_exponentiation_with_least_rounds
    2.40 -            elif (use_exponentiation == "masked"):
    2.41 +            elif use_exponentiation == "masked":
    2.42                  self.invert = self.invert_by_masked_exponentiation
    2.43              else:
    2.44                  self.invert = self.invert_by_exponentiation
    2.45          else:
    2.46              self.invert = self.invert_by_masking
    2.47  
    2.48 -            if (not quiet):
    2.49 +            if not quiet:
    2.50                  print "Use inversion by masking."
    2.51  
    2.52      exponentiation_variants = ["standard_square_and_multiply",
    2.53 @@ -131,7 +131,7 @@
    2.54              bits[j].addCallback(lambda x: GF256(1) - x)
    2.55  #            bits[j] = 1 - bits[j]
    2.56  
    2.57 -        while(len(bits) > 1):
    2.58 +        while len(bits) > 1:
    2.59              bits.append(bits.pop(0) * bits.pop(0))
    2.60  
    2.61          # b == 1 if byte is 0, b == 0 else
    2.62 @@ -141,7 +141,7 @@
    2.63          c = Share(self.runtime, GF256)
    2.64  
    2.65          def get_masked_byte(c_opened, r_related, c, r, byte):
    2.66 -            if (c_opened == 0):
    2.67 +            if c_opened == 0:
    2.68                  r_trial = self.runtime.prss_share_random(GF256)
    2.69                  c_trial = self.runtime.open((byte + b) * r_trial)
    2.70                  self.runtime.schedule_callback(c_trial, get_masked_byte,
    2.71 @@ -247,7 +247,7 @@
    2.72                  # (see definition of AES.A)
    2.73                  bits.append(Share(self.runtime, GF256, GF256(1)))
    2.74  
    2.75 -                if (use_lin_comb):
    2.76 +                if use_lin_comb:
    2.77                      bits = [self.runtime.lin_comb(AES.A.rows[j], bits)
    2.78                              for j in range(len(bits) - 1)]
    2.79                      row[i] = self.runtime.lin_comb(
    2.80 @@ -294,7 +294,7 @@
    2.81  
    2.82          assert len(state) == 4, "Wrong state size."
    2.83  
    2.84 -        if (use_lin_comb):
    2.85 +        if use_lin_comb:
    2.86              columns = zip(*state)
    2.87  
    2.88              for i, row in enumerate(state):
    2.89 @@ -332,11 +332,11 @@
    2.90          for i in xrange(len(key), self.n_b * (new_length + 1)):
    2.91              temp = list(expanded_key[i - 1])
    2.92  
    2.93 -            if (i % self.n_k == 0):
    2.94 +            if i % self.n_k == 0:
    2.95                  temp.append(temp.pop(0))
    2.96                  self.byte_sub([temp])
    2.97                  temp[0] += GF256(2) ** (i / self.n_k - 1)
    2.98 -            elif (self.n_k > 6 and i % self.n_k == 4):
    2.99 +            elif self.n_k > 6 and i % self.n_k == 4:
   2.100                  self.byte_sub([temp])
   2.101  
   2.102              new_word = []
   2.103 @@ -349,7 +349,7 @@
   2.104          return expanded_key
   2.105  
   2.106      def preprocess(self, input):
   2.107 -        if (isinstance(input, str)):
   2.108 +        if isinstance(input, str):
   2.109              return [Share(self.runtime, GF256, GF256(ord(c)))
   2.110                      for c in input]
   2.111          else:
   2.112 @@ -378,7 +378,7 @@
   2.113          state = [cleartext[i::4] for i in xrange(4)]
   2.114          key = [key[4*i:4*i+4] for i in xrange(self.n_k)]
   2.115  
   2.116 -        if (benchmark):
   2.117 +        if benchmark:
   2.118              global preparation, communication
   2.119              preparation = 0
   2.120              communication = 0
   2.121 @@ -419,11 +419,11 @@
   2.122              self.mix_column(state)
   2.123              self.add_round_key(state, expanded_key[i*self.n_b:(i+1)*self.n_b])
   2.124  
   2.125 -            if (not prepare_at_once):
   2.126 +            if not prepare_at_once:
   2.127                  trigger = get_trigger(state)
   2.128                  trigger.addCallback(progress, i, time.time())
   2.129  
   2.130 -                if (i < self.rounds - 1):
   2.131 +                if i < self.rounds - 1:
   2.132                      self.runtime.schedule_complex_callback(trigger, round, state, i + 1)
   2.133                  else:
   2.134                      self.runtime.schedule_complex_callback(trigger, final_round, state)
   2.135 @@ -444,7 +444,7 @@
   2.136              trigger = get_trigger(state)
   2.137              trigger.addCallback(progress, self.rounds, time.time())
   2.138  
   2.139 -            if (benchmark):
   2.140 +            if benchmark:
   2.141                  trigger.addCallback(finish, state)
   2.142  
   2.143              # connect to final result
   2.144 @@ -463,7 +463,7 @@
   2.145  
   2.146          result = [Share(self.runtime, GF256) for i in xrange(4 * self.n_b)]
   2.147  
   2.148 -        if (prepare_at_once):
   2.149 +        if prepare_at_once:
   2.150              for i in range(1, self.rounds):
   2.151                  round(None, state, i)
   2.152