SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
el_gamal.h
Go to the documentation of this file.
1 /*
2 SeComLib
3 Copyright 2012-2013 TU Delft, Information Security & Privacy Lab (http://isplab.tudelft.nl/)
4 
5 Contributors:
6 Inald Lagendijk (R.L.Lagendijk@TUDelft.nl)
7 Mihai Todor (todormihai@gmail.com)
8 Thijs Veugen (P.J.M.Veugen@tudelft.nl)
9 Zekeriya Erkin (z.erkin@tudelft.nl)
10 
11 Licensed under the Apache License, Version 2.0 (the "License");
12 you may not use this file except in compliance with the License.
13 You may obtain a copy of the License at
14 
15 http://www.apache.org/licenses/LICENSE-2.0
16 
17 Unless required by applicable law or agreed to in writing, software
18 distributed under the License is distributed on an "AS IS" BASIS,
19 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20 See the License for the specific language governing permissions and
21 limitations under the License.
22 */
29 #ifndef EL_GAMAL_HEADER_GUARD
30 #define EL_GAMAL_HEADER_GUARD
31 
32 #include "big_integer.h"
33 #include "random_provider.h"
34 #include "crypto_provider.h"
35 #include "utils/config.h"
36 #include "el_gamal_ciphertext.h"
37 
38 //include C++ headers
39 #include <map>
40 #include <stdexcept>
41 
42 namespace SeComLib {
43 namespace Core {
48  public:
50  BigInteger p;
52  BigInteger q;
54  BigInteger gq;
56  BigInteger h;
57  };
58 
63  public:
65  BigInteger s;
66  };
67 
73  BigInteger x;
74 
76  BigInteger y;
77 
80 
82  ElGamalRandomizer (const BigInteger &x, const BigInteger &y);
83  };
84 
88  class ElGamal : public CryptoProvider<ElGamalPublicKey, ElGamalPrivateKey, ElGamalCiphertext, ElGamalRandomizer> {
89  public:
91  ElGamal (const bool precomputeDecryptionMap = false);
92 
95 
97  ElGamal (const ElGamalPublicKey &publicKey, const ElGamalPrivateKey &privateKey, const bool precomputeDecryptionMap = false);
98 
100  ~ElGamal () {}
101 
102  /* Base class methods */
103 
106  virtual bool GenerateKeys ();
107 
109  virtual BigInteger DecryptInteger (const Ciphertext &ciphertext) const;
110 
112  virtual Ciphertext EncryptIntegerNonrandom (const BigInteger &plaintext) const;
113 
115  virtual Randomizer GetRandomizer () const;
116 
118  virtual Ciphertext RandomizeCiphertext (const Ciphertext &ciphertext) const;
119 
120  #ifdef ENABLE_CRYPTO_PROVIDER_HOMOMORPHIC_OPERATIONS
121  Ciphertext HomomorphicAdd (const Ciphertext &lhs, const Ciphertext &rhs) const;
123 
125  Ciphertext GetHomomorphicInverse (const Ciphertext &input) const;
126 
128  Ciphertext HomomorphicSubtract (const Ciphertext &lhs, const Ciphertext &rhs) const;
129 
131  Ciphertext HomomorphicMultiply (const Ciphertext &lhs, const BigInteger &rhs) const;
132  #endif
133 
135  virtual const BigInteger &GetMessageSpaceUpperBound () const;
136 
138  virtual size_t GetMessageSpaceSize () const;
139 
140  /* /Base class methods */
141 
143  bool IsEncryptedZero (const Ciphertext &ciphertext) const;
144 
145  private:
147  typedef std::map<const BigInteger, BigInteger> DecryptionMap;
148 
151 
153  BigInteger g;
154 
157 
160 
161  /* Base class methods */
162 
164  virtual void validateParameters () {}
165 
167  virtual void doPrecomputations ();
168 
169  /* /Base class methods */
170 
172  ElGamal (const ElGamal &);
173 
175  ElGamal operator= (const ElGamal &);
176  };
177 }//namespace Core
178 }//namespace SeComLib
179 
180 #endif//EL_GAMAL_HEADER_GUARD
The private key container structure for the ElGamal cryptosystem.
Definition: el_gamal.h:62
Defines BigInteger.
DecryptionMap decryptionMap
Contains all possible values of , where , and it is required for decryption.
Definition: el_gamal.h:159
Definition of class ElGamalCiphertext.
Definition of class Config.
virtual size_t GetMessageSpaceSize() const
Returns the message space bit size.
Definition: el_gamal.cpp:341
ElGamal(const bool precomputeDecryptionMap=false)
Default constructor.
Definition: el_gamal.cpp:53
virtual Ciphertext EncryptIntegerNonrandom(const BigInteger &plaintext) const
Encrypt number without randomization.
Definition: el_gamal.cpp:219
virtual const BigInteger & GetMessageSpaceUpperBound() const
Returns the message space upper bound.
Definition: el_gamal.cpp:334
virtual Ciphertext RandomizeCiphertext(const Ciphertext &ciphertext) const
Randomize encrypted number with a self-generated random value.
Definition: el_gamal.cpp:253
BigInteger messageSpaceThreshold
Definition: el_gamal.h:150
bool precomputeDecryptionMap
If true, full decryptions are enabled and the decryption map is (pre)computed.
Definition: el_gamal.h:156
~ElGamal()
Destructor.
Definition: el_gamal.h:100
Implementation of the public-key ElGamal Cryptosystem.
Definition: el_gamal.h:88
virtual void validateParameters()
Do nothing for now.
Definition: el_gamal.h:164
BigInteger g
A generator of .
Definition: el_gamal.h:153
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
Definition: el_gamal.cpp:174
virtual Randomizer GetRandomizer() const
Compute the random factor required for the encryption operation.
Definition: el_gamal.cpp:241
virtual bool GenerateKeys()
Definition: el_gamal.cpp:104
Defines RandomProvider.
ElGamal operator=(const ElGamal &)
Copy assignment operator - not implemented.
The randomizer type for Paillier.
Definition: el_gamal.h:71
std::map< const BigInteger, BigInteger > DecryptionMap
std::map template specialization
Definition: el_gamal.h:147
Definition of template abstract class CryptoProvider.
Template abstract base class for homomorphic encryption primitives.
virtual void doPrecomputations()
Precompute values for speedups.
Definition: el_gamal.cpp:368
The public key container structure for the ElGamal cryptosystem.
Definition: el_gamal.h:47
ElGamalRandomizer()
Default constructor.
Definition: el_gamal.cpp:38
bool IsEncryptedZero(const Ciphertext &ciphertext) const
Determines if ciphertext contains an encryption of 0 or not.
Definition: el_gamal.cpp:353