Skip to content

Hash clone v2 - #176

Draft
ounsworth wants to merge 6 commits into
bcgit:release/0.1.3alphafrom
ounsworth:hash_clone_v2
Draft

ounsworth wants to merge 6 commits into
bcgit:release/0.1.3alphafrom
ounsworth:hash_clone_v2

Conversation

@ounsworth

Copy link
Copy Markdown
Contributor

This PR replaces #121.
That branch got all tangled up with the #133 changes, so it was easier to cherry-pick the specific commits onto a clean branch.

Original issue:

Adds docs for cloning a hash function mid-stream so that you now have two hash objects that are identical up to this point, but you can feed different suffix input into before finalizing.

I put this next to the existing sections for [Suspendable], since it's closely-related functionality. (and re-arranged order to put these before Memory Usage and Security Consideration sections).

Extension

During development of that, I realized that the pub interface flip of HMAC and HKDF introduced in #122 meant that the way HMACParams was defined was now really clunky. A refactor of that lead to realizing that actually, SP 800-107r1 specifies the security strength of an HMAC higher than the collision strength of the underlying hash function, so I re-worked that as well.

ounsworth and others added 6 commits October 24, 2026 08:42
(cherry picked from commit 1f4a84e)

Replayed onto the HMAC/HKDF utility-crate split, which had restructured both
crate doc headers. Adapted while resolving the conflict:

  * link [`SHA256Internal`] / [`SHA512Internal`] and [`SHA3Internal`] rather
    than [`SHA2`] / [`SHA3`]; the latter two are not type names in either
    crate and would have been dead intra-doc links.
  * keep the "## HMAC" pointer that the split added to the sha3 header.
  * move sha2's "Memory Usage" and "Security Considerations" below
    "Suspending and resuming execution", so that both crates' doc headers
    present the same section order. sha3 was already in that order.

Assisted-by: Claude Code:claude-opus-5

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…aliases

The HMAC test suite exercised HMAC over SHA-2 and SHA-3, which forced
bouncycastle-hmac to carry bouncycastle-sha2, -sha3, -rng and -hex as
dev-dependencies purely in order to test itself. That was a deliberate cycle
through dev-dependencies, flagged with a todo, left over from the
utility-crate split.

Split the suite by the hash it exercises and move each half to the crate that
publishes the aliases under test:

  * crypto/sha2/tests/hmac_tests.rs -- HMAC-SHA224/256/384/512: the full
    RFC 4231 suite, suspend/resume, keygen, and weak-RNG rejection.
  * crypto/sha3/tests/hmac_tests.rs -- HMAC-SHA3-224/256/384/512: the
    143-byte long-key regression (SHA3-224 has the largest block at 144
    bytes), truncated-tag rejection, suspend/resume, and keygen.

No test bodies or expected values were changed; the suite was partitioned,
not rewritten. bouncycastle-hmac's [dev-dependencies] are gone entirely and
with them the dependency cycle. The hex dev-dependency follows the tests to
bouncycastle-sha2, which did not previously have one.

This leaves bouncycastle-hmac with no tests of its own. That is inherent to
it being a utility crate rather than a gap in coverage: HMAC<H> cannot be
instantiated without a hash, and this crate must not depend on the hash
crates. Every behaviour it had is still exercised, from the two suites above.

On rebasing onto feature/simple-ciphers, its HMAC-SHA512/224 and -SHA512/256 tests
follow SHA-2 here, and its HMAC-SM3 tests move to a new crypto/sm3/tests/hmac_tests.rs.

Assisted-by: Claude Code:claude-opus-5

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
…ating it

Assisted-by: Claude Code:claude-opus-5
@ounsworth ounsworth added this to the 0.1.3alpha milestone Oct 24, 2026
This was referenced Oct 24, 2026

This branch has not been deployed

No deployments
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.

1 participant