Expand description
Modular math implemented with traits.
This crate provides modular arithmetic implemented not for
any particular type, but for any type that implements minimal
set of core::ops:: and num_traits:: traits.
All provided functions are simply free functions.
There are three verions of each: basic that has least amount
of constraints, but requires Copy to be implemented for the type.
constrained requires Clone.
strict requires neither, but has most other constaints to be able to
operate with references and Overflowing arithmetic.
Tested with builtin integers and num-bigint, crypto-bigint, bnum, ibig
and fixed-bigint crates. basic versions of functions
wont work with num-bigint and ibig as both require heap
allocation.
Enums§
- NPrime
Method - Methods for computing N’ in Montgomery parameter computation
Functions§
- basic_
compute_ montgomery_ params - Montgomery parameter computation (Basic) with default method Computes R, R^(-1) mod N, N’, and R bit length for Montgomery arithmetic using trial search Returns None if parameter computation fails
- basic_
compute_ montgomery_ params_ with_ method - Montgomery parameter computation (Basic) Computes R, R^(-1) mod N, N’, and R bit length for Montgomery arithmetic Returns None if parameter computation fails
- basic_
from_ montgomery - Convert from Montgomery form (Basic): (a * R) -> a mod N Uses Montgomery reduction algorithm
- basic_
mod_ add - Modular Addition (Basic)
- basic_
mod_ exp - Modular Exponentiation (Basic)
- basic_
mod_ inv - Modular Inverse (Basic)
- basic_
mod_ mul - Modular Multiplication (Basic)
- basic_
mod_ sub - Modular Subtraction (Basic)
- basic_
montgomery_ mod_ exp - Montgomery-based modular exponentiation (Basic): base^exponent mod modulus Uses Montgomery arithmetic for efficient repeated multiplication Returns None if Montgomery parameter computation fails
- basic_
montgomery_ mod_ mul - Complete Montgomery modular multiplication (Basic): A * B mod N Returns None if Montgomery parameter computation fails
- basic_
montgomery_ mul - Montgomery multiplication (Basic): (a * R) * (b * R) -> (a * b * R) mod N
- basic_
to_ montgomery - Convert to Montgomery form (Basic): a -> (a * R) mod N
- constrained_
compute_ montgomery_ params - Montgomery parameter computation (Constrained) with default method Computes R, R^(-1) mod N, N’, and R bit length for Montgomery arithmetic Returns None if parameter computation fails
- constrained_
compute_ montgomery_ params_ with_ method - Montgomery parameter computation (Constrained) Computes R, R^(-1) mod N, N’, and R bit length for Montgomery arithmetic Returns None if N’ computation fails or R^(-1) mod N cannot be found
- constrained_
from_ montgomery - Convert from Montgomery form (Constrained): (a * R) -> a mod N Uses Montgomery reduction algorithm
- constrained_
mod_ add - Modular Addition (Constrained)
- constrained_
mod_ exp - Modular Exponentiation (Constrained)
- constrained_
mod_ inv - Modular Inverse (Constrained)
- constrained_
mod_ mul - Modular Multiplication (Constrained)
- constrained_
mod_ sub - Modular Subtraction (Constrained)
- constrained_
montgomery_ mod_ exp - Montgomery-based modular exponentiation (Constrained): base^exponent mod modulus Uses Montgomery arithmetic for efficient repeated multiplication Returns None if Montgomery parameter computation fails
- constrained_
montgomery_ mod_ mul - Complete Montgomery modular multiplication (Constrained): A * B mod N Returns None if Montgomery parameter computation fails
- constrained_
montgomery_ mul - Montgomery multiplication (Constrained): (a * R) * (b * R) -> (a * b * R) mod N
- constrained_
to_ montgomery - Convert to Montgomery form (Constrained): a -> (a * R) mod N
- strict_
compute_ montgomery_ params - Montgomery parameter computation (Strict) Computes R, R^(-1) mod N, N’, and R bit length for Montgomery arithmetic Uses reference-based operations to minimize copying of large integers
- strict_
compute_ montgomery_ params_ with_ method - Montgomery parameter computation with method selection (Strict) Computes R, R^(-1) mod N, N’, and R bit length for Montgomery arithmetic using specified method Uses reference-based operations to minimize copying of large integers Returns None if parameter computation fails
- strict_
from_ montgomery - Convert from Montgomery form (Strict): (a * R) -> a mod N Uses Montgomery reduction algorithm with reference-based operations to minimize copying of large integers
- strict_
mod_ add - Modular Addition (Strict)
- strict_
mod_ exp - Modular Exponentiation (Strict)
- strict_
mod_ inv - Modular Inverse (Strict)
- strict_
mod_ mul - Modular Multiplication (Strict)
- strict_
mod_ sub - Modular Subtraction (Strict)
- strict_
montgomery_ mod_ exp - Montgomery-based modular exponentiation (Strict): base^exponent mod modulus Uses Montgomery arithmetic for efficient repeated multiplication with reference-based operations to minimize copying of large integers Returns None if Montgomery parameter computation fails
- strict_
montgomery_ mod_ mul - Complete Montgomery modular multiplication (Strict): A * B mod N Uses reference-based operations throughout to minimize copying of large integers Returns None if Montgomery parameter computation fails
- strict_
to_ montgomery - Convert to Montgomery form (Strict): a -> (a * R) mod N Uses reference-based operations to minimize copying of large integers