pub struct Montgomery<T> { /* private fields */ }Expand description
Provides a method to perform Montgomery Reduction.
Montgomery::convert can convert an integer to a Montgomery representation, and Montgomery::reduce can restore a normal integer representation.
None of the other methods do the conversion internally.
use modutil::Montgomery;
const M: Montgomery<u8> = Montgomery::<u8>::new(17);
let a = M.convert(3);
assert_eq!(M.multiply(a, a), M.convert(9));
assert_eq!(M.pow(a, 3), M.convert(10));
assert_eq!(M.reduce(a), 3);Implementations§
Source§impl Montgomery<u8>
impl Montgomery<u8>
Sourcepub const fn reduce(&self, val: u8) -> u8
pub const fn reduce(&self, val: u8) -> u8
Convert Montgomery representation to a normal integer representation.
Sourcepub const fn multiply(&self, lhs: u8, rhs: u8) -> u8
pub const fn multiply(&self, lhs: u8, rhs: u8) -> u8
Multiply lhs and rhs.
lhs and rhs must be Montgomery representations.
Sourcepub const fn convert(&self, val: u8) -> u8
pub const fn convert(&self, val: u8) -> u8
Convert a normal integer representation to Montgomery representation.
To restore, you can use Montgomery::reduce.
§Examples
use modutil::Montgomery;
const M: Montgomery<u8> = Montgomery::<u8>::new(17);
assert_eq!(M.reduce(M.convert(3)), 3);Source§impl Montgomery<u16>
impl Montgomery<u16>
Sourcepub const fn reduce(&self, val: u16) -> u16
pub const fn reduce(&self, val: u16) -> u16
Convert Montgomery representation to a normal integer representation.
Sourcepub const fn multiply(&self, lhs: u16, rhs: u16) -> u16
pub const fn multiply(&self, lhs: u16, rhs: u16) -> u16
Multiply lhs and rhs.
lhs and rhs must be Montgomery representations.
Sourcepub const fn convert(&self, val: u16) -> u16
pub const fn convert(&self, val: u16) -> u16
Convert a normal integer representation to Montgomery representation.
To restore, you can use Montgomery::reduce.
§Examples
use modutil::Montgomery;
const M: Montgomery<u8> = Montgomery::<u8>::new(17);
assert_eq!(M.reduce(M.convert(3)), 3);Source§impl Montgomery<u32>
impl Montgomery<u32>
Sourcepub const fn reduce(&self, val: u32) -> u32
pub const fn reduce(&self, val: u32) -> u32
Convert Montgomery representation to a normal integer representation.
Sourcepub const fn multiply(&self, lhs: u32, rhs: u32) -> u32
pub const fn multiply(&self, lhs: u32, rhs: u32) -> u32
Multiply lhs and rhs.
lhs and rhs must be Montgomery representations.
Sourcepub const fn convert(&self, val: u32) -> u32
pub const fn convert(&self, val: u32) -> u32
Convert a normal integer representation to Montgomery representation.
To restore, you can use Montgomery::reduce.
§Examples
use modutil::Montgomery;
const M: Montgomery<u8> = Montgomery::<u8>::new(17);
assert_eq!(M.reduce(M.convert(3)), 3);Source§impl Montgomery<u64>
impl Montgomery<u64>
Sourcepub const fn reduce(&self, val: u64) -> u64
pub const fn reduce(&self, val: u64) -> u64
Convert Montgomery representation to a normal integer representation.
Sourcepub const fn multiply(&self, lhs: u64, rhs: u64) -> u64
pub const fn multiply(&self, lhs: u64, rhs: u64) -> u64
Multiply lhs and rhs.
lhs and rhs must be Montgomery representations.
Sourcepub const fn convert(&self, val: u64) -> u64
pub const fn convert(&self, val: u64) -> u64
Convert a normal integer representation to Montgomery representation.
To restore, you can use Montgomery::reduce.
§Examples
use modutil::Montgomery;
const M: Montgomery<u8> = Montgomery::<u8>::new(17);
assert_eq!(M.reduce(M.convert(3)), 3);Trait Implementations§
Source§impl<T: Clone> Clone for Montgomery<T>
impl<T: Clone> Clone for Montgomery<T>
Source§fn clone(&self) -> Montgomery<T>
fn clone(&self) -> Montgomery<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more