Skip to main content

CyclicModule

Trait CyclicModule 

Source
pub trait CyclicModule: AbelianGroup + Sized {
    type Scalar: AlgebraField;

    // Required methods
    fn generator() -> Self;
    fn generator_mul(scalar: &Self::Scalar) -> Self;
    fn random_scalar_with_rng(rng: &mut impl RngCore) -> Self::Scalar;

    // Provided method
    fn random_scalar() -> Self::Scalar { ... }
}
Expand description

Algebraic carrier with a distinguished generator and non-zero scalar sampler.

This is not a replacement group hierarchy; it is the extra capability needed by cryptographic algorithms such as ElGamal after the carrier already implements AbelianGroup and Module. The implementation obligation is that generator_mul(s) equals generator() * s and that sampled scalars are non-zero field elements.

Module<Self::Scalar> stays as an explicit consumer bound instead of a supertrait here. CyclicModule introduces the associated scalar type, while Module proves the right scalar action for arbitrary elements; consumers that multiply elements by scalars should request both CyclicModule and Module<Element::Scalar>. This keeps the generator and sampling capability separate from the module-action proof while still requiring generator_mul(s) to be observationally equal to generator() * s.

Non-zero scalar sampling also appears in CurveScalarField intentionally. Curve adapters provide the native scalar-field sampler; CyclicModule exposes the same cryptographic capability through the element carrier so algorithms do not need to know the curve marker type.

Required Associated Types§

Source

type Scalar: AlgebraField

Scalar field for the module action.

Required Methods§

Source

fn generator() -> Self

Distinguished generator for the cyclic subgroup used by the algorithm.

Source

fn generator_mul(scalar: &Self::Scalar) -> Self

Multiply the distinguished generator by a scalar.

Source

fn random_scalar_with_rng(rng: &mut impl RngCore) -> Self::Scalar

Generate a fresh non-zero random scalar from an explicit RNG.

Provided Methods§

Source

fn random_scalar() -> Self::Scalar

Generate a fresh non-zero random scalar from the default thread-local RNG.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§