1
1
//! SASL-based authentication support.
2
2
3
- use hmac:: { Hmac , Mac } ;
3
+ use hmac:: { Hmac , Mac , NewMac } ;
4
4
use rand:: { self , Rng } ;
5
5
use sha2:: { Digest , Sha256 } ;
6
+ use sha2:: digest:: FixedOutput ;
6
7
use std:: fmt:: Write ;
7
8
use std:: io;
8
9
use std:: iter;
@@ -33,16 +34,16 @@ fn normalize(pass: &[u8]) -> Vec<u8> {
33
34
34
35
fn hi ( str : & [ u8 ] , salt : & [ u8 ] , i : u32 ) -> [ u8 ; 32 ] {
35
36
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 ( ) ;
39
40
40
41
let mut hi = prev;
41
42
42
43
for _ in 1 ..i {
43
44
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 ( ) ;
46
47
47
48
for ( hi, prev) in hi. iter_mut ( ) . zip ( prev) {
48
49
* hi ^= prev;
@@ -196,12 +197,12 @@ impl ScramSha256 {
196
197
197
198
let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & salted_password)
198
199
. 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 ( ) ;
201
202
202
203
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 ( ) ;
205
206
206
207
let mut cbind_input = vec ! [ ] ;
207
208
cbind_input. extend ( channel_binding. gs2_header ( ) . as_bytes ( ) ) ;
@@ -215,11 +216,11 @@ impl ScramSha256 {
215
216
216
217
let mut hmac =
217
218
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 ( ) ;
220
221
221
222
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) {
223
224
* proof ^= signature;
224
225
}
225
226
@@ -267,12 +268,12 @@ impl ScramSha256 {
267
268
268
269
let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & salted_password)
269
270
. 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 ( ) ;
272
273
273
- let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & server_key. code ( ) )
274
+ let mut hmac = Hmac :: < Sha256 > :: new_varkey ( & server_key)
274
275
. expect ( "HMAC is able to accept all key sizes" ) ;
275
- hmac. input ( auth_message. as_bytes ( ) ) ;
276
+ hmac. update ( auth_message. as_bytes ( ) ) ;
276
277
hmac. verify ( & verifier)
277
278
. map_err ( |_| io:: Error :: new ( io:: ErrorKind :: InvalidInput , "SCRAM verification error" ) )
278
279
}
0 commit comments