@@ -3,12 +3,12 @@ use core::fmt::{Display, Formatter, LowerHex, Result as FmtResult, UpperHex};
3
3
use core:: iter:: Sum ;
4
4
use core:: ops:: { Add , AddAssign , Mul , MulAssign , Neg , Sub , SubAssign } ;
5
5
6
- use crate :: constants:: BASEPOINT_ORDER ;
6
+ use crate :: constants:: EDWARDS_BASEPOINT_ORDER ;
7
7
use crate :: curve:: edwards:: affine:: AffinePoint ;
8
8
use crate :: curve:: montgomery:: MontgomeryPoint ; // XXX: need to fix this path
9
9
use crate :: curve:: scalar_mul:: variable_base;
10
10
use crate :: curve:: twedwards:: extended:: ExtendedPoint as TwistedExtendedPoint ;
11
- use crate :: field:: { FieldElement , Scalar } ;
11
+ use crate :: field:: FieldElement ;
12
12
use crate :: * ;
13
13
use elliptic_curve:: {
14
14
CurveGroup , Error ,
@@ -339,7 +339,7 @@ impl PartialEq for EdwardsPoint {
339
339
impl Eq for EdwardsPoint { }
340
340
341
341
impl Group for EdwardsPoint {
342
- type Scalar = Scalar ;
342
+ type Scalar = EdwardsScalar ;
343
343
344
344
fn try_from_rng < R > ( rng : & mut R ) -> Result < Self , R :: Error >
345
345
where
@@ -508,9 +508,9 @@ impl From<&EdwardsPoint> for AffinePoint {
508
508
}
509
509
}
510
510
511
- impl < const N : usize > LinearCombination < [ ( EdwardsPoint , Scalar ) ; N ] > for EdwardsPoint { }
511
+ impl < const N : usize > LinearCombination < [ ( EdwardsPoint , EdwardsScalar ) ; N ] > for EdwardsPoint { }
512
512
513
- impl LinearCombination < [ ( EdwardsPoint , Scalar ) ] > for EdwardsPoint { }
513
+ impl LinearCombination < [ ( EdwardsPoint , EdwardsScalar ) ] > for EdwardsPoint { }
514
514
515
515
impl CurveGroup for EdwardsPoint {
516
516
type AffineRepr = AffinePoint ;
@@ -546,7 +546,7 @@ impl EdwardsPoint {
546
546
}
547
547
548
548
/// Generic scalar multiplication to compute s*P
549
- pub fn scalar_mul ( & self , scalar : & Scalar ) -> Self {
549
+ pub fn scalar_mul ( & self , scalar : & EdwardsScalar ) -> Self {
550
550
// Compute floor(s/4)
551
551
let mut scalar_div_four = * scalar;
552
552
scalar_div_four. div_by_four ( ) ;
@@ -558,7 +558,7 @@ impl EdwardsPoint {
558
558
}
559
559
560
560
/// Returns (scalar mod 4) * P in constant time
561
- pub ( crate ) fn scalar_mod_four ( & self , scalar : & Scalar ) -> Self {
561
+ pub ( crate ) fn scalar_mod_four ( & self , scalar : & EdwardsScalar ) -> Self {
562
562
// Compute compute (scalar mod 4)
563
563
let s_mod_four = scalar[ 0 ] & 3 ;
564
564
@@ -727,7 +727,7 @@ impl EdwardsPoint {
727
727
/// * `false` if `self` has a nonzero torsion component and is not
728
728
/// in the prime-order subgroup.
729
729
pub fn is_torsion_free ( & self ) -> Choice {
730
- ( self * BASEPOINT_ORDER ) . ct_eq ( & Self :: IDENTITY )
730
+ ( self * EDWARDS_BASEPOINT_ORDER ) . ct_eq ( & Self :: IDENTITY )
731
731
}
732
732
733
733
/// Hash a message to a point on the curve
@@ -972,28 +972,36 @@ impl Neg for EdwardsPoint {
972
972
// Scalar multiplication
973
973
// ------------------------------------------------------------------------
974
974
975
- impl < ' b > MulAssign < & ' b Scalar > for EdwardsPoint {
976
- fn mul_assign ( & mut self , scalar : & ' b Scalar ) {
975
+ impl < ' b > MulAssign < & ' b EdwardsScalar > for EdwardsPoint {
976
+ fn mul_assign ( & mut self , scalar : & ' b EdwardsScalar ) {
977
977
let result = * self * scalar;
978
978
* self = result;
979
979
}
980
980
}
981
981
982
- define_mul_assign_variants ! ( LHS = EdwardsPoint , RHS = Scalar ) ;
982
+ define_mul_assign_variants ! ( LHS = EdwardsPoint , RHS = EdwardsScalar ) ;
983
983
984
- define_mul_variants ! ( LHS = EdwardsPoint , RHS = Scalar , Output = EdwardsPoint ) ;
985
- define_mul_variants ! ( LHS = Scalar , RHS = EdwardsPoint , Output = EdwardsPoint ) ;
984
+ define_mul_variants ! (
985
+ LHS = EdwardsPoint ,
986
+ RHS = EdwardsScalar ,
987
+ Output = EdwardsPoint
988
+ ) ;
989
+ define_mul_variants ! (
990
+ LHS = EdwardsScalar ,
991
+ RHS = EdwardsPoint ,
992
+ Output = EdwardsPoint
993
+ ) ;
986
994
987
- impl Mul < & Scalar > for & EdwardsPoint {
995
+ impl Mul < & EdwardsScalar > for & EdwardsPoint {
988
996
type Output = EdwardsPoint ;
989
997
990
998
/// Scalar multiplication: compute `scalar * self`.
991
- fn mul ( self , scalar : & Scalar ) -> EdwardsPoint {
999
+ fn mul ( self , scalar : & EdwardsScalar ) -> EdwardsPoint {
992
1000
self . scalar_mul ( scalar)
993
1001
}
994
1002
}
995
1003
996
- impl Mul < & EdwardsPoint > for & Scalar {
1004
+ impl Mul < & EdwardsPoint > for & EdwardsScalar {
997
1005
type Output = EdwardsPoint ;
998
1006
999
1007
/// Scalar multiplication: compute `scalar * self`.
@@ -1295,24 +1303,24 @@ mod tests {
1295
1303
use rand_core:: SeedableRng ;
1296
1304
1297
1305
let mut rng = rand_chacha:: ChaCha8Rng :: seed_from_u64 ( 0 ) ;
1298
- let x = Scalar :: random ( & mut rng) ;
1299
- let b = Scalar :: random ( & mut rng) ;
1306
+ let x = EdwardsScalar :: random ( & mut rng) ;
1307
+ let b = EdwardsScalar :: random ( & mut rng) ;
1300
1308
1301
1309
let g1 = EdwardsPoint :: GENERATOR ;
1302
1310
let g2 = EdwardsPoint :: hash_with_defaults ( b"test_pow_add_mul" ) ;
1303
1311
1304
1312
let expected_commitment = g1 * x + g2 * b;
1305
1313
1306
- let shift = Scalar :: from ( 256u16 ) ;
1314
+ let shift = EdwardsScalar :: from ( 256u16 ) ;
1307
1315
let x_bytes = x. to_bytes_rfc_8032 ( ) ;
1308
- let mut sum = Scalar :: ZERO ;
1316
+ let mut sum = EdwardsScalar :: ZERO ;
1309
1317
let mut components = [ EdwardsPoint :: IDENTITY ; 57 ] ;
1310
1318
for i in 1 ..57 {
1311
- let r = Scalar :: random ( & mut rng) ;
1319
+ let r = EdwardsScalar :: random ( & mut rng) ;
1312
1320
sum += r * shift. pow ( [ i as u64 ] ) ;
1313
- components[ i] = g1 * Scalar :: from ( x_bytes[ i] ) + g2 * r;
1321
+ components[ i] = g1 * EdwardsScalar :: from ( x_bytes[ i] ) + g2 * r;
1314
1322
}
1315
- components[ 0 ] = g1 * Scalar :: from ( x_bytes[ 0 ] ) + g2 * ( b - sum) ;
1323
+ components[ 0 ] = g1 * EdwardsScalar :: from ( x_bytes[ 0 ] ) + g2 * ( b - sum) ;
1316
1324
1317
1325
let mut computed_commitment = EdwardsPoint :: IDENTITY ;
1318
1326
for i in ( 0 ..57 ) . rev ( ) {
0 commit comments