Commit Graph
57 Commits
Author SHA1 Message Date
Piotr Dyraga 21d6230b20 Improved documentation for the safe prime generator 2018-07-26 10:19:20 +02:00
Piotr Dyraga e0b836a4bc Generate safe prime concurrently
How fast we generate a prime number is mostly a matter of luck. It
varies from miliseconds to seconds and depends how lucky we are with
drawing bytes.

With today's multicore processors, we can execute the process on
multiple cores concurrently, accept the first valid result and cancel
the rest of work. This way, with the same algorithm, we get the result
faster.
2018-07-26 08:53:23 +02:00
Piotr Dyraga f5a107a36f Draft implementation of a safe prime generator
I've adapted a Go code for generating random numbers by inserting some
optimisations that will allow us to generate safe primes faster than
with the previous, naive approach.

First of all, having q which can be prime, we first check whether q%3=1.
If that's true, there is no chance p=2q+1 is prime. It lets us to reject
candidate numbers quicker without running an expensive primality tests.

Also, before we run a primality test for q, we may check p=2q+1 against
the primes between 3-53 (We are limited by Go's uint64 range).

If all those conditions are met and we know p is prime, it's enough to
check Pocklington criterion for q instead of running an expensive
primality test for it.
2018-07-25 10:55:49 +02:00
Jakub Nowakowski 3eb21f405c Merge pull request #7 from keep-network/cypher-multiplication
Added support for a Cypher multiplication
2018-07-17 15:27:34 +02:00
Piotr Dyraga c685186ca3 Use Cmp to compare Ints, reflections is just to heavy 2018-07-17 15:20:17 +02:00
Piotr Dyraga f5a4d18889 Added support for a Cypher multiplication
It's now possible to multiply Cypher by an integer.

Paillier is a homomorphic encryption scheme, where an encrypted
plaintext `m` raised to an integer `k` will decrypt to the product of
the plaintext `m` and `k`.
2018-07-17 15:05:59 +02:00
Jakub Nowakowski c9c5d2df02 Merge pull request #6 from keep-network/encrypt-with-randomness
Added EncryptWithR allowing to specify the randomness
2018-07-09 11:08:12 +02:00
Piotr Dyraga cfa2d72bef Added EncryptWithR allowing to specify the randomness
Function `EncryptWithR` lets to specify randomness `r` explicitely. For
some ZKPs based on the Paillier scheme, it's required to use the same
`r` for encryption and constructing ZKP. It wasn't possible previously,
because `r` was generated internally and never returned.

I did not want to modify `Encrypt` to return `r` because it would break
existing code using this API, as well as, I want to make sure person
using the specific `r` and using it somewhere else really knows what
he's doing.
2018-07-09 09:34:09 +02:00
Jakub Nowakowski 715a2097b7 Merge pull request #5 from keep-network/add-cyphers
Let to pass an arbitrary number of cyphers to PublicKey.Add
2018-06-28 15:59:42 +02:00
Piotr Dyraga d439831ffd pub self-reference renamed to pk
We want to use a noun-ish name, not an adjective.
2018-06-28 15:52:26 +02:00
Piotr Dyraga b7abc00044 Test of an additively homomorphic property for a small modulus 2018-06-28 15:47:41 +02:00
Piotr Dyraga 5631d7cca5 Better explanation of an additively homomorphic property 2018-06-28 15:46:45 +02:00
Piotr Dyraga 053ae45b59 Let to pass an arbitrary number of cyphers to PublicKey.Add
`PublicKey.Add` accepts now an arbitrary number of `*Cypher`s.
Previously, it was possible to add only two `*Cypher*` instances and it
was quite unwieldy for a lot of use cases.

The current implementation is backward compatible. It's still possible
to pass just two `*Cypher` arguments, so every project referencing the
library will observe no compilation issues.
2018-06-28 14:28:05 +02:00
pdyraga a18a8243cb Merge pull request #4 from keep-network/extract-bson-wip
Extract BSON/JSON code to separate package
2018-06-21 08:13:38 +02:00
Jakub Nowakowski d331cd9df5 Changed Serializable types names, updates tests names 2018-06-20 12:39:42 +02:00
Jakub Nowakowski e3cb617c60 Splited encoding per object type, added public methods for serialization 2018-06-19 14:49:26 +02:00
Jakub Nowakowski 091f257cd5 Changed names of method's receivers 2018-06-13 14:55:20 -04:00
Jakub Nowakowski d038e085a3 Second round of bson extraction 2018-06-13 11:27:43 -04:00
Jakub Nowakowski c0e04321bb Moved bson to separate package 2018-06-11 19:15:21 +02:00
Matt Luongo 581517debf Merge pull request #3 from keep-network/threshold-rabbit-hole
Threshold Paillier scheme - evaluation and cleanup
2018-06-05 05:10:08 -07:00
Piotr Dyraga 3acf9e6948 Explained how do we handle negative lambda parameter value 2018-06-05 13:11:50 +02:00
Piotr Dyraga ba2c5aaa5f Shortened name of the partial decryption verification function 2018-06-01 21:42:49 +02:00
Piotr Dyraga 9d17da0d33 ThresholdKey renamed to ThresholdPublicKey 2018-06-01 21:36:04 +02:00
Piotr Dyraga 86b9f01f99 PartialDecryptionZKP self-ref renamed from this to pd 2018-06-01 21:31:04 +02:00
Piotr Dyraga 3f301a765d ThresholdPrivateKey self-ref renamed from this to tpk 2018-06-01 21:29:43 +02:00
Piotr Dyraga 00f21c0b6f ThresholdKey self-ref renamed from this to tk 2018-06-01 21:28:13 +02:00
Piotr Dyraga df9231e7b2 ThresholdKeyGenerator self-ref renamed from this to tkg 2018-06-01 20:51:15 +02:00
Piotr Dyraga bb8c3928d2 Explained how Fiat-Shamir heuristic works on a high level 2018-06-01 20:45:22 +02:00
Piotr Dyraga e43575684d Removed G parameter serialization code for ThresholdKey 2018-05-30 15:37:53 +02:00
Piotr Dyraga 5d49cb0f72 Added documentation to code evaluating ZKP 2018-05-30 14:49:41 +02:00
Piotr Dyraga b715df420a Removed unneeded return statements from tests 2018-05-30 14:49:29 +02:00
Piotr Dyraga f05e5219c2 Added documentation describing how partial decryptions are combined 2018-05-30 14:49:18 +02:00
Piotr Dyraga 76f8f63a47 Added test ensuring threshold Paillier is a partially homomorphic system 2018-05-30 14:49:05 +02:00
Piotr Dyraga 915950cb35 Removed unused ThresholdKey.divide function 2018-05-30 14:48:50 +02:00
Piotr Dyraga 1dc8db4cb2 Improved documentation for ThresholdKey functions 2018-05-30 14:48:39 +02:00
Piotr Dyraga adcb812a08 Do not export internal ThresholdKey functions 2018-05-30 14:48:28 +02:00
Piotr Dyraga e25bc358e8 G parameter removed from ThresholdKey
G _MUST_ be always n+1 to make the threshold encryption algorithm safe. We assume G=n+1 both for standard and threshold version.
2018-05-30 14:48:15 +02:00
Piotr Dyraga e10b02e420 Small improvements to the threshold key generator tests
First of all, we should check both `p,p1` and `q,q1` in the `TestInitPsAndQs`. Moreover, it's better to operate on primes in `TestArePsAndQsGood` and in `TestInitShortcuts` because non-prime numbers are not allowed there in a real world and tests were a bit misleading because of it.
2018-05-30 14:47:56 +02:00
Piotr Dyraga 92c3842e5f Improved documentation for a secret share computation fn 2018-05-30 14:47:41 +02:00
Piotr Dyraga 27dcab18e0 Do not export internal threshold generator functions 2018-05-30 14:47:27 +02:00
Piotr Dyraga ad44ab64cb Added documentation to the threshold Paillier key generator 2018-05-30 14:46:54 +02:00
Piotr Dyraga 7c2ec95fb8 Explained how do we compute D from Chinese Remainder Theorem 2018-05-30 14:46:41 +02:00
Matt Luongo 83928fcadb Merge pull request #1 from keep-network/evaluate-and-fix
Paillier scheme API - evaluation and clearing up
2018-05-25 08:47:25 -07:00
Piotr Dyraga 9fe64ff57b Comment about G value moved to ThresholdKey
G is no longer a parameter of PublicKey.
2018-05-25 09:58:26 +02:00
Piotr Dyraga 013296b8e4 Removed PrivateKey's String() method
It's better to have no code encouraging to turn key into a string and printing it somewhere, especially that string contains private key Lambda parameter.
2018-05-24 19:15:48 +02:00
Piotr Dyraga 4595f69872 G parameter moved from PublicKey to ThresholdKey
We don't need G for our PublicKey since it's now always equal N+1. It's required by the `ThresholdKey` to compile, so I moved it there. I will investigate if for a threshold Paillier scheme G is really needed in the pkey.
2018-05-24 19:13:29 +02:00
Piotr Dyraga 69c60e90d5 Do not cache N^2 value in PublicKey
Let's keep this structure clean. Computing N^2 is just a really small piece of encryption/decryption work and if we decide we need to tweak performance, we will need a different approach anyway.
2018-05-24 19:02:01 +02:00
Piotr Dyraga d892a58e4b Cleared up Paillier scheme API
The code for generating private key is based on approach described in [KL 08], construction 11.32 which is compatible with the one described in [DJN 10], section 3.2 except that instead of generating Lamda private key compontent from LCM of `p` and `q` we use Euler's totient function as suggested in [KL 08]. I cleared up naming as well as removed G and Mu parameters from Paillier key. For the modification of Paillier scheme we use, where g = n + 1, N is the only one parameter needed for a public key. Also, Mu is needed only for Decrypting and can be computed there from Lambda and N so there is no need to keep it in the private key.

I added documentation to <Key, Enc, Dec> functions with an important note that `p` and `q` supplied to `CreatePrivateKey` must be either of equal length or `gcd(pq, (p-1)(q-1)) = 1` which is assured if both primes are of equal length. This requirement is mentioned both in [KL 08] and [DJN 10].

[KL 08]:  Jonathan Katz, Yehuda Lindell, (2008)
          Introduction to Modern Cryptography: Principles and Protocols,
          Chapman & Hall/CRC

[DJN 10]: Ivan Damgard, Mads Jurik, Jesper Buus Nielsen, (2010)
          A Generalization of Paillier’s Public-Key System
          with Applications to Electronic Voting
          Aarhus University, Dept. of Computer Science, BRICS
2018-05-24 18:41:10 +02:00
Piotr Dyraga f550c00e74 Added test for Lambda parameter computation 2018-05-23 18:43:14 +02:00
Piotr Dyraga 622644f19d Fixed test for LCM
The LCM test was expecting GCD result and because assertion was flipped (missing negation), the test was passing.
2018-05-23 18:37:15 +02:00