22
33#![ allow( clippy:: too_many_arguments) ]
44
5- use alloc:: vec:: Vec ;
6-
75use crate :: {
8- Mode ,
6+ Error , Mode , Result ,
97 pwxform:: { PwxformCtx , SWORDS } ,
108 salsa20,
119 util:: { cast_slice, hmac_sha256, slice_as_chunks_mut, xor} ,
1210} ;
11+ use alloc:: vec:: Vec ;
1312
1413const SBYTES : u64 = crate :: pwxform:: SBYTES as u64 ;
1514
@@ -28,7 +27,7 @@ pub(crate) fn smix(
2827 v : & mut [ u32 ] ,
2928 xy : & mut [ u32 ] ,
3029 passwd : & mut [ u8 ] ,
31- ) {
30+ ) -> Result < ( ) > {
3231 let r = r as usize ;
3332 let s = 32 * r;
3433
@@ -100,7 +99,7 @@ pub(crate) fn smix(
10099
101100 // 17: if YESCRYPT_RW flag is set
102101 let mut ctx_i = if mode. is_rw ( ) {
103- let si = sn. next ( ) . unwrap ( ) ;
102+ let si = sn. next ( ) . ok_or ( Error :: Internal ) ? ;
104103
105104 // 18: SMix1_1(B_i, Sbytes / 128, S_i, no flags)
106105 smix1 (
@@ -111,7 +110,7 @@ pub(crate) fn smix(
111110 & mut si[ ..] ,
112111 xy,
113112 & mut None ,
114- ) ;
113+ ) ? ;
115114
116115 let ( s2, s10) = si. split_at_mut ( ( 1 << 8 ) * 4 ) ;
117116 let ( s1, s0) = s10. split_at_mut ( ( 1 << 8 ) * 4 ) ;
@@ -134,7 +133,7 @@ pub(crate) fn smix(
134133 // 23: if i = 0
135134 if i == 0 {
136135 // 24: passwd <-- HMAC-SHA256(B_{0,2r-1}, passwd)
137- let digest = hmac_sha256 ( cast_slice ( & bs[ ( s - 16 ) ..s] ) , & passwd[ ..32 ] ) ;
136+ let digest = hmac_sha256 ( cast_slice ( & bs[ ( s - 16 ) ..s] ) ? , & passwd[ ..32 ] ) ? ;
138137 passwd[ ..32 ] . copy_from_slice ( & digest) ;
139138 }
140139
@@ -145,7 +144,7 @@ pub(crate) fn smix(
145144 } ;
146145
147146 // 27: SMix1_r(B_i, n, V_{u..v}, flags)
148- smix1 ( bs, r, np, mode, vp, xy, & mut ctx_i) ;
147+ smix1 ( bs, r, np, mode, vp, xy, & mut ctx_i) ? ;
149148
150149 // 28: SMix2_r(B_i, p2floor(n), Nloop_rw, V_{u..v}, flags)
151150 smix2 (
@@ -157,7 +156,7 @@ pub(crate) fn smix(
157156 vp,
158157 xy,
159158 & mut ctx_i,
160- ) ;
159+ ) ? ;
161160
162161 vchunk += nchunk;
163162 }
@@ -185,8 +184,10 @@ pub(crate) fn smix(
185184 v,
186185 xy,
187186 & mut ctx_i,
188- ) ;
187+ ) ? ;
189188 }
189+
190+ Ok ( ( ) )
190191}
191192
192193/// Compute first loop of `B = SMix_r(B, N)`.
@@ -201,7 +202,7 @@ fn smix1(
201202 v : & mut [ u32 ] ,
202203 xy : & mut [ u32 ] ,
203204 ctx : & mut Option < & mut PwxformCtx < ' _ > > ,
204- ) {
205+ ) -> Result < ( ) > {
205206 let s = 32 * r;
206207 let ( x, y) = xy. split_at_mut ( s) ;
207208
@@ -218,7 +219,7 @@ fn smix1(
218219 v[ i as usize * s..] [ ..s] . copy_from_slice ( x) ;
219220 if mode. is_rw ( ) && i > 1 {
220221 let n = prev_power_of_two ( i) ;
221- let j = usize:: try_from ( ( integerify ( x, r) & ( n - 1 ) ) + ( i - n) ) . unwrap ( ) ;
222+ let j = usize:: try_from ( ( integerify ( x, r) & ( n - 1 ) ) + ( i - n) ) ? ;
222223 xor ( x, & v[ j * s..] [ ..s] ) ;
223224 }
224225
@@ -235,6 +236,8 @@ fn smix1(
235236 b[ ( k * 16 ) + ( ( i * 5 ) % 16 ) ] = ( x[ k * 16 + i] ) . to_le ( ) ;
236237 }
237238 }
239+
240+ Ok ( ( ) )
238241}
239242
240243/// Compute second loop of `B = SMix_r(B, N)`.
@@ -251,7 +254,7 @@ fn smix2(
251254 v : & mut [ u32 ] ,
252255 xy : & mut [ u32 ] ,
253256 ctx : & mut Option < & mut PwxformCtx < ' _ > > ,
254- ) {
257+ ) -> Result < ( ) > {
255258 let s = 32 * r;
256259 let ( x, y) = xy. split_at_mut ( s) ;
257260
@@ -265,7 +268,7 @@ fn smix2(
265268 // 6: for i = 0 to N - 1 do
266269 for _ in 0 ..nloop {
267270 // 7: j <-- Integerify(X) mod N
268- let j = usize:: try_from ( integerify ( x, r) & ( n - 1 ) ) . unwrap ( ) ;
271+ let j = usize:: try_from ( integerify ( x, r) & ( n - 1 ) ) ? ;
269272
270273 // 8.1: X <-- X xor V_j
271274 xor ( x, & v[ j * s..] [ ..s] ) ;
@@ -288,6 +291,8 @@ fn smix2(
288291 b[ ( k * 16 ) + ( ( i * 5 ) % 16 ) ] = ( x[ k * 16 + i] ) . to_le ( ) ;
289292 }
290293 }
294+
295+ Ok ( ( ) )
291296}
292297
293298/// Return the result of parsing B_{2r-1} as a little-endian integer.
0 commit comments