pub struct CipherState { /* private fields */ }Expand description
Stateful AES-128-CFB8 stream cipher for Minecraft protocol encryption.
After the login handshake, all traffic is encrypted with AES-128-CFB8 where the key and IV are both the 16-byte shared secret. The cipher is stateful — its internal feedback register advances with every byte, so encryption must happen on the raw TCP byte stream, not per-frame.
CFB-8 processes one byte at a time:
- Encrypt the 16-byte shift register with AES-128-ECB
- XOR the first byte of the result with the plaintext/ciphertext byte
- Shift the register left by 1 byte, inserting the output byte at the end
Implementations§
Source§impl CipherState
impl CipherState
Sourcepub fn new(shared_secret: &[u8; 16]) -> Self
pub fn new(shared_secret: &[u8; 16]) -> Self
Creates a new cipher from the shared secret.
Per the Minecraft protocol, the key and IV are both the 16-byte shared secret (AES-128-CFB8 with key == IV).
Sourcepub fn decrypt(&mut self, data: &mut [u8])
pub fn decrypt(&mut self, data: &mut [u8])
Decrypts data in-place.
Must be called on the raw byte stream (before frame decoding).
Sourcepub fn encrypt(&mut self, data: &mut [u8])
pub fn encrypt(&mut self, data: &mut [u8])
Encrypts data in-place.
Must be called on the raw byte stream (after frame encoding).
Sourcepub fn split(self) -> (DecryptCipher, EncryptCipher)
pub fn split(self) -> (DecryptCipher, EncryptCipher)
Splits this cipher into independent decrypt and encrypt halves.
Each half owns its own AES key schedule and IV register, allowing concurrent decryption (reader task) and encryption (writer task) after the connection is split.