swdev: pair internal wolfCrypt_Init() with wolfCrypt_Cleanup()

This commit is contained in:
rizlik
2026-05-06 09:42:26 +02:00
parent 6d4fa5919c
commit 71819bcb44
4 changed files with 18 additions and 5 deletions
+5 -3
View File
@@ -116,10 +116,12 @@ $(BUILDDIR)/swdev.o: $(BUILDDIR)/swdev.partial.o
@# visibility("default") and overrides the command-line
@# -fvisibility=hidden. --keep-global-symbol sidesteps that by matching
@# on symbol name directly.
$(OBJCOPY) --keep-global-symbol=wc_SwDev_Callback $< $@
@# Sanity-check: only wc_SwDev_Callback may be externally visible.
$(OBJCOPY) --keep-global-symbol=wc_SwDev_Callback \
--keep-global-symbol=wc_SwDev_InternalCleanup $< $@
@# Sanity-check: only the two swdev entry points may be externally visible.
@visible=$$( $(NM) --extern-only --defined-only $@ | awk '{print $$3}' \
| grep -v '^wc_SwDev_Callback$$' || true); \
| grep -v '^wc_SwDev_Callback$$' \
| grep -v '^wc_SwDev_InternalCleanup$$' || true); \
if [ -n "$$visible" ]; then \
echo "error: unexpected externally-visible symbols in $@:"; \
echo "$$visible"; \
+8
View File
@@ -54,6 +54,14 @@ static int swdev_ensure_init(void)
return 0;
}
WC_SWDEV_EXPORT void wc_SwDev_InternalCleanup(void)
{
if (swdev_initialized) {
wolfCrypt_Cleanup();
swdev_initialized = 0;
}
}
#ifndef NO_RSA
static int swdev_rsa(wc_CryptoInfo* info)
{
+2 -1
View File
@@ -38,8 +38,9 @@ extern "C" {
#define WC_SWDEV_EXPORT
#endif
WC_SWDEV_EXPORT int wc_SwDev_Callback(int devId, wc_CryptoInfo* info,
WC_SWDEV_EXPORT int wc_SwDev_Callback(int devId, wc_CryptoInfo* info,
void* ctx);
WC_SWDEV_EXPORT void wc_SwDev_InternalCleanup(void);
#ifdef __cplusplus
}
+3 -1
View File
@@ -30,7 +30,8 @@
#endif
/* resolved at link time from swdev.o */
extern int wc_SwDev_Callback(int devId, wc_CryptoInfo* info, void* ctx);
extern int wc_SwDev_Callback(int devId, wc_CryptoInfo* info, void* ctx);
extern void wc_SwDev_InternalCleanup(void);
/* Init always (re)registers because wolfCrypt_Cleanup wipes the cryptocb
* table; only the final Cleanup unregisters. */
@@ -61,6 +62,7 @@ void wc_SwDev_Cleanup(void)
wc_CryptoCb_SetDeviceFindCb(NULL);
#endif
wc_CryptoCb_UnRegisterDevice(WC_SWDEV_ID);
wc_SwDev_InternalCleanup();
}
else if (my_refCount < 0) {
/* called more times than Init; restore floor */