elastic_elgamal

Struct PublicKey

Source
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>

Source§

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>

Source§

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>

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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>,

Source§

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>,