File tree Expand file tree Collapse file tree 6 files changed +66
-0
lines changed Expand file tree Collapse file tree 6 files changed +66
-0
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,30 @@ impl VartimePrecomputedStraus {
128128 }
129129 }
130130
131+ pub fn len ( & self ) -> usize {
132+ use crate :: traits:: VartimePrecomputedMultiscalarMul ;
133+
134+ match self {
135+ #[ cfg( curve25519_dalek_backend = "simd" ) ]
136+ VartimePrecomputedStraus :: Avx2 ( inner) => inner. len ( ) ,
137+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
138+ VartimePrecomputedStraus :: Avx512ifma ( inner) => inner. len ( ) ,
139+ VartimePrecomputedStraus :: Scalar ( inner) => inner. len ( ) ,
140+ }
141+ }
142+
143+ pub fn is_empty ( & self ) -> bool {
144+ use crate :: traits:: VartimePrecomputedMultiscalarMul ;
145+
146+ match self {
147+ #[ cfg( curve25519_dalek_backend = "simd" ) ]
148+ VartimePrecomputedStraus :: Avx2 ( inner) => inner. is_empty ( ) ,
149+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
150+ VartimePrecomputedStraus :: Avx512ifma ( inner) => inner. is_empty ( ) ,
151+ VartimePrecomputedStraus :: Scalar ( inner) => inner. is_empty ( ) ,
152+ }
153+ }
154+
131155 pub fn optional_mixed_multiscalar_mul < I , J , K > (
132156 & self ,
133157 static_scalars : I ,
Original file line number Diff line number Diff line change @@ -46,6 +46,14 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
4646 }
4747 }
4848
49+ fn len ( & self ) -> usize {
50+ self . static_lookup_tables . len ( )
51+ }
52+
53+ fn is_empty ( & self ) -> bool {
54+ self . static_lookup_tables . is_empty ( )
55+ }
56+
4957 fn optional_mixed_multiscalar_mul < I , J , K > (
5058 & self ,
5159 static_scalars : I ,
Original file line number Diff line number Diff line change @@ -54,6 +54,14 @@ pub mod spec {
5454 }
5555 }
5656
57+ fn len ( & self ) -> usize {
58+ self . static_lookup_tables . len ( )
59+ }
60+
61+ fn is_empty ( & self ) -> bool {
62+ self . static_lookup_tables . is_empty ( )
63+ }
64+
5765 fn optional_mixed_multiscalar_mul < I , J , K > (
5866 & self ,
5967 static_scalars : I ,
Original file line number Diff line number Diff line change @@ -879,6 +879,14 @@ impl VartimePrecomputedMultiscalarMul for VartimeEdwardsPrecomputation {
879879 Self ( crate :: backend:: VartimePrecomputedStraus :: new ( static_points) )
880880 }
881881
882+ fn len ( & self ) -> usize {
883+ self . 0 . len ( )
884+ }
885+
886+ fn is_empty ( & self ) -> bool {
887+ self . 0 . is_empty ( )
888+ }
889+
882890 fn optional_mixed_multiscalar_mul < I , J , K > (
883891 & self ,
884892 static_scalars : I ,
@@ -2136,6 +2144,8 @@ mod test {
21362144
21372145 let precomputation = VartimeEdwardsPrecomputation :: new ( static_points. iter ( ) ) ;
21382146
2147+ assert_eq ! ( precomputation. len( ) , 128 ) ;
2148+
21392149 let P = precomputation. vartime_mixed_multiscalar_mul (
21402150 & static_scalars,
21412151 & dynamic_scalars,
Original file line number Diff line number Diff line change @@ -1027,6 +1027,14 @@ impl VartimePrecomputedMultiscalarMul for VartimeRistrettoPrecomputation {
10271027 ) )
10281028 }
10291029
1030+ fn len ( & self ) -> usize {
1031+ self . 0 . len ( )
1032+ }
1033+
1034+ fn is_empty ( & self ) -> bool {
1035+ self . 0 . is_empty ( )
1036+ }
1037+
10301038 fn optional_mixed_multiscalar_mul < I , J , K > (
10311039 & self ,
10321040 static_scalars : I ,
@@ -1852,6 +1860,8 @@ mod test {
18521860
18531861 let precomputation = VartimeRistrettoPrecomputation :: new ( static_points. iter ( ) ) ;
18541862
1863+ assert_eq ! ( precomputation. len( ) , 128 ) ;
1864+
18551865 let P = precomputation. vartime_mixed_multiscalar_mul (
18561866 & static_scalars,
18571867 & dynamic_scalars,
Original file line number Diff line number Diff line change @@ -299,6 +299,12 @@ pub trait VartimePrecomputedMultiscalarMul: Sized {
299299 I : IntoIterator ,
300300 I :: Item : Borrow < Self :: Point > ;
301301
302+ /// Return the number of static points in the precomputation.
303+ fn len ( & self ) -> usize ;
304+
305+ /// Determine if the precomputation is empty.
306+ fn is_empty ( & self ) -> bool ;
307+
302308 /// Given `static_scalars`, an iterator of public scalars
303309 /// \\(b_i\\), compute
304310 /// $$
You can’t perform that action at this time.
0 commit comments