Loading [MathJax]/extensions/tex2jax.js
SeComLib
All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
secure_face_recognition_utils/secure_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 */
30 //avoid circular includes
32 
33 namespace SeComLib {
34 namespace SecureFaceRecognitionUtils {
40  SecureComparisonServer::SecureComparisonServer (const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath) :
41  paillierCryptoProvider(paillierCryptoProvider),
42  dgkCryptoProvider(dgkCryptoProvider),
43  dgkComparisonServer(std::make_shared<DgkComparisonServer>(paillierCryptoProvider, dgkCryptoProvider, configurationPath)),
44  l(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath + ".l")),
45  twoPowL(BigInteger(2).GetPow(static_cast<unsigned long>(l))),
46  twoPowMinusLModN(BigInteger(2).GetPowModN(-(static_cast<long>(l)), paillierCryptoProvider.GetEncryptionModulus())),
47  encryptedTwoPowL(paillierCryptoProvider.EncryptInteger(twoPowL)),
48  blindingFactorCache(paillierCryptoProvider, ComparisonBlindingFactorCacheParameters(configurationPath, l)) {
49  }
50 
58  Paillier::Ciphertext z = this->encryptedTwoPowL + a - b;
59 
62 
64 
66  const BlindingFactorContainer &blindingFactorContainer = this->blindingFactorCache.Pop();
67  Paillier::Ciphertext d = z + blindingFactorContainer.encryptedR;
68 
70  d = this->paillierCryptoProvider.RandomizeCiphertext(d);//is this really needed?
71 
73  Paillier::Ciphertext minusDModTwoPowL = this->secureComparisonClient.lock()->ComputeMinusDModTwoPowL(d);
74 
77  Paillier::Ciphertext minusTildeZ = minusDModTwoPowL + blindingFactorContainer.encryptedRModTwoPowL;
78 
87  BigInteger s = RandomProvider::GetInstance().GetRandomInteger(1);
89 
90  /*
91  std::cout << "z: "; this->secureComparisonClient.lock()->DebugPaillierEncryption(z);
92  std::cout << "d%2^l: "; this->secureComparisonClient.lock()->DebugPaillierEncryption(this->paillierCryptoProvider.HomomorphicMultiply(minusDModTwoPowL, -1));
93  std::cout << "r%2^l: "; this->secureComparisonClient.lock()->DebugPaillierEncryption(blindingFactorContainer.encryptedRModTwoPowL);
94  std::cout << "s:" << s.ToString(10) << std::endl;
95  */
96 
98  Paillier::Ciphertext lambda = this->dgkComparisonServer->ComputeLambda(blindingFactorContainer.hatRBits, s);
99 
100  //std::cout << "lambda: "; this->secureComparisonClient.lock()->DebugPaillierEncryption(lambda);
101 
103  Paillier::Ciphertext y = (z + minusDModTwoPowL + blindingFactorContainer.encryptedRModTwoPowL + lambda) * twoPowMinusLModN;
104 
105  return y;
106  }
107 
111  void SecureComparisonServer::SetClient (const std::shared_ptr<SecureComparisonClient> &secureComparisonClient) {
112  this->secureComparisonClient = secureComparisonClient;
113  this->dgkComparisonServer->SetClient(secureComparisonClient->GetDgkComparisonClient());
114  }
115 
119  const std::shared_ptr<DgkComparisonServer> &SecureComparisonServer::GetDgkComparisonServer () const {
120  return this->dgkComparisonServer;
121  }
122 
123 }//namespace SecureFaceRecognitionUtils
124 }//namespace SeComLib
Definition of class SecureComparisonServer.
Implementation of the public-key DGK Cryptosystem.
Definition: dgk.h:104
RandomizerCache< BlindingFactorContainer > blindingFactorCache
Blinding factor cache instance.
virtual Ciphertext RandomizeCiphertext(const Ciphertext &ciphertext) const
Randomize encrypted number with a self-generated random value.
Definition: paillier.cpp:269
SecureComparisonServer(const Paillier &paillierCryptoProvider, const Dgk &dgkCryptoProvider, const std::string &configurationPath)
Constructor.
Definition of class SecureComparisonClient.
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
const std::shared_ptr< DgkComparisonServer > dgkComparisonServer
A reference to the DgkComparisonServer.
const std::shared_ptr< DgkComparisonServer > & GetDgkComparisonServer() const
Getter for this->dgkComparisonServer.
Paillier::Ciphertext Compare(const Paillier::Ciphertext &a, const Paillier::Ciphertext &b)
Interactive secure comparison.
std::weak_ptr< const SecureComparisonClient > secureComparisonClient
A reference to the SecureComparisonClient.
void SetClient(const std::shared_ptr< SecureComparisonClient > &secureComparisonClient)
Setter for this->secureComparisonClient.