derive ElGamal keypair from Ed25519 keypair instead of just the signing key
This commit is contained in:
parent
defdf8da72
commit
89ddae29ef
|
@ -11,7 +11,7 @@ use {
|
||||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||||
scalar::Scalar,
|
scalar::Scalar,
|
||||||
},
|
},
|
||||||
ed25519_dalek::SecretKey as SigningKey,
|
ed25519_dalek::Keypair as SigningKeyPair,
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
solana_sdk::pubkey::Pubkey,
|
solana_sdk::pubkey::Pubkey,
|
||||||
std::collections::HashMap,
|
std::collections::HashMap,
|
||||||
|
@ -136,8 +136,8 @@ impl ElGamalKeypair {
|
||||||
/// address.
|
/// address.
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub fn new(signing_key: &SigningKey, address: &Pubkey) -> Self {
|
pub fn new(signing_key_pair: &SigningKeyPair, address: &Pubkey) -> Self {
|
||||||
let secret = ElGamalSecretKey::new(signing_key, address);
|
let secret = ElGamalSecretKey::new(signing_key_pair, address);
|
||||||
let public = ElGamalPubkey::new(&secret);
|
let public = ElGamalPubkey::new(&secret);
|
||||||
|
|
||||||
Self { public, secret }
|
Self { public, secret }
|
||||||
|
@ -292,10 +292,11 @@ impl fmt::Display for ElGamalPubkey {
|
||||||
#[zeroize(drop)]
|
#[zeroize(drop)]
|
||||||
pub struct ElGamalSecretKey(Scalar);
|
pub struct ElGamalSecretKey(Scalar);
|
||||||
impl ElGamalSecretKey {
|
impl ElGamalSecretKey {
|
||||||
pub fn new(signing_key: &SigningKey, address: &Pubkey) -> Self {
|
pub fn new(signing_key_pair: &SigningKeyPair, address: &Pubkey) -> Self {
|
||||||
let mut hashable = [0_u8; 64];
|
let mut hashable = [0_u8; 96];
|
||||||
hashable[..32].copy_from_slice(&signing_key.to_bytes());
|
hashable[..32].copy_from_slice(&signing_key_pair.secret.to_bytes());
|
||||||
hashable[32..].copy_from_slice(&address.to_bytes());
|
hashable[32..64].copy_from_slice(&signing_key_pair.public.to_bytes());
|
||||||
|
hashable[64..].copy_from_slice(&address.to_bytes());
|
||||||
ElGamalSecretKey(Scalar::hash_from_bytes::<Sha3_512>(&hashable))
|
ElGamalSecretKey(Scalar::hash_from_bytes::<Sha3_512>(&hashable))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue