Commit Graph

340 Commits

Author SHA1 Message Date
Dan Cline 8c15d0e7b9 ecdsa: impl recoverable RandomizedPrehashSigner for SigningKey (#878) 2025-01-19 14:13:52 -07:00
Tony Arcieri f46f4a32ac ecdsa: simplify serde feature (#874)
To get `serde` support for `VerifyingKey`, confusingly the `pem` feature
previously needed to be enabled (even though PEM is not actually used).

This changed the `serde` feature to auto-enable `pkcs8`, similar to
what was done in the `elliptic-curve` crate.
2024-10-18 10:17:06 -06:00
Arthur Gautier cf81fb325c ecdsa,dsa,ed25519,ed448: pkcs8 API changes (#851)
Signed-off-by: Arthur Gautier <baloo@superbaloo.net>
2024-09-05 16:00:43 -06:00
Tony Arcieri 132b046314 ecdsa: add IEEE P1363 reference (#850) 2024-08-18 15:08:41 -06:00
Tony Arcieri 4d35f35bcb ecdsa: fix deprecation warnings (#839) 2024-07-26 21:12:25 -06:00
Tony Arcieri 9566f5eb71 Bump hybrid-array to v0.2.0-pre.9 (#835)
Fixes deprecation warnings
2024-07-26 18:45:43 -06:00
xjd 73a8922480 ecdsa: optimize trial_recovery_from_prehash using recover_from_prehash_noverify (#832)
verifying the public key on each attempt is unnecessary. Just verify
once.
2024-07-25 07:20:02 -06:00
xjd 7bcbfdefa3 ecdsa: add VerifyingKey::recover_from_prehash_noverify (#831)
If the recovered public key isn't correct, an error occurs when comparing it to
the correct public key or public key hash. Therefore, we can skip this expensive
verification.
2024-07-23 10:14:26 -06:00
Shao-Fu Chen 21a9dfb4a9 Remove unnecessary DigestPrimitive bound on PrehashVerifier (#823) 2024-05-17 18:17:04 -06:00
Arthur Gautier 6544071722 ecdsa: fixup unnecessary qualification warnings (#824) 2024-05-17 10:39:06 -06:00
turbocool3r 31838b9dcd dsa+ecdsa: support der custom error types (#809)
Goes with this `formats` PR: RustCrypto/formats#1055
2024-03-03 11:26:29 -07:00
Tony Arcieri 5c2ee91960 ecdsa: bump elliptic-curve to v0.14.0-pre.5 (#805)
Notably this includes the newly refactored `LinearCombination` trait
2024-02-01 19:00:07 -07:00
Tony Arcieri 996130459a ecdsa: refactor VerifyingKey::recover_from_prehash (#804)
Replaces some manual branching and use of `unwrap()` with a more
combinator-like style.

This could benefit from it being easier to convert `CtOption` into
`Option`. See dalek-cryptography/subtle#119
2024-02-01 18:25:44 -07:00
Tony Arcieri ff9a2058bd ecdsa: use NonZeroScalar arguments to sign_prehashed (#794)
Provides type-level enforcement that these parameters are non-zero
2024-01-17 19:07:59 -07:00
Tony Arcieri 3ed9867409 ecdsa: remove SignPrimitive and VerifyPrimitive traits (#793)
The backstory of these traits was once upon a time we didn't yet have
the trait structure in place to express algorithms like ECDSA signing
and verification generically, so each crate (at the time just `k256` and
`p256`) had a nearly duplicated implementation of ECDSA, with `k256`
including tweaks for low-S normalization.

Now the `ecdsa` crate contains fully generic implementations of both
algorithms, and with the `EcdsaCurve` trait, carries a `NORMALIZE_S`
preference, so these traits are just needless indirection at this point.

This removes the traits, converting non-trivial methods into static
functions in the `hazmat` module, namely `sign_prehashed_rfc6979`.
2024-01-17 18:18:59 -07:00
Tony Arcieri c5206d43db ecdsa: use EcdsaCurve in bounds (#792)
Replaces previous `PrimeCurve` bounds with the new `EcdsaCurve` trait
(which has a supertrait bound on `PrimeCurve`).
2024-01-17 16:14:01 -07:00
Tony Arcieri 56b8b7acdf ecdsa: move EcdsaCurve trait to toplevel (#791)
Moves the trait added in #787 out of the `hazmat` module and into the
toplevel, so it's available regardless of whether or not the `hazmat`
feature has been enabled.
2024-01-17 14:20:52 -07:00
Tony Arcieri 3992dc30e0 ecdsa: don't feature-gate EcdsaCurve (#790)
There's no reason for it to be gated on `arithmetic`. It can be provided
in all use cases.
2024-01-17 13:09:03 -07:00
Tony Arcieri 9eda95a623 ecdsa: add EcdsaCurve marker trait (#787)
This trait is the intended successor to the `SignPrimitive` and
`VerifyPrimitive` traits.

Currently the only reason for a non-default impl of those traits is to
handle low-S normalization. The `EcdsaCurve` trait now not only marks
the curve as being safe for use with ECDSA, but also captures this
decision regarding low-S normalization so it doesn't have to be
expressed in code.
2024-01-17 12:16:17 -07:00
Tony Arcieri 81adf2e2fc ecdsa: add DER support to SignatureWithOid (#786)
Adds the following methods:

- `from_der_with_digest`
- `from_der_with_oid`
- `to_der`

These handle deserializing/serializing ASN.1 DER-encoded signatures.
2024-01-17 10:17:26 -07:00
Tony Arcieri 4a94edb56a Bump digest, elliptic-curve, and signature; MSRV 1.72 (#785)
Bumps the following dependencies:
- `digest` v0.11.0-pre.7
- `elliptic-curve` v0.14.0-pre.3
- `signature` v2.3.0-pre.2
2024-01-17 10:07:35 -07:00
Tony Arcieri 970aacfaea ecdsa: gate pkcs8::Encode*Key impls under alloc+pkcs8 (#783)
...rather than `pem`, as these can be used to encode DER without having
full `pem` support enabled.

Closes #721
2024-01-17 08:09:20 -07:00
Tony Arcieri 32edd0d630 ecdsa: make Signature::normalize_s infallible (#780)
Unconditionally returns a normalized signature, regardless of whether
the signature was normalized to begin with.

Closes #736
2024-01-16 18:33:49 -07:00
Tony Arcieri 83359e104d ecdsa: reduce z mod q when performing RFC6979 (#777)
The RFC specifies this, however we were not performing it.

Going forward, it would be nice to be able to refactor these APIs to
operate over a `Scalar` which we know is always reduced.
2024-01-16 17:57:05 -07:00
Tony Arcieri 8e12e1c7cd ecdsa: remove OutputSize bounds on DigestPrimitive (#774)
Notably for curves like P-521, the digest used to compute the signature
is smaller than a serialized field element (SHA-512 w\ 64-byte output vs
66-byte serialized field elements).

To support such curves, we need to remove this bound.

The already implemented `bits2field` function as defined in
RFC6979 § 2.3.2 and SEC1 § 2.3.8 handles producing a serialized field
element from an input which may be a different size.
2024-01-16 14:06:50 -07:00
Tony Arcieri 2472e1cb7f rfc6979: add generate_k_mut; remove digest bounds (#773)
Adds an API which writes `k` into an output buffer rather than
allocating and returning it, which also accepts slices as inputs. This
makes it possible to use `rfc6979` to implement the `dsa` crate.

Also removes output size bounds on the underlying digest function, which
aren't actually relevant to the implementation at all since HMAC-DRBG
writes a variable-sized amount of output. This makes it possible to use
`rfc6979` + `ecdsa` in conjunction with `p521`, which has unusually
sized scalars (66-bytes) which don't match the output size of the
underlying digest function (SHA-512, which has a 64-byte output).
2024-01-16 09:57:05 -07:00
Bernd Krietenstein b41c216560 Fixed rfc reference in comment. (#772) 2024-01-12 05:55:44 -07:00
Tony Arcieri 2cb7693956 ecdsa: fix new_wycheproof_test! macro (#770)
Updates `from_exact_iter` => `from_iter`
2024-01-10 14:11:13 -07:00
Tony Arcieri 1e5e29cc50 Bump elliptic-curve and signature dependencies (#769)
As well as bumping `hybrid-array` to v0.2.0-rc.0 and `digest` to
v0.11.0-pre.4.

Also cuts `ecdsa` v0.17.0-pre.1 and `rfc6979` v0.5.0-pre.1
2024-01-10 13:34:47 -07:00
Tony Arcieri d935382d8d ecdsa: fix dev macros (#768)
The method changed from `GenericArray::from_slice` to
`Array::ref_from_slice`.

This has been renamed back upstream in `hybrid-array` to simplify
people's upgrades, but for now we need to rename it until we can upgrade
`hybrid-array` again.

Longer term the method will be deprecated, so this is temporary anyway.
2024-01-10 08:16:08 -07:00
Tony Arcieri 4ee30f578e Bump signature to v2.3.0-pre.0; MSRV 1.71 (#765)
For `ecdsa` crate: MSRV is 1.73 due to a bump of `elliptic-curve` to
v0.14.0-pre.0.

This commit begins the next round of breaking changes and bumps all
crates to prerelease versions.

The main change in `signature` is an upgrade of the `digest` crate to
v0.11.0-pre.3, which is what brings the new MSRV 1.71 requirement.
2024-01-09 12:07:49 -07:00
Tony Arcieri e8d4d23a43 ed25519: hexify Debug impl on Signature (#747)
Formats the `R` and `s` signature components as hexidecimal to make the
representation more compact, as requested in #723:

ed25519::Signature {
    R: 0x3f3e3d3c3b3a393837363534333231302f2e2d2c2b2a29282726252423222120,
    s: 0x1f1e1d1c1b1a191817161514131211100f0e0d0c0b0a09080706050403020100,
}
2023-10-15 12:47:01 -06:00
Tony Arcieri d7557a62bc ecdsa: extract hazmat::{sign_prehashed, verify_prehashed}. (#731)
Extracts generic, reusable functions from the `SignPrimitive` and
`VerifyPrimitive` traits.

The main motivation for this is to make it possible for the `*Primitive`
trait impls to be composed in terms of a generic implementation, in
order to add support for low-S normalization in the `k256` crate.
2023-07-17 16:55:05 -06:00
Tony Arcieri 2c3d90ed6f ecdsa: refactor Signature constructors and improve docs (#730)
Implements `from_bytes` in terms of `from_scalars`, rather than the
other way around.

This places the logic for checking that `r` and `s` are nonzero inside
of the `from_scalars` method.

Additionally improves the documentation to note the various failure
cases, i.e. if `r` and/or `s` is out of the range `1..n`, where `n` is
the scalar modulus.
2023-07-10 12:46:56 -06:00
Arthur Gautier 7bf1313e85 ecdsa: Adds support for the SignatureBitStringEncoding trait (#716) 2023-05-04 16:29:24 -06:00
Tony Arcieri 800eda2a07 ecdsa: make fmt impls more consistent (#713) 2023-04-14 11:30:03 -06:00
Tony Arcieri 31ebc99a15 ecdsa: serde doc fixup (#712)
The width of a serialized `Signature` is generic and based on the size
of the underlying curve's modulus, not a fixed 64-bytes.
2023-04-14 10:57:19 -06:00
Tony Arcieri 9433d578fa ecdsa: change der::Signature citation to RFC5912 (#711) 2023-04-13 14:21:53 -06:00
Tony Arcieri b776db27b0 ecdsa: add RFC5480 citation for der::Signature (#710)
Adds a reference to the ASN.1 schema and where it's defined
2023-04-13 14:09:26 -06:00
Tony Arcieri c3e35b13f2 ecdsa: fix test macros handling of serialized field size (#707)
Uses `C::FieldBytesSize` instead of `C::Uint::BYTES`, which is needed
for curves like P-224 where the serialized field element may be smaller
than the bigint used to represent them.
2023-04-09 18:13:59 -06:00
Tony Arcieri d18b8a90f3 ecdsa: use C::FieldBytesSize over C::Uint::BYTES (#705)
This is needed to make curves like P-224 and P-521 work, since the size
of the `C::Uint` may not match the size of an integer serialization of a
field element (since `C::Uint::MAX` may be much larger than the field
modulus)
2023-04-08 20:27:34 -06:00
Tony Arcieri 621a847b8a ecdsa: fix RecoveryId computation in SignPrimitive (#702)
The implementation was adapted from `k256`, which produces signatures
with low-S normalization.

However, the provided implementation does not low-S normalize
signatures, so it should not be considered in the `RecoveryId`
computation.
2023-04-05 12:19:39 -06:00
Tony Arcieri d25b07c18e ecdsa: forward AssociatedAlgorithmIdentifier impls (#698)
...from the `elliptic-curve` crate, as released in v0.13.3
2023-04-04 20:39:20 -06:00
Dmitry Baryshkov 9de47b676e ecdsa: follow the DynAssociatedAlgorithmIdentifier changes (#695)
Signed-off-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
2023-04-04 18:08:25 -06:00
Tony Arcieri bb601997d8 ecdsa: add SignatureWithOid verification support (#690)
Gated under a newly added `sha2` feature.

This implementation dispatches based on RFC5758 OIDs, selecting the
appropriate hash function to use at runtime based on the OID.
2023-04-02 19:59:53 -06:00
Tony Arcieri e05b64f4d8 ecdsa: add SignatureWithOid (#689)
Adds a signature type which is paramaterized by an RFC5758-defined OID
identifying the variant of ECDSA used to produce the signature.
2023-04-02 19:22:20 -06:00
Tony Arcieri 5ebcfef950 ecdsa: impl SignatureAlgorithmIdentifier (#688)
Propagates the `AssociatedAlgorithmIdentifier` from `Signature<C>` to
`SigningKey<C>` and `VerifyingKey<C>`.
2023-04-02 18:31:20 -06:00
Tony Arcieri 56dd91a963 ecdsa: add RFC5758 OID support (#686)
Adds support for obtaining the RFC5758 OIDs associated with the digest
algorithm used with the `Signer` and `Verifier` traits, i.e. the digest
defined via `DigestPrimitive::Digest` for a given curve.

The ECDSA OID is available via an `AssociatedOid` impl on `Signature`.

The `AlgorithmIdentifier` is also available via the newly added
`AssociatedAlgorithmIdentifier` trait.
2023-04-02 16:13:16 -06:00
Tony Arcieri 6121f15d59 ecdsa: add Signature::{from_bytes, from_slice} (#684)
Adds inherent methods for parsing a signature from `SignatureBytes<C>`
and a byte slice respectively.

The existing `TryFrom<&[u8]>` impl now calls `Signature::from_slice`.

These methods match similar inherent methods on other types.
2023-03-28 10:58:49 -06:00
Jonas Lindstrøm e572a42236 ecdsa: handle the reduced R.x case in public key recovery (#680) 2023-03-18 14:11:22 -06:00