Be a little bit more careful about what items we do and don't include, start adding modular math into the system.
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -15,6 +15,10 @@ mod div;
|
||||
#[macro_use]
|
||||
mod formatter;
|
||||
#[macro_use]
|
||||
mod modexp;
|
||||
#[macro_use]
|
||||
mod modmul;
|
||||
#[macro_use]
|
||||
mod mul;
|
||||
#[macro_use]
|
||||
mod shifts;
|
||||
@@ -27,6 +31,7 @@ use self::cmp::compare;
|
||||
use self::codec::{Encoder,Decoder,raw_decoder};
|
||||
use self::div::{DivMod,get_number_size};
|
||||
use self::formatter::tochar;
|
||||
use self::modmul::ModMul;
|
||||
use self::mul::multiply;
|
||||
use self::shifts::{shiftl,shiftr};
|
||||
use self::sub::subtract;
|
||||
@@ -41,29 +46,21 @@ use std::ops::{Sub,SubAssign};
|
||||
#[cfg(test)]
|
||||
use quickcheck::{Arbitrary,Gen};
|
||||
|
||||
macro_rules! generate_number
|
||||
macro_rules! base_impls
|
||||
{
|
||||
($name: ident, $size: expr) => {
|
||||
generate_base!($name, $size);
|
||||
generate_base_conversions!($name);
|
||||
generate_codec!($name);
|
||||
generate_formatter!($name);
|
||||
|
||||
cmp_impls!($name);
|
||||
|
||||
subtraction_impls!($name, $size);
|
||||
shift_impls!($name, $size);
|
||||
};
|
||||
($name: ident, $size: expr, $plus1: ident, $times2: ident) => {
|
||||
generate_number!($name, $size);
|
||||
addition_impls!($name, $plus1);
|
||||
multiply_impls!($name, $times2);
|
||||
div_impls!($name, $times2);
|
||||
};
|
||||
($name: ident, $size: expr, $plus1: ident, $times2: ident, $big: ident, $bar: ident) => {
|
||||
generate_number!($name, $size, $plus1, $times2);
|
||||
barrett_impl!($bar, $name, $plus1, $times2, $big);
|
||||
}
|
||||
}
|
||||
|
||||
include!("invoc.rs");
|
||||
macro_rules! modsq_impls
|
||||
{
|
||||
($name: ident) => {
|
||||
}
|
||||
}
|
||||
|
||||
include!("invoc.rs");
|
||||
|
||||
39
src/unsigned/modexp.rs
Normal file
39
src/unsigned/modexp.rs
Normal file
@@ -0,0 +1,39 @@
|
||||
pub trait ModExp<T> {
|
||||
fn modexp(&self, e: &Self, m: &T) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! modexp_impls {
|
||||
($name: ident) => {
|
||||
// impl ModExp<$name> for $name {
|
||||
// fn modexp(&self, e: &$name, m: &$name) -> $name {
|
||||
// // S <- g
|
||||
// let mut s = self.clone();
|
||||
// // A <- 1
|
||||
// let mut a = $name::from(1u64);
|
||||
// // We do a quick skim through and find the highest index that
|
||||
// // actually has a value in it.
|
||||
// let mut e = ine.clone();
|
||||
// // While e != 0 do the following:
|
||||
// while e.values.iter().any(|x| *x != 0) {
|
||||
// // If e is odd then A <- A * S
|
||||
// if e.values[0] & 1 != 0 {
|
||||
// a.modmul(&s, m);
|
||||
// }
|
||||
// // e <- floor(e / 2)
|
||||
// let mut carry = 0;
|
||||
// e.values.iter_mut().rev().for_each(|x| {
|
||||
// let new_carry = *x & 1;
|
||||
// *x = (*x >> 1) | (carry << 63);
|
||||
// carry = new_carry;
|
||||
// });
|
||||
// // If e != 0 then S <- S * S
|
||||
// s.modsq(m);
|
||||
// }
|
||||
// // Return A
|
||||
// a
|
||||
// }
|
||||
// }
|
||||
};
|
||||
($name: ident, $barrett: ident) => {
|
||||
};
|
||||
}
|
||||
16
src/unsigned/modmul.rs
Normal file
16
src/unsigned/modmul.rs
Normal file
@@ -0,0 +1,16 @@
|
||||
pub trait ModMul<T> {
|
||||
fn modmul(&self, x: &Self, m: &T) -> Self;
|
||||
}
|
||||
|
||||
macro_rules! modmul_impls {
|
||||
($name: ident, $dbl: ident) => {
|
||||
impl ModMul<$name> for $name {
|
||||
fn modmul(&self, x: &$name, m: &$name) -> $name {
|
||||
let mulres = (self as &$name) * x;
|
||||
let bigm = $dbl::from(m);
|
||||
let (_, bigres) = mulres.divmod(&bigm);
|
||||
$name::from(bigres)
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user