@@ -11,30 +11,29 @@ extern crate bencher;
1111
1212use bencher:: { black_box, Bencher } ;
1313
14- const PBKDF2_NUM_ITERATIONS : u32 = 100000 ;
15- const PBKDF2_SALT_LEN : usize = 32 ;
16- const PBKDF2_KEY_LEN : usize = 32 ;
14+ use mbedtls:: hash:: Type as MdType ;
15+ use mbedtls:: hash:: pbkdf2_hmac;
1716
18- use mbedtls:: hash;
17+ fn test_pbkdf2 ( ) {
18+ let mut output = [ 0u8 ; 48 ] ;
1919
20- fn bench_pbkdf2_hmac ( b : & mut Bencher ) {
21- let password = "password" . as_bytes ( ) ;
22- let salt = vec ! [ 123u8 ; PBKDF2_SALT_LEN ] ;
20+ let salt = [ 0x00 , 0x01 , 0x02 , 0x03 , 0x04 , 0x05 , 0x06 , 0x07 ] ;
21+
22+ let iterations = 10000 ;
23+ let passphrase = b"xyz" ;
2324
24- let mut key_val : Vec < u8 > = vec ! [ 0 ; PBKDF2_KEY_LEN ] ;
25+ pbkdf2_hmac ( MdType :: Sha256 , passphrase , & salt , iterations , & mut output ) . unwrap ( ) ;
2526
27+ assert_eq ! ( output[ 0 ..4 ] , [ 0xDE , 0xFD , 0x29 , 0x87 ] ) ;
28+
29+ assert_eq ! ( output[ 44 ..48 ] , [ 0xE7 , 0x0B , 0x72 , 0xD0 ] ) ;
30+ }
31+
32+
33+ fn bench_pbkdf2_hmac ( b : & mut Bencher ) {
2634 b. iter ( || {
2735 // Inner closure, the actual test
28- black_box (
29- hash:: pbkdf2_hmac (
30- hash:: Type :: Sha512 ,
31- password,
32- & salt,
33- PBKDF2_NUM_ITERATIONS ,
34- key_val. as_mut_slice ( ) ,
35- )
36- . unwrap ( ) ,
37- ) ;
36+ black_box ( test_pbkdf2 ( ) ) ;
3837 } ) ;
3938}
4039
0 commit comments