diff --git a/src/groups/mod.rs b/src/groups/mod.rs index 82d759d..ae2b307 100644 --- a/src/groups/mod.rs +++ b/src/groups/mod.rs @@ -7,6 +7,13 @@ use rand::Rng; #[cfg(feature = "rustc-serialize")] use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; +// This is the NAF version of ate_loop_count. Entries are all mod 4, so 3 = -1 +// n.b. ate_loop_count = 0x19d797039be763ba8 +// = 11001110101111001011100000011100110111110011101100011101110101000 +// (naf version) = 11010003030003010300300000100301003000030100030300100030030101000 +// We skip the first element (1) as we would need to skip over it in the main loop +const ATE_LOOP_COUNT_NAF : [u8; 64] = [1,0,1,0,0,0,3,0,3,0,0,0,3,0,1,0,3,0,0,3,0,0,0,0,0,1,0,0,3,0,1,0,0,3,0,0,0,0,3,0,1,0,0,0,3,0,3,0,0,1,0,0,0,3,0,0,3,0,1,0,1,0,0,0]; + pub trait GroupElement : Sized + Copy @@ -575,16 +582,6 @@ fn two_inv() -> Fq { ]) } -// This is the NAF version of ate_loop_count. Entries are all mod 4, so 3 = -1 -// n.b. ate_loop_count = 0x19d797039be763ba8 -// = 11001110101111001011100000011100110111110011101100011101110101000 -// (naf version) = 11010003030003010300300000100301003000030100030300100030030101000 -// We skip the first element (1) as we would need to skip over it in the main loop -#[inline] -fn ate_loop_count_naf() -> Vec { - vec![1,0,1,0,0,0,3,0,3,0,0,0,3,0,1,0,3,0,0,3,0,0,0,0,0,1,0,0,3,0,1,0,0,3,0,0,0,0,3,0,1,0,0,0,3,0,3,0,0,1,0,0,0,3,0,0,3,0,1,0,1,0,0,0] -} - #[inline] fn twist_mul_by_q_x() -> Fq2 { Fq2::new( @@ -640,14 +637,13 @@ impl G2Precomp { let mut idx = 0; - for i in ate_loop_count_naf() { - + for i in ATE_LOOP_COUNT_NAF.iter() { let c = &self.coeffs[idx]; idx += 1; f = f.squared() .mul_by_024(c.ell_0, c.ell_vw.scale(g1.y), c.ell_vv.scale(g1.x)); - if i != 0 { + if *i != 0 { let c = &self.coeffs[idx]; idx += 1; f = f.mul_by_024(c.ell_0, c.ell_vw.scale(g1.y), c.ell_vv.scale(g1.x)); @@ -670,15 +666,14 @@ fn miller_loop_batch(g2_precomputes: &Vec, g1_vec: &Vec { let mut coeffs = Vec::with_capacity(102); let q_neg = self.neg(); - for i in ate_loop_count_naf() { - + for i in ATE_LOOP_COUNT_NAF.iter() { coeffs.push(r.doubling_step_for_flipped_miller_loop()); - if i == 1 { + if *i == 1 { coeffs.push(r.mixed_addition_step_for_flipped_miller_loop(self)); } - if i == 3 { + if *i == 3 { coeffs.push(r.mixed_addition_step_for_flipped_miller_loop(&q_neg)); } }