SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
private_recommendations_utils/secure_comparison_client.cpp
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 */
30 //avoid circular includes
32 
33 namespace SeComLib {
34 namespace PrivateRecommendationsUtils {
41  SecureComparisonClient::SecureComparisonClient (const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath) :
42  paillierCryptoProvider(paillierCryptoProvider),
43  dgkCryptoProvider(dgkCryptoProvider),
44  dgkComparisonClient(std::make_shared<DgkComparisonClient>(paillierCryptoProvider, dgkCryptoProvider)),
45  l(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath + ".l")),
46  twoPowL(BigInteger(2).GetPow(static_cast<unsigned long>(l))) {
47  }
48 
54  BigInteger plaintextZ = this->paillierCryptoProvider.DecryptInteger(z);
55 
57  this->dgkComparisonClient->SetZModTwoPowL(plaintextZ % this->twoPowL);
58 
60  return this->paillierCryptoProvider.EncryptInteger(plaintextZ / this->twoPowL);
61  }
62 
66  void SecureComparisonClient::SetServer (const std::shared_ptr<SecureComparisonServer> &secureComparisonServer) {
67  this->secureComparisonServer = secureComparisonServer;
68  this->dgkComparisonClient->SetServer(secureComparisonServer->GetDgkComparisonServer());
69  }
70 
74  const std::shared_ptr<DgkComparisonClient> &SecureComparisonClient::GetDgkComparisonClient () const {
75  return this->dgkComparisonClient;
76  }
77 
82  std::cout << this->paillierCryptoProvider.DecryptInteger(input).ToString(10) << std::endl;
83  }
84 
85 }//namespace PrivateRecommendationsUtils
86 }//namespace SeComLib
Implementation of the public-key DGK Cryptosystem.
Definition: dgk.h:104
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
Definition: paillier.cpp:176
virtual T_Ciphertext EncryptInteger(const BigInteger &plaintext) const
Encrypt an integer and apply randomization.
Paillier::Ciphertext ComputeZDivTwoPowL(const Paillier::Ciphertext &z) const
Computes .
void SetServer(const std::shared_ptr< SecureComparisonServer > &secureComparisonServer)
Setter for this->secureComparisonServer.
std::shared_ptr< const SecureComparisonServer > secureComparisonServer
A reference to the SecureComparisonServer.
Definition of class SecureComparisonServer.
const std::shared_ptr< DgkComparisonClient > dgkComparisonClient
A reference to the DgkComparisonClient.
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
Definition of class SecureComparisonClient.
SecureComparisonClient(const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath)
Constructor.
void DebugPaillierEncryption(const Paillier::Ciphertext &input) const
Decrypts and prints a Paillier encrypted integer.
const std::shared_ptr< DgkComparisonClient > & GetDgkComparisonClient() const
Getter for this->dgkComparisonClient.