viff

changeset 1361:736ad1d97024

Generate_config_files:Added support NaCl implementation of Paillier.
author Janus Dam Nielsen <janus.nielsen@alexandra.dk>
date Wed, 28 Oct 2009 14:53:51 +0100
parents 3fe6e03541c1
children 361aeb2668fc
files apps/generate-config-files.py viff/paillierutil.py
diffstat 2 files changed, 38 insertions(+), 4 deletions(-) [+]
line diff
     1.1 --- a/apps/generate-config-files.py	Wed Oct 28 14:53:49 2009 +0100
     1.2 +++ b/apps/generate-config-files.py	Wed Oct 28 14:53:51 2009 +0100
     1.3 @@ -55,7 +55,17 @@
     1.4  from optparse import OptionParser
     1.5  
     1.6  from viff.config import generate_configs
     1.7 -from viff.paillierutil import ViffPaillier
     1.8 +from viff.paillierutil import ViffPaillier, NaClPaillier
     1.9 +
    1.10 +try:
    1.11 +    import pypaillier
    1.12 +except ImportError:
    1.13 +    pypaillier = None
    1.14 +
    1.15 +paillier_choices = ['viff']
    1.16 +
    1.17 +if pypaillier:
    1.18 +    paillier_choices += ['nacl']
    1.19  
    1.20  parser = OptionParser()
    1.21  parser.add_option("-p", "--prefix",
    1.22 @@ -68,21 +78,27 @@
    1.23                    help="number of players")
    1.24  parser.add_option("-k", "--keysize", type="int",
    1.25                    help="Specify the key-size for Paillier encryption")
    1.26 +parser.add_option("--paillier", type="choice", choices=paillier_choices,
    1.27 +                  help="the implementation of Paillier encryption")
    1.28  parser.add_option("-t", "--threshold", dest="t", type="int",
    1.29                    help="threshold (it must hold that t < n/2)")
    1.30  parser.add_option("--skip-prss", action="store_true",
    1.31                    help="do not generate PRSS keys")
    1.32  
    1.33  parser.set_defaults(verbose=True, n=3, t=1, prefix='player', skip_prss=False,
    1.34 -                    keysize=1024)
    1.35 +                    keysize=1024, paillier='viff')
    1.36  
    1.37  (options, args) = parser.parse_args()
    1.38  
    1.39 +paillier = ViffPaillier(options.keysize)
    1.40 +if "nacl" == options.paillier:
    1.41 +    paillier = NaClPaillier(options.keysize)
    1.42 +
    1.43  if len(args) != options.n:
    1.44      parser.error("must supply a hostname:port argument for each player")
    1.45  
    1.46  addresses = [arg.split(':', 1) for arg in args]
    1.47 -configs = generate_configs(options.n, options.t, ViffPaillier(options.keysize), addresses,
    1.48 +configs = generate_configs(options.n, options.t, paillier, addresses,
    1.49                             options.prefix, options.skip_prss)
    1.50  
    1.51  for config in configs.itervalues():
     2.1 --- a/viff/paillierutil.py	Wed Oct 28 14:53:49 2009 +0100
     2.2 +++ b/viff/paillierutil.py	Wed Oct 28 14:53:51 2009 +0100
     2.3 @@ -17,6 +17,12 @@
     2.4  
     2.5  from viff import paillier
     2.6  
     2.7 +try:
     2.8 +    import pypaillier
     2.9 +except ImportError:
    2.10 +    pypaillier = None
    2.11 +
    2.12 +
    2.13  class Paillier:
    2.14  
    2.15      def __init__(self, keysize):
    2.16 @@ -35,8 +41,20 @@
    2.17  
    2.18      def generate_keys(self):
    2.19          return paillier.generate_keys(self.keysize)
    2.20 +
    2.21 +class NaClPaillier:
    2.22 +
    2.23 +    def __init__(self, keysize):
    2.24 +        self.keysize = keysize
    2.25 +        self.type = 'nacl'
    2.26 +
    2.27 +    def generate_keys(self):
    2.28 +        return pypaillier.generate_keys(self.keysize)
    2.29      
    2.30  
    2.31  def deserializer(paillier_type, str):
    2.32 -    return tuple(map(long, str))
    2.33 +    if paillier_type == "viff":
    2.34 +        return tuple(map(long, str))
    2.35 +    if paillier_type == "nacl":
    2.36 +        return str.dict()
    2.37