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

Expose scalar multiplication on ed25519 #29

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ed25519-compact"
version = "2.0.3"
version = "2.0.5"
authors = ["Frank Denis <github@pureftpd.org>"]
edition = "2018"
description = "A small, self-contained, wasm-friendly Ed25519 implementation"
Expand Down
10 changes: 10 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use core::ptr;
use core::sync::atomic;

use super::error::Error;
use super::sha512;

/// A seed, which a key pair can be derived from.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
Expand Down Expand Up @@ -33,6 +34,15 @@ impl Seed {
Ok(Seed::new(seed_))
}

/// Get the scalar value of the seed.
#[cfg(not(feature = "disable-signatures"))]
pub fn scalar(&self) -> [u8; 32] {
let hash_output = sha512::Hash::hash(&self[..]);
let (scalar, _) = crate::KeyPair::split(&hash_output, false, true);

scalar
}

/// Tentatively overwrite the content of the seed with zeros.
pub fn wipe(self) {
Mem::wipe(self.0)
Expand Down
5 changes: 1 addition & 4 deletions src/ed25519.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,10 +397,7 @@ impl KeyPair {
if seed.iter().fold(0, |acc, x| acc | x) == 0 {
panic!("All-zero seed");
}
let (scalar, _) = {
let hash_output = sha512::Hash::hash(&seed[..]);
KeyPair::split(&hash_output, false, true)
};
let scalar = seed.scalar();
let pk = ge_scalarmult_base(&scalar).to_bytes();
let mut sk = [0u8; 64];
sk[0..32].copy_from_slice(&*seed);
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ pub use crate::error::*;
#[cfg(not(feature = "disable-signatures"))]
mod ed25519;
#[cfg(not(feature = "disable-signatures"))]
mod edwards25519;
pub mod edwards25519;

#[cfg(not(feature = "disable-signatures"))]
pub use crate::ed25519::*;
Expand Down