Skip to content

Commit

Permalink
docs: Make crypto_core.h appear on doxygen.
Browse files Browse the repository at this point in the history
  • Loading branch information
iphydf committed Feb 5, 2022
1 parent 96814c4 commit 9080072
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 74 deletions.
2 changes: 1 addition & 1 deletion .doxygen.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2236,7 +2236,7 @@ INCLUDE_FILE_PATTERNS =
# recursively expanded use the := operator instead of the = operator.
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.

PREDEFINED = DOXYGEN_SKIP
PREDEFINED = DOXYGEN_IGNORE

# If the MACRO_EXPANSION and EXPAND_ONLY_PREDEF tags are set to YES then this
# tag can be used to specify a list of macro names that should be expanded. The
Expand Down
3 changes: 2 additions & 1 deletion .github/scripts/cmake-linux
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,6 @@ cmake -B_build -H. -GNinja \
cmake --build _build --parallel "$NPROC" --target install -- -k 0

cd _build # pushd
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 ||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
cd - # popd
3 changes: 2 additions & 1 deletion .github/scripts/cmake-osx
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,6 @@ cmake -B_build -H. \

cd _build # pushd
make "-j$NPROC" -k install
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6 ||
ctest -j50 --output-on-failure --rerun-failed --repeat until-pass:6
cd - # popd
4 changes: 2 additions & 2 deletions toxav/toxav.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Copyright © 2013-2015 Tox project.
*/

/** @file toxav.h
/** @file
* @brief Public audio/video API for Tox clients.
*
* This API can handle multiple calls. Each call has its state, in very rare
Expand Down Expand Up @@ -832,7 +832,7 @@ bool toxav_groupchat_av_enabled(Tox *tox, uint32_t groupnumber);
#endif

//!TOKSTYLE-
#ifdef DOXYGEN_IGNORE
#ifndef DOXYGEN_IGNORE

typedef Toxav_Err_Call TOXAV_ERR_CALL;
typedef Toxav_Err_New TOXAV_ERR_NEW;
Expand Down
138 changes: 78 additions & 60 deletions toxcore/crypto_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright © 2013 Tox project.
*/

/**
* Functions for the core crypto.
/** @file
* @brief Functions for the core crypto.
*/
#ifndef C_TOXCORE_TOXCORE_CRYPTO_CORE_H
#define C_TOXCORE_TOXCORE_CRYPTO_CORE_H
Expand All @@ -18,171 +18,183 @@ extern "C" {
#endif

/**
* The number of bytes in a Tox public key used for encryption.
* @brief The number of bytes in a Tox public key used for encryption.
*/
#define CRYPTO_PUBLIC_KEY_SIZE 32

/**
* The number of bytes in a Tox secret key used for encryption.
* @brief The number of bytes in a Tox secret key used for encryption.
*/
#define CRYPTO_SECRET_KEY_SIZE 32

/**
* The number of bytes in a shared key computed from public and secret keys.
* @brief The number of bytes in a shared key computed from public and secret keys.
*/
#define CRYPTO_SHARED_KEY_SIZE 32

/**
* The number of bytes in a symmetric key.
* @brief The number of bytes in a symmetric key.
*/
#define CRYPTO_SYMMETRIC_KEY_SIZE CRYPTO_SHARED_KEY_SIZE

/**
* The number of bytes needed for the MAC (message authentication code) in an
* @brief The number of bytes needed for the MAC (message authentication code) in an
* encrypted message.
*/
#define CRYPTO_MAC_SIZE 16

/**
* The number of bytes in a nonce used for encryption/decryption.
* @brief The number of bytes in a nonce used for encryption/decryption.
*/
#define CRYPTO_NONCE_SIZE 24

/**
* The number of bytes in a SHA256 hash.
* @brief The number of bytes in a SHA256 hash.
*/
#define CRYPTO_SHA256_SIZE 32

/**
* The number of bytes in a SHA512 hash.
* @brief The number of bytes in a SHA512 hash.
*/
#define CRYPTO_SHA512_SIZE 64

/**
* A `bzero`-like function which won't be optimised away by the compiler. Some
* compilers will inline `bzero` or `memset` if they can prove that there will
* be no reads to the written data. Use this function if you want to be sure the
* memory is indeed zeroed.
* @brief A `bzero`-like function which won't be optimised away by the compiler.
*
* Some compilers will inline `bzero` or `memset` if they can prove that there
* will be no reads to the written data. Use this function if you want to be
* sure the memory is indeed zeroed.
*/
void crypto_memzero(void *data, size_t length);

/**
* Compute a SHA256 hash (32 bytes).
* @brief Compute a SHA256 hash (32 bytes).
*/
void crypto_sha256(uint8_t *hash, const uint8_t *data, size_t length);

/**
* Compute a SHA512 hash (64 bytes).
* @brief Compute a SHA512 hash (64 bytes).
*/
void crypto_sha512(uint8_t *hash, const uint8_t *data, size_t length);

/**
* Compare 2 public keys of length CRYPTO_PUBLIC_KEY_SIZE, not vulnerable to
* @brief Compare 2 public keys of length @ref CRYPTO_PUBLIC_KEY_SIZE, not vulnerable to
* timing attacks.
*
* @return 0 if both mem locations of length are equal, -1 if they are not.
* @retval 0 if both mem locations of length are equal
* @retval -1 if they are not
*/
int32_t public_key_cmp(const uint8_t *pk1, const uint8_t *pk2);

/**
* Compare 2 SHA512 checksums of length CRYPTO_SHA512_SIZE, not vulnerable to
* @brief Compare 2 SHA512 checksums of length CRYPTO_SHA512_SIZE, not vulnerable to
* timing attacks.
*
* @return 0 if both mem locations of length are equal, -1 if they are not.
*/
int32_t crypto_sha512_cmp(const uint8_t *cksum1, const uint8_t *cksum2);

/**
* Return a random 8 bit integer.
* @brief Return a random 8 bit integer.
*/
uint8_t random_u08(void);

/**
* Return a random 16 bit integer.
* @brief Return a random 16 bit integer.
*/
uint16_t random_u16(void);

/**
* Return a random 32 bit integer.
* @brief Return a random 32 bit integer.
*/
uint32_t random_u32(void);

/**
* Return a random 64 bit integer.
* @brief Return a random 64 bit integer.
*/
uint64_t random_u64(void);

/**
* Return a random 32 bit integer between 0 and upper_bound (excluded).
* @brief Return a random 32 bit integer between 0 and upper_bound (excluded).
*
* On libsodium builds this function guarantees a uniform distribution of possible outputs.
* On vanilla NACL builds this function is equivalent to `random() % upper_bound`.
*/
uint32_t random_range_u32(uint32_t upper_bound);

/**
* Fill the given nonce with random bytes.
* @brief Fill the given nonce with random bytes.
*/
void random_nonce(uint8_t *nonce);

/**
* Fill an array of bytes with random values.
* @brief Fill an array of bytes with random values.
*/
void random_bytes(uint8_t *bytes, size_t length);

/**
* Check if a Tox public key CRYPTO_PUBLIC_KEY_SIZE is valid or not. This
* should only be used for input validation.
* @brief Check if a Tox public key CRYPTO_PUBLIC_KEY_SIZE is valid or not.
*
* This should only be used for input validation.
*
* @return false if it isn't, true if it is.
*/
bool public_key_valid(const uint8_t *public_key);

/**
* Generate a new random keypair. Every call to this function is likely to
* generate a different keypair.
* @brief Generate a new random keypair.
*
* Every call to this function is likely to generate a different keypair.
*/
int32_t crypto_new_keypair(uint8_t *public_key, uint8_t *secret_key);

/**
* Derive the public key from a given secret key.
* @brief Derive the public key from a given secret key.
*/
void crypto_derive_public_key(uint8_t *public_key, const uint8_t *secret_key);

/**
* Encrypt plain text of the given length to encrypted of length +
* CRYPTO_MAC_SIZE using the public key (CRYPTO_PUBLIC_KEY_SIZE bytes) of the
* receiver and the secret key of the sender and a CRYPTO_NONCE_SIZE byte
* nonce.
* @brief Encrypt message to send from secret key to public key.
*
* @return -1 if there was a problem, length of encrypted data if everything
* was fine.
* Encrypt plain text of the given length to encrypted of
* `length + CRYPTO_MAC_SIZE` using the public key (@ref CRYPTO_PUBLIC_KEY_SIZE
* bytes) of the receiver and the secret key of the sender and a
* @ref CRYPTO_NONCE_SIZE byte nonce.
*
* @retval -1 if there was a problem.
* @retval >=0 length of encrypted data if everything was fine.
*/
int32_t encrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce, const uint8_t *plain,
size_t length, uint8_t *encrypted);

/**
* Decrypt encrypted text of the given length to plain text of the given length
* - CRYPTO_MAC_SIZE using the public key (CRYPTO_PUBLIC_KEY_SIZE bytes) of
* the sender, the secret key of the receiver and a CRYPTO_NONCE_SIZE byte
* nonce.
* @brief Decrypt message from public key to secret key.
*
* @return -1 if there was a problem (decryption failed), length of plain text
* data if everything was fine.
* Decrypt encrypted text of the given @p length to plain text of the given
* `length - CRYPTO_MAC_SIZE` using the public key (@ref CRYPTO_PUBLIC_KEY_SIZE
* bytes) of the sender, the secret key of the receiver and a
* @ref CRYPTO_NONCE_SIZE byte nonce.
*
* @retval -1 if there was a problem (decryption failed).
* @retval >=0 length of plain text data if everything was fine.
*/
int32_t decrypt_data(const uint8_t *public_key, const uint8_t *secret_key, const uint8_t *nonce,
const uint8_t *encrypted, size_t length, uint8_t *plain);

/**
* Fast encrypt/decrypt operations. Use if this is not a one-time communication.
* encrypt_precompute does the shared-key generation once so it does not have
* to be performed on every encrypt/decrypt.
* @brief Fast encrypt/decrypt operations.
*
* Use if this is not a one-time communication. @ref encrypt_precompute does the
* shared-key generation once so it does not have to be performed on every
* encrypt/decrypt.
*/
int32_t encrypt_precompute(const uint8_t *public_key, const uint8_t *secret_key, uint8_t *shared_key);

/**
* Encrypts plain of length length to encrypted of length + CRYPTO_MAC_SIZE
* using a shared key CRYPTO_SYMMETRIC_KEY_SIZE big and a CRYPTO_NONCE_SIZE
* @brief Encrypt message with precomputed shared key.
*
* Encrypts plain of length length to encrypted of length + @ref CRYPTO_MAC_SIZE
* using a shared key @ref CRYPTO_SYMMETRIC_KEY_SIZE big and a @ref CRYPTO_NONCE_SIZE
* byte nonce.
*
* @return -1 if there was a problem, length of encrypted data if everything
Expand All @@ -192,9 +204,11 @@ int32_t encrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
uint8_t *encrypted);

/**
* @brief Decrypt message with precomputed shared key.
*
* Decrypts encrypted of length length to plain of length length -
* CRYPTO_MAC_SIZE using a shared key CRYPTO_SHARED_KEY_SIZE big and a
* CRYPTO_NONCE_SIZE byte nonce.
* @ref CRYPTO_MAC_SIZE using a shared key @ref CRYPTO_SHARED_KEY_SIZE big and a
* @ref CRYPTO_NONCE_SIZE byte nonce.
*
* @return -1 if there was a problem (decryption failed), length of plain data
* if everything was fine.
Expand All @@ -203,39 +217,43 @@ int32_t decrypt_data_symmetric(const uint8_t *shared_key, const uint8_t *nonce,
uint8_t *plain);

/**
* Increment the given nonce by 1 in big endian (rightmost byte incremented
* @brief Increment the given nonce by 1 in big endian (rightmost byte incremented
* first).
*/
void increment_nonce(uint8_t *nonce);

/**
* Increment the given nonce by a given number. The number should be in host
* byte order.
* @brief Increment the given nonce by a given number.
*
* The number should be in host byte order.
*/
void increment_nonce_number(uint8_t *nonce, uint32_t increment);

/**
* Fill a key CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes.
* @brief Fill a key @ref CRYPTO_SYMMETRIC_KEY_SIZE big with random bytes.
*/
void new_symmetric_key(uint8_t *key);

/**
* Locks `length` bytes of memory pointed to by `data`. This will attempt to prevent
* the specified memory region from being swapped to disk.
* @brief Locks `length` bytes of memory pointed to by `data`.
*
* This will attempt to prevent the specified memory region from being swapped
* to disk.
*
* Returns true on success.
* @return true on success.
*/
bool crypto_memlock(void *data, size_t length);

/**
* Unlocks `length` bytes of memory pointed to by `data`. This allows the specified
* memory region to be swapped to disk.
* @brief Unlocks `length` bytes of memory pointed to by `data`.
*
* This allows the specified memory region to be swapped to disk.
*
* This function call has the side effect of zeroing the specified memory region
* whether or not it succeeds. Therefore it should only be used once the memory
* is no longer in use.
*
* Returns true on success.
* @return true on success.
*/
bool crypto_memunlock(void *data, size_t length);

Expand Down
12 changes: 6 additions & 6 deletions toxcore/ping_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
* Copyright © 2013 Tox project.
*/

/**
* Implementation of an efficient array to store that we pinged something.
/** @file
* @brief Implementation of an efficient array to store that we pinged something.
*/
#ifndef C_TOXCORE_TOXCORE_PING_ARRAY_H
#define C_TOXCORE_TOXCORE_PING_ARRAY_H
Expand All @@ -21,7 +21,7 @@ extern "C" {
typedef struct Ping_Array Ping_Array;

/**
* Initialize a Ping_Array.
* @brief Initialize a Ping_Array.
*
* @param size represents the total size of the array and should be a power of 2.
* @param timeout represents the maximum timeout in seconds for the entry.
Expand All @@ -31,20 +31,20 @@ typedef struct Ping_Array Ping_Array;
struct Ping_Array *ping_array_new(uint32_t size, uint32_t timeout);

/**
* Free all the allocated memory in a Ping_Array.
* @brief Free all the allocated memory in a @ref Ping_Array.
*/
void ping_array_kill(struct Ping_Array *array);

/**
* Add a data with length to the Ping_Array list and return a ping_id.
* @brief Add a data with length to the @ref Ping_Array list and return a ping_id.
*
* @return ping_id on success, 0 on failure.
*/
uint64_t ping_array_add(struct Ping_Array *array, const struct Mono_Time *mono_time, const uint8_t *data,
uint32_t length);

/**
* Check if ping_id is valid and not timed out.
* @brief Check if @p ping_id is valid and not timed out.
*
* On success, copies the data into data of length,
*
Expand Down

0 comments on commit 9080072

Please sign in to comment.