Skip to content

Commit

Permalink
[open-quantum-safe#1823] Add Comments for Doxygen
Browse files Browse the repository at this point in the history
Signed-off-by: Songling Han <[email protected]>
  • Loading branch information
songlingatpan committed Sep 21, 2024
1 parent 7f3fe9c commit d544770
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions src/common/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
extern "C" {
#endif

/**
* @brief Memory allocation and deallocation functions.
*
* These macros provide a unified interface for memory operations,
* using OpenSSL functions when OQS_USE_OPENSSL is defined, and
* standard C library functions otherwise.
*/
#if defined(OQS_USE_OPENSSL)
#ifndef OPENSSL_malloc
# define OPENSSL_malloc(num) \
Expand All @@ -45,14 +52,54 @@ extern void *CRYPTO_malloc(size_t num, const char *file, int line);
extern void *CRYPTO_zalloc(size_t num, const char *file, int line);
extern void CRYPTO_free(void *str, const char *file, int line);
extern char *CRYPTO_strdup(const char *str, const char *file, int line);
/**
* Allocates memory of a given size.
* @param size The size of the memory to be allocated in bytes.
* @return A pointer to the allocated memory.
*/
#define OQS_MEM_malloc(size) OPENSSL_malloc(size)
/**
* Frees the allocated memory.
* @param ptr The pointer to the memory to be freed.
*/
#define OQS_MEM_free(ptr) OPENSSL_free(ptr)
/**
* Allocates memory for an array of elements of a given size.
* @param num_elements The number of elements to allocate.
* @param element_size The size of each element in bytes.
* @return A pointer to the allocated memory.
*/
#define OQS_MEM_calloc(num_elements, element_size) OPENSSL_zalloc((num_elements) * (element_size))
/**
* Duplicates a string.
* @param str The string to be duplicated.
* @return A pointer to the newly allocated string.
*/
#define OQS_MEM_strdup(str) OPENSSL_strdup(str)
#else
/**
* Allocates memory of a given size.
* @param size The size of the memory to be allocated in bytes.
* @return A pointer to the allocated memory.
*/
#define OQS_MEM_malloc(size) malloc(size)
/**
* Frees the allocated memory.
* @param ptr The pointer to the memory to be freed.
*/
#define OQS_MEM_free(ptr) free(ptr)
/**
* Allocates memory for an array of elements of a given size.
* @param num_elements The number of elements to allocate.
* @param element_size The size of each element in bytes.
* @return A pointer to the allocated memory.
*/
#define OQS_MEM_calloc(num_elements, element_size) calloc(num_elements, element_size)
/**
* Duplicates a string.
* @param str The string to be duplicated.
* @return A pointer to the newly allocated string.
*/
#define OQS_MEM_strdup(str) strdup(str)
#endif

Expand Down

0 comments on commit d544770

Please sign in to comment.