ddn.net.ssh.packet_etm

Encrypt-then-MAC SSH packet protection for AES-CTR with hmac-sha2-256-etm@openssh.com and hmac-sha2-512-etm@openssh.com.

OpenSSH layout: the packet length travels in the clear; the packet body (padding length, payload, random padding) is encrypted with a continuous AES-CTR stream per direction, and the MAC covers the packet sequence number, the clear length, and the ciphertext. The reader verifies the MAC before any decryption, so unauthenticated plaintext never exists.

Types 5

classSshEtmException : Exception

Raised for encrypt-then-MAC packet violations: bad lengths, padding, or authentication failures.

Constructors
this(string msg, string file = __FILE__, size_t line = __LINE__)Constructs an encrypt-then-MAC exception.
enumEtMMac

MAC algorithms supported by the encrypt-then-MAC layout.

sha256hmac-sha2-256-etm@openssh.com
sha512hmac-sha2-512-etm@openssh.com

Encrypt-then-MAC framing parameters.

blockSize = 16AES block size; the packet body is aligned to this
macSizeSha256 = 32SHA-256 truncated MAC length
macSizeSha512 = 64SHA-512 truncated MAC length

Encrypt-then-MAC packet writer.

Produces length || ciphertext || MAC wire packets. The CTR stream continues across packets for one key; the sequence number enters every MAC.

Fields
private CTR!AES cipher_
private HMAC mac_
private size_t macSize_
private CryptoRandom rng_
private uint sequenceNumber_
private bool wiped_
Methods
uint sequenceNumber() @property const pure nothrow @nogcReturns: the sequence number of the next packet to be written.
void wipe() nothrow @nogc @trustedVolatile-wipes the AES-CTR and HMAC key state.
void setSequence(uint value) pure nothrow @nogc @safeSets the sequence number explicitly (continuity across rekey).
ubyte[] protect(const(ubyte)[] payload)Frames, encrypts, and authenticates one payload.
private ubyte[] computeMac(uint packetLength, const(ubyte)[] ciphertext)
Constructors
this(const(ubyte)[] cipherKey, in ubyte[16] iv, const(ubyte)[] macKey, EtMMac mac, CryptoRandom rng)Constructs a writer from derived key material.

Incremental encrypt-then-MAC packet reader.

Collects the clear length and ciphertext, verifies the MAC first, then decrypts and validates padding. Nothing unauthenticated is ever returned.

Fields
private CTR!AES cipher_
private HMAC mac_
private size_t macSize_
private ubyte[] buffer_
private uint sequenceNumber_
private bool wiped_
Methods
uint sequenceNumber() @property const pure nothrow @nogcReturns: the sequence number of the next packet to be read.
void wipe() nothrow @nogc @trustedVolatile-wipes the AES-CTR/HMAC state and buffered wire data.
void setSequence(uint value) pure nothrow @nogc @safeSets the sequence number explicitly (continuity across rekey).
size_t bytesNeeded() @property const pure nothrow @nogc @safeReturns: how many more wire bytes the current packet still needs, or 0 when a full packet is buffered.
bool packetReady() @property const pure nothrow @nogc @safeReturns: whether a complete packet is buffered.
void feed(const(ubyte)[] data) @safeFeeds received wire bytes.
ubyte[] take()Takes the next authenticated packet's payload.
private uint peekLength() const pure nothrow @nogc @safe
private ubyte[] computeMac(uint packetLength, const(ubyte)[] ciphertext)
Constructors
this(const(ubyte)[] cipherKey, in ubyte[16] iv, const(ubyte)[] macKey, EtMMac mac)Constructs a reader from derived key material.

Functions 2

private fnHMAC makeMac(EtMMac mac, const(ubyte)[] key)
private fnsize_t macSize(EtMMac mac) pure nothrow @nogc @safe