@@ -44,16 +44,22 @@ pub mod vector;
44
44
45
45
#[ derive( Copy , Clone ) ]
46
46
enum BackendKind {
47
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
47
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
48
48
Avx2 ,
49
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
49
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
50
50
Avx512 ,
51
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
52
+ Neon ,
51
53
Serial ,
52
54
}
53
55
54
56
#[ inline]
55
57
fn get_selected_backend ( ) -> BackendKind {
56
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
58
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
59
+ {
60
+ return BackendKind :: Neon ;
61
+ }
62
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="x86_64" ) ) ]
57
63
{
58
64
cpufeatures:: new!( cpuid_avx512, "avx512ifma" , "avx512vl" ) ;
59
65
let token_avx512: cpuid_avx512:: InitToken = cpuid_avx512:: init ( ) ;
@@ -62,7 +68,7 @@ fn get_selected_backend() -> BackendKind {
62
68
}
63
69
}
64
70
65
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
71
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
66
72
{
67
73
cpufeatures:: new!( cpuid_avx2, "avx2" ) ;
68
74
let token_avx2: cpuid_avx2:: InitToken = cpuid_avx2:: init ( ) ;
@@ -85,25 +91,32 @@ where
85
91
use crate :: traits:: VartimeMultiscalarMul ;
86
92
87
93
match get_selected_backend ( ) {
88
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
94
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
89
95
BackendKind :: Avx2 =>
90
96
self :: vector:: scalar_mul:: pippenger:: spec_avx2:: Pippenger :: optional_multiscalar_mul :: < I , J > ( scalars, points) ,
91
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
97
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
92
98
BackendKind :: Avx512 =>
93
99
self :: vector:: scalar_mul:: pippenger:: spec_avx512ifma_avx512vl:: Pippenger :: optional_multiscalar_mul :: < I , J > ( scalars, points) ,
100
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
101
+ BackendKind :: Neon =>
102
+ self :: vector:: scalar_mul:: pippenger:: spec_neon:: Pippenger :: optional_multiscalar_mul :: < I , J > ( scalars, points) ,
94
103
BackendKind :: Serial =>
95
104
self :: serial:: scalar_mul:: pippenger:: Pippenger :: optional_multiscalar_mul :: < I , J > ( scalars, points) ,
96
105
}
97
106
}
98
107
99
108
#[ cfg( feature = "alloc" ) ]
100
109
pub ( crate ) enum VartimePrecomputedStraus {
101
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
110
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
102
111
Avx2 ( self :: vector:: scalar_mul:: precomputed_straus:: spec_avx2:: VartimePrecomputedStraus ) ,
103
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
112
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
104
113
Avx512ifma (
105
114
self :: vector:: scalar_mul:: precomputed_straus:: spec_avx512ifma_avx512vl:: VartimePrecomputedStraus ,
106
115
) ,
116
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
117
+ Neon (
118
+ self :: vector:: scalar_mul:: precomputed_straus:: spec_neon:: VartimePrecomputedStraus
119
+ ) ,
107
120
Scalar ( self :: serial:: scalar_mul:: precomputed_straus:: VartimePrecomputedStraus ) ,
108
121
}
109
122
@@ -117,12 +130,15 @@ impl VartimePrecomputedStraus {
117
130
use crate :: traits:: VartimePrecomputedMultiscalarMul ;
118
131
119
132
match get_selected_backend ( ) {
120
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
133
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
121
134
BackendKind :: Avx2 =>
122
135
VartimePrecomputedStraus :: Avx2 ( self :: vector:: scalar_mul:: precomputed_straus:: spec_avx2:: VartimePrecomputedStraus :: new ( static_points) ) ,
123
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
136
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
124
137
BackendKind :: Avx512 =>
125
138
VartimePrecomputedStraus :: Avx512ifma ( self :: vector:: scalar_mul:: precomputed_straus:: spec_avx512ifma_avx512vl:: VartimePrecomputedStraus :: new ( static_points) ) ,
139
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
140
+ BackendKind :: Neon =>
141
+ VartimePrecomputedStraus :: Neon ( self :: vector:: scalar_mul:: precomputed_straus:: spec_neon:: VartimePrecomputedStraus :: new ( static_points) ) ,
126
142
BackendKind :: Serial =>
127
143
VartimePrecomputedStraus :: Scalar ( self :: serial:: scalar_mul:: precomputed_straus:: VartimePrecomputedStraus :: new ( static_points) )
128
144
}
@@ -144,18 +160,24 @@ impl VartimePrecomputedStraus {
144
160
use crate :: traits:: VartimePrecomputedMultiscalarMul ;
145
161
146
162
match self {
147
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
163
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
148
164
VartimePrecomputedStraus :: Avx2 ( inner) => inner. optional_mixed_multiscalar_mul (
149
165
static_scalars,
150
166
dynamic_scalars,
151
167
dynamic_points,
152
168
) ,
153
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
169
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
154
170
VartimePrecomputedStraus :: Avx512ifma ( inner) => inner. optional_mixed_multiscalar_mul (
155
171
static_scalars,
156
172
dynamic_scalars,
157
173
dynamic_points,
158
174
) ,
175
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
176
+ VartimePrecomputedStraus :: Neon ( inner) => inner. optional_mixed_multiscalar_mul (
177
+ static_scalars,
178
+ dynamic_scalars,
179
+ dynamic_points,
180
+ ) ,
159
181
VartimePrecomputedStraus :: Scalar ( inner) => inner. optional_mixed_multiscalar_mul (
160
182
static_scalars,
161
183
dynamic_scalars,
@@ -177,19 +199,25 @@ where
177
199
use crate :: traits:: MultiscalarMul ;
178
200
179
201
match get_selected_backend ( ) {
180
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
202
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
181
203
BackendKind :: Avx2 => {
182
204
self :: vector:: scalar_mul:: straus:: spec_avx2:: Straus :: multiscalar_mul :: < I , J > (
183
205
scalars, points,
184
206
)
185
207
}
186
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
208
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
187
209
BackendKind :: Avx512 => {
188
210
self :: vector:: scalar_mul:: straus:: spec_avx512ifma_avx512vl:: Straus :: multiscalar_mul :: <
189
211
I ,
190
212
J ,
191
213
> ( scalars, points)
192
214
}
215
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
216
+ BackendKind :: Neon => {
217
+ self :: vector:: scalar_mul:: straus:: spec_neon:: Straus :: multiscalar_mul :: < I , J > (
218
+ scalars, points,
219
+ )
220
+ }
193
221
BackendKind :: Serial => {
194
222
self :: serial:: scalar_mul:: straus:: Straus :: multiscalar_mul :: < I , J > ( scalars, points)
195
223
}
@@ -207,19 +235,25 @@ where
207
235
use crate :: traits:: VartimeMultiscalarMul ;
208
236
209
237
match get_selected_backend ( ) {
210
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
238
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
211
239
BackendKind :: Avx2 => {
212
240
self :: vector:: scalar_mul:: straus:: spec_avx2:: Straus :: optional_multiscalar_mul :: < I , J > (
213
241
scalars, points,
214
242
)
215
243
}
216
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
244
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
217
245
BackendKind :: Avx512 => {
218
246
self :: vector:: scalar_mul:: straus:: spec_avx512ifma_avx512vl:: Straus :: optional_multiscalar_mul :: <
219
247
I ,
220
248
J ,
221
249
> ( scalars, points)
222
250
}
251
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
252
+ BackendKind :: Neon => {
253
+ self :: vector:: scalar_mul:: straus:: spec_neon:: Straus :: optional_multiscalar_mul :: < I , J > (
254
+ scalars, points
255
+ )
256
+ }
223
257
BackendKind :: Serial => {
224
258
self :: serial:: scalar_mul:: straus:: Straus :: optional_multiscalar_mul :: < I , J > (
225
259
scalars, points,
@@ -231,12 +265,14 @@ where
231
265
/// Perform constant-time, variable-base scalar multiplication.
232
266
pub fn variable_base_mul ( point : & EdwardsPoint , scalar : & Scalar ) -> EdwardsPoint {
233
267
match get_selected_backend ( ) {
234
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
268
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
235
269
BackendKind :: Avx2 => self :: vector:: scalar_mul:: variable_base:: spec_avx2:: mul ( point, scalar) ,
236
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
270
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
237
271
BackendKind :: Avx512 => {
238
272
self :: vector:: scalar_mul:: variable_base:: spec_avx512ifma_avx512vl:: mul ( point, scalar)
239
273
}
274
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
275
+ BackendKind :: Neon => self :: vector:: scalar_mul:: variable_base:: spec_neon:: mul ( point, scalar) ,
240
276
BackendKind :: Serial => self :: serial:: scalar_mul:: variable_base:: mul ( point, scalar) ,
241
277
}
242
278
}
@@ -245,12 +281,14 @@ pub fn variable_base_mul(point: &EdwardsPoint, scalar: &Scalar) -> EdwardsPoint
245
281
#[ allow( non_snake_case) ]
246
282
pub fn vartime_double_base_mul ( a : & Scalar , A : & EdwardsPoint , b : & Scalar ) -> EdwardsPoint {
247
283
match get_selected_backend ( ) {
248
- #[ cfg( curve25519_dalek_backend = "simd" ) ]
284
+ #[ cfg( all ( curve25519_dalek_backend = "simd" , target_arch= "x86_64" ) ) ]
249
285
BackendKind :: Avx2 => self :: vector:: scalar_mul:: vartime_double_base:: spec_avx2:: mul ( a, A , b) ,
250
- #[ cfg( all( curve25519_dalek_backend = "simd" , nightly) ) ]
286
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch= "x86_64" ) ) ]
251
287
BackendKind :: Avx512 => {
252
288
self :: vector:: scalar_mul:: vartime_double_base:: spec_avx512ifma_avx512vl:: mul ( a, A , b)
253
289
}
290
+ #[ cfg( all( curve25519_dalek_backend = "simd" , nightly, target_arch="aarch64" ) ) ]
291
+ BackendKind :: Neon => self :: vector:: scalar_mul:: vartime_double_base:: spec_neon:: mul ( a, A , b) ,
254
292
BackendKind :: Serial => self :: serial:: scalar_mul:: vartime_double_base:: mul ( a, A , b) ,
255
293
}
256
294
}
0 commit comments