Repository navigation
sha2: one SHA-2, toyos-crypto's; toyos-sha2 and toyos-sha2-hw gone - #1016
Conversation
The owner (2026-10-22): use our own crypto where possible. Every SHA-256 and SHA-512 in the tree is now toyos-crypto's: the build's digests, pkg, lib/swap, sdk/icon's test, lib/update, the UEFI loader and system/update. - The loader keeps SHA-NI. Its target is soft-float, so the crate's intrinsic path does not compile there. toyos-sha2-hw's one asm block, which saves and restores every XMM register it uses, moves into the crate as its UEFI SHA-256 path (`arch/x86_64/sha_saving.rs`), held against the portable rounds on any x86-64 host with the instructions. - AArch64 hashes on the Armv8 SHA instructions where the target promises them at compile time (`sha2` for SHA-256, `sha3` for SHA-512, as Rust names FEAT_SHA256 and FEAT_SHA512): the development Mac's, where the build hashes every image. ToyOS's own AArch64 targets promise neither and nothing detects them at run time; the issue records that. - Consumers keep the crate's refusal past FIPS 180-4's 2^61-byte bound: a stream with an error path carries it, and a hash of an in-memory or signed-length input expects it, naming why. The build has one helper, `toyos_build::sha256`, in place of release's `sha256_hex`. - toyos-crypto now ships in an image, so the licence gate counts files under its directory as shipped. NIST's ACVP vectors, under the NIST-Software licence the allowlist does not name, move to `tests/acvp/`, as `tests/cavp/` was placed for the same reason. The ML-KEM unit test reads its vectors at run time rather than embedding them, so Miri skips that one test. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q
Review, round 1: #1016 at 55ecebe (code be8ac5c), against main 18a3873ArchitectureThis is the right shape. One SHA-2 now lives in the crate that owns ToyOS's crypto, and both superseded crates are gone. Nothing in the tree outside
Errors are handled in two ways. Streams with an error path ( Net change: +358/−789. Production code shrinks: about 300 lines of I checked the AArch64 rounds against DDI 0487's operand conventions:
All of these are correct. The two negative controls in the evidence (H2 operand, SHA512H operand) show that the dispatched-against-portable test catches errors at this level. Required
Suggestions
Evidence
SEND BACK: items 1–3 are cheap fixes. Item 4 is gated on the bench run. |
|
The speed requirement for #1016 has bench results. These come from the probe f0a2d1b56: #1019's head plus
The units are the parity row's, the same for both columns. Lower is faster. The crate is no slower than #1019's loader signature verification took 253,975 counter ticks on the T14 and 122,724 on the AMD bench. The AMD loader states no counter rate. Readbacks are kept by the orchestrator, for the implementer to publish. |
- The issue's SHA-512 figure is its evidence's: 1.36 GB/s at 1 MiB on the Mac, not 1.7, which was a run before. - ML-KEM key generation stays under Miri: the keygen-vector test reads its file from `tests/acvp/` with Miri's isolation off, which the recorded Miri run now names, rather than being ignored there. - `SHA_BOUND` names `ARCHIVE_CAP`, which holds a streamed archive to 1 GiB; a signed `u64` does not. - The register-saving SHA-256 block's host test fails on a host without the instructions, as toyos-sha2-hw's did, rather than passing. - `SAFETY:` on the AArch64 path's unsafe blocks; NOTICE's sentence reflowed. - The speed requirement holds: on both benches the crate's SHA-256 is no slower than toyos-sha2-hw's at 64 B, 16 KiB and 1 MiB, and 2.8 to 4.6 times as fast at 64 B. The issue's row says so. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q
|
Response to review r1. The head is e5414b9 (main hasn't moved).
Suggestions, all taken:
|
Review, round 2: #1016 at e5414b9All of round 1's required items are resolved.
Suggestions taken:
One leftover nit, not blocking:
LAND |
Problem
The owner asked (2026-10-22): "Use our own crypto where possible." ToyOS hashed with two crates of its own besides
toyos-crypto's SHA-2:toyos-sha2, scalar;toyos-sha2-hw, SHA-NI on x86-64 and scalar on AArch64.The build,
pkg,lib/swap,system/update,lib/updateand the UEFI loader hashed with them.On main after #993 and #1015.
Change
toyos-crypto's: the build's digests (now one helper,toyos_build::sha256),pkg,lib/swap,sdk/icon's test,lib/update(SHA-512 over the signed header too), the loader andsystem/update.toyos-sha2andtoyos-sha2-hware deleted.toyos-sha2-hw's single asm block, which saves and restores every XMM register it uses, moves into the crate as its UEFI SHA-256 path (arch/x86_64/sha_saving.rs). On any x86-64 host with the instructions it is held to the portable rounds. Hosted x86-64 keeps the crate's existing intrinsic path.sha2for SHA-256 andsha3for SHA-512, as Rust names FEAT_SHA256 and FEAT_SHA512 (arch/aarch64.rs).pkg'sReadandupdate'sstream_root.expects it and names why.toyos-cryptonow ships in an image, so the gate counts files under its directory as shipped.NIST-Software, a licence the allowlist does not name) move totests/acvp/, the waytests/cavp/was placed. TheirNOTICEsection andCOMMITTED_FILESrows move with them.MIRIFLAGS=-Zmiri-disable-isolation, which the issue's Miri record now names.undocumented_unsafe_blocks, which now reaches the crate's code built for UEFI. Thoseunsafeblocks and impls getSAFETY:comments.Checks
cargo run -- --ci hostat e5414b9 (review r1): exit 0, 93 steps green. Before r1, the same at be8ac5c (on main 18a3873).SAFETY:comments, was red on the loader's clippy step alone.cargo test -p toyos-cryptoin all three forms (portable, all features, default): exit 0. The crate's SHAVS tests (toyos-crypto stage 4, the test side: vectors, integer oracle, differential, fuzz, controls, Miri and the constant-time harness #993) run the dispatched path.hash::tests::dispatched_compression_matches_the_portable_roundscompares the instructions with the portable rounds over 0–9 blocks. Negative controls:toyos-update(withsign),toyos-swap,pkg,toyos-iconandupdate-copies: all pass. The tests that pin fixed digests also pass: the icons' pixels, the wallpaper, ROOT's UUID andNOTICE's records. Those are byte-for-byte oracles that the SHA-256 is unchanged.cargo run -- --build-only: exit 0 for x86-64 and for AArch64.toyos-cryptois compiled for both UEFI targets and the guest.a_bent_supervisor_is_refused_and_the_other_slot_bootspasses, on images built for both architectures. The loader's SHA-256 refuses the bent slot's section and boots the intact one.licence::judgepasses: only its six standing exceptions remain. Before the vectors moved, it refused the sixNIST-Softwarefiles.Evidence: https://github.com/ToyOSOrg/evidence/tree/f1de6e6eba9952b7c461c2fa3844ad65e7d9c471/pr-1016
The speed requirement holds
The owner required the crate to be no slower than
toyos-sha2-hw. A never-landed probe image timed both SHA-256s against the same ring incrypto_parity, one boot on each bench. Mean times; lower is faster.The crate is no slower at any size, and 2.8–4.6× as fast at 64 B. Readbacks (extracts, no machine identifiers): https://github.com/ToyOSOrg/evidence/tree/c186d4592d98b86e5fef3ea45e570f05279ddb4b/pr-1016/r1
Risks
update's streamed ROOT hash is still untimed on any compression (issues/no-t14-reading-of-updates-root-hash-before-and-after-sha-ni.md, reworded).🤖 Generated with Claude Code
https://claude.ai/code/session_01PXEk8BBMDT8tXu4AnENB9Q