merge
This commit is contained in:
parent
ee6a13ef6f
commit
9fdadb503d
|
@ -12,6 +12,7 @@ use {
|
||||||
scalar::Scalar,
|
scalar::Scalar,
|
||||||
},
|
},
|
||||||
ed25519_dalek::SecretKey as SigningKey,
|
ed25519_dalek::SecretKey as SigningKey,
|
||||||
|
solana_sdk::pubkey::Pubkey,
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
std::collections::HashMap,
|
std::collections::HashMap,
|
||||||
std::convert::TryInto,
|
std::convert::TryInto,
|
||||||
|
@ -56,14 +57,6 @@ impl ElGamal {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
|
||||||
#[allow(non_snake_case)]
|
|
||||||
pub fn from_signing_key(signing_key: &SigningKey, label: &'static [u8]) -> Self {
|
|
||||||
let secret = ElGamalSecretKey::new(signing_key, label);
|
|
||||||
let public = ElGamalPubkey::new(&secret);
|
|
||||||
Self { secret, public }
|
|
||||||
}
|
|
||||||
|
|
||||||
/// On input a public key and a message to be encrypted, the function
|
/// On input a public key and a message to be encrypted, the function
|
||||||
/// returns an ElGamal ciphertext of the message under the public key.
|
/// returns an ElGamal ciphertext of the message under the public key.
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
|
@ -139,6 +132,21 @@ pub struct ElGamalKeypair {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ElGamalKeypair {
|
impl ElGamalKeypair {
|
||||||
|
/// Generates the public and secret keys for ElGamal encryption from Ed25519 signing key and an
|
||||||
|
/// address.
|
||||||
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
|
#[allow(non_snake_case)]
|
||||||
|
pub fn new(signing_key: &SigningKey, address: &Pubkey) -> Self {
|
||||||
|
let secret = ElGamalSecretKey::new(signing_key, address);
|
||||||
|
let public = ElGamalPubkey::new(&secret);
|
||||||
|
|
||||||
|
Self {
|
||||||
|
secret,
|
||||||
|
public,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// Generates the public and secret keys for ElGamal encryption.
|
/// Generates the public and secret keys for ElGamal encryption.
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
#[allow(clippy::new_ret_no_self)]
|
#[allow(clippy::new_ret_no_self)]
|
||||||
|
@ -288,8 +296,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: &SigningKey, label: &'static [u8]) -> Self {
|
pub fn new(signing_key: &SigningKey, address: &Pubkey) -> Self {
|
||||||
let hashable = [&signing_key.to_bytes(), label].concat();
|
let mut hashable = [0_u8; 64];
|
||||||
|
hashable[..32].copy_from_slice(&signing_key.to_bytes());
|
||||||
|
hashable[32..].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