derive ElGamal keypair from the secret component of keypair
This commit is contained in:
@ -22,7 +22,6 @@ bincode = "1"
|
|||||||
byteorder = "1"
|
byteorder = "1"
|
||||||
cipher = "0.3"
|
cipher = "0.3"
|
||||||
curve25519-dalek = { version = "3.2.0", features = ["serde"]}
|
curve25519-dalek = { version = "3.2.0", features = ["serde"]}
|
||||||
ed25519-dalek = "=1.0.1"
|
|
||||||
getrandom = { version = "0.1", features = ["dummy"] }
|
getrandom = { version = "0.1", features = ["dummy"] }
|
||||||
merlin = "2"
|
merlin = "2"
|
||||||
rand = "0.7"
|
rand = "0.7"
|
||||||
|
@ -6,8 +6,8 @@ use {
|
|||||||
};
|
};
|
||||||
use {
|
use {
|
||||||
arrayref::{array_ref, array_refs},
|
arrayref::{array_ref, array_refs},
|
||||||
ed25519_dalek::SecretKey as SigningKey,
|
|
||||||
solana_sdk::pubkey::Pubkey,
|
solana_sdk::pubkey::Pubkey,
|
||||||
|
solana_sdk::signature::Keypair as SigningKeypair,
|
||||||
std::convert::TryInto,
|
std::convert::TryInto,
|
||||||
zeroize::Zeroize,
|
zeroize::Zeroize,
|
||||||
};
|
};
|
||||||
@ -54,9 +54,9 @@ impl Aes {
|
|||||||
#[derive(Debug, Zeroize)]
|
#[derive(Debug, Zeroize)]
|
||||||
pub struct AesKey([u8; 16]);
|
pub struct AesKey([u8; 16]);
|
||||||
impl AesKey {
|
impl AesKey {
|
||||||
pub fn new(signing_key: &SigningKey, address: &Pubkey) -> Self {
|
pub fn new(signing_keypair: &SigningKeypair, address: &Pubkey) -> Self {
|
||||||
let mut hashable = [0_u8; 64];
|
let mut hashable = [0_u8; 64];
|
||||||
hashable[..32].copy_from_slice(&signing_key.to_bytes());
|
hashable[..32].copy_from_slice(&signing_keypair.secret().to_bytes());
|
||||||
hashable[32..].copy_from_slice(&address.to_bytes());
|
hashable[32..].copy_from_slice(&address.to_bytes());
|
||||||
|
|
||||||
let mut hasher = Sha3_256::new();
|
let mut hasher = Sha3_256::new();
|
||||||
|
@ -11,9 +11,9 @@ use {
|
|||||||
ristretto::{CompressedRistretto, RistrettoPoint},
|
ristretto::{CompressedRistretto, RistrettoPoint},
|
||||||
scalar::Scalar,
|
scalar::Scalar,
|
||||||
},
|
},
|
||||||
ed25519_dalek::Keypair as SigningKeyPair,
|
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
solana_sdk::pubkey::Pubkey,
|
solana_sdk::pubkey::Pubkey,
|
||||||
|
solana_sdk::signature::Keypair as SigningKeypair,
|
||||||
std::collections::HashMap,
|
std::collections::HashMap,
|
||||||
std::convert::TryInto,
|
std::convert::TryInto,
|
||||||
subtle::{Choice, ConstantTimeEq},
|
subtle::{Choice, ConstantTimeEq},
|
||||||
@ -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_pair: &SigningKeyPair, address: &Pubkey) -> Self {
|
pub fn new(signing_keypair: &SigningKeypair, address: &Pubkey) -> Self {
|
||||||
let secret = ElGamalSecretKey::new(signing_key_pair, address);
|
let secret = ElGamalSecretKey::new(signing_keypair, address);
|
||||||
let public = ElGamalPubkey::new(&secret);
|
let public = ElGamalPubkey::new(&secret);
|
||||||
|
|
||||||
Self { public, secret }
|
Self { public, secret }
|
||||||
@ -292,11 +292,10 @@ 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_pair: &SigningKeyPair, address: &Pubkey) -> Self {
|
pub fn new(signing_keypair: &SigningKeypair, address: &Pubkey) -> Self {
|
||||||
let mut hashable = [0_u8; 96];
|
let mut hashable = [0_u8; 64];
|
||||||
hashable[..32].copy_from_slice(&signing_key_pair.secret.to_bytes());
|
hashable[..32].copy_from_slice(&signing_keypair.secret().to_bytes());
|
||||||
hashable[32..64].copy_from_slice(&signing_key_pair.public.to_bytes());
|
hashable[32..].copy_from_slice(&address.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))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user