Struct safe_zk_token_sdk::encryption::elgamal::ElGamalSecretKey
source · pub struct ElGamalSecretKey(_);
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(signer: &dyn Signer, address: &Pubkey) -> Result<Self, SignerError>
pub fn new(signer: &dyn Signer, address: &Pubkey) -> Result<Self, SignerError>
Deterministically derives an ElGamal keypair from an Ed25519 signing key and a Safecoin address.
See ElGamalKeypair::new
for more context on the key derivation.
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
.
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]
pub fn from_bytes(bytes: &[u8]) -> Option<ElGamalSecretKey>
Trait Implementations§
source§impl Clone for ElGamalSecretKey
impl Clone for ElGamalSecretKey
source§fn clone(&self) -> ElGamalSecretKey
fn clone(&self) -> ElGamalSecretKey
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
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>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Drop for ElGamalSecretKey
impl Drop for ElGamalSecretKey
source§impl From<Scalar> for ElGamalSecretKey
impl From<Scalar> for ElGamalSecretKey
source§fn from(scalar: Scalar) -> ElGamalSecretKey
fn from(scalar: Scalar) -> ElGamalSecretKey
Converts to this type from the input type.