Skip to content

Commit e572523

Browse files
committed
Expose wc_CryptoCb_GetDevice and add CryptoCb API test coverage
1 parent 1f0f29c commit e572523

4 files changed

Lines changed: 40 additions & 12 deletions

File tree

tests/api.c

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28972,13 +28972,39 @@ static int test_wc_CryptoCb(void)
2897228972
#if defined(WOLF_CRYPTO_CB) && \
2897328973
(!defined(WOLF_CRYPTO_CB_ONLY_SHA256) && !defined(WOLF_CRYPTO_CB_ONLY_AES) && \
2897428974
!defined(WOLF_CRYPTO_CB_ONLY_ECC) && !defined(WOLF_CRYPTO_CB_ONLY_RSA))
28975+
#if defined(HAVE_IO_TESTS_DEPENDENCIES) && \
28976+
(!defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519))
28977+
int tlsVer;
28978+
#endif
2897528979
/* TODO: Add crypto callback API tests */
2897628980

28977-
#ifdef HAVE_IO_TESTS_DEPENDENCIES
28978-
#if !defined(NO_RSA) || defined(HAVE_ECC) || defined(HAVE_ED25519)
28979-
int tlsVer;
28980-
#endif
28981+
/* Test wc_CryptoCb_GetDevice() lookup behavior. */
28982+
{
28983+
int getDevId = 1234;
28984+
int getDevCtx = 0;
28985+
CryptoCb* dev = NULL;
28986+
28987+
/* Unregistered devId is not found. */
28988+
ExpectNull(wc_CryptoCb_GetDevice(getDevId));
28989+
28990+
/* After registering, the device is found with matching fields. */
28991+
ExpectIntEQ(wc_CryptoCb_RegisterDevice(getDevId, NULL, &getDevCtx), 0);
28992+
ExpectNotNull(dev = wc_CryptoCb_GetDevice(getDevId));
28993+
if (dev != NULL) {
28994+
ExpectIntEQ(dev->devId, getDevId);
28995+
ExpectNull(dev->cb);
28996+
ExpectPtrEq(dev->ctx, &getDevCtx);
28997+
}
28998+
28999+
/* A different, unregistered devId is still not found. */
29000+
ExpectNull(wc_CryptoCb_GetDevice(getDevId + 1));
2898129001

29002+
/* After unregistering, the device is no longer found. */
29003+
wc_CryptoCb_UnRegisterDevice(getDevId);
29004+
ExpectNull(wc_CryptoCb_GetDevice(getDevId));
29005+
}
29006+
29007+
#ifdef HAVE_IO_TESTS_DEPENDENCIES
2898229008
#ifndef NO_RSA
2898329009
for (tlsVer = WOLFSSL_SSLV3; tlsVer <= WOLFSSL_DTLSV1; tlsVer++) {
2898429010
ExpectIntEQ(test_wc_CryptoCb_TLS(tlsVer,

wolfcrypt/src/cryptocb.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,6 @@ Crypto Callback Build Options:
7474
#define MAX_CRYPTO_DEVID_CALLBACKS 8
7575
#endif
7676

77-
typedef struct CryptoCb {
78-
int devId;
79-
CryptoDevCallbackFunc cb;
80-
void* ctx;
81-
} CryptoCb;
8277
static WC_THREADSHARED CryptoCb gCryptoDev[MAX_CRYPTO_DEVID_CALLBACKS];
8378

8479
#ifdef WOLF_CRYPTO_CB_FIND
@@ -345,7 +340,7 @@ void wc_CryptoCb_InfoString(wc_CryptoInfo* info)
345340

346341
/* Search through listed devices and return the first matching device ID
347342
* found. */
348-
static CryptoCb* wc_CryptoCb_GetDevice(int devId)
343+
CryptoCb* wc_CryptoCb_GetDevice(int devId)
349344
{
350345
int i;
351346
for (i = 0; i < MAX_CRYPTO_DEVID_CALLBACKS; i++) {

wolfssl/version.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
extern "C" {
2929
#endif
3030

31-
#define LIBWOLFSSL_VERSION_STRING "5.9.1"
32-
#define LIBWOLFSSL_VERSION_HEX 0x05009001
31+
#define LIBWOLFSSL_VERSION_STRING "5.8.4"
32+
#define LIBWOLFSSL_VERSION_HEX 0x05008004
3333

3434
#ifdef __cplusplus
3535
}

wolfssl/wolfcrypt/cryptocb.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,12 +672,19 @@ typedef struct wc_CryptoInfo {
672672

673673
typedef int (*CryptoDevCallbackFunc)(int devId, struct wc_CryptoInfo* info, void* ctx);
674674

675+
typedef struct CryptoCb {
676+
int devId;
677+
CryptoDevCallbackFunc cb;
678+
void* ctx;
679+
} CryptoCb;
680+
675681
WOLFSSL_LOCAL void wc_CryptoCb_Init(void);
676682
WOLFSSL_LOCAL void wc_CryptoCb_Cleanup(void);
677683
WOLFSSL_LOCAL int wc_CryptoCb_GetDevIdAtIndex(int startIdx);
678684
WOLFSSL_API int wc_CryptoCb_RegisterDevice(int devId, CryptoDevCallbackFunc cb, void* ctx);
679685
WOLFSSL_API void wc_CryptoCb_UnRegisterDevice(int devId);
680686
WOLFSSL_API int wc_CryptoCb_DefaultDevID(void);
687+
WOLFSSL_API CryptoCb* wc_CryptoCb_GetDevice(int devId);
681688

682689
#ifdef WOLF_CRYPTO_CB_FIND
683690
typedef int (*CryptoDevCallbackFind)(int devId, int algoType);

0 commit comments

Comments
 (0)