SeComLib
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Macros Pages
Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | Static Private Attributes | List of all members
SeComLib::SecureRecommendations::Hub Class Reference

Home hub client. More...

#include <hub.h>

Public Member Functions

 Hub ()
 Default constructor. More...
 
 ~Hub ()
 Destructor - void implementation.
 
const PaillierPublicKeyGetPublicKey () 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 Serverserver
 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< TestDataRowmedicalRelevanceTestData
 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...
 

Detailed Description

Home hub client.

Definition at line 65 of file hub.h.

Constructor & Destructor Documentation

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

Todo:
Throw a custom exception here
Todo:
Throw a custom error.

Definition at line 58 of file hub.cpp.

Member Function Documentation

void SeComLib::SecureRecommendations::Hub::computeSafetyBlockFalsePredictions ( )
private

Computes the number of false negatives and false positives of the safety block.

Todo:
Throw a custom exception here...

Definition at line 653 of file hub.cpp.

void SeComLib::SecureRecommendations::Hub::DebugValue ( const Paillier::Ciphertext value) const

Decrypts and prints an encrypted value.

Parameters
valuean encrypted value

Definition at line 403 of file hub.cpp.

void SeComLib::SecureRecommendations::Hub::DoAccuracyAnalysis ( )

Execute the accuracy analysis of the system.

Sends each test vector to the server to obtain the recommendations and computes the accuracy of the received data.

Prints statistic information.

Exceptions
std::runtime_errorinvalid kernel type

Print statistics

Definition at line 240 of file hub.cpp.

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.

Exceptions
std::runtime_errorinvalid 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

Definition at line 290 of file hub.cpp.

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.

Exceptions
std::runtime_errorinvalid 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

Definition at line 359 of file hub.cpp.

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.

Parameters
numeratorthe value of the numerator
inputthe encrypted denominators. Will be overwritten by the encrypted results of the division

Perform division

Definition at line 218 of file hub.cpp.

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]

Parameters
inputthe 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

Definition at line 165 of file hub.cpp.

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

Parameters
inputthe encrypted SVM values

Decrypt the value

Populate the vector received from the server with RE-RANDOMIZED [0]s and [1]s

Definition at line 133 of file hub.cpp.

std::string SeComLib::SecureRecommendations::Hub::getKernelName ( ) const
private

Returns a string containing the name of the kernel specified in the configuration file.

Returns
a string containing the name of the kernel
Exceptions
std::runtime_errorinvalid kernel type
Todo:
Throw a custom error here

Definition at line 694 of file hub.cpp.

unsigned int SeComLib::SecureRecommendations::Hub::getMedicalRelevanceBlockCorrectPredictionCount ( ) const
private

Computes the number of correct predictions of the medical relevance block.

Returns
The number of correct predictions of the medical relevance block

Definition at line 641 of file hub.cpp.

const PaillierPublicKey & SeComLib::SecureRecommendations::Hub::GetPublicKey ( ) const

Returns a reference to the public key.

Returns
a reference to the public key

Definition at line 113 of file hub.cpp.

unsigned short SeComLib::SecureRecommendations::Hub::getVotedCluster ( const std::vector< Paillier::Ciphertext > &  encryptedClusterVotes) 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.

Parameters
encryptedClusterVotesThe encrypted cluster votes vector
Returns
the index of the cluster containing the maximum number of votes. Return 0 if no maximum was found.

Definition at line 601 of file hub.cpp.

void SeComLib::SecureRecommendations::Hub::loadSafetyTestData ( const std::string &  testFilesDirectory,
const std::string &  safetyTestFilesPrefix 
)
private

Populates the safetyTestData structure.

Populates the safetyTestData structure.

Parameters
testFilesDirectorythe directory of the test files
safetyTestFilesPrefixthe prefix of the safety test files name
Exceptions
std::runtime_errorcan't find test files
Todo:
Throw a custom error.
Todo:
Throw a custom exception here
Todo:
Throw a custom error.

Definition at line 414 of file hub.cpp.

TestDataRow SeComLib::SecureRecommendations::Hub::parseTestDataRow ( const std::string &  line) const
private

Extracts test data from a single line.

Populates a TestDataRow container.

Parameters
linea line from a test data file
Returns
An instance of the TestDataRow container
Exceptions
std::runtime_errorvarious 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

Definition at line 478 of file hub.cpp.

std::vector< unsigned short > SeComLib::SecureRecommendations::Hub::processSafetyPredictions ( const std::vector< Paillier::Ciphertext > &  encryptedSafetyPredictions) const
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.

Parameters
encryptedSafetyPredictionsThe encrypted safety block SVM predictions vector
Returns
the decrypted safety block SVM predictions

Definition at line 625 of file hub.cpp.

void SeComLib::SecureRecommendations::Hub::SetServer ( const std::shared_ptr< const Server > &  server)

Sets a reference to the recommendations server.

Associates the hub with the server instance

Parameters
servera server instance

Definition at line 122 of file hub.cpp.

Member Data Documentation

BigInteger SeComLib::SecureRecommendations::Hub::bitsReceived
staticprivate

Counts the number of bits received from the server.

Initialize the received bits counter

Definition at line 147 of file hub.h.

BigInteger SeComLib::SecureRecommendations::Hub::bitsSent
staticprivate

Counts the numbe of bits sent to the server.

Initialize the sent bits counter

Definition at line 144 of file hub.h.

bool SeComLib::SecureRecommendations::Hub::measureTraffic
staticprivate

Enables traffic profiling.

Disable traffic analysys by thefault

Definition at line 141 of file hub.h.

unsigned long SeComLib::SecureRecommendations::Hub::testVectorCount
private

Contains the number of vectors in the test data file. Since the homogeneous polynomial kernel does not need the x matrix, there should be a variable which maintains the number of elements so that its available for all kernel types.

Definition at line 108 of file hub.h.


The documentation for this class was generated from the following files: