Skip to content

Commit

Permalink
Bump to 4.0.0; update curve25519-dalek (#82)
Browse files Browse the repository at this point in the history
* upgrade curve25519-dalek to 4.0.0-rc.2

* clippy fixes

* activate ed25519/pem only when needed

* bump to 4.0.0; bump MSRV to 1.65; fix no_std support; test MSRV and no_std in CI

* use rust-toolchain instead of TOML to work with (unmaitained) actions-rs/toolchain
  • Loading branch information
conradoplg authored Jun 8, 2023
1 parent d08ae22 commit cab0bcd
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 27 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@ on:
- main

jobs:
test_msrv:
name: test on MSRV
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.2
- uses: actions-rs/toolchain@v1.0.7
with:
# When toolchain is not specified, it uses rust-toolchain, which is the MSRV
override: true
- uses: actions-rs/cargo@v1.0.3
with:
command: test
args: --all-features

test_nightly:
name: test on nightly
runs-on: ubuntu-latest
Expand All @@ -23,3 +37,20 @@ jobs:
with:
command: test
args: --all-features

build_no_std:
name: build with no_std
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3.5.2
- uses: actions-rs/toolchain@v1.0.7
with:
toolchain: stable
override: true
# This does not support std, so we use to test if no_std works
target: thumbv6m-none-eabi
- uses: actions-rs/cargo@v1.0.3
with:
command: build
# Disables std feature
args: --no-default-features --target thumbv6m-none-eabi
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

Entries are listed in reverse chronological order.

# 3.2.0
# 4.0.0

* Updates `sha2` version to `0.10` and `curve25519-dalek` version to `4.0.0-pre.5`.
* `Signature` is now an alias for `ed25519::Signature`
* `impl From<Signature> for [u8; 64]` no longer exists; use `to_bytes()` instead.
* `signature::{Signer, Verifier} is now implemented for `SigningKey` and `VerificationKey`.
* Updates `sha2` version to `0.10` and `curve25519-dalek` version to `4.0.0-rc.2`.
* Add DER & PEM support for SigningKeySeed and VerificationKeyBytes (RFC 8410) #46 https://github.com/ZcashFoundation/ed25519-zebra/pull/46
* This is under the non-default `pem` and `pkcs8` features

MSRV increased to `1.60.0`.
MSRV increased to `1.65.0`.

# 3.1.0

Expand Down
12 changes: 7 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
name = "ed25519-zebra"
# Before publishing:
# - update CHANGELOG.md
version = "3.1.0"
version = "4.0.0"
rust-version = "1.65.0"
authors = ["Henry de Valence <hdevalence@hdevalence.ca>"]
license = "MIT OR Apache-2.0"
edition = "2018"
Expand All @@ -15,9 +16,9 @@ features = ["nightly"]

[dependencies]
# "digest" is exempt from SemVer, so we should always use a specific version
curve25519-dalek = { version = "=4.0.0-pre.5", default-features = false, features = ["alloc", "digest"] }
curve25519-dalek = { version = "=4.0.0-rc.2", default-features = false, features = ["alloc", "digest", "zeroize", "precomputed-tables"] }
der = { version = "0.7.1", optional = true }
ed25519 = { version = "2.2.0", features = ["alloc", "pem"] }
ed25519 = { version = "2.2.0", default-features = false }
hashbrown = "0.14.0"
hex = { version = "0.4.3", default-features = false, features = ["alloc"] }
pkcs8 = { version = "0.10.1", optional = true, features = ["alloc", "pem"] }
Expand All @@ -37,9 +38,10 @@ once_cell = "1.4"
[features]
nightly = []
default = ["serde", "std"]
pem = ["der"]
pem = ["der", "ed25519/pem"]
pkcs8 = ["dep:pkcs8"]
std = []
serde = ["dep:serde", "ed25519/serde"]
std = ["ed25519/std"]

[[test]]
name = "rfc8032"
Expand Down
1 change: 1 addition & 0 deletions rust-toolchain
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.65.0
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ mod error;
mod signing_key;
mod verification_key;

// Allows importing traits used by `Signature`.
pub use ed25519;
pub use ed25519::Signature;
pub use error::Error;
pub use signing_key::SigningKey;
pub use verification_key::{VerificationKey, VerificationKeyBytes};
pub use ed25519::Signature;
15 changes: 11 additions & 4 deletions src/signing_key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@ const ALGORITHM_ID: AlgorithmIdentifierRef = AlgorithmIdentifierRef {
};

use crate::Error;
use core::convert::{TryFrom, TryInto};
use core::convert::TryFrom;
#[cfg(feature = "pem")]
use core::convert::TryInto;
use curve25519_dalek::{constants, digest::Update, scalar::Scalar};
use rand_core::{CryptoRng, RngCore};
use sha2::{Digest, Sha512};
use zeroize::Zeroize;

pub use ed25519::{
signature::{Signer, Verifier},
ComponentBytes, Error as Ed25519Error, KeypairBytes, PublicKeyBytes, Signature,
ComponentBytes, Error as Ed25519Error, Signature,
};

#[cfg(feature = "pem")]
pub use ed25519::{KeypairBytes, PublicKeyBytes};

#[cfg(all(feature = "pem", feature = "pkcs8"))]
use der::pem::LineEnding;
#[cfg(feature = "pkcs8")]
Expand Down Expand Up @@ -118,7 +123,7 @@ impl From<[u8; 32]> for SigningKey {
};

// Compute the public key as A = [s]B.
let A = &s * &constants::ED25519_BASEPOINT_TABLE;
let A = &s * constants::ED25519_BASEPOINT_TABLE;

SigningKey {
seed,
Expand Down Expand Up @@ -194,12 +199,14 @@ impl TryFrom<&KeypairBytes> for SigningKey {
}
}

#[cfg(feature = "pem")]
impl From<SigningKey> for KeypairBytes {
fn from(signing_key: SigningKey) -> KeypairBytes {
KeypairBytes::from(&signing_key)
}
}

#[cfg(feature = "pem")]
impl From<&SigningKey> for KeypairBytes {
fn from(signing_key: &SigningKey) -> KeypairBytes {
KeypairBytes {
Expand Down Expand Up @@ -278,7 +285,7 @@ impl SigningKey {
pub fn sign(&self, msg: &[u8]) -> Signature {
let r = Scalar::from_hash(Sha512::default().chain(&self.prefix[..]).chain(msg));

let R_bytes = (&r * &constants::ED25519_BASEPOINT_TABLE)
let R_bytes = (&r * constants::ED25519_BASEPOINT_TABLE)
.compress()
.to_bytes();

Expand Down
2 changes: 0 additions & 2 deletions tests/rfc8032.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
//! so these are basic sanity checks, rather than the more detailed test vectors
//! in consensus.rs.

use bincode;
use ed25519::Signature;
use ed25519_zebra::*;
use hex;

fn rfc8032_test_case(sk_bytes: Vec<u8>, pk_bytes: Vec<u8>, sig_bytes: Vec<u8>, msg: Vec<u8>) {
let sk: SigningKey = bincode::deserialize(&sk_bytes).expect("sk should deserialize");
Expand Down
9 changes: 2 additions & 7 deletions tests/small_order.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,10 @@ pub static SMALL_ORDER_SIGS: Lazy<Vec<TestCase>> = Lazy::new(|| {
);
let check = R + k * A;
let non_canonical_R = R.compress().as_bytes() != R_bytes;
let valid_legacy = if vk_bytes == [0; 32]
let valid_legacy = !(vk_bytes == [0; 32]
|| util::EXCLUDED_POINT_ENCODINGS.contains(R.compress().as_bytes())
|| !check.is_identity()
|| non_canonical_R
{
false
} else {
true
};
|| non_canonical_R);

tests.push(TestCase {
vk_bytes,
Expand Down
8 changes: 3 additions & 5 deletions tests/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,10 @@ pub fn order(point: EdwardsPoint) -> &'static str {
} else {
"8"
}
} else if point.is_torsion_free() {
"p"
} else {
if point.is_torsion_free() {
"p"
} else {
"8p"
}
"8p"
}
}

Expand Down

0 comments on commit cab0bcd

Please sign in to comment.