11//! SASL-based authentication support.
22
3- use hmac:: { Hmac , Mac } ;
3+ use hmac:: { Hmac , Mac , NewMac } ;
44use rand:: { self , Rng } ;
55use sha2:: { Digest , Sha256 } ;
6+ use sha2:: digest:: FixedOutput ;
67use std:: fmt:: Write ;
78use std:: io;
89use std:: iter;
@@ -33,16 +34,16 @@ fn normalize(pass: &[u8]) -> Vec<u8> {
3334
3435fn hi ( str : & [ u8 ] , salt : & [ u8 ] , i : u32 ) -> [ u8 ; 32 ] {
3536 let mut hmac = Hmac :: < Sha256 > :: new_varkey ( str) . expect ( "HMAC is able to accept all key sizes" ) ;
36- hmac. input ( salt) ;
37- hmac. input ( & [ 0 , 0 , 0 , 1 ] ) ;
38- let mut prev = hmac. result ( ) . code ( ) ;
37+ hmac. update ( salt) ;
38+ hmac. update ( & [ 0 , 0 , 0 , 1 ] ) ;
39+ let mut prev = hmac. finalize ( ) . into_bytes ( ) ;
3940
4041 let mut hi = prev;
4142
4243 for _ in 1 ..i {
4344 let mut hmac = Hmac :: < Sha256 > :: new_varkey ( str) . expect ( "already checked above" ) ;
44- hmac. input ( prev. as_slice ( ) ) ;
45- prev = hmac. result ( ) . code ( ) ;
45+ hmac. update ( & prev) ;
46+ prev = hmac. finalize ( ) . into_bytes ( ) ;
4647
4748 for ( hi, prev) in hi. iter_mut ( ) . zip ( prev) {
4849 * hi ^= prev;
@@ -196,12 +197,12 @@ impl ScramSha256 {
196197
197198 let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & salted_password)
198199 . expect ( "HMAC is able to accept all key sizes" ) ;
199- hmac. input ( b"Client Key" ) ;
200- let client_key = hmac. result ( ) . code ( ) ;
200+ hmac. update ( b"Client Key" ) ;
201+ let client_key = hmac. finalize ( ) . into_bytes ( ) ;
201202
202203 let mut hash = Sha256 :: default ( ) ;
203- hash. input ( client_key. as_slice ( ) ) ;
204- let stored_key = hash. result ( ) ;
204+ hash. update ( client_key. as_slice ( ) ) ;
205+ let stored_key = hash. finalize_fixed ( ) ;
205206
206207 let mut cbind_input = vec ! [ ] ;
207208 cbind_input. extend ( channel_binding. gs2_header ( ) . as_bytes ( ) ) ;
@@ -215,11 +216,11 @@ impl ScramSha256 {
215216
216217 let mut hmac =
217218 Hmac :: < Sha256 > :: new_varkey ( & stored_key) . expect ( "HMAC is able to accept all key sizes" ) ;
218- hmac. input ( auth_message. as_bytes ( ) ) ;
219- let client_signature = hmac. result ( ) ;
219+ hmac. update ( auth_message. as_bytes ( ) ) ;
220+ let client_signature = hmac. finalize ( ) . into_bytes ( ) ;
220221
221222 let mut client_proof = client_key;
222- for ( proof, signature) in client_proof. iter_mut ( ) . zip ( client_signature. code ( ) ) {
223+ for ( proof, signature) in client_proof. iter_mut ( ) . zip ( client_signature) {
223224 * proof ^= signature;
224225 }
225226
@@ -267,12 +268,12 @@ impl ScramSha256 {
267268
268269 let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & salted_password)
269270 . expect ( "HMAC is able to accept all key sizes" ) ;
270- hmac. input ( b"Server Key" ) ;
271- let server_key = hmac. result ( ) ;
271+ hmac. update ( b"Server Key" ) ;
272+ let server_key = hmac. finalize ( ) . into_bytes ( ) ;
272273
273- let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & server_key. code ( ) )
274+ let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & server_key)
274275 . expect ( "HMAC is able to accept all key sizes" ) ;
275- hmac. input ( auth_message. as_bytes ( ) ) ;
276+ hmac. update ( auth_message. as_bytes ( ) ) ;
276277 hmac. verify ( & verifier)
277278 . map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "SCRAM verification error" ) )
278279 }
0 commit comments