Repository navigation
Description
This is an announcement of a 2-week final comment period (ending March 22nd) which will be followed by a 1.0 release of the signature crate some time thereafter.
Original 1.0 stabilization proposal here.
Current status
I've published signature v1.0.0-pre.3, which includes significantly more documentation and clearly calls out (using doc_cfg) the 1.0 stable versus unstable "preview" parts of the API:
Docs: https://docs.rs/signature/1.0.0-pre.3/signature/index.html
I'd love feedback on the docs before a final release, particularly what parts of the current design remain unclear.
Note that I do intend to include more usage examples, but I would like those examples to highlight notable real-world ecosystem examples rather than contrived ones, and there's a bit of a chicken-and-egg problem in doing that.
API to be stabilized
The goal of this stabilization proposal is to stabilize the following types in the signature crate:
The remaining types (e.g. Digest*) now require enabling off-by-default *-preview features which call out their instability, but with a pledge that breaking changes are accompanied by a minor version bump. I've opened separate tracking issues for each of these here:
- #92
digest-preview:DigestSignature,DigestSigner,DigestVerifier - #93
derive-preview: custom derive forSignerandVerifierfor use withDigestSignature - #94:
rand-preview:RandomizedSigner
Rationale for stabilization
The four types/traits called out earlier for stabilization are sufficient for stable use of Ed25519 signatures/signers/verifiers via the ed25519 crate, which is intended to see a 1.0 release as well after a 1.0 release of this crate is published. This is the main impetus for a 1.0 release of this crate.
Current usage
The signature traits have seen a lot of real world usage, both in libraries that natively use them, and in crates which provide thin wrappers (and therefore a unified object-safe API) across several other notable ecosystem crates:
ed25519-dalek: via thesignatory-dalekwrapper crate. There is also an open PR to use thesignaturetraits anded25519crate directlyring: via thesignatory-ringcratesecp256k1-rs: via thesignatory-secp256k1cratesodiumoxide: via thesignatory-sodiumoxidecrate
Crates which natively leverage the signature traits include:
yubihsmfor ECDSA and Ed25519 signingledger-tendermintfor Ed25519 signing
Alternatives considered
NOTE: See also the "Alternatives considered" section of the signature rustdoc.
This stabilization proposal is for a trait/object-safe API, as enumerated above. The main audience of this API is consumers of digital signature systems, and thus its design is very much optimized with that audience in mind.
Several people have proposed, and we have previously investigated, an alternative design based on generic signature types with algorithm-specific marker traits, as well as leveraging use of associated types, rather than generic type parameters on traits, to allow the usage of more concrete types. An API like this would be more beneficial to implementers of signature provider libraries, and allow less invasive first-class support of the signature traits.
The good news is that these approaches aren't orthogonal, and several of the other crates in RustCrypto/traits provide both an object-safe high-level API as well as an associated type-leveraging lower-level API for similar reasons. Done correctly there can be a blanket impl of the object-safe API for the provider-oriented API.
That said, the design and implementation of such an API isn't considered a blocker on a 1.0 release specifically for the reasons that it can be implemented in the future in a purely additive manner.
Activity
tarcieri commentedon Mar 8, 2020
One notable issue with the current
Signaturetrait is that it isn't object safe, and not for a particularly good reason: it has animpl AsRef<[u8]>in itsfrom_bytesmethod. The trait could be made object safe by switching that parameter to&[u8].TryFrom<&[u8]>would probably be ideal as a bound, except the&[u8]would necessitate adding a lifetime to the trait or using HRTB. The latter may still be worth considering, but complicates theSignaturebounds story for somewhat dubious reasons (and may also re-break object safety were it "fixed" as I mentioned above? I haven't investigated that specifically).tarcieri commentedon Mar 9, 2020
Removed
BoxErrorfrom the public API: #81roblabla commentedon Mar 9, 2020
Hey, thanks for the new docs, they're really helpful.
IMO, there's still a bit of documentation missing on each trait. In particular, it'd be good to explain in Signer and Verifier that they take a Signature type argument to allow for a single concrete type to generate different "kinds" of signatures. Maybe give some concrete example (I believe ECDSA has multiple kinds of signatures, and some HSMs are able to use multiple different signatures).
There should be a section of documentation show-casing a simple implementation. As it currently stands, the crate doc has no guidelines on how to write your own impls, and the traits aren't so straightforward that it can be figured out right away. IMO there should be a simple example, maybe wrapping ring or something. The impl here seems very simple and straightforward, perfect for inclusion in docs.
Also, something that bothers me is that every single example uses
signatoryas a wrapper forsignature. It gives this very weird impression that signature isn't usable without signatory (which I know is not the case, but it's just how it feels when literally every single example goes through signatory instead). In particular, I can't help but notice all implementations share theirSignaturetype with it. What's the use-case for this (VS just having each crate define their own)? If I'm making an impl for a new kind of signature (say, RSA), should I make a separate crate with a simple RSA signature type, allowing it to get shared with other potential implementations? Should it get added to signatory (even though signatory seems to be mostly about eliptic curves)? Those are all questions left unanswered in the current signature docs.(I rambled a lot about the docs, but as far as the API goes, it looks fine to me).
roblabla commentedon Mar 9, 2020
Oh one small misgiving about the Error type: As it stands it's possible in
no_stdto create anErrorwithout going through thenewmethod, since it has no fields. E.G. this works (when signature is built in no_std mode):For the sake of forward-compatibility (should we eventually add the ability to define errors with sources in no_std), the Error type should be changed to the following to ensure that users have to go through the new constructor.
tarcieri commentedon Mar 10, 2020
Good point regarding the
Errortype. I'll do that. (Edit: done, see #83)To answer some of your other questions:
The signature types used by Signatory come from the
ecdsaanded25519crates in https://github.com/RustCrypto/signaturesSignatory provides a set of wrappers for notable Rust ecosystem signature provider crates which use the signature types from the
ecdsaanded25519crates. This means if you want to write a crate that uses theSignaturetrait to produce aned25519::Signature, you don't have to care about Signatory at all, but someone wanting to instantiate it withed25519-dalekcan use thesignatory-dalekcrate. Or if they wanted to usesodiumoxide, they could usesignatory-sodiumoxideinstead. Either way they get (or can verify) aned25519::Signature.Ideally though, provider crates would adopt these traits/types natively, so "wrapper crates" aren't needed. The
yubihsmandtendermint-ledgercrates are examples of this.burdges commentedon Mar 11, 2020
We could do that Error type much better, although I've still never gotten around to doing so.
tarcieri commentedon Mar 11, 2020
Any concrete suggestions?
burdges commentedon Mar 11, 2020
I'll try to make one, but maybe it'll need to wait until v2.
In essence, there are many rust crates that should be using an error type with the small box optimization, but doing that in rust is mildly tricky. It's not that the small box optimization matters so much for performance, although that's nice if you plan to error lots, but I think it can be made to work for small types even without alloc.
roblabla commentedon Mar 13, 2020
I mean, for what it's worth the signature error cause should only be set in very rare situations from what we've talked about (basically, it should only be used to communicate transport errors such as HSM connection failures) and nothing else. Errors happening during the signature process should be "empty" to avoid leaking info. So the kind of errors that actually allocate are expected to be extremely rare and not require too much optimization work.
tarcieri commentedon Mar 15, 2020
Just adding a quick note I took a look at HRTBs for adding a
TryFrombound toSignature:This eliminates the ability to use
Signaturewithout the HRTB, which IMO is almost more annoying than having a lifetime on the trait. Just that change causes these compilation failures:tarcieri commentedon Mar 16, 2020
One other note: the
Signature::from_bytesand::as_slicenames are, at best, inconsistent. (Edit: done, see #87)Suggestion: rename
Signature::as_sliceto::as_bytesdaira commentedon Mar 17, 2020
The Fiat-Shamir heuristic is about hashing the transcript of an interactive protocol, not about hashing the message. You can have a non-Fiat-Shamir signature algorithm that hashes the message in this way, and you can have a Fiat-Shamir-derived algorithm that does not. These aren't obscure cases, either; an example of the latter is Ed25519. The important thing is whether you can compute the digest separately from the signature (and without the private key), not how the signature algorithm was derived.
tarcieri commentedon Mar 17, 2020
@daira yeah, these have been tricky things to document, that one in particular. See here for the original PR on it (which mentioned nothing about Fiat-Shamir):
RustCrypto/signatures#10
Notably as you mentioned
DigestSignaturedoes not work in cases like Ed25519 because it hashes twice.I'm not sure if there's a better name for such a signature algorithm (some of the previous discussion called it "raw digest" signer. I think "prehash" is another common term ala Ed25519ph), but notably the
signaturecrate andsignature_derivecan derive theSignatureimplementation in this case (as opposed to e.g. Ed25519, which has a more complex protocol that hashes the message twice)roblabla commentedon Mar 17, 2020
FWIW I think DigestSignature conversation should go in a dedicated tracking issue since it's not part of the API getting currently stabilized, and it'd suck for those discussion points to get lost in an unrelated ticket ^^.
Which brings me to something else: It'd be nice to have a tracking issue per preview feature to funnel API and stabilization discussion of those APIs there.
tarcieri commentedon Mar 17, 2020
@roblabla good idea, will open an issue for each of the
*-previewfeatures (Edit: opened #92, #93, and #94 and added descriptions of them to the OP)Use `ed25519` + `signature` interop crates
tarcieri commentedon Mar 24, 2020
Quick update on this:
I got some good feedback it seems. Here are the remaining issues, neither of which are a 1.0 blocker, but both of which could probably use work before a 1.0 release:
DigestSignature->PrehashSignature(technically not a part of the 1.0 API, but I think it'd still be good to change sooner than later)Would still be nice to have some clarity / feedback around dalek-cryptography/ed25519-dalek#80 before shipping this as well.
All that said, I'm not in a huge rush here, so if you'd still like to give any final feedback, please do.
tarcieri commentedon Apr 18, 2020
DigestSignaturewas renamed toPrehashSignaturein #96tarcieri commentedon Apr 18, 2020
I've opened a PR for the final 1.0 release of the
signaturecrate in #97I'm going to do some preflight checks on it and then cut the release
tarcieri commentedon Apr 18, 2020
It's out! 🎉
https://crates.io/crates/signature/1.0.0
Upgrade to v1.0 release of the `signature` crate
Upgrade to v1.0 release of the `signature` crate
Use `ed25519` + `signature` interop crates
sha-crypt v0.1.0 (RustCrypto#78)
Upgrade to v1.0 release of the `signature` crate