Skip to content

Commit d70bd44

Browse files
committed
fixup api breaks
1 parent 750d681 commit d70bd44

12 files changed

Lines changed: 296 additions & 106 deletions

File tree

Cargo.lock

Lines changed: 40 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ed448/Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ rust-version = "1.85"
1717
version = "0.17.0-pre.0"
1818

1919
[dependencies]
20-
crypto-bigint = { version = "=0.7.0-pre.3", features = ["hybrid-array"], default-features = false }
21-
crypto_signature = { version = "=3.0.0-pre", default-features = false, features = ["digest", "rand_core"], optional = true, package = "signature" }
22-
elliptic-curve = { version = "0.14.0-rc.0", features = ["arithmetic", "bits", "hash2curve", "jwk", "pkcs8", "pem", "sec1"] }
20+
crypto-bigint = { version = "=0.7.0-pre.4", features = ["hybrid-array"], default-features = false }
21+
crypto_signature = { version = "3.0.0-rc.0", default-features = false, features = ["digest", "rand_core"], optional = true, package = "signature" }
22+
elliptic-curve = { version = "0.14.0-rc.3", features = ["arithmetic", "bits", "hash2curve", "jwk", "pkcs8", "pem", "sec1"] }
2323
rand_core = { version = "0.9", default-features = false }
2424
serdect = { version = "0.3.0", optional = true }
25-
sha3 = { version = "=0.11.0-pre.5", default-features = false }
25+
sha3 = { version = "0.11.0-rc.0", default-features = false }
2626
subtle = { version = "2.6", default-features = false }
2727
zeroize = { version = "1.8", default-features = false, optional = true }
2828

ed448/src/curve/edwards/affine.rs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::curve::edwards::EdwardsPoint;
22
use crate::field::FieldElement;
33
use crate::*;
4+
use core::ops::Mul;
5+
use elliptic_curve::{Error, Result, point::NonIdentity};
46
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
57

68
#[cfg(feature = "zeroize")]
@@ -115,3 +117,35 @@ impl AffinePoint {
115117
self.y.to_bytes()
116118
}
117119
}
120+
121+
impl From<NonIdentity<AffinePoint>> for AffinePoint {
122+
fn from(affine: NonIdentity<AffinePoint>) -> Self {
123+
affine.to_point()
124+
}
125+
}
126+
127+
impl TryFrom<AffinePoint> for NonIdentity<AffinePoint> {
128+
type Error = Error;
129+
130+
fn try_from(affine_point: AffinePoint) -> Result<Self> {
131+
NonIdentity::new(affine_point).into_option().ok_or(Error)
132+
}
133+
}
134+
135+
impl Mul<AffinePoint> for Scalar {
136+
type Output = EdwardsPoint;
137+
138+
#[inline]
139+
fn mul(self, rhs: AffinePoint) -> EdwardsPoint {
140+
self * &rhs
141+
}
142+
}
143+
144+
impl Mul<&AffinePoint> for Scalar {
145+
type Output = EdwardsPoint;
146+
147+
#[inline]
148+
fn mul(self, rhs: &AffinePoint) -> EdwardsPoint {
149+
rhs.to_edwards() * self
150+
}
151+
}

ed448/src/curve/edwards/extended.rs

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ use crate::curve::twedwards::extended::ExtendedPoint as TwistedExtendedPoint;
1111
use crate::field::{FieldElement, Scalar};
1212
use crate::*;
1313
use elliptic_curve::{
14-
array::{
15-
typenum::{Unsigned, U56, U57, U84},
16-
Array,
17-
},
18-
group::{cofactor::CofactorGroup, prime::PrimeGroup, Curve, Group, GroupEncoding},
14+
Error,
15+
array::{Array, typenum::Unsigned},
16+
consts::{U28, U84},
17+
group::{Curve, Group, GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
1918
hash2curve::{ExpandMsg, ExpandMsgXof, Expander, FromOkm},
2019
ops::LinearCombination,
20+
point::NonIdentity,
2121
};
2222
use rand_core::TryRngCore;
2323
use subtle::{Choice, ConditionallyNegatable, ConditionallySelectable, ConstantTimeEq, CtOption};
@@ -747,7 +747,7 @@ impl EdwardsPoint {
747747
///
748748
/// Hash using the default domain separation tag and hash function
749749
pub fn hash_with_defaults(msg: &[u8]) -> Self {
750-
Self::hash::<ExpandMsgXof<sha3::Shake256, U84>>(msg, DEFAULT_HASH_TO_CURVE_SUITE)
750+
Self::hash::<ExpandMsgXof<sha3::Shake256>>(msg, DEFAULT_HASH_TO_CURVE_SUITE)
751751
}
752752

753753
/// Hash a message to a point on the curve
@@ -756,7 +756,7 @@ impl EdwardsPoint {
756756
/// see <https://datatracker.ietf.org/doc/rfc9380/>
757757
pub fn hash<X>(msg: &[u8], dst: &[u8]) -> Self
758758
where
759-
X: for<'a> ExpandMsg<'a>,
759+
X: ExpandMsg<U28>,
760760
{
761761
type RandomLen = U84;
762762
let mut random_bytes = Array::<u8, RandomLen>::default();
@@ -784,7 +784,7 @@ impl EdwardsPoint {
784784
///
785785
/// Encode using the default domain separation tag and hash function
786786
pub fn encode_with_defaults(msg: &[u8]) -> Self {
787-
Self::encode::<ExpandMsgXof<sha3::Shake256, U84>>(msg, DEFAULT_ENCODE_TO_CURVE_SUITE)
787+
Self::encode::<ExpandMsgXof<sha3::Shake256>>(msg, DEFAULT_ENCODE_TO_CURVE_SUITE)
788788
}
789789

790790
/// Encode a message to a point on the curve
@@ -793,7 +793,7 @@ impl EdwardsPoint {
793793
/// see <https://datatracker.ietf.org/doc/rfc9380/>
794794
pub fn encode<X>(msg: &[u8], dst: &[u8]) -> Self
795795
where
796-
X: for<'a> ExpandMsg<'a>,
796+
X: ExpandMsg<U28>,
797797
{
798798
type RandomLen = U84;
799799
let mut random_bytes = Array::<u8, RandomLen>::default();
@@ -814,6 +814,21 @@ impl EdwardsPoint {
814814
}
815815
}
816816

817+
impl From<NonIdentity<EdwardsPoint>> for EdwardsPoint {
818+
fn from(p: NonIdentity<EdwardsPoint>) -> Self {
819+
p.to_point()
820+
}
821+
}
822+
823+
/// The constant-time alternative is available at [`NonIdentity::new()`].
824+
impl TryFrom<EdwardsPoint> for NonIdentity<EdwardsPoint> {
825+
type Error = Error;
826+
827+
fn try_from(point: EdwardsPoint) -> Result<Self, Error> {
828+
NonIdentity::new(point).into_option().ok_or(Error)
829+
}
830+
}
831+
817832
// ------------------------------------------------------------------------
818833
// Addition and Subtraction
819834
// ------------------------------------------------------------------------
@@ -1188,7 +1203,7 @@ mod tests {
11881203
];
11891204

11901205
for (msg, x, y) in MSGS {
1191-
let p = EdwardsPoint::hash::<ExpandMsgXof<sha3::Shake256, U84>>(msg, DST);
1206+
let p = EdwardsPoint::hash::<ExpandMsgXof<sha3::Shake256>>(msg, DST);
11921207
assert_eq!(p.is_on_curve().unwrap_u8(), 1u8);
11931208
let p = p.to_affine();
11941209
let mut xx = [0u8; 56];
@@ -1225,7 +1240,7 @@ mod tests {
12251240
];
12261241

12271242
for (msg, x, y) in MSGS {
1228-
let p = EdwardsPoint::encode::<ExpandMsgXof<sha3::Shake256, U84>>(msg, DST);
1243+
let p = EdwardsPoint::encode::<ExpandMsgXof<sha3::Shake256>>(msg, DST);
12291244
assert_eq!(p.is_on_curve().unwrap_u8(), 1u8);
12301245
let p = p.to_affine();
12311246
let mut xx = [0u8; 56];

ed448/src/decaf/affine.rs

Lines changed: 72 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
use crate::curve::twedwards::affine::AffinePoint as InnerAffinePoint;
22
use crate::field::FieldElement;
3-
use crate::{Decaf448FieldBytes, DecafPoint};
3+
use crate::{Decaf448FieldBytes, DecafPoint, Scalar};
4+
use core::ops::Mul;
5+
use elliptic_curve::{Error, point::NonIdentity};
46
use subtle::{Choice, ConditionallySelectable, ConstantTimeEq};
57

68
#[cfg(feature = "zeroize")]
@@ -70,3 +72,72 @@ impl AffinePoint {
7072
self.0.y.to_bytes()
7173
}
7274
}
75+
76+
/// The constant-time alternative is available at [`NonIdentity::new()`].
77+
impl TryFrom<AffinePoint> for NonIdentity<AffinePoint> {
78+
type Error = Error;
79+
80+
fn try_from(affine_point: AffinePoint) -> Result<Self, Error> {
81+
NonIdentity::new(affine_point).into_option().ok_or(Error)
82+
}
83+
}
84+
85+
impl From<NonIdentity<AffinePoint>> for AffinePoint {
86+
fn from(affine: NonIdentity<AffinePoint>) -> Self {
87+
affine.to_point()
88+
}
89+
}
90+
91+
impl Mul<Scalar> for AffinePoint {
92+
type Output = DecafPoint;
93+
94+
#[inline]
95+
fn mul(self, scalar: Scalar) -> DecafPoint {
96+
&self * scalar
97+
}
98+
}
99+
100+
impl Mul<Scalar> for &AffinePoint {
101+
type Output = DecafPoint;
102+
103+
#[inline]
104+
fn mul(self, scalar: Scalar) -> DecafPoint {
105+
self * &scalar
106+
}
107+
}
108+
109+
impl Mul<&Scalar> for AffinePoint {
110+
type Output = DecafPoint;
111+
112+
#[inline]
113+
fn mul(self, scalar: &Scalar) -> DecafPoint {
114+
&self * scalar
115+
}
116+
}
117+
118+
impl Mul<&Scalar> for &AffinePoint {
119+
type Output = DecafPoint;
120+
121+
#[inline]
122+
fn mul(self, scalar: &Scalar) -> DecafPoint {
123+
self.to_decaf() * scalar
124+
}
125+
}
126+
127+
impl Mul<AffinePoint> for Scalar {
128+
type Output = DecafPoint;
129+
130+
#[inline]
131+
fn mul(self, point: AffinePoint) -> DecafPoint {
132+
point * self
133+
}
134+
}
135+
136+
impl Mul<&AffinePoint> for Scalar {
137+
type Output = DecafPoint;
138+
139+
#[inline]
140+
fn mul(self, point: &AffinePoint) -> DecafPoint {
141+
point * self
142+
}
143+
}

ed448/src/decaf/points.rs

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ use crate::field::FieldElement;
44
use crate::*;
55

66
use elliptic_curve::{
7-
array::{
8-
Array,
9-
},
7+
Error, Group,
8+
array::{Array, typenum::Unsigned},
9+
consts::{U32, U56, U84},
1010
group::{Curve, GroupEncoding, cofactor::CofactorGroup, prime::PrimeGroup},
1111
hash2curve::{ExpandMsg, Expander, FromOkm},
1212
ops::LinearCombination,
13-
Group,
13+
point::NonIdentity,
1414
};
1515

1616
use core::fmt::{Display, Formatter, LowerHex, Result as FmtResult, UpperHex};
@@ -356,7 +356,7 @@ impl DecafPoint {
356356
/// separation tag.
357357
pub fn hash<X>(msg: &[u8], dst: &[u8]) -> Self
358358
where
359-
X: for<'a> ExpandMsg<'a>,
359+
X: ExpandMsg<U32>,
360360
{
361361
type RandomLen = U84;
362362
let dst = [dst];
@@ -605,6 +605,21 @@ impl CompressedDecaf {
605605
}
606606
}
607607

608+
/// The constant-time alternative is available at [`NonIdentity::new()`].
609+
impl TryFrom<DecafPoint> for NonIdentity<DecafPoint> {
610+
type Error = Error;
611+
612+
fn try_from(point: DecafPoint) -> Result<Self, Error> {
613+
NonIdentity::new(point).into_option().ok_or(Error)
614+
}
615+
}
616+
617+
impl From<NonIdentity<DecafPoint>> for DecafPoint {
618+
fn from(decaf: NonIdentity<DecafPoint>) -> Self {
619+
decaf.to_point()
620+
}
621+
}
622+
608623
#[cfg(test)]
609624
mod test {
610625
use super::*;
@@ -761,8 +776,7 @@ mod test {
761776
use elliptic_curve::hash2curve::ExpandMsgXof;
762777

763778
let msg = b"Hello, world!";
764-
let point =
765-
DecafPoint::hash::<ExpandMsgXof<sha3::Shake256, U84>>(msg, b"test_hash_to_curve");
779+
let point = DecafPoint::hash::<ExpandMsgXof<sha3::Shake256>>(msg, b"test_hash_to_curve");
766780
assert_eq!(point.0.is_on_curve().unwrap_u8(), 1u8);
767781
assert_ne!(point, DecafPoint::IDENTITY);
768782
assert_ne!(point, DecafPoint::GENERATOR);

0 commit comments

Comments
 (0)