Skip to content

Commit

Permalink
refactor: change encryptPassword to encryptPoint
Browse files Browse the repository at this point in the history
  • Loading branch information
csirianni committed Nov 16, 2023
1 parent 3fe7a05 commit 13401bc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion backend/src/cryptography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
14 changes: 12 additions & 2 deletions backend/src/cryptography.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ namespace cryptography
*/
std::vector<std::string> encrypt(const std::unordered_set<std::string> &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);
}
2 changes: 1 addition & 1 deletion backend/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace server
return response;
}

std::string password = cryptography::encryptPassword(reinterpret_cast<const unsigned char*>(user_password.data()), b);
std::string password = cryptography::encryptPoint(reinterpret_cast<const unsigned char*>(user_password.data()), b);
response["status"] = "success";
response["userPassword"] = password;
response["breachedPasswords"] = passwords;
Expand Down
2 changes: 1 addition & 1 deletion backend/test/cryptography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 13401bc

Please sign in to comment.