SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
secure_extremum_selection/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 #include "client.h"
31 //avoid circular includes
32 #include "server.h"
33 
34 namespace SeComLib {
35 namespace SecureExtremumSelection {
39  const std::string Client::configurationPath("SecureExtremumSelection");
40 
45  testVectorLength(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath + ".testVectorLength")),
46  l(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath + ".l")) {
48 
50 
51  //can't initialize it in the initialization list, because the crypto providers need to generate keys first
52  this->secureExtremumSelectionClient = std::make_shared<SecureExtremumSelectionClient<SecureComparisonServer, SecureComparisonClient>>(this->paillierCryptoProvider, this->dgkCryptoProvider, this->configurationPath);
53  }
54 
60  this->testVector.reserve(this->testVectorLength);
61  for (size_t i = 0; i < this->testVectorLength; ++i) {
62  this->testVector.emplace_back(this->paillierCryptoProvider.EncryptInteger(RandomProvider::GetInstance().GetRandomInteger(this->l)));
63  }
64 
65  //debugging
66  std::cout << "Test vector:" << std::endl;
67  for (size_t i = 0; i < this->testVectorLength; ++i) {
68  this->DebugPaillierEncryption(this->testVector[i]);
69  }
70 
72  Paillier::Ciphertext minimum = this->server->ComputeMinimum(this->testVector);
73  Paillier::Ciphertext maximum = this->server->ComputeMaximum(this->testVector);
74 
75  //debugging
76  std::cout << "Minimum: "; this->DebugPaillierEncryption(minimum);
77  std::cout << "Maximum: "; this->DebugPaillierEncryption(maximum);
78  }
79 
83  void Client::SetServer (const std::shared_ptr<const Server> &server) {
84  this->server = server;
85  this->secureExtremumSelectionClient->SetServer(server->GetSecureExtremumSelectionServer());
86  }
87 
91  const std::shared_ptr<SecureExtremumSelectionClient<SecureComparisonServer, SecureComparisonClient>> &Client::GetSecureExtremumSelectionClient () const {
92  return this->secureExtremumSelectionClient;
93  }
94 
99  std::cout << this->paillierCryptoProvider.DecryptInteger(input).ToString(10) << std::endl;
100  }
101 
102 }//namespace SecureExtremumSelection
103 }//namespace SeComLib
const std::shared_ptr< SecureExtremumSelectionClient< SecureComparisonServer, SecureComparisonClient > > & GetSecureExtremumSelectionClient() const
Getter for this->secureExtremumSelectionClient.
Definition of class Server.
virtual BigInteger DecryptInteger(const Ciphertext &ciphertext) const
Decrypt number.
Definition: paillier.cpp:176
virtual bool GenerateKeys()
Definition: paillier.cpp:105
void DebugPaillierEncryption(const Paillier::Ciphertext &input) const
Decrypts and prints a Paillier encrypted integer.
static const std::string configurationPath
Service Provider configuration path.
virtual T_Ciphertext EncryptInteger(const BigInteger &plaintext) const
Encrypt an integer and apply randomization.
Definition of class Client.
std::shared_ptr< SecureExtremumSelectionClient< SecureComparisonServer, SecureComparisonClient > > secureExtremumSelectionClient
A reference to the SecureExtremumSelectionClient.
void SetServer(const std::shared_ptr< const Server > &server)
Sets a reference to the Privacy Service Provider.
Paillier paillierCryptoProvider
The Paillier crypto provider.
virtual bool GenerateKeys()
Generate the public and private keys.
Definition: dgk.cpp:161
const size_t testVectorLength
The length of the test vector.
std::vector< Paillier::Ciphertext > testVector
The test vector.
std::shared_ptr< const Server > server
A reference to the Server.