Skip to content

Setkey callbacks#9851

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

Setkey callbacks#9851
night1rider wants to merge 2 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.

@night1rider night1rider self-assigned this Mar 2, 2026
@night1rider night1rider force-pushed the setkey-callbacks branch 3 times, most recently from 895126c to 19ef100 Compare March 13, 2026 23:12
  utilities for generic SetKey and ExportKey operations on HMAC, RSA, ECC,
  and AES. Add wc_ecc_size/wc_ecc_sig_size callback hooks for hardware-only
  keys. Integrate into configure.ac as --enable-cryptocbutils=setkey,export
  options with CI test configurations in os-check.yml.

  Add test handlers in test.c and api.c with export/import delegation
  pattern, small-stack-safe allocations, custom curve support, and
  DEBUG_CRYPTOCB helpers.
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