From 13401bcc248dde60f6d843f93a242355050834db Mon Sep 17 00:00:00 2001 From: Cedric Sirianni Date: Thu, 16 Nov 2023 14:54:27 -0500 Subject: [PATCH] refactor: change encryptPassword to encryptPoint --- backend/src/cryptography.cpp | 2 +- backend/src/cryptography.hpp | 14 ++++++++++++-- backend/src/server.cpp | 2 +- backend/test/cryptography.cpp | 2 +- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/backend/src/cryptography.cpp b/backend/src/cryptography.cpp index 9be6983..af8cfd4 100644 --- a/backend/src/cryptography.cpp +++ b/backend/src/cryptography.cpp @@ -27,7 +27,7 @@ namespace cryptography return result; } - std::string encryptPassword(const unsigned char *point, unsigned char *b) + std::string encryptPoint(const unsigned char *point, unsigned char *b) { // multiply by b unsigned char encryptedPassword[crypto_core_ristretto255_BYTES]; diff --git a/backend/src/cryptography.hpp b/backend/src/cryptography.hpp index f01e6a8..da68ea7 100644 --- a/backend/src/cryptography.hpp +++ b/backend/src/cryptography.hpp @@ -13,6 +13,16 @@ namespace cryptography */ std::vector encrypt(const std::unordered_set &passwords, unsigned char *b); - // TODO add documentation - std::string encryptPassword(const unsigned char *, unsigned char *b); + + /** + * @brief Encrypt the provided point using secret key b. + * + * @param password the point to encrypt + * @param b the secret key + * @return std::string the encrypted password + * + * @warning The password must be hashed to a point before being passed to this function. + * @warning The result of this function is not a string, but a vector of bytes (excluding the null terminator). + */ + std::string encryptPoint(const unsigned char *password, unsigned char *b); } \ No newline at end of file diff --git a/backend/src/server.cpp b/backend/src/server.cpp index 2dfab07..7049a5a 100644 --- a/backend/src/server.cpp +++ b/backend/src/server.cpp @@ -69,7 +69,7 @@ namespace server return response; } - std::string password = cryptography::encryptPassword(reinterpret_cast(user_password.data()), b); + std::string password = cryptography::encryptPoint(reinterpret_cast(user_password.data()), b); response["status"] = "success"; response["userPassword"] = password; response["breachedPasswords"] = passwords; diff --git a/backend/test/cryptography.cpp b/backend/test/cryptography.cpp index 59ad44a..bde6962 100644 --- a/backend/test/cryptography.cpp +++ b/backend/test/cryptography.cpp @@ -47,7 +47,7 @@ TEST_CASE("Test encryptPassword") crypto_core_ristretto255_from_hash(point, hash); // encrypt password - std::string encryptedPasswordStr = cryptography::encryptPassword(point, b); + std::string encryptedPasswordStr = cryptography::encryptPoint(point, b); unsigned char encryptedPassword[crypto_core_ristretto255_BYTES]; std::memcpy(encryptedPassword, encryptedPasswordStr.data(), crypto_core_ristretto255_BYTES);