Skip to content

Commit

Permalink
test: use variable for offset and fix test description
Browse files Browse the repository at this point in the history
  • Loading branch information
csirianni committed Dec 9, 2023
1 parent 58215a1 commit 5a503b1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions backend/tests/cryptography.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "cryptography.hpp"
#include "sodium.h"

TEST_CASE("Test hashAndEncryptPassword without leaked byte")
TEST_CASE("Test hashAndEncryptPassword")
{
// generate constants
const std::string password = "TestPass1&";
Expand Down Expand Up @@ -40,18 +40,19 @@ TEST_CASE("Test hashAndEncryptPassword without leaked byte")
{
for (int i = 0; i < 30; ++i)
{
const size_t offset = 1;
// encrypt password
std::string encryptedPasswordStr = cryptography::hashAndEncryptPassword(password, b, 1);
unsigned char encryptedPassword[crypto_core_ristretto255_BYTES + 1];
memcpy(encryptedPassword, encryptedPasswordStr.data(), crypto_core_ristretto255_BYTES + 1);
std::string encryptedPasswordStr = cryptography::hashAndEncryptPassword(password, b, offset);
unsigned char encryptedPassword[crypto_core_ristretto255_BYTES + offset];
memcpy(encryptedPassword, encryptedPasswordStr.data(), crypto_core_ristretto255_BYTES + offset);

// decrypt password
unsigned char decryptedPassword[crypto_core_ristretto255_BYTES + 1];
int result = crypto_scalarmult_ristretto255(decryptedPassword + 1, inverse, encryptedPassword + 1);
unsigned char decryptedPassword[crypto_core_ristretto255_BYTES + offset];
int result = crypto_scalarmult_ristretto255(decryptedPassword + offset, inverse, encryptedPassword + offset);
REQUIRE(result == 0);
memcpy(decryptedPassword, encryptedPassword, 1);
memcpy(decryptedPassword, encryptedPassword, offset);

CHECK(std::memcmp(expectedPoint, decryptedPassword + 1, crypto_core_ristretto255_BYTES) == 0);
CHECK(std::memcmp(expectedPoint, decryptedPassword + offset, crypto_core_ristretto255_BYTES) == 0);
CHECK(expectedPoint[0] == decryptedPassword[0]);
}
}
Expand Down

0 comments on commit 5a503b1

Please sign in to comment.