35 namespace PrivateRecommendationsDataPacking {
48 paillierCryptoProvider(paillierPublicKey),
49 dgkCryptoProvider(dgkPublicKey),
50 userCount(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath +
".userCount")),
51 itemCount(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath +
".itemCount")),
52 denselyRatedItemCount(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath +
".denselyRatedItemCount")),
53 scaledNormalizedRatingBitSize(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath +
".scaledNormalizedRatingBitSize")),
54 digitsToPreserve(Utils::Config::GetInstance().GetParameter<unsigned int>(configurationPath +
".digitsToPreserve")),
55 kappa(Utils::Config::GetInstance().GetParameter<size_t>(configurationPath +
".BlindingFactorCache.kappa")),
57 similarityTreshold(BigInteger(Utils::Config::GetInstance().GetParameter<double>(configurationPath +
".similarityTreshold"), 2 * digitsToPreserve)) {
59 unsigned long ceilLogBaseTwoR =
static_cast<unsigned long>(std::ceil(std::log(static_cast<double>(this->
denselyRatedItemCount)) / std::log(2.0)));
92 #ifdef FIRST_USER_ONLY
93 std::cout <<
"Warning: running simulation for a single user." << std::endl << std::endl;
94 for (
size_t user = 0; user < 1; ++user) {
96 for (
size_t user = 0; user < this->
userCount; ++user) {
107 size_t bucketCount = 0;
108 for (
size_t i = 0; i < this->
userCount; ++i) {
114 if (0 == bucketCount) {
119 packedBuckets = normalizedScaledRatings[i][item] * (this->
emptyBuckets[bucketCount] << 1);
128 packedBuckets = packedBuckets + normalizedScaledRatings[i][item] * (this->
emptyBuckets[bucketCount] << 1);
134 packedItems.emplace_back(packedBuckets);
144 if (bucketCount > 0) {
145 packedItems.emplace_back(packedBuckets);
149 if (packedItems.size() > 0) {
150 userPackedDenselyRelatedItems.emplace_back(packedItems);
154 std::cout <<
"Packed items for user " << user <<
" in " << userTimer.
ToString() << std::endl;
156 if (userPackedDenselyRelatedItems.size() > 0) {
169 #ifdef FIRST_USER_ONLY
170 for (
size_t user = 0; user < 1; ++user) {
180 packedSimilarityValues.emplace_back(this->
secureMultiplicationServer->Multiply(this->packedNormalizedScaledRatings[user][0][i], normalizedScaledRatings[user][0]));
194 std::cout <<
"Similarity processing: " << similarityTimer.
ToString();
204 size_t rowSimilarityCount = this->
userCount - 1 - user;
205 this->
gamma.emplace_back(this->
secureComparisonServer->Compare(packedSimilarityValues, rowSimilarityCount % this->maxPackedBuckets));
207 std::cout <<
" Gamma processing (" << this->
gamma.back().size() <<
" values): " << gammaTimer.
ToString() <<
" for user " << user << std::endl;
221 #ifdef FIRST_USER_ONLY
222 for (
size_t user = 0; user < 1; ++user) {
224 for (
size_t user = 0; user < this->
userCount; ++user) {
234 for (
size_t encryptionIndex = 0; encryptionIndex < sparseRatings[user].size(); ++encryptionIndex) {
236 userURSum.emplace_back(this->
secureMultiplicationServer->Multiply(sparseRatings[user == 0 ? 1 : 0][encryptionIndex], this->gamma[0][user == 0 ? user : user - 1]));
243 for (
size_t i = (user == 0 ? 2 : 1); i < this->
userCount; ++i) {
246 size_t gammaRow = user < i ? user : i;
247 size_t gammaColumn = user < i ? i - 1 - user : user - 1 - i;
249 L = L + this->
gamma[gammaRow][gammaColumn];
251 for (
size_t encryptionIndex = 0; encryptionIndex < sparseRatings[i].size(); ++encryptionIndex) {
252 userURSum[encryptionIndex] = userURSum[encryptionIndex] + this->
secureMultiplicationServer->Multiply(sparseRatings[i][encryptionIndex], this->gamma[gammaRow][gammaColumn]);
259 std::cout <<
"Generated recommendations for user " << user <<
" in " << recommendationsTimer.
ToString() << std::endl;
269 return this->
LValues.at(userId);
293 for (
size_t encryptionIndex = 0; encryptionIndex < userPackedSparseRatings.size(); ++encryptionIndex) {
294 output.emplace_back(this->
secureMultiplicationServer->Multiply(userPackedSparseRatings[encryptionIndex], this->gamma[userId][0]));
298 for (
size_t i = 1; i < this->
gamma[userId].size(); ++i) {
299 for (
size_t encryptionIndex = 0; encryptionIndex < userPackedSparseRatings.size(); ++encryptionIndex) {
300 output[encryptionIndex] = output[encryptionIndex] + this->
secureMultiplicationServer->Multiply(userPackedSparseRatings[encryptionIndex], this->
gamma[userId][i]);
PaillierCiphertext Ciphertext
Provide public access to the T_Ciphertext type.
const std::shared_ptr< SecureComparisonServer > & GetSecureComparisonServer() const
Getter for this->secureComparisonClient.
void GenerateDummyDatabase(const EncryptedUserDataContainer &normalizedScaledRatings)
Generates a dummy database for the users.
std::deque< BigInteger > emptyBuckets
Empty buckets .
const Paillier::Ciphertext & GetEncryptedL(const size_t userId) const
Returns the value for the specified user.
size_t GetMaxPackedBuckets() const
Getter for the maximum number of packed data buckets.
std::deque< EncryptedUserData > EncryptedUserDataContainer
Container for encrypted user data.
const std::shared_ptr< SecureMultiplicationServer< Paillier > > & GetSecureMultiplicationServer() const
Getter for this->secureMultiplicationServer.
size_t bucketSize
The size of the data buckets (in bits)
EncryptedUserData LValues
Vector of values, where L is the number of users similar to a given user.
The public key container structure for the Dgk cryptosystem.
std::weak_ptr< const PrivacyServiceProvider > privacyServiceProvider
A reference to the PrivacyServiceProvider.
void SetPrivacyServiceProvider(const std::shared_ptr< const PrivacyServiceProvider > &privacyServiceProvider)
Sets a reference to the Privacy Service Provider.
size_t userCount
Number of users who need recommendations.
Dgk dgkCryptoProvider
DGK crypto provider.
PackedItems URSumContainer
Contains the vectors for each user.
Utilitary class providing algorithm timing functionality.
PackedItemContainer packedNormalizedScaledRatings
, where ,
std::string ToString() const
Returns the elapsed user process time as a formatted string (HH::MM::SS.mmm)
std::deque< PackedData > PackedItems
Packed items.
virtual size_t GetMessageSpaceSize() const
Returns the message space bit size.
ServiceProvider(const PaillierPublicKey &paillierPublicKey, const DgkPublicKey &dgkPublicKey)
Constructor.
std::shared_ptr< SecureComparisonServer > secureComparisonServer
A reference to the SecureComparisonServer.
size_t scaledNormalizedRatingBitSize
k - The size of the scaled normalized ratings (in bits) (should be l / 2?)
size_t kappa
The security parameter for the secure comparison protocol (in bits)
Definition of class PrivacyServiceProvider.
std::deque< Paillier::Ciphertext > PackedData
Packed data.
BigInteger similarityTreshold
- Scaled public threshold value for the similarity values
void ComputeUserRecommendations(const PackedItems &sparseRatings)
Computes , and for each user.
EncryptedUserDataContainer gamma
- the encrypted gamma values for every user (the upper triangle of the matrix, excluding the diagona...
Definition of class ServiceProvider.
static const std::string configurationPath
Service Provider configuration path.
size_t denselyRatedItemCount
Number of densely rated items.
size_t maxPackedBuckets
The maximum number of buckets that fit in one encryption.
std::shared_ptr< SecureMultiplicationServer< Paillier > > secureMultiplicationServer
A reference to the SecureMultiplicationServer.
size_t GetBucketSize() const
Getter for the data bucket size.
const PackedData & GetEncryptedURSum(const size_t userId) const
Returns the vector for the specified user.
Paillier paillierCryptoProvider
Paillier crypto provider.
void ComputeSimilarityValues(const EncryptedUserDataContainer &normalizedScaledRatings)
Computes the similarity values between each pair of users for the first items.
The public key container structure for the Paillier cryptosystem.