A valid signature proves that a trusted key signed these bits. It does not by itself prove the version is acceptable, that the measured image is the one about to execute, or that a key is released in the right lifecycle.
Learning objectives and classroom plan
By the end of this lesson, you should be able to:
- Derive the fetch/key distribution over 128 combinations of seven conditions.
- Locate TOCTOU and misbinding using transaction, digest, version, and key slot.
- Specify interruption and recovery contracts for version-floor updates.
Suggested 50-minute teaching plan: Condition definitions 10 minutes; enumeration 10; misbinding cases and lab 15; power-loss state discussion 15. This includes student calculations, lab work, and discussion. It is a teaching plan, not measured student completion time.
Bind the decision to the executed image
At a warehouse, seal, lot number, and contents must match; checking the seal alone does not prove the box was not swapped in transit. Secure Boot binds signer, image digest, hardware target, security version, load address, and final fetch to one transaction. The analogy does not include hash-collision assumptions, DMA races, or microarchitectural caches.
A typical path uses an immutable/ROM root to obtain a key or key identifier, verifies the manifest and signature, enforces a version floor, locks relevant settings, then transfers execution. If DMA can change writable memory after verification, the earlier pass no longer describes the current bytes. Bind the measured digest to an immutable buffer or protected load region and record acceptance at commit. OpenTitan’s key-manager theory separates software binding, version checks, and sideload outputs; interpret it against the actual product integration. Key manager.
The gap between check and use is easy to miss. If software reads a rollback counter only once, a concurrent update may change the version. If key release checks only a boot_done sticky bit, it may reuse permission from a previous image. Bind transaction ID, digest, version, lifecycle, and destination key slot; fail closed on release. Also prevent a security rejection from creating unrecoverable denial of service.
Define asset boundaries as the first instruction fetch and the first sideload-key use. First fetch must bind signature, version, digest, and transaction ID to the same transaction. Key release must also meet lifecycle and destination key-slot policy. This RTL/SVA sketch is not a product assertion and has not been wired or compiled.
Find TOCTOU and rollback
Compare a valid current image, a correctly signed but stale image, a digest for image A followed by fetch from image B, a stale boot_done sticky bit, and a production-key request in debug lifecycle. Preserve the first unauthorized acceptance edge and the rejection reason for each trace.
Worked case: one boot_done, two assets
Open this lesson’s interactive lab
Continue with the teaching chip from Lesson 11. ROM is about to launch an image, and the cryptographic engine is preparing to use a production key. An engineer proposes using one boot_done to enable both CPU fetch and sideload. Ask first: does permission to execute a signed debug image also permit that image to use a production key? If not, a single pass already omits a policy distinction.
Separate acceptance into the first instruction fetch and the first key use. The former protects which bytes execute; the latter protects which execution environment may use which key. They share signature, version, and image binding, but need not share lifecycle permission. Combining them lets the less restrictive condition authorize the other asset.
The interactive model represents this with seven Boolean conditions. Let S be signatureValid, V be versionAllowed, D be digestBound, L_f be fetchLifecycleAllowed, L_k be productionKeyLifecycleAllowed, T_f be fetchTxnBound, and T_k be keyTxnBound. Then fetch = S ∧ V ∧ D ∧ L_f ∧ T_f; key = S ∧ V ∧ D ∧ L_k ∧ T_k. This is an authorization matrix. It does not perform cryptographic verification, an actual DMA operation, or key derivation.
| Model case | S | V | D | L_f | L_k | T_f | T_k | fetch | key |
|---|---|---|---|---|---|---|---|---|---|
| Current authorized image | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
| Obsolete version | 1 | 0 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
| Verify A, fetch B | 1 | 1 | 0 | 1 | 1 | 1 | 1 | 0 | 0 |
| Reuse the previous transaction’s completion flag | 1 | 1 | 1 | 1 | 1 | 0 | 0 | 0 | 0 |
| Debug environment requests a production key | 1 | 1 | 1 | 1 | 0 | 1 | 1 | 1 | 0 |
| Invalid signature | 0 | 1 | 1 | 1 | 1 | 1 | 1 | 0 | 0 |
Start with the fifth row. All five fetch conditions are 1, so fetch is allowed. L_k is 0, so key use is rejected. That is consistent with two assets having different policies. In the second row, a valid signature does not compensate for V being 0: both acceptance points reject. Signature verification addresses origin and integrity; the version floor determines whether an older version remains permitted. Neither substitutes for the other.
Trace “verify A, then use B” step by step
A and B are symbolic names for different images, not actual hashes. At t0, ROM verifies A. At t1, the controller records pass. At t2, a writable region is replaced with B. At t3, the CPU fetches its first instruction from that region. Even if pass remains 1, the bytes used at t3 are outside that verification. This is a teaching TOCTOU counterexample, not an attack reproduced in RTL or silicon by this lesson.
A repair starts by choosing a contract the implementation can maintain. If the verified load region becomes immutable, identify whether CPU, DMA, debug, and other bus masters all encounter the same protection, and when the lock takes effect. If the design re-verifies, explain how verification and use remain consistent. Computing a digest again at an earlier instant can leave another gap. The repair must bind evidence to the object actually used at acceptance.
Transaction ID similarly distinguishes this attempt from the previous one. Suppose boot A succeeded and its boot_done remained 1. If a new boot B starts without revoking old authorization, B can borrow A’s completed state. Row four sets both T_f and T_k to 0 so that readers can see both acceptance points reject. Real ID width, wraparound, reset behavior, and cross-domain transfer require separate design work. The model proves none of those details.
The key path must also record the destination key slot and first use, rather than just the release command being issued. Sideload can keep keys off an ordinary software read interface, but authorization still needs checking. If the receiving engine retains a previous valid flag, a new image could use old authorization in the wrong transaction generation. Follow command, acknowledgment, and actual use to locate the asset boundary where the effect becomes irreversible.
Deeper exercises: explain each rejection
Exercise A: change one condition. Start from row one. Set only V, D, T_f, or T_k to 0 in each trial. Calculate fetch and key; compare V and D with the table, and derive T_f and T_k from the formulas. Which conditions should affect only one acceptance point?
Answer and reasoning: V or D at 0 rejects both. T_f at 0 rejects fetch while key can remain allowed. T_k at 0 rejects key while fetch can remain allowed. The last two are new exercises derived from the formulas; the existing six presets do not provide those rows separately. Describe them as matrix deductions, rather than claiming the interface has new controls.
Exercise B: repair a sticky flag. Someone proposes clearing boot_done when a new boot starts. Is that sufficient when the producer restarts but the key consumer does not?
Answer and reasoning: Also check retained consumer permission, stale in-flight messages, and consistent ID or epoch handling. Clearing source state does not guarantee destination revocation. A legitimate new boot must be able to re-establish authorization too, or the repair could cause permanent denial of service.
Exercise C: find circular evidence. A testbench copies DUT signature_ok into reference_signature_valid, while a fault may flip signature_ok. The assertion reports no error. Does that establish signature-policy safety?
Answer and reasoning: No. A fault-affected signal controls both acceptance and the expected result, so they may become wrong together. An independent oracle derives expectations from trusted inputs and policy, outside the specified fault influence cone. Check it with the invalid-signature negative case and the current-authorized-image positive control. These are harness requirements. This lesson executes neither a real signature algorithm nor a formal proof.
Classroom derivation: 128 combinations beyond six presets
Prerequisites are Boolean AND, set intersection, and a persistent version floor. Seven independent binary inputs give 2⁷ = 128 combinations. This enumerates Boolean inputs, not reachable states in every product. Fetch fixes five conditions at 1 and leaves L_k and T_k free, so 2² = 4 combinations permit fetch. Four similarly permit key use.
Both acceptance points allow only when all seven conditions are 1, giving one shared combination. Fetch-only therefore has 4 − 1 = 3 combinations, as does key-only. Neither allows in 128 − (1 + 3 + 3) = 121 combinations. Account for the intersection before calculating the remainder. Adding the two fours would incorrectly count eight combinations with at least one permission.
| fetch | key | Combinations | Derivation |
|---|---|---|---|
| 1 | 1 | 1 | All seven conditions are 1 |
| 1 | 0 | 3 | Four fetch combinations minus one shared |
| 0 | 1 | 3 | Four key combinations minus one shared |
| 0 | 0 | 121 | 128 minus seven with either permission |
The three fetch-only combinations have L_k/T_k at 0/0, 0/1, and 1/0; the other five conditions are 1. The first two lack key-lifecycle permission; the third lacks key-transaction binding. This explains execution versus key-use permission beyond the debug preset alone. Key-only rows are combinations in the independent Boolean model. If a real boot protocol prohibits them, its unreachable-state assumptions need verification.
Rollback floor and power loss need another state table
Let the persistent security version floor be 5. Version 4 is rejected despite a valid signature; version 6 satisfies the version condition. Decide when the floor advances to 6. Advancing before a viable recovery path exists may cause power loss or image failure to leave the only bootable version 5 rejected. Advancing too late may leave a window permitting rollback to 5. Security and recovery need joint design; this example prescribes no universal update order.
An update contract defines new-image integrity and authorization; pending, confirmed, and recovery states; counter-write atomicity and persistence; and which image is selected after every possible power-loss point. Recovery images have their own authorization and version policy. Treat each interruption point as an input and check unauthorized execution and unrecoverable loss of legitimate service, rather than asking only whether to write the counter first or last.
Compare two TOCTOU paths. Hashing an SRAM copy and executing that same copy requires protecting it against every writer between verification and use. With execute-in-place (XIP) from flash, verification reads and CPU fetch are separate accesses, so contents and mapping need consistency protection. Neither memory-path name establishes that contract. Multistage boot also needs image, transaction, version, and key-destination binding at every handoff; a single-image matrix does not authorize all stages.
Calculation and design exercise: Add key-slot binding K_s as an eighth Boolean input affecting only key use. How many combinations allow both, fetch only, key only, or neither? If K_s is 0 while all original seven conditions hold, is key use allowed?
Worked answer: Eight inputs give 256 combinations. Fetch fixes five and leaves three free, giving eight allowed combinations. Key fixes its original five plus K_s, leaving two free and giving four. Their intersection has all eight at 1, one combination. The four counts are therefore 1, 7, 3, and 245. With K_s = 0, fetch can remain allowed while key use must reject. This is a new article derivation; the original seven-input HTML does not implement an eighth input.
A power-loss table for an explicit update contract
Construct a separate two-slot example: A is verified version 5; B will become version 6; version floor F starts at 5. Assume verifiable images/slot metadata, atomic and durable confirmed records and F writes, and an available independent recovery image R at version 6 with separate authorization. These are assumptions; the original lab implements no storage or power-loss behavior.
The contract marks B pending only after complete writing and verification. It raises F only after successful trial boot and a durable confirmed record. Every restart verifies image and version again, without trusting an earlier pass. Slot selection follows this table:
| Interruption point | Durable state/F | Restart choice and rejection | Unauthorized execution/recovery |
|---|---|---|---|
| Before writing B | A confirmed; F=5 | Verify and select A5 | No unauthorized execution; A serves |
| B incompletely written | B incomplete; F=5 | Reject B; verify and select A5 | No unauthorized execution; A serves |
| Verified B and pending record durable | A5/B6; F=5 | Try B6; this contract permits fallback to A5 if needed | A5 remains permitted under F; a legitimate recovery path exists |
| B confirmed, before raising F | B confirmed; F=5 | Verify and select B6; use R6 if needed | Unauthorized paths remain rejected; B or R recovers |
| During atomic F write | B confirmed; F can only be 5 or 6 | Verify and select B6; use R6 if needed | Both possible floors permit version 6 |
| F=6 durable | B confirmed; F=6 | Verify and select B6 or R6; reject A5 | No rollback to 5; B/R recovers |
Recovery relies on image availability and successful verification. If B and R both fail, reject execution and record service loss. If an F write can produce a third invalid value, atomicity has failed; detection and recovery need another definition. The interim F=5 rows do not claim that merely trying version 6 immediately forbids 5. Specify when the policy commits to a new floor.
Power-loss exercise: Raise F before B is fully written. F is now 6, B is incomplete, A is still 5, and no R6 exists. Which requirement fails?
Answer: B fails verification and A fails the floor check. Safe rejection may hold while legitimate service has no recovery path. Establish verifiable new-image and recovery conditions before the irreversible update under an explicit contract; do not bypass the version floor to conceal the availability failure.
Replay and compare
Download the program and result JSON into one folder. Run with Python 3.8 or newer:
python rtl-university-workbook-v1.py --output replay.json
Compare replay.json with the supplied result, starting with this lesson’s lesson12 field. sourceSha256 identifies the program’s bytes, separately from mathematical correctness. Editing content or resaving LF as CRLF changes that value. Keep the downloaded original and save student changes separately to distinguish method changes from file changes.
Download the classroom replay program · Inspect fixed JSON results
Offline interactive lab
RTL / SVA review direction
These are property sketches: define the harness transaction, reset and oracle, then confirm sampling boundaries before binding to the design. They have not been compiled or proven.
assert property (@(posedge clk) disable iff (!rst_n)
key_release |-> signature_ok && reference_signature_valid && active_txn_id == reference_txn_id &&
active_digest == reference_digest && active_version >= security_version_floor &&
reference_key_release_allowed && key_slot == reference_key_slot);
assert property (@(posedge clk) disable iff (!rst_n)
first_fetch |-> fetch_digest == reference_digest && fetch_txn_id == reference_txn_id &&
signature_ok && reference_signature_valid &&
fetch_version >= security_version_floor && reference_fetch_policy_ok);
cover property (@(posedge clk) disable iff (!rst_n)
key_release && signature_ok && reference_signature_valid && reference_key_release_allowed);
cover property (@(posedge clk) disable iff (!rst_n)
first_fetch && signature_ok && reference_signature_valid && reference_fetch_policy_ok);
reference_*, reference_signature_valid, and security_version_floor must come from an independent harness oracle, not DUT sticky/pass signals. If first_fetch and key_release use different clocks, check each in its event domain; this sketch does not prove CDC.
This snippet does not prove CDC, timing, side-channel, or physical injection behavior; each requires its own tool evidence or measurement.
Check your reasoning
- Recognition — What does a valid signature establish, and what remains undecided? Reasoning: It authenticates a signed bit string under the selected key. Version policy, target binding, the bytes eventually fetched, and key-release policy remain separate checks.
- Contrast — How is a version floor different from signature verification? Reasoning: A signature can be valid for an old image. The version floor rejects rollback according to policy; it does not authenticate the image by itself.
- Scenario — DMA can alter the verified buffer before the first instruction fetch. What must be bound or protected? Reasoning: The digest must describe the same bytes the CPU fetches. Lock or protect the loaded region, or verify at the actual consumption boundary.
- Failure diagnosis — A sticky boot_done bit came from the previous boot transaction. Why is it insufficient evidence for key release? Reasoning: The bit does not identify the current image or transaction. Bind transaction ID, digest, lifecycle, version, and destination key slot to this release.
- Design risk / transfer — A signed image may be fetched in debug lifecycle, but its production sideload key must stay unavailable. Which results should be recorded? Reasoning: Record first fetch and first key release independently. The fetch may be allowed while the production key release is rejected.
References
OpenTitan Key Manager · NIST SP 800-193
MY ACADEMY · LESSON FILM
Lesson video
The film explains this lesson’s data path. After a section, return to the interactive exercise and change the input or fault conditions. The animation presents a teaching model; it does not replace RTL simulation.
Swipe the film horizontally, or use the arrow keys to inspect the diagrams.
Diagram scope
Teaching model · Not RTL simulation or silicon testing
Uncompiled property sketches; not CDC, side-channel or physical-injection proof
Narration uses a synthetic voice. Both the interaction and animation have model boundaries; interpret results using this lesson’s sources and validation scope.
Wrap-up: take this lesson into a design review
- Threat model and assumptions
One boot transaction contains image digest, signature result, version floor, lifecycle and key slot; final fetch/release is the asset boundary.
- Why the design fails
The verification result is detached from the later consumer, or rollback/old sticky state reuses stale authorization.
- Defenses
Bind bytes, version, lifecycle and key slot in immutable transaction context; fail closed and protect the accepting endpoint.
- Validation and checks to perform
Check valid, stale, modified, swapped-image, and lifecycle-mismatch cases; RTL/signature/memory integration is untested.
- Limits and unverified claims
Product key policy, supply-chain root trust, side channels, physical key vault and recovery-image details are outside scope.
Try a changed assumption
Add rollback-counter update and concurrent DMA. Identify when contents must be locked and when sideload key release is safe.
This wrap-up summarizes the lesson’s teaching cases, references and experiment scope. Checks not reported as completed remain future work.