Skip to content

Commit

Permalink
feat: update server for password with offset
Browse files Browse the repository at this point in the history
  • Loading branch information
ni-jessica authored and csirianni committed Dec 9, 2023
1 parent ceb434e commit 832e03b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions backend/src/cryptography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ namespace cryptography

std::string encryptPassword(const std::string &password, unsigned char *b, int offset)
{
// encrypt password
const unsigned char *data = (const unsigned char *)password.data();
unsigned char encryptedPassword[crypto_core_ristretto255_BYTES + offset];
crypto_scalarmult_ristretto255(encryptedPassword + offset, b, data);
memcpy(encryptedPassword, data, offset);
return std::string(encryptedPassword, encryptedPassword + crypto_core_ristretto255_BYTES+offset);
std::string rawPassword = password.substr(offset, crypto_core_ristretto255_BYTES);

This comment has been minimized.

Copy link
@csirianni

csirianni Dec 9, 2023

Owner

thought: Not sure using substring is going to work because one byte does not always correspond to one letter.

const unsigned char *data = (const unsigned char *)rawPassword.data();
unsigned char encryptedPassword[crypto_core_ristretto255_BYTES];
crypto_scalarmult_ristretto255(encryptedPassword, b, data);
return std::string(encryptedPassword, encryptedPassword + crypto_core_ristretto255_BYTES);
}

std::vector<std::string> encrypt(const std::unordered_set<std::string> &passwords, unsigned char *b, int offset)
Expand Down
2 changes: 1 addition & 1 deletion backend/src/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ namespace server
int offset = 1;
std::string encrypted_password = cryptography::encryptPassword(crow::utility::base64decode(user_password, user_password.size()), b, offset);
response["status"] = "success";
response["userPassword"] = crow::utility::base64encode(encrypted_password, encrypted_password.size()+offset);
response["userPassword"] = crow::utility::base64encode(encrypted_password, encrypted_password.size());
response["breachedPasswords"] = breached_passwords;

return response; });
Expand Down

0 comments on commit 832e03b

Please sign in to comment.