wolfcrypt/src/wc_port.c, wolfssl/wolfcrypt/wc_port.h:

* implement wolfSSL_RefInc_IfAtLeast() and wolfSSL_RefDec_IfEquals().
* implement wolfSSL_RefWithMutexInc_IfAtLeast() and wolfSSL_RefWithMutexDec_IfEquals().

wolfssl/wolfcrypt/wc_port.h: for old FIPS when __GNUC__ or __clang__, always map __FUNCTION__ to __func__ for pedantic conformance.
This commit is contained in:
Daniel Pouzzner
2026-07-07 00:18:27 -05:00
parent bd977dc0b9
commit 0fdceafe6b
2 changed files with 98 additions and 1 deletions
+45
View File
@@ -2153,6 +2153,28 @@ void wolfSSL_RefWithMutexInc2(wolfSSL_RefWithMutex* ref, int *new_count,
*err = ret;
}
void wolfSSL_RefWithMutexInc_IfAtLeast(wolfSSL_RefWithMutex* ref,
int cur_at_least, int *new_count,
int* err)
{
*err = wc_LockMutex(&ref->mutex);
if (*err != 0) {
WOLFSSL_MSG("Failed to lock mutex for reference increment!");
*new_count = -1;
}
else {
if (ref->count < cur_at_least) {
*new_count = ref->count;
*err = BAD_STATE_E;
}
else {
*new_count = ++ref->count;
*err = 0;
}
wc_UnLockMutex(&ref->mutex);
}
}
int wolfSSL_RefWithMutexLock(wolfSSL_RefWithMutex* ref)
{
return wc_LockMutex(&ref->mutex);
@@ -2198,6 +2220,29 @@ void wolfSSL_RefWithMutexDec2(wolfSSL_RefWithMutex* ref, int* new_count,
}
*err = ret;
}
void wolfSSL_RefWithMutexDec_IfEquals(wolfSSL_RefWithMutex* ref,
int current_count, int* new_count,
int* err)
{
*err = wc_LockMutex(&ref->mutex);
if (*err != 0) {
WOLFSSL_MSG("Failed to lock mutex for reference decrement!");
*new_count = -1;
}
else {
if (ref->count != current_count) {
*new_count = ref->count;
*err = BAD_STATE_E;
}
else {
*new_count = --ref->count;
*err = 0;
}
wc_UnLockMutex(&ref->mutex);
}
}
#endif /* ! SINGLE_THREADED */
#if WOLFSSL_CRYPT_HW_MUTEX