Skip to content

Commit 89ee8ef

Browse files
committed
WIP: make things compile
1 parent c0717c3 commit 89ee8ef

File tree

4 files changed

+49
-40
lines changed

4 files changed

+49
-40
lines changed

ed448-goldilocks/src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ pub use edwards::{
6060
AffinePoint, CompressedEdwardsY, EdwardsPoint, EdwardsScalar, EdwardsScalarBytes,
6161
WideEdwardsScalarBytes,
6262
};
63-
pub use field::{MODULUS_LIMBS, ORDER, Scalar, WIDE_ORDER};
63+
pub use field::{MODULUS_LIMBS, ORDER, Scalar, ScalarBytes, WIDE_ORDER};
6464
pub use montgomery::{
65-
MontgomeryPoint, MontgomeryScalar, MontgomeryScalarBytes, MontgomeryXpoint,
66-
ProjectiveMontgomeryPoint, ProjectiveMontgomeryXpoint, WideMontgomeryScalarBytes,
65+
LOW_A, LOW_B, LOW_C, MontgomeryPoint, MontgomeryScalar, MontgomeryScalarBytes,
66+
MontgomeryXpoint, ProjectiveMontgomeryPoint, ProjectiveMontgomeryXpoint,
67+
WideMontgomeryScalarBytes,
6768
};
6869
pub use ristretto::{CompressedRistretto, RistrettoPoint};
6970
#[cfg(feature = "signing")]

ed448-goldilocks/src/montgomery.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ mod x;
1515

1616
pub use point::{MontgomeryPoint, ProjectiveMontgomeryPoint};
1717
pub use scalar::{MontgomeryScalar, MontgomeryScalarBytes, WideMontgomeryScalarBytes};
18-
pub use x::{MontgomeryXpoint, ProjectiveMontgomeryXpoint};
18+
pub use x::{LOW_A, LOW_B, LOW_C, MontgomeryXpoint, ProjectiveMontgomeryXpoint};
1919

2020
/// The default hash to curve domain separation tag
2121
const DEFAULT_HASH_TO_CURVE_SUITE: &[u8] = b"curve448_XOF:SHAKE256_ELL2_RO_";

ed448-goldilocks/src/montgomery/x.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ use super::{
2121
};
2222

2323
// Low order points on Curve448 and it's twist
24-
const LOW_A: MontgomeryXpoint = MontgomeryXpoint([
24+
pub const LOW_A: MontgomeryXpoint = MontgomeryXpoint([
2525
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2626
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2727
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2828
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
2929
]);
30-
const LOW_B: MontgomeryXpoint = MontgomeryXpoint([
30+
pub const LOW_B: MontgomeryXpoint = MontgomeryXpoint([
3131
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3232
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3333
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3434
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3535
]);
36-
const LOW_C: MontgomeryXpoint = MontgomeryXpoint([
36+
pub const LOW_C: MontgomeryXpoint = MontgomeryXpoint([
3737
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
3838
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xfe, 0xff, 0xff, 0xff,
3939
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,

x448/src/lib.rs

Lines changed: 41 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
#![no_std]
22

3-
use ed448_goldilocks::MontgomeryPoint;
4-
use ed448_goldilocks::Scalar;
3+
use ed448_goldilocks::Curve448;
4+
use ed448_goldilocks::MontgomeryScalar;
5+
use ed448_goldilocks::MontgomeryScalar as Scalar;
6+
use ed448_goldilocks::MontgomeryXpoint;
7+
use ed448_goldilocks::ProjectiveMontgomeryPoint as MontgomeryPoint;
8+
use ed448_goldilocks::ScalarBytes;
9+
use ed448_goldilocks::elliptic_curve::group::GroupEncoding;
510
use rand_core::{CryptoRng, RngCore};
611
use zeroize::Zeroize;
712

813
/// Computes a Scalar according to RFC7748
914
/// given a byte array of length 56
1015
impl From<[u8; 56]> for Secret {
1116
fn from(arr: [u8; 56]) -> Secret {
12-
let mut secret = Secret(arr);
17+
let mut secret = Secret(arr.into());
1318
secret.clamp();
1419
secret
1520
}
@@ -20,25 +25,26 @@ impl From<[u8; 56]> for Secret {
2025
/// XXX: Waiting for upstream PR to use pre-computation
2126
impl From<&Secret> for PublicKey {
2227
fn from(secret: &Secret) -> PublicKey {
23-
let point = &MontgomeryPoint::GENERATOR * &Scalar::from_bytes(&secret.0);
28+
let point =
29+
&MontgomeryXpoint::GENERATOR * &Scalar::from_canonical_bytes(&secret.0).unwrap();
2430
PublicKey(point)
2531
}
2632
}
2733

2834
/// A PublicKey is a point on Curve448.
2935
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
30-
pub struct PublicKey(MontgomeryPoint);
36+
pub struct PublicKey(MontgomeryXpoint);
3137

3238
/// A Secret is a Scalar on Curve448.
3339
#[derive(Clone, Zeroize)]
3440
#[zeroize(drop)]
35-
pub struct Secret([u8; 56]);
41+
pub struct Secret(ScalarBytes<Curve448>);
3642

3743
/// A SharedSecret is a point on Curve448.
3844
/// This point is the result of a Diffie-Hellman key exchange.
3945
#[derive(Zeroize)]
4046
#[zeroize(drop)]
41-
pub struct SharedSecret(MontgomeryPoint);
47+
pub struct SharedSecret(MontgomeryXpoint);
4248

4349
impl PublicKey {
4450
/// Converts a bytes slice into a Public key
@@ -63,7 +69,7 @@ impl PublicKey {
6369

6470
// Check if the point has low order
6571
let arr = slice_to_array(bytes);
66-
let point = MontgomeryPoint(arr);
72+
let point = MontgomeryXpoint(arr);
6773

6874
Some(PublicKey(point))
6975
}
@@ -102,8 +108,8 @@ impl Secret {
102108
}
103109

104110
/// Views a Secret as a Scalar
105-
fn as_scalar(&self) -> Scalar {
106-
Scalar::from_bytes(&self.0)
111+
fn as_scalar(&self) -> MontgomeryScalar {
112+
Scalar::from_canonical_bytes(&self.0).unwrap()
107113
}
108114

109115
/// Performs a Diffie-hellman key exchange between the secret key and an external public key
@@ -134,7 +140,7 @@ impl Secret {
134140

135141
/// Converts a secret into a byte array
136142
pub fn as_bytes(&self) -> &[u8; 56] {
137-
&self.0
143+
&self.0.as_ref()
138144
}
139145
}
140146

@@ -158,12 +164,12 @@ pub fn x448(scalar_bytes: [u8; 56], point_bytes: [u8; 56]) -> Option<[u8; 56]> {
158164
/// An unchecked version of the x448 function defined in RFC448
159165
/// No checks are made on the points.
160166
pub fn x448_unchecked(scalar_bytes: [u8; 56], point_bytes: [u8; 56]) -> [u8; 56] {
161-
let point = MontgomeryPoint(point_bytes);
167+
let point = MontgomeryXpoint(point_bytes);
162168
let scalar = Secret::from(scalar_bytes).as_scalar();
163169
(&point * &scalar).0
164170
}
165171

166-
pub const X448_BASEPOINT_BYTES: [u8; 56] = MontgomeryPoint::GENERATOR.0;
172+
pub const X448_BASEPOINT_BYTES: [u8; 56] = MontgomeryXpoint::GENERATOR.0;
167173

168174
#[cfg(test)]
169175
mod test {
@@ -172,27 +178,29 @@ mod test {
172178
use super::*;
173179
use alloc::vec;
174180

181+
use ed448_goldilocks::{LOW_A, LOW_B, LOW_C};
182+
175183
#[test]
176184
fn test_low_order() {
177185
// These are also in ed448-goldilocks. We could export them, but I cannot see any use except for this test.
178-
const LOW_A: MontgomeryPoint = MontgomeryPoint([
179-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
180-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
181-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
182-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
183-
]);
184-
const LOW_B: MontgomeryPoint = MontgomeryPoint([
185-
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
186-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
187-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188-
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
189-
]);
190-
const LOW_C: MontgomeryPoint = MontgomeryPoint([
191-
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
192-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
193-
0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
194-
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
195-
]);
186+
//const LOW_A: MontgomeryPoint = MontgomeryPoint([
187+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
188+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
189+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
190+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
191+
//]);
192+
//const LOW_B: MontgomeryPoint = MontgomeryPoint([
193+
// 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
194+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
195+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
196+
// 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
197+
//]);
198+
//const LOW_C: MontgomeryPoint = MontgomeryPoint([
199+
// 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
200+
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
201+
// 0xfe, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
202+
// 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
203+
//]);
196204

197205
// Notice, that this is the only way to add low order points into the system
198206
// and this is not exposed to the user. The user will use `from_bytes` which will check for low order points.
@@ -393,8 +401,8 @@ mod test {
393401
0xda, 0x8d, 0x52, 0x4d, 0xe3, 0xd6, 0x9b, 0xd9, 0xd9, 0xd6, 0x6b, 0x99, 0x7e, 0x37,
394402
];
395403

396-
let mut point = MontgomeryPoint::GENERATOR.0;
397-
let mut scalar = MontgomeryPoint::GENERATOR.0;
404+
let mut point = MontgomeryXpoint::GENERATOR.0;
405+
let mut scalar = MontgomeryXpoint::GENERATOR.0;
398406
let mut result = [0u8; 56];
399407

400408
// Iterate 1 time then check value on 1st iteration

0 commit comments

Comments
 (0)