k256::FieldElement: PrimeField + FromUniformBytes<64>#1703
k256::FieldElement: PrimeField + FromUniformBytes<64>#1703kayabaNerve wants to merge 2 commits intoRustCrypto:masterfrom
k256::FieldElement: PrimeField + FromUniformBytes<64>#1703Conversation
I don't _love_ this implementation. `crypto_bigint` could generate a faster modular reduction, and I'm sure the tailored arithmetic would also be faster if this was expressed as a linear combination of `hi * 2**256 + lo`. This is just the most direct possible way to implement this. As for why perform a hit and run for this specific function, I maintain an implementation of secq256k1 where the `Scalar`, `FieldElement` types are secp256k1's `FieldElement`, `Scalar` types (respectively). This means I need all functions for `FieldElement` as one would want (or as I would want) from `Scalar`. I wanted to make this PR now as obviously, many RustCrypto crates have recently moved out of `rc`, so I'm double checking if anything slipped through the cracks on my end for features I want to ensure are included. Historically, I implemented this trait for the `Scalar` types with RustCrypto#1379. While that included feedback on deferring to `Reduce`, this type does not have any outstanding implementations of `Reduce`.
Same rationale as the prior PR, yet the implementation is effectively copy/pasted from `Scalar` and should be without reservation.
|
Instead of an issue for my remaining issues on trying to make this usable, I added this comment to the relevant issue: #531 (comment) |
|
Aah, I was going to say why not use |
|
Yeah, unfortunately, it seems like k256 and curve25519-dalek have neglected field element code (k256 exposing one which panics if used via the ff API, dalek not exposing one at all). I think overall, given the gap between:
There likely has to be an overarching design decision on how to move forward and the future of That just doesn't change this is a continued "want" on my end, with many possible options, and no agreed path forward :/ |
|
#531 and introducing a |
I don't love this implementation.
crypto_bigintcould generate a fastermodular reduction, and I'm sure the tailored arithmetic would also be faster if
this was expressed as a linear combination of
hi * 2**256 + lo. This is justthe most direct possible way to implement this.
As for why perform a hit and run for this specific function, I maintain an
implementation of secq256k1 where the
Scalar,FieldElementtypes aresecp256k1's
FieldElement,Scalartypes (respectively). This means I needall functions for
FieldElementas one would want (or as I would want) fromScalar. I wanted to make this PR now as obviously, many RustCrypto crateshave recently moved out of
rc, so I'm double checking if anything slippedthrough the cracks on my end for features I want to ensure are included.
Historically, I implemented this trait for the
Scalartypes with#1379. While that included
feedback on deferring to
Reduce, this type does not have any outstandingimplementations of
Reduce.Same rationale as the prior PR, yet the implementation is effectively
copy/pasted from
Scalarand should be without reservation.s/prior PR/prior commit/
The above is my commit messages, which I find sufficiently descriptive for the PR as a whole.
This satisfies the type contracts I currently require in my
secq256k1library, allowing me to replace my bespoke type (which largely just defers tocrypto-bigint, which is amazing for things like this). While I did verify this satisfies the type contract after backporting to the0.13releases, I realized the 0.13FieldElementisn't safe for public consumption as it isn't normalized, despite implementing a variety of the traits fromffwhich don't allow representing non-normalized values. I'm reminded of the inactive PR on curve25519-dalek which showed one can do this with the type system, but it becomes quite complicated (dalek-cryptography/curve25519-dalek#816). For my own current use case, I just want to be able to, as a consumer, use theFieldElement.Shotgunning calls to
normalizeappears to work, but isn't something I'm actually fine moving to. I'll make an issue to track this other blocker properly, as I believe this issue is still present in the current HEAD.