Skip to content

Simple ciphers: stream + symmetric cipher unification off the release branch, plus SHA-512/t for any t - #133

Open
dghgit wants to merge 89 commits into
release/0.1.3alphafrom
feature/simple-ciphers
Open

dghgit wants to merge 89 commits into
release/0.1.3alphafrom
feature/simple-ciphers

Conversation

@dghgit

@dghgit dghgit commented Sep 16, 2026

Copy link
Copy Markdown
Contributor

Consolidates the stacked pair #113 (feature/stream-cipherrelease/0.1.3alpha) and #115
(feature/symmetric-cipherfeature/stream-cipher) into a single branch off the release
branch, and adds the SHA-512/t work on top.

feature/simple-ciphers was built by branching from release/0.1.3alpha and merging
feature/stream-cipher then feature/symmetric-cipher; both merges fast-forwarded, so the
content below the two new commits is exactly what #113 and #115 already carried — this is a
re-packaging, not new review surface. #113 (+21,938) and #115 (+2,310) sum to roughly the
+23,499 here.

New in this PR, on top of those two

core: SecurityStrength::from_bits / from_bytes become const fn (3912434) — two
keywords, no behaviour change. Needed so an associated const can derive a strength from a const
generic; split out ahead of the feature per CLAUDE.md's scope-of-changes rule.

sha2: SHA512t<T> is usable for every t FIPS 180-4 s. 5.3.6 defines a hash for (785dbef).
Previously only T = 224 and T = 256 had parameter impls, so nothing else could be named.

  • The t-value checks are back, and they are the spec's. b11f8f6 had narrowed sha512t_h0 to
    100 <= t < 512 and emitted a fixed three digits, since only 224 and 256 were reachable. With
    arbitrary t reachable that would produce the "0256" spelling s. 5.3.6 explicitly forbids —
    and hence the wrong IV — for every t below 100. The one- and two-digit branches are restored
    and check_t asserts the section's own rule: positive, < 512, not 384.
  • One deviation, documented: t must be a multiple of 8, because Hash is byte-oriented and
    a 100-bit digest has no representation here. BC Java's SHA512tDigest imposes the identical
    restriction, so the two libraries accept the same set of truncations.
  • Unapproved truncations are gated the way ElectronicCodeBook::ENCRYPTION_APPROVED gates
    two-key TDEA: SHA512tParams::<T>::FIPS_APPROVED is public and SHA512Internal::new asserts it
    in an inline const, so an unapproved t is a compile error at the call site and
    new_allow_unapproved_t() is the deliberate way in. That also blocks Default, which keeps an
    unapproved truncation out of generic code by accident.
  • ALG_NAME, OUTPUT_LEN and MAX_SECURITY_STRENGTH are derived from t, with const
    assertions pinning them to the values 224 and 256 previously had by hand.

Verification

  • cargo test --workspace: 943 passed, 0 failed (was 923). cargo fmt --check clean; no new
    clippy warnings. Both new commits build independently.
  • Spec text read from a freshly downloaded FIPS 180-4, not from recall.
  • Test vectors cross-checked against BC Java's SHA512tDigest, an independent implementation:
    eight truncations (8, 16, 24, 88, 96, 104, 264, 504) spanning all three decimal branches, over
    the FIPS 180-4 Appendix C messages plus the one-million-'a' case. The 224/256 rows in the same
    table match the NIST-published values.
  • cargo mutants on the changed files: 259 mutants — 180 caught, 5 timeout-kills, 69 unviable,
    5 missed. All five missed are the pre-existing XOR/OR equivalences already annotated at their
    sites in ch, maj and do_final_internal; no new missed mutants.

Note for reviewers

Adding const to a public core function is a forward compatibility commitment, and
SHA512tParams is currently its only caller. The alternative was a private copy of the rounding
ladder inside sha2, free to drift from the real one — happy to switch if the API-surface cost is
the greater worry.

🤖 Generated with Claude Code

dghgit and others added 30 commits September 6, 2026 12:02
…ptor with multi-block and one-shot methods (PR #107)
…me lengths, AES_CBC_* aliases, simpler CLI (PR #109)
…locks8, SymmetricCipherEncryptor/Decryptor (from feature/sm4); CFB follows suit
…cb CLI subcommands; block-mode CLI generic over INIT_DATA_LEN
…S_PADS; SymmetricCipherEncryptor::do_final reports its output length
…rams/HashMLDSAParams/MLKEMParams traits, one impl per parameter set (#117)
…eamCipherDecryptor pair, shaped like the block cipher pair (in place, any length, generated init data); TestFrameworkStreamCipher implemented in place of its todo!()
… and Cfb8 (SP 800-38A Sec 6.3, s = 8) is added, with AES_CFB8_* aliases, aes*-cfb8 CLI subcommands and a shared stream-mode CLI
…, CFB8 is added, and the StreamCipher trait is replaced by the split encryptor/decryptor pair; re-measured throughput and mutation figures
…inst real AES at all three key lengths, not only the toy permutation
…th picks the counter width (max 4 bytes) and which errors rather than repeat a counter, with AES_CTR_* aliases and aes*-ctr CLI subcommands
… the nonce-plus-counter construction, pinning the 1, 2 and 3-byte counter widths that the ACVP and OpenSSL vectors cannot reach
dghgit and others added 30 commits September 9, 2026 13:42
…pt_4blocks (was eight): AES fills a pair and the u16/u32-plane engines fill four, so eight was two passes for every engine and left a four-lane engine half-empty on a 4-to-7-block tail; modes chunk fours, then pairs, then singles, the framework suite and the rotated-four toy pin the four path, benches and notes follow
…ipherEncryptor / SimpleCipherDecryptor; the framework suite becomes TestFrameworkSimpleCipher and the modes API test file is renamed to match; aes, padding, modes and the notes follow
…ems like a personal workflow rather than a general thing.
…ems like a personal workflow rather than a general thing.
…Added a note about this to QUALITY_AND_STYLE.md.
…so the lib target the src/ move introduced does not compile them as failing Rust doctests
…ding, and the SHA-512/t sealing trait is now named SHA512InitValue
….6 prints it, with H(0)'' on the left of the XOR and as the IV of the final SHA-512 call
…enches sources moved under src/ and are now doctested, and integration tests are preferred per QUALITY_AND_STYLE.md
…, dropping the one- and two-digit branches of s. 5.3.6 that no approved-t caller or test could reach; of its 43 mutants none is now missed
…4 a comment claimed, and exceeding it truncates the 64-bit length field silently instead of panicking on the byte-count add, so do_update asserts it in debug builds; sha512t_h0's assertion stops crediting FIPS 180-4 s. 5.3.6 with the t >= 100 its own three-digit formatting imposes, and a new test pins the 128-bit length carry that exempts SHA-512
… l < 2^64 bits, and exceeding it truncates the 64-bit length field silently instead of panicking on the byte-count add, so do_update asserts it in debug builds
…tor bundled into a feature commit makes the diff unreviewable however correct it is, so a refactor that unblocks the task goes in its own commit ahead of it and one that unblocks nothing gets proposed rather than done
… whose per-hash instantiations live in the hash crates, so HMAC_SHA512_224 and HMAC_SHA512_256 move to sha2::hmac as HMACParams impls; HMAC-SM3 is dropped here and reinstated under the new layout in the following commit, which is the only way to keep both commits building
…ed, as a new sm3::hmac module holding the HMACParams impl, the HMAC_SM3 alias and the OSCCA OID, with its criterion bench, factory and CLI wiring and known-answer tests restored alongside it
…anch, taking the shortened release notes from b282942 over the long form this branch still carried and accepting 5825050's deletion of core-test-framework/summary.md; no code conflicts, since the MAC factory and CLI changes are additive here
…a parameter set can derive MAX_SECURITY_STRENGTH from a const generic instead of naming a variant by hand; no behaviour change, and the following commit is the first caller that needs it

Assisted-by: Claude:claude-opus-5

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
…a hash for, not just the two approved truncations, so the IV Generation Function regains the one- and two-digit decimal branches that b11f8f6 dropped as unreachable -- writing a fixed three digits gives the "0256" spelling the section forbids, and hence the wrong IV, for every t below 100; t is checked against the section's own rule (positive, below 512, not 384) plus this crate's multiple-of-8 requirement, which BC Java's SHA512tDigest also imposes, and the unapproved truncations carry SHA512tParams::FIPS_APPROVED = false which SHA512Internal::new asserts in an inline const, so reaching one takes new_allow_unapproved_t() the way an encrypting mode takes ENCRYPTION_APPROVED; ALG_NAME, OUTPUT_LEN and MAX_SECURITY_STRENGTH are now derived from t and pinned to their old values for t = 224 and t = 256; new sha512t_tests.rs cross-checks eight truncations spanning all three digit branches against BC Java, and of the file's 259 mutants 180 are caught, 5 die on timeout and the 5 missed are the XOR/OR equivalences already documented at their sites

Assisted-by: Claude:claude-opus-5

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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.

2 participants