Commit Graph
18 Commits
Author SHA1 Message Date
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
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
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
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
Piotr Dyraga 3acf9e6948 Explained how do we handle negative lambda parameter value 2018-06-05 13:11:50 +02:00