From 38bd7fd978a07cccdd99b5ac4bbd2101374476a3 Mon Sep 17 00:00:00 2001 From: Kyle Swanson Date: Tue, 14 May 2019 20:23:10 -0400 Subject: [PATCH] Restructing package --- README.md | 12 +++++-- damgard_jurik/__init__.py | 3 ++ .../damgard_jurik.py => crypto.py} | 2 +- damgard_jurik/damgard_jurik/__init__.py | 6 ---- .../{damgard_jurik => }/prime_gen.py | 0 damgard_jurik/setup.py | 27 --------------- damgard_jurik/{damgard_jurik => }/shamir.py | 5 +-- damgard_jurik/{damgard_jurik => }/utils.py | 0 setup.py | 34 +++++++++++++++++++ tests/test.py | 2 +- 10 files changed, 51 insertions(+), 40 deletions(-) create mode 100644 damgard_jurik/__init__.py rename damgard_jurik/{damgard_jurik/damgard_jurik.py => crypto.py} (99%) delete mode 100644 damgard_jurik/damgard_jurik/__init__.py rename damgard_jurik/{damgard_jurik => }/prime_gen.py (100%) delete mode 100644 damgard_jurik/setup.py rename damgard_jurik/{damgard_jurik => }/shamir.py (97%) rename damgard_jurik/{damgard_jurik => }/utils.py (100%) create mode 100644 setup.py diff --git a/README.md b/README.md index 24862a0..639d1dd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Damgard-Jurik -An implementation of the [Damgard-Jurik](https://people.csail.mit.edu/rivest/voting/papers/DamgardJurikNielsen-AGeneralizationOfPailliersPublicKeySystemWithApplicationsToElectronicVoting.pdf) multi-authority, homomorphic encryption cryptosystem. +An implementation of the threshold variant of the [Damgard-Jurik](https://people.csail.mit.edu/rivest/voting/papers/DamgardJurikNielsen-AGeneralizationOfPailliersPublicKeySystemWithApplicationsToElectronicVoting.pdf) homomorphic encryption cryptosystem. ## Table of Contents @@ -14,10 +14,16 @@ An implementation of the [Damgard-Jurik](https://people.csail.mit.edu/rivest/vot Requires Python 3.6+. +```bash +pip install damgard-jurik +``` + +Alternatively, the code can be cloned and installed locally as follows. + ```bash git clone https://github.com/cryptovoting/damgard-jurik.git cd damgard-jurik -pip install -e damgard_jurik +pip install -e . ``` *Note that the `-e` flag will instruct pip to install the package as "editable". That is, when changes are made to any part of the package during development, those changes will immediately be available system-wide on the activated python environment.* @@ -25,7 +31,7 @@ All requirements for this package should be added to `setup.py`. ## Public and Private Keys -In the multi-authority variant of Damgard-Jurik implemented in this repository, a key pair consists of single public key along with a private key that has been split into multiple components using [Shamir's secret sharing](https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing). The public key encrypts messages while the shares of the private key all contribute a portion of the decryption without ever requiring reconstruction of the private key. Thus, trust is distributed among the holders of the private key shares. +In the threshold variant of Damgard-Jurik implemented in this repository, a key pair consists of single public key along with a private key that has been split into multiple components using [Shamir's secret sharing](https://en.wikipedia.org/wiki/Shamir%27s_Secret_Sharing). The public key encrypts messages while the shares of the private key all contribute a portion of the decryption without ever requiring reconstruction of the private key. Thus, trust is distributed among the holders of the private key shares. In this implementation, the public key is a `PublicKey` object with an encrypt function while the private key shares are `PrivateKeyShare` objects with a decrypt function that performs a partial decryption using that share of the private key. A `PrivateKeyRing` object holds a set of `PrivateKeyShare`s and contains a decrypt function that calls each `PrivateKeyShare`'s decrypt function and combines the results to obtain the final decryption. diff --git a/damgard_jurik/__init__.py b/damgard_jurik/__init__.py new file mode 100644 index 0000000..9f785e0 --- /dev/null +++ b/damgard_jurik/__init__.py @@ -0,0 +1,3 @@ +#!/usr/bin/env python3 + +from damgard_jurik.crypto import EncryptedNumber, PrivateKeyRing, PrivateKeyShare, PublicKey, keygen diff --git a/damgard_jurik/damgard_jurik/damgard_jurik.py b/damgard_jurik/crypto.py similarity index 99% rename from damgard_jurik/damgard_jurik/damgard_jurik.py rename to damgard_jurik/crypto.py index c445472..d99ec05 100644 --- a/damgard_jurik/damgard_jurik/damgard_jurik.py +++ b/damgard_jurik/crypto.py @@ -3,7 +3,7 @@ crypto.py Boucher, Govedič, Saowakon, Swanson 2019 -Contains an implementation of the Damgard-Jurik threshold decryption scheme. +Contains an implementation of the threshold decryption variant of the Damgard-Jurik cryptosystem. """ from functools import lru_cache diff --git a/damgard_jurik/damgard_jurik/__init__.py b/damgard_jurik/damgard_jurik/__init__.py deleted file mode 100644 index c66d8ec..0000000 --- a/damgard_jurik/damgard_jurik/__init__.py +++ /dev/null @@ -1,6 +0,0 @@ -#!/usr/bin/env python3 -import pkgutil - -__path__ = pkgutil.extend_path(__path__, __name__) - -from damgard_jurik.damgard_jurik import EncryptedNumber, PrivateKeyRing, PrivateKeyShare, PublicKey, keygen diff --git a/damgard_jurik/damgard_jurik/prime_gen.py b/damgard_jurik/prime_gen.py similarity index 100% rename from damgard_jurik/damgard_jurik/prime_gen.py rename to damgard_jurik/prime_gen.py diff --git a/damgard_jurik/setup.py b/damgard_jurik/setup.py deleted file mode 100644 index a59dc3e..0000000 --- a/damgard_jurik/setup.py +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env python3 -""" -setup.py -Boucher, Govedič, Saowakon, Swanson 2019 - -Setup script for installation. - -""" -import setuptools - -setuptools.setup( - name="damgard-jurik", - version="0.0.1", - author="Boucher, Govedič, Saowakon, Swanson", - description="Multi-authority, homomorphic encryption using the Damgard-Jurik cryptosystem.", - long_description="Multi-authority, homomorphic encryption using the Damgard-Jurik cryptosystem.", - url="https://github.com/cryptovoting/damgard-jurik", - packages=setuptools.find_packages(), - install_requires=[ - 'gmpy2' - ], - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: MIT License", - "Operating System :: OS Independent", - ] -) diff --git a/damgard_jurik/damgard_jurik/shamir.py b/damgard_jurik/shamir.py similarity index 97% rename from damgard_jurik/damgard_jurik/shamir.py rename to damgard_jurik/shamir.py index 1af26a1..a4135b9 100644 --- a/damgard_jurik/damgard_jurik/shamir.py +++ b/damgard_jurik/shamir.py @@ -1,9 +1,10 @@ #!/usr/bin/env python3 """ -crypto.py +shamir.py Boucher, Govedič, Saowakon, Swanson 2019 -Implementation of Shamir secret sharing. +Contains an implementation of Shamir's secret sharing. + """ from secrets import randbelow from typing import List, Tuple diff --git a/damgard_jurik/damgard_jurik/utils.py b/damgard_jurik/utils.py similarity index 100% rename from damgard_jurik/damgard_jurik/utils.py rename to damgard_jurik/utils.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..34cc56e --- /dev/null +++ b/setup.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +""" +setup.py +Boucher, Govedič, Saowakon, Swanson 2019 + +Setup script for installation. + +""" +import setuptools + + +with open('README.md') as f: + long_description = f.read() + + +setuptools.setup( + name='damgard-jurik', + version='0.0.2', + author='Nicholas Boucher, Luka Govedič, Pasapol Saowakon, Kyle Swanson', + author_email='swansonk.14@gmail.com', + description='Homomorphic encryption using the threshold variant of the Damgard-Jurik cryptosystem.', + long_description=long_description, + long_description_content_type='text/markdown', + url='https://github.com/cryptovoting/damgard-jurik', + packages=setuptools.find_packages(), + install_requires=[ + 'gmpy2' + ], + classifiers=[ + 'Programming Language :: Python :: 3', + 'License :: OSI Approved :: MIT License', + 'Operating System :: OS Independent', + ] +) diff --git a/tests/test.py b/tests/test.py index a31d12c..fbbad51 100644 --- a/tests/test.py +++ b/tests/test.py @@ -3,7 +3,7 @@ test.py Boucher, Govedič, Saowakon, Swanson 2019 -Unit tests for crypto. +Contains unit tests for the damgard-jurik package. """ from secrets import randbelow