libngu PR #64: harden entropy backends and state handling
libngu-pr-64
Latest reviewed change
source content difference between and
The pull request was merged, its commit count increased from three to four, and a new review comment addressed the MICROPY_PY_STM backend selector.
Insights
random: harden entropy backends and state handling - #64
#64
-Open
-jgmontoya wants to merge 3 commits into
+Merged
+switck merged 4 commits into
switck:masterswitck/libngu:masterfrom
First lines only. The complete diff is in the timeline below.
- Organisation
- switck
- Evidence role
- Repository pull request
- Published
- not established
- Source changes
- 4
- Detected differences
- 5
- Unreviewed
- 0
- Copies held
- 6
Third of the three-PR split of #59, open at first capture on 7 Aug 2026 with three commits: rejecting two-word entropy cycles, hardening entropy backend boundaries, and gating the backend contracts in tests. Registered from its own page rather than from the title shown on #59 and #61.
Every check is recorded, including checks that found no text change. A detected edit is therefore bounded between two checks. The publisher's exact save time is not observable from this record. Last checked .
This post is held twice: here, with this project's own note on why it matters, and again as part of the conversation captured at , which is polled for changes. Both copies are the same post; neither is a separate event.
Snapshot and diff bodies for this chain monitor are held in the local evidence archive but withheld from the public site because they can contain the addresses of people who published nothing themselves. Capture times and reviewed change summaries remain available below.
Held captures
-
The pull request was merged, its commit count increased from three to four, and a new review comment addressed the MICROPY_PY_STM backend selector.
Recovered from the Internet Archive rather than captured by this project. The row records that third-party provenance separately from captures made by this project.
What changed from the previous capture 45 lines
Insights random: harden entropy backends and state handling - #64 #64 -Open -jgmontoya wants to merge 3 commits into +Merged +switck merged 4 commits into switck:masterswitck/libngu:masterfrom jgmontoya:rng-3-random-reworkjgmontoya/libngu:rng-3-random-reworkCopy head branch name to clipboard -ConversationCommits3 (3)ChecksFiles changed -Open +Aug 10, 2026 +ConversationCommits4 (4)ChecksFiles changed +Merged random: harden entropy backends and state handling#64 -jgmontoya wants to merge 3 commits into +switck merged 4 commits into switck:masterswitck/libngu:masterfrom jgmontoya:rng-3-random-reworkjgmontoya/libngu:rng-3-random-reworkCopy head branch name to clipboard Conversation There was an error while loading. Please reload this page. Copy link Copy Markdown +Contributor Summary Hardens the target entropy boundary used by the Cifra Hash_DRBG introduced in #61. Cifra Hash_DRBG remains the generator. It is initialized with 128 bytes from the selected backend, and generated bytes are XORed with fresh backend words. This PR makes backend selection fail closed, handles source failures safely, and documents the platform and serialization contracts. All reactions Comment thread ngu/random_backend.h +Outdated return true; } #elif MICROPY_PY_STM Uh oh! There was an error while loading. Please reload this page. All reactions +jgmontoya +Aug 10, 2026 +Copy link +Copy Markdown +Contributor +Author +There was a problem hiding this comment. +Choose a reason for hiding this comment +The reason will be displayed to describe this comment to others. Learn more. +Choose a reason +Spam +Abuse +Off Topic +Outdated +Duplicate +Resolved +Low Quality +Hide comment +Good catch. MICROPY_PY_STM is a module flag, so I changed the backend selector to test whether it is defined and added compile gates for MICROPY_PY_STM=0, covering the missing-provider failure and both valid rng_get() paths. +Sorry, something went wrong. +Uh oh! +There was an error while loading. Please reload this page. +All reactions +random: select STM32 backend when stm module is disabled +376441e +switck +merged commit 5d04106 +into +switck:master +Aug 10, 2026 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Successfully merging this pull request may close these issues. Uh oh! There was an error while loading. Please reload this page. -2 participants +3 participants Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. Footer © 2026 GitHub, Inc.Extracted text as captured
Skip to content Navigation Menu Sign inAppearance settings Platform AI CODE CREATION GitHub CopilotWrite better code with AI GitHub Copilot appDirect agents from issue to merge MCP RegistryIntegrate external tools DEVELOPER WORKFLOWS ActionsAutomate any workflow CodespacesInstant dev environments IssuesPlan and track work Code ReviewManage code changes Code QualityEnforce quality at merge APPLICATION SECURITY GitHub Advanced SecurityFind and fix vulnerabilities Code securitySecure your code as you build Secret protectionStop leaks before they start EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial servicesExcerpt only. The complete copy is held offline and backs quotations on this site. The original publication remains the canonical public source.
-
Reviewer scgbckbone approved the pull request and left two comments, a general approval and a nit on the MICROPY_PY_STM conditional. The reviewer and participant counts updated accordingly.
Recovered from the Internet Archive rather than captured by this project. The row records that third-party provenance separately from captures made by this project.
What changed from the previous capture 61 lines
August 7, 2026 21:18 test: gate external STM32 rng_get provider ab26f08 +scgbckbone +approved these changes +Aug 9, 2026 +View reviewed changes +scgbckbone +left a comment +Copy link +Copy Markdown +Contributor +There was a problem hiding this comment. +Choose a reason for hiding this comment +The reason will be displayed to describe this comment to others. Learn more. +Choose a reason +Spam +Abuse +Off Topic +Outdated +Duplicate +Resolved +Low Quality +Hide comment +nice improvements, thanks! +Sorry, something went wrong. +Uh oh! +There was an error while loading. Please reload this page. +All reactions +Comment thread +ngu/random_backend.h +return true; +} +#elif MICROPY_PY_STM +scgbckbone +Aug 9, 2026 +Copy link +Copy Markdown +Contributor +There was a problem hiding this comment. +Choose a reason for hiding this comment +The reason will be displayed to describe this comment to others. Learn more. +Choose a reason +Spam +Abuse +Off Topic +Outdated +Duplicate +Resolved +Low Quality +Hide comment +#if defined(MICROPY_PY_STM) +nit: just a module flag which can be 0 for stm32 build +Sorry, something went wrong. +Uh oh! +There was an error while loading. Please reload this page. +All reactions This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters Already have an account? Sign in to comment Reviewers -No reviews +1 more reviewer +scgbckbone +scgbckbone approved these changes +Reviewers whose approvals may not affect merge requirements Assignees No one assigned Labels Successfully merging this pull request may close these issues. Uh oh! There was an error while loading. Please reload this page. -1 participant +2 participants Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. Footer © 2026 GitHub, Inc.Extracted text as captured
Skip to content Navigation Menu Sign inAppearance settings Platform AI CODE CREATION GitHub CopilotWrite better code with AI GitHub Copilot appDirect agents from issue to merge MCP RegistryIntegrate external tools DEVELOPER WORKFLOWS ActionsAutomate any workflow CodespacesInstant dev environments IssuesPlan and track work Code ReviewManage code changes Code QualityEnforce quality at merge APPLICATION SECURITY GitHub Advanced SecurityFind and fix vulnerabilities Code securitySecure your code as you build Secret protectionStop leaks before they start EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial servicesExcerpt only. The complete copy is held offline and backs quotations on this site. The original publication remains the canonical public source.
-
The pull-request description was rewritten to match a force-pushed branch with revised commits, including the backend gate matrix and updated contract language.
Recovered from the Internet Archive rather than captured by this project. The row records that third-party provenance separately from captures made by this project.
What changed from the previous capture 85 lines
Copy link Copy Markdown Summary -Hardens the platform entropy boundary used by the Cifra Hash_DRBG merged in #61. This PR is stacked on #63; the first commit drops out of the diff after #63 merges. -The existing generator remains Cifra Hash_DRBG. It starts with 128 bytes from the selected entropy source, and generated bytes are XORed with fresh source words after the runtime health check. +Hardens the target entropy boundary used by the Cifra Hash_DRBG introduced in #61. +Cifra Hash_DRBG remains the generator. It is initialized with 128 bytes from the selected backend, and generated bytes are XORed with fresh backend words. This PR makes backend selection fail closed, handles source failures safely, and documents the platform and serialization contracts. Changes -Centralizes entropy backend selection in random_backend.h. Unknown targets fail to build. -Allows STM32 builds only when MICROPY_HW_ENABLE_RNG=1. The pinned MicroPython implementation otherwise uses a pseudo-random rng_get() fallback. Zero is rejected because rng_get() also returns zero on hardware timeout. -Requires NGU_ESP32_RNG_IS_TRUE_RANDOM=1 for ESP32. The integrator must keep RF or another ESP-IDF entropy source active whenever random data is requested. -Uses arc4random() on macOS and FreeBSD, and getrandom(2) on Linux. -Cleans the temporary seed buffer before raising when initial entropy collection fails. -Refuses thread-enabled builds without a GIL. The Unix variant disables threads because the DRBG and health state are mutable. -Corrects the rejection mask used by uniform() so it draws the minimum number of bits required for the requested range. -Documents the platform contracts and the limits of the runtime health check. -Compile gates -make -C ngu/ngu_tests gates checks these contracts: -STM32 missing and zero-valued hardware RNG configuration fail; value 1 succeeds. -ESP32 missing, zero, and wrong attestation values fail; value 1 succeeds. -Threads without a GIL fail; GIL and no-thread configurations succeed. +Move target entropy selection into random_backend.h. +Reject unknown targets and invalid target configurations at compile time. +Reject backend failures, zero words, and immediately repeated source words. +Clear the temporary seed buffer before raising when initial entropy collection fails. +Require the GIL when MicroPython threads are enabled. The Unix variant disables threads because the DRBG +and last-source-word state are mutable. +Correct uniform() rejection sampling to use the minimum bit width required for the requested range. +Add compile gates for valid and invalid backend configurations. +Document the backend, threading, and reseeding contracts. +Platform contract +STM32 accepts either: +MICROPY_HW_ENABLE_RNG=1 for MicroPython's hardware-backed rng_get(), or +an external rng_get() implementation with NGU_STM32_EXTERNAL_RNG_GET=1. +Missing, zero, and other values fail the compile gates. A zero result is rejected; MicroPython's STM32 implementation uses zero to report a peripheral timeout. +ESP32 requires NGU_ESP32_RNG_IS_TRUE_RANDOM=1. The integrator must keep RF or another ESP-IDF entropy source active whenever ngu.random is used. See the ESP-IDF RNG documentation. +macOS and FreeBSD use arc4random(). Linux uses getrandom(2). +Python calls rely on the VM's GIL for serialization. Direct C callers must provide their own +synchronization. +ngu.random.reseed() accepts bytes-like values of at least 32 bytes and mixes them into the existing +DRBG state. +The runtime source check is intentionally narrow: it rejects zero and an immediate repeated word. Target hardware still requires validation of the raw entropy source. Verification -make -C ngu/ngu_tests entropy-health make -C ngu/ngu_tests gates make -C ngu/ngu_tests hash-drbg-cavp -Strict syntax compilation of ngu/random.c -ngu/ngu_tests/test_random.py with the Unix MicroPython build -git diff --check +git diff --check origin/master...HEAD +The backend gate matrix passed, both Cifra Hash_DRBG SHA-256 CAVP test modes passed, and the changed ngu/random.c translation unit compiled successfully. +A full Unix rebuild was blocked by existing -Warray-bounds errors in the pinned MicroPython py/vm.c under Apple Clang 26. STM32 and ESP32 hardware validation remains required. Disclosure -This PR was developed with substantial LLM assistance and reviewed in several adversarial passes. The backend claims have negative compile tests, and the random path has focused runtime and CAVP coverage. Maintainer review and target hardware validation are still required. +This PR was developed with substantial LLM assistance. The behavior and configuration claims were checked against the source and compile gates. Maintainer review and target hardware validation are still required. Sorry, something went wrong. Uh oh! There was an error while loading. Please reload this page. #61 Merged jgmontoya -added 3 commits -August 7, 2026 00:16 -random: reject two-word entropy cycles -c09eff6 -random: harden entropy backend boundaries -b67a967 -test: gate random backend contracts -23d77bc -jgmontoya force-pushed the rng-3-random-rework random: fail-closed entropy backends; all output via HMAC_DRBG random: harden entropy backends and state handling Aug 7, 2026 +jgmontoya +force-pushed +the +rng-3-random-rework +branch +from +23d77bc to +1dfdf8c +Compare +August 7, 2026 20:56 +jgmontoya +added 2 commits +August 7, 2026 17:18 +random: harden entropy backend boundaries +5c1e854 +test: gate random backend contracts +0316d2f +jgmontoya +force-pushed +the +rng-3-random-rework +branch +from +1dfdf8c to +0316d2f +Compare +August 7, 2026 21:18 +test: gate external STM32 rng_get provider +ab26f08 This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden charactersExtracted text as captured
Skip to content Navigation Menu Sign inAppearance settings Platform AI CODE CREATION GitHub CopilotWrite better code with AI GitHub Copilot appDirect agents from issue to merge MCP RegistryIntegrate external tools DEVELOPER WORKFLOWS ActionsAutomate any workflow CodespacesInstant dev environments IssuesPlan and track work Code ReviewManage code changes Code QualityEnforce quality at merge APPLICATION SECURITY GitHub Advanced SecurityFind and fix vulnerabilities Code securitySecure your code as you build Secret protectionStop leaks before they start EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial servicesExcerpt only. The complete copy is held offline and backs quotations on this site. The original publication remains the canonical public source.
-
The pull request state changed from Open to Closed.
Recovered from the Internet Archive rather than captured by this project. The row records that third-party provenance separately from captures made by this project.
What changed from the previous capture 2 lines
Aug 1, 2026 random: reject two-word entropy cycles #63 -Open +Closed jgmontoya changed the title Rng 3 random reworkExtracted text as captured
Skip to content Navigation Menu Sign inAppearance settings Platform AI CODE CREATION GitHub CopilotWrite better code with AI GitHub Copilot appDirect agents from issue to merge MCP RegistryIntegrate external tools DEVELOPER WORKFLOWS ActionsAutomate any workflow CodespacesInstant dev environments IssuesPlan and track work Code ReviewManage code changes Code QualityEnforce quality at merge APPLICATION SECURITY GitHub Advanced SecurityFind and fix vulnerabilities Code securitySecure your code as you build Secret protectionStop leaks before they start EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial servicesExcerpt only. The complete copy is held offline and backs quotations on this site. The original publication remains the canonical public source.
-
Recovered from the Internet Archive rather than captured by this project. The row records that third-party provenance separately from captures made by this project.
What changed from the previous capture 0 lines
Extracted text as captured
Skip to content Navigation Menu Sign inAppearance settings Platform AI CODE CREATION GitHub CopilotWrite better code with AI GitHub Copilot appDirect agents from issue to merge MCP RegistryIntegrate external tools DEVELOPER WORKFLOWS ActionsAutomate any workflow CodespacesInstant dev environments IssuesPlan and track work Code ReviewManage code changes Code QualityEnforce quality at merge APPLICATION SECURITY GitHub Advanced SecurityFind and fix vulnerabilities Code securitySecure your code as you build Secret protectionStop leaks before they start EXPLORE Why GitHub Documentation Blog Changelog Marketplace View all features Solutions BY COMPANY SIZE Enterprises Small and medium teams Startups Nonprofits BY USE CASE App Modernization DevSecOps DevOps CI/CD View all use cases BY INDUSTRY Healthcare Financial servicesExcerpt only. The complete copy is held offline and backs quotations on this site. The original publication remains the canonical public source.
1 presentation-noise difference. Sidebar, ticker and other page chrome churn that our review classified as not being a change to what the source says.
- +5 -3 Only GitHub header chrome changed. The 'Sign in' and 'Appearance settings' labels split onto separate lines, and the search prompt changed from 'Type / to search' to 'Search/'.
The excerpts and plain unified diffs above show the text this project held and how it changed. To verify a quotation, compare it against the page itself or against the Internet Archive's copies, which are independent of this project.
Complete captures are held offline rather than mirrored here, so this page shows diffs and excerpts. If a quotation is ever disputed, the full copy can be produced. Ask.
Compare the screenshot or a quotation against the original while it is available.