Expand description
Modular arithmetic support.
This module provides support for various modular arithmetic operations, implemented in terms of Montgomery form.
Β§Constant moduli
The ConstMontyForm and ConstMontyParams types implement support for modular arithmetic
where the modulus is fixed at compile-time.
The const_monty_params! macro can be used to define Montgomery
parameters at compile-time from a modulus, whereas the const_monty_form!
macro can define a ConstMontyForm constant.
Β§Dynamic moduli chosen at runtime
The FixedMontyForm and FixedMontyParams types implement support for modular arithmetic where
the modulus can vary at runtime.
ModulesΒ§
- add π
- bingcd π
- This module implements (a constant variant of) the Optimized Extended Binary GCD algorithm, which is described by Pornin as Algorithm 2 in βOptimized Binary GCD for Modular Inversionβ. Ref: https://eprint.iacr.org/2020/972.pdf
- boxed_
monty_ πform - Implements heap-allocated
BoxedMontyForms, supporting modular arithmetic with a modulus set at runtime. - const_
monty_ πform - Implements
ConstMontyForms, supporting modular arithmetic with a constant modulus. - div_
by_ π2 - fixed_
monty_ πform - Implements
MontyForms, supporting modular arithmetic with a modulus set at runtime. - lincomb π
- monty_
params π - Modulus-specific Montgomery form parameters.
- mul π
- pow π
- prime_
params π - Parameter calculation for prime moduli.
- reduction π
- Modular reduction implementation.
- safegcd π
- Implementation of Bernstein-Yang modular inversion and GCD algorithm (a.k.a. safegcd) as described in: https://eprint.iacr.org/2019/266.
- sqrt π
- sub π
StructsΒ§
- Boxed
Monty Form - An integer in Montgomery form represented using heap-allocated limbs.
- Boxed
Monty Params - Parameters to efficiently go to/from the Montgomery form for an odd modulus whose size and value are both chosen at runtime.
- Const
Monty Form - An integer in Montgomery form modulo
MOD, represented usingLIMBSlimbs. The modulus is constant, so it cannot be set at runtime. - Fixed
Monty Form - An integer in Montgomery form represented using
LIMBSlimbs. The odd modulus is set at runtime. - Monty
Params - Parameters to efficiently go to/from the Montgomery form for an odd modulus provided at runtime.
- Prime
Params - Parameters for supporting efficient computations on integers in Montgomery form with a prime modulus.
TraitsΒ§
- Const
Monty Params - Trait representing a modulus and its associated constants for converting in and out of Montgomery form.
- Const
Prime Monty Params - Trait representing a prime modulus and its associated constants for converting in and out of Montgomery form.
- Retrieve
- A generalization for numbers kept in optimized representations (e.g. Montgomery) that can be converted back to the original form.
Type AliasesΒ§
- Fixed
Monty Params - Parameters to efficiently go to/from the Montgomery form for an odd modulus provided at runtime.