Skip to content

Commit

Permalink
tests: add test for aesBuildEncrypted
Browse files Browse the repository at this point in the history
  • Loading branch information
Adrien Béraud committed Dec 4, 2023
1 parent 0592b9f commit e35a11a
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions tests/cryptotester.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,12 @@ void CryptoTester::testAesEncryption() {

CPPUNIT_ASSERT(salt1 != salt2);

auto encrypted11 = dht::crypto::aesBuildEncrypted(encrypted1_data, salt1);
auto encrypted22 = dht::crypto::aesBuildEncrypted(encrypted2_data, salt2);

CPPUNIT_ASSERT(encrypted11 == encrypted1);
CPPUNIT_ASSERT(encrypted22 == encrypted2);

auto key12 = dht::crypto::stretchKey(password, salt1, 256/8);
auto key22 = dht::crypto::stretchKey(password, salt2, 256/8);

Expand All @@ -219,6 +225,18 @@ void CryptoTester::testAesEncryption() {

CPPUNIT_ASSERT(data1 == decrypted1);
CPPUNIT_ASSERT(data2 == decrypted2);

auto encrypted12_data = dht::crypto::aesEncrypt(data1, key12);
auto encrypted22_data = dht::crypto::aesEncrypt(data2, key22);

encrypted11 = dht::crypto::aesBuildEncrypted(encrypted12_data, salt1);
encrypted22 = dht::crypto::aesBuildEncrypted(encrypted22_data, salt2);

decrypted1 = dht::crypto::aesDecrypt(encrypted11, password);
decrypted2 = dht::crypto::aesDecrypt(encrypted22, password);

CPPUNIT_ASSERT(data1 == decrypted1);
CPPUNIT_ASSERT(data2 == decrypted2);
}

void
Expand Down

0 comments on commit e35a11a

Please sign in to comment.