SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
secure_face_recognition_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 SecureFaceRecognitionUtils {
40  DgkComparisonClient::DgkComparisonClient (const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath) :
41  paillierCryptoProvider(paillierCryptoProvider),
42  dgkCryptoProvider(dgkCryptoProvider),
43  l(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath + ".l")),
44  encryptedMinusTwoPowL(paillierCryptoProvider.EncryptIntegerNonrandom(BigInteger(-1) << static_cast<unsigned long>(l))) {
45  }
46 
50  void DgkComparisonClient::SetHatD (const BigInteger &hatD) {
51  this->hatD = hatD;
52  }
53 
57  std::deque<Dgk::Ciphertext> DgkComparisonClient::GetHatDBits () const {
58  std::deque<Dgk::Ciphertext> hatDBits;
59 
61  for (size_t i = 0; i < this->l; ++i) {
62  hatDBits.emplace_back(this->dgkCryptoProvider.EncryptInteger(BigInteger(static_cast<long>(this->hatD.GetBit(i)))));
63  }
64 
65  return hatDBits;
66  }
67 
72  Paillier::Ciphertext DgkComparisonClient::ComputeLambda (const std::deque<Dgk::Ciphertext> &e) const {
74 
75  for (size_t i = 0; i < this->l + 1; ++i) {
76  if (this->dgkCryptoProvider.IsEncryptedZero(e[i])) {
79  }
80  }
81 
84  }
85 
89  void DgkComparisonClient::SetServer (const std::shared_ptr<DgkComparisonServer> &dgkComparisonServer) {
90  this->dgkComparisonServer = dgkComparisonServer;
91  }
92 
97  std::cout << !this->dgkCryptoProvider.IsEncryptedZero(input) << std::endl;
98  }
99 
100 }//namespace SecureFaceRecognitionUtils
101 }//namespace SeComLib
Implementation of the public-key DGK Cryptosystem.
Definition: dgk.h:104
Definition of class DgkComparisonClient.
Ciphertext GetEncryptedZero(const bool randomized=true) const
Returns [0].
const Paillier & paillierCryptoProvider
Reference to the Paillier crypto provider.
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: paillier.cpp:269
Paillier::Ciphertext ComputeLambda(const std::deque< Dgk::Ciphertext > &e) const
Computes .
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
void DebugDgkEncryption(const Dgk::Ciphertext &input) const
Prints 0 if the received encryption is [0] and 1 otherwise.
void SetHatD(const BigInteger &hatD)
Set before the comparison protocol is initiated.
Definition of class DgkComparisonServer.
DgkComparisonClient(const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath)
Constructor.
std::deque< Dgk::Ciphertext > GetHatDBits() const
Computes the encrypted bits of .
void SetServer(const std::shared_ptr< DgkComparisonServer > &dgkComparisonServer)
Setter for this->dgkComparisonServer.
std::shared_ptr< const DgkComparisonServer > dgkComparisonServer
A reference to the DgkComparisonServer.