Struct elastic_elgamal::PublicKey
source · pub struct PublicKey<G: Group> { /* private fields */ }
Expand description
Implementations§
source§impl<G: Group> PublicKey<G>
impl<G: Group> PublicKey<G>
sourcepub fn encrypt<T, R: CryptoRng + RngCore>(
&self,
value: T,
rng: &mut R
) -> Ciphertext<G>
pub fn encrypt<T, R: CryptoRng + RngCore>( &self, value: T, rng: &mut R ) -> Ciphertext<G>
Encrypts a value for this key.
sourcepub fn encrypt_element<R: CryptoRng + RngCore>(
&self,
value: G::Element,
rng: &mut R
) -> Ciphertext<G>
pub fn encrypt_element<R: CryptoRng + RngCore>( &self, value: G::Element, rng: &mut R ) -> Ciphertext<G>
Encrypts a group element.
sourcepub fn encrypt_zero<R>(
&self,
rng: &mut R
) -> (Ciphertext<G>, LogEqualityProof<G>)
pub fn encrypt_zero<R>( &self, rng: &mut R ) -> (Ciphertext<G>, LogEqualityProof<G>)
Encrypts zero value and provides a zero-knowledge proof of encryption correctness.
sourcepub fn verify_zero(
&self,
ciphertext: Ciphertext<G>,
proof: &LogEqualityProof<G>
) -> Result<(), VerificationError>
pub fn verify_zero( &self, ciphertext: Ciphertext<G>, proof: &LogEqualityProof<G> ) -> Result<(), VerificationError>
Verifies that this is an encryption of a zero value.
§Errors
Returns an error if the proof
does not verify.
sourcepub fn encrypt_bool<R: CryptoRng + RngCore>(
&self,
value: bool,
rng: &mut R
) -> (Ciphertext<G>, RingProof<G>)
pub fn encrypt_bool<R: CryptoRng + RngCore>( &self, value: bool, rng: &mut R ) -> (Ciphertext<G>, RingProof<G>)
Encrypts a boolean value (0 or 1) and provides a zero-knowledge proof of encryption correctness.
§Examples
See Ciphertext
docs for an example of usage.
sourcepub fn verify_bool(
&self,
ciphertext: Ciphertext<G>,
proof: &RingProof<G>
) -> Result<(), VerificationError>
pub fn verify_bool( &self, ciphertext: Ciphertext<G>, proof: &RingProof<G> ) -> Result<(), VerificationError>
Verifies a proof of encryption correctness of a boolean value, which was presumably
obtained via Self::encrypt_bool()
.
§Errors
Returns an error if the proof
does not verify.
§Examples
See Ciphertext
docs for an example of usage.
sourcepub fn encrypt_range<R: CryptoRng + RngCore>(
&self,
range: &PreparedRange<G>,
value: u64,
rng: &mut R
) -> (Ciphertext<G>, RangeProof<G>)
pub fn encrypt_range<R: CryptoRng + RngCore>( &self, range: &PreparedRange<G>, value: u64, rng: &mut R ) -> (Ciphertext<G>, RangeProof<G>)
Encrypts value
and provides a zero-knowledge proof that it lies in the specified range
.
§Panics
Panics if value
is out of range
.
§Examples
See Ciphertext
docs for an example of usage.
sourcepub fn verify_range(
&self,
range: &PreparedRange<G>,
ciphertext: Ciphertext<G>,
proof: &RangeProof<G>
) -> Result<(), VerificationError>
pub fn verify_range( &self, range: &PreparedRange<G>, ciphertext: Ciphertext<G>, proof: &RangeProof<G> ) -> Result<(), VerificationError>
Verifies proof
that ciphertext
encrypts a value lying in range
.
The proof
should be created with a call to Self::encrypt_range()
with the same
PreparedRange
; otherwise, the proof will not verify.
§Errors
Returns an error if the proof
does not verify.
source§impl<G: Group> PublicKey<G>
impl<G: Group> PublicKey<G>
sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, PublicKeyConversionError>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, PublicKeyConversionError>
Deserializes a public key from bytes.
§Errors
Returns an error if bytes
has invalid byte size, does not represent a valid group element
or represents the group identity.
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Returns bytes representing the group element corresponding to this key.
sourcepub fn as_element(&self) -> G::Element
pub fn as_element(&self) -> G::Element
Returns the group element equivalent to this key.