1
0
Fork 0
mirror of https://github.com/librespot-org/librespot.git synced 2025-10-04 10:19:27 +02:00

replace rust-crypto's hashes, HMAC and PBKDF2

This commit is contained in:
newpavlov 2018-07-23 16:41:39 +03:00
parent 431be9e847
commit e4677027d2
13 changed files with 253 additions and 101 deletions

View file

@ -1,7 +1,6 @@
use byteorder::{BigEndian, ByteOrder, WriteBytesExt};
use crypto::hmac::Hmac;
use crypto::mac::Mac;
use crypto::sha1::Sha1;
use hmac::{Hmac, Mac};
use sha1::Sha1;
use futures::{Async, Future, Poll};
use protobuf::{self, Message, MessageStatic};
use rand::thread_rng;
@ -187,17 +186,19 @@ fn read_into_accumulator<T: AsyncRead>(
}
fn compute_keys(shared_secret: &[u8], packets: &[u8]) -> (Vec<u8>, Vec<u8>, Vec<u8>) {
let mut data = Vec::with_capacity(0x64);
let mut mac = Hmac::new(Sha1::new(), &shared_secret);
type HmacSha1 = Hmac<Sha1>;
let mut data = Vec::with_capacity(0x64);
for i in 1..6 {
let mut mac = HmacSha1::new_varkey(&shared_secret)
.expect("HMAC can take key of any size");
mac.input(packets);
mac.input(&[i]);
data.extend_from_slice(&mac.result().code());
mac.reset();
}
mac = Hmac::new(Sha1::new(), &data[..0x14]);
let mut mac = HmacSha1::new_varkey(&data[..0x14])
.expect("HMAC can take key of any size");;
mac.input(packets);
(