40 int main (
int argc,
char *argv[]) {
45 Utils::Config::SetConfigFile(std::string(argv[1]));
50 Dgk dgkCryptoProvider(
true);
51 ElGamal elGamalCryptoProvider(
true);
53 std::cout <<
"Generating keys for every crypto provider." << std::endl;
61 std::cout <<
"Testing encryption / decryption of 0." << std::endl;
67 std::cout <<
"Testing encryption / decryption of 1." << std::endl;
73 std::cout <<
"Testing encryption / decryption of -1." << std::endl;
79 std::cout <<
"Testing encryption / decryption of the positive / negative interval boundaries." << std::endl;
91 std::cout <<
"Testing DGK decryption of 0 without decryption map." << std::endl;
92 Dgk dgkCryptoProviderNoDecryptionMap;
97 std::cout <<
"Testing ElGamal decryption of 0 without decryption map." << std::endl;
98 ElGamal elGamalCryptoProviderNoDecryptionMap;
105 std::cout <<
"Testing homomorphic addition, inverse, subtraction and multiplication." << std::endl;
108 Paillier::Ciphertext encX = paillierCryptoProvider.
EncryptInteger(x);
109 Paillier::Ciphertext encY = paillierCryptoProvider.
EncryptInteger(y);
110 Paillier::Ciphertext sum = encX + encY;
111 Paillier::Ciphertext inv = -encX;
112 Paillier::Ciphertext dif = encX - encY;
113 Paillier::Ciphertext prod = encX * y;
121 OkamotoUchiyama::Ciphertext encX = okamotoUchiyamaCryptoProvider.
EncryptInteger(x);
122 OkamotoUchiyama::Ciphertext encY = okamotoUchiyamaCryptoProvider.
EncryptInteger(y);
123 OkamotoUchiyama::Ciphertext sum = encX + encY;
124 OkamotoUchiyama::Ciphertext inv = -encX;
125 OkamotoUchiyama::Ciphertext dif = encX - encY;
126 OkamotoUchiyama::Ciphertext prod = encX * y;
127 assert(okamotoUchiyamaCryptoProvider.
DecryptInteger(sum) == x + y);
129 assert(okamotoUchiyamaCryptoProvider.
DecryptInteger(dif) == x - y);
130 assert(okamotoUchiyamaCryptoProvider.
DecryptInteger(prod) == x * y);
136 Dgk::Ciphertext sum = encX + encY;
137 Dgk::Ciphertext inv = -encX;
138 Dgk::Ciphertext dif = encX - encY;
139 Dgk::Ciphertext prod = encX * y;
147 ElGamal::Ciphertext encX = elGamalCryptoProvider.
EncryptInteger(x);
148 ElGamal::Ciphertext encY = elGamalCryptoProvider.
EncryptInteger(y);
149 ElGamal::Ciphertext sum = encX + encY;
150 ElGamal::Ciphertext inv = -encX;
151 ElGamal::Ciphertext dif = encX - encY;
152 ElGamal::Ciphertext prod = encX * y;
159 std::cout <<
"Testing Data Packing with Paillier." << std::endl;
165 size_t bucketCount = 30;
167 for (
size_t i = 0; i < bucketCount; ++i)
172 bucket.
data = BigInteger(2);
174 lhs.emplace_back(bucket);
177 bucket.
data = BigInteger(3);
179 rhs.emplace_back(bucket);
193 for (
size_t i = 0; i < bucketCount; ++i)
195 assert(unpackedSum[i].frontPadding == 1);
196 assert(unpackedSum[i].data == 5);
197 assert(unpackedSum[i].backPadding == 1);
199 assert(unpackedProd[i].frontPadding == 0);
200 assert(unpackedProd[i].data == 6);
201 assert(unpackedProd[i].backPadding == 0);
205 std::cout <<
"Testing Paillier cryptoprovider construction from public and private key pairs." << std::endl;
215 Paillier cryptoProviderClone(publicKeyClone, privateKeyClone);
222 std::cout <<
"Testing Okamoto-Uchiyama cryptoprovider construction from public and private key pairs." << std::endl;
225 publicKeyClone.
G = okamotoUchiyamaCryptoProvider.
GetPublicKey().
G;
226 publicKeyClone.
H = okamotoUchiyamaCryptoProvider.
GetPublicKey().
H;
227 publicKeyClone.
n = okamotoUchiyamaCryptoProvider.
GetPublicKey().
n;
242 std::cout <<
"Testing DGK cryptoprovider construction from public and private key pairs." << std::endl;
256 Dgk cryptoProviderClone(publicKeyClone, privateKeyClone,
true);
263 std::cout <<
"Testing ElGamal cryptoprovider construction from public and private key pairs." << std::endl;
274 ElGamal cryptoProviderClone(publicKeyClone, privateKeyClone,
true);
281 catch (
const std::runtime_error &exception) {
282 std::cout << exception.what() << std::endl;
284 catch (
const std::exception &exception) {
285 std::cout << exception.what() << std::endl;
289 std::cout <<
"Unexpected exception occured." << std::endl;
Implementation of the public-key DGK Cryptosystem.
Ciphertext GetEncryptedOne(const bool randomized=true) const
Returns [1].
Ciphertext GetEncryptedZero(const bool randomized=true) const
Returns [0].
const T_PublicKey & GetPublicKey() const
Public key getter.
BigInteger backPadding
The back padding ( )
Container for data buckets.
PackedData Pack(const UnpackedData &input) const
Pack data.
virtual bool GenerateKeys()
Generate the public and private keys.
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
The private key container structure for the ElGamal cryptosystem.
BigInteger data
The data ( )
virtual bool GenerateKeys()
The public key container structure for the Dgk cryptosystem.
virtual T_Ciphertext EncryptInteger(const BigInteger &plaintext) const
Encrypt an integer and apply randomization.
virtual const BigInteger & GetMessageSpaceUpperBound() const
Returns the message space upper bound.
virtual const BigInteger & GetPositiveNegativeBoundary() const
Returns the biggest positive number that can be encrypted without overflowing.
const T_PrivateKey & GetPrivateKey() const
Private key getter.
UnpackedData Unpack(const PackedData &input, const size_t totalBucketCount) const
Unpack data.
std::deque< typename DataPacker< T_CryptoProvider >::DataBucket > UnpackedData
Define a vector template specialization for vectors of unpacked data.
Implementation of the public-key ElGamal Cryptosystem.
Template class which implements the data packing functionality.
BigInteger t
, the prime factor of
BigInteger frontPadding
The front padding ( )
bool IsEncryptedZero(const Ciphertext &ciphertext) const
Determines if ciphertext contains an encryption of 0 or not.
Implementation of the public-key Paillier Cryptosystem.
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
Implementation of the public-key Okamoto-Uchiyama Cryptosystem.
The private key container structure for the Okamoto-Uchiyama cryptosystem.
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
virtual bool GenerateKeys()
virtual bool GenerateKeys()
Generate the public and private keys.
PackedData HomomorphicAdd(const PackedData &lhs, const PackedData &rhs)
Add two vectors of packed data.
int main(int argc, char *argv[])
std::deque< typename T_CryptoProvider::Ciphertext > PackedData
Define a vector template specialization for vectors of packed data.
The private key container structure for the Dgk cryptosystem.
BigInteger u
- The message space upper bound
PackedData HomomorphicMultiply(const PackedData &lhs, const BigInteger &rhs)
Multiply a vector of packed data with a constant plaintext term.
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
The public key container structure for the Okamoto-Uchiyama cryptosystem.
The public key container structure for the ElGamal cryptosystem.
The private key container structure for the Paillier cryptosystem.
bool IsEncryptedZero(const Ciphertext &ciphertext) const
Determines if ciphertext contains an encryption of 0 or not.
The public key container structure for the Paillier cryptosystem.