Skip to content

Conversation

@douzzer
Copy link
Contributor

@douzzer douzzer commented Jan 6, 2026

wolfcrypt/src/random.c and wolfssl/wolfcrypt/random.h: implement WC_RNG_BANK_SUPPORT:

  • add WC_DRBG_BANKREF status code;
  • add struct wc_rng_bank *bankref to struct WC_RNG, and move status slot out from HAVE_HASHDRBG gate;
  • add WC_DRBG_MAX_SALT_SZ, and add saltSz and salt slots to struct DRBG_internal;
  • add salt handling to Hash_df(), Hash_DRBG_Instantiate(), and _InitRng();
  • add types:
    • enum wc_rng_bank_flags
    • struct wc_rng_bank
    • struct wc_rng_bank_inst
  • add implementations:
    • wc_rng_bank_init()
    • wc_rng_bank_set_affinity_handlers()
    • wc_rng_bank_fini()
    • wc_rng_bank_checkout()
    • wc_rng_bank_checkin()
    • wc_rng_bank_inst_reinit()
    • wc_rng_bank_seed()
    • wc_rng_bank_reseed()
    • wc_InitRng_BankRef()
    • wc_rng_new_bankref()
    • WC_RNG_BANK_INST_TO_RNG()
  • in wc_RNG_GenerateBlock() and wc_FreeRng(), add WC_RNG_BANK_SUPPORT sections;

wolfcrypt/src/random.c: in WC_VERBOSE_RNG messages, add "ERROR: " prefixes to text to assure pickup by autotesting. also fixed line lengths.

linuxkm/lkcapi_sha_glue.c:

  • refactor to use new wc_rng_bank facility:
    • wc_linuxkm_drbg_init_tfm()
    • wc_linuxkm_drbg_exit_tfm()
    • get_drbg() (renamed to linuxkm_get_drbg())
    • put_drbg() (renamed to linuxkm_put_drbg())
    • wc_linuxkm_drbg_generate()
    • wc_linuxkm_drbg_seed()
    • wc_mix_pool_bytes()
    • wc_crng_reseed()
  • add:
    • linuxkm_affinity_lock()
    • linuxkm_affinity_get_id()
    • linuxkm_affinity_unlock()
    • linuxkm_InitRng_DefaultRef()
  • remove:
    • get_drbg_n()
    • drbg_init_from()
    • fork_default_rng()
    • LKCAPI_INITRNG_FOR_SELFTEST
  • when LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT, define LKCAPI_INITRNG to linuxkm_InitRng_DefaultRef, else define it to wc_InitRng().

linuxkm/{lkcapi_dh_glue.c,lkcapi_ecdh_glue.c,lkcapi_rsa_glue.c}: use LKCAPI_INITRNG() rather than wc_InitRng(), and remove calls to LKCAPI_INITRNG_FOR_SELFTEST(). also, in km_rsa_ctx_init_rng(), recognize WC_DRBG_BANKREF as a usable RNG status.

configure.ac: add handling for --enable-rng-bank, and add it to the all-crypto feature set.

wolfcrypt/src/error.c, wolfssl/wolfcrypt/error-crypt.h: add BUSY_E and ALREADY_E.

wolfcrypt/src/wc_port.c and wolfssl/wolfcrypt/wc_port.h: in wolfSSL_RefFree() and wolfSSL_RefWithMutexFree(), zero the refcount (valid refcount objects are initialized to count of 1); add wolfSSL_RefCur().

wolfssl/wolfcrypt/settings.h:

  • add FIPS_VERSION_NE();
  • move more generic setup code from WOLFSSL_LINUXKM/WOLFSSL_BSDKM sections to kernel-generic WOLFSSL_KERNEL_MODE section; fix WOLFSSL_OLD_PRIME_CHECK setup to exclude FIPS.

linuxkm/linuxkm_wc_port.h and linuxkm/module_hooks.c: remove WOLFSSL_DEBUG_BACKTRACE_ERROR_CODES gate around setup for wolfssl_linuxkm_pie_redirect_table.dump_stack.

linuxkm/module_hooks.c: in wc_linuxkm_relax_long_loop(), use cpu_relax() as a fallback when non-preemptible.

linuxkm/x86_vector_register_glue.c: in wc_save_vector_registers_x86(), don't render warning of call while non-preemptible if WC_SVR_FLAG_INHIBIT was passed in.

Copy link
Contributor

@philljj philljj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all-c89-clang-tidy and all-c89-cppcheck CI had errors.

@philljj philljj self-requested a review January 6, 2026 18:29
philljj
philljj previously requested changes Jan 6, 2026
Copy link
Contributor

@philljj philljj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far, just have some suggestions.

douzzer added 13 commits January 7, 2026 22:54
…efFree() and wolfSSL_RefWithMutexFree(), zero the refcount (valid refcount objects are initialized to count of 1); add wolfSSL_RefCur().
* add FIPS_VERSION_NE();
* move more generic setup code from WOLFSSL_LINUXKM/WOLFSSL_BSDKM to kernel-generic WOLFSSL_KERNEL_MODE; fix WOLFSSL_OLD_PRIME_CHECK setup to exclude FIPS.
…DEBUG_BACKTRACE_ERROR_CODES gate around setup for wolfssl_linuxkm_pie_redirect_table.dump_stack.

linuxkm/module_hooks.c: in wc_linuxkm_relax_long_loop(), use cpu_relax() as a fallback when non-preemptible.
…, don't render warning of call while non-preemptible if WC_SVR_FLAG_INHIBIT was passed in.
…NG_BANK_SUPPORT:

* add WC_DRBG_BANKREF status code;
* add `struct wc_rng_bank *bankref` to struct WC_RNG, and move status slot out from HAVE_HASHDRBG gate;
* add WC_DRBG_MAX_SALT_SZ, and add saltSz and salt slots to struct DRBG_internal;
* add salt handling to Hash_df(), Hash_DRBG_Instantiate(), and _InitRng();
* add types:
  * enum wc_rng_bank_flags
  * struct wc_rng_bank
* add implementations:
  * wc_rng_bank_init()
  * wc_rng_bank_set_affinity_handlers()
  * wc_rng_bank_fini()
  * wc_rng_bank_checkout()
  * wc_rng_bank_checkin()
  * wc_rng_bank_inst_reinit()
  * wc_rng_bank_seed()
  * wc_rng_bank_reseed()
  * wc_InitRng_BankRef()
  * wc_rng_new_bankref()
  * WC_RNG_BANK_INST_TO_RNG()
* in wc_RNG_GenerateBlock() and wc_FreeRng(), add WC_RNG_BANK_SUPPORT sections;

wolfcrypt/src/random.c: in WC_VERBOSE_RNG messages, add "ERROR: " prefixes to text to assure pickup by autotesting.  also fixed line lengths.
* refactor to use new wc_rng_bank facility:
  * wc_linuxkm_drbg_init_tfm()
  * wc_linuxkm_drbg_exit_tfm()
  * get_drbg() (renamed to linuxkm_get_drbg())
  * put_drbg() (renamed to linuxkm_put_drbg())
  * wc_linuxkm_drbg_generate()
  * wc_linuxkm_drbg_seed()
  * wc_mix_pool_bytes()
  * wc_crng_reseed()
* add:
  * linuxkm_affinity_lock()
  * linuxkm_affinity_get_id()
  * linuxkm_affinity_unlock()
  * linuxkm_InitRng_DefaultRef()
* remove:
  * get_drbg_n()
  * drbg_init_from()
  * fork_default_rng()
  * LKCAPI_INITRNG_FOR_SELFTEST.
* when LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT, define LKCAPI_INITRNG to linuxkm_InitRng_DefaultRef, else define it to wc_InitRng().
…LKCAPI_INITRNG() rather than wc_InitRng(), and remove calls to LKCAPI_INITRNG_FOR_SELFTEST(). also, in km_rsa_ctx_init_rng(), recognize WC_DRBG_BANKREF as a usable RNG status.
…/wc_port.h, linuxkm/lkcapi_sha_glue.c: fixes from autotesting:

* refactor to eliminate recursion in wc_RNG_GenerateBlock();
* refactor enum wc_rng_bank_flags as word32 and macros;
* fix -Wconversions, -Wunused, and stray EINVAL in wc_rng_bank_init();
* make struct wc_rng_bank_inst a top-level definition for C++ compat;
* fix several bugprone-macro-parentheses.
… HAVE_ANONYMOUS_INLINE_AGGREGATES`, not `#if HAVE_ANONYMOUS_INLINE_AGGREGATES`.
…nd wolfssl/wolfcrypt/random.h to new files wolfcrypt/src/rng_bank.c and wolfssl/wolfcrypt/rng_bank.h;

wolfcrypt/src/rng_bank.c:

  * add wc_local_rng_bank_checkout_for_bankref, wc_BankRef_Release(), wc_rng_bank_new(), and wc_rng_bank_free();

  * in wc_rng_bank_checkin(), take a struct wc_rng_bank_inst **rng_inst and NULL it before return;

  * in wc_rng_bank_init(), add a devId arg, and handle devId in wc_rng_bank_inst_reinit();

  * add WC_RNG_BANK_INST_LOCK_* and use them in wc_rng_bank_checkout() and wc_rng_bank_checkin();

  * fix order of operations in wc_rng_bank_checkout() re DISABLE_VECTOR_REGISTERS();

wolfcrypt/src/random.c:

  * refactor per-instance salting for wc_rng_bank_inst: remove changes in Hash_df(), Hash_DRBG_Instantiate(), and _InitRng(), and in wc_rng_bank_init() and wc_rng_bank_inst_reinit(), use wc_InitRngNonce_ex() and pass the wc_rng_bank_inst pointer as the nonce;

  * simplify the WC_RNG_BANK_SUPPORT variant of wc_RNG_GenerateBlock() -- delegate to wc_local_rng_bank_checkout_for_bankref() and remove supplementary error checking;

  * in wc_FreeRng(), call wc_BankRef_Release() when WC_DRBG_BANKREF, and in wc_BankRef_Release(), fix refcount flub (not wolfSSL_RefFree, rather wolfSSL_RefDec);

  * streamline the WOLFSSL_LINUXKM wc_GenerateSeed();

wolfcrypt/test/test.c: add random_bank_test();

linuxkm/lkcapi_sha_glue.c: use WC_RNG_BANK_INST_TO_RNG() opportunistically;

configure.ac: add --enable-amdrdseed as a synonym for --enable-amdrand;

linuxkm/linuxkm_wc_port.h: when LINUXKM_LKCAPI_REGISTER_HASH_DRBG_DEFAULT, don't include get_random_bytes() in struct wolfssl_linuxkm_pie_redirect_table;

add various comments for clarity.
@douzzer douzzer force-pushed the 20251230-persistent-drbg branch from ef6793d to 0059f16 Compare January 8, 2026 04:54
@douzzer douzzer requested a review from philljj January 8, 2026 05:27
@douzzer
Copy link
Contributor Author

douzzer commented Jan 8, 2026

retest this please
(Jenkins glitches X 5)

@philljj philljj assigned wolfSSL-Bot and unassigned douzzer and philljj Jan 8, 2026
@dgarske dgarske self-assigned this Jan 8, 2026
Copy link
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR review and testing is fine, but I’d really like some more documentation for --enable-rng-bank and WC_RNG_BANK_SUPPORT. Eventually the new rng_bank.c file will need added to CMake and VS project.

@dgarske dgarske removed their assignment Jan 8, 2026
@dgarske dgarske merged commit f57484d into wolfSSL:master Jan 8, 2026
483 of 485 checks passed
douzzer added a commit that referenced this pull request Jan 9, 2026
…0251229-linuxkm-rng-wolfentropy" (450b0b4, 299ca1c, 0621615) and #9616 "20251230-persistent-drbg" (3c15be6, c1d2828, 0059f16, 1e0351a).
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.

4 participants