pub struct CryptoBigintElement<U: Limbs> {
a: U,
b: (Choice, U),
c: U::Wide,
discriminant_abs: U::Wide,
}Expand description
A constant-time primitive element of a class group, implemented via crypto-bigint.
This only supports discriminants delta such that $delta < 0, |delta| \cong 1 \mod 2$.
This is implemented in time variable to the discriminant yet constant to the a, b, c
coefficients. This prevents timing analysis from leaking the elements being composed. It is
only recommended for provers as it has a significant performance overhead compared to other
backends, which verifiers should take advantage of.
This implementation does not itself allocate and can be used with crypto_bigint::Uint to
achieve elements which are fixed size and live on the stack, albeit only with support for a
bounded subset of discriminants. Alternatively, crypto_bigint::BoxedUint may be used to
support all discriminants, at the cost of using the heap.
Fields§
§a: UThe a coefficient.
This may not be reduced but is bounded to less than the square root of the discriminant.
b: (Choice, U)The b coefficient.
This may not be reduced but is bounded to have an absolute value less than the square root of the discriminant.
c: U::WideThe c coefficient.
This may not be reduced but is bounded to be less than the discriminant.
discriminant_abs: U::WideThe absolute value of the negative discriminant for this form.
This is used to recalculate the c coefficient after composition.
Implementations§
Source§impl<U: Limbs> CryptoBigintElement<U>
impl<U: Limbs> CryptoBigintElement<U>
Sourcefn identity_from_discriminant(discriminant_abs: U::Wide) -> Self
fn identity_from_discriminant(discriminant_abs: U::Wide) -> Self
This is only valid for forms of negative odd discriminant.
Source§impl<U: Limbs> CryptoBigintElement<U>
impl<U: Limbs> CryptoBigintElement<U>
Trait Implementations§
Source§impl<U: Clone + Limbs> Clone for CryptoBigintElement<U>
impl<U: Clone + Limbs> Clone for CryptoBigintElement<U>
Source§fn clone(&self) -> CryptoBigintElement<U>
fn clone(&self) -> CryptoBigintElement<U>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<U: Limbs> Coefficients for CryptoBigintElement<U>
impl<U: Limbs> Coefficients for CryptoBigintElement<U>
Source§impl<U: Limbs> CtEq for CryptoBigintElement<U>
impl<U: Limbs> CtEq for CryptoBigintElement<U>
Source§impl<U: Limbs> CtSelect for CryptoBigintElement<U>
impl<U: Limbs> CtSelect for CryptoBigintElement<U>
Source§impl<U: Limbs> Element for CryptoBigintElement<U>
impl<U: Limbs> Element for CryptoBigintElement<U>
Source§fn identity(discriminant_abs: impl AsRef<[u8]>) -> Self
fn identity(discriminant_abs: impl AsRef<[u8]>) -> Self
This is only valid for forms of negative odd discriminant.
Source§fn is_identity(&self) -> Choice
fn is_identity(&self) -> Choice
This MAY return an incorrect result when the form doesn’t have an odd, negative discriminant.
Source§fn add(&self, other: &Self) -> Self
fn add(&self, other: &Self) -> Self
This is only correct for forms of the same discriminant where at least one form is primitive.
Source§fn sub(&self, other: Self) -> Self
fn sub(&self, other: Self) -> Self
This is only correct for forms of the same discriminant where at least one form is primitive.
Source§unsafe fn from_coefficients(
a: impl AsRef<[u8]>,
(b_positive, b_abs): (Choice, impl AsRef<[u8]>),
c: impl AsRef<[u8]>,
discriminant_abs: impl AsRef<[u8]>,
) -> Self
unsafe fn from_coefficients( a: impl AsRef<[u8]>, (b_positive, b_abs): (Choice, impl AsRef<[u8]>), c: impl AsRef<[u8]>, discriminant_abs: impl AsRef<[u8]>, ) -> Self
This function is only valid for primitive reduced positive definite binary quadratic forms of
negative odd discriminant where the discriminant fits within (2 * max_bits) - 2 bits.
This function MAY run in time variable to:
- the byte-length of the inputs
- the validity of the inputs
- the discriminant
This function MAY panic if asked to handle coefficients which exceed the capacity of the underlying container(s).
Source§fn uncompressed_encode(self) -> impl AsRef<[u8]>
fn uncompressed_encode(self) -> impl AsRef<[u8]>
This runs in time variable to the size of the discriminant and the size of the underlying container.
Source§fn uncompressed_decode(
buf: impl AsRef<[u8]>,
discriminant_abs: impl AsRef<[u8]>,
) -> CtOption<Self>
fn uncompressed_decode( buf: impl AsRef<[u8]>, discriminant_abs: impl AsRef<[u8]>, ) -> CtOption<Self>
This runs in time variable to the size of the discriminant and the size of the underlying
container. This MAY return None for discriminants which fit within the bounds but have
trailing zero bytes which cause the amount of encoded bits to exceed the bounds.
Source§fn compress(self, writer: impl Write) -> Result<()>
fn compress(self, writer: impl Write) -> Result<()>
std only.Source§impl<U: Limbs> ElementExt for CryptoBigintElement<U>
Available on crate feature alloc only.
impl<U: Limbs> ElementExt for CryptoBigintElement<U>
alloc only.Source§impl<U: Limbs> Eq for CryptoBigintElement<U>
impl<U: Limbs> Eq for CryptoBigintElement<U>
1.0.0 (const: unstable) · Source§#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
#[doc(hidden)]fn assert_receiver_is_total_eq(&self)
implementation detail of #[derive(Eq)]
Source§#[doc(hidden)]fn assert_fields_are_eq(&self)
#[doc(hidden)]fn assert_fields_are_eq(&self)
derive_eq_internals)Source§impl<U: Limbs> Neg for CryptoBigintElement<U>
impl<U: Limbs> Neg for CryptoBigintElement<U>
Source§impl<U: Limbs> PartialEq for CryptoBigintElement<U>
impl<U: Limbs> PartialEq for CryptoBigintElement<U>
Auto Trait Implementations§
impl<U> Freeze for CryptoBigintElement<U>
impl<U> RefUnwindSafe for CryptoBigintElement<U>
impl<U> Send for CryptoBigintElement<U>
impl<U> Sync for CryptoBigintElement<U>
impl<U> Unpin for CryptoBigintElement<U>
impl<U> UnsafeUnpin for CryptoBigintElement<U>
impl<U> UnwindSafe for CryptoBigintElement<U>
Blanket Implementations§
Source§impl<T> AssertZeroize for T
impl<T> AssertZeroize for T
fn zeroize_or_on_drop(&mut self)
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> SizedTypeProperties for T
impl<T> SizedTypeProperties for T
Source§#[doc(hidden)]const SIZE: usize = _
#[doc(hidden)]const SIZE: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGN: usize = _
#[doc(hidden)]const ALIGN: usize = _
sized_type_properties)Source§#[doc(hidden)]const ALIGNMENT: Alignment = _
#[doc(hidden)]const ALIGNMENT: Alignment = _
ptr_alignment_type)Source§#[doc(hidden)]const IS_ZST: bool = _
#[doc(hidden)]const IS_ZST: bool = _
sized_type_properties)Source§#[doc(hidden)]const LAYOUT: Layout = _
#[doc(hidden)]const LAYOUT: Layout = _
sized_type_properties)Source§#[doc(hidden)]const MAX_SLICE_LEN: usize = _
#[doc(hidden)]const MAX_SLICE_LEN: usize = _
sized_type_properties)[Self]. Read more