Trait classgroup::ClassGroup
source · pub trait ClassGroup: Sized + Clone + for<'a> MulAssign<&'a Self> + for<'a> Mul<&'a Self> + PartialEq + Debug {
type BigNum: BigNum;
Show 16 methods
fn from_ab_discriminant(
a: Self::BigNum,
b: Self::BigNum,
discriminant: Self::BigNum
) -> Self;
fn from_bytes(bytearray: &[u8], discriminant: Self::BigNum) -> Self;
fn serialize(&self, buf: &mut [u8]) -> Result<(), usize>;
fn unsigned_deserialize_bignum(_: &[u8]) -> Self::BigNum;
fn reduce(&mut self);
fn normalize(&mut self);
fn size_in_bits(num: &Self::BigNum) -> usize;
fn discriminant(&self) -> &Self::BigNum;
fn inverse(&mut self);
fn pow(&mut self, exponent: Self::BigNum);
fn deserialize(buf: &[u8], discriminant: Self::BigNum) -> Self;
fn identity_for_discriminant(discriminant: Self::BigNum) -> Self { ... }
fn square(&mut self) { ... }
fn identity(&self) -> Self { ... }
fn generator_for_discriminant(discriminant: Self::BigNum) -> Self { ... }
fn repeated_square(&mut self, iterations: u64) { ... }
}
Required Associated Types§
Required Methods§
sourcefn from_ab_discriminant(
a: Self::BigNum,
b: Self::BigNum,
discriminant: Self::BigNum
) -> Self
fn from_ab_discriminant(
a: Self::BigNum,
b: Self::BigNum,
discriminant: Self::BigNum
) -> Self
Produces a Self
from a
, b
, and a discriminant.
sourcefn from_bytes(bytearray: &[u8], discriminant: Self::BigNum) -> Self
fn from_bytes(bytearray: &[u8], discriminant: Self::BigNum) -> Self
Unmarshals a Self
from a byte array and discriminant.
The byte array will be in the format of two big-endian byte sequences concatenated together.
sourcefn serialize(&self, buf: &mut [u8]) -> Result<(), usize>
fn serialize(&self, buf: &mut [u8]) -> Result<(), usize>
Serializes self
to a byte array. Returns Err(s)
if there
is not enough space in the buffer.
The data must be serialized in twos-complement, big-endian format.
sourcefn unsigned_deserialize_bignum(_: &[u8]) -> Self::BigNum
fn unsigned_deserialize_bignum(_: &[u8]) -> Self::BigNum
Deserializes a bignum from raw bytes. The bytes must be interpreted as a big-endian unsigned integer.
sourcefn size_in_bits(num: &Self::BigNum) -> usize
fn size_in_bits(num: &Self::BigNum) -> usize
The length of num
in bits
sourcefn discriminant(&self) -> &Self::BigNum
fn discriminant(&self) -> &Self::BigNum
Gets the discriminant of self
.
sourcefn deserialize(buf: &[u8], discriminant: Self::BigNum) -> Self
fn deserialize(buf: &[u8], discriminant: Self::BigNum) -> Self
Deserialization
Provided Methods§
sourcefn identity_for_discriminant(discriminant: Self::BigNum) -> Self
fn identity_for_discriminant(discriminant: Self::BigNum) -> Self
Computes the identity element of Self
for a given discriminant.
If the discriminant is not valid, the result is unspecified.
Panics
This may panic (but is not required to) if the discriminant is not valid. If this function does not panic, the results of future operations are unspecified: they will not invoke undefined behavior, but may panic, loop forever, or just compute garbage.
In debug builds, this will always panic if the discriminant is invalid.
sourcefn square(&mut self)
fn square(&mut self)
Squares self
, modifying it in-place.
A default implementation is provided, but implementations are suggested to override it for performance reasons.
sourcefn generator_for_discriminant(discriminant: Self::BigNum) -> Self
fn generator_for_discriminant(discriminant: Self::BigNum) -> Self
Generates a generator for the class group of Self
, given a
discriminant.
If the discriminant is not valid, the result is unspecified.
Relation to Self::identity_for_discriminant
This is not the same as Self::identity_for_discriminant
: the
identity element is never a generator for any group. This follows
from their definitions: the identity element, when multiplied by another
element, always gives that other element, whereas every element in the
group is some power of a generator.
Panics
This may panic (but is not required to) if the discriminant is not valid. If this function does not panic, the results of future operations are unspecified: they will not invoke undefined behavior, but may panic, loop forever, or just compute garbage.
If the global allocator panics on running out of memory, then this function may panic in the same situation, but it may also just abort the program instead.
In debug builds, this will always panic if the discriminant is invalid.
sourcefn repeated_square(&mut self, iterations: u64)
fn repeated_square(&mut self, iterations: u64)
Squares self
repeatedly in-place.
Implementors of this trait are encouraged to override this with a more efficient implementation, if one exists.