Commit Graph

81 Commits

Author SHA1 Message Date
Tony Arcieri 26e21c8a4f ed25519: optional serde support
Serializes and deserializes Ed25519 signatures as 64-byte "octet strings"
2019-10-27 09:54:03 -07:00
Tony Arcieri 6b759c387a Merge pull request #39 from RustCrypto/ed25519/try-from
ed25519: Add `TryFrom` impl for `Signature`
2019-10-27 08:46:52 -07:00
Tony Arcieri 9fb6720117 ed25519: Add TryFrom impl for Signature 2019-10-27 08:34:43 -07:00
Tony Arcieri d5bb9b984a Merge pull request #38 from RustCrypto/remove-alloc-feature-msrv-1-31
signature: Remove `alloc` feature; MSRV 1.31+
2019-10-26 09:31:21 -07:00
Tony Arcieri 3a67e63545 signature: Remove alloc feature; MSRV 1.31+
The only thing the `signature` crate uses `alloc` for is the
`Signature::to_vec` method, which is trivially accomplished otherwise as
`sig.as_ref().to_vec()` or various other ways.

By getting rid of it, we can completely get rid of the `alloc` feature,
and with that reduce the MSRV back to 1.31.

It might be worth considering a 1.0 release with a higher MSRV so we can
leverage `TryFrom`, but for now, this provides wider compatibility by
removing a single (mis)feature.
2019-10-26 09:22:02 -07:00
Tony Arcieri 301c1091f7 Merge pull request #37 from RustCrypto/rust-1-30-error-handling
signature: Use `Error::source` instead of `::cause`
2019-10-26 09:01:15 -07:00
Tony Arcieri fc835cd182 signature: Use Error::source instead of ::cause
This upgrades to the `std::error::Error` features for boxed,
downcastable error sources introduced in Rust 1.30, namely switching
from `Error::cause` to `Error::source`, which adds a `'static` bound and
therefore allows it to support downcasting.

Additionally, it defines a `BoxError` type incorporating those bounds
along with `Send + Sync`, ensuring that `signature::Error` itself is
`Send + Sync`, which should improve the ergonomics.
2019-10-26 08:44:51 -07:00
Tony Arcieri aa74a320b5 Merge pull request #36 from RustCrypto/readme/fix-link
README.md: Fix link
2019-10-11 11:12:37 -07:00
Tony Arcieri ce3372ae6a README.md: Fix link 2019-10-11 11:02:35 -07:00
Tony Arcieri 56bbcce71b Merge pull request #35 from RustCrypto/ed25519/1.0.0-pre.0
ed25519 1.0.0-pre.0
2019-10-11 11:01:12 -07:00
Tony Arcieri e47830d381 ed25519 1.0.0-pre.0 ed25519/v1.0.0-pre.0 2019-10-11 10:50:27 -07:00
Tony Arcieri 9edb86a20b Merge pull request #34 from RustCrypto/signature-crate/1.0.0-pre.0
signature 1.0.0-pre.0
2019-10-11 10:07:07 -07:00
Tony Arcieri 833ba72276 signature 1.0.0-pre.0 2019-10-11 09:58:08 -07:00
Tony Arcieri e1c8919ba9 Merge pull request #32 from RustCrypto/signature-crate/1.0-stabilization-proposal
signature crate: 1.0 stabilization proposal
2019-10-11 09:52:05 -07:00
Tony Arcieri b229861ef0 signature crate: 1.0 stabilization proposal
The motivation for 1.0 stabilization of the `signature` crate is the
upcoming 1.0 release of `ed25519-dalek`. In order to promote Ed25519
interoperability, it would be great if `ed25519-dalek` could use the
traits from this crate along with the `ed25519::Signature` type from the
`ed25519` crate.

To get there, I think we need to do a 1.0 release of this crate, as well
as the `ed25519` crate.

The main impediment towards doing so is the `digest` crate is presently
stuck at v0.8. It would be nice to be able to continue upgrading it,
especially to a 1.0 release, but that would otherwise be a semver
breaking change.

To allow agility around `digest`, and `signatory_derive` which depends
on it, this commit places access to both under the `digest-preview` and
`derive-preview` Cargo features respectively, and calls them out as
not covered under SemVer and subject to change, but breaking changes
will be done with a minor version bump.
2019-10-11 09:33:55 -07:00
Tony Arcieri bc54784f27 Merge pull request #33 from RustCrypto/revert-removal-of-digest-signature
Revert removal of DigestSignature
2019-10-11 09:31:55 -07:00
Tony Arcieri 87f0b1b2f1 DigestSignature: update description
Updates the description to note the `DigestSignature` marker trait is
useful for custom derive support as the blanket impl was removed.
2019-10-11 09:20:46 -07:00
Tony Arcieri 13674773a5 Revert "signature-crate: Replace DigestSignature with derive attr"
This reverts commit 48e33d8758.

After updating my downstream consumers to try to use this, I encountered
an important case where this falls down: deriving `Signer` and
`Verifier` on generic types where the `Digest` *can only* be generically
specified as an associated type, as the `yubihsm` crate is doing here:

https://github.com/tendermint/yubihsm-rs/blob/develop/src/ecdsa/signer.rs#L22

The goal of switching to a derive attribute was to make this
functionality more flexible and eliminate the need for a marker trate,
but in this particular case (one I personally consider very important)
it had the opposite effect.
2019-10-11 09:13:50 -07:00
Tony Arcieri 0284decb3f Merge pull request #31 from RustCrypto/improve-toplevel-readme
Toplevel README.md improvements
2019-10-10 09:29:21 -07:00
Tony Arcieri 203b872918 Toplevel README.md improvements 2019-10-10 09:14:37 -07:00
Tony Arcieri 8a7078a867 Merge pull request #30 from RustCrypto/ed25519/v0.2.0
ed25519 v0.2.0
2019-10-10 09:05:07 -07:00
Tony Arcieri 03ef0b3f0b ed25519 v0.2.0 ed25519/v0.2.0 2019-10-10 08:55:45 -07:00
Tony Arcieri df35dabe3b Merge pull request #29 from RustCrypto/signature/v0.3.0
signature v0.3.0
2019-10-10 08:37:42 -07:00
Tony Arcieri 0584689d31 signature v0.3.0 2019-10-10 08:25:58 -07:00
Tony Arcieri 8ef2d3b04b Merge pull request #28 from RustCrypto/simplify-alloc-gating
signature: Simplify alloc gating
2019-10-10 08:12:33 -07:00
Tony Arcieri 82fe77fbba signature: Simplify alloc gating
Unconditionally link to liballoc when the std feature is enabled and
always access `Vec` as `alloc::vec::Vec`.

MSRV 1.36+
2019-10-10 08:05:51 -07:00
Tony Arcieri a12143ff1d Merge pull request #27 from RustCrypto/remove-digest-signature
signature-crate: Replace DigestSignature with derive attr
2019-10-09 13:04:31 -07:00
Tony Arcieri 48e33d8758 signature-crate: Replace DigestSignature with derive attr
The `DigestSignature` trait was originally used as the marker trait used
by a blanket impl of `Signer` for `DigestSigner` and `Verifier` for
`DigestVerifier` (#12, #16).

Unfortunately, this approach turned out to be too inflexible to cover
real-world use cases encountered and was replaced with a proc macro (#18)
The `DigestSignature` trait is leftover from this, and is no longer
needed.

This commit replaces it with a `#[digest(...)]` custom derive attribute
which can be used to specify the digest which should be used when
computing a signature.
2019-10-09 12:57:22 -07:00
Tony Arcieri 1cc55ca09d Merge pull request #26 from RustCrypto/signature_derive/1.x-proc-macro-crates
signature_derive: Upgrade to 1.x proc macro crates
2019-10-09 11:09:37 -07:00
Tony Arcieri f1f852cb90 signature_derive: Upgrade to 1.x proc macro crates 2019-10-09 10:10:41 -07:00
Tony Arcieri a223fc4e32 Merge pull request #24 from RustCrypto/ed25519/v0.1.0
ed25519 v0.1.0
2019-08-10 12:06:03 -07:00
Tony Arcieri 99d4e33cfa ed25519 v0.1.0 ed25519/v0.1.0 2019-08-10 12:00:22 -07:00
Tony Arcieri dce3b26788 Merge pull request #23 from RustCrypto/ed25519-crate
ed25519: Initial implementation (closes #22)
2019-08-10 07:24:26 -07:00
Tony Arcieri 9703638db9 ed25519: Initial implementation
Basic implementation with an initial `ed25519::Signature` type which
impls the `signature::Signature` trait.
2019-08-10 07:15:17 -07:00
Tony Arcieri 84e3decc59 Merge pull request #21 from RustCrypto/signature_derive/v0.2.1
signature_derive v0.2.1
2019-06-07 09:30:25 -07:00
Tony Arcieri 3372991a04 signature_derive v0.2.1 2019-06-07 09:21:34 -07:00
Tony Arcieri eec88447b5 Merge pull request #20 from RustCrypto/signature_derive/fully-qualified-paths
signature_derive: Use fully qualified paths
2019-06-07 09:20:17 -07:00
Tony Arcieri 889ecce13c signature_derive: Use fully qualified paths
Replaces `use` directives with fully qualified paths. This prevents
potential name clashes in the event types have the same name as the
traits needed for the custom derive.
2019-06-07 09:08:37 -07:00
Tony Arcieri 4a44453c12 Merge pull request #19 from RustCrypto/signature/v0.2.0
signature v0.2.0
2019-06-06 17:38:14 -07:00
Tony Arcieri cd60a81908 signature v0.2.0 2019-06-06 17:26:19 -07:00
Tony Arcieri 6bc013adad Merge pull request #18 from RustCrypto/signature_derive
signature_derive: Custom derive support for Signer/Verifier
2019-06-06 17:17:18 -07:00
Tony Arcieri 338dbb1136 signature_derive: Custom derive support for Signer/Verifier
We've explored several different possible trait bounds for a blanket
impl of `Signer` for `DigestSigner` (and likewise for `Verifier`).

Unfortunately, the approach we netted out at in #12 does not permit
anything but the blanket impl, and was removed in #16.

It's definitely still worth exploring if there's a way to define the
bounds of the default impl that works, however there is one approach we
haven't explored yet: a procedural macro.

This approach feels like a bit of a hack, but gets us to where we
originally wanted to be with the blanket impl API-wise. The impl it
derives uses the same approach and bounds as the blanket impl did:
the `Digest` to use is sourced from an associated type of the
`DigestSignature` trait, which means the digest to use is both automatic
and ensures the type deriving the trait supports the expected `Digest`
for the given signature.

The implementation uses `synstructure` which simplifies both handling of
generics and testing the output of the proc macro.

Additionally, it includes a complete integration test of the derived
code which ensures it works as expected.

It's gated under a cargo feature and disabled-by-default. This should
make it unobtrusive for downstream crates which don't need its
functionality.
2019-06-06 17:07:24 -07:00
Tony Arcieri a94234e649 Merge pull request #17 from RustCrypto/revise-digest-apis
Have DigestSigner/DigestVerifier take Digest instance
2019-06-06 10:17:37 -07:00
Tony Arcieri 7ce2694b07 Have DigestSigner/DigestVerifier take Digest instance
This is needed forcompatibility with ed25519-dalek's Ed25519ph:

https://docs.rs/ed25519-dalek/1.0.0-pre.1/ed25519_dalek/struct.Keypair.html#method.sign_prehashed

Until const generics land, this API feels a lot cleaner to me. It gets
all the `GenericArray` crap out of the way.

It's also misuse resistant in that it ensures the prehashing is done by
the relevant hash function, as opposed to the user being able to pass in
arbitrary values. There's a potential attack if a verifier accidentally
accepts a raw value which isn't the output of a hash function which
could allow an attacker to forge signatures:

https://twitter.com/pwuille/status/1063582706288586752
2019-06-06 09:33:38 -07:00
Tony Arcieri 566002edb7 Merge pull request #16 from RustCrypto/replace-blanket-impls-with-trait-methods
Replace Digest-related blanket impls with methods
2019-06-06 09:31:59 -07:00
Tony Arcieri 6c0c9e2c0f Replace Digest-related blanket impls with methods
The current "clever" blanket impl (for which I'm entirely responsible!)
seems to have bounds which prevent anything from implementing `Signer`
or `Verifier` when the `digest` feature is enabled:

```
   = note: conflicting implementation in crate `signature`:
           - impl<S, T> signature::signer::Signer<S> for T
             where S: signature::signature::DigestSignature, T: signature::signer::DigestSigner<<S as signature::signature::DigestSignature>::Digest, S>;
   = note: upstream crates may add new impl of trait `signature::signature::DigestSignature` for type `signatory::ed25519::signature::Signature` in future versions
   = note: downstream crates may implement trait `signature::signer::DigestSigner<_, signatory::ed25519::signature::Signature>` for type `ed25519::Ed25519Signer`
```

This commit, while a bit ugly, at least eliminates all of the complexity
around bounds on the blanket impl by entirely removing the blanket impl,
and adding an additional method to precompute the digest.

I'm not entirely happy with this and think the method names are a bit
confusing and not descriptive enough, but it does have the following
rather nice properties:

- Easy to reason about: no blanket impls
- Allows the same type to impl both the `Digest` and non-`Digest` forms
  of `Signer` and `Verifier` simultaneously.

There are a lot of potential directions this could go in order to
improve the API, potentially splitting it into two traits rather than
one (which gets us back to the `Sha*Signer`/`Sha*Verifier` traits which
Signatory used originally), however I think this is the MVP for actually
using the `signature` crate in Signatory, so I'd like to start with this
and then iterate towards a better API.
2019-06-05 15:14:28 -07:00
Tony Arcieri c40669ae5c Merge pull request #15 from RustCrypto/signature/v0.1.0
signature v0.1.0
2019-05-25 09:54:47 -07:00
Tony Arcieri 303210aedd signature v0.1.0 2019-05-25 09:48:56 -07:00
Tony Arcieri f6dd277356 Merge pull request #14 from RustCrypto/try-sign
Add `try_*` methods to `*Signer` traits
2019-04-01 08:21:27 -07:00
Tony Arcieri c9269c1bcd Add try_* methods to *Signer traits
For many signature providers, it's not possible for an error to occur
when creating a signature. Support for handling errors which occur when
computing signatures is intended for use with cloud KMS, HSMs, or other
hardware tokens where things like I/O errors are possible.

To simplify usage in the event that only software signers are in use,
this commit splits the `sign` API into `Result`-based `try_sign` method
and another `sign` method that always assumes success and unwraps the
result of the former method.
2019-04-01 08:13:19 -07:00