viff

changeset 1439:6d3dc3f181d3

Compute the fixed base element for NaCl paillier.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Thu, 20 May 2010 10:41:45 +0200
parents 6caded57e489
children 91222852a0a4
files viff/config.py viff/paillierutil.py
diffstat 2 files changed, 25 insertions(+), 9 deletions(-) [+]
line diff
     1.1 --- a/viff/config.py	Thu May 20 10:38:21 2010 +0200
     1.2 +++ b/viff/config.py	Thu May 20 10:41:45 2010 +0200
     1.3 @@ -134,7 +134,7 @@
     1.4          if 'paillier' in config[player]:
     1.5              paillier_type = config[player]['paillier']['type']
     1.6              pub_key = config[player]['paillier']['pubkey']
     1.7 -            pubkey = paillierutil.deserializer(paillier_type, pub_key)
     1.8 +            pubkey = paillierutil.deserializ_pubkey(paillier_type, pub_key)
     1.9          else:
    1.10              # old format
    1.11              pubkey = tuple(map(long, config[player]['pubkey']))
    1.12 @@ -142,7 +142,7 @@
    1.13          if 'prss_keys' in config[player]:
    1.14              if 'paillier' in config[player]:
    1.15                  sec_key = config[player]['paillier']['seckey']
    1.16 -                seckey = paillierutil.deserializer(paillier_type, sec_key)
    1.17 +                seckey = paillierutil.deserializ_seckey(sec_key)
    1.18              else:
    1.19                  # old format
    1.20                  seckey = tuple(map(long, config[player]['seckey']))
     2.1 --- a/viff/paillierutil.py	Thu May 20 10:38:21 2010 +0200
     2.2 +++ b/viff/paillierutil.py	Thu May 20 10:41:45 2010 +0200
     2.3 @@ -22,6 +22,12 @@
     2.4  except ImportError:
     2.5      pypaillier = None
     2.6  
     2.7 +try:
     2.8 +    import tripple
     2.9 +
    2.10 +except ImportError:
    2.11 +    tripple = None
    2.12 +
    2.13  
    2.14  class Paillier:
    2.15  
    2.16 @@ -49,12 +55,22 @@
    2.17          self.type = 'nacl'
    2.18  
    2.19      def generate_keys(self):
    2.20 -        return pypaillier.generate_keys(self.keysize)
    2.21 -    
    2.22 +        return pypaillier.generate_keys(self.keysize)  
    2.23  
    2.24 -def deserializer(paillier_type, str):
    2.25 -        d = {}
    2.26 +def deserializ_seckey(str):
    2.27 +    d = {}
    2.28 +    for k, v in str.items():
    2.29 +        d[k] = long(v)
    2.30 +    return d
    2.31 +
    2.32 +def deserializ_pubkey(paillier_type, str):
    2.33 +        pubkey = {}
    2.34          for k, v in str.items():
    2.35 -            d[k] = long(v)
    2.36 -        return d
    2.37 -        
    2.38 +            pubkey[k] = long(v)
    2.39 +        if paillier_type == "nacl":
    2.40 +            g1 = pypaillier.encrypt_r(1, 1, pubkey)
    2.41 +            pubkey['fixed_base'] = tripple.init(g1, pubkey['n_square'])            
    2.42 +        return pubkey
    2.43 +
    2.44 +
    2.45 +