elastic_elgamal::group

Struct Generic

Source
pub struct Generic<C>(/* private fields */);
Expand description

Generic Group implementation for elliptic curves defined in terms of the traits from the elliptic-curve crate.

§Assumptions

  • Arithmetic operations required to be constant-time as per ScalarOps and ElementOps contracts are indeed constant-time.

Trait Implementations§

Source§

impl<C> Clone for Generic<C>

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<C: Debug> Debug for Generic<C>

Source§

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

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

impl<C> ElementOps for Generic<C>
where C: CurveArithmetic, Scalar<C>: Zeroize, FieldBytesSize<C>: ModulusSize, ProjectivePoint<C>: ToEncodedPoint<C> + FromEncodedPoint<C>,

Source§

const ELEMENT_SIZE: usize = _

Byte size of a serialized Self::Element.
Source§

type Element = <C as CurveArithmetic>::ProjectivePoint

Element of the group. Arithmetic operations requested here (addition among elements and multiplication by a Scalar) must be constant-time.
Source§

fn identity() -> Self::Element

Returns the identity of the group (aka point at infinity for EC groups).
Source§

fn is_identity(element: &Self::Element) -> bool

Checks if the specified element is the identity.
Source§

fn generator() -> Self::Element

Returns the agreed-upon generator of the group.
Source§

fn serialize_element(element: &Self::Element, buffer: &mut [u8])

Serializes element into the provided buffer, which is guaranteed to have length Self::ELEMENT_SIZE.
Source§

fn deserialize_element(input: &[u8]) -> Option<Self::Element>

Deserializes an element from buffer, which is guaranteed to have length Self::ELEMENT_SIZE. This method returns None if the buffer does not correspond to a representation of a valid scalar.
Source§

impl<C> Group for Generic<C>
where C: CurveArithmetic + 'static, Scalar<C>: Zeroize, FieldBytesSize<C>: ModulusSize, ProjectivePoint<C>: ToEncodedPoint<C> + FromEncodedPoint<C>,

Source§

fn mul_generator(k: &Self::Scalar) -> Self::Element

Multiplies the provided scalar by ElementOps::generator(). This operation must be constant-time. Read more
Source§

fn vartime_mul_generator(k: &Self::Scalar) -> Self::Element

Multiplies the provided scalar by ElementOps::generator(). Unlike Self::mul_generator(), this operation does not need to be constant-time; thus, it may employ additional optimizations. Read more
Source§

fn multi_mul<'a, I, J>(scalars: I, elements: J) -> Self::Element
where I: IntoIterator<Item = &'a Self::Scalar>, J: IntoIterator<Item = Self::Element>,

Multiplies provided scalars by elements. This operation must be constant-time w.r.t. the given length of elements. Read more
Source§

fn vartime_double_mul_generator( k: &Self::Scalar, k_element: Self::Element, r: &Self::Scalar, ) -> Self::Element

Calculates k * k_element + r * G, where G is the group generator. This operation does not need to be constant-time. Read more
Source§

fn vartime_multi_mul<'a, I, J>(scalars: I, elements: J) -> Self::Element
where I: IntoIterator<Item = &'a Self::Scalar>, J: IntoIterator<Item = Self::Element>,

Multiplies provided scalars by elements. Unlike Self::multi_mul(), this operation does not need to be constant-time; thus, it may employ additional optimizations. Read more
Source§

impl<C> ScalarOps for Generic<C>
where C: CurveArithmetic, Scalar<C>: Zeroize,

Source§

const SCALAR_SIZE: usize = <FieldBytesSize<C> as Unsigned>::USIZE

Byte size of a serialized Self::Scalar.
Source§

type Scalar = <C as CurveArithmetic>::Scalar

Scalar type. As per Group contract, scalars must form a prime field. Arithmetic operations on scalars requested here must be constant-time.
Source§

fn generate_scalar<R: CryptoRng + RngCore>(rng: &mut R) -> Self::Scalar

Generates a random scalar based on the provided CSPRNG. This operation must be constant-time.
Source§

fn invert_scalar(scalar: Self::Scalar) -> Self::Scalar

Inverts the scalar, which is guaranteed to be non-zero. This operation does not need to be constant-time.
Source§

fn serialize_scalar(scalar: &Self::Scalar, buffer: &mut [u8])

Serializes the scalar into the provided buffer, which is guaranteed to have length Self::SCALAR_SIZE.
Source§

fn deserialize_scalar(buffer: &[u8]) -> Option<Self::Scalar>

Deserializes the scalar from buffer, which is guaranteed to have length Self::SCALAR_SIZE. This method returns None if the buffer does not correspond to a representation of a valid scalar.
Source§

fn scalar_from_random_bytes(source: RandomBytesProvider<'_>) -> Self::Scalar

Generates a scalar from a source of random bytes. This operation must be constant-time. The source is guaranteed to return any necessary number of bytes. Read more
Source§

fn invert_scalars(scalars: &mut [Self::Scalar])

Inverts scalars in a batch. This operation does not need to be constant-time. Read more
Source§

impl<C> Copy for Generic<C>

Auto Trait Implementations§

§

impl<C> Freeze for Generic<C>

§

impl<C> RefUnwindSafe for Generic<C>
where C: RefUnwindSafe,

§

impl<C> Send for Generic<C>
where C: Send,

§

impl<C> Sync for Generic<C>
where C: Sync,

§

impl<C> Unpin for Generic<C>
where C: Unpin,

§

impl<C> UnwindSafe for Generic<C>
where C: 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