28 iv[4] = (uint8_t)(seqnr >> 24);
29 iv[5] = (uint8_t)(seqnr >> 16);
30 iv[6] = (uint8_t)(seqnr >> 8);
31 iv[7] = (uint8_t)seqnr;
46 "ChachapolyWork outgrew PC_WORK_CHACHAPOLY - raise it in protocore_config.h, which derives "
47 "PC_SECURE_ARENA_SIZE from it");
54 SecureBorrow ws_b(
sizeof(ChachapolyWork),
alignof(ChachapolyWork));
60 ChachapolyWork *w =
reinterpret_cast<ChachapolyWork *
>(ws.
buf);
61 seq_nonce(seqnr, w->iv);
63 uint32_t n = ((uint32_t)w->len[0] << 24) | ((uint32_t)w->len[1] << 16) | ((uint32_t)w->len[2] << 8) | w->len[3];
70 SecureBorrow ws_b(
sizeof(ChachapolyWork),
alignof(ChachapolyWork));
76 ChachapolyWork *w =
reinterpret_cast<ChachapolyWork *
>(ws.
buf);
77 seq_nonce(seqnr, w->iv);
81 pc_poly1305(dest + 4 + payload_len, dest, 4 + payload_len, w->poly_key);
87 SecureBorrow ws_b(
sizeof(ChachapolyWork),
alignof(ChachapolyWork));
93 ChachapolyWork *w =
reinterpret_cast<ChachapolyWork *
>(ws.
buf);
94 seq_nonce(seqnr, w->iv);
96 pc_poly1305(w->tag, src, 4 + payload_len, w->poly_key);
97 if (!pc_ct_eq(w->tag, src + 4 + payload_len, 16))
void pc_chacha20_xor(const uint8_t key[PC_CHACHA20_KEY_LEN], const uint8_t iv[8], uint64_t counter, const uint8_t *in, uint8_t *out, size_t len)
XOR len bytes of in with the ChaCha20 keystream into out (OpenSSH layout).
ChaCha20 stream cipher (D. J. Bernstein; RFC 8439).
bool pc_chachapoly_decrypt(const uint8_t key[PC_CHACHAPOLY_KEY_LEN], uint32_t seqnr, uint8_t *dest, const uint8_t *src, uint32_t payload_len)
Verify+decrypt one packet.
uint32_t pc_chachapoly_get_length(const uint8_t key[PC_CHACHAPOLY_KEY_LEN], uint32_t seqnr, const uint8_t enc_len[PC_CHACHAPOLY_AAD_LEN])
Decrypt just the 4-byte length field to learn the packet length before reading the body.
void pc_chachapoly_encrypt(const uint8_t key[PC_CHACHAPOLY_KEY_LEN], uint32_t seqnr, uint8_t *dest, const uint8_t *src, uint32_t payload_len)
Encrypt+authenticate one packet.
chacha20-poly1305@openssh.com AEAD cipher (OpenSSH PROTOCOL.chacha20poly1305).
#define PC_CHACHAPOLY_AAD_LEN
the encrypted packet-length field
#define PC_CHACHAPOLY_KEY_LEN
two 256-bit ChaCha20 keys
A secure borrow whose acquire and release are one call each.
const pc_span & span() const
The borrowed region; empty if the pool could not satisfy it.
Per-translation-unit optimization override for hot, pure-integer crypto.
Constant-time comparison for secret-dependent checks.
void seq_nonce(uint32_t seqnr, uint8_t iv[8])
void pc_poly1305(uint8_t tag[PC_POLY1305_TAG_LEN], const uint8_t *msg, size_t len, const uint8_t key[PC_POLY1305_KEY_LEN])
Compute the 16-byte Poly1305 tag over msg under the 32-byte one-time key.
Poly1305 one-time authenticator (D. J. Bernstein; RFC 8439 Section 2.5).
#define PC_WORK_CHACHAPOLY
Secure pool accessor - borrows that hold key material.
bool pc_span_ok(const pc_span &s)
True when the span refers to real storage and every write so far has fit.
A writable byte region: the storage, the capacity that belongs to it, and what has been produced into...
uint8_t * buf
first byte, or nullptr when the region could not be obtained