Skip to content

Commit a927183

Browse files
committed
test: Add a test for encrypting 100MB of data.
Both in C and C++, because the C++ tests don't currently run on FreeBSD, and we want to know how the FreeBSD VM performs (answer: poorly).
1 parent 28f3904 commit a927183

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

auto_tests/crypto_test.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,6 +269,30 @@ static void test_large_data_symmetric(void)
269269
free(m1);
270270
}
271271

272+
static void test_very_large_data(void)
273+
{
274+
const Random *rng = system_random();
275+
ck_assert(rng != nullptr);
276+
277+
uint8_t nonce[CRYPTO_NONCE_SIZE] = {0};
278+
uint8_t pk[CRYPTO_PUBLIC_KEY_SIZE];
279+
uint8_t sk[CRYPTO_SECRET_KEY_SIZE];
280+
crypto_new_keypair(rng, pk, sk);
281+
282+
// 100 MiB of data (all zeroes, doesn't matter what's inside).
283+
const uint32_t plain_size = 100 * 1024 * 1024;
284+
uint8_t *plain = (uint8_t *)malloc(plain_size);
285+
uint8_t *encrypted = (uint8_t *)malloc(plain_size + CRYPTO_MAC_SIZE);
286+
287+
ck_assert(plain != nullptr);
288+
ck_assert(encrypted != nullptr);
289+
290+
encrypt_data(pk, sk, nonce, plain, plain_size, encrypted);
291+
292+
free(encrypted);
293+
free(plain);
294+
}
295+
272296
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
273297
{
274298
uint32_t num1 = 0;
@@ -340,6 +364,7 @@ int main(void)
340364
test_endtoend(); /* waiting up to 15 seconds */
341365
test_large_data();
342366
test_large_data_symmetric();
367+
test_very_large_data();
343368
test_increment_nonce();
344369
test_memzero();
345370

toxcore/crypto_core_test.cc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,30 @@ namespace {
1212

1313
using HmacKey = std::array<uint8_t, CRYPTO_HMAC_KEY_SIZE>;
1414
using Hmac = std::array<uint8_t, CRYPTO_HMAC_SIZE>;
15+
using PublicKey = std::array<uint8_t, CRYPTO_PUBLIC_KEY_SIZE>;
16+
using SecretKey = std::array<uint8_t, CRYPTO_SECRET_KEY_SIZE>;
1517
using ExtPublicKey = std::array<uint8_t, EXT_PUBLIC_KEY_SIZE>;
1618
using ExtSecretKey = std::array<uint8_t, EXT_SECRET_KEY_SIZE>;
1719
using Signature = std::array<uint8_t, CRYPTO_SIGNATURE_SIZE>;
1820
using Nonce = std::array<uint8_t, CRYPTO_NONCE_SIZE>;
1921

22+
TEST(CryptoCore, EncryptLargeData)
23+
{
24+
const Random *rng = system_random();
25+
ASSERT_NE(rng, nullptr);
26+
27+
Nonce nonce{};
28+
PublicKey pk;
29+
SecretKey sk;
30+
crypto_new_keypair(rng, pk.data(), sk.data());
31+
32+
// 100 MiB of data (all zeroes, doesn't matter what's inside).
33+
std::vector<uint8_t> plain(100 * 1024 * 1024);
34+
std::vector<uint8_t> encrypted(plain.size() + CRYPTO_MAC_SIZE);
35+
36+
encrypt_data(pk.data(), sk.data(), nonce.data(), plain.data(), plain.size(), encrypted.data());
37+
}
38+
2039
TEST(CryptoCore, IncrementNonce)
2140
{
2241
Nonce nonce{};

0 commit comments

Comments
 (0)