Skip to main content

CipherState

Struct CipherState 

Source
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:

  1. Encrypt the 16-byte shift register with AES-128-ECB
  2. XOR the first byte of the result with the plaintext/ciphertext byte
  3. Shift the register left by 1 byte, inserting the output byte at the end

Implementations§

Source§

impl CipherState

Source

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).

Source

pub fn decrypt(&mut self, data: &mut [u8])

Decrypts data in-place.

Must be called on the raw byte stream (before frame decoding).

Source

pub fn encrypt(&mut self, data: &mut [u8])

Encrypts data in-place.

Must be called on the raw byte stream (after frame encoding).

Source

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.

Trait Implementations§

Source§

impl Debug for CipherState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V