54 messageSpaceThreshold(BigInteger(2).Pow(Utils::Config::GetInstance().GetParameter<unsigned long>(
"Core.ElGamal.messageSpaceThresholdBitSize"))),
55 precomputeDecryptionMap(precomputeDecryptionMap) {
66 messageSpaceThreshold(BigInteger(2).Pow(Utils::Config::GetInstance().GetParameter<unsigned long>(
"Core.ElGamal.messageSpaceThresholdBitSize"))) {
79 messageSpaceThreshold(BigInteger(2).Pow(Utils::Config::GetInstance().GetParameter<unsigned long>(
"Core.ElGamal.messageSpaceThresholdBitSize"))),
80 precomputeDecryptionMap(precomputeDecryptionMap) {
108 if (largePrimeFactorSize >= this->
keyLength) {
110 throw std::runtime_error(
"Please choose a smaller prime factor size.");
117 unsigned int sizeR = this->
keyLength - largePrimeFactorSize;
118 unsigned int sizeMN = (sizeR - 1) / 2;
121 this->
publicKey.
q = RandomProvider::GetInstance().GetMaxLengthRandomPrime(largePrimeFactorSize);
124 m = RandomProvider::GetInstance().GetMaxLengthRandomPrime(sizeMN);
125 n = RandomProvider::GetInstance().GetMaxLengthRandomPrime(sizeMN);
138 this->
g = RandomProvider::GetInstance().GetRandomInteger(this->
publicKey.
p);
141 while (BigInteger::Gcd(this->
g, this->
publicKey.
p) != 1 ||
142 this->g.GetPowModN(this->publicKey.q * m * n, this->publicKey.p) == 1 ||
143 this->
g.GetPowModN(this->
publicKey.
q * m * 2, this->publicKey.p) == 1 ||
144 this->
g.GetPowModN(this->
publicKey.
q * n * 2, this->publicKey.p) == 1 ||
145 this->
g.GetPowModN(m * n * 2, this->
publicKey.
p) == 1);
176 throw std::runtime_error(
"This operation requires the private key.");
180 throw std::runtime_error(
"This operation requires the decryption map.");
187 if (cyCxPowMinusSModP == 1) {
196 DecryptionMap::const_iterator iterator = this->
decryptionMap.find(cyCxPowMinusSModP);
200 output = BigInteger(iterator->second);
203 throw std::runtime_error(
"Can't decrypt ciphertext.");
242 BigInteger random = RandomProvider::GetInstance().GetRandomInteger(this->
publicKey.
q);
265 #ifdef ENABLE_CRYPTO_PROVIDER_HOMOMORPHIC_OPERATIONS
319 throw std::runtime_error(
"The plaintext term should not be 0.");
355 throw std::runtime_error(
"This operation requires the private key.");
360 return test == 1 ?
true :
false;
377 for (BigInteger i = this->
publicKey.
q - this->messageSpaceThreshold + 1; i < this->
publicKey.
q; ++i) {
ElGamalCiphertext Ciphertext
Provide public access to the T_Ciphertext type.
RandomizerCache< RandomizerContainer< CryptoProvider< ElGamalPublicKey, ElGamalPrivateKey, ElGamalCiphertext, ElGamalRandomizer >, RandomizerCacheParameters > > RandomizerCacheType
Data type of the randomizer cache.
Data data
Cipertext container.
static Config & GetInstance()
Returns a reference to the singleton.
unsigned int keyLength
The key length in bits.
The private key container structure for the ElGamal cryptosystem.
DecryptionMap decryptionMap
Contains all possible values of , where , and it is required for decryption.
virtual size_t GetMessageSpaceSize() const
Returns the message space bit size.
virtual ElGamalCiphertext EncryptInteger(const BigInteger &plaintext) const
Encrypt an integer and apply randomization.
ElGamalPrivateKey privateKey
Private key container.
ElGamal(const bool precomputeDecryptionMap=false)
Default constructor.
virtual Ciphertext EncryptIntegerNonrandom(const BigInteger &plaintext) const
Encrypt number without randomization.
virtual const BigInteger & GetMessageSpaceUpperBound() const
Returns the message space upper bound.
virtual Ciphertext RandomizeCiphertext(const Ciphertext &ciphertext) const
Randomize encrypted number with a self-generated random value.
BigInteger messageSpaceThreshold
bool precomputeDecryptionMap
If true, full decryptions are enabled and the decryption map is (pre)computed.
ElGamalCiphertext encryptedZero
Contains [0] used as initializer for homomorphic addition accumulators. Precompute it for optimizatio...
BigInteger g
A generator of .
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
std::unique_ptr< RandomizerCacheType > randomizerCache
Lazy loading randomizer cache.
virtual Randomizer GetRandomizer() const
Compute the random factor required for the encryption operation.
virtual bool GenerateKeys()
T GetParameter(const std::string ¶meter) const
Template method which returns the value of the specified configuration parameter. ...
ElGamalCiphertext encryptedOne
Contains [1].
BigInteger positiveNegativeBoundary
Contains the delimiter between positive and negative values in the message space (usually ) ...
The randomizer type for Paillier.
ElGamalRandomizer Randomizer
Provide public access to the T_Randomizer type.
const BigInteger & GetEncryptionModulus() const
Returns the modulus required for reducing the encryption after randomization.
Definition of class ElGamal.
ElGamalPublicKey publicKey
Public key container.
Template abstract base class for homomorphic encryption primitives.
std::shared_ptr< BigInteger > encryptionModulus
The encryption modulus.
virtual void doPrecomputations()
Precompute values for speedups.
bool hasPrivateKey
Boolean flag that enables decryption if the private key is present.
The public key container structure for the ElGamal cryptosystem.
ElGamalRandomizer()
Default constructor.
bool IsEncryptedZero(const Ciphertext &ciphertext) const
Determines if ciphertext contains an encryption of 0 or not.