Commit Graph

207 Commits

Author SHA1 Message Date
Tony Arcieri 58eccf8c74 ecdsa: make SignPrimitive's ephemeral scalar generic (#107)
...and remove masking scalar.

This API allows the inversion masking process to be handled outside of
the ECDSA implementation itself (potentially generically in a way that
can work across elliptic curves).
2020-07-28 10:47:02 -07:00
Tony Arcieri 12b96e3ac5 ecdsa: bound ecdsa::SignPrimitive on Arithmetic (#106)
Avoids re-declaring the associated type
2020-07-27 19:40:07 -07:00
Tony Arcieri 3800528655 ecdsa: implement RustCrypto/traits#223 updates (#105)
Updates usages of the `elliptic-curve` crate API
2020-07-27 14:01:36 -07:00
Tony Arcieri 3655c0b7a1 ecdsa: gate PrehashSignature impl on digest feature (#104) 2020-07-23 11:49:10 -07:00
Tony Arcieri 30e586033a ecdsa: initial dev module with new_*_test macros (#103)
Adds a `dev` module ala the ones in the trait crates which contains
`new_signing_test` and `new_verification_test` macros which implement
a basic set of tests for implementers of `SignPrimitive` and
`VerifyPrimitive` respectively.

Ideally this would implement something close to the set of tests
described in the FIPS 186-4 ECDSA Validation System (ECDSA2VS), however
for now it tests basic signing, verification, and a verification failure
in the event the `s` component of the signature has an incorrect value.

Eventually it'd probably be good to convert to using `blobby` for
consistency with the other `dev` modules, however for now it specifies a
`TestVector` struct which the macros accept a slice of for vectors.
2020-07-23 11:01:09 -07:00
Tony Arcieri 932ab457c0 ecdsa: rename asn1::Signature; impl signature trait (#102)
This commit renames `asn1::Document` to `asn1::Signature`.

This means we now have the following types:

- `ecdsa::Signature`: fixed-sized encoding
- `ecdsa::asn1::Signature`: ASN.1 DER encoding

Additionally this commit adds an impl of the `signature::Signature`
trait for `asn1::Signature`, promoting it back to a first-class
signature type. This allows ECDSA `signature::Signer` impls to directly
produce ASN.1 encoded signatures again without transcoding, if they
so desire.
2020-07-23 09:36:49 -07:00
Tony Arcieri e9037b7d94 ecdsa: have SignPrimitive borrow scalars (#101)
Avoids making unnecessary copies
2020-07-17 07:33:39 -07:00
Tony Arcieri c8ed0f2546 ecdsa: use signature::Error in hazmat module (#100)
It previously used `elliptic_curve::Error` instead by mistake
2020-07-16 19:23:37 -07:00
Tony Arcieri 04ca0e23ca ecdsa: add DigestPrimitive (#99)
The `DigestPrimitive` trait, intended to be implemented within a crate
which impls `elliptic_curve::weierstrass::Curve`, provides a blanket
impl of `PrehashSignature` for `ecdsa::Signature<C: Curve>`.

This is a small hack needed to work around the fact that the ECDSA
signature trait now lies in an external crate, so crates which implement
a specific curve can no longer impl traits on `ecdsa::Signature`.
2020-07-13 20:11:46 -07:00
Tony Arcieri bc5a7055e4 ecdsa: refactor signature types into Signature + asn1::Document (#98)
The previous implementation had `Asn1Signature` and `FixedSignature`
types which sat side-by-side as equals.

However, that's annoying, because it means we need to do various work in
duplicate for both signature types.

It's also annoying because there's no "one true signature type" to reach
for.

The original motivations for doing this were a few different things:

- Initial implementation lacked transcoding necessitating the split
- Avoids unnecessary transcoding, which could preserve ASN.1 structures

Now that we have bidirectional transcoding between the formats, and
particularly one which should always serialize to "strict DER", it
seems like it's probably worth it to pay the transcoding costs and
"standardize" on the previous `FixedSignature` format as the blessed
`ecdsa::Signature` type.

This allows factoring everything ASN.1 related (besides a few helper
methods and a From-impl on Signature) into the `ecdsa::asn1` module
which everything else aside just feels cleaner than before.

This also means downstream ECDSA provider crates don't need to worry
about ASN.1 at all (unless they're e.g. parsing it from HSM/KMS output)
and can focus exclusively on the `ecdsa::Signature` type.
2020-07-13 18:09:16 -07:00
Tony Arcieri 4c3cf22b3c ecdsa: bump version to v0.7.0-pre (#97)
This commit isn't intended to be a release, but just bumps the version
number in Cargo.toml to `-pre` to distinguish it from the currently
released v0.6.1.

Several backwards incompatible / semver breaking changes have been
introduced since the release.

It also updates `elliptic-curve` to v0.5.0-pre, which was similarly
bumped to a `-pre` version in:

https://github.com/RustCrypto/traits/pull/215
2020-07-13 11:21:55 -07:00
Tony Arcieri 30390b357b ecdsa: add hazmat primitives; remove/reverse curve deps (#96)
Adds "hazmat" ECDSA signing and verification traits intended to be
implemented by individual elliptic curve implementations:

- `SignPrimitive`: intended to be implemented on `Scalar`
- `VerifyPrimitive`: intended to be implemented on `AffinePoint`

The traits are generic over elliptic curves, allowing one type to
potentially support multiple curves. This is potentially useful for
things like FFI bindings to multi-curve libraries, or host libraries for
hardware devices which support ECDSA signing for multiple elliptic
curves.

These traits must be consumed directly by elliptic curve
implementations, which means we need to reverse the current relationship
where the `ecdsa` crate has optional features for `k256`, `p256`, and
`p384`.

Instead, we can add an `ecdsa` feature to the `k256`, `p256`, and `p384`
crates which optionally pulls this crate in.

With the dependency relationship reversed, we can support an open ended
number of elliptic curves including 3rd party non-RustCrypto
implementations (as well as 3rd party ECDSA implementations ala
afforementioned hardware tokens).

This allows the `ecdsa` crate to focus on only the high-level details of
the ECDSA algorithm, like RFC 6979 deterministic signatures.

It also allows for wrapping complete ECDSA implementations, including
assembly optimized ECDSA primitives or things like hardware
accelerators.
2020-07-13 07:33:43 -07:00
Tony Arcieri 9d8f4b693c Add secp256k1 feature (#95)
...which wraps the underlying `k256` crate

People will ultimately be looking for "secp256k1" and `k256` is largely
an artifact of trying to use a crate name that wasn't taken and fit with
the other elliptic curve crates (`p256`, `k256`).

This should make it clearer.
2020-07-03 09:55:31 -07:00
Tony Arcieri f1001a6cf3 ecdsa: implement secp256k1 low-S normalization (#94)
Adds `normalize_s` method to `secp256k1::{Asn1Signature, FixedSignature}`
when the (new) `k256-arithmetic` feature is enabled.

This normalizes the s-component of ECDSA signatures in order to make
them non-malleable as describe din BIP 0062: Dealing with Malleability.
2020-06-30 17:36:38 -07:00
Tony Arcieri 37157efe2b Cargo.toml: fetch RustCrypto/elliptic-curves crates from git (#93)
Adds a `[patch.crates-io]` directive so we can work off the latest
versions of the https://github.com/RustCrypto/elliptic-curves crates.

This is a breaking change for the `ecdsa` crate and makes it
unreleasable until releases of the elliptic curve crates happen,
but will allow us to implement a number of new features which require a
curve arithmetic implementation.
2020-06-30 14:01:48 -07:00
Tony Arcieri ab958a0f86 ecdsa v0.6.1 (#92) ecdsa/v0.6.1 2020-06-29 12:44:40 -07:00
Tony Arcieri f1981c1502 ecdsa: add doc_cfg (#91)
Uses the nightly-only `doc_cfg` feature to document which modules/types
are gated behind cargo features (namely `k256`, `p256`, and `p384`)

This is intended for use with https://docs.rs
2020-06-29 12:11:11 -07:00
Tony Arcieri 569fbd86db ecdsa::curve::secp256k1::RecoverableSignature (#90)
Adds a signature type for Ethereum-style recoverable signatures.
2020-06-29 11:35:51 -07:00
Tony Arcieri 2110ec6649 README.md(s): documentation improvements (#89) 2020-06-16 11:39:46 -07:00
Tony Arcieri d41eaabaeb ecdsa v0.6.0 (#88) ecdsa/v0.6.0 2020-06-09 21:49:53 -07:00
Tony Arcieri 798b6de6d7 ecdsa: upgrade to signature ~1.1.0; sha v0.9 (#87)
These both depend on the `digest` v0.9 crate
2020-06-09 21:41:44 -07:00
Tony Arcieri fac52ad94f ecdsa: bump all elliptic curve crates; MSRV 1.41+ (#86)
Bumps the following crate dependencies, which all now depend on
`generic-array` v0.14:

- `elliptic-curve` v0.4.0
- `k256` v0.3.0
- `p256` v0.3.0
- `p384` v0.2.0

Also re-exports `generic-array` from the `elliptic-curve` crate rather
than depending on it directly, which simplifies upgrades.
2020-06-08 10:20:16 -07:00
Tony Arcieri 1ce6ebd301 .github: fix security-audit.yml branch 2020-06-08 10:02:23 -07:00
Tony Arcieri 8ddcb61618 Merge pull request #85 from RustCrypto/ecdsa/p256-k256-v0.2
Bump `p256` and `k256` to v0.2
2020-05-01 12:09:35 -07:00
Tony Arcieri cf0a95431e Bump p256 and k256 to v0.2
Release announcement:

https://www.reddit.com/r/rust/comments/gbjsr9/ann_rustcrypto_p256_and_k256_v020_pure_rust_nist/
2020-05-01 11:57:21 -07:00
Tony Arcieri e537618423 Merge pull request #84 from RustCrypto/ed25519/v1.0.1
ed25519 v1.0.1
2020-04-20 09:10:03 -07:00
Tony Arcieri d554249f1d ed25519 v1.0.1 ed25519/v1.0.1 2020-04-20 09:00:21 -07:00
Tony Arcieri 4ded235f71 Merge pull request #83 from RustCrypto/usage-docs
ed25519: improve usage documentation
2020-04-20 08:56:07 -07:00
Tony Arcieri 7dd3c60ba1 ed25519: improve usage documentation
Adds usage examples of how to write code which is generic over an
underlying signing provider.
2020-04-20 08:45:34 -07:00
Tony Arcieri 86187c3929 Merge pull request #82 from RustCrypto/ecdsa/v0.5.0
ecdsa v0.5.0
2020-04-18 12:20:13 -07:00
Tony Arcieri f6fa9198df ecdsa v0.5.0 ecdsa/v0.5.0 2020-04-18 12:13:11 -07:00
Tony Arcieri e8d26610c9 Merge pull request #81 from RustCrypto/ed25519/v1.0.0
ed25519 v1.0.0
2020-04-18 11:58:30 -07:00
Tony Arcieri 47f3a97e24 ed25519 v1.0.0 ed25519/v1.0.0 2020-04-18 11:47:24 -07:00
Tony Arcieri 5e154244f9 Merge pull request #80 from RustCrypto/signature-crate/v1.0
Upgrade to v1.0 release of the `signature` crate
2020-04-18 11:42:35 -07:00
Tony Arcieri cbf01646e6 Upgrade to v1.0 release of the signature crate
More info on this release: https://github.com/RustCrypto/traits/issues/78
2020-04-18 11:39:19 -07:00
Tony Arcieri fc4aeba557 Merge pull request #79 from RustCrypto/ed25519/v1.0.0-pre.4
ed25519 v1.0.0-pre.4
2020-03-17 10:03:39 -07:00
Tony Arcieri 35d05deadb ed25519 v1.0.0-pre.4 ed25519/v1.0.0-pre.4 2020-03-17 09:54:56 -07:00
Tony Arcieri 27bb964ed5 Merge pull request #78 from RustCrypto/ed25519/serde-fix
ed25519: avoid serializing a length prefix with serde
2020-03-17 09:48:57 -07:00
Tony Arcieri f5cc8b709e ed25519: avoid serializing a length prefix with serde
Previously the serde serializer used `Serialize::serialize_bytes` which
accepts a slice and when serialized with e.g. bincode also includes a
length prefix on the signature. As it were, this made it incompatible
with the extant deserializer (and as such, this PR also adds much needed
serialization tests).

This commit changes the serializer to use the same internal
implementation as serde's own `array_impls`, i.e. signatures are
serialized as a tuple with 64 members.

Using this implementation, it means an Ed25519 signature serialized with
bincode is identical to `to_bytes()`, i.e. there is no redundant length
prefix.
2020-03-17 09:35:00 -07:00
Tony Arcieri 0a9aca05e7 Merge pull request #77 from RustCrypto/ed25519/v1.0.0-pre.3
ed25519 v1.0.0-pre.3
2020-03-16 11:19:23 -07:00
Tony Arcieri 26519de8ae ed25519 v1.0.0-pre.3 ed25519/v1.0.0-pre.3 2020-03-16 11:07:23 -07:00
Tony Arcieri d3f17d0142 Merge pull request #76 from RustCrypto/build-badges
Improve build badges
2020-03-16 11:01:34 -07:00
Tony Arcieri bd497aad6f Improve build badges 2020-03-16 10:58:02 -07:00
Tony Arcieri a20a709a71 Merge pull request #75 from RustCrypto/github-actions
Switch to GitHub Actions
2020-03-16 10:47:26 -07:00
Tony Arcieri a1ae696733 Switch to GitHub Actions
Uses Rust actions from https://github.com/actions-rs
2020-03-16 10:42:18 -07:00
Tony Arcieri 5225653c1f Merge pull request #74 from RustCrypto/update-signature-requirement-to-v1.0.0-pre.5
Update signature requirement to v1.0.0-pre.5
2020-03-16 09:50:01 -07:00
Tony Arcieri 50aee81e3a Update signature requirement to v1.0.0-pre.5
Changelog here: https://github.com/RustCrypto/traits/pull/90
2020-03-16 09:43:43 -07:00
Tony Arcieri 99650e4935 Merge pull request #73 from RustCrypto/ecdsa/v0.5.0-pre
ecdsa v0.5.0-pre
2020-03-08 15:36:06 -07:00
Tony Arcieri b5ce35b515 ecdsa v0.5.0-pre ecdsa/v0.5.0-pre 2020-03-08 15:29:20 -07:00
Tony Arcieri 21539bf752 Merge pull request #72 from RustCrypto/ed25519/v1.0.0-pre.2
ed25519 v1.0.0-pre.2
2020-03-08 15:23:48 -07:00