Skip to content

Commit c2d518b

Browse files
committed
merge other upstream branches
2 parents bf4b234 + c80e327 commit c2d518b

File tree

17 files changed

+623
-133
lines changed

17 files changed

+623
-133
lines changed

.github/workflows/x448.yml

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
name: x448
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- ".github/workflows/x448.yml"
7+
- "ed448-goldilocks/**"
8+
- "x448/**"
9+
- "Cargo.*"
10+
push:
11+
branches: master
12+
13+
defaults:
14+
run:
15+
working-directory: x448
16+
17+
env:
18+
CARGO_INCREMENTAL: 0
19+
RUSTFLAGS: "-Dwarnings"
20+
RUSTDOCFLAGS: "-Dwarnings"
21+
22+
jobs:
23+
build:
24+
runs-on: ubuntu-latest
25+
strategy:
26+
matrix:
27+
rust:
28+
- 1.85.0 # MSRV
29+
- stable
30+
target:
31+
- thumbv7em-none-eabi
32+
- wasm32-unknown-unknown
33+
steps:
34+
- uses: actions/checkout@v4
35+
- uses: dtolnay/rust-toolchain@master
36+
with:
37+
toolchain: ${{ matrix.rust }}
38+
targets: ${{ matrix.target }}
39+
- run: cargo build --target ${{ matrix.target }} --release
40+
41+
test:
42+
runs-on: ubuntu-latest
43+
strategy:
44+
matrix:
45+
include:
46+
# 32-bit Linux
47+
- target: i686-unknown-linux-gnu
48+
rust: 1.85.0 # MSRV
49+
deps: sudo apt update && sudo apt install gcc-multilib
50+
- target: i686-unknown-linux-gnu
51+
rust: stable
52+
deps: sudo apt update && sudo apt install gcc-multilib
53+
54+
# 64-bit Linux
55+
- target: x86_64-unknown-linux-gnu
56+
rust: 1.85.0 # MSRV
57+
- target: x86_64-unknown-linux-gnu
58+
rust: stable
59+
60+
steps:
61+
- uses: actions/checkout@v4
62+
- uses: dtolnay/rust-toolchain@master
63+
with:
64+
toolchain: ${{ matrix.rust }}
65+
targets: ${{ matrix.target }}
66+
- uses: RustCrypto/actions/cargo-hack-install@master
67+
- run: ${{ matrix.deps }}
68+
- run: cargo test --release --target ${{ matrix.target }}
69+
70+
cross:
71+
strategy:
72+
matrix:
73+
include:
74+
# ARM32
75+
- target: armv7-unknown-linux-gnueabihf
76+
rust: 1.85.0 # MSRV (cross)
77+
- target: armv7-unknown-linux-gnueabihf
78+
rust: stable
79+
80+
# ARM64
81+
- target: aarch64-unknown-linux-gnu
82+
rust: 1.85.0 # MSRV (cross)
83+
- target: aarch64-unknown-linux-gnu
84+
rust: stable
85+
86+
# PPC32
87+
- target: powerpc-unknown-linux-gnu
88+
rust: 1.85.0 # MSRV (cross)
89+
- target: powerpc-unknown-linux-gnu
90+
rust: stable
91+
92+
runs-on: ubuntu-latest
93+
steps:
94+
- uses: actions/checkout@v4
95+
- run: ${{ matrix.deps }}
96+
- uses: dtolnay/rust-toolchain@master
97+
with:
98+
toolchain: ${{ matrix.rust }}
99+
targets: ${{ matrix.target }}
100+
- uses: RustCrypto/actions/cross-install@master
101+
- run: cross test --release --target ${{ matrix.target }}
102+
103+
doc:
104+
runs-on: ubuntu-latest
105+
steps:
106+
- uses: actions/checkout@v4
107+
- uses: RustCrypto/actions/cargo-cache@master
108+
- uses: dtolnay/rust-toolchain@master
109+
with:
110+
toolchain: stable
111+
- run: cargo doc

Cargo.lock

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

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ members = [
1414
"p521",
1515
"primefield",
1616
"primeorder",
17-
"sm2"
17+
"sm2",
18+
"x448"
1819
]
1920

2021
[profile.dev]
2122
opt-level = 2
2223

2324
[patch.crates-io]
25+
ed448-goldilocks = { path = "ed448-goldilocks" }
2426
elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }
2527
hash2curve = { path = "hash2curve" }
2628
primefield = { path = "primefield" }

ed448-goldilocks/src/constants.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,7 @@ pub const DECAF_BASEPOINT: DecafPoint = DecafPoint(curve::twedwards::extended::E
77
T: TWISTED_EDWARDS_BASE_POINT.T,
88
});
99

10-
/// `BASEPOINT_ORDER` is the order of the Ed448 basepoint, i.e.,
11-
/// $$
12-
/// \ell = 2^\{446\} + 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d.
13-
/// $$
14-
pub const EDWARDS_BASEPOINT_ORDER: EdwardsScalar = EdwardsScalar::new(ORDER);
15-
16-
/// `BASEPOINT_ORDER` is the order of the Decaf448 basepoint, i.e.,
17-
/// $$
18-
/// \ell = 2^\{446\} + 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d.
19-
/// $$
20-
pub const DECAF_BASEPOINT_ORDER: DecafScalar = DecafScalar::new(ORDER);
21-
22-
/// `BASEPOINT_ORDER` is the order of the Curve448 basepoint, i.e.,
10+
/// [`MONTGOMERY_BASEPOINT_ORDER`] is the order of the Curve448 basepoint, i.e.,
2311
/// $$
2412
/// \ell = 2^\{446\} + 0x8335dc163bb124b65129c96fde933d8d723a70aadc873d6d54a7bb0d.
2513
/// $$

ed448-goldilocks/src/curve/twedwards/extended.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ impl ExtendedPoint {
115115

116116
// Compute x
117117
let xy = x * y;
118-
let x_numerator = xy + xy;
118+
let x_numerator = xy.double();
119119
let x_denom = y.square() - (a * x.square());
120120
let new_x = x_numerator * x_denom.invert();
121121

ed448-goldilocks/src/curve/twedwards/extensible.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl ExtensiblePoint {
5252
pub fn double(&self) -> ExtensiblePoint {
5353
let A = self.X.square();
5454
let B = self.Y.square();
55-
let C = self.Z.square() + self.Z.square();
55+
let C = self.Z.square().double();
5656
let D = -A;
5757
let E = (self.X + self.Y).square() - A - B;
5858
let G = D + B;

ed448-goldilocks/src/decaf/affine.rs

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -93,36 +93,6 @@ impl From<NonIdentity<AffinePoint>> for AffinePoint {
9393
}
9494
}
9595

96-
impl Mul<DecafScalar> for AffinePoint {
97-
type Output = DecafPoint;
98-
99-
#[inline]
100-
#[expect(clippy::op_ref, reason = "false-positive")]
101-
fn mul(self, scalar: DecafScalar) -> DecafPoint {
102-
&self * scalar
103-
}
104-
}
105-
106-
#[allow(clippy::op_ref)] // https://github.com/rust-lang/rust-clippy/issues/12463
107-
impl Mul<DecafScalar> for &AffinePoint {
108-
type Output = DecafPoint;
109-
110-
#[inline]
111-
fn mul(self, scalar: DecafScalar) -> DecafPoint {
112-
self * &scalar
113-
}
114-
}
115-
116-
#[allow(clippy::op_ref)] // https://github.com/rust-lang/rust-clippy/issues/12463
117-
impl Mul<&DecafScalar> for AffinePoint {
118-
type Output = DecafPoint;
119-
120-
#[inline]
121-
fn mul(self, scalar: &DecafScalar) -> DecafPoint {
122-
&self * scalar
123-
}
124-
}
125-
12696
impl Mul<&DecafScalar> for &AffinePoint {
12797
type Output = DecafPoint;
12898

@@ -132,20 +102,4 @@ impl Mul<&DecafScalar> for &AffinePoint {
132102
}
133103
}
134104

135-
impl Mul<AffinePoint> for DecafScalar {
136-
type Output = DecafPoint;
137-
138-
#[inline]
139-
fn mul(self, point: AffinePoint) -> DecafPoint {
140-
point * self
141-
}
142-
}
143-
144-
impl Mul<&AffinePoint> for DecafScalar {
145-
type Output = DecafPoint;
146-
147-
#[inline]
148-
fn mul(self, point: &AffinePoint) -> DecafPoint {
149-
point * self
150-
}
151-
}
105+
define_mul_variants!(LHS = AffinePoint, RHS = DecafScalar, Output = DecafPoint);

ed448-goldilocks/src/decaf/ops.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,6 @@ impl Mul<&DecafScalar> for &DecafPoint {
2020

2121
define_mul_variants!(LHS = DecafPoint, RHS = DecafScalar, Output = DecafPoint);
2222

23-
impl Mul<&DecafPoint> for &DecafScalar {
24-
type Output = DecafPoint;
25-
26-
fn mul(self, point: &DecafPoint) -> DecafPoint {
27-
point * self
28-
}
29-
}
30-
31-
define_mul_variants!(LHS = DecafScalar, RHS = DecafPoint, Output = DecafPoint);
32-
3323
impl<'s> MulAssign<&'s DecafScalar> for DecafPoint {
3424
fn mul_assign(&mut self, scalar: &'s DecafScalar) {
3525
*self = *self * scalar;

ed448-goldilocks/src/decaf/points.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::constants::{DECAF_BASEPOINT, DECAF_BASEPOINT_ORDER};
1+
use crate::constants::DECAF_BASEPOINT;
22
use crate::curve::twedwards::extended::ExtendedPoint;
33
use crate::field::FieldElement;
44
use crate::*;
@@ -226,7 +226,7 @@ impl CofactorGroup for DecafPoint {
226226
}
227227

228228
fn is_torsion_free(&self) -> Choice {
229-
(self * DECAF_BASEPOINT_ORDER).ct_eq(&Self::IDENTITY)
229+
Choice::from(1)
230230
}
231231
}
232232

@@ -550,7 +550,7 @@ impl CompressedDecaf {
550550
let (I, ok) = (v * u1_sqr).inverse_square_root();
551551

552552
let Dx = I * u1;
553-
let Dxs = (s + s) * Dx;
553+
let Dxs = s.double() * Dx;
554554

555555
let mut X = (Dxs * I) * v;
556556
let k = Dxs * FieldElement::DECAF_FACTOR;

ed448-goldilocks/src/decaf/scalar.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl DecafScalar {
5252
}
5353
}
5454

55-
elliptic_curve::scalar_from_impls!(Decaf448, DecafScalar);
55+
elliptic_curve::scalar_impls!(Decaf448, DecafScalar);
5656

5757
/// The number of bytes needed to represent the scalar field
5858
pub type DecafScalarBytes = ScalarBytes<Decaf448>;

0 commit comments

Comments
 (0)