@@ -15,7 +15,7 @@ mod precomp;
15
15
#[ derive( Clone , Debug ) ]
16
16
pub struct PublicKey {
17
17
point : AffineMontPoint ,
18
- precomp_wnaf_5 : JacobianMontPointTableW5 ,
18
+ precomp_w5 : JacobianMontPointTableW5 ,
19
19
}
20
20
21
21
impl PublicKey {
@@ -40,7 +40,7 @@ impl PublicKey {
40
40
41
41
fn from_affine ( point : AffineMontPoint ) -> Self {
42
42
Self {
43
- precomp_wnaf_5 : point. public_precomp_wnaf_5 ( ) ,
43
+ precomp_w5 : point. public_precomp_w5 ( ) ,
44
44
point,
45
45
}
46
46
}
@@ -54,7 +54,7 @@ impl PublicKey {
54
54
// 5. Compute: R = (xR, yR) = u1 G + u2 QU
55
55
// If R = O, output "invalid" and stop.
56
56
let lhs = JacobianMontPoint :: public_base_multiply ( & u1) ;
57
- let rhs = JacobianMontPoint :: public_multiply_wnaf_5 ( & u2, & self . precomp_wnaf_5 ) ;
57
+ let rhs = JacobianMontPoint :: public_multiply_w5 ( & u2, & self . precomp_w5 ) ;
58
58
59
59
// nb. if lhs == rhs, then we need a doubling rather than addition
60
60
// (even complete point addition formula is only defined for P != Q)
@@ -109,8 +109,7 @@ impl PrivateKey {
109
109
/// Returns a [`SharedSecret`]. May return an error in fault conditions.
110
110
pub fn diffie_hellman ( self , peer : & PublicKey ) -> Result < SharedSecret , Error > {
111
111
let _entry = low:: Entry :: new_secret ( ) ;
112
- let result =
113
- JacobianMontPoint :: multiply_wnaf_5 ( & self . scalar , & peer. precomp_wnaf_5 ) . as_affine ( ) ;
112
+ let result = JacobianMontPoint :: multiply_w5 ( & self . scalar , & peer. precomp_w5 ) . as_affine ( ) ;
114
113
match result. on_curve ( ) {
115
114
true => Ok ( SharedSecret ( util:: u64x4_to_big_endian (
116
115
& result. x ( ) . demont ( ) . 0 ,
@@ -351,18 +350,19 @@ impl AffineMontPoint {
351
350
self . xy [ Self :: Y ] . copy_from_slice ( & result. 0 ) ;
352
351
}
353
352
354
- /// Precomputes wNAF form (with 𝑤=6) for the point `self`
353
+ /// Precomputes a table (with 𝑤=6) for the point `self`
355
354
///
356
355
/// 64 is the row size, 2**6.
357
- /// 37 is the table height, ceil(256/7) (wNAF gives us one bit
358
- /// extra free, in exchange for a negation to compute a negative
359
- /// point from the precomputed positive point -- this is ~free).
356
+ /// 37 is the table height, ceil(256/7) (Booth encoding gives us
357
+ /// one bit extra free, in exchange for a negation to compute a
358
+ /// negative point from the precomputed positive point -- this is
359
+ /// ~free).
360
360
///
361
361
/// This should not be used at runtime, since (for brevity) it
362
362
/// does excessive point representation conversions, and recomputes
363
- /// items in a given row several times (compare `public_precomp_wnaf_5 `).
363
+ /// items in a given row several times (compare `public_precomp_w5 `).
364
364
#[ cfg( test) ]
365
- fn public_precomp_wnaf_7_slow ( & self ) -> [ [ Self ; 64 ] ; 37 ] {
365
+ fn public_precomp_w7_slow ( & self ) -> [ [ Self ; 64 ] ; 37 ] {
366
366
let mut r = [ [ Self :: default ( ) ; 64 ] ; 37 ] ;
367
367
368
368
for window in 0 ..( ( 256 + 6 ) / 7 ) {
@@ -382,7 +382,7 @@ impl AffineMontPoint {
382
382
r
383
383
}
384
384
385
- fn public_precomp_wnaf_5 ( & self ) -> JacobianMontPointTableW5 {
385
+ fn public_precomp_w5 ( & self ) -> JacobianMontPointTableW5 {
386
386
let mut r = [ JacobianMontPoint :: zero ( ) ; 16 ] ;
387
387
388
388
// indices into r are intuitively 1-based; index i contains i * G,
@@ -491,17 +491,14 @@ impl JacobianMontPoint {
491
491
}
492
492
493
493
fn base_multiply ( scalar : & Scalar ) -> Self {
494
- Self :: multiply_wnaf_7 :: < true > ( scalar, & precomp:: CURVE_GENERATOR_PRECOMP_WNAF_7 )
494
+ Self :: multiply_w7 :: < true > ( scalar, & precomp:: CURVE_GENERATOR_PRECOMP_W7 )
495
495
}
496
496
497
497
fn public_base_multiply ( scalar : & Scalar ) -> Self {
498
- Self :: multiply_wnaf_7 :: < false > ( scalar, & precomp:: CURVE_GENERATOR_PRECOMP_WNAF_7 )
498
+ Self :: multiply_w7 :: < false > ( scalar, & precomp:: CURVE_GENERATOR_PRECOMP_W7 )
499
499
}
500
500
501
- fn multiply_wnaf_7 < const SECRET : bool > (
502
- scalar : & Scalar ,
503
- precomp : & AffineMontPointTableW7 ,
504
- ) -> Self {
501
+ fn multiply_w7 < const SECRET : bool > ( scalar : & Scalar , precomp : & AffineMontPointTableW7 ) -> Self {
505
502
let mut terms = scalar. booth_recoded_w7 ( ) ;
506
503
// unwrap: number of terms is constant
507
504
let ( digit, sign) = terms. next ( ) . unwrap ( ) ;
@@ -545,15 +542,15 @@ impl JacobianMontPoint {
545
542
result
546
543
}
547
544
548
- fn multiply_wnaf_5 ( scalar : & Scalar , precomp : & JacobianMontPointTableW5 ) -> Self {
549
- Self :: _multiply_wnaf_5 :: < true > ( scalar, precomp)
545
+ fn multiply_w5 ( scalar : & Scalar , precomp : & JacobianMontPointTableW5 ) -> Self {
546
+ Self :: _multiply_w5 :: < true > ( scalar, precomp)
550
547
}
551
548
552
- fn public_multiply_wnaf_5 ( scalar : & Scalar , precomp : & JacobianMontPointTableW5 ) -> Self {
553
- Self :: _multiply_wnaf_5 :: < false > ( scalar, precomp)
549
+ fn public_multiply_w5 ( scalar : & Scalar , precomp : & JacobianMontPointTableW5 ) -> Self {
550
+ Self :: _multiply_w5 :: < false > ( scalar, precomp)
554
551
}
555
552
556
- fn _multiply_wnaf_5 < const SECRET : bool > (
553
+ fn _multiply_w5 < const SECRET : bool > (
557
554
scalar : & Scalar ,
558
555
precomp : & JacobianMontPointTableW5 ,
559
556
) -> Self {
@@ -1256,12 +1253,10 @@ mod tests {
1256
1253
}
1257
1254
1258
1255
#[ test]
1259
- fn base_point_precomp_wnaf_7 ( ) {
1260
- let precomp = CURVE_GENERATOR . public_precomp_wnaf_7_slow ( ) ;
1256
+ fn base_point_precomp_w7 ( ) {
1257
+ let precomp = CURVE_GENERATOR . public_precomp_w7_slow ( ) ;
1261
1258
1262
- println ! (
1263
- "pub(super) static CURVE_GENERATOR_PRECOMP_WNAF_7: super::AffineMontPointTableW7 = ["
1264
- ) ;
1259
+ println ! ( "pub(super) static CURVE_GENERATOR_PRECOMP_W7: super::AffineMontPointTableW7 = [" ) ;
1265
1260
for w in 0 ..37 {
1266
1261
println ! ( " // 1G..64G << {}" , w * 7 ) ;
1267
1262
println ! ( " [" ) ;
0 commit comments