SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
private_recommendations_utils/dgk_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 */
29 #include "dgk_comparison_client.h"
30 //avoid circular includes
31 #include "dgk_comparison_server.h"
32 
33 namespace SeComLib {
34 namespace PrivateRecommendationsUtils {
39  DgkComparisonClient::DgkComparisonClient (const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider) :
40  paillierCryptoProvider(paillierCryptoProvider),
41  dgkCryptoProvider(dgkCryptoProvider) {
42  }
43 
47  void DgkComparisonClient::SetZModTwoPowL (const BigInteger &zModTwoPowL) {
48  this->b = zModTwoPowL;
49  }
50 
56  Dgk::Ciphertext DgkComparisonClient::GetTb (const Dgk::Ciphertext &tau, const size_t i) const {
57  Dgk::Ciphertext tb;
58 
60  if (this->b.GetBit(i) == 0) {
62  tb = this->dgkCryptoProvider.GetEncryptedZero(false);
63  }
64  else {
65  // @f$ \llbracket tb \rrbracket = \llbracket \tau \rrbracket @f$
66  tb = tau;
67  }
68 
70 
71  return tb;
72  }
73 
79  return this->dgkCryptoProvider.EncryptInteger(BigInteger(static_cast<long>(this->b.GetBit(i))));
80  }
81 
88  if (this->dgkCryptoProvider.IsEncryptedZero(dgkCiphertext)) {
90  }
91  else {
93  }
94  }
95 
101  int decryptedCiPSP;
102  if (this->dgkCryptoProvider.IsEncryptedZero(CiPSP)) {
103  decryptedCiPSP = 0;
104  }
105  else {
106  decryptedCiPSP = 1;
107  }
108 
110  int diPSP = this->b.GetBit(this->dgkComparisonServer->GetMSBPosition()) ^ decryptedCiPSP;
111 
112  if (diPSP == 0) {
114  }
115  else {
117  }
118  }
119 
123  void DgkComparisonClient::SetServer (const std::shared_ptr<DgkComparisonServer> &dgkComparisonServer) {
124  this->dgkComparisonServer = dgkComparisonServer;
125  }
126 
131  std::cout << !this->dgkCryptoProvider.IsEncryptedZero(input) << std::endl;
132  }
133 
134 }//namespace PrivateRecommendationsUtils
135 }//namespace SeComLib
DgkCiphertext Ciphertext
Provide public access to the T_Ciphertext type.
Implementation of the public-key DGK Cryptosystem.
Definition: dgk.h:104
Ciphertext GetEncryptedOne(const bool randomized=true) const
Returns [1].
Ciphertext GetEncryptedZero(const bool randomized=true) const
Returns [0].
DgkComparisonClient(const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider)
Constructor.
Paillier::Ciphertext ConvertToPaillier(const Dgk::Ciphertext &dgkCiphertext) const
Converts to .
Paillier::Ciphertext ComputeDiPSP(const Dgk::Ciphertext &CiPSP) const
Computes .
virtual T_Ciphertext EncryptInteger(const BigInteger &plaintext) const
Encrypt an integer and apply randomization.
virtual Ciphertext RandomizeCiphertext(const Ciphertext &ciphertext) const
Randomize encrypted number with a self-generated random value.
Definition: dgk.cpp:437
Definition of class DgkComparisonServer.
Dgk::Ciphertext GetBi(const size_t i) const
Extracts bit i from and encrypts it.
const Paillier & paillierCryptoProvider
Reference to the Paillier crypto provider.
bool IsEncryptedZero(const Ciphertext &ciphertext) const
Determines if ciphertext contains an encryption of 0 or not.
Definition: dgk.cpp:463
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
std::shared_ptr< const DgkComparisonServer > dgkComparisonServer
A reference to the DgkComparisonServer.
void DebugDgkEncryption(const Dgk::Ciphertext &input) const
Prints 0 if the received encryption is [0] and 1 otherwise.
Definition of class DgkComparisonClient.
void SetServer(const std::shared_ptr< DgkComparisonServer > &dgkComparisonServer)
Setter for this->dgkComparisonServer.
Dgk::Ciphertext GetTb(const Dgk::Ciphertext &tau, const size_t i) const
Computes for .
void SetZModTwoPowL(const BigInteger &zModTwoPowL)
Set before the comparison protocol is initiated.