From 8317b5b28153794770a8c7b84a1b6dd50eaa3f80 Mon Sep 17 00:00:00 2001 From: mat Date: Fri, 29 Apr 2022 20:20:56 -0500 Subject: upgrade aes and cfb8 --- azalea-auth/Cargo.toml | 4 ++-- azalea-auth/src/encryption.rs | 30 +++++++++++++++++++++--------- 2 files changed, 23 insertions(+), 11 deletions(-) (limited to 'azalea-auth') diff --git a/azalea-auth/Cargo.toml b/azalea-auth/Cargo.toml index 6279d903..5f62991b 100755 --- a/azalea-auth/Cargo.toml +++ b/azalea-auth/Cargo.toml @@ -6,8 +6,8 @@ version = "0.1.0" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -aes = "0.7.4" -cfb8 = "0.7.1" +aes = "0.8.1" +cfb8 = "0.8.1" num-bigint = "^0.4.3" rand = {version = "^0.8.4", features = ["getrandom"]} rsa_public_encrypt_pkcs1 = "0.4.0" diff --git a/azalea-auth/src/encryption.rs b/azalea-auth/src/encryption.rs index 6f2e43a8..dc2620cc 100644 --- a/azalea-auth/src/encryption.rs +++ b/azalea-auth/src/encryption.rs @@ -1,8 +1,11 @@ +use aes::cipher::inout::InOutBuf; +use aes::cipher::BlockEncrypt; use aes::{ - cipher::{AsyncStreamCipher, NewCipher}, + cipher::{ + generic_array::GenericArray, AsyncStreamCipher, BlockDecryptMut, BlockEncryptMut, KeyIvInit, + }, Aes128, }; -use cfb8::Cfb8; use rand::{rngs::OsRng, RngCore}; use sha1::{Digest, Sha1}; @@ -57,17 +60,26 @@ pub fn encrypt(public_key: &[u8], nonce: &[u8]) -> Result } // TODO: update the aes and cfb8 crates -pub type Aes128Cfb = Cfb8; +pub type Aes128CfbEnc = cfb8::Encryptor; +pub type Aes128CfbDec = cfb8::Decryptor; -pub fn create_cipher(key: &[u8]) -> Aes128Cfb { - Aes128Cfb::new_from_slices(&key, &key).unwrap() +pub fn create_cipher(key: &[u8]) -> (Aes128CfbEnc, Aes128CfbDec) { + ( + Aes128CfbEnc::new_from_slices(key, key).unwrap(), + Aes128CfbDec::new_from_slices(key, key).unwrap(), + ) } -pub fn encrypt_packet(cipher: &mut Aes128Cfb, packet: &mut [u8]) { - cipher.encrypt(packet); +// wow this is terrible +pub fn encrypt_packet(cipher: &mut Aes128CfbEnc, packet: &mut [u8]) { + let (chunks, rest) = InOutBuf::from(packet).into_chunks(); + assert!(rest.is_empty()); + cipher.encrypt_blocks_inout_mut(chunks); } -pub fn decrypt_packet(cipher: &mut Aes128Cfb, packet: &mut [u8]) { - cipher.decrypt(packet); +pub fn decrypt_packet(cipher: &mut Aes128CfbDec, packet: &mut [u8]) { + let (chunks, rest) = InOutBuf::from(packet).into_chunks(); + assert!(rest.is_empty()); + cipher.decrypt_blocks_inout_mut(chunks); } #[cfg(test)] -- cgit v1.2.3