viff

changeset 1369:7115ba16f72a

Orlandi: Uniform format for Paillier keys.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 29 Oct 2009 13:46:21 +0100
parents 4306568ab9c6
children d93acdb61f34
files viff/orlandi.py viff/paillier.py viff/paillierutil.py
diffstat 3 files changed, 16 insertions(+), 14 deletions(-) [+]
line diff
     1.1 --- a/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
     1.2 +++ b/viff/orlandi.py	Thu Oct 29 13:46:21 2009 +0100
     1.3 @@ -877,7 +877,7 @@
     1.4              pc = tuple(self.program_counter)
     1.5              p3 = field.modulus**3
     1.6              for pi in self.players.keys():
     1.7 -                n = self.players[pi].pubkey[0]
     1.8 +                n = self.players[pi].pubkey['n']
     1.9                  nsq = n * n
    1.10                  # choose random d_i,j in Z_p^3
    1.11                  dij = random_number(p3)
    1.12 @@ -915,9 +915,9 @@
    1.13          r2 = random_number(field.modulus)
    1.14  
    1.15          # compute alpha_i = Enc_eki(a_i)
    1.16 -        n, g = self.players[self.id].pubkey
    1.17 -        alpha_randomness = rand.randint(1, long(n))
    1.18 -        alphai = encrypt_r(ai.value, alpha_randomness, (n, g))
    1.19 +        pubkey = self.players[self.id].pubkey
    1.20 +        alpha_randomness = rand.randint(1, long(pubkey['n']))
    1.21 +        alphai = encrypt_r(ai.value, alpha_randomness, pubkey)
    1.22          # and A_i = Com_ck(a_i, r_i).
    1.23          Ai = commitment.commit(ai.value, r1.value, r2.value)
    1.24  
    1.25 @@ -1136,7 +1136,7 @@
    1.26                  # 3) the gammaij he received is equal to the gammaij
    1.27                  # he now computes based on the values he reveives
    1.28                  for j in xrange(len(ais)):
    1.29 -                    n = self.players[self.id].pubkey[0]
    1.30 +                    n = self.players[self.id].pubkey['n']
    1.31                      nsq = n * n
    1.32                      dij = dijs[j]
    1.33                      # 5) ... and dij < p^3.
     2.1 --- a/viff/paillier.py	Thu Oct 29 13:46:21 2009 +0100
     2.2 +++ b/viff/paillier.py	Thu Oct 29 13:46:21 2009 +0100
     2.3 @@ -52,20 +52,25 @@
     2.4          g = rand.randint(1, long(nsq))
     2.5          if gmpy.gcd(L(pow(g, lm, nsq), n), n) == 1: break
     2.6  
     2.7 -    return (n, g), (n, g, lm)
     2.8 +    return {'n':n, 'g': g}, {'n': n, 'g': g, 'lm': lm}
     2.9  
    2.10 -def encrypt(m, (n, g)):
    2.11 -    r = rand.randint(1, long(n))
    2.12 -    return encrypt_r(m, r, (n, g))
    2.13 +def encrypt(m, pubkey):
    2.14 +    r = rand.randint(1, long(pubkey['n']))
    2.15 +    return encrypt_r(m, r, pubkey)
    2.16  
    2.17 -def encrypt_r(m, r, (n, g)):
    2.18 +def encrypt_r(m, r, pubkey):
    2.19 +    n = pubkey['n']
    2.20 +    g = pubkey['g']
    2.21      nsq = n*n
    2.22      return (pow(g, m, nsq)*pow(r, n, nsq)) % nsq
    2.23  
    2.24  #: Cache for ciphertext-independent factors.
    2.25  _decrypt_factors = {}
    2.26  
    2.27 -def decrypt(c, (n, g, lm)):
    2.28 +def decrypt(c, seckey):
    2.29 +    n = seckey['n']
    2.30 +    g = seckey['g']
    2.31 +    lm = seckey['lm']
    2.32      numer = L(pow(c, lm, n*n), n)
    2.33      key = (n, g, lm)
    2.34      try:
     3.1 --- a/viff/paillierutil.py	Thu Oct 29 13:46:21 2009 +0100
     3.2 +++ b/viff/paillierutil.py	Thu Oct 29 13:46:21 2009 +0100
     3.3 @@ -53,9 +53,6 @@
     3.4      
     3.5  
     3.6  def deserializer(paillier_type, str):
     3.7 -    if paillier_type == "viff":
     3.8 -        return tuple(map(long, str))
     3.9 -    if paillier_type == "nacl":
    3.10          d = {}
    3.11          for k, v in str.items():
    3.12              d[k] = long(v)