@@ -15,6 +15,7 @@ pub(crate) fn create(seed: PotSeed, key: PotKey, checkpoint_iterations: u32) ->
15
15
{
16
16
cpufeatures:: new!( has_aes, "aes" ) ;
17
17
if has_aes:: get ( ) {
18
+ // SAFETY: Checked `aes` feature
18
19
return unsafe { x86_64:: create ( seed. as_ref ( ) , key. as_ref ( ) , checkpoint_iterations) } ;
19
20
}
20
21
}
@@ -51,6 +52,47 @@ pub(crate) fn verify_sequential(
51
52
) -> bool {
52
53
assert_eq ! ( checkpoint_iterations % 2 , 0 ) ;
53
54
55
+ #[ cfg( target_arch = "x86_64" ) ]
56
+ {
57
+ cpufeatures:: new!( has_avx512f_vaes, "avx512f" , "vaes" ) ;
58
+ if has_avx512f_vaes:: get ( ) {
59
+ // SAFETY: Checked `avx512f` and `vaes` features
60
+ return unsafe {
61
+ x86_64:: verify_sequential_avx512f_vaes (
62
+ & seed,
63
+ & key,
64
+ checkpoints,
65
+ checkpoint_iterations,
66
+ )
67
+ } ;
68
+ }
69
+
70
+ cpufeatures:: new!( has_avx2_vaes, "avx2" , "vaes" ) ;
71
+ if has_avx2_vaes:: get ( ) {
72
+ // SAFETY: Checked `avx2` and `vaes` features
73
+ return unsafe {
74
+ x86_64:: verify_sequential_avx2_vaes ( & seed, & key, checkpoints, checkpoint_iterations)
75
+ } ;
76
+ }
77
+
78
+ cpufeatures:: new!( has_aes_sse41, "aes" , "sse4.1" ) ;
79
+ if has_aes_sse41:: get ( ) {
80
+ // SAFETY: Checked `aes` and `sse4.1` features
81
+ return unsafe {
82
+ x86_64:: verify_sequential_aes_sse41 ( & seed, & key, checkpoints, checkpoint_iterations)
83
+ } ;
84
+ }
85
+ }
86
+
87
+ verify_sequential_generic ( seed, key, checkpoints, checkpoint_iterations)
88
+ }
89
+
90
+ fn verify_sequential_generic (
91
+ seed : PotSeed ,
92
+ key : PotKey ,
93
+ checkpoints : & PotCheckpoints ,
94
+ checkpoint_iterations : u32 ,
95
+ ) -> bool {
54
96
let key = Array :: from ( * key) ;
55
97
let cipher = Aes128 :: new ( & key) ;
56
98
@@ -94,6 +136,65 @@ mod tests {
94
136
] ;
95
137
const BAD_CIPHER : [ u8 ; 16 ] = [ 22 ; 16 ] ;
96
138
139
+ fn verify_test (
140
+ seed : PotSeed ,
141
+ key : PotKey ,
142
+ checkpoints : & PotCheckpoints ,
143
+ checkpoint_iterations : u32 ,
144
+ ) -> bool {
145
+ let sequential = verify_sequential ( seed, key, checkpoints, checkpoint_iterations) ;
146
+ let sequential_generic =
147
+ verify_sequential_generic ( seed, key, checkpoints, checkpoint_iterations) ;
148
+ assert_eq ! ( sequential, sequential_generic) ;
149
+
150
+ #[ cfg( target_arch = "x86_64" ) ]
151
+ {
152
+ cpufeatures:: new!( has_avx512f_vaes, "avx512f" , "vaes" ) ;
153
+ if has_avx512f_vaes:: get ( ) {
154
+ // SAFETY: Checked `avx512f` and `vaes` features
155
+ let avx512f_vaes = unsafe {
156
+ x86_64:: verify_sequential_avx512f_vaes (
157
+ & seed,
158
+ & key,
159
+ checkpoints,
160
+ checkpoint_iterations,
161
+ )
162
+ } ;
163
+ assert_eq ! ( sequential, avx512f_vaes) ;
164
+ }
165
+
166
+ cpufeatures:: new!( has_avx2_vaes, "avx2" , "vaes" ) ;
167
+ if has_avx2_vaes:: get ( ) {
168
+ // SAFETY: Checked `avx2` and `vaes` features
169
+ let avx2_vaes = unsafe {
170
+ x86_64:: verify_sequential_avx2_vaes (
171
+ & seed,
172
+ & key,
173
+ checkpoints,
174
+ checkpoint_iterations,
175
+ )
176
+ } ;
177
+ assert_eq ! ( sequential, avx2_vaes) ;
178
+ }
179
+
180
+ cpufeatures:: new!( has_aes_sse41, "aes" , "sse4.1" ) ;
181
+ if has_aes_sse41:: get ( ) {
182
+ // SAFETY: Checked `aes` and `sse4.1` features
183
+ let aes = unsafe {
184
+ x86_64:: verify_sequential_aes_sse41 (
185
+ & seed,
186
+ & key,
187
+ checkpoints,
188
+ checkpoint_iterations,
189
+ )
190
+ } ;
191
+ assert_eq ! ( sequential, aes) ;
192
+ }
193
+ }
194
+
195
+ sequential
196
+ }
197
+
97
198
#[ test]
98
199
fn test_create_verify ( ) {
99
200
let seed = PotSeed :: from ( SEED ) ;
@@ -107,47 +208,42 @@ mod tests {
107
208
assert_eq ! ( checkpoints, generic_checkpoints) ;
108
209
}
109
210
110
- assert ! ( verify_sequential(
111
- seed,
112
- key,
113
- & checkpoints,
114
- checkpoint_iterations,
115
- ) ) ;
211
+ assert ! ( verify_test( seed, key, & checkpoints, checkpoint_iterations, ) ) ;
116
212
117
213
// Decryption of invalid cipher text fails.
118
214
let mut checkpoints_1 = checkpoints;
119
215
checkpoints_1[ 0 ] = PotOutput :: from ( BAD_CIPHER ) ;
120
- assert ! ( !verify_sequential (
216
+ assert ! ( !verify_test (
121
217
seed,
122
218
key,
123
219
& checkpoints_1,
124
220
checkpoint_iterations,
125
221
) ) ;
126
222
127
223
// Decryption with wrong number of iterations fails.
128
- assert ! ( !verify_sequential (
224
+ assert ! ( !verify_test (
129
225
seed,
130
226
key,
131
227
& checkpoints,
132
228
checkpoint_iterations + 2 ,
133
229
) ) ;
134
- assert ! ( !verify_sequential (
230
+ assert ! ( !verify_test (
135
231
seed,
136
232
key,
137
233
& checkpoints,
138
234
checkpoint_iterations - 2 ,
139
235
) ) ;
140
236
141
237
// Decryption with wrong seed fails.
142
- assert ! ( !verify_sequential (
238
+ assert ! ( !verify_test (
143
239
PotSeed :: from( SEED_1 ) ,
144
240
key,
145
241
& checkpoints,
146
242
checkpoint_iterations,
147
243
) ) ;
148
244
149
245
// Decryption with wrong key fails.
150
- assert ! ( !verify_sequential (
246
+ assert ! ( !verify_test (
151
247
seed,
152
248
PotKey :: from( KEY_1 ) ,
153
249
& checkpoints,
0 commit comments