ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
comp.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4#ifndef PROTOCORE_TRANSPORT_COMP_H
5#define PROTOCORE_TRANSPORT_COMP_H
6
7#include "protocore_config.h" // the entry point: protocore_types.h for the widths
8
9EMBED_BEGIN_DECLS
10
11/**
12 * @file comp.h
13 * @brief RFC 4253 sec 6.2 compression: the negotiated stream, both directions.
14 *
15 * @c work is bytes the CALLER holds. This module reads none of them: it carries nothing
16 * between calls, so there is no state to keep and nothing to wipe. The parameter is there so
17 * a caller drives every namespace the same way.
18 */
19
20// PROTOCORE_COMP_BORROW - the bytes this module runs out of - is stated in protocore_config.h, which sums
21// it into its arena. Its size and its offset are each a static_assert, so a feature
22// combination that does not fit fails to compile rather than overrunning at run time.
23
24/** @brief Negotiated compression algorithm, held per direction. */
25EMBED_ENUM_BYTE(SshCompAlg,
26 SSH_COMP_NONE = 0, ///< no compression
27 SSH_COMP_ZLIB = 1, ///< "zlib" (RFC 4253) - starts right after NEWKEYS
28 SSH_COMP_ZLIB_DELAYED = 2 ///< "zlib@openssh.com" - starts after SSH_MSG_USERAUTH_SUCCESS
29);
30
31/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
32typedef struct
33{
34 void (*reset)(uint8_t *, uint8_t);
35 void (*set_s2c)(uint8_t *, uint8_t, SshCompAlg);
36 void (*on_newkeys)(uint8_t *, uint8_t);
37 void (*on_auth_success)(uint8_t *, uint8_t);
38 embed_bool (*s2c_active)(uint8_t *, uint8_t);
39 int (*s2c)(uint8_t *, uint8_t, const uint8_t *, size_t, uint8_t *, size_t, size_t *);
40 void (*set_c2s)(uint8_t *, uint8_t, SshCompAlg);
41 embed_bool (*c2s_active)(uint8_t *, uint8_t);
42 int (*c2s)(uint8_t *, uint8_t, const uint8_t *, size_t, uint8_t *, size_t, size_t *);
43} CompNs;
44PROTOCORE_NS_LAYOUT(CompNs, reset, set_s2c, on_newkeys, on_auth_success, s2c_active, s2c, set_c2s, c2s_active, c2s);
45
46/**
47 * @brief Reset compression state for slot i (fresh connection). Does NOT run .
48 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
49 * @param i I
50 */
51void protocore_comp_reset(uint8_t *work, uint8_t i);
52/**
53 * @brief Record the s2c algorithm negotiated in KEXINIT (::SshCompAlg).
54 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
55 * @param i I
56 * @param alg Alg
57 */
58void protocore_comp_set_s2c(uint8_t *work, uint8_t i, SshCompAlg alg);
59/**
60 * @brief NEWKEYS completed: start the stream now if `zlib` was negotiated .
61 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
62 * @param i I
63 */
64void protocore_comp_on_newkeys(uint8_t *work, uint8_t i);
65/**
66 * @brief SSH_MSG_USERAUTH_SUCCESS sent: start the stream if .
67 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
68 * @param i I
69 */
70void protocore_comp_on_auth_success(uint8_t *work, uint8_t i);
71/**
72 * @brief True once the s2c stream is active and outbound payloads must be .
73 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
74 * @param i I
75 * @return EMBED_TRUE on success.
76 */
77embed_bool protocore_comp_s2c_active(uint8_t *work, uint8_t i);
78/**
79 * @brief Compress one outbound payload, continuing the session's zlib stream.
80 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
81 * @param i I
82 * @param src Src
83 * @param src_len Src len
84 * @param dst Dst
85 * @param dst_cap Dst cap
86 * @param out_len Out len
87 * @return The int.
88 */
89int protocore_comp_s2c(uint8_t *work, uint8_t i, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap,
90 size_t *out_len);
91/**
92 * @brief Record the client-to-server algorithm negotiated in KEXINIT .
93 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
94 * @param i I
95 * @param alg Alg
96 */
97void protocore_comp_set_c2s(uint8_t *work, uint8_t i, SshCompAlg alg);
98/**
99 * @brief True once the c2s stream is active and inbound payloads must be .
100 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
101 * @param i I
102 * @return EMBED_TRUE on success.
103 */
104embed_bool protocore_comp_c2s_active(uint8_t *work, uint8_t i);
105/**
106 * @brief Decompress one inbound payload, continuing the session's .
107 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
108 * @param i I
109 * @param src Src
110 * @param src_len Src len
111 * @param dst Dst
112 * @param dst_cap Dst cap
113 * @param out_len Out len
114 * @return The int.
115 */
116int protocore_comp_c2s(uint8_t *work, uint8_t i, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap,
117 size_t *out_len);
118
119/**
120 * @brief The bytes every entry here runs out of: one compressor per SSH connection.
121 *
122 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where that
123 * borrow comes from. The transport and the server both drive the same connection's streams, so the
124 * bytes belong to this module rather than to either caller. Taken once from the end of the plaintext
125 * pool, which no mark and no release walks, because a zlib@openssh.com stream takes its window over
126 * from one packet to the next.
127 *
128 * @return the span.
129 */
131
132/** @brief Module namespace. */
134 .set_s2c = protocore_comp_set_s2c,
135 .on_newkeys = protocore_comp_on_newkeys,
136 .on_auth_success = protocore_comp_on_auth_success,
137 .s2c_active = protocore_comp_s2c_active,
138 .s2c = protocore_comp_s2c,
139 .set_c2s = protocore_comp_set_c2s,
140 .c2s_active = protocore_comp_c2s_active,
141 .c2s = protocore_comp_c2s};
142
143EMBED_END_DECLS
144
145#endif // PROTOCORE_TRANSPORT_COMP_H
embed_bool protocore_comp_c2s_active(uint8_t *work, uint8_t i)
True once the c2s stream is active and inbound payloads must be .
int protocore_comp_s2c(uint8_t *work, uint8_t i, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap, size_t *out_len)
Compress one outbound payload, continuing the session's zlib stream.
embed_bool protocore_comp_s2c_active(uint8_t *work, uint8_t i)
True once the s2c stream is active and outbound payloads must be .
EMBED_ENUM_BYTE(SshCompAlg, SSH_COMP_NONE=0, SSH_COMP_ZLIB=1, SSH_COMP_ZLIB_DELAYED=2)
Negotiated compression algorithm, held per direction.
void protocore_comp_set_c2s(uint8_t *work, uint8_t i, SshCompAlg alg)
Record the client-to-server algorithm negotiated in KEXINIT .
void protocore_comp_on_auth_success(uint8_t *work, uint8_t i)
SSH_MSG_USERAUTH_SUCCESS sent: start the stream if .
void protocore_comp_set_s2c(uint8_t *work, uint8_t i, SshCompAlg alg)
Record the s2c algorithm negotiated in KEXINIT (SshCompAlg).
uint8_t * protocore_ssh_comp_span(void)
The bytes every entry here runs out of: one compressor per SSH connection.
void protocore_comp_reset(uint8_t *work, uint8_t i)
Reset compression state for slot i (fresh connection). Does NOT run .
int protocore_comp_c2s(uint8_t *work, uint8_t i, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap, size_t *out_len)
Decompress one inbound payload, continuing the session's .
void protocore_comp_on_newkeys(uint8_t *work, uint8_t i)
NEWKEYS completed: start the stream now if zlib was negotiated .
#define PROTOCORE_UNUSED
Suppress the unused warning. Every module ends in a namespace most callers only partly use.
Definition ns_contract.h:36
#define PROTOCORE_NS_LAYOUT(T,...)
Pin every dispatch slot of a table that is nothing but function pointers.
#define PROTOCORE_NS
Storage for a dispatch table. The const is load bearing.
Dispatch table. Addressed by offset, so the layout is asserted below.
Definition comp.h:33
void(* on_auth_success)(uint8_t *, uint8_t)
Definition comp.h:37
void(* set_c2s)(uint8_t *, uint8_t, SshCompAlg)
Definition comp.h:40
int(* s2c)(uint8_t *, uint8_t, const uint8_t *, size_t, uint8_t *, size_t, size_t *)
Definition comp.h:39
void(* on_newkeys)(uint8_t *, uint8_t)
Definition comp.h:36
int(* c2s)(uint8_t *, uint8_t, const uint8_t *, size_t, uint8_t *, size_t, size_t *)
Definition comp.h:42
void(* set_s2c)(uint8_t *, uint8_t, SshCompAlg)
Definition comp.h:35
void(* reset)(uint8_t *, uint8_t)
Definition comp.h:34
embed_bool(* c2s_active)(uint8_t *, uint8_t)
Definition comp.h:41
embed_bool(* s2c_active)(uint8_t *, uint8_t)
Definition comp.h:38