@@ -8,15 +8,18 @@ use elliptic_curve::{
88 consts:: U32 ,
99 group:: { GroupEncoding , ff:: PrimeField } ,
1010 ops:: { LinearCombination , Reduce , ReduceNonZero } ,
11- point:: NonIdentity ,
11+ point:: { AffineCoordinates , NonIdentity } ,
1212 sec1:: { self , ToSec1Point } ,
1313} ;
1414use p256:: {
1515 AffinePoint , FieldBytes , NonZeroScalar , ProjectivePoint , Scalar ,
1616 test_vectors:: group:: { ADD_TEST_VECTORS , MUL_TEST_VECTORS } ,
1717} ;
1818use primeorder:: test_projective_arithmetic;
19- use proptest:: { prelude:: any, prop_compose, proptest} ;
19+ use proptest:: { prelude:: * , prop_compose, proptest} ;
20+
21+ #[ cfg( feature = "alloc" ) ]
22+ use elliptic_curve:: group:: Wnaf ;
2023
2124test_projective_arithmetic ! (
2225 AffinePoint ,
@@ -26,6 +29,26 @@ test_projective_arithmetic!(
2629 MUL_TEST_VECTORS
2730) ;
2831
32+ #[ cfg( feature = "alloc" ) ]
33+ #[ test]
34+ fn wnaf ( ) {
35+ for ( k, coords) in ADD_TEST_VECTORS . iter ( ) . enumerate ( ) {
36+ let scalar = Scalar :: from ( k as u64 + 1 ) ;
37+ dbg ! ( & scalar, coords) ;
38+
39+ let mut wnaf = Wnaf :: new ( ) ;
40+ // let p = wnaf
41+ // .scalar(&scalar)
42+ // .base(ProjectivePoint::GENERATOR)
43+ // .to_affine();
44+ let mut wnaf_base = wnaf. base ( ProjectivePoint :: GENERATOR , 1 ) ;
45+ let p = wnaf_base. scalar ( & scalar) . to_affine ( ) ;
46+
47+ let ( x, _y) = ( p. x ( ) , p. y ( ) ) ;
48+ assert_eq ! ( x. 0 , coords. 0 ) ;
49+ }
50+ }
51+
2952#[ test]
3053fn projective_identity_to_bytes ( ) {
3154 // This is technically an invalid SEC1 encoding, but is preferable to panicking.
@@ -52,6 +75,17 @@ prop_compose! {
5275
5376// TODO: move to `primeorder::test_projective_arithmetic`.
5477proptest ! {
78+ #[ cfg( feature = "alloc" ) ]
79+ #[ test]
80+ fn wnaf_proptest(
81+ point in projective( ) ,
82+ scalar in scalar( ) ,
83+ ) {
84+ let result = point * scalar;
85+ let wnaf_result = Wnaf :: new( ) . scalar( & scalar) . base( point) ;
86+ prop_assert_eq!( result. to_affine( ) , wnaf_result. to_affine( ) ) ;
87+ }
88+
5589 #[ test]
5690 fn batch_normalize(
5791 a in non_identity( ) ,
0 commit comments