-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[wip] first pass at framing arithmetic #10
[wip] first pass at framing arithmetic #10
Conversation
src/finite_field.rs
Outdated
// TODO: implement bernstein yang inversion | ||
Self::zero_array() | ||
|
||
pub const fn greater_than(&self, a: &[u64; L], b:&[u64;L])-> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not truly constant time as different branches on the comparator may return at different times, we should instead always run through the whole loop and then return only afterwards.
src/finite_field.rs
Outdated
r_squared, | ||
n_prime, | ||
} | ||
correction: [0u64; L], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These values could be computed beforehand rather than having a mutation occur.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agreed, this was left over from before I moved arithmetic to _internal
s, will remedy
src/finite_field.rs
Outdated
// TODO (Implement Montgomery r squared) | ||
Self::zero_array() | ||
} | ||
let diff = Self::subtraction_correction(modulus); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be passed in to the function rather than recomputed.
src/finite_field.rs
Outdated
let n = modulus[0]; //need only least significant bits | ||
let mut n_prime = 1u64; | ||
let mut i = 0; | ||
while i < 64 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this number, because 64 bits?
src/finite_field.rs
Outdated
} | ||
|
||
pub const fn to_montgomery(&self, a: &[u64; L]) -> [u64; L] { | ||
// TODO (Implement to monty form) | ||
Self::zero_array() | ||
self.montgomery_multiply(a, &self.r_squared) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some detail on why multiplying by r_squared gives us the monty form would be helpful.
src/finite_field.rs
Outdated
} | ||
|
||
pub const fn from_montgomery(&self, a: &[u64; L]) -> [u64; L] { | ||
// TODO (Implement from monty form) | ||
Self::zero_array() | ||
self.montgomery_multiply(a, &Self::one_array()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here on why multiplying by 1 (the identity, not an array filled with ones) gives us the normal form.
src/finite_field.rs
Outdated
@@ -198,110 +206,177 @@ impl<const L: usize, const D: usize> FinitePrimeField<L, D> { | |||
j += 1; | |||
} | |||
|
|||
result | |||
self.to_montgomery(&result) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why here do we convert to_montgomery? Should this not already be in monty form at the end of this, or has it been reduced?
src/finite_field.rs
Outdated
let mut negated = Self::zero_array(); | ||
let mut i = 0; | ||
while i < L { | ||
negated[i] = self.modulus[i].wrapping_sub(a[i]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking some carry about the modulus needs to happen here.
src/finite_field.rs
Outdated
} | ||
} | ||
/// The following performs the Bernstein-Yang inversion on a scalar. | ||
pub const fn bernstein_yang_invert(&self, a: &[u64; L]) -> [u64; L] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perfect use case for dimensionals 💯
* chore: bring in template * fmt
bc19bcb
into
tristan/war-529-deep-sylow-optimization
No description provided.