Implementation of the public-key Paillier Cryptosystem. More...
#include <paillier.h>
Public Member Functions | |
Paillier () | |
Default constructor. More... | |
Paillier (const PaillierPublicKey &publicKey) | |
Creates an instance of the class for homomorphic operations and ecryption. More... | |
Paillier (const PaillierPublicKey &publicKey, const PaillierPrivateKey &privateKey) | |
Creates an instance of the class for homomorphic operations, ecryption and decryption. More... | |
~Paillier () | |
Destructor. | |
virtual bool | GenerateKeys () |
virtual BigInteger | DecryptInteger (const Ciphertext &ciphertext) const |
Decrypt number. More... | |
virtual Ciphertext | EncryptIntegerNonrandom (const BigInteger &plaintext) const |
Encrypt number without randomization. More... | |
virtual Randomizer | GetRandomizer () const |
Compute the random factor required for the encryption operation. More... | |
virtual Ciphertext | RandomizeCiphertext (const Ciphertext &ciphertext) const |
Randomize encrypted number with a self-generated random value. More... | |
virtual const BigInteger & | GetMessageSpaceUpperBound () const |
Returns the message space upper bound. More... | |
virtual size_t | GetMessageSpaceSize () const |
Returns the message space bit size. More... | |
![]() | |
CryptoProvider (const unsigned int keyLength) | |
Constructor. More... | |
CryptoProvider (const PaillierPublicKey &publicKey, const unsigned int keyLength) | |
Constructor. More... | |
CryptoProvider (const PaillierPublicKey &publicKey, const PaillierPrivateKey &privateKey, const unsigned int keyLength) | |
Constructor. More... | |
virtual | ~CryptoProvider () |
Destructor. | |
virtual PaillierCiphertext | EncryptInteger (const BigInteger &plaintext) const |
Encrypt an integer and apply randomization. More... | |
const BigInteger & | GetEncryptionModulus () const |
Returns the modulus required for reducing the encryption after randomization. More... | |
virtual const BigInteger & | GetPositiveNegativeBoundary () const |
Returns the biggest positive number that can be encrypted without overflowing. More... | |
const PaillierPublicKey & | GetPublicKey () const |
Public key getter. More... | |
const PaillierPrivateKey & | GetPrivateKey () const |
Private key getter. More... | |
Ciphertext | GetEncryptedZero (const bool randomized=true) const |
Returns [0]. More... | |
Ciphertext | GetEncryptedOne (const bool randomized=true) const |
Returns [1]. More... | |
Private Member Functions | |
BigInteger | L (const BigInteger &input, const BigInteger &d) const |
L function evaluator. More... | |
virtual void | validateParameters () |
Do nothing for now. | |
virtual void | doPrecomputations () |
Precompute values for speedups. More... | |
Paillier (const Paillier &) | |
Copy constructor - not implemented. | |
Paillier | operator= (const Paillier &) |
Copy assignment operator - not implemented. | |
Private Attributes | |
BigInteger | pMinusOne |
\( p - 1 \) | |
BigInteger | qMinusOne |
\( q - 1 \) | |
BigInteger | nMinusOne |
Contains \( n - 1 \). | |
BigInteger | pSquared |
\( p^2 \) | |
BigInteger | qSquared |
\( q^2 \) | |
BigInteger | nSquared |
Contains \( n^2 \). | |
BigInteger | pTimesPInvModQ |
\( p (p^{-1} \pmod q) \) | |
BigInteger | qTimesQInvModP |
\( q (q^{-1} \pmod p) \) | |
BigInteger | hp |
\( L_p(g^{p - 1} (\pmod p^2))^{-1} \pmod p \) | |
BigInteger | hq |
\( L_q(g^{q - 1} (\pmod q^2))^{-1} \pmod q \) | |
Additional Inherited Members | |
![]() | |
typedef PaillierCiphertext | Ciphertext |
Provide public access to the T_Ciphertext type. | |
typedef PaillierRandomizer | Randomizer |
Provide public access to the T_Randomizer type. | |
![]() | |
typedef RandomizerCache < RandomizerContainer < CryptoProvider < PaillierPublicKey, PaillierPrivateKey, PaillierCiphertext, PaillierRandomizer > , RandomizerCacheParameters > > | RandomizerCacheType |
Data type of the randomizer cache. | |
![]() | |
std::unique_ptr < RandomizerCacheType > | randomizerCache |
Lazy loading randomizer cache. | |
PaillierPublicKey | publicKey |
Public key container. | |
PaillierPrivateKey | privateKey |
Private key container. | |
unsigned int | keyLength |
The key length in bits. | |
std::shared_ptr< BigInteger > | encryptionModulus |
The encryption modulus. | |
BigInteger | positiveNegativeBoundary |
Contains the delimiter between positive and negative values in the message space (usually \( \lfloor messagespace / 2 \rfloor \)) | |
bool | hasPrivateKey |
Boolean flag that enables decryption if the private key is present. | |
bool | precomputeSpeedupValues |
Boolean flag that indicates wether doPrecomputations() should precompute certain values. | |
PaillierCiphertext | encryptedZero |
Contains [0] used as initializer for homomorphic addition accumulators. Precompute it for optimization purposes. | |
PaillierCiphertext | encryptedOne |
Contains [1]. | |
Implementation of the public-key Paillier Cryptosystem.
Definition at line 103 of file paillier.h.
SeComLib::Core::Paillier::Paillier | ( | ) |
Default constructor.
Sets the specified key size from the configuration file (defaults to 1024)
Definition at line 73 of file paillier.cpp.
SeComLib::Core::Paillier::Paillier | ( | const PaillierPublicKey & | publicKey | ) |
Creates an instance of the class for homomorphic operations and ecryption.
Performs required precomputations.
publicKey | a PaillierPublicKey structure |
Definition at line 81 of file paillier.cpp.
SeComLib::Core::Paillier::Paillier | ( | const PaillierPublicKey & | publicKey, |
const PaillierPrivateKey & | privateKey | ||
) |
Creates an instance of the class for homomorphic operations, ecryption and decryption.
Performs required precomputations.
publicKey | a PaillierPublicKey structure |
privateKey | a PaillierPrivateKey structure |
Definition at line 92 of file paillier.cpp.
|
virtual |
Decrypt number.
If \( plaintext \geq \lfloor messagespace / 2 \), it is remapped to a negative value.
ciphertext | the ciphertext integer |
std::runtime_error | operation requires the private key |
Apply CRT for decryption: \( h_p = L_p(g^{p - 1} (\pmod p^2))^{-1} \pmod p \) \( h_q = L_q(g^{q - 1} (\pmod q^2))^{-1} \pmod q \) \( m_p = L_p(c^{p - 1} (\pmod p^2)) h_p \pmod p \) \( m_q = L_q(c^{q - 1} (\pmod q^2)) h_q \pmod q \) \( m = (m_p q (q^{-1} \pmod p) + m_q p (p^{-1} \pmod q)) (\pmod n) \)
If \( plaintext \leq \lfloor messagespace / 2 \rfloor \Rightarrow plaintext \geq 0 \) otherwise \( plaintext < 0 \Rightarrow plaintext = plaintext - messagespace \)
Definition at line 176 of file paillier.cpp.
|
privatevirtual |
Precompute values for speedups.
Precompute \( h_p = L_p(g^{p - 1} (\pmod p^2))^{-1} \pmod p \) and \( h_q = L_q(g^{q - 1} (\pmod q^2))^{-1} \pmod q \) to speed up decryption via CRT
Speed optimizations for decryption: precompute \( p (p^{-1} \pmod q) \) and \( q (q^{-1} \pmod p) \)
Populate the randomizer cache
Definition at line 304 of file paillier.cpp.
|
virtual |
Encrypt number without randomization.
Contains the "standard" and "shortcut" versions of the Paillier encryption algorithm without randomization.
plaintext | the plaintext integer |
If \( plaintext < 0 \), we remap it to the second half of the message space
"Shortcut" version: \( c = (n*m + 1) \pmod {n^2} \)
Definition at line 214 of file paillier.cpp.
|
virtual |
Generate the public and private keys
Generates the Paillier cryptosystem keys.
Produces \( p \) and \( q \), each having half of the key length, and computes \( n = p q \), enforcing \( n \) to have the length specified by the key length.
Set the length of primes p and q
If both are equal (highly unlikely) seek another prime
Compute \( n = p q \)
Need to guarantee that n always has the specified length? There should be a faster implementation for this...
"Shortcut" version:
Set \( g = n + 1 \)
\( \phi(n) \), \( \lambda \) and \( \mu \) are required by the "shortcut version" of the algorithm, but are no longer needed if decryption is done via CRT
Definition at line 105 of file paillier.cpp.
|
virtual |
Returns the message space bit size.
Definition at line 283 of file paillier.cpp.
|
virtual |
|
virtual |
Compute the random factor required for the encryption operation.
Generates a random number \( r \in \mathbb{Z}_n^* \) and computes \( r^n \pmod {n^2} \).
Computes \( r^n \pmod {n^2} \).
Definition at line 259 of file paillier.cpp.
|
private |
L function evaluator.
Computes \( L(u) = \frac{u - 1}{d} \)
input | the function variable |
d | the divisor |
Definition at line 294 of file paillier.cpp.
|
virtual |
Randomize encrypted number with a self-generated random value.
Computes \( c = c r^n \pmod {n^2} \).
ciphertext | the ciphertext integer |
Definition at line 269 of file paillier.cpp.