Commit graph

39 commits

Author SHA1 Message Date
Tony Arcieri
c8c9f29989
Add Scalar and MontgomeryPoint conversions (#296)
* Add `Scalar` and `MontgomeryPoint` conversions

- Adds `SigningKey::to_scalar` to extract the private scalar
- Adds `VerifyingKey::to_montgomery` to map the verifying key's
  `EdwardsPoint` to a `MontgomeryPoint`
- Also adds corresponding `From<&T>` impls which call the inherent
  methods.

This is useful for systems which are keyed using Ed25519 keys which
would like to use X25519 for D-H. Having inherent methods means it's
possible to call these methods without having to import `Scalar` and
`MontgomeryPoint` from `curve25519-dalek`.

This is of course a bit circuitous: we could just multiply `Scalar` by
`EdwardsPoint` and use the resulting `EdwardsPoint` as the D-H shared
secret, however it seems many protocols have adopted this approach of
mapping to `MontgomeryPoint` and using that for the shared secret, since
X25519 is traditionally used for ECDH with Curve25519.

* Add reference to eprint 2021/509

* Basic X25519 Diffie-Hellman test
2023-03-30 13:29:36 -04:00
Rob Ede
7901b21e06
Improve diagnostics when key being deserializing is too long (#294) 2023-03-26 04:11:23 -04:00
Samuel Moelius
7dc1bbd855
Remove two unnecessary into_iter (#290) 2023-03-18 09:22:15 -06:00
Michael Rosenberg
5190ad6df8
Impl VerifyingKey::is_weak (#277)
* Implemented VerifyingKey::is_weak

* Added unit test for VerifyingKey::is_weak
2023-01-31 16:23:38 -05:00
Tony Arcieri
27ba9dd614
Bump ed25519 crate dependency to v2.1 (#272)
The original v2.0.0 release has been yanked.

This release includes a different infallible parsing API which can be
used to eliminate some usages of `unwrap()`.
2023-01-21 17:59:11 -05:00
pinkforest(she/her)
431e69959d
Make digest optional (#268)
digest isn't yet stable but we have use it in the public API.

This makes the digest API optional to use in opt-in basis by
feature gating this via an optional digest feature.

API items now feature-gated:

- `pub use ed25519_dalek::Digest`
- `SigningKey::sign_prehashed(D: prehashed_message, ..)`
- `SigningKey::verify_prehashed(D: prehahed_message, ..)`
- `VerifyingKey::verify_prehashed(D: prehashed_message, ..)`
- `VerifyingKey::verify_prehashed_strict(D: prehashed_message, ..)`

Also no longer re-exporting `sha2::Sha512`
2023-01-19 02:59:43 -05:00
Linus Karl
e1d4ef313e
Implement Hash trait for VerifyingKey (#265)
* Added and cleaned up some verification docs

Co-authored-by: Michael Rosenberg <michael@mrosenberg.pub>
2023-01-16 22:43:05 -05:00
pinkforest(she/her)
8c455f58ae
Make rand_core optional (#262)
* Make rand_core optional
* Bench requires features rand_core
2023-01-15 19:13:33 -05:00
Michael Rosenberg
b5dc40bedf
Make verify_batch deterministic (#256)
Also removed `batch_deterministic` feature
2023-01-14 21:26:39 -05:00
andrew lyon
4f218d8e67
Adding verify_prehashed_strict() (#212)
Combines `verify_prehashed` and `verify_strict` to allow strict
verification with prehashed values.
2023-01-07 09:21:54 -07:00
Michael Rosenberg
f036eaf482
Validation criteria tests (#253) 2023-01-05 22:58:54 -05:00
Michael Rosenberg
e2ed3133a6
Fix batch build (#220)
* Fixed bench when `batch` feature is not present

* Added bench build regression test to CI

* Fixed batch build more generally

* Simplified batch cfg gates in benches

* Updated criterion

* Made CI batch-nondeterministic test use nostd

* Fix batch_deterministic build

* Removed bad compile error when batch and batch_deterministic are selected
2023-01-02 00:59:19 -05:00
Tony Arcieri
f6a242a5b0
Use namespaced/weak features; MSRV 1.60 (#235)
This enables activating the `alloc` and `std` features without
unnecessarily pulling in optional dependencies like `rand` and `serde`.

It also fixes tests for `--no-default-features` (w\ `--lib` only)
2022-12-20 04:48:55 -05:00
pinkforest(she/her)
194b17f18a
Fix all Clippy warnings (#244)
- Add Clippy to CI
- Rename InternalError variants without redundant Error suffix
- Rename to_bytes to as_bytes on well known naming
- Fix Redundant refs
- Fix redundant lifetimes
- Fix late declarations
2022-12-18 13:56:41 -07:00
Michal Nazarewicz
24cd9421d5 Change from_bytes methods to take fixed-size array argument
Change from_bytes methods to take `&[u8; N]` argument (with `N`
appropriate for given type) rather than `&[u8]`.  This harmonises
the convention with SigningKey and ed25519::Signature; helps type
inference; and allows users to assert bytes size to be asserted at
compile time.

Creating from a slice is still possible via `TryFrom<&[u8]>` trait.

This is an API breaking change.  The simplest way to update existing
code is to replace Foo::from_bytes with Foo::try_from.  This should
cover majority of uses.
2022-12-18 19:43:37 +01:00
Tony Arcieri
52da7353b8
Rename Keypair => SigningKey; PublicKey => VerifyingKey (#242)
* Rename `signing` and `verifying` modules

Renames the following modules:

- `keypair` => `signing`
- `public` => `verifying`

Renaming these in an individual commit preserves the commit history.

This is in anticipation of renaming the following per #225:

- `Keypair` => `SigningKey`
- `PublicKey` => `VerifyingKey`

* Rename `Keypair` => `SigningKey`; `PublicKey` => `VerifyingKey`

As proposed in #225, renames key types after their roles:

- `SigningKey` produces signatures
- `VerifyingKey` verifies signatures

The `SecretKey` type is changed to a type alias for `[u8; 32]`, which
matches the RFC8032 definition:

https://www.rfc-editor.org/rfc/rfc8032#section-5.1.5

> The private key is 32 octets (256 bits, corresponding to b) of
> cryptographically secure random data.
2022-12-18 01:24:58 -05:00
Tony Arcieri
55620dcde5
PKCS#8 support (#224)
Adds optional integration with `ed25519::pkcs8` with support for
decoding/encoding `Keypair` from/to PKCS#8-encoded documents as well as
`PublicKey` from/to SPKI-encoded documents.

Includes test vectors generated for the `ed25519` crate from:
https://github.com/RustCrypto/signatures/tree/master/ed25519/tests/examples
2022-12-13 18:19:31 -05:00
Tony Arcieri
cfcdf536a0
Cargo.toml: compatibility updates for curve25519-dalek and ed25519 (#236)
curve25519-dalek:

- Enables `digest` and `rand_core` features
- Removes transitive `nightly`, `simd_backend`, and `std` features

ed25519:

- `AsRef` impl for `Signature` has been removed; uses `to_bytes`
- Uses `try_from` for `InternalSignature` conversion
2022-12-09 21:14:38 -05:00
Tony Arcieri
01ad6305f2
Edition fixups: remove extern crate, add idioms lint (#231)
Rust editions 2018+ do not require `extern crate` except for linking
`alloc` and `std`.
2022-12-08 02:39:48 -05:00
Tony Arcieri
ae4bd2c81e
Fix warnings and add -D warnings check in CI (#226) 2022-11-20 22:28:09 -05:00
Tony Arcieri
f7cbeee7f6
Bump curve25519-dalek to v4.0.0-pre (via git) (#223)
Also bumps these corresponding dependencies which are needed for everything to compile with this update:

* `merlin` v3.0
* `rand` v0.8
* `rand_core` v0.6
* `sha2` v0.10
2022-11-20 15:08:05 -05:00
Alex Xiong
9638ab40a5
Made ExpandedSecretKey private to avoid signing key oracle (#205)
This fix eliminates a scenario where a user misuses the `ExpandedSecretKey` API
in a way that leaks the user's secret key. In short, if a user sends
`ExpandedSecretKey::sign(sk, msg, pk1)` followed by
`ExpandedSecretKey::sign(sk, msg, pk2)`, where `pk1 != pk2`, a passive
adversary [can easily][0] derive `sk`. To mitigate this, we remove the API
entirely.

[0]: https://github.com/MystenLabs/ed25519-unsafe-libs
2022-10-15 15:04:03 -04:00
François Garillot
da6c7e114f
[test-only] Add test showing the non-repudiation property of the signature verifications used in PublicKey::verify and PublicKey::verify_strict.
This PR is a follow-up of #98, which aims to demonstrate the issue brought by small-order public keys. It shows an example of crafting a (public_key, signature) that verifies against two distinct messages using `verify`, but fails using `verify_strict`.
This has consequences on the possibility to repudiate a signed contract of blockchain transactions.

For more details, see:
https://eprint.iacr.org/2020/1244

Joint work with @kchalkias @valerini
2020-10-14 17:28:51 -04:00
Cheng XU
008c9680f6
Update tests for serde
* Upgrade bincode to 1.0
* Add more serde tests including json serialization.
2020-09-21 18:26:59 -07:00
Isis Lovecruft
1c97dac4dc
Update to curve25519-dalek version 3. 2020-08-20 21:19:21 +00:00
Isis Lovecruft
7243d7151d
Fix handling of external error types. 2020-07-16 22:19:40 +00:00
Isis Lovecruft
b8f36d48d8
Fix proc_macro crate name resolution for serde integration tests. 2020-07-15 17:39:23 +00:00
Isis Lovecruft
e7a88c2c7f
Try compiling tests using serde_crate instead. 2020-07-14 23:58:35 +00:00
Isis Lovecruft
3a9435df94
Fixup serde and ed25519 trait errors in tests/benches. 2020-07-13 23:16:30 +00:00
Isis Lovecruft
84047448da
Merge remote-tracking branch 'tarcieri/ed25519-crate' into develop 2020-07-13 23:00:23 +00:00
Isis Lovecruft
9e247c493c
Add additional tests for keypair (de)serialisation. 2020-06-30 22:40:24 +00:00
Tony Arcieri
6e0667d429 Use ed25519 + signature interop crates
The `signature` crate provides `Signer` and `Verifier` traits generic
over signature types:

https://github.com/RustCrypto/traits/tree/master/signature

There's presently an open call to stabilize the parts of its API needed
by Ed25519 signatures and release a 1.0 version:

https://github.com/RustCrypto/traits/issues/78

The `ed25519` crate, based on the `signature` crate, provides an
`ed25519::Signature` type which can be shared across multiple Ed25519
crates (e.g. it is also used by the `yubihsm` crate):

https://github.com/RustCrypto/signatures/tree/master/ed25519

This commit integrates the `ed25519::Signature` type, and changes the
existing `sign` and `verify` methods (where applicable) to use the
`Signer` and `Verifier` traits from the `signature` crate. Additionally,
it replaces `SignatureError` with the `signature` crate's error type.

This has the drawback of requiring the `Signer` and/or `Verifier` traits
are in scope in order to create and/or verify signatures, but with the
benefit of supporting interoperability with other Ed25519 crates which
also make use of these traits.
2020-04-20 09:15:10 -07:00
Michael Lodder
c3f4c7a67e Update to latest rand
Signed-off-by: Michael Lodder <redmike7@gmail.com>
2019-10-21 09:03:08 -06:00
Isis Lovecruft
d31df0aaa8
Remove sha2 dep; limit rand depends; fixes after PR#68 merge.
* ADD new "batch" feature for feature-gating ed25519 batch verification; off by
   default. The "batch" feature is the only thing which depends on all of the
   `rand` crate, since it requires the functionality of `rand::thread_rng()`.
   Without batch verification, the rest of ed25519-dalek only depends on
   `rand_os` and `rand_core`.
2019-04-02 01:46:23 +00:00
Isis Lovecruft
ae8764fbef
Update copyright year to 2019 and destroy capitalism. 2019-01-18 04:59:12 +00:00
Isis Lovecruft
42b571eb24
Remove unused clear_on_drop import from tests. 2018-12-30 04:26:56 +00:00
Isis Lovecruft
144e87bfc8
Remove unnecessary tests/mod.rs file. 2018-12-30 04:01:39 +00:00
Isis Lovecruft
eb8ab9f06b
Organise integration tests into modules. 2018-12-30 02:32:21 +00:00
Isis Lovecruft
e88da5ea85
Move integration tests to their own directory. 2018-12-30 02:32:21 +00:00