wc_port.h
Functions
| Name | |
|---|---|
| int | wolfCrypt_Init(void ) Used to initialize resources used by wolfCrypt. |
| int | wolfCrypt_Cleanup(void ) Used to clean up resources used by wolfCrypt. |
| void | wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int * c, int i) Initializes atomic integer. |
| void | wolfSSL_Atomic_Uint_Init(wolfSSL_Atomic_Uint * c, unsigned int i) Initializes atomic unsigned integer. |
| int | wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int * c, int i) Atomically adds to integer and returns old value. |
| int | wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int * c, int i) Atomically subtracts from integer and returns old value. |
| int | wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int * c, int i) Atomically adds to integer and returns new value. |
| int | wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int * c, int i) Atomically subtracts from integer and returns new value. |
| int | wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int * c, int * expected_i, int new_i) Atomically compares and exchanges integer. |
| unsigned int | wolfSSL_Atomic_Uint_FetchAdd(wolfSSL_Atomic_Uint * c, unsigned int i) Atomically adds to unsigned integer and returns old value. |
| unsigned int | wolfSSL_Atomic_Uint_FetchSub(wolfSSL_Atomic_Uint * c, unsigned int i) Atomically subtracts from unsigned integer, returns old value. |
| unsigned int | wolfSSL_Atomic_Uint_AddFetch(wolfSSL_Atomic_Uint * c, unsigned int i) Atomically adds to unsigned integer, returns new value. |
| unsigned int | wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint * c, unsigned int i) Atomically subtracts from unsigned integer, returns new value. |
| int | wolfSSL_Atomic_Uint_CompareExchange(wolfSSL_Atomic_Uint * c, unsigned int * expected_i, unsigned int new_i) Atomically compares and exchanges unsigned integer. |
| int | wolfSSL_Atomic_Ptr_CompareExchange(void c, void expected_ptr, void * new_ptr) Atomically compares and exchanges pointer. |
| int | wc_InitMutex(wolfSSL_Mutex * m) Initializes mutex. |
| int | wc_FreeMutex(wolfSSL_Mutex * m) Frees mutex resources. |
| int | wc_LockMutex(wolfSSL_Mutex * m) Locks mutex. |
| int | wc_UnLockMutex(wolfSSL_Mutex * m) Unlocks mutex. |
| wolfSSL_Mutex * | wc_InitAndAllocMutex(void ) Initializes and allocates mutex. |
| int | wc_InitRwLock(wolfSSL_RwLock * m) Initializes read-write lock. |
| int | wc_FreeRwLock(wolfSSL_RwLock * m) Frees read-write lock resources. |
| int | wc_LockRwLock_Wr(wolfSSL_RwLock * m) Locks read-write lock for writing. |
| int | wc_LockRwLock_Rd(wolfSSL_RwLock * m) Locks read-write lock for reading. |
| int | wc_UnLockRwLock(wolfSSL_RwLock * m) Unlocks read-write lock. |
| int | wc_LockMutex_ex(int flag, int type, const char * file, int line) Locks mutex with debug info. |
| int | wc_SetMutexCb(mutex_cb * cb) Sets mutex callback. |
| mutex_cb * | wc_GetMutexCb(void ) Gets mutex callback. |
| long | wolfCrypt_heap_peakAllocs_checkpoint(void ) Checkpoints peak heap allocations. |
| long | wolfCrypt_heap_peakBytes_checkpoint(void ) Checkpoints peak heap bytes. |
| int | wc_FileLoad(const char * fname, unsigned char ** buf, size_t * bufLen, void * heap) Loads file into buffer. |
| int | wc_ReadDirFirst(ReadDirCtx * ctx, const char * path, char ** name) Reads first entry in directory. |
| int | wc_ReadDirNext(ReadDirCtx * ctx, const char * path, char ** name) Reads next entry in directory. |
| void | wc_ReadDirClose(ReadDirCtx * ctx) Closes directory reading. |
| int | wc_FileExists(const char * fname) Checks if file exists. |
| int | wolfSSL_GetHandleCbSet(void ) Checks if handle callback is set. |
| int | wolfSSL_SetHandleCb(wolfSSL_DSP_Handle_cb in) Sets handle callback. |
Functions Documentation
function wolfCrypt_Init
int wolfCrypt_Init(
void
)
Used to initialize resources used by wolfCrypt.
Parameters:
- none No parameters.
See: wolfCrypt_Cleanup
Return:
- 0 upon success.
- <0 upon failure of init resources.
Example
...
if (wolfCrypt_Init() != 0) {
WOLFSSL_MSG("Error with wolfCrypt_Init call");
}
function wolfCrypt_Cleanup
int wolfCrypt_Cleanup(
void
)
Used to clean up resources used by wolfCrypt.
Parameters:
- none No parameters.
See: wolfCrypt_Init
Return:
- 0 upon success.
- <0 upon failure of cleaning up resources.
Example
...
if (wolfCrypt_Cleanup() != 0) {
WOLFSSL_MSG("Error with wolfCrypt_Cleanup call");
}
function wolfSSL_Atomic_Int_Init
void wolfSSL_Atomic_Int_Init(
wolfSSL_Atomic_Int * c,
int i
)
Initializes atomic integer.
Parameters:
- c Atomic integer pointer
- i Initial value
See: wolfSSL_Atomic_Int_FetchAdd
Return: none No returns
Example
wolfSSL_Atomic_Int counter;
wolfSSL_Atomic_Int_Init(&counter, 0);
function wolfSSL_Atomic_Uint_Init
void wolfSSL_Atomic_Uint_Init(
wolfSSL_Atomic_Uint * c,
unsigned int i
)
Initializes atomic unsigned integer.
Parameters:
- c Atomic unsigned integer pointer
- i Initial value
See: wolfSSL_Atomic_Uint_FetchAdd
Return: none No returns
Example
wolfSSL_Atomic_Uint counter;
wolfSSL_Atomic_Uint_Init(&counter, 0);
function wolfSSL_Atomic_Int_FetchAdd
int wolfSSL_Atomic_Int_FetchAdd(
wolfSSL_Atomic_Int * c,
int i
)
Atomically adds to integer and returns old value.
Parameters:
- c Atomic integer pointer
- i Value to add
See: wolfSSL_Atomic_Int_AddFetch
Return: Old value before addition
Example
wolfSSL_Atomic_Int counter;
int old = wolfSSL_Atomic_Int_FetchAdd(&counter, 1);
function wolfSSL_Atomic_Int_FetchSub
int wolfSSL_Atomic_Int_FetchSub(
wolfSSL_Atomic_Int * c,
int i
)
Atomically subtracts from integer and returns old value.
Parameters:
- c Atomic integer pointer
- i Value to subtract
See: wolfSSL_Atomic_Int_SubFetch
Return: Old value before subtraction
Example
wolfSSL_Atomic_Int counter;
int old = wolfSSL_Atomic_Int_FetchSub(&counter, 1);
function wolfSSL_Atomic_Int_AddFetch
int wolfSSL_Atomic_Int_AddFetch(
wolfSSL_Atomic_Int * c,
int i
)
Atomically adds to integer and returns new value.
Parameters:
- c Atomic integer pointer
- i Value to add
See: wolfSSL_Atomic_Int_FetchAdd
Return: New value after addition
Example
wolfSSL_Atomic_Int counter;
int new_val = wolfSSL_Atomic_Int_AddFetch(&counter, 1);
function wolfSSL_Atomic_Int_SubFetch
int wolfSSL_Atomic_Int_SubFetch(
wolfSSL_Atomic_Int * c,
int i
)
Atomically subtracts from integer and returns new value.
Parameters:
- c Atomic integer pointer
- i Value to subtract
See: wolfSSL_Atomic_Int_FetchSub
Return: New value after subtraction
Example
wolfSSL_Atomic_Int counter;
int new_val = wolfSSL_Atomic_Int_SubFetch(&counter, 1);
function wolfSSL_Atomic_Int_CompareExchange
int wolfSSL_Atomic_Int_CompareExchange(
wolfSSL_Atomic_Int * c,
int * expected_i,
int new_i
)
Atomically compares and exchanges integer.
Parameters:
- c Atomic integer pointer
- expected_i Pointer to expected value
- new_i New value to set
See: wolfSSL_Atomic_Int_FetchAdd
Return: 1 if exchange occurred, 0 otherwise
Example
wolfSSL_Atomic_Int counter;
int expected = 0;
int ret = wolfSSL_Atomic_Int_CompareExchange(&counter, &expected, 1);
function wolfSSL_Atomic_Uint_FetchAdd
unsigned int wolfSSL_Atomic_Uint_FetchAdd(
wolfSSL_Atomic_Uint * c,
unsigned int i
)
Atomically adds to unsigned integer and returns old value.
Parameters:
- c Atomic unsigned integer pointer
- i Value to add
See: wolfSSL_Atomic_Uint_AddFetch
Return: Old value before addition
Example
wolfSSL_Atomic_Uint counter;
unsigned int old = wolfSSL_Atomic_Uint_FetchAdd(&counter, 1);
function wolfSSL_Atomic_Uint_FetchSub
unsigned int wolfSSL_Atomic_Uint_FetchSub(
wolfSSL_Atomic_Uint * c,
unsigned int i
)
Atomically subtracts from unsigned integer, returns old value.
Parameters:
- c Atomic unsigned integer pointer
- i Value to subtract
See: wolfSSL_Atomic_Uint_SubFetch
Return: Old value before subtraction
Example
wolfSSL_Atomic_Uint counter;
unsigned int old = wolfSSL_Atomic_Uint_FetchSub(&counter, 1);
function wolfSSL_Atomic_Uint_AddFetch
unsigned int wolfSSL_Atomic_Uint_AddFetch(
wolfSSL_Atomic_Uint * c,
unsigned int i
)
Atomically adds to unsigned integer, returns new value.
Parameters:
- c Atomic unsigned integer pointer
- i Value to add
See: wolfSSL_Atomic_Uint_FetchAdd
Return: New value after addition
Example
wolfSSL_Atomic_Uint counter;
unsigned int new_val = wolfSSL_Atomic_Uint_AddFetch(&counter, 1);
function wolfSSL_Atomic_Uint_SubFetch
unsigned int wolfSSL_Atomic_Uint_SubFetch(
wolfSSL_Atomic_Uint * c,
unsigned int i
)
Atomically subtracts from unsigned integer, returns new value.
Parameters:
- c Atomic unsigned integer pointer
- i Value to subtract
See: wolfSSL_Atomic_Uint_FetchSub
Return: New value after subtraction
Example
wolfSSL_Atomic_Uint counter;
unsigned int new_val = wolfSSL_Atomic_Uint_SubFetch(&counter, 1);
function wolfSSL_Atomic_Uint_CompareExchange
int wolfSSL_Atomic_Uint_CompareExchange(
wolfSSL_Atomic_Uint * c,
unsigned int * expected_i,
unsigned int new_i
)
Atomically compares and exchanges unsigned integer.
Parameters:
- c Atomic unsigned integer pointer
- expected_i Pointer to expected value
- new_i New value to set
See: wolfSSL_Atomic_Uint_FetchAdd
Return: 1 if exchange occurred, 0 otherwise
Example
wolfSSL_Atomic_Uint counter;
unsigned int expected = 0;
int ret = wolfSSL_Atomic_Uint_CompareExchange(&counter, &expected, 1);
function wolfSSL_Atomic_Ptr_CompareExchange
int wolfSSL_Atomic_Ptr_CompareExchange(
void ** c,
void ** expected_ptr,
void * new_ptr
)
Atomically compares and exchanges pointer.
Parameters:
- c Pointer to pointer
- expected_ptr Pointer to expected pointer value
- new_ptr New pointer value
See: wolfSSL_Atomic_Int_CompareExchange
Return: 1 if exchange occurred, 0 otherwise
Example
void* ptr = NULL;
void* expected = NULL;
void* new_val = malloc(100);
int ret = wolfSSL_Atomic_Ptr_CompareExchange(&ptr, &expected, new_val);
function wc_InitMutex
int wc_InitMutex(
wolfSSL_Mutex * m
)
Initializes mutex.
Parameters:
- m Mutex pointer
See: wc_FreeMutex
Return:
- 0 on success
- negative on error
Example
wolfSSL_Mutex mutex;
int ret = wc_InitMutex(&mutex);
function wc_FreeMutex
int wc_FreeMutex(
wolfSSL_Mutex * m
)
Frees mutex resources.
Parameters:
- m Mutex pointer
See: wc_InitMutex
Return:
- 0 on success
- negative on error
Example
wolfSSL_Mutex mutex;
wc_InitMutex(&mutex);
int ret = wc_FreeMutex(&mutex);
function wc_LockMutex
int wc_LockMutex(
wolfSSL_Mutex * m
)
Locks mutex.
Parameters:
- m Mutex pointer
See: wc_UnLockMutex
Return:
- 0 on success
- negative on error
Example
wolfSSL_Mutex mutex;
int ret = wc_LockMutex(&mutex);
function wc_UnLockMutex
int wc_UnLockMutex(
wolfSSL_Mutex * m
)
Unlocks mutex.
Parameters:
- m Mutex pointer
See: wc_LockMutex
Return:
- 0 on success
- negative on error
Example
wolfSSL_Mutex mutex;
wc_LockMutex(&mutex);
int ret = wc_UnLockMutex(&mutex);
function wc_InitAndAllocMutex
wolfSSL_Mutex * wc_InitAndAllocMutex(
void
)
Initializes and allocates mutex.
Parameters:
- none No parameters
See: wc_InitMutex
Return:
- Pointer to mutex on success
- NULL on error
Example
wolfSSL_Mutex* mutex = wc_InitAndAllocMutex();
if (mutex != NULL) {
wc_LockMutex(mutex);
}
function wc_InitRwLock
int wc_InitRwLock(
wolfSSL_RwLock * m
)
Initializes read-write lock.
Parameters:
- m Read-write lock pointer
See: wc_FreeRwLock
Return:
- 0 on success
- negative on error
Example
wolfSSL_RwLock lock;
int ret = wc_InitRwLock(&lock);
function wc_FreeRwLock
int wc_FreeRwLock(
wolfSSL_RwLock * m
)
Frees read-write lock resources.
Parameters:
- m Read-write lock pointer
See: wc_InitRwLock
Return:
- 0 on success
- negative on error
Example
wolfSSL_RwLock lock;
wc_InitRwLock(&lock);
int ret = wc_FreeRwLock(&lock);
function wc_LockRwLock_Wr
int wc_LockRwLock_Wr(
wolfSSL_RwLock * m
)
Locks read-write lock for writing.
Parameters:
- m Read-write lock pointer
See: wc_UnLockRwLock
Return:
- 0 on success
- negative on error
Example
wolfSSL_RwLock lock;
int ret = wc_LockRwLock_Wr(&lock);
function wc_LockRwLock_Rd
int wc_LockRwLock_Rd(
wolfSSL_RwLock * m
)
Locks read-write lock for reading.
Parameters:
- m Read-write lock pointer
See: wc_UnLockRwLock
Return:
- 0 on success
- negative on error
Example
wolfSSL_RwLock lock;
int ret = wc_LockRwLock_Rd(&lock);
function wc_UnLockRwLock
int wc_UnLockRwLock(
wolfSSL_RwLock * m
)
Unlocks read-write lock.
Parameters:
- m Read-write lock pointer
See: wc_LockRwLock_Rd
Return:
- 0 on success
- negative on error
Example
wolfSSL_RwLock lock;
wc_LockRwLock_Rd(&lock);
int ret = wc_UnLockRwLock(&lock);
function wc_LockMutex_ex
int wc_LockMutex_ex(
int flag,
int type,
const char * file,
int line
)
Locks mutex with debug info.
Parameters:
- flag Lock flag
- type Lock type
- file Source file name
- line Source line number
See: wc_LockMutex
Return:
- 0 on success
- negative on error
Example
int ret = wc_LockMutex_ex(0, 0, __FILE__, __LINE__);
function wc_SetMutexCb
int wc_SetMutexCb(
mutex_cb * cb
)
Sets mutex callback.
Parameters:
- cb Mutex callback pointer
See: wc_GetMutexCb
Return:
- 0 on success
- negative on error
Example
mutex_cb cb;
int ret = wc_SetMutexCb(&cb);
function wc_GetMutexCb
mutex_cb * wc_GetMutexCb(
void
)
Gets mutex callback.
Parameters:
- none No parameters
See: wc_SetMutexCb
Return: Pointer to mutex callback
Example
mutex_cb* cb = wc_GetMutexCb();
function wolfCrypt_heap_peakAllocs_checkpoint
long wolfCrypt_heap_peakAllocs_checkpoint(
void
)
Checkpoints peak heap allocations.
Parameters:
- none No parameters
See: wolfCrypt_heap_peakBytes_checkpoint
Return: Peak allocation count
Example
long peak = wolfCrypt_heap_peakAllocs_checkpoint();
function wolfCrypt_heap_peakBytes_checkpoint
long wolfCrypt_heap_peakBytes_checkpoint(
void
)
Checkpoints peak heap bytes.
Parameters:
- none No parameters
See: wolfCrypt_heap_peakAllocs_checkpoint
Return: Peak bytes allocated
Example
long peak = wolfCrypt_heap_peakBytes_checkpoint();
function wc_FileLoad
int wc_FileLoad(
const char * fname,
unsigned char ** buf,
size_t * bufLen,
void * heap
)
Loads file into buffer.
Parameters:
- fname File name
- buf Buffer pointer
- bufLen Buffer length pointer
- heap Heap hint
See: wc_FileExists
Return:
- 0 on success
- negative on error
Example
unsigned char* buf = NULL;
size_t len = 0;
int ret = wc_FileLoad("file.txt", &buf, &len, NULL);
function wc_ReadDirFirst
int wc_ReadDirFirst(
ReadDirCtx * ctx,
const char * path,
char ** name
)
Reads first entry in directory.
Parameters:
- ctx Directory context
- path Directory path
- name Pointer to store entry name
See: wc_ReadDirNext
Return:
- 0 on success
- negative on error
Example
ReadDirCtx ctx;
char* name;
int ret = wc_ReadDirFirst(&ctx, "/path", &name);
function wc_ReadDirNext
int wc_ReadDirNext(
ReadDirCtx * ctx,
const char * path,
char ** name
)
Reads next entry in directory.
Parameters:
- ctx Directory context
- path Directory path
- name Pointer to store entry name
See: wc_ReadDirFirst
Return:
- 0 on success
- negative on error
Example
ReadDirCtx ctx;
char* name;
int ret = wc_ReadDirNext(&ctx, "/path", &name);
function wc_ReadDirClose
void wc_ReadDirClose(
ReadDirCtx * ctx
)
Closes directory reading.
Parameters:
- ctx Directory context
See: wc_ReadDirFirst
Return: none No returns
Example
ReadDirCtx ctx;
wc_ReadDirClose(&ctx);
function wc_FileExists
int wc_FileExists(
const char * fname
)
Checks if file exists.
Parameters:
- fname File name
See: wc_FileLoad
Return:
- 1 if file exists
- 0 if file does not exist
Example
if (wc_FileExists("file.txt")) {
// file exists
}
function wolfSSL_GetHandleCbSet
int wolfSSL_GetHandleCbSet(
void
)
Checks if handle callback is set.
Parameters:
- none No parameters
See: wolfSSL_SetHandleCb
Return:
- 1 if set
- 0 if not set
Example
if (wolfSSL_GetHandleCbSet()) {
// callback is set
}
function wolfSSL_SetHandleCb
int wolfSSL_SetHandleCb(
wolfSSL_DSP_Handle_cb in
)
Sets handle callback.
Parameters:
- in Handle callback
Return:
- 0 on success
- negative on error
Example
int ret = wolfSSL_SetHandleCb(myHandleCallback);
Source code
int wolfCrypt_Init(void);
int wolfCrypt_Cleanup(void);
void wolfSSL_Atomic_Int_Init(wolfSSL_Atomic_Int* c, int i);
void wolfSSL_Atomic_Uint_Init(wolfSSL_Atomic_Uint* c, unsigned int i);
int wolfSSL_Atomic_Int_FetchAdd(wolfSSL_Atomic_Int* c, int i);
int wolfSSL_Atomic_Int_FetchSub(wolfSSL_Atomic_Int* c, int i);
int wolfSSL_Atomic_Int_AddFetch(wolfSSL_Atomic_Int* c, int i);
int wolfSSL_Atomic_Int_SubFetch(wolfSSL_Atomic_Int* c, int i);
int wolfSSL_Atomic_Int_CompareExchange(wolfSSL_Atomic_Int* c,
int *expected_i, int new_i);
unsigned int wolfSSL_Atomic_Uint_FetchAdd(wolfSSL_Atomic_Uint* c,
unsigned int i);
unsigned int wolfSSL_Atomic_Uint_FetchSub(wolfSSL_Atomic_Uint* c,
unsigned int i);
unsigned int wolfSSL_Atomic_Uint_AddFetch(wolfSSL_Atomic_Uint* c,
unsigned int i);
unsigned int wolfSSL_Atomic_Uint_SubFetch(wolfSSL_Atomic_Uint* c,
unsigned int i);
int wolfSSL_Atomic_Uint_CompareExchange(wolfSSL_Atomic_Uint* c,
unsigned int *expected_i,
unsigned int new_i);
int wolfSSL_Atomic_Ptr_CompareExchange(void** c, void **expected_ptr,
void *new_ptr);
int wc_InitMutex(wolfSSL_Mutex* m);
int wc_FreeMutex(wolfSSL_Mutex* m);
int wc_LockMutex(wolfSSL_Mutex* m);
int wc_UnLockMutex(wolfSSL_Mutex* m);
wolfSSL_Mutex* wc_InitAndAllocMutex(void);
int wc_InitRwLock(wolfSSL_RwLock* m);
int wc_FreeRwLock(wolfSSL_RwLock* m);
int wc_LockRwLock_Wr(wolfSSL_RwLock* m);
int wc_LockRwLock_Rd(wolfSSL_RwLock* m);
int wc_UnLockRwLock(wolfSSL_RwLock* m);
int wc_LockMutex_ex(int flag, int type, const char* file, int line);
int wc_SetMutexCb(mutex_cb* cb);
mutex_cb* wc_GetMutexCb(void);
long wolfCrypt_heap_peakAllocs_checkpoint(void);
long wolfCrypt_heap_peakBytes_checkpoint(void);
int wc_FileLoad(const char* fname, unsigned char** buf, size_t* bufLen,
void* heap);
int wc_ReadDirFirst(ReadDirCtx* ctx, const char* path, char** name);
int wc_ReadDirNext(ReadDirCtx* ctx, const char* path, char** name);
void wc_ReadDirClose(ReadDirCtx* ctx);
int wc_FileExists(const char* fname);
int wolfSSL_GetHandleCbSet(void);
int wolfSSL_SetHandleCb(wolfSSL_DSP_Handle_cb in);
Updated on 2025-12-31 at 01:16:04 +0000