Rc4
RC4 (ARC4) stream cipher. Pure-Kotlin port of the libTomCrypt-derived rc4_init / rc4_encrypt in libtorrent's src/pe_crypto.cpp, used by the Message Stream Encryption / Protocol Encryption (MSE/PE) handshake.
RC4 is symmetric: the same operation both encrypts and decrypts (it XORs the keystream into the data), so process serves both directions. The cipher is stateful, because each call to process advances the keystream, exactly like libtorrent's rc4_handler, which keeps separate incoming and outgoing Rc4 states per connection.
Note on MSE: libtorrent discards the first 1024 bytes of keystream after keying (set_incoming_key / set_outgoing_key). That discard is a property of the MSE handler, not of RC4 itself, so it lives in the protocol layer; discard is provided as a convenience for that.
Validated against the canonical RFC 6229 / Wikipedia RC4 test vectors.