mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2026-07-05 11:50:52 +02:00
0f82b9e5fb
Add a software crypto-callback device (wc_swdev) that lets the wolfcrypt test suite run under WOLF_CRYPTO_CB_ONLY_* flags without per-test devId plumbing. The bundle is a separately-compiled second copy of wolfcrypt (software implementations enabled, WOLF_CRYPTO_CB_ONLY_* stripped) linked into testwolfcrypt as a single relocatable object; every symbol is demoted to local via objcopy --keep-global-symbol except wc_SwDev_Callback, so there is no collision with the main libwolfssl. A find callback routes unbound operations (devId == INVALID_DEVID) to the swdev while letting real device IDs pass through. wc_SwDev_Init / wc_SwDev_Cleanup hooks are wired into wolfcrypt/test/test.c. cryptocb_test's WOLF_CRYPTO_CB_FIND and WOLF_CRYPTO_CB_ONLY_RSA blocks are gated off under WOLFSSL_SWDEV. Enable via --enable-swdev (requires --enable-cryptocb).
58 lines
1.2 KiB
C
58 lines
1.2 KiB
C
/* tests/swdev/swdev_loader.c -- main-side loader for wc_swdev. */
|
|
|
|
#include "swdev_loader.h"
|
|
|
|
#include <wolfssl/wolfcrypt/error-crypt.h>
|
|
|
|
#ifndef WOLF_CRYPTO_CB
|
|
#error "wc_swdev loader requires WOLF_CRYPTO_CB"
|
|
#endif
|
|
|
|
/* resolved at link time from swdev.o */
|
|
extern int wc_SwDev_Callback(int devId, wc_CryptoInfo* info, void* ctx);
|
|
|
|
static int swdev_registered = 0;
|
|
|
|
int wc_SwDev_Init(void)
|
|
{
|
|
int ret;
|
|
|
|
/* always re-register: cryptocb table is wiped by wolfCrypt_Cleanup */
|
|
ret = wc_CryptoCb_RegisterDevice(WC_SWDEV_ID, wc_SwDev_Callback, NULL);
|
|
if (ret != 0)
|
|
return ret;
|
|
|
|
#ifdef WOLF_CRYPTO_CB_FIND
|
|
wc_CryptoCb_SetDeviceFindCb(wc_SwDev_FindCb);
|
|
#endif
|
|
|
|
swdev_registered = 1;
|
|
return 0;
|
|
}
|
|
|
|
void wc_SwDev_Cleanup(void)
|
|
{
|
|
if (!swdev_registered)
|
|
return;
|
|
|
|
#ifdef WOLF_CRYPTO_CB_FIND
|
|
wc_CryptoCb_SetDeviceFindCb(NULL);
|
|
#endif
|
|
|
|
wc_CryptoCb_UnRegisterDevice(WC_SWDEV_ID);
|
|
swdev_registered = 0;
|
|
}
|
|
|
|
#ifdef WOLF_CRYPTO_CB_FIND
|
|
int wc_SwDev_FindCb(int currentId, int algoType)
|
|
{
|
|
(void)algoType;
|
|
|
|
/* only redirect ops with no bound device; let others pass through */
|
|
if (currentId == INVALID_DEVID)
|
|
return WC_SWDEV_ID;
|
|
|
|
return currentId;
|
|
}
|
|
#endif
|