SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
secure_recommendations/server.h
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 #ifndef SERVER_HEADER_GUARD
30 #define SERVER_HEADER_GUARD
31 
32 //include our headers
33 #include "utils/config.h"
34 #include "utils/filesystem.h"
35 #include "core/big_integer.h"
36 #include "core/random_provider.h"
37 #include "core/paillier.h"
39 
40 #include "hub.h"
41 #include "secure_svm.h"
42 #include "test_data_row.h"
43 
44 //include C++ libraries
45 #include <string>
46 #include <vector>
47 #include <deque>
48 #include <sstream>
49 #include <stdexcept>
50 
51 namespace SeComLib {
52 using namespace Core;
53 
54 namespace SecureRecommendations {
55  //forward-declare required classes
56  class Hub;
57 
61  //we need a reference to the Server object in the SecureSvm instances, so we make use of shared_from_this() when instantiating SecureSvm
62  class Server : public std::enable_shared_from_this<Server> {
63  public:
65  typedef std::vector<Paillier::Ciphertext> EncryptedSvmValues;
66 
68  typedef std::vector<Paillier::Ciphertext> EncryptedClusterVotes;
69 
71  Server (const PaillierPublicKey &key);
72 
74  ~Server () {}
75 
77  void SetClient (const std::shared_ptr<const Hub> &client);
78 
80  void Initialize ();
81 
83  void InteractiveSecureDivision (const BigInteger &numerator, SecureSvm::EncryptedVector &denominators) const;
84 
86  void GetAccuracyPredictions (Server::EncryptedClusterVotes &clusterVotes, SecureSvm::EncryptedVector &safetyPredictions, const TestDataRow &medicalRelevanceTestData, const std::map<std::string, TestDataRow> &safetyTestData) const;
87 
89  void GetPerformancePredictions (SecureSvm::EncryptedVector &firstTwoBlocksPredictions, SecureSvm::EncryptedVector &SafetyBlockPredictions, const TestDataRow &medicalRelevanceTestData, const std::map<std::string, TestDataRow> &safetyTestData) const;
90 
92  std::vector<std::string> GetSafetyBlockSvmsUnsafeClasses () const;
93 
95  std::deque<std::string> GetSafetyBlockModelFiles () const;
96 
98  void DebugValue (const Paillier::Ciphertext &value) const;
99 
100  private:
102  typedef std::vector<std::pair<size_t, size_t>> PermutationVector;
103 
106  std::weak_ptr<const Hub> client;
107 
110 
113 
116 
118  unsigned int contentItemCount;
119 
121  std::vector<BigInteger> dummyContentItems;
122 
124  std::vector<Paillier::Ciphertext> dummyEncryptedPreferenceScores;
125 
127  unsigned int blindingFactorSize;
128 
130  std::string modelFileExtension;
131 
134 
137 
139  std::deque<std::string> safetySvmModelFiles;
140 
142  std::vector<std::unique_ptr<SecureSvm>> medicalRelevanceSvms;
143 
145  std::vector<std::unique_ptr<SecureSvm>> safetySvms;
146 
149 
152 
155 
158 
160  void loadMedicalRelevanceSvmModels (const std::string &modelsDirectory);
161 
163  void loadSafetySvmModels (const std::string &modelsDirectory);
164 
166  Server::EncryptedClusterVotes getTotalClusterVotes (Server::EncryptedSvmValues &votes) const;
167 
169  void interactiveSignEvaluation (Server::EncryptedSvmValues &data) const;
170 
172  void interactiveMaximumEvaluation (Server::EncryptedClusterVotes &data) const;
173 
175  Server (Server const &);
176 
178  Server operator= (Server const &);
179  };
180 }//namespace SecureRecommendations
181 }//namespace SeComLib
182 
183 #endif//SERVER_HEADER_GUARD
std::vector< Paillier::Ciphertext > EncryptedVector
Define a vector template specialization for vectors of encrypted data.
Definition: secure_svm.h:62
Processed test data container.
Definition: test_data_row.h:40
Paillier::Ciphertext encryptedOne
Precompute [1] for optimization purposes.
std::vector< std::unique_ptr< SecureSvm > > safetySvms
Safety Block SVM models.
std::deque< std::string > safetySvmModelFiles
The safety block model files.
Definition of class SecurePermutation.
std::vector< BigInteger > dummyContentItems
Dummy vector of content items.
std::string medicalRelevanceModelsDirectory
Medical relevance models folder.
Defines BigInteger.
Definition of class Config.
std::vector< Paillier::Ciphertext > EncryptedClusterVotes
Container for the encrypted cluster votes.
SecureSvm::KernelTypes kernel
The SVM kernel type.
Definition of class Hub.
PaillierPublicKey clientPublicKey
The client public key.
unsigned int contentItemCount
The number of content items.
std::vector< std::unique_ptr< SecureSvm > > medicalRelevanceSvms
Medical Relevance Block SVM models.
Definition of class SecureSvm.
unsigned int medicalRelevanceClusterCount
Number of clusters for the Medical Relevance Block.
Definition of class Filesystem.
Implementation of the public-key Paillier Cryptosystem.
Definition: paillier.h:103
Definition of struct TestDataRow.
KernelTypes
Types of implemented kernels.
Definition: secure_svm.h:68
std::vector< Paillier::Ciphertext > EncryptedSvmValues
Vector of encrypted SVM evaluations.
unsigned int blindingFactorSize
The maximum size of the blinding factors.
std::string modelFileExtension
The model files extension.
Defines RandomProvider.
std::vector< std::pair< size_t, size_t > > PermutationVector
Define the permutation map container.
Server::EncryptedClusterVotes encryptedClusterVotes
Stores the number of votes received for each cluster after evaluating the SVMs.
std::vector< Paillier::Ciphertext > dummyEncryptedPreferenceScores
Dummy vector of encrypted preference scores.
Definition of class Paillier.
std::string safetyModelsDirectory
The full path to the safety block models directory.
Paillier::Ciphertext encryptedZero
Precompute [0] for optimization purposes.
The public key container structure for the Paillier cryptosystem.
Definition: paillier.h:49