-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
signature v2.0.0-pre #1141
signature v2.0.0-pre #1141
Conversation
b96d650
to
73e4ef5
Compare
This commit contains the first breaking changes to the `signature` crate made since its initial 1.0 stabilization. Planning for these changes occurred in #237. The following changes have been made: - The `Signature` trait has been renamed to `SignatureEncoding`. The `Signature` bound on `*Signer` and `*Verifier` traits has been removed, meaning there are no longer any mandatory trait bounds on the signature paramters at all. - The `AsRef<[u8]>` bound formerly found on the `Signature` crate has been replaced with an associated `Repr` type, inspired by the `group::GroupEncoding` trait. This means signature types no longer need to retain a serialized form, and can parse the bag-of-bytes representation to something more convenient, which is useful for e.g. batch verification. - The `std` feature is no longer enabled by default, which matches the other RustCrypto/traits crates. - The `derive-preview` and `hazmat-preview` features have been stabilized. - The former `Keypair` trait has been renamed to `KeypairRef`, and the signature generic parameter removed. A new `Keypair` trait has been added which returns an owned instance of the associated `VerifyingKey`, and a blanket impl of `Keypair` for `KeypairRef` has been added. This addresses the issues described in #1124.
73e4ef5
to
2c1b3bd
Compare
@tarcieri What about the problem of owned vs unowned Signatures? I really want zero-copy validation. |
@npmccallum removing the So this could eliminate the intermediate |
I don't quite follow the design behind removing the Please excuse me if these questions sound stupid. I just can't grok the expected model. |
@lumag I didn't spell out the exact rationale for that, so thanks for pointing it out. The main argument for getting rid of it is simplifying the API and permitting more possible combinations, for example it becomes possible to use foreign types which don't necessarily implement the It also really doesn't introduce any additional complexity to generic code, since you need to notate the current The only real disadvantage I can think of is it no longer "forces" users of the Can you think of any other disadvantages to removing it? |
I think it'd just complicate the users API. E.g. when having a generic function over the different signature types, I have the following arguments: fn gen_sign_cert<S, SK, PK, F, PKF>(
rng: &mut (impl CryptoRng + RngCore),
serno: &[u8],
subject: &RdnSequence,
public_key: &PK,
issuer: &RdnSequence,
signing_key: &SK,
get_pub_key: PKF,
encode_sig: F,
) -> Result<Vec<u8>, Box<dyn Error>>
where
S: Signature,
SK: RandomizedSigner<S>,
PK: Verifier<S> + EncodePublicKey + KeyAlgorithmIdentifier,
PKF: Fn(&SK) -> PK,
F: Fn(&S) -> Vec<u8>,
{ ...... } The |
@lumag in practice I'm not sure what the purpose of the other parameters is in your example?
What do you think is doing that? The only crate that supports ASN.1 signatures at all is There is nothing ASN.1-specific in the
ECDSA supports fixed-sized and ASN.1 DER signatures. |
The |
@tarcieri So, as |
@lumag both the signature types already exist:
It would be possible to add It would also be possible to add a |
@tarcieri I know :-) |
Use `package` on the dependency import instead
Since signatures all encode to a "bag of bytes" of some form, choosing a common representation is useful when abstracting over a number of different signature systems. These helpers make it easy to use either a `Vec<u8>` or `Box<[u8]>` as that common type.
@lumag there's one big reason I've encountered porting various code not to bound on ASN.1 signatures can impl Without the bounds, this means that these signature types can still be used with the |
Implements the proposed breaking changes to the `signature` crate from RustCrypto/traits#1141 Most notably the `Signature` trait has been replaced with a `SignatureEncoding` trait which permits an internally structured signature representation.
Implements the proposed breaking changes to the `signature` crate from RustCrypto/traits#1141 Most notably the `Signature` trait has been replaced with a `SignatureEncoding` trait which permits an internally structured signature representation.
Implements the proposed breaking changes to the `signature` crate from RustCrypto/traits#1141 Most notably the `Signature` trait has been replaced with a `SignatureEncoding` trait which permits an internally structured signature representation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry it took so long. Nothing here is a big deal. Would like to know some of the reasoning though because I might wanna copy these techniques over to kem
later
use alloc::{boxed::Box, vec::Vec}; | ||
|
||
/// Support for decoding/encoding signatures as bytes. | ||
pub trait SignatureEncoding: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the main argument here that there's no inherent need for someone with access to an S: Signer
to be able to (de)serialize the resulting signatures? I'd buy that argument. Are there examples in the wild?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is largely a reaction (perhaps an overreaction) to mandatory trait bounds around the Signature
trait in the v1.0 signature
crate being too restrictive and preventing some things that would otherwise be valid. Although debatably the AsRef<[u8]>
one was too onerous.
As far as a real-world example of something eliminating the bounds enables, the main thing is probably a heapless core implementation with an alloc
-dependent SignatureEncoding
impl:
In this case, it's a variable-width ASN.1 DER-encoded type, which knows how to serialize itself into a buffer on heapless platforms, but when the heap is available, it's nice to be able to serialize it into a heap-backed structure (in this case Box<[u8]>
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. In the above case, couldn't SignatureEncoding
be implemented without the feature gate? The def simply won't contain the to_vec
part if alloc
isn't set. Or is the trait simply not useful in that case (for this particular crate)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SignatureEncoding::Repr
in that example is an alloc::boxed::Box<[u8]>
, so no, it cannot be defined without the alloc
feature enabled.
/// Signing keypair with an associated verifying key. | ||
/// | ||
/// This represents a type which holds both a signing key and a verifying key. | ||
pub trait Keypair<S: Signature>: AsRef<Self::VerifyingKey> { | ||
pub trait Keypair { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another maybe silly question: how is this intended to be used? It seems that the only thing Keypari
is good for is getting a verification key. But you can't even do anything with that verification key, because it's not necessarily part of or an input to a Verifier
. So when does this trait get used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Keypair
originally started out with mandatory bounds for Signer
and Verifier
. We removed these because there are other possible traits Keypair
could be used in conjunction with, like DigestSigner
/DigestVerifier
, PrehashSigner
/PrehashVerifier
, as well as RandomizedSigner
/RandomizedDigestSigner
/RandomizedPrehashSigner
(and these all have further async equivalents in async-signature
). See #1107.
So, like with SignatureEncoding
, the idea is to provide more flexible traits that don't mandate bounds but are intended to be composed.
In the case of Keypair
, the trait is intended only as a way to obtain a verifying key from a signing key.
Implements the proposed breaking changes to the `signature` crate from RustCrypto/traits#1141 Most notably the `Signature` trait has been replaced with a `SignatureEncoding` trait which permits an internally structured signature representation.
Implements the proposed breaking changes to the `signature` crate from RustCrypto/traits#1141 Most notably the `Signature` trait has been replaced with a `SignatureEncoding` trait which permits an internally structured signature representation.
This (unpublished) prerelease of the `ecdsa` crate impl's the prospective `signature` v2 API from: RustCrypto/traits#1141
This (unpublished) prerelease of the `ecdsa` crate impl's the prospective `signature` v2 API from: RustCrypto/traits#1141
This (unpublished) prerelease of the `ecdsa` crate impl's the prospective `signature` v2 API from: RustCrypto/traits#1141
This (unpublished) prerelease of the `ecdsa` crate impl's the prospective `signature` v2 API from: RustCrypto/traits#1141
Bumps the `ed25519` crate to the v2.0.0-pre.0 prerelease. This version notably uses the `signature` crate's v2 API: RustCrypto/traits#1141
Bumps the `ed25519` crate to the v2.0.0-pre.0 prerelease. This version notably uses the `signature` crate's v2 API: RustCrypto/traits#1141
Bumps the `ed25519` crate to the v2.0.0-pre.0 prerelease. This version notably uses the `signature` crate's v2 API: RustCrypto/traits#1141
Bumps the `ed25519` crate to the v2.0.0-pre.0 prerelease. This version notably uses the `signature` crate's v2 API: RustCrypto/traits#1141
Bumps the `ed25519` crate to the v2.0.0-pre.0 prerelease. This version notably uses the `signature` crate's v2 API: RustCrypto/traits#1141
Bumps the `ed25519` crate to the v2.0.0-pre.0 prerelease. This version notably uses the `signature` crate's v2 API: RustCrypto/traits#1141
This commit contains the first breaking changes to the
signature
crate made since its initial 1.0 stabilization. Planning for these changes occurred in #237.The following changes have been made:
Signature
trait has been renamed toSignatureEncoding
. TheSignature
bound on*Signer
and*Verifier
traits has been removed, meaning there are no longer any mandatory trait bounds on the signature paramters at all.AsRef<[u8]>
bound formerly found on theSignature
crate has been replaced with an associatedRepr
type on the newSignatureEncoding
trait, inspired by thegroup::GroupEncoding
trait. This means signature types no longer need to retain a serialized form, and can parse the bag-of-bytes representation to something more convenient, which is useful for e.g. batch verification.std
feature is no longer enabled by default, which matches the other RustCrypto/traits crates.derive-preview
andhazmat-preview
features have been stabilized.Keypair
trait has been renamed toKeypairRef
, and the signature generic parameter removed. A newKeypair
trait has been added which returns an owned instance of the associatedVerifyingKey
, and a blanket impl ofKeypair
forKeypairRef
has been added. This addresses the issues described in signature:Keypair
design problems #1124.