File tree 6 files changed +70
-0
lines changed
6 files changed +70
-0
lines changed Original file line number Diff line number Diff line change @@ -128,6 +128,32 @@ impl VartimePrecomputedStraus {
128
128
}
129
129
}
130
130
131
+ /// Return the number of static points in the precomputation.
132
+ pub fn len ( & self ) -> usize {
133
+ use crate :: traits:: VartimePrecomputedMultiscalarMul ;
134
+
135
+ match self {
136
+ #[ cfg( curve25519_dalek_backend = "simd" ) ]
137
+ VartimePrecomputedStraus :: Avx2 ( inner) => inner. len ( ) ,
138
+ #[ cfg( all( curve25519_dalek_backend = "unstable_avx512" , nightly) ) ]
139
+ VartimePrecomputedStraus :: Avx512ifma ( inner) => inner. len ( ) ,
140
+ VartimePrecomputedStraus :: Scalar ( inner) => inner. len ( ) ,
141
+ }
142
+ }
143
+
144
+ /// Determine if the precomputation is empty.
145
+ pub fn is_empty ( & self ) -> bool {
146
+ use crate :: traits:: VartimePrecomputedMultiscalarMul ;
147
+
148
+ match self {
149
+ #[ cfg( curve25519_dalek_backend = "simd" ) ]
150
+ VartimePrecomputedStraus :: Avx2 ( inner) => inner. is_empty ( ) ,
151
+ #[ cfg( all( curve25519_dalek_backend = "unstable_avx512" , nightly) ) ]
152
+ VartimePrecomputedStraus :: Avx512ifma ( inner) => inner. is_empty ( ) ,
153
+ VartimePrecomputedStraus :: Scalar ( inner) => inner. is_empty ( ) ,
154
+ }
155
+ }
156
+
131
157
pub fn optional_mixed_multiscalar_mul < I , J , K > (
132
158
& self ,
133
159
static_scalars : I ,
Original file line number Diff line number Diff line change @@ -46,6 +46,14 @@ impl VartimePrecomputedMultiscalarMul for VartimePrecomputedStraus {
46
46
}
47
47
}
48
48
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
+
49
57
fn optional_mixed_multiscalar_mul < I , J , K > (
50
58
& self ,
51
59
static_scalars : I ,
Original file line number Diff line number Diff line change @@ -57,6 +57,14 @@ pub mod spec {
57
57
}
58
58
}
59
59
60
+ fn len ( & self ) -> usize {
61
+ self . static_lookup_tables . len ( )
62
+ }
63
+
64
+ fn is_empty ( & self ) -> bool {
65
+ self . static_lookup_tables . is_empty ( )
66
+ }
67
+
60
68
fn optional_mixed_multiscalar_mul < I , J , K > (
61
69
& self ,
62
70
static_scalars : I ,
Original file line number Diff line number Diff line change @@ -879,6 +879,14 @@ impl VartimePrecomputedMultiscalarMul for VartimeEdwardsPrecomputation {
879
879
Self ( crate :: backend:: VartimePrecomputedStraus :: new ( static_points) )
880
880
}
881
881
882
+ fn len ( & self ) -> usize {
883
+ self . 0 . len ( )
884
+ }
885
+
886
+ fn is_empty ( & self ) -> bool {
887
+ self . 0 . is_empty ( )
888
+ }
889
+
882
890
fn optional_mixed_multiscalar_mul < I , J , K > (
883
891
& self ,
884
892
static_scalars : I ,
@@ -2136,6 +2144,9 @@ mod test {
2136
2144
2137
2145
let precomputation = VartimeEdwardsPrecomputation :: new ( static_points. iter ( ) ) ;
2138
2146
2147
+ assert_eq ! ( precomputation. len( ) , 128 ) ;
2148
+ assert ! ( !precomputation. is_empty( ) ) ;
2149
+
2139
2150
let P = precomputation. vartime_mixed_multiscalar_mul (
2140
2151
& static_scalars,
2141
2152
& dynamic_scalars,
Original file line number Diff line number Diff line change @@ -1027,6 +1027,14 @@ impl VartimePrecomputedMultiscalarMul for VartimeRistrettoPrecomputation {
1027
1027
) )
1028
1028
}
1029
1029
1030
+ fn len ( & self ) -> usize {
1031
+ self . 0 . len ( )
1032
+ }
1033
+
1034
+ fn is_empty ( & self ) -> bool {
1035
+ self . 0 . is_empty ( )
1036
+ }
1037
+
1030
1038
fn optional_mixed_multiscalar_mul < I , J , K > (
1031
1039
& self ,
1032
1040
static_scalars : I ,
@@ -1852,6 +1860,9 @@ mod test {
1852
1860
1853
1861
let precomputation = VartimeRistrettoPrecomputation :: new ( static_points. iter ( ) ) ;
1854
1862
1863
+ assert_eq ! ( precomputation. len( ) , 128 ) ;
1864
+ assert ! ( !precomputation. is_empty( ) ) ;
1865
+
1855
1866
let P = precomputation. vartime_mixed_multiscalar_mul (
1856
1867
& static_scalars,
1857
1868
& dynamic_scalars,
Original file line number Diff line number Diff line change @@ -299,6 +299,12 @@ pub trait VartimePrecomputedMultiscalarMul: Sized {
299
299
I : IntoIterator ,
300
300
I :: Item : Borrow < Self :: Point > ;
301
301
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
+
302
308
/// Given `static_scalars`, an iterator of public scalars
303
309
/// \\(b_i\\), compute
304
310
/// $$
You can’t perform that action at this time.
0 commit comments