Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ed25519 signing leaks #381

Merged
merged 1 commit into from
Jul 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## master

Changes:

- Protect against double-sign leak in ed25519 (See https://github.com/MystenLabs/ed25519-unsafe-libs)


## 6.2.1 Jul 1, 2022

Changes:
Expand Down
41 changes: 21 additions & 20 deletions packages/wasm-crypto/src/rs/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@ use ed25519_dalek::{Keypair, PublicKey, SecretKey, Signature, Signer as _, Verif
use wasm_bindgen::prelude::*;

/// Keypair helper function
fn new_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
let mut pair = vec![];
fn new_from_seed(seed: &[u8]) -> Keypair {
match &SecretKey::from_bytes(seed) {
Ok(s) => {
let pubkey: PublicKey = s.into();
let mut pair = vec![];

pair.extend_from_slice(seckey);
pair.extend_from_slice(pubkey);
pair.extend_from_slice(seed);
pair.extend_from_slice(pubkey.as_bytes());

match Keypair::from_bytes(&pair) {
Ok(p) => p,
_ => panic!("Provided pair is invalid.")
match Keypair::from_bytes(&pair) {
Ok(p) => p,
_ => panic!("Created pair is invalid.")
}
},
_ => panic!("Invalid seed provided.")
}
}

Expand All @@ -26,31 +32,26 @@ fn new_from_parts(pubkey: &[u8], seckey: &[u8]) -> Keypair {
/// followed by the public key (32) bytes, as the full secret keys.
#[wasm_bindgen]
pub fn ext_ed_from_seed(seed: &[u8]) -> Vec<u8> {
match &SecretKey::from_bytes(seed) {
Ok(s) => {
let pubkey: PublicKey = s.into();

new_from_parts(pubkey.as_bytes(), seed)
.to_bytes()
.to_vec()
},
_ => panic!("Invalid seed provided.")
}
new_from_seed(seed)
.to_bytes()
.to_vec()
}

/// Sign a message
///
/// The combination of both public and private key must be provided.
/// This is effectively equivalent to a keypair.
///
/// * pubkey: UIntArray with 32 element
/// * _: UIntArray with 32 element (was pubkey, now ignored)
/// * private: UIntArray with 64 element
/// * message: Arbitrary length UIntArray
///
/// * returned vector is the signature consisting of 64 bytes.
#[wasm_bindgen]
pub fn ext_ed_sign(pubkey: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
new_from_parts(pubkey, seckey)
pub fn ext_ed_sign(_: &[u8], seckey: &[u8], message: &[u8]) -> Vec<u8> {
// https://github.com/MystenLabs/ed25519-unsafe-libs
// we never use the provided pubkey
new_from_seed(seckey)
.sign(message)
.to_bytes()
.to_vec()
Expand Down