Commit Graph
10 Commits
Author SHA1 Message Date
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
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 b7abc00044 Test of an additively homomorphic property for a small modulus 2018-06-28 15:47:41 +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
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
didier amyot 8a9743f08e imported from https://bitbucket.org/ustraca/crypto 2014-11-29 22:40:35 -08:00