Commit 7babb634 authored by Bernard van Gastel's avatar Bernard van Gastel
Browse files

Merge branch '1-coinciding-pseudonymisation-and-decryption-factors' into 'main'

Resolve "Coinciding pseudonymisation and decryption factors"

Closes #1

See merge request ilab/libpep!1
parents 7a3be76d 55dad317
...@@ -17,20 +17,28 @@ GlobalEncryptedPseudonym pep::GeneratePseudonym(const std::string& identity, con ...@@ -17,20 +17,28 @@ GlobalEncryptedPseudonym pep::GeneratePseudonym(const std::string& identity, con
return Encrypt(p, pk); return Encrypt(p, pk);
} }
Scalar MakeFactor(const std::string& secret, const std::string& context) { Scalar MakeFactor(const std::string& type, const std::string& secret, const std::string& context) {
HashSHA512 uhash; HashSHA512 uhash;
SHA512(uhash, secret, "|", context); SHA512(uhash, type, "|", secret, "|", context);
return Scalar::FromHash(uhash); return Scalar::FromHash(uhash);
} }
Scalar MakePseudonymisationFactor(const std::string& secret, const std::string& context) {
return MakeFactor("pseudonym", secret, context);
}
Scalar MakeDecryptionFactor(const std::string& secret, const std::string& context) {
return MakeFactor("decryption", secret, context);
}
LocalEncryptedPseudonym pep::ConvertToLocalPseudonym(GlobalEncryptedPseudonym p, const std::string& secret, const std::string& decryptionContext, const std::string& pseudonimisationContext) { LocalEncryptedPseudonym pep::ConvertToLocalPseudonym(GlobalEncryptedPseudonym p, const std::string& secret, const std::string& decryptionContext, const std::string& pseudonimisationContext) {
Scalar u = MakeFactor(secret, pseudonimisationContext); Scalar u = MakePseudonymisationFactor(secret, pseudonimisationContext);
Scalar t = MakeFactor(secret, decryptionContext); Scalar t = MakeDecryptionFactor(secret, decryptionContext);
return RKS(p, t, u); return RKS(p, t, u);
} }
LocalDecryptionKey pep::MakeLocalDecryptionKey(GlobalSecretKey k, const std::string& secret, const std::string& decryptionContext) { LocalDecryptionKey pep::MakeLocalDecryptionKey(GlobalSecretKey k, const std::string& secret, const std::string& decryptionContext) {
Scalar t = MakeFactor(secret, decryptionContext); Scalar t = MakeDecryptionFactor(secret, decryptionContext);
return t * k; return t * k;
} }
......
...@@ -682,7 +682,7 @@ TEST_CASE("PEP.HighLevelAPI", "[PEP]") { ...@@ -682,7 +682,7 @@ TEST_CASE("PEP.HighLevelAPI", "[PEP]") {
auto decryptionKey = MakeLocalDecryptionKey(secretKey, "very_secret_on_server", "decryption_context"); auto decryptionKey = MakeLocalDecryptionKey(secretKey, "very_secret_on_server", "decryption_context");
auto lp = DecryptLocalPseudonym(lep, decryptionKey); auto lp = DecryptLocalPseudonym(lep, decryptionKey);
auto expected = LocalPseudonym::FromHex("529c6099511d7d91aab86e4b3d2f6b529c76406da586d7aad5038df063997945"); auto expected = LocalPseudonym::FromHex("4854bb37a8f2e9555f317614290cbef72210901e05f0e0a6623e10df30dfa739");
CHECK(lp.hex() == expected.hex()); CHECK(lp.hex() == expected.hex());
CHECK(lp == expected); CHECK(lp == expected);
std::cout << "(decrypted local pseudonym) for '" << id << "': " << lp.hex() << std::endl; std::cout << "(decrypted local pseudonym) for '" << id << "': " << lp.hex() << std::endl;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment