Skip to content
Closed
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 bolos-impl/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ edition = "2018"
bolos-common = { version = "0.1", path = "../bolos-common" }
bolos-sys = { version = "0.1", path = "../bolos-sys" }
zemu-sys = { version = "0.1", path = "../zemu" }

ed25519-dalek = { version = "2.1.1", default-features = false }
cfg-if = "1.0.0"
no-std-compat = { version = "0.4" }

Expand Down
19 changes: 19 additions & 0 deletions bolos-impl/src/crypto/ecfp256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ impl AsRef<[u8]> for PublicKey {
}
}

pub fn public_from_bytes_ed25519(
bytes: &[u8; 32],
out: &mut MaybeUninit<PublicKey>,
) -> Result<(), Error> {
use ed25519_dalek::{SigningKey, VerifyingKey};

// Initialize the PublicKey struct with the appropriate data
unsafe {
let out_ptr = out.as_mut_ptr();
(*out_ptr).0.W[0] = 0x02; // Add prefix for compressed format
(*out_ptr).0.W[1..33]
.copy_from_slice(&SigningKey::from_bytes(bytes).verifying_key().to_bytes());
(*out_ptr).0.W_len = 33; // Length includes the prefix byte
(*out_ptr).0.curve = Curve::Ed25519 as u32;
}

Ok(())
}

pub struct SecretKey<const B: usize> {
mode: Mode,
curve: Curve,
Expand Down
23 changes: 6 additions & 17 deletions bolos-mock/src/crypto/ecfp256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,7 @@ impl<const B: usize> SecretKey<B> {
rand_chacha7::ChaCha8Rng::from_seed(seed)
}

pub fn new(
_: Mode,
curve: Curve,
path: BIP32Path<B>,
ed25519_secret_key_bytes: Option<[u8; 32]>,
) -> Self {
pub fn new(_: Mode, curve: Curve, path: BIP32Path<B>) -> Self {
let bytes = match curve {
Curve::Secp256K1 => {
let secret = k256::ecdsa::SigningKey::random(&mut Self::rng8(path));
Expand All @@ -132,17 +127,11 @@ impl<const B: usize> SecretKey<B> {
*secret.to_bytes().as_ref()
}
Curve::Ed25519 => {
if let Some(bytes) = ed25519_secret_key_bytes {
let secret = ed25519_dalek::SigningKey::from_bytes(&bytes);
secret.to_bytes()
} else {
// Generate random bytes using the path if no bytes provided
let mut bytes = [0u8; 32];
let mut rng = Self::rng8(path);
use rand_chacha8::rand_core::RngCore;
rng.fill_bytes(&mut bytes);
bytes
}
let mut bytes = [0u8; 32];
let mut rng = Self::rng8(path);
use rand_chacha8::rand_core::RngCore;
rng.fill_bytes(&mut bytes);
bytes
}
Curve::Stark256 => {
panic!("invalid curve passed to ecfp256 new")
Expand Down
Loading