SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
paillier.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 PAILLIER_HEADER_GUARD
30 #define PAILLIER_HEADER_GUARD
31 
32 #include "big_integer.h"
33 #include "random_provider.h"
34 #include "ciphertext_base.h"
35 #include "crypto_provider.h"
36 #include "utils/config.h"
37 
38 //include C++ headers
39 #include <stdexcept>
40 
41 namespace SeComLib {
42 namespace Core {
43  //uncomment this to use the standard version of the Paillier key generation and encryption algorithms
44  //#define USE_STANDARD_PAILLIER_ALGORITHM
45 
50  public:
52  BigInteger n;
54  BigInteger g;
55  };
56 
61  public:
63  BigInteger p;//required if decrypting using CRT
65  BigInteger q;//required if decrypting using CRT
66  #ifdef USE_STANDARD_PAILLIER_ALGORITHM
67  BigInteger lambda;
70  BigInteger mu;
71  #endif
72  };
73 
77  class PaillierCiphertext : public CiphertextBase<PaillierCiphertext> {
78  public:
81 
83  PaillierCiphertext (const std::shared_ptr<BigInteger> &encryptionModulus);
84 
86  PaillierCiphertext (const BigInteger &data, const std::shared_ptr<BigInteger> &encryptionModulus);
87  };
88 
95 
97  PaillierRandomizer (const BigInteger &data);
98  };
99 
103  class Paillier : public CryptoProvider<PaillierPublicKey, PaillierPrivateKey, PaillierCiphertext, PaillierRandomizer> {
104  public:
106  Paillier ();
107 
110 
112  Paillier (const PaillierPublicKey &publicKey, const PaillierPrivateKey &privateKey);
113 
115  ~Paillier () {}
116 
117  /* Base class methods */
118 
121  virtual bool GenerateKeys ();
122 
124  virtual BigInteger DecryptInteger (const Ciphertext &ciphertext) const;
125 
127  virtual Ciphertext EncryptIntegerNonrandom (const BigInteger &plaintext) const;
128 
130  virtual Randomizer GetRandomizer () const;
131 
133  virtual Ciphertext RandomizeCiphertext (const Ciphertext &ciphertext) const;
134 
136  virtual const BigInteger &GetMessageSpaceUpperBound () const;
137 
139  virtual size_t GetMessageSpaceSize () const;
140 
141  /* /Base class methods */
142 
143  private:
145  BigInteger pMinusOne;
146 
148  BigInteger qMinusOne;
149 
151  BigInteger nMinusOne;
152 
154  BigInteger pSquared;
155 
157  BigInteger qSquared;
158 
160  BigInteger nSquared;
161 
163  BigInteger pTimesPInvModQ;
164 
166  BigInteger qTimesQInvModP;
167 
169  BigInteger hp;
170 
172  BigInteger hq;
173 
175  BigInteger L (const BigInteger &input, const BigInteger &d) const;
176 
177  /* Base class methods */
178 
180  virtual void validateParameters () {}
181 
183  virtual void doPrecomputations ();
184 
185  /* /Base class methods */
186 
188  Paillier (const Paillier &);
189 
191  Paillier operator= (const Paillier &);
192  };
193 }//namespace Core
194 }//namespace SeComLib
195 
196 #endif//PAILLIER_HEADER_GUARD
BigInteger pSquared
Definition: paillier.h:154
BigInteger qTimesQInvModP
Definition: paillier.h:166
BigInteger pMinusOne
Definition: paillier.h:145
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
Definition: paillier.cpp:176
BigInteger L(const BigInteger &input, const BigInteger &d) const
L function evaluator.
Definition: paillier.cpp:294
virtual const BigInteger & GetMessageSpaceUpperBound() const
Returns the message space upper bound.
Definition: paillier.cpp:276
Defines BigInteger.
RandomizerBase struct.
Definition of class Config.
virtual bool GenerateKeys()
Definition: paillier.cpp:105
BigInteger qMinusOne
Definition: paillier.h:148
BigInteger nMinusOne
Contains .
Definition: paillier.h:151
BigInteger data
The randomizer data.
Paillier()
Default constructor.
Definition: paillier.cpp:73
virtual void validateParameters()
Do nothing for now.
Definition: paillier.h:180
PaillierCiphertext()
Default constructor.
Definition: paillier.cpp:37
BigInteger qSquared
Definition: paillier.h:157
virtual Ciphertext RandomizeCiphertext(const Ciphertext &ciphertext) const
Randomize encrypted number with a self-generated random value.
Definition: paillier.cpp:269
BigInteger pTimesPInvModQ
Definition: paillier.h:163
virtual size_t GetMessageSpaceSize() const
Returns the message space bit size.
Definition: paillier.cpp:283
std::shared_ptr< BigInteger > encryptionModulus
The encryption modulus.
virtual Ciphertext EncryptIntegerNonrandom(const BigInteger &plaintext) const
Encrypt number without randomization.
Definition: paillier.cpp:214
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
BigInteger nSquared
Contains .
Definition: paillier.h:160
virtual Randomizer GetRandomizer() const
Compute the random factor required for the encryption operation.
Definition: paillier.cpp:259
Paillier cipertext.
Definition: paillier.h:77
Defines RandomProvider.
CiphertextBase template class.
PaillierRandomizer()
Default constructor.
Definition: paillier.cpp:60
The randomizer type for Paillier.
Definition: paillier.h:92
~Paillier()
Destructor.
Definition: paillier.h:115
Definition of template abstract class CryptoProvider.
Template abstract base class for homomorphic encryption primitives.
Definition of template class CiphertextBase.
virtual void doPrecomputations()
Precompute values for speedups.
Definition: paillier.cpp:304
The private key container structure for the Paillier cryptosystem.
Definition: paillier.h:60
Paillier operator=(const Paillier &)
Copy assignment operator - not implemented.
The public key container structure for the Paillier cryptosystem.
Definition: paillier.h:49