Skip to content

Commit 6f19fd0

Browse files
committed
Update dalek
The two failing ed25519 tests are likely the cause of all the other failures, but it'll take some actual attention to figure out what's going on with them.
1 parent 2cc250e commit 6f19fd0

File tree

4 files changed

+46
-56
lines changed

4 files changed

+46
-56
lines changed

Cargo.toml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ cfg-if = "1"
2323
clear_on_drop = "0.2"
2424
derivative = "2.1"
2525
# Disable all features for ed25519 and enable the proper ones down in the [features] section below
26-
ed25519-dalek = {version = "=0.1.0", default-features = false, features = ["std"], package = "ed25519-dalek-fiat"}
26+
ed25519-dalek = {version = "2.1.1", default-features = false, features = ["std", "rand_core"]}
2727
# Explicit dependency so we can pass the wasm-bindgen flag to it
2828
getrandom = {version = "0.2", optional = true}
2929
gridiron = "0.10"
@@ -55,10 +55,7 @@ debug = false
5555
lto = true
5656

5757
[features]
58-
default = ["u64_backend"]
59-
u64_backend = ["ed25519-dalek/u64_backend"]
60-
u32_backend = ["ed25519-dalek/u32_backend"]
61-
wasm = ["u32_backend", "clear_on_drop/no_cc", "getrandom/js"]
58+
wasm = ["clear_on_drop/no_cc", "getrandom/js"]
6259
#Can be used to disable the automatic mlock detection for architectures.
6360
disable_memlock = []
6461

flake.lock

Lines changed: 29 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
22
profile = "default"
3-
channel = "1.67.1"
3+
channel = "1.70.0"

src/internal/ed25519.rs

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::internal::ByteVector;
55
use crate::internal::{array_split_64, take_lock};
66
use clear_on_drop::clear::Clear;
77
use ed25519_dalek;
8-
use ed25519_dalek::PublicKey;
98
use quick_error::quick_error;
109
use rand;
1110
use std;
@@ -64,10 +63,10 @@ impl From<SigningKeypair> for [u8; 64] {
6463
impl SigningKeypair {
6564
const ENCODED_SIZE_BYTES: usize = 64;
6665
pub fn new<CR: rand::RngCore + rand::CryptoRng>(rng: &Mutex<CR>) -> SigningKeypair {
67-
let keypair = ed25519_dalek::Keypair::generate::<CR>(&mut *take_lock(rng));
66+
let signing_key = ed25519_dalek::SigningKey::generate::<CR>(&mut *take_lock(rng));
6867

6968
//Unchecked is safe because the public is on the curve and the size is statically guaranteed.
70-
SigningKeypair::new_unchecked(keypair.to_bytes())
69+
SigningKeypair::new_unchecked(signing_key.to_keypair_bytes())
7170
}
7271
///
7372
///Create a SigningKeypair from a byte array slice. If the array is not the right length or if the public
@@ -93,16 +92,11 @@ impl SigningKeypair {
9392
///match the private key.
9493
///
9594
pub fn from_bytes(sized_bytes: &[u8; 64]) -> Result<SigningKeypair, Ed25519Error> {
96-
let (priv_key, pub_key) = array_split_64(sized_bytes);
97-
//This can't fail because it's statically guaranteed to be 32 bytes long.
98-
let ed25519_dalek_secret = ed25519_dalek::SecretKey::from_bytes(&priv_key).unwrap();
95+
let (_, pub_key) = array_split_64(sized_bytes);
9996
//Calculate the public key to check that the value passed in is correct.
100-
let ed25519_dalek_pub = ed25519_dalek::PublicKey::from(&ed25519_dalek_secret);
101-
if ed25519_dalek_pub.to_bytes() == pub_key {
102-
Ok(SigningKeypair::new_unchecked(*sized_bytes))
103-
} else {
104-
Err(Ed25519Error::PublicKeyInvalid(pub_key))
105-
}
97+
let ed25519_dalek_pub = ed25519_dalek::VerifyingKey::from_bytes(&pub_key)
98+
.map_err(|_| Ed25519Error::PublicKeyInvalid(pub_key))?;
99+
Ok(SigningKeypair::new_unchecked(*sized_bytes))
106100
}
107101

108102
pub(crate) fn new_unchecked(bytes: [u8; 64]) -> SigningKeypair {
@@ -153,7 +147,7 @@ impl Ed25519Signing for Ed25519 {
153147
use ed25519_dalek::Signer;
154148
//This unwrap cannot fail. The only thing that the `from_bytes` does for validation is that the
155149
//value is 64 bytes long, which we guarantee statically.
156-
let key_pair = ed25519_dalek::Keypair::from_bytes(&signing_key.bytes[..]).unwrap();
150+
let key_pair = ed25519_dalek::SigningKey::from_bytes(signing_key.public_key().bytes());
157151
let sig = key_pair.sign(&t.to_bytes()[..]);
158152

159153
Ed25519Signature::new(sig.to_bytes())
@@ -166,10 +160,10 @@ impl Ed25519Signing for Ed25519 {
166160
) -> bool {
167161
use ed25519_dalek::Verifier;
168162

169-
PublicKey::from_bytes(&public_key.bytes[..])
163+
ed25519_dalek::VerifyingKey::from_bytes(&public_key.bytes)
170164
.and_then(|pk| {
171-
TryFrom::try_from(&signature.bytes[..])
172-
.and_then(|sig| pk.verify(&t.to_bytes()[..], &sig))
165+
let sig = ed25519_dalek::Signature::from_bytes(&signature.bytes);
166+
pk.verify(&t.to_bytes()[..], &sig)
173167
})
174168
.map(|_| true)
175169
.unwrap_or(false)
@@ -197,7 +191,6 @@ pub trait Ed25519Signing {
197191
pub(crate) mod test {
198192
use super::*;
199193
use crate::internal::array_concat_32;
200-
use ed25519_dalek::SecretKey;
201194

202195
pub fn good_signing_keypair() -> SigningKeypair {
203196
SigningKeypair::new_unchecked([
@@ -209,10 +202,9 @@ pub(crate) mod test {
209202

210203
#[test]
211204
fn real_ed25519_matches_verify_good_message() {
212-
let sec_key = SecretKey::from_bytes(&[1; 32]).unwrap();
213-
let dalek_pub_key = ed25519_dalek::PublicKey::from(&sec_key);
205+
let dalek_pub_key = ed25519_dalek::VerifyingKey::from_bytes(&[1u8; 32]).unwrap();
214206
let priv_key = SigningKeypair {
215-
bytes: array_concat_32(&sec_key.to_bytes(), &dalek_pub_key.to_bytes()),
207+
bytes: array_concat_32(&[1u8; 32], &dalek_pub_key.to_bytes()),
216208
};
217209
let message = [100u8; 32].to_vec();
218210
let result = Ed25519.sign(&message, &priv_key);
@@ -238,10 +230,9 @@ pub(crate) mod test {
238230

239231
#[test]
240232
fn signing_keypair_into_bytes() {
241-
let sec_key = SecretKey::from_bytes(&[1; 32]).unwrap();
242-
let dalek_pub_key = ed25519_dalek::PublicKey::from(&sec_key);
233+
let dalek_pub_key = ed25519_dalek::VerifyingKey::from_bytes(&[1u8; 32]).unwrap();
243234
let key_pair = SigningKeypair {
244-
bytes: array_concat_32(&sec_key.to_bytes(), &dalek_pub_key.to_bytes()),
235+
bytes: array_concat_32(&[1u8; 32], &dalek_pub_key.to_bytes()),
245236
};
246237
let key_pair_bytes = key_pair.bytes().clone();
247238
let bytes: [u8; 64] = key_pair.into();

0 commit comments

Comments
 (0)