2022-06-30 13:30:24 +00:00
|
|
|
use ff::PrimeFieldBits;
|
|
|
|
use group::Group;
|
2022-06-07 04:02:10 +00:00
|
|
|
|
2022-06-30 13:30:24 +00:00
|
|
|
use crate::{prep_bits, prep_tables};
|
2022-06-07 04:02:10 +00:00
|
|
|
|
2022-06-30 13:30:24 +00:00
|
|
|
pub(crate) fn straus<G: Group>(
|
|
|
|
pairs: &[(G::Scalar, G)],
|
|
|
|
window: u8
|
|
|
|
) -> G where G::Scalar: PrimeFieldBits {
|
|
|
|
let groupings = prep_bits(pairs, window);
|
|
|
|
let tables = prep_tables(pairs, window);
|
2022-06-07 04:02:10 +00:00
|
|
|
|
|
|
|
let mut res = G::identity();
|
2022-06-30 13:30:24 +00:00
|
|
|
for b in (0 .. groupings[0].len()).rev() {
|
|
|
|
for _ in 0 .. window {
|
2022-06-07 04:02:10 +00:00
|
|
|
res = res.double();
|
|
|
|
}
|
|
|
|
|
|
|
|
for s in 0 .. tables.len() {
|
2022-06-30 13:30:24 +00:00
|
|
|
res += tables[s][usize::from(groupings[s][b])];
|
2022-06-07 04:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
res
|
|
|
|
}
|
|
|
|
|
2022-06-30 13:30:24 +00:00
|
|
|
pub(crate) fn straus_vartime<G: Group>(
|
|
|
|
pairs: &[(G::Scalar, G)],
|
|
|
|
window: u8
|
|
|
|
) -> G where G::Scalar: PrimeFieldBits {
|
|
|
|
let groupings = prep_bits(pairs, window);
|
|
|
|
let tables = prep_tables(pairs, window);
|
2022-06-07 04:02:10 +00:00
|
|
|
|
|
|
|
let mut res = G::identity();
|
2022-06-30 13:30:24 +00:00
|
|
|
for b in (0 .. groupings[0].len()).rev() {
|
|
|
|
if b != (groupings[0].len() - 1) {
|
|
|
|
for _ in 0 .. window {
|
2022-06-07 04:02:10 +00:00
|
|
|
res = res.double();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for s in 0 .. tables.len() {
|
2022-06-30 13:30:24 +00:00
|
|
|
if groupings[s][b] != 0 {
|
|
|
|
res += tables[s][usize::from(groupings[s][b])];
|
2022-06-07 04:02:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
res
|
|
|
|
}
|