Skip to content

feat(core): add a boring feature for SHA and HMAC - #923

Open
vovacf201 wants to merge 4 commits into
apache:mainfrom
vovacf201:feat/core-boring-backend
Open

vovacf201 wants to merge 4 commits into
apache:mainfrom
vovacf201:feat/core-boring-backend

Conversation

@vovacf201

Copy link
Copy Markdown

What

Adds an opt-in boring cargo feature to reqsign-core that computes the SHA and HMAC in reqsign_core::hash with BoringSSL (through the boring crate) instead of RustCrypto.

  • reqsign_core::hash keeps its public API. The functions now call a private backend module, which is either RustCrypto (default, unchanged) or BoringSSL (boring feature). Covered: hex_sha1, hex_sha256, hmac_sha256, base64_hmac_sha256, hex_hmac_sha1, hex_hmac_sha256, base64_hmac_sha1.
  • The facade reqsign crate gets a matching boring feature that forwards to reqsign-core/boring.
  • Known-answer tests run on both backends: SHA-256/SHA-1 digests of "" and "abc", RFC 4231 test cases 1 and 6 (including a key longer than the block size), RFC 2202 test case 1, and the AWS SigV4 signing-key example from the AWS documentation.
  • CI: one extra step runs the reqsign-core and reqsign-aws-v4 tests with --features reqsign-core/boring. Clippy already builds the feature through --all-features.
  • README: one line in Features.

Why

Some applications standardize all their cryptography on BoringSSL and don't want a second implementation of SHA/HMAC on the request-signing path. Today they have to fork reqsign-core to change hash.rs. Higher-level users such as OpenDAL build the signing Context internally, so a runtime hook wouldn't reach them without API changes in those crates as well.

A cargo feature works through feature unification. An application can add reqsign-core = { version = "3", features = ["boring"] } as a direct dependency, and the copy used by OpenDAL (or any other dependent) switches backends with no changes in the intermediate crates.

Scope and compatibility

  • Off by default, so nothing changes unless the feature is enabled. The RustCrypto dependencies stay non-optional, so turning on boring can't break a dependent that disables default features. When both are compiled, boring takes precedence.
  • Covers only reqsign_core::hash. That is all of the hashing and HMAC behind AWS SigV4 (reqsign-aws-v4) and the other services that call these helpers. Asymmetric signing (SigV4a ECDSA, Google/Oracle RSA, the jwt feature, Azure client certificates) is unchanged.
  • boring builds BoringSSL from source (CMake and a C/C++ toolchain) and isn't available on wasm32-unknown-unknown. The wasm-supported crates are unaffected because the feature is off by default. The CI wasm builds still pass.

Testing

  • cargo fmt --all -- --check
  • cargo clippy --workspace --all-targets --all-features -- -D warnings
  • cargo test --no-fail-fast -p reqsign-core -p reqsign-aws-v4 (RustCrypto): reqsign-core 45, reqsign-aws-v4 69 (+ integration test binaries), all pass.
  • cargo test --no-fail-fast -p reqsign-core -p reqsign-aws-v4 --features reqsign-core/boring (BoringSSL): the same results.
  • cargo build --target wasm32-unknown-unknown --no-default-features --features=aws,aws-v4a,azure,aliyun,tencent (facade): passes.

🤖 Generated with Claude Code

@erickguan erickguan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this feature.

Some requests:

  1. Reuse hasher. boring will allocate much less when signing again.
  2. Feel free to change data structure and function signatures. It can be lazy init hasher. It can be a struct.
  3. We validate at least reqsign compiles with at least one feature.

Comment thread core/src/hash.rs Resolved
@vovacf201
vovacf201 force-pushed the feat/core-boring-backend branch from 845cc4a to c62ef85 Compare November 18, 2026 14:02
@vovacf201

vovacf201 commented Nov 18, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review! Pushed eb4db64 (and rebased on main):

  1. Reuse hasher. SHA-1 and SHA-256 now reuse a thread-local Hasher (see the inline reply). HMAC still goes through boring::hash::hmac_sha1/hmac_sha256: boring's safe API can't reset or re-key an Hmac (finalize consumes it, and HmacCtx has no safe constructor), so reusing an HMAC context would need unsafe calls into boring-sys. I'd rather not add the first unsafe to reqsign for that, but I'm happy to if you prefer it.
  2. Data structures. I kept the public reqsign_core::hash functions unchanged; the reuse lives in the private backend module, so callers such as reqsign-aws-v4 get it without changes.
  3. Build with features. CI now builds the reqsign facade with --features boring and with --no-default-features --features boring,aws (Linux and macOS). The commit also fixes the test step, which my first version had left without its RUST_LOG/RUST_BACKTRACE env.

vovacf201 and others added 2 commits November 18, 2026 14:03
The functions in `reqsign_core::hash` keep their API and now go through a
private backend. RustCrypto stays the default. With the new `boring` feature,
SHA-1, SHA-256, HMAC-SHA1 and HMAC-SHA256 use BoringSSL through the `boring`
crate instead. The facade `reqsign` crate forwards the feature.

Known-answer tests (the standard SHA "abc" and empty-input digests, RFC 4231
and RFC 2202 HMAC, and the AWS SigV4 signing-key example) run on both
backends. CI runs the reqsign-core and reqsign-aws-v4 tests with the feature
enabled.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each thread keeps one SHA-1 and one SHA-256 `Hasher` and reuses it, so
hashing no longer creates a new digest context per call. CI now also
builds the `reqsign` facade with the `boring` feature, with and without
default features, and the main test step gets its env back.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vovacf201
vovacf201 force-pushed the feat/core-boring-backend branch from c62ef85 to eb4db64 Compare November 18, 2026 14:04
@erickguan

erickguan commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Is thread-local safe?

How do you think about APIs in user ends?

Hashing from another thread-local's destructor during thread exit could
reach the hasher after it was destroyed, and the resulting panic aborted
the process. Use a one-off hasher in that case.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vovacf201

Copy link
Copy Markdown
Author

Is thread-local safe?

How do you think about APIs in user ends?

yes it's safe

if the question about API means how API changes for user - nothing changes

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.

2 participants