-
Notifications
You must be signed in to change notification settings - Fork 198
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
Generic curve arithmetic #22
Comments
@tuxxy brought up scalars on #23 It might make sense to replace the existing https://docs.rs/elliptic-curve/0.3.0/elliptic_curve/scalar/struct.Scalar.html The existing Unfortunately the byte-based sizing is heavily leveraged in |
I have some curve generic traits that I used for a library I am building with @nucypher called Twinkle. I've changed a lot of the backend since, but I have some trait definitions for As an example, here's the definition for pub trait Point: Sized {
type Backend: Backend<Point = Self>;
/// This can be used to swap out the library point type with a custom type.
/// If no such swapping is done, this should simply be Self.
type BackendPoint: Sized;
// Arithmetic functions
fn point_mul(lhs: <Self::Backend as Backend>::Scalar, rhs: Self) -> Self;
fn point_add(lhs: Self, rhs: Self) -> Self;
fn point_sub(lhs: Self, rhs: Self) -> Self;
fn point_neg(point_val: Self) -> Self;
fn point_eq(lhs: &Self, rhs: &Self) -> bool;
// Constants
fn basepoint() -> Self;
fn identity() -> Self;
// Helper functions
fn new() -> Self {
Self::identity()
}
fn from_backend_point(point: Self::BackendPoint) -> Self;
fn get_backend_point(self) -> Self::BackendPoint;
} Obviously, this won't work straight out of the box, but I can imagine a very similar architecture. These traits get implemented on the backend type (e.g. Ristretto's What I'm thinking is that the |
See the |
@str4d awesome! If you have a crate with some existing traits to use for this, all the better |
I'm finding myself interested in using this crate, but I also need scalar arithmetic. Since we presently lack this, it makes sense for me to potentially scope this out a bit more. Why would it make sense to refactor Also, I'm not very keen on the idea of a type simply named |
I'm pretty happy with the group and curve trait API I've arrived at in zkcrypto/group#6, so I'll spend some time thinking about refactoring this crate in terms of it. I'm interested to hear feedback in that issue. |
I'd vote for either zcash's new traits like @str4d suggests, or zexe's traits, which started as a fork of zcash's traits, and could surely remerge. I suppose zcash's new traits make it easier to express less structure than the simpler zexe ones, and maybe accommodate Edwards curves better? |
@str4d These traits look great. 👍 |
@tuxxy I'm definitely a fan of keeping the existing concrete Scalar type which is heavily wired into mundane things like supporting private key storage formats (e.g. PKCS#8). I guess the question is how do you reconcile that with the individual I'd be happy with any solution for The tricky part in all of this is the type-level arithmetic which makes it possible to compute exact-sized (or in the case of ASN.1 DER signatures, near exact) types and therefore have
The reason why I was interested in making scalars generic over an I suppose alternatively we could have a fully generic |
If the new zcash traits by @str4d work for Edwards curves then they should probably work with Schnorr and RSA groups too. |
In the
This is roughly the direction that the
They are intended to work for Edwards curves (Jubjub is a twisted Edwards curve). The base unit that the |
The really tricky thing right now is weierstrass::Curve::ScalarSize is the base For an example, an ECDSA signature is represented as two scalar values |
I added an /// Perform an inversion on a field element (i.e. base field element or scalar)
pub trait Invert {
/// Field element type
type Output;
/// Invert a field element.
fn invert(&self) -> CtOption<Self::Output>;
} This made it possible to eliminate the specifics of blinding scalar inversions from the ECDSA signing API, which was helpful: But I also didn't really put any thought into this trait design, and I'm curious if there are other places we could source a similar trait from, or alternative designs to consider /cc @nickray @str4d Also note that I'd like to cut another release of |
One of the goals of the
elliptic-curve
crate is to be able to write code that's generic over (at least Weierstrass) elliptic curve types.Now that the
p256
andk256
crates have arithmetic implementations (thanks @str4d and @tuxxy!), an open question is how to write code that's generic over the underlyingAffinePoint
and/orProjectivePoint
types.It seems like
AffinePoint
andProjectivePoint
could benefit from having traits which at the very least are bounded by the point arithmetic they must support.It also seems like there needs to be some trait connecting the two of them which can be used to access the
From
impls and arithmetic (e.g.Add
) between the two different point types.Finally, it seems like there needs to be a trait a
weierstrass::Curve
type can impl which provides that curve'sAffinePoint
andProjectivePoint
types as associated types.Curious if people think this is a good idea and what those traits might look like.
cc @tuxxy
The text was updated successfully, but these errors were encountered: