-
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
Finite base field and elements #12
Conversation
The updated version has a few big changes from the previous iteration. Namely, crypto_bigint generates the struct that contains the modular information via macro, so in order to use this, you either create a local wrap and then assign all of the needed traits which was very verbose, or do what I did and roll our field generation into a macro itself, which was one of our goals anyhow. This now defines the The struct created by the macro is designed in the build ladder format, where There are, however, some issues created now by the usage of crypto_bigint.
|
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.
- Constant time equality in partial eq
- Documentation and commentary
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.
@trbritt please fix clippy, fmt, docs and satisfy the CI pipeline before merge incl test cases passing or marked out not expecting to pass yet. Otherwise looks good.
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.
Nice.
This makes a few upgrades, namely not rolling our own multiprecision arithmetic. It now uses crypto_bigint and its build in functionality for these things.
This required a change to the structure of FinitePrimeField because of the internal layout of crypto_bigint. The biggest issue that I've come across is that is defines a modulus struct on the fly via a macro:
so in order to use it for our case, I build the necessary structs in house. However, this requires the trait bound
pub trait ModulusTrait: std::cmp::Eq + std::default::Default + std::fmt::Debug + std::marker::Copy + Send + Sync + 'static
to be flying around, which is verbose, and not ideal.The field struct now incorporates the modulus information as a generic T, which allows it to port with it all of the associated constants (R, R2, INV, etc) determined by the Montgomery backend.
Unclear how to improve right now. Too zonked.
All operations are constant time.
Further, there are only two tests that currently fail, both of which have to do with the multiplication wrapping around the modulus. I don't know if this is an issue with the reference values in the tests, or the definition of the modulus, or what. Everything else passes no problem, so this is a todo.
One more todo, is to fix the Deref implementation for the FinitePrimeField, as it currently uses unsafe code.