Squashed 'external/toxcore/c-toxcore/' changes from 640e6cace..e58eb27a8

e58eb27a8 fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.
206ea3530 refactor: Explicitly pass dependencies to constructors.
7cefa93cf fix(toxencryptsave): Wipe salt and passkey after usage.
7c3be2342 refactor: Add file/line to tox-bootstrapd logging.
f84e8cdce refactor: Move loglogdata out of network.c.
390f7db06 refactor: Move random and memory OS-specifics to `os_*` files.
REVERT: 640e6cace fix(toxav): remove extra copy of video frame on encode Tested and works, but there might be alignment issues and other stuff.

git-subtree-dir: external/toxcore/c-toxcore
git-subtree-split: e58eb27a84f9fa0cd996868e079f39e90a5c04b6
This commit is contained in:
Green Sky
2025-11-04 21:18:05 +01:00
parent 54c0a3c874
commit 596ea37298
117 changed files with 1409 additions and 697 deletions

View File

@@ -17,6 +17,7 @@
#include "attributes.h"
#include "mem.h"
#include "tox_random.h"
#ifdef __cplusplus
extern "C" {
@@ -78,44 +79,6 @@ extern "C" {
*/
#define CRYPTO_SHA512_SIZE 64
/** @brief Fill a byte array with random bytes.
*
* This is the key generator callback and as such must be a cryptographically
* secure pseudo-random number generator (CSPRNG). The security of Tox heavily
* depends on the security of this RNG.
*/
typedef void crypto_random_bytes_cb(void *_Nullable obj, uint8_t *_Nonnull bytes, size_t length);
/** @brief Generate a random integer between 0 and @p upper_bound.
*
* Should produce a uniform random distribution, but Tox security does not
* depend on this being correct. In principle, it could even be a non-CSPRNG.
*/
typedef uint32_t crypto_random_uniform_cb(void *_Nullable obj, uint32_t upper_bound);
/** @brief Virtual function table for Random. */
typedef struct Random_Funcs {
crypto_random_bytes_cb *_Nullable random_bytes;
crypto_random_uniform_cb *_Nullable random_uniform;
} Random_Funcs;
/** @brief Random number generator object.
*
* Can be used by test code and fuzzers to make toxcore behave in specific
* well-defined (non-random) ways. Production code ought to use libsodium's
* CSPRNG and use `os_random` below.
*/
typedef struct Random {
const Random_Funcs *_Nullable funcs;
void *_Nullable obj;
} Random;
/** @brief System random number generator.
*
* Uses libsodium's CSPRNG (on Linux, `/dev/urandom`).
*/
const Random *_Nullable os_random(void);
/**
* @brief The number of bytes in an encryption public key used by DHT group chats.
*/
@@ -227,6 +190,11 @@ bool crypto_sha512_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA512_SIZE], const u
*/
bool crypto_sha256_eq(const uint8_t cksum1[_Nonnull CRYPTO_SHA256_SIZE], const uint8_t cksum2[_Nonnull CRYPTO_SHA256_SIZE]);
/**
* @brief Shorter internal name for the RNG type.
*/
typedef Tox_Random Random;
/**
* @brief Return a random 8 bit integer.
*/