Skip to content

Commit

Permalink
Expose ed25519 curve operations
Browse files Browse the repository at this point in the history
This allows to for example implement ECDH on the ed25519 curve.
  • Loading branch information
cloudhead committed Feb 9, 2023
1 parent cf1a0c0 commit 434fb21
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
9 changes: 9 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, KeyPair};

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

/// Get the scalar value of the seed.
pub fn scalar(&self) -> [u8; 32] {
let hash_output = sha512::Hash::hash(&self[..]);
let (scalar, _) = 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

0 comments on commit 434fb21

Please sign in to comment.