tc_modular
Modular arithmetic for cryptography over the integers of
tc_bigint: the Mod* operations, and
Montgomery parameters and forms for an odd modulus. no_std, no unsafe,
Rust 1.85 or later.
Types
NonZero<T>,Odd<T>— a value checked once to be non-zero, or odd, as a modulus must be.FixedMontyParams<N>,PaddedMontyParams(alloc),BigMontyParams(alloc) — what Montgomery arithmetic modulo an odd modulus works out once.FixedMontyForm<N>,PaddedMontyForm(alloc),BigMontyForm(alloc) — a value kept asx · R mod m, with the operators,square,double,powandinvert.
Traits
ModAdd,ModSub,ModMul,ModPow,ModInverse— onFixedBigUint<N>,PaddedBigUintandBigUint, over aNonZeromodulus of any parity.
Features
alloc(off by default) — the padded and big types, and the traits on them.
Usage
use ;
use ;
type U256 = 256 / BITS as usize }>;
let p = U256from; // 2^127 - 1, a prime
let params = new;
let three = new;
assert_eq!;
Benchmarks of the three kinds are in BENCHES.md.
Security
Over the fixed-width and padded integers everything is constant time, except
for two things that show: the parity of the modulus, which picks the path of
ModPow and ModInverse, and whether an inverse exists. Over BigUint,
going in and out of a form is variable time, for public values only. Working
values are wiped; the values handed back are the caller's to wipe. This is a
learning port with no independent security audit.
License
Licensed under either the MIT license or the Apache License, Version 2.0, at your option.