Skip to content

Setkey callbacks#9851

Draft
night1rider wants to merge 6 commits intowolfSSL:masterfrom
night1rider:setkey-callbacks
Draft

Setkey callbacks#9851
night1rider wants to merge 6 commits intowolfSSL:masterfrom
night1rider:setkey-callbacks

Conversation

@night1rider
Copy link
Contributor

@night1rider night1rider commented Mar 2, 2026

Add WOLF_CRYPTO_CB_SETKEY, a generic SetKey crypto callback that notifies callback handlers when key material is imported for HMAC, RSA, ECC, and AES. For RSA and ECC, the callback passes a fully-populated temporary key struct (initialized with INVALID_DEVID to prevent recursion) alongside the real destination key object. This lets callback implementors use whatever wolfSSL export function best suits their hardware: wc_RsaKeyToDer, wc_ecc_export_x963, raw component exports, etc. rather than the library trying to anticipate every format a hardware backend might need. The temporary key handles all the parsing complexity so the callback can focus solely on getting key material into hardware.

SetKey callbacks are wired into: wc_AesSetKey, wc_HmacSetKey, wc_RsaPublicKeyDecodeRaw, wc_RsaPrivateKeyDecodeRaw, wc_RsaPrivateKeyDecode, wc_ecc_import_x963_ex2, wc_ecc_import_raw_private, and wc_ecc_import_private_key_ex. All RSA and ECC callsites pass the actual key size in bytes via the keySz parameter.

The feature is enabled via --enable-cryptocbutils=setkey, --enable-cryptocbutils, or -DWOLF_CRYPTO_CB_SETKEY with corresponding CI test configurations. Includes test handlers in test.c and api.c, a GetSetKeyTypeStr debug helper for readable type names under DEBUG_CRYPTOCB.

…A, ECC, and AES with test handler in test.c using export/import delegation pattern. Integrate into configure.ac as a --enable-cryptocbutils=setkey option and add CI test configurations in os-check.yml.
…_PUB and WC_SETKEY_RSA_PRIV cases with WOLFSSL_KEY_TO_DER, and add --enable-keygen to CI setkey test configs to ensure RSA DER export functions are available
…GetSetKeyTypeStr debug helper in cryptocb.c for readable SetKey type names under DEBUG_CRYPTOCB
…cc_import_private_key_ex so all RSA/ECC key import paths notify crypto callback handlers.
@night1rider night1rider self-assigned this Mar 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant