Skip to content

20261030-RNG-invalidation-redux - #12050

Merged
JacobBarthelmeh merged 8 commits into
wolfSSL:masterfrom
douzzer:20261030-RNG-invalidation-redux
Nov 9, 2026
Merged

JacobBarthelmeh merged 8 commits into
wolfSSL:masterfrom
douzzer:20261030-RNG-invalidation-redux

Conversation

@douzzer

@douzzer douzzer commented Nov 6, 2026

Copy link
Copy Markdown
Contributor

wolfcrypt/src/random.c, wolfssl/wolfcrypt/random.h wolfcrypt/src/rng_bank.c,
linuxkm/lkcapi_sha_glue.c, wolfcrypt/test/test.c,
doc/dox_comments/header_files/random.h: rename nonce to addIn in reseed
APIs, for consistent naming of "additional" data as such.

tests/api/test_random.c, tests/unit-mcdc/test_random_fault_whitebox.c,
tests/unit-mcdc/test_random_whitebox.c: rename nonce to addIn in reseed APIs.

.github/workflows/codespell.yml: add "addIn" to ignore_words_list.

wolfssl/wolfcrypt/wc_port.h, wolfcrypt/src/wc_port.c: add wolfSSL_Atomic_Func_Ptr_CompareExchange() -- casting wrapper around wolfSSL_Atomic_Ptr_CompareExchange().

RNG: add auxiliary invalidation pathway, both sender-side and receiver-side.

  • add APIs wc_RNG_entropy_epoch_extra_inv_init() and wc_RNG_extra_entropy_epoch_init(), and associated callback types.
  • add internal routine current_entropy_epoch() and associated internal state.
  • refactor all ad hoc invalidation checks of global_entropy_epoch to use current_entropy_epoch().
  • refactor entropy epochs as 64 bit width, with wc_RNG_entropy_epoch_t (word64).
  • add struct wc_RNG_entropy_epoch_atomic and associated initializers.
  • add inline helpers wc_RNG_entropy_epoch_export(), wc_RNG_entropy_epoch_import(), and wc_RNG_entropy_epoch_increment_atomic().
  • refactor Hash_DRBG_Reseed() and its callers to pass cur_epoch only when defined(WC_RNG_HAVE_ENTROPY_EPOCH).
  • update tests and documentation for 64 bit epochs.
  • add test and documentation coverage of auxiliary epoch facility.

tested with

wolfssl-multi-test.sh ...
super-quick-check

Copilot AI balanced review requested due to automatic review settings November 6, 2026 20:13
@douzzer douzzer added the For FIPS v7 Module Related to FIPS v7.0.0 module prep for submission label Nov 6, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Non-atomic epoch transitions and unsynchronized callback registration can bypass RNG invalidation, duplicate publisher calls, and cause C data races.

4 open issues
What changed in this PR

This PR extends wolfCrypt’s RNG invalidation mechanism with auxiliary callbacks for publishing and receiving entropy events, while standardizing additional-input naming.

Changes:

  • Introduces 64-bit entropy epochs and routes invalidation checks through external-event detection.
  • Adds callback registration APIs and a function-pointer atomic comparison wrapper.
  • Renames reseed APIs from Nonce to AddIn, updates callers and documentation, and adds auxiliary-epoch tests.
File Description
wolfssl/​wolfcrypt/​wc_port.h Adds the function-pointer atomic comparison wrapper.
wolfssl/​wolfcrypt/​random.h Defines epoch types, helpers, callbacks, and renamed APIs.
wolfcrypt/​test/​test.h Declares the auxiliary-epoch test.
wolfcrypt/​test/​test.c Adds auxiliary-epoch coverage and updates API calls.
wolfcrypt/​src/​wc_port.c Checks the wrapper’s pointer-size assumption.
wolfcrypt/​src/​rng_bank.c Updates reseed and stir API names.
wolfcrypt/​src/​random.c Implements auxiliary invalidation and integrates epoch checks.
tests/​unit-mcdc/​test_random_whitebox.c Updates internal stir API calls.
tests/​unit-mcdc/​test_random_fault_whitebox.c Updates stir calls and related comments.
tests/​api/​test_random.c Updates tests to use renamed APIs.
linuxkm/​lkcapi_sha_glue.c Updates kernel reseed call sites.
doc/​dox_comments/​header_files/​random.h Documents auxiliary epochs and renamed APIs.
.github/​workflows/​codespell.yml Adds addIn to the spelling allowlist.

Review effort: Balanced

Comment thread wolfcrypt/src/random.c Resolved
Comment thread wolfcrypt/src/random.c Resolved
Comment thread wolfssl/wolfcrypt/random.h Resolved
Comment thread wolfcrypt/test/test.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12050

Scan targets checked: linuxkm-src, linuxkm-bugs, wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/workflows/codespell.yml, doc/dox_comments/header_files/random.h, wolfcrypt/test/test.h
Coverage: 7 of 10 in-scope changed file(s) opened by the reviewer; not opened: tests/api/test_random.c, tests/unit-mcdc/test_random_fault_whitebox.c, tests/unit-mcdc/test_random_whitebox.c

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Max

Comment thread wolfcrypt/src/random.c Resolved
…bank.c,

  linuxkm/lkcapi_sha_glue.c, wolfcrypt/test/test.c,
  doc/dox_comments/header_files/random.h: rename "nonce" to "addIn" in reseed
  APIs, for consistent naming of "additional" data as such.
tests/unit-mcdc/test_random_whitebox.c: rename "nonce" to "addIn" in reseed APIs.
…mic_Func_Ptr_CompareExchange() -- casting wrapper around wolfSSL_Atomic_Ptr_CompareExchange().
…r-side.

    * add APIs wc_RNG_entropy_epoch_extra_inv_init() and wc_RNG_extra_entropy_epoch_init(), and associated callback types.
    * add internal routine current_entropy_epoch() and associated internal state.
    * refactor all ad hoc invalidation checks of global_entropy_epoch to use current_entropy_epoch().
    * refactor entropy epochs as 64 bit width, with wc_RNG_entropy_epoch_t (word64).
    * add struct wc_RNG_entropy_epoch_atomic and associated initializers.
    * add inline helpers wc_RNG_entropy_epoch_export(), wc_RNG_entropy_epoch_import(), and wc_RNG_entropy_epoch_increment_atomic().
    * refactor Hash_DRBG_Reseed() and its caller to pass cur_epoch only when defined(WC_RNG_HAVE_ENTROPY_EPOCH).
    * update tests and documentation for 64 bit epochs.
    * add test and documentation coverage of auxiliary epoch facility.
…ra_entropy_epoch_reset() and wc_RNG_entropy_epoch_extra_inv_reset() (test helpers).

wolfcrypt/test/test.c and wolfcrypt/test/test.h: call rng_epoch_extra_test()
  from rng_epoch_test() rather than reporting its results separately; fix data
  race in rng_epoch_extra_getCb(); implement ext epoch save/restore in
  rng_epoch_extra_test().
@douzzer
douzzer force-pushed the 20261030-RNG-invalidation-redux branch from 6b5e3f0 to 2775dca Compare November 7, 2026 04:19
@douzzer
douzzer requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 7, 2026 04:33

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The new RNG epoch tests can falsely report success because subtest failures are not propagated, and small-stack allocation failure can discard installed production handlers without restoring them.

2 open issues
4 resolved since last review

Review effort: Balanced

Comment thread wolfcrypt/test/test.c Resolved
Comment thread wolfcrypt/test/test.c Resolved

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12050

Scan targets checked: linuxkm-src, linuxkm-bugs, wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Not reviewed (no scan target covers them): .github/workflows/codespell.yml, doc/dox_comments/header_files/random.h
Coverage: 3 of 10 in-scope changed file(s) opened by the reviewer; not opened: linuxkm/lkcapi_sha_glue.c, tests/api/test_random.c, tests/unit-mcdc/test_random_fault_whitebox.c, tests/unit-mcdc/test_random_whitebox.c, wolfcrypt/src/rng_bank.c, wolfcrypt/src/wc_port.c, wolfssl/wolfcrypt/random.h

Findings: 2
2 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfcrypt/test/test.c Resolved
Comment thread wolfcrypt/src/random.c Resolved
@douzzer
douzzer requested review from wolfSSL-Fenrir-bot and a balanced review from Copilot November 7, 2026 05:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🔵 Needs a closer look

A stale epoch import can publish mixed shadow values despite a failed low-word CAS, leaving a new external epoch undetected and suppressing RNG recovery.

No open issues 🎉

1 previously missed issue

In code that hasn't changed since last review

High severity Prevent stale imports from publishing mixed external epochs

wolfssl/​wolfcrypt/​random.h:1164

A stale import can fail its low-word CAS but still change the high word, manufacturing an unobserved external epoch and suppressing recovery. Starting with shadow 0x1, reader A detects 0x100000002 and pauses after invalidating; reader B detects a rollback to 0x3, imports it, and an RNG recovers; if the source then changes to 0x100000003, A's resumed import makes the shadow equal that new event without another invalidation. Use a coherent shadow update, such as a full-width CAS after the bump, that cannot publish mixed values; arbitrary external epochs and snapshot restores make this distinct from local counter wraparound.

2 resolved since last review

Review effort: Balanced

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12050

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): linuxkm-src, linuxkm-bugs
Not reviewed (no scan target covers them): .github/workflows/codespell.yml, doc/dox_comments/header_files/random.h
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

Findings: 1
1 finding(s) posted as inline comments (see file-level comments below)

💬 1 finding(s) from an earlier review are still open and were not re-posted:

  • Auxiliary epoch handler pointers are read twice without atomics, so a concurrent reset can cause a NULL function call — wolfcrypt/src/random.c:440

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

Comment thread wolfcrypt/test/test.c Resolved
* in rng_epoch_test(), capture retval from rng_epoch_extra_test() directly
  to ret, and move call to end of rng_epoch_test() so that it isn't
  conditional on rng_test_generate_is_local(rng).

* in rng_epoch_extra_test(), direct return on failed initial allocation to avoid
  spurious and destructive handler resets at cleanup.
@douzzer
douzzer force-pushed the 20261030-RNG-invalidation-redux branch from 8d2a21c to 813520c Compare November 7, 2026 06:08

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fenrir Automated Review — PR #12050

Scan targets checked: wolfcrypt-src, wolfcrypt-bugs, wolfssl-src, wolfssl-bugs
Unchanged since last review (not re-run): linuxkm-src, linuxkm-bugs
Not reviewed (no scan target covers them): .github/workflows/codespell.yml, doc/dox_comments/header_files/random.h
Coverage: 1 of 1 in-scope changed file(s) opened by the reviewer

No new issues found in the changed files.

💬 1 finding(s) from an earlier review are still open and were not re-posted:

  • Auxiliary epoch handler pointers are read twice without atomics, so a concurrent reset can cause a NULL function call — wolfcrypt/src/random.c:440

This review was generated automatically by Fenrir. Reported findings require changes before merge.

Review tier: Lite

…rg names.

Co-Authored-By: Kaleb Himes <kaleb@wolfssl.com>

@kaleb-himes kaleb-himes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you @douzzer, the renaming looks good! Over to PR captain for remaining Fenrir/CoPilot items.

@JacobBarthelmeh
JacobBarthelmeh dismissed wolfSSL-Fenrir-bot’s stale review November 9, 2026 21:11

comment made about the bots report being in a testing case and not applicable

@JacobBarthelmeh
JacobBarthelmeh merged commit ff206ad into wolfSSL:master Nov 9, 2026
443 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For FIPS v7 Module Related to FIPS v7.0.0 module prep for submission

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants