Impl pow_vartime and sqrt on ed libs

This commit is contained in:
Luke Parker
2022-12-15 19:23:42 -05:00
parent 461504ccbf
commit b8db677d4c
4 changed files with 152 additions and 10 deletions

View File

@@ -113,8 +113,20 @@ macro_rules! field {
fn cube(&self) -> Self {
self.square() * self
}
fn pow_vartime<S: AsRef<[u64]>>(&self, _exp: S) -> Self {
unimplemented!()
fn pow_vartime<S: AsRef<[u64]>>(&self, exp: S) -> Self {
let mut sum = Self::one();
let mut accum = *self;
for (_, num) in exp.as_ref().iter().enumerate() {
let mut num = *num;
for _ in 0 .. 64 {
if (num & 1) == 1 {
sum *= accum;
}
num >>= 1;
accum *= accum;
}
}
sum
}
}