Commit Graph
105 Commits
Author SHA1 Message Date
sachaservan 970db06efc standardize naming 2018-08-18 14:54:38 -04:00
sachaservan 63e4695b16 more robust testing 2018-08-18 13:41:12 -04:00
sachaservan d2aad1b7fb rename: standardize 2018-08-18 13:39:43 -04:00
sachaservan 0453e4bc3f rename ZNP -> ZKP (zero-Knowledge proof) 2018-08-18 13:21:31 -04:00
sachaservan 9743feecea rename Cypher -> Ciphertext 2018-08-18 13:19:03 -04:00
sachaservan a1d5898e75 rename PrivateKey -> SecretKey 2018-08-18 13:15:02 -04:00
sachaservan 5adb70bc7b rename PrivateKey -> SecretKey 2018-08-18 13:14:21 -04:00
didier amyot 753322e473 Merge pull request #11 from keep-network/master
Pass a public key bit length when creating a threshold key generator
2018-08-10 06:50:46 -04:00
pdyraga f6ed66f4be Merge pull request #11 from keep-network/gitignore
Add IDE's workspace configuration directories to gitignore
2018-08-09 14:11:26 +02:00
Jakub Nowakowski 88d1beaf50 Added IDEs specific directories to gitignore 2018-08-09 14:04:41 +02:00
Jakub Nowakowski 3571790b8a Merge pull request #10 from keep-network/public-key-bit-length
Pass a public key bit length when creating a threshold key generator
2018-08-08 15:31:49 +02:00
Piotr Dyraga 1d535dc740 Simplified ThresholdKeyGenerator factory function tests 2018-08-08 15:11:43 +02:00
Piotr Dyraga 695e73602d Updated test to make sure all generator ctor values are set correctly 2018-08-08 14:03:35 +02:00
Piotr Dyraga 0084a3762b Fixed documentation about the bit length of p,q and n 2018-08-08 13:50:23 +02:00
Piotr Dyraga 5d09ad8609 Added test ensuring correct n,p,q bit length for threshold key-gen 2018-08-08 13:46:51 +02:00
Piotr Dyraga 5332558625 ThresholdKeyGenerator random reference is no longer exported 2018-08-08 13:22:02 +02:00
Piotr Dyraga e726ad489b PublicKeyBitLength made an exported value just like all the others 2018-08-08 13:19:20 +02:00
Piotr Dyraga 51b5bac262 Create and return ThresholdKeyGenerator in one shot. 2018-08-08 13:16:25 +02:00
Piotr Dyraga 0d2a123af7 Fixed comment for safe primes required bit length
Safe primes bit length is n-1 for n-bit public key
2018-08-08 11:28:25 +02:00
Piotr Dyraga 12b3dadef7 Make sure public key bit length is an even number
For an odd n-bit number, we can't find two n-1-bit numbers which
multiplied gives an n-bit number. That's why public key length n must be
an even number.

I have also renamed AreSafePrimes to IsSafePrime since only the first
function argument is considered to be a safe prime according to a safe
prime definition.
2018-08-08 11:11:05 +02:00
Piotr Dyraga d5973f86a7 Improved GetThresholdKeyGenerator documentation
Added information about the required minimum bit length of the public
key. Removed the threshold information as we are not sure now if it's
valid. We'll investigate it separately and make sure a proper validation
for threshold is made.
2018-08-08 10:56:26 +02:00
Piotr Dyraga 3394a6136a Check threshold public key bit length 2018-08-08 10:44:28 +02:00
Piotr Dyraga 408bafa61a Use GenThresholdKeyGenerator whenever it's possible 2018-08-08 10:44:12 +02:00
Piotr Dyraga 3c6123c0e3 Accept PubKey bit length when constructing TKey generator
Instead of passing safe prime bit length which is a kind of an
implementation detail, we should pass a public key bit length. Public
key is a Paillier modulus defining plaintext space. This information is
more important than the safe prime value/bit length used under the hood.
2018-08-08 10:44:02 +02:00
didier amyot ce3779f8f1 Merge pull request #10 from keep-network/master
Plaintext space check
2018-08-07 20:43:35 -04:00
Jakub Nowakowski 3a27db63e5 Merge pull request #9 from keep-network/check-plaintext-space
Plaintext space check
2018-08-02 13:48:22 +02:00
didier amyot d03e8850a8 Merge pull request #9 from keep-network/master
Improved performance of the safe prime generator
2018-08-02 06:47:12 -04:00
Piotr Dyraga edb17e88e7 TestAddCypherWithSmallKeyModulus fixed - m can't be bigger than N now
For Paillier modulus N=pq, plaintext m space is [0, N). We now report an
error if m is not in the allowed range.
2018-07-31 17:06:42 +02:00
Piotr Dyraga 2a33f6e35c Plaintext space check
According to [DJN 10], the plaintext space is `Z_n`. We had this
information in the `Encrypt` and `EncryptWithR` documentation but
sometimes, when encrypting result of more complex equations, it's easy
to miss the fact the result is out of the allowed range.

Here we have just a safety check making sure that if plaintext is out of
allowed space, we report an error.
2018-07-31 16:18:19 +02:00
Jakub Nowakowski fd71647982 Merge pull request #8 from keep-network/safe-primes-gen
Improved performance of the safe prime generator
2018-07-31 09:27:25 +02:00
Piotr Dyraga be670a086c Added documentation to isPoclingtonCriterionSatisfied 2018-07-30 16:34:59 +02:00
Piotr Dyraga 1200243127 Simplified how values are returned from the GenerateSafePrime
We can use `defer waitGroup.Wait()` to make sure it's called regardless
which path we go. This we, we can call `return ...` directly from all
select cases and we don't need named parameters.
2018-07-30 16:04:00 +02:00
Piotr Dyraga 82f050d7b2 Simplified concurrency mechanisms for goroutines
It does not longer make sense to have a mutex and cancelled context check
since we have a wait group and channels with buffers with the size equal
the number of workers.

Without the wait group we had to make sure no goroutine tries to write
to the closed channel. Now, channel is closed after all goroutines
completed (either by finding prime or cancelling the work), so there is
no chance someone tries to write to closed channel.
2018-07-30 15:46:16 +02:00
Piotr Dyraga b21e0d7d97 Name parameters for the safe prime generator call
`4` and `120*time.Seconds` were just some magic numbers in the code.
We decided to move them to separate value declarations to make the
code more self-explanatory.
2018-07-30 12:27:59 +02:00
Piotr Dyraga 530e40c1d4 Deadlock fixed - result channel buffer increased
Although the result channel send operation and context cancel are
guarded by the same mutex and context is cancelled by the main thread
when it receives a result message from the channnel, there is absolutely
no guarantee that one goroutine can't write result to the channel after
the first goroutine did the same and before the main thread cancelled
the context. This is the following scenario:

- Worker #1 acquires mutex, writes to the result channel
- Worker #2 acquires mutex, writes to the result channel
- Main thread reads from the result channel, acquires mutex, cancels the
context

Since our result channel (and error channel) had buffer of size 1, the
Worker #2 was hanging indefinitely. Setting the buffer size to the
number of goroutines fixed the problem.

Alternative scenario was:

- Worker #1 acquires mutex, writes to the result channel
- Main thread acquires mutex, reads from the result channel, cancels the
context
- Worker #2 receives cancel notification so it completes without
yielding the result

That's why deadlock was happening only from time to time.
2018-07-30 09:56:40 +02:00
Piotr Dyraga 65d7ad4e73 Fixed typo in the documentation 2018-07-27 17:43:46 +02:00
Piotr Dyraga ca756b481b Removed deprecated GenerateSafePrimes function
The new function should be now called directly.
2018-07-27 17:42:05 +02:00
Piotr Dyraga 78ea6668f8 Improved safe prime generator documentation 2018-07-27 17:31:27 +02:00
Piotr Dyraga 7f7e390737 Removed not needed code 2018-07-27 16:56:48 +02:00
Piotr Dyraga ee7e96eaf6 Fixed bit lenght assertions for safe prime generator tests 2018-07-27 16:45:29 +02:00
Piotr Dyraga 7ab24f0641 Drop support for Go 1.3, 1,4. Support Go 1.7+
Go 1.7 moved the `golang.org/x/net/context` package into the standard
library as `context`. Code importing `context` is no longer compiling
for Go versions earlier than 1.7. Since 1.7 was released two years ago
and we don't want to sacrifice quality, we decided to drop support for
1.4 and 1.3 and support 1.7+ now.
2018-07-26 15:39:58 +02:00
Piotr Dyraga ab52193fbf Use the new, faster way for generating safe primes everywhere 2018-07-26 11:22:12 +02:00
Piotr Dyraga 2c0d4e093d Wait for all goroutines to finish
Initially, we did not wait for all goroutines to finish which was fine
as long as we did not run all tests with `go test` and observe deadlock
in 50% of cases. This is interesting, since deadlock never occurred when
running safe_prime_generator_test.go. Anyway, waiting for all go
routines to finish shouldn't harm the performance a lot and it gives a
guarantee we did not miss anything.
2018-07-26 11:12:23 +02:00
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
didier amyot 63054a6528 Merge pull request #8 from keep-network/master
Added support for a Cypher multiplication
2018-07-20 07:14:38 -04: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