@@ -8,6 +8,8 @@ use crate::{
8
8
sha256:: HMAC_SHA256_Buf ,
9
9
} ;
10
10
11
+ const SBYTES : u64 = crate :: pwxform:: SBYTES as u64 ;
12
+
11
13
/// Compute `B = SMix_r(B, N)`.
12
14
///
13
15
/// The input B must be 128rp bytes in length; the temporary storage V must be 128rN bytes in
@@ -82,21 +84,14 @@ pub(crate) unsafe fn smix(
82
84
} else {
83
85
n - vchunk
84
86
} ;
85
- let bp = b. as_mut_ptr ( ) . add ( i * s) ;
87
+
88
+ let bs = & mut b[ ( i * s) ..] ;
86
89
let vp = v. add ( vchunk as usize * s) ;
87
90
88
91
// 17: if YESCRYPT_RW flag is set
89
92
let mut ctx_i = if flags. contains ( Flags :: RW ) {
90
93
// 18: SMix1_1(B_i, Sbytes / 128, S_i, no flags)
91
- smix1 (
92
- bp,
93
- 1 ,
94
- 3 * ( 1 << 8 ) * 2 * 8 / 128 ,
95
- Flags :: empty ( ) ,
96
- ctx[ i] . s ,
97
- xy,
98
- & mut None ,
99
- ) ;
94
+ smix1 ( bs, 1 , SBYTES / 128 , Flags :: empty ( ) , ctx[ i] . s , xy, & mut None ) ;
100
95
101
96
// 19: S2_i <-- S_{i,0...2^Swidth-1}
102
97
ctx[ i] . s2 = ctx[ i] . s as * mut [ u32 ; 2 ] ;
@@ -114,7 +109,7 @@ pub(crate) unsafe fn smix(
114
109
if i == 0 {
115
110
// 24: passwd <-- HMAC-SHA256(B_{0,2r-1}, passwd)
116
111
HMAC_SHA256_Buf (
117
- bp . add ( s - 16 ) as * const u8 ,
112
+ bs [ ( s - 16 ) .. ] . as_ptr ( ) as * const u8 ,
118
113
64 ,
119
114
passwd as * const u8 ,
120
115
32 ,
@@ -128,11 +123,11 @@ pub(crate) unsafe fn smix(
128
123
} ;
129
124
130
125
// 27: SMix1_r(B_i, n, V_{u..v}, flags)
131
- smix1 ( bp , r, np, flags, vp, xy, & mut ctx_i) ;
126
+ smix1 ( bs , r, np, flags, vp, xy, & mut ctx_i) ;
132
127
133
128
// 28: SMix2_r(B_i, p2floor(n), Nloop_rw, V_{u..v}, flags)
134
129
smix2 (
135
- bp ,
130
+ bs ,
136
131
r,
137
132
prev_power_of_two ( np) ,
138
133
nloop_rw,
@@ -156,7 +151,7 @@ pub(crate) unsafe fn smix(
156
151
157
152
// 31: SMix2_r(B_i, N, Nloop_all - Nloop_rw, V, flags excluding YESCRYPT_RW)
158
153
smix2 (
159
- b . as_mut_ptr ( ) . add ( i * s) ,
154
+ & mut b [ ( i * s) .. ] ,
160
155
r,
161
156
n,
162
157
nloop_all - nloop_rw,
@@ -173,7 +168,7 @@ pub(crate) unsafe fn smix(
173
168
/// The input B must be 128r bytes in length; the temporary storage `V` must be 128rN bytes in
174
169
/// length; the temporary storage `XY` must be 256r bytes in length.
175
170
unsafe fn smix1 (
176
- b : * mut u32 ,
171
+ b : & mut [ u32 ] ,
177
172
r : usize ,
178
173
n : u64 ,
179
174
flags : Flags ,
@@ -188,7 +183,7 @@ unsafe fn smix1(
188
183
// 1: X <-- B
189
184
for k in 0 ..( 2 * r) {
190
185
for i in 0 ..16 {
191
- * x. add ( k * 16 + i) = u32:: from_le ( * b. add ( ( k * 16 ) + ( i * 5 % 16 ) ) ) ;
186
+ * x. add ( k * 16 + i) = u32:: from_le ( * b. as_mut_ptr ( ) . add ( ( k * 16 ) + ( i * 5 % 16 ) ) ) ;
192
187
}
193
188
}
194
189
@@ -204,15 +199,15 @@ unsafe fn smix1(
204
199
205
200
// 4: X <-- H(X)
206
201
match ctx {
207
- Some ( ctx) => PwxformCtx :: blockmix_pwxform ( ctx , x, r) ,
202
+ Some ( ctx) => ctx . blockmix_pwxform ( x, r) ,
208
203
None => salsa20:: blockmix_salsa8 ( x, y, r) ,
209
204
}
210
205
}
211
206
212
207
/* B' <-- X */
213
208
for k in 0 ..( 2 * r) {
214
209
for i in 0 ..16 {
215
- * b. add ( ( k * 16 ) + ( ( i * 5 ) % 16 ) ) = ( * x. add ( k * 16 + i) ) . to_le ( ) ;
210
+ * b. as_mut_ptr ( ) . add ( ( k * 16 ) + ( ( i * 5 ) % 16 ) ) = ( * x. add ( k * 16 + i) ) . to_le ( ) ;
216
211
}
217
212
}
218
213
}
@@ -223,7 +218,7 @@ unsafe fn smix1(
223
218
/// the temporary storage XY must be 256r bytes in length. The value N must be a power of 2
224
219
/// greater than 1.
225
220
unsafe fn smix2 (
226
- b : * mut u32 ,
221
+ b : & mut [ u32 ] ,
227
222
r : usize ,
228
223
n : u64 ,
229
224
nloop : u64 ,
@@ -239,7 +234,7 @@ unsafe fn smix2(
239
234
/* X <-- B */
240
235
for k in 0 ..( 2 * r) {
241
236
for i in 0 ..16usize {
242
- * x. add ( k * 16 + i) = u32:: from_le ( * b. add ( ( k * 16 ) + ( i * 5 % 16usize ) ) ) ;
237
+ * x. add ( k * 16 + i) = u32:: from_le ( * b. as_mut_ptr ( ) . add ( ( k * 16 ) + ( i * 5 % 16 ) ) ) ;
243
238
}
244
239
}
245
240
@@ -258,15 +253,15 @@ unsafe fn smix2(
258
253
259
254
// 8.2: X <-- H(X)
260
255
match ctx {
261
- Some ( ctx) => PwxformCtx :: blockmix_pwxform ( ctx , x, r) ,
256
+ Some ( ctx) => ctx . blockmix_pwxform ( x, r) ,
262
257
None => salsa20:: blockmix_salsa8 ( x, y, r) ,
263
258
}
264
259
}
265
260
266
261
// 10: B' <-- X
267
262
for k in 0 ..( 2 * r) {
268
263
for i in 0 ..16 {
269
- * b. add ( ( k * 16 ) + ( ( i * 5 ) % 16 ) ) = ( * x. add ( k * 16 + i) ) . to_le ( ) ;
264
+ * b. as_mut_ptr ( ) . add ( ( k * 16 ) + ( ( i * 5 ) % 16 ) ) = ( * x. add ( k * 16 + i) ) . to_le ( ) ;
270
265
}
271
266
}
272
267
}
0 commit comments