pub struct ElGamalSecretKey(/* private fields */);
Expand description
Secret key for the ElGamal encryption scheme.
Instances of ElGamal secret key are zeroized on drop.
Implementations§
Source§impl ElGamalSecretKey
impl ElGamalSecretKey
Sourcepub fn new_from_signer(
signer: &dyn Signer,
public_seed: &[u8],
) -> Result<Self, Box<dyn Error>>
pub fn new_from_signer( signer: &dyn Signer, public_seed: &[u8], ) -> Result<Self, Box<dyn Error>>
Deterministically derives an ElGamal secret key from a Solana signer and a public seed.
See ElGamalKeypair::new_from_signer
for more context on the key derivation.
Sourcepub fn seed_from_signer(
signer: &dyn Signer,
public_seed: &[u8],
) -> Result<Vec<u8>, SignerError>
pub fn seed_from_signer( signer: &dyn Signer, public_seed: &[u8], ) -> Result<Vec<u8>, SignerError>
Derive a seed from a Solana signer used to generate an ElGamal secret key.
The seed is derived as the hash of the signature of a public seed.
Sourcepub fn new_rand() -> Self
pub fn new_rand() -> Self
Randomly samples an ElGamal secret key.
This function is randomized. It internally samples a scalar element using OsRng
.
Sourcepub fn from_seed(seed: &[u8]) -> Result<Self, ElGamalError>
pub fn from_seed(seed: &[u8]) -> Result<Self, ElGamalError>
Derive an ElGamal secret key from an entropy seed.
pub fn get_scalar(&self) -> &Scalar
Sourcepub fn decrypt(&self, ciphertext: &ElGamalCiphertext) -> DiscreteLog
pub fn decrypt(&self, ciphertext: &ElGamalCiphertext) -> DiscreteLog
Decrypts a ciphertext using the ElGamal secret key.
The output of this function is of type DiscreteLog
. To recover, the originally encrypted
message, use DiscreteLog::decode
.
Sourcepub fn decrypt_u32(&self, ciphertext: &ElGamalCiphertext) -> Option<u64>
pub fn decrypt_u32(&self, ciphertext: &ElGamalCiphertext) -> Option<u64>
Decrypts a ciphertext using the ElGamal secret key interpretting the message as type u32
.
pub fn as_bytes(&self) -> &[u8; 32]
pub fn to_bytes(&self) -> [u8; 32]
into()
insteadpub fn from_bytes(bytes: &[u8]) -> Option<ElGamalSecretKey>
try_from()
insteadTrait Implementations§
Source§impl Clone for ElGamalSecretKey
impl Clone for ElGamalSecretKey
Source§fn clone(&self) -> ElGamalSecretKey
fn clone(&self) -> ElGamalSecretKey
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl ConstantTimeEq for ElGamalSecretKey
impl ConstantTimeEq for ElGamalSecretKey
Source§impl Debug for ElGamalSecretKey
impl Debug for ElGamalSecretKey
Source§impl<'de> Deserialize<'de> for ElGamalSecretKey
impl<'de> Deserialize<'de> for ElGamalSecretKey
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl EncodableKey for ElGamalSecretKey
impl EncodableKey for ElGamalSecretKey
fn read<R: Read>(reader: &mut R) -> Result<Self, Box<dyn Error>>
fn write<W: Write>(&self, writer: &mut W) -> Result<String, Box<dyn Error>>
fn read_from_file<F>(path: F) -> Result<Self, Box<dyn Error>>
fn write_to_file<F>(&self, outfile: F) -> Result<String, Box<dyn Error>>
Source§impl From<&ElGamalSecretKey> for [u8; 32]
impl From<&ElGamalSecretKey> for [u8; 32]
Source§fn from(secret_key: &ElGamalSecretKey) -> Self
fn from(secret_key: &ElGamalSecretKey) -> Self
Source§impl From<ElGamalSecretKey> for [u8; 32]
impl From<ElGamalSecretKey> for [u8; 32]
Source§fn from(secret_key: ElGamalSecretKey) -> Self
fn from(secret_key: ElGamalSecretKey) -> Self
Source§impl From<Scalar> for ElGamalSecretKey
impl From<Scalar> for ElGamalSecretKey
Source§fn from(scalar: Scalar) -> ElGamalSecretKey
fn from(scalar: Scalar) -> ElGamalSecretKey
Source§impl PartialEq for ElGamalSecretKey
impl PartialEq for ElGamalSecretKey
Source§impl SeedDerivable for ElGamalSecretKey
impl SeedDerivable for ElGamalSecretKey
fn from_seed(seed: &[u8]) -> Result<Self, Box<dyn Error>>
fn from_seed_and_derivation_path( _seed: &[u8], _derivation_path: Option<DerivationPath>, ) -> Result<Self, Box<dyn Error>>
fn from_seed_phrase_and_passphrase( seed_phrase: &str, passphrase: &str, ) -> Result<Self, Box<dyn Error>>
Source§impl Serialize for ElGamalSecretKey
impl Serialize for ElGamalSecretKey
Source§impl TryFrom<&[u8]> for ElGamalSecretKey
impl TryFrom<&[u8]> for ElGamalSecretKey
Source§impl Zeroize for ElGamalSecretKey
impl Zeroize for ElGamalSecretKey
impl Eq for ElGamalSecretKey
Auto Trait Implementations§
impl Freeze for ElGamalSecretKey
impl RefUnwindSafe for ElGamalSecretKey
impl Send for ElGamalSecretKey
impl Sync for ElGamalSecretKey
impl Unpin for ElGamalSecretKey
impl UnwindSafe for ElGamalSecretKey
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more