pub struct PublicKey<G: Group> { /* private fields */ }
Expand description

Public key for ElGamal encryption and related protocols.

§Implementation details

We store both the original bytes (which are used in zero-knowledge proofs) and its decompression into a Group element. This increases the memory footprint, but speeds up generating / verifying proofs.

Implementations§

source§

impl<G: Group> PublicKey<G>

source

pub fn encrypt<T, R: CryptoRng + RngCore>( &self, value: T, rng: &mut R ) -> Ciphertext<G>
where G::Scalar: From<T>,

Encrypts a value for this key.

source

pub fn encrypt_element<R: CryptoRng + RngCore>( &self, value: G::Element, rng: &mut R ) -> Ciphertext<G>

Encrypts a group element.

source

pub fn encrypt_zero<R>( &self, rng: &mut R ) -> (Ciphertext<G>, LogEqualityProof<G>)
where R: CryptoRng + RngCore,

Encrypts zero value and provides a zero-knowledge proof of encryption correctness.

source

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.

source

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.

source

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.

source

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.

source

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>

source

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.

source

pub fn as_bytes(&self) -> &[u8]

Returns bytes representing the group element corresponding to this key.

source

pub fn as_element(&self) -> G::Element

Returns the group element equivalent to this key.

Trait Implementations§

source§

impl<G: Group> Add for PublicKey<G>

§

type Output = PublicKey<G>

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self

Performs the + operation. Read more
source§

impl<G: Group> Clone for PublicKey<G>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<G: Group> Debug for PublicKey<G>

source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, G: Group> Deserialize<'de> for PublicKey<G>

source§

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<G: Group> From<&SecretKey<G>> for PublicKey<G>

source§

fn from(secret_key: &SecretKey<G>) -> Self

Converts to this type from the input type.
source§

impl<G: Group> Mul<&<G as ScalarOps>::Scalar> for PublicKey<G>

§

type Output = PublicKey<G>

The resulting type after applying the * operator.
source§

fn mul(self, k: &G::Scalar) -> Self

Performs the * operation. Read more
source§

impl<G: Group> Mul<u64> for PublicKey<G>

§

type Output = PublicKey<G>

The resulting type after applying the * operator.
source§

fn mul(self, k: u64) -> Self

Performs the * operation. Read more
source§

impl<G> PartialEq for PublicKey<G>
where G: Group,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<G: Group> Serialize for PublicKey<G>

source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<G> Freeze for PublicKey<G>
where <G as ElementOps>::Element: Freeze,

§

impl<G> RefUnwindSafe for PublicKey<G>

§

impl<G> Send for PublicKey<G>
where <G as ElementOps>::Element: Send,

§

impl<G> Sync for PublicKey<G>
where <G as ElementOps>::Element: Sync,

§

impl<G> Unpin for PublicKey<G>
where <G as ElementOps>::Element: Unpin,

§

impl<G> UnwindSafe for PublicKey<G>
where <G as ElementOps>::Element: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,