Fast Modular Arithmetic
High-performance word-size modular arithmetic using Montgomery and Plantard multiplication.
Overview
Naive modular multiplication typically requires widening the operands, followed by an expensive division. This crate avoids division by using:
- Montgomery multiplication
- Plantard multiplication
These techniques significantly improve performance, especially when the modulus is determined at runtime.
Features
- 🚀 Fast modular multiplication without division
- ⚡ Optimized 32-bit and 64-bit implementations
- 🔒 Supports any odd modulus
Example
use Modulus32;
let modulus = new;
// residue of 1025 modulo 1023
let two = modulus.residue;
assert_eq!;
assert_eq!;
See more examples.
Further reading
Fast modular multiplication algorithm
Fast remainder algorithm