Crate signature[][src]

RustCrypto: signature crate.

Traits which provide generic, object-safe APIs for generating and verifying digital signatures, i.e. message authentication using public-key cryptography.

Minimum Supported Rust Version

Rust 1.41 or higher.

Minimum supported Rust version may be changed in the future, but such changes will be accompanied with a minor version bump.

SemVer policy

Design

This crate provides a common set of traits for signing and verifying digital signatures intended to be implemented by libraries which produce or contain implementations of digital signature algorithms, and used by libraries which want to produce or verify digital signatures while generically supporting any compatible backend.

Goals

The traits provided by this crate were designed with the following goals in mind:

Implementation

To accomplish the above goals, the Signer and Verifier traits provided by this are generic over a Signature return value, and use generic parameters rather than associated types. Notably, they use such a parameter for the return value, allowing it to be inferred by the type checker based on the desired signature type.

The Signature trait is bounded on AsRef<[u8]>, enforcing that signature types are thin wrappers around a “bag-of-bytes” serialization. Inspiration for this approach comes from the Ed25519 signature system, which was based on the observation that past systems were not prescriptive about how signatures should be represented on-the-wire, and that lead to a proliferation of different wire formats and confusion about which ones should be used. This crate aims to provide similar simplicity by minimizing the number of steps involved to obtain a serializable signature.

Alternatives considered

This crate is based on over two years of exploration of how to encapsulate digital signature systems in the most flexible, developer-friendly way. During that time many design alternatives were explored, tradeoffs compared, and ultimately the provided API was selected.

The tradeoffs made in this API have all been to improve simplicity, ergonomics, type safety, and flexibility for consumers of the traits. At times, this has come at a cost to implementers. Below are some concerns we are cognizant of which were considered in the design of the API:

It may still make sense to continue to explore the above tradeoffs, but with a new set of traits which are intended to be implementor-friendly, rather than consumer friendly. The existing Signer and Verifier traits could have blanket impls for the “provider-friendly” traits. However, as noted above this is a design space easily explored after stabilizing the consumer-oriented traits, and thus we consider these more important.

That said, below are some caveats of trying to design such traits, and why we haven’t actively pursued them:

Unstable features

Despite being post-1.0, this crate includes a number of off-by-default unstable features named *-preview, each of which depends on a pre-1.0 crate.

These features are considered exempt from SemVer. See the SemVer policy above for more information.

The following unstable features are presently supported:

NOTE: the async-signature crate contains experimental async support for Signer and [DigestSigner].

Structs

Error

Signature errors.

Traits

Signature

Trait impl’d by concrete types that represent digital signatures.

Signer

Sign the provided message bytestring using Self (e.g. a cryptographic key or connection to an HSM), returning a digital signature.

Verifier

Verify the provided message bytestring using Self (e.g. a public key)