MseEncryption

class MseEncryption(encryptKey: Sha1Hash, decryptKey: Sha1Hash)

Holds the two keyed RC4 streams for one MSE connection, the port of libtorrent's rc4_handler. There is one Rc4 instance per direction. Each is keyed, then its first MseCrypto.RC4_DISCARD (1024) keystream bytes are discarded, exactly as rc4_handler::set_outgoing_key and set_incoming_key do.

RC4 is symmetric, so "encrypt" and "decrypt" are the same XOR-with-keystream operation; they differ only in which stream (and thus which key) they advance. The streams are stateful: every encrypt/decrypt call moves the keystream forward, so calls must happen in the same order on both peers.

Construct via MseCrypto.rc4; the public constructor takes the already-derived 20-byte encrypt/decrypt keys directly (useful for tests).

Constructors

Link copied to clipboard
constructor(encryptKey: Sha1Hash, decryptKey: Sha1Hash)

Functions

Link copied to clipboard

Decrypt data with the incoming keystream, returning a new array; advances the incoming stream by data.size bytes. The input is not modified.

Link copied to clipboard

Encrypt data with the outgoing keystream, returning a new array; advances the outgoing stream by data.size bytes. The input is not modified.