Squashed 'external/toxcore/c-toxcore/' changes from 67badf694..82460b212
82460b212 feat: add ngc events 24b54722a fix: Ensure we have allocators available for the error paths. 48dbcfebc cleanup: Remove redundant `-DSODIUM_EXPORT` from definitions. 0cef46ee9 cleanup: Fix a few more clang-tidy warnings. 0c5b918e9 cleanup: Fix a few more clang-tidy warnings. 4d3c97f49 cleanup: Enforce stricter identifier naming using clang-tidy. a549807df refactor: Add `mem` module to allow tests to override allocators. 6133fb153 chore: Add devcontainer setup for codespaces. 620e07ecd chore: Set a timeout for tests started using Conan c0ec33b16 chore: Migrate Windows CI from Appveyor to Azure DevOps 8ed47f3ef fix incorrect documentation a1e245841 docs: Fix doxygen config and remove some redundant comments. b0f633185 chore: Fix the Android CI job 7469a529b fix: Add missing `#include <array>`. 2b1a6b0d2 add missing ngc constants getter declarations and definitions 2e02d5637 chore: Add missing module dependencies. REVERT: 67badf694 feat: add ngc events git-subtree-dir: external/toxcore/c-toxcore git-subtree-split: 82460b2124216af1ac9d63060de310a682a2fd15
This commit is contained in:
@ -9,9 +9,7 @@
|
||||
|
||||
static void rand_bytes(const Random *rng, uint8_t *b, size_t blen)
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < blen; i++) {
|
||||
for (size_t i = 0; i < blen; i++) {
|
||||
b[i] = random_u08(rng);
|
||||
}
|
||||
}
|
||||
@ -84,19 +82,18 @@ static void test_known(void)
|
||||
{
|
||||
uint8_t c[147];
|
||||
uint8_t m[131];
|
||||
uint16_t clen, mlen;
|
||||
|
||||
ck_assert_msg(sizeof(c) == sizeof(m) + CRYPTO_MAC_SIZE * sizeof(uint8_t),
|
||||
"cyphertext should be CRYPTO_MAC_SIZE bytes longer than plaintext");
|
||||
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
|
||||
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
|
||||
|
||||
clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
const uint16_t clen = encrypt_data(bobpk, alicesk, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
|
||||
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
|
||||
ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length");
|
||||
|
||||
mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
const uint16_t mlen = decrypt_data(bobpk, alicesk, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
|
||||
ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
|
||||
ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length");
|
||||
@ -107,7 +104,6 @@ static void test_fast_known(void)
|
||||
uint8_t k[CRYPTO_SHARED_KEY_SIZE];
|
||||
uint8_t c[147];
|
||||
uint8_t m[131];
|
||||
uint16_t clen, mlen;
|
||||
|
||||
encrypt_precompute(bobpk, alicesk, k);
|
||||
|
||||
@ -116,12 +112,12 @@ static void test_fast_known(void)
|
||||
ck_assert_msg(sizeof(test_c) == sizeof(c), "sanity check failed");
|
||||
ck_assert_msg(sizeof(test_m) == sizeof(m), "sanity check failed");
|
||||
|
||||
clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
const uint16_t clen = encrypt_data_symmetric(k, test_nonce, test_m, sizeof(test_m) / sizeof(uint8_t), c);
|
||||
|
||||
ck_assert_msg(memcmp(test_c, c, sizeof(c)) == 0, "cyphertext doesn't match test vector");
|
||||
ck_assert_msg(clen == sizeof(c) / sizeof(uint8_t), "wrong ciphertext length");
|
||||
|
||||
mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
const uint16_t mlen = decrypt_data_symmetric(k, test_nonce, test_c, sizeof(test_c) / sizeof(uint8_t), m);
|
||||
|
||||
ck_assert_msg(memcmp(test_m, m, sizeof(m)) == 0, "decrypted text doesn't match test vector");
|
||||
ck_assert_msg(mlen == sizeof(m) / sizeof(uint8_t), "wrong plaintext length");
|
||||
@ -275,10 +271,10 @@ static void test_large_data_symmetric(void)
|
||||
|
||||
static void increment_nonce_number_cmp(uint8_t *nonce, uint32_t num)
|
||||
{
|
||||
uint32_t num1, num2;
|
||||
uint32_t num1 = 0;
|
||||
memcpy(&num1, nonce + (CRYPTO_NONCE_SIZE - sizeof(num1)), sizeof(num1));
|
||||
num1 = net_ntohl(num1);
|
||||
num2 = num + num1;
|
||||
uint32_t num2 = num + num1;
|
||||
|
||||
if (num2 < num1) {
|
||||
for (uint16_t i = CRYPTO_NONCE_SIZE - sizeof(num1); i != 0; --i) {
|
||||
@ -299,11 +295,9 @@ static void test_increment_nonce(void)
|
||||
const Random *rng = system_random();
|
||||
ck_assert(rng != nullptr);
|
||||
|
||||
uint32_t i;
|
||||
|
||||
uint8_t n[CRYPTO_NONCE_SIZE];
|
||||
|
||||
for (i = 0; i < CRYPTO_NONCE_SIZE; ++i) {
|
||||
for (uint32_t i = 0; i < CRYPTO_NONCE_SIZE; ++i) {
|
||||
n[i] = random_u08(rng);
|
||||
}
|
||||
|
||||
@ -311,13 +305,13 @@ static void test_increment_nonce(void)
|
||||
|
||||
memcpy(n1, n, CRYPTO_NONCE_SIZE);
|
||||
|
||||
for (i = 0; i < (1 << 18); ++i) {
|
||||
for (uint32_t i = 0; i < (1 << 18); ++i) {
|
||||
increment_nonce_number_cmp(n, 1);
|
||||
increment_nonce(n1);
|
||||
ck_assert_msg(memcmp(n, n1, CRYPTO_NONCE_SIZE) == 0, "Bad increment_nonce function");
|
||||
}
|
||||
|
||||
for (i = 0; i < (1 << 18); ++i) {
|
||||
for (uint32_t i = 0; i < (1 << 18); ++i) {
|
||||
const uint32_t r = random_u32(rng);
|
||||
increment_nonce_number_cmp(n, r);
|
||||
increment_nonce_number(n1, r);
|
||||
@ -331,9 +325,8 @@ static void test_memzero(void)
|
||||
memcpy(src, test_c, sizeof(test_c));
|
||||
|
||||
crypto_memzero(src, sizeof(src));
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < sizeof(src); i++) {
|
||||
for (size_t i = 0; i < sizeof(src); i++) {
|
||||
ck_assert_msg(src[i] == 0, "Memory is not zeroed");
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user