ddn.net.ssh.packet_chacha
OpenSSH chacha20-poly1305@openssh.com packet protection.
This is the OpenSSH construction from PROTOCOL.chacha20poly1305, not the RFC 8439 AEAD: 64-byte key material splits into K_2 (first 32 bytes, payload) and K_1 (second 32 bytes, packet length); the Poly1305 key is the first 256 bits of the K_2 stream at block counter zero; the payload is encrypted with K_2 from block counter one; the tag covers the encrypted length and encrypted payload together. The nonce is the 64-bit packet sequence number in SSH wire (big-endian) encoding.
Types 4
Raised for packet violations: bad lengths, padding, authentication failures, or sequence exhaustion.
this(string msg, string file = __FILE__, size_t line = __LINE__)Constructs a packet-protection exception.Framing parameters of the OpenSSH construction.
OpenSSH ChaCha20-Poly1305 packet writer.
Produces encrypted-length || encrypted-payload || tag wire packets with a fresh key/nonce derivation per packet.
private ubyte[64] key_private CryptoRandom rng_private uint sequenceNumber_private bool sequenceExhausted_private bool wiped_uint sequenceNumber() @property const pure nothrow @nogcReturns: the sequence number of the next packet to be written.void setSequence(uint value) pure nothrow @nogc @safeSets the sequence number explicitly (continuity across rekey).ubyte[] protect(const(ubyte)[] payload)Encrypts and authenticates one payload.ubyte[] computeTag(const(ubyte)[] tagKey,
const(ubyte)[] encryptedLength, const(ubyte)[] encryptedBody) staticthis(const(ubyte)[] key, CryptoRandom rng)Constructs a writer from the 64-byte derived key material.OpenSSH ChaCha20-Poly1305 packet reader.
Decrypts the announced length first (K_1, counter zero) and bounds it before further buffering, then verifies the tag over the ciphertext before any payload decryption.
private ubyte[64] key_private ubyte[] buffer_private ulong announcedLength_private bool lengthDecoded_private uint sequenceNumber_private bool sequenceExhausted_private bool wiped_uint sequenceNumber() @property const pure nothrow @nogcReturns: the sequence number of the next packet to be read.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.ubyte[] take()Takes the next authenticated packet's payload.this(const(ubyte)[] key)Constructs a reader from the 64-byte derived key material.Functions 3
ubyte[] chachaCrypt(const(ubyte)[] key, in ubyte[8] nonce,
ulong blockCounter, const(ubyte)[] input) @trustedvoid advanceSequence(ref uint sequenceNumber,
ref bool exhausted) pure nothrow @nogc @safe