SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
secure_face_recognition_utils/dgk_comparison_server.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_server.h"
30 //avoid circular includes
31 #include "dgk_comparison_client.h"
32 
33 namespace SeComLib {
34 namespace SecureFaceRecognitionUtils {
40  DgkComparisonServer::DgkComparisonServer (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  blindingFactorCache(dgkCryptoProvider, DgkComparisonBlindingFactorCacheParameters(configurationPath, l + 1)) {
46  }
47 
54  Paillier::Ciphertext DgkComparisonServer::ComputeLambda (const std::deque<long> &hatRBits, const BigInteger &s) {
56 
58  std::deque<Dgk::Ciphertext> hatDBits = this->dgkComparisonClient.lock()->GetHatDBits();
59 
60  const BlindingFactorContainer &blindingFactorContainer = this->blindingFactorCache.Pop();
61 
63  std::deque<Dgk::Ciphertext> e;
64 
66  if (s == hatRBits[l - 1]) {
68 
70  if (hatRBits[l - 1] == 0) {
72  e.emplace_front((hatDBits[l - 1] - this->dgkCryptoProvider.GetEncryptedOne(false)) * blindingFactorContainer.R[l]);
73  }
74  else {
76  e.emplace_front(hatDBits[l - 1] * blindingFactorContainer.R[l]);//the indexes in R are shifted by one
77  }
79  e.front() = this->dgkCryptoProvider.RandomizeCiphertext(e.front());
80  }
81  else {
83  e.emplace_front(blindingFactorContainer.encryptedR[l]);//the indexes in encryptedR are shifted by one
84  }
85 
87  Dgk::Ciphertext sigma = hatRBits[l - 1] == 0 ? hatDBits[l - 1] : (this->dgkCryptoProvider.GetEncryptedOne(false) - hatDBits[l - 1]);
88  //can't use size_t because the stop condition requires i = -1
89  for (long i = static_cast<long>(this->l - 2); i >= 0; --i) {
91  if (s == hatRBits[i]) {
93  Dgk::Ciphertext c = hatDBits[i] + sigma;
94 
95  if (s == 0) {
97  c = c - this->dgkCryptoProvider.GetEncryptedOne(false) + sigma;
98  }
99 
101  e.emplace_front(c * blindingFactorContainer.R[i + 1]);//the indexes in R are shifted by one
102  e.front() = this->dgkCryptoProvider.RandomizeCiphertext(e.front());
103  }
104  else {
106  e.emplace_front(blindingFactorContainer.encryptedR[i + 1]);//the indexes in encryptedR are shifted by one
107  }
108 
110  sigma = sigma + (hatRBits[i] == 0 ? hatDBits[i] : (this->dgkCryptoProvider.GetEncryptedOne(false) - hatDBits[i]));
111  }
112 
120  if (s == 1) {
122  e.emplace_front(blindingFactorContainer.encryptedR[0]);//the indexes in encryptedR are shifted by one
123  }
124  else {
126  e.emplace_front(sigma * blindingFactorContainer.R[0]);//the indexes in R are shifted by one
127  e.front() = this->dgkCryptoProvider.RandomizeCiphertext(e.front());//is this really necessary?
128  }
129 
131  SecurePermutation permutation(e.size());
132  permutation.Permute(e);
133 
134  Paillier::Ciphertext lambda = this->dgkComparisonClient.lock()->ComputeLambda(e);
135 
136  if (s == 0) {
138  lambda = this->encryptedMinusTwoPowL - lambda;
139  }
140 
141  return lambda;
142  }
143 
147  void DgkComparisonServer::SetClient (const std::shared_ptr<DgkComparisonClient> &dgkComparisonClient) {
148  this->dgkComparisonClient = dgkComparisonClient;
149  }
150 
151 }//namespace SecureFaceRecognitionUtils
152 }//namespace SeComLib
Implementation of the public-key DGK Cryptosystem.
Definition: dgk.h:104
Ciphertext GetEncryptedOne(const bool randomized=true) const
Returns [1].
Definition of class DgkComparisonClient.
virtual Ciphertext RandomizeCiphertext(const Ciphertext &ciphertext) const
Randomize encrypted number with a self-generated random value.
Definition: dgk.cpp:437
std::weak_ptr< const DgkComparisonClient > dgkComparisonClient
A reference to the DgkComparisonClient.
void SetClient(const std::shared_ptr< DgkComparisonClient > &dgkComparisonClient)
Setter for this->dgkComparisonClient.
Paillier::Ciphertext ComputeLambda(const std::deque< long > &hatRBits, const BigInteger &s)
Compute .
RandomizerCache< BlindingFactorContainer > blindingFactorCache
Blinding factor cache instance.
DgkComparisonServer(const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath)
Constructor.
Permutation class which implements the Fisher-Yates (Knuth) shuffle algorithm.
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
Definition of class DgkComparisonServer.
void Permute(T_DataType &vector) const
Applies the permutations to the input vector.