CJOSE  0.6.0
Macros | Typedefs | Functions
util.h File Reference

Utility functions and data structures for CJOSE. More...

#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <openssl/rsa.h>

Go to the source code of this file.

Macros

#define CJOSE_OPENSSL_11X   OPENSSL_VERSION_NUMBER >= 0x10100005L && !defined(LIBRESSL_VERSION_NUMBER)
 
#define CJOSE_UNUSED_PARAM(x)   (void)(x)
 

Typedefs

typedef void *(* cjose_alloc_fn_t) (size_t)
 
typedef void *(* cjose_alloc3_fn_t) (size_t, const char *, int)
 
typedef void *(* cjose_realloc_fn_t) (void *, size_t)
 
typedef void *(* cjose_realloc3_fn_t) (void *, size_t, const char *, int)
 
typedef void(* cjose_dealloc_fn_t) (void *)
 
typedef void(* cjose_dealloc3_fn_t) (void *, const char *, int)
 

Functions

void cjose_set_alloc_funcs (cjose_alloc_fn_t alloc, cjose_realloc_fn_t realloc, cjose_dealloc_fn_t dealloc)
 
void cjose_set_alloc_ex_funcs (cjose_alloc3_fn_t alloc3, cjose_realloc3_fn_t realloc3, cjose_dealloc3_fn_t dealloc3)
 
cjose_alloc_fn_t cjose_get_alloc ()
 
cjose_alloc3_fn_t cjose_get_alloc3 ()
 
cjose_realloc_fn_t cjose_get_realloc ()
 
cjose_realloc3_fn_t cjose_get_realloc3 ()
 
cjose_dealloc_fn_t cjose_get_dealloc ()
 
cjose_dealloc3_fn_t cjose_get_dealloc3 ()
 
int cjose_const_memcmp (const uint8_t *a, const uint8_t *b, const size_t size)
 

Detailed Description

Utility functions and data structures for CJOSE.

Macro Definition Documentation

◆ CJOSE_UNUSED_PARAM

#define CJOSE_UNUSED_PARAM (   x)    (void)(x)

Macro to explicitly mark a parameter unused, and usable across multiple compiler/platform environments.

Typedef Documentation

◆ cjose_alloc3_fn_t

typedef void*(* cjose_alloc3_fn_t) (size_t, const char *, int)

Typedef for the enhanced memory allocator function.

◆ cjose_alloc_fn_t

typedef void*(* cjose_alloc_fn_t) (size_t)

Typedef for the basic memory allocator function.

◆ cjose_dealloc3_fn_t

typedef void(* cjose_dealloc3_fn_t) (void *, const char *, int)

Typedef for the enhanced memory deallocator function.

◆ cjose_dealloc_fn_t

typedef void(* cjose_dealloc_fn_t) (void *)

Typedef for the basic memory deallocator function.

◆ cjose_realloc3_fn_t

typedef void*(* cjose_realloc3_fn_t) (void *, size_t, const char *, int)

Typedef for the enhanced memory reallocator function.

◆ cjose_realloc_fn_t

typedef void*(* cjose_realloc_fn_t) (void *, size_t)

Typedef for the basic memory reallocator function.

Function Documentation

◆ cjose_const_memcmp()

int cjose_const_memcmp ( const uint8_t *  a,
const uint8_t *  b,
const size_t  size 
)

Compares the first n bytes of the memory areas s1 and s2 in constant time.

Parameters
a[in] The first octet string to compare
b[in] The second octet string to compare
size[in] The length to compare
Returns
an integer less than, equal to, or greater than zero if the first n bytes of s1 is found, respectively, to be less than, to match, or be greater than the first n bytes of s2

◆ cjose_get_alloc()

cjose_alloc_fn_t cjose_get_alloc ( )

Retrieves the configured allocator function. If an allocator function is not set, this function returns a pointer to malloc().

Returns
The configured allocator function

◆ cjose_get_alloc3()

cjose_alloc3_fn_t cjose_get_alloc3 ( )

Retrieves the configured enhanced allocator function. If an enhanced allocator function is not set, this function returns a pointer to an internally defined variant that wraps the basic allocator returned by cjose_get_alloc().

Returns
The configured enhanced allocator function

◆ cjose_get_dealloc()

cjose_dealloc_fn_t cjose_get_dealloc ( )

Retrieves the configured deallocator function. If a deallocator function is not set, this function returns a pointer to free().

Returns
The configured deallocator function

◆ cjose_get_dealloc3()

cjose_dealloc3_fn_t cjose_get_dealloc3 ( )

Retrieves the configured enhanced deallocator function. If an enhanced deallocator function is not set, this function returns a pointer to an internally defined variant that wraps the basic allocator returned by cjose_get_dealloc().

Returns
The configured enhanced allocator function

◆ cjose_get_realloc()

cjose_realloc_fn_t cjose_get_realloc ( )

Retrieve the configured reallocator function. If a reallocator function is not set, this function retursn a pointer to realloc.

Returns
The configured reallocator function

◆ cjose_get_realloc3()

cjose_realloc3_fn_t cjose_get_realloc3 ( )

Retrieves the configured enhanced reallocator function. If an enhanced reallocator function is not set, this function returns a pointer to an internally defined variant that wraps the basic allocator returned by cjose_get_realloc().

Returns
The configured enhanced allocator function

◆ cjose_set_alloc_ex_funcs()

void cjose_set_alloc_ex_funcs ( cjose_alloc3_fn_t  alloc3,
cjose_realloc3_fn_t  realloc3,
cjose_dealloc3_fn_t  dealloc3 
)

Sets the enhanced allocator and deallocator functions. This function provides improved support for OpenSSL >= 1.1.x.

NOTE: This function is mutually exclusive from cjose_set_alloc_funcs(). Both SHOULD NOT be called.

If alloc3 is NULL, any previously set allocator function is cleared and the the default allocator malloc() is used.

If dealloc3 is NULL, the default dallocator free() is used.

Parameters
alloc3[in] The custom allocator function to use for OpenSSL >= 1.1.0, called with extra file/line params.
realloc3[in] The custom reallocator function to use for OpenSSL >= 1.1.0, called with extra file/line params.
dealloc3[in] The custom deallocator function to use for OpenSSL >= 1.1.0, called with extra file/line params.

◆ cjose_set_alloc_funcs()

void cjose_set_alloc_funcs ( cjose_alloc_fn_t  alloc,
cjose_realloc_fn_t  realloc,
cjose_dealloc_fn_t  dealloc 
)

Sets the allocator and deallocator functions.

NOTE: This function is mutually exclusive from cjose_set_alloc_ex_funcs(). Both SHOULD NOT be called.

If alloc is NULL, any previously set allocator function is cleared and the the default allocator malloc() is used.

If dealloc is NULL, the default dallocator free() is used.

Parameters
alloc[in] The custom allocator function to use.
realloc[in] The custom reallocator function to use.
dealloc[in] The custom deallocator function to use.