Skip to content

Refactor crypto backend architecture to support multiple backends - #118

Open
dwhjames wants to merge 3 commits into
awslabs:mainfrom
dwhjames:crypto_backend
Open

Refactor crypto backend architecture to support multiple backends#118
dwhjames wants to merge 3 commits into
awslabs:mainfrom
dwhjames:crypto_backend

Conversation

@dwhjames

Copy link
Copy Markdown

This commit introduces pluggable cryptographic backends, allowing users to select between openssl, ring, and aws-lc-rs at compile time. This unifies the public API across backends while maintaining backend-specific optimizations and compatibility constraints.

Key changes:

  • Extract backend-agnostic crypto traits and abstractions (EcPrivateKey, EcPublicKey) with consistent APIs across all backends
  • Implement ring and aws-lc-rs backends with feature-gated compilation; exactly one backend must be selected (mutual exclusivity enforced)
  • Introduce CoseError::KeyDecodingError for precise key parsing/decoding error reporting instead of catch-all SignatureError
  • Allow key_tpm and key_kms to work with any backend (e.g., ring + key_tpm, aws-lc-rs + key_kms), except ring + key_kms which is compile-time rejected
  • Refactor repetitive error-handling patterns and OID/encoding helpers to reduce duplication across backends

This enables the 0.6.0 release with breaking API changes.


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

This commit introduces pluggable cryptographic backends, allowing users to
select between openssl, ring, and aws-lc-rs at compile time. This unifies
the public API across backends while maintaining backend-specific
optimizations and compatibility constraints.

Key changes:

* Extract backend-agnostic crypto traits and abstractions (EcPrivateKey,
  EcPublicKey) with consistent APIs across all backends
* Implement ring and aws-lc-rs backends with feature-gated compilation;
  exactly one backend must be selected (mutual exclusivity enforced)
* Introduce CoseError::KeyDecodingError for precise key parsing/decoding
  error reporting instead of catch-all SignatureError
* Allow key_tpm and key_kms to work with any backend (e.g., ring + key_tpm,
  aws-lc-rs + key_kms), except ring + key_kms which is compile-time rejected
* Refactor repetitive error-handling patterns and OID/encoding helpers to
  reduce duplication across backends

This enables the 0.6.0 release with breaking API changes.
…hash

Restore the design where sign.rs owns hashing: new_with_protected and
verify_signature now call ActiveBackend::hash() on the Sig_Structure bytes
and pass the resulting digest to sign()/verify(), rather than each backend
hashing the raw message internally.

Key changes:

* Add hashes_internally() to SigningPublicKey (default false); ring/aws-lc-rs
  backends override to true since their ECDSA algorithms always hash internally
  and provide no raw-signing API
* sign.rs conditionally hashes based on hashes_internally(), passing raw bytes
  to ring-like keys and pre-computed digests to all others
* openssl: remove internal openssl::hash::hash() from sign() and verify()
* kms: remove internal ActiveBackend::hash(); forward digest directly to KMS
  as MessageType::Digest; guard verify_with_public_key fast-path to skip
  ring-like public keys that would double-hash the digest
* tpm: remove internal ActiveBackend::hash(); pass digest slice directly to
  Digest::try_from()
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