From ba7f9108735d3065cb322de798a26e8a164c81d7 Mon Sep 17 00:00:00 2001 From: Tony Arcieri Date: Fri, 13 Jun 2025 17:21:25 -0600 Subject: [PATCH] elliptic-curve: re-export `group::Curve` as `CurveGroup` This crate also defines a `Curve` trait, and while that trait is used to describe an elliptic curve, `group::Curve` is a `Group`, i.e. the elliptic curve group for a particular curve. See also: zkcrypto/group#51 To prevent this name clash, this commit re-exports `group::Curve` as `CurveGroup`. --- elliptic-curve/src/arithmetic.rs | 6 +++--- elliptic-curve/src/dev.rs | 8 ++++---- elliptic-curve/src/ecdh.rs | 5 ++--- elliptic-curve/src/lib.rs | 2 +- elliptic-curve/src/ops.rs | 5 +++-- 5 files changed, 13 insertions(+), 13 deletions(-) diff --git a/elliptic-curve/src/arithmetic.rs b/elliptic-curve/src/arithmetic.rs index 6e18774d2..88769e5dc 100644 --- a/elliptic-curve/src/arithmetic.rs +++ b/elliptic-curve/src/arithmetic.rs @@ -1,7 +1,7 @@ //! Elliptic curve arithmetic traits. use crate::{ - Curve, Error, FieldBytes, NonZeroScalar, PrimeCurve, ScalarPrimitive, + Curve, CurveGroup, Error, FieldBytes, Group, NonZeroScalar, PrimeCurve, ScalarPrimitive, ops::{Invert, LinearCombination, Mul, Reduce, ShrAssign}, point::{AffineCoordinates, NonIdentity}, scalar::{FromUintUnchecked, IsHigh}, @@ -50,8 +50,8 @@ pub trait CurveArithmetic: Curve { + LinearCombination<[(Self::ProjectivePoint, Self::Scalar)]> + LinearCombination<[(Self::ProjectivePoint, Self::Scalar); 2]> + TryInto, Error = Error> - + group::Curve - + group::Group; + + CurveGroup + + Group; /// Scalar field modulo this curve's order. /// diff --git a/elliptic-curve/src/dev.rs b/elliptic-curve/src/dev.rs index 4d1f6c080..e6f6c1418 100644 --- a/elliptic-curve/src/dev.rs +++ b/elliptic-curve/src/dev.rs @@ -4,7 +4,7 @@ //! the traits in this crate. use crate::{ - BatchNormalize, Curve, CurveArithmetic, FieldBytesEncoding, PrimeCurve, + BatchNormalize, Curve, CurveArithmetic, CurveGroup, FieldBytesEncoding, PrimeCurve, array::typenum::U32, bigint::{Limb, U256}, error::{Error, Result}, @@ -651,7 +651,7 @@ impl From> for ProjectivePoint { impl From for AffinePoint { fn from(point: ProjectivePoint) -> AffinePoint { - group::Curve::to_affine(&point) + CurveGroup::to_affine(&point) } } @@ -736,11 +736,11 @@ impl group::GroupEncoding for ProjectivePoint { } fn to_bytes(&self) -> Self::Repr { - group::Curve::to_affine(self).to_bytes() + CurveGroup::to_affine(self).to_bytes() } } -impl group::Curve for ProjectivePoint { +impl CurveGroup for ProjectivePoint { type AffineRepr = AffinePoint; fn to_affine(&self) -> AffinePoint { diff --git a/elliptic-curve/src/ecdh.rs b/elliptic-curve/src/ecdh.rs index 74143999a..87784ec4a 100644 --- a/elliptic-curve/src/ecdh.rs +++ b/elliptic-curve/src/ecdh.rs @@ -27,12 +27,11 @@ //! [SIGMA]: https://webee.technion.ac.il/~hugo/sigma-pdf.pdf use crate::{ - AffinePoint, Curve, CurveArithmetic, FieldBytes, NonZeroScalar, ProjectivePoint, PublicKey, - point::AffineCoordinates, + AffinePoint, Curve, CurveArithmetic, CurveGroup, FieldBytes, NonZeroScalar, ProjectivePoint, + PublicKey, point::AffineCoordinates, }; use core::{borrow::Borrow, fmt}; use digest::{Digest, crypto_common::BlockSizeUser}; -use group::Curve as _; use hkdf::{Hkdf, hmac::SimpleHmac}; use rand_core::{CryptoRng, TryCryptoRng}; use zeroize::{Zeroize, ZeroizeOnDrop}; diff --git a/elliptic-curve/src/lib.rs b/elliptic-curve/src/lib.rs index 79f444d3b..4876c9716 100644 --- a/elliptic-curve/src/lib.rs +++ b/elliptic-curve/src/lib.rs @@ -139,7 +139,7 @@ pub use { scalar::{NonZeroScalar, Scalar}, }, ff::{self, Field, PrimeField}, - group::{self, Group}, + group::{self, Curve as CurveGroup, Group}, }; #[cfg(feature = "jwk")] diff --git a/elliptic-curve/src/ops.rs b/elliptic-curve/src/ops.rs index 3fd9bb820..2e7252d65 100644 --- a/elliptic-curve/src/ops.rs +++ b/elliptic-curve/src/ops.rs @@ -1,9 +1,10 @@ //! Traits for arithmetic operations on elliptic curve field elements. -use core::iter; pub use core::ops::{Add, AddAssign, Mul, MulAssign, Neg, Shr, ShrAssign, Sub, SubAssign}; pub use crypto_bigint::Invert; +use crate::CurveGroup; +use core::iter; use crypto_bigint::Integer; use ff::Field; use subtle::{Choice, CtOption}; @@ -159,7 +160,7 @@ pub(crate) fn invert_batch_internal + MulAssign>( /// /// It's generic around `PointsAndScalars` to allow overlapping impls. For example, const generic /// impls can use the input size to determine the size needed to store temporary variables. -pub trait LinearCombination: group::Curve +pub trait LinearCombination: CurveGroup where PointsAndScalars: AsRef<[(Self, Self::Scalar)]> + ?Sized, {