primefield: add FieldExt - #1838
Merged
Merged
Conversation
Also bounds `PrimeFieldExt` on it, adds it to the macro boilerplate, adds manual definitions where needed, and bounds the `FieldElement` type used by `primeorder::PrimeCurveParams` on it so it needs to impl it as well. This follows from RustCrypto/traits#1997 where we were discussing how we could better leverage the various lazy field implementations we had. In that thread I suggested we could avoid exposing separate field element types for reduced/unreduced operations and have a simpler abstraction for eagerly versus lazily reduced field elements if we supported various "fused" operations that are useful in dense field arithmetic, e.g. add-then-mul, mul-then-add. For example the RCB implementation in `primeorder` could migrate to using the "fused" operations which start out backed by default impls which call the individual arithmetic ops which, where applicable (mostly `k256` and `p521` for now) can be replaced by optimized implementations which can avoid unnecessary normalization/reductions when performing these sequences of operations. This adds a `FieldExt` with no methods despite the fact we already have a `PrimeFieldExt`. The idea is `FieldExt` is an extension trait for functionality that would otherwise go on `ff::Field`, and `PrimeFieldExt` is an extension trait for `ff::PrimeField`, which in this case due to how the `ff` crate factors the relevant operations happens to be dealing with encoding, whereas `FieldExt` can have the "fused" arithmetic ops as `ff::Field` otherwise deals with the low-level arithmetic operations. What's nice is we could stabilize it after adding this and worry about the specific arithmetic operations to add later so it doesn't block stabilization. I will follow up with a PR to propose some I think make sense looking at what sorts of operations appear frequently in RCB which remains the main candidate for these sorts of optimizations as it would improve point addition performance which improves practically every other point arithmetic operation.
Member
Author
|
PR to add some initial fused operations backed by |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Also bounds
PrimeFieldExton it, adds it to the macro boilerplate, adds manual definitions where needed, and bounds theFieldElementtype used byprimeorder::PrimeCurveParamson it so it needs to impl it as well.This follows from RustCrypto/traits#1997 where we were discussing how we could better leverage the various lazy field implementations we had.
In that thread I suggested we could avoid exposing separate field element types for reduced/unreduced operations and have a simpler abstraction for eagerly versus lazily reduced field elements if we supported various "fused" operations that are useful in dense field arithmetic, e.g. add-then-mul, mul-then-add.
For example the RCB implementation in
primeordercould migrate to using the "fused" operations which start out backed by default impls which call the individual arithmetic ops which, where applicable (mostlyk256andp521for now) can be replaced by optimized implementations which can avoid unnecessary normalization/reductions when performing these sequences of operations.This adds a
FieldExtwith no methods despite the fact we already have aPrimeFieldExt. The idea isFieldExtis an extension trait for functionality that would otherwise go onff::Field, andPrimeFieldExtis an extension trait forff::PrimeField, which in this case due to how theffcrate factors the relevant operations happens to be dealing with encoding, whereasFieldExtcan have the "fused" arithmetic ops asff::Fieldotherwise deals with the low-level arithmetic operations.What's nice is we could stabilize it after adding this and worry about the specific arithmetic operations to add later so it doesn't block stabilization. I will follow up with a PR to propose some I think make sense looking at what sorts of operations appear frequently in RCB which remains the main candidate for these sorts of optimizations as it would improve point addition performance which improves practically every other point arithmetic operation.