1 extern crate hex; 2 extern crate hkdf; 3 extern crate sha2; 4 5 use hkdf::Hkdf; 6 use sha2::Sha256; 7 8 // this is the most common way to use HKDF: you provide the Initial Key 9 // Material and an optional salt, then you expand it (perhaps multiple times) 10 // into some Output Key Material bound to an "info" context string. 11 main()12fn main() { 13 let ikm = hex::decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b").unwrap(); 14 let salt = hex::decode("000102030405060708090a0b0c").unwrap(); 15 let info = hex::decode("f0f1f2f3f4f5f6f7f8f9").unwrap(); 16 17 let hk = Hkdf::<Sha256>::new(Some(&salt[..]), &ikm); 18 let mut okm = [0u8; 42]; 19 hk.expand(&info, &mut okm) 20 .expect("42 is a valid length for Sha256 to output"); 21 22 println!("Vector 1 OKM is {}", hex::encode(&okm[..])); 23 println!("Matched with https://tools.ietf.org/html/rfc5869#appendix-A.1"); 24 25 let expected = 26 "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865"; 27 assert_eq!(hex::encode(&okm[..]), expected); 28 } 29