Home hub client. More...
#include <hub.h>
Public Member Functions | |
Hub () | |
Default constructor. More... | |
~Hub () | |
Destructor - void implementation. | |
const PaillierPublicKey & | GetPublicKey () const |
Returns a reference to the public key. More... | |
void | SetServer (const std::shared_ptr< const Server > &server) |
Sets a reference to the recommendations server. More... | |
void | EvaluateSign (SecureSvm::EncryptedVector &input) const |
Secure sign evaluation. More... | |
void | EvaluateMaximum (SecureSvm::EncryptedVector &input) const |
Secure maximum evaluation. More... | |
void | EvaluateDivision (const BigInteger &numerator, SecureSvm::EncryptedVector &input) const |
Secure division evaluation. More... | |
void | DoAccuracyAnalysis () |
Execute the accuracy analysis of the system. More... | |
void | DoPerformanceAnalysis () |
Execute the performance analysis of the system. More... | |
void | DoTrafficAnalysis () |
Execute the traffic analysis of the system. More... | |
void | DebugValue (const Paillier::Ciphertext &value) const |
Decrypts and prints an encrypted value. More... | |
Private Member Functions | |
void | loadSafetyTestData (const std::string &testFilesDirectory, const std::string &safetyTestFilesPrefix) |
Populates the safetyTestData structure. More... | |
TestDataRow | parseTestDataRow (const std::string &line) const |
Extracts test data from a single line. More... | |
unsigned short | getVotedCluster (const std::vector< Paillier::Ciphertext > &encryptedClusterVotes) const |
Returns the cluster index, which corresponds to the maximum. More... | |
std::vector< unsigned short > | processSafetyPredictions (const std::vector< Paillier::Ciphertext > &encryptedSafetyPredictions) const |
Returns the processed predictions of the safety block SVMs. More... | |
unsigned int | getMedicalRelevanceBlockCorrectPredictionCount () const |
Computes the number of correct predictions of the medical relevance block. More... | |
void | computeSafetyBlockFalsePredictions () |
Computes the number of false negatives and false positives of the safety block. More... | |
std::string | getKernelName () const |
Returns a string containing the name of the kernel specified in the configuration file. More... | |
Hub (Hub const &) | |
Copy constructor - not implemented. | |
Hub | operator= (Hub const &) |
Copy assignment operator - not implemented. | |
Static Private Member Functions | |
static void | resetTrafficCounters () |
Resets the traffic counters. | |
Private Attributes | |
Paillier | cryptoProvider |
The crypto provider. | |
std::shared_ptr< const Server > | server |
A reference to the recommendations server. | |
unsigned long | testVectorCount |
unsigned int | attributeCount |
The number of attributes in each test vector of the test data. | |
SecureSvm::KernelTypes | kernel |
The SVM kernel type. We want to pre-compute only the data that is necessary for a particular kernel. | |
BigInteger | featureScalingFactor |
The scaling applied to the test and model vectors \( x_i \) and \( s_i \). | |
BigInteger | svWeightScaling |
The scaling applied to the SVM parameters, \( a_i \) and \( b \). | |
std::vector< TestDataRow > | medicalRelevanceTestData |
The medical relevance block test data. | |
std::vector< std::map < std::string, TestDataRow > > | safetyTestData |
The safety block test data array (vector of collection of rows; each file should have the same number of rows) | |
std::vector< unsigned short > | predictedClusters |
The predicted clusters. | |
std::vector< std::vector < unsigned short > > | predictedQualityOfLifeMatrix |
Vector of predicted quality of life values (contains 0 for negative values and 1 for positive values) | |
std::map< std::string, unsigned int > | safetyBlockFalsePositives |
Vector containing number of false positives per safety SVM. | |
std::map< std::string, unsigned int > | safetyBlockFalseNegatives |
Vector containing number of false negatives per safety SVM. | |
Static Private Attributes | |
static bool | measureTraffic |
Enables traffic profiling. More... | |
static BigInteger | bitsSent |
Counts the numbe of bits sent to the server. More... | |
static BigInteger | bitsReceived |
Counts the number of bits received from the server. More... | |
SeComLib::SecureRecommendations::Hub::Hub | ( | ) |
Default constructor.
Initializes the test vector counter (not all kernels require the x matrix, so wee need to keep track of the number of est vectors)
Generates the crypto provider keys.
Initializes the private members with the configuration data.
Pre-processes the test data.
Generate keys
Set the kernel
Enable traffic measurements
|
private |
void SeComLib::SecureRecommendations::Hub::DebugValue | ( | const Paillier::Ciphertext & | value | ) | const |
void SeComLib::SecureRecommendations::Hub::DoAccuracyAnalysis | ( | ) |
void SeComLib::SecureRecommendations::Hub::DoPerformanceAnalysis | ( | ) |
Execute the performance analysis of the system.
Sends each test vector to the server to obtain the recommendations of the first two blocks and the third one.
Performs the performance analysis of the algorithm.
Prints statistic information.
std::runtime_error | invalid kernel type |
Store the processing time for each input vector
Start the main timer
Simulate client decryption and processing of the received data (but do not store it...)
Store the duration for processing one input vector
Print statistics
void SeComLib::SecureRecommendations::Hub::DoTrafficAnalysis | ( | ) |
Execute the traffic analysis of the system.
Sends each test vector to the server to obtain the recommendations of the first two blocks and the third one.
Performs the traffic analysis of the algorithm.
Prints statistic information.
std::runtime_error | invalid kernel type |
In a real scenario, we only have a single test data file, so we don't want to count the medical safety test files
void SeComLib::SecureRecommendations::Hub::EvaluateDivision | ( | const BigInteger & | numerator, |
SecureSvm::EncryptedVector & | input | ||
) | const |
Secure division evaluation.
Implements step 2 of the interactive secure division protocol.
Decrypts the received denominators, computes \( 1 / D_i \), reencrypts and sets the results back in the input vector.
numerator | the value of the numerator |
input | the encrypted denominators. Will be overwritten by the encrypted results of the division |
Perform division
void SeComLib::SecureRecommendations::Hub::EvaluateMaximum | ( | SecureSvm::EncryptedVector & | input | ) | const |
Secure maximum evaluation.
Implements step 2 of the interactive secure maximum evaluation protocol
Replaces the contents of input with [1] at the location of the maximum and [0] everywhere else.
If the maximum value is detected multiple times, consider that the prediction is wrong by default and return a vector of [0]
input | the encrypted number ov votes for each cluster |
Set the maximum as the first value
Compare maximum with the other values to determine the real maximum
void SeComLib::SecureRecommendations::Hub::EvaluateSign | ( | SecureSvm::EncryptedVector & | input | ) | const |
Secure sign evaluation.
Implements step 2 of the interactive secure comparison protocol.
Replaces the contents of input with \( [1] \) if \( input[i] \geq 0 \) or \( [0] \) otherwise
input | the encrypted SVM values |
Decrypt the value
Populate the vector received from the server with RE-RANDOMIZED [0]s and [1]s
|
private |
|
private |
const PaillierPublicKey & SeComLib::SecureRecommendations::Hub::GetPublicKey | ( | ) | const |
|
private |
Returns the cluster index, which corresponds to the maximum.
Iterates through the encrypted cluster votes vector and identifies the position which holds the value [1].
The input test data cluster labels are indexed starting from 1. We return 0 if the maximum could not be determined.
encryptedClusterVotes | The encrypted cluster votes vector |
|
private |
Populates the safetyTestData structure.
Populates the safetyTestData structure.
testFilesDirectory | the directory of the test files |
safetyTestFilesPrefix | the prefix of the safety test files name |
std::runtime_error | can't find test files |
|
private |
Extracts test data from a single line.
Populates a TestDataRow container.
line | a line from a test data file |
std::runtime_error | various line parsing errors |
Since g++ does not yet support std::regex properly, we'll have to extract the input data the old fashioned way...
Use std::istringstream to manipulate the label data
Parse label data and persist it in our internal vectors.
If the SVM result is negative, then the label must be contained in the model file name (valid values: 0-6) for correct predictions
Build a vector of attributes
Extract the attribute values. Each attribute is stored as index:value, where index >= 1. We assume that each input line does not omit any attribute value (if it's 0), even though libsvm accepts this, so we simply discard the attribute indexes.
Polynomial kernel => need to send the encrypted attributes combinations, \( x_i x_j \), of the test vector, stored as an unraveled upper triangular matrix
RBF kernel => need to send the encrypted squared attributes of the test vector
|
private |
Returns the processed predictions of the safety block SVMs.
Decrypts the safety predictions received from the server.
Compares the descryptions with the unsafe classes of each SVM to determine if the prediction matched the qol label of the test data.
encryptedSafetyPredictions | The encrypted safety block SVM predictions vector |
void SeComLib::SecureRecommendations::Hub::SetServer | ( | const std::shared_ptr< const Server > & | server | ) |
|
staticprivate |
|
staticprivate |
|
staticprivate |
|
private |