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
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. */
26{
27 SSH_COMP_NONE = 0, ///< no compression
28 SSH_COMP_ZLIB = 1, ///< "zlib" (RFC 4253) - starts right after NEWKEYS
29 SSH_COMP_ZLIB_DELAYED = 2 ///< "zlib@openssh.com" - starts after SSH_MSG_USERAUTH_SUCCESS
31
32/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
33typedef struct
34{
35 void (*reset)(uint8_t *, uint8_t);
36 void (*set_s2c)(uint8_t *, uint8_t, SshCompAlg);
37 void (*on_newkeys)(uint8_t *, uint8_t);
38 void (*on_auth_success)(uint8_t *, uint8_t);
39 proto_bool (*s2c_active)(uint8_t *, uint8_t);
40 int (*s2c)(uint8_t *, uint8_t, const uint8_t *, size_t, uint8_t *, size_t, size_t *);
41 void (*set_c2s)(uint8_t *, uint8_t, SshCompAlg);
42 proto_bool (*c2s_active)(uint8_t *, uint8_t);
43 int (*c2s)(uint8_t *, uint8_t, const uint8_t *, size_t, uint8_t *, size_t, size_t *);
44} CompNs;
45PROTOCORE_NS_LAYOUT(CompNs, reset, set_s2c, on_newkeys, on_auth_success, s2c_active, s2c, set_c2s, c2s_active, c2s);
46
47/**
48 * @brief Reset compression state for slot i (fresh connection). Does NOT run .
49 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
50 * @param i I
51 */
52void protocore_comp_reset(uint8_t *work, uint8_t i);
53/**
54 * @brief Record the s2c algorithm negotiated in KEXINIT (::SshCompAlg).
55 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
56 * @param i I
57 * @param alg Alg
58 */
59void protocore_comp_set_s2c(uint8_t *work, uint8_t i, SshCompAlg alg);
60/**
61 * @brief NEWKEYS completed: start the stream now if `zlib` was negotiated .
62 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
63 * @param i I
64 */
65void protocore_comp_on_newkeys(uint8_t *work, uint8_t i);
66/**
67 * @brief SSH_MSG_USERAUTH_SUCCESS sent: start the stream if .
68 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
69 * @param i I
70 */
71void protocore_comp_on_auth_success(uint8_t *work, uint8_t i);
72/**
73 * @brief True once the s2c stream is active and outbound payloads must be .
74 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
75 * @param i I
76 * @return PROTO_TRUE on success.
77 */
78proto_bool protocore_comp_s2c_active(uint8_t *work, uint8_t i);
79/**
80 * @brief Compress one outbound payload, continuing the session's zlib stream.
81 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
82 * @param i I
83 * @param src Src
84 * @param src_len Src len
85 * @param dst Dst
86 * @param dst_cap Dst cap
87 * @param out_len Out len
88 * @return The int.
89 */
90int protocore_comp_s2c(uint8_t *work, uint8_t i, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap,
91 size_t *out_len);
92/**
93 * @brief Record the client-to-server algorithm negotiated in KEXINIT .
94 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
95 * @param i I
96 * @param alg Alg
97 */
98void protocore_comp_set_c2s(uint8_t *work, uint8_t i, SshCompAlg alg);
99/**
100 * @brief True once the c2s stream is active and inbound payloads must be .
101 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
102 * @param i I
103 * @return PROTO_TRUE on success.
104 */
105proto_bool protocore_comp_c2s_active(uint8_t *work, uint8_t i);
106/**
107 * @brief Decompress one inbound payload, continuing the session's .
108 * @param work PROTOCORE_COMP_BORROW bytes the caller took. Not held past the call.
109 * @param i I
110 * @param src Src
111 * @param src_len Src len
112 * @param dst Dst
113 * @param dst_cap Dst cap
114 * @param out_len Out len
115 * @return The int.
116 */
117int protocore_comp_c2s(uint8_t *work, uint8_t i, const uint8_t *src, size_t src_len, uint8_t *dst, size_t dst_cap,
118 size_t *out_len);
119
120/**
121 * @brief The bytes every entry here runs out of: one compressor per SSH connection.
122 *
123 * Stated beside the namespace rather than on it: an entry takes a borrow, and this is where that
124 * borrow comes from. The transport and the server both drive the same connection's streams, so the
125 * bytes belong to this module rather than to either caller. Taken once from the end of the plaintext
126 * pool, which no mark and no release walks, because a zlib@openssh.com stream takes its window over
127 * from one packet to the next.
128 *
129 * @return the span.
130 */
132
133/** @brief Module namespace. */
143
145
146#endif // PROTOCORE_TRANSPORT_COMP_H
PROTO_ENUM_PACKED
Application protocol spoken on a listener port or connection slot.
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.
PROTOCORE_NS CompNs Comp PROTOCORE_UNUSED
Module namespace.
Definition comp.h:134
proto_bool protocore_comp_c2s_active(uint8_t *work, uint8_t i)
True once the c2s stream is active and inbound payloads must be .
enum PROTO_ENUM_PACKED SshCompAlg
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.
proto_bool protocore_comp_s2c_active(uint8_t *work, uint8_t i)
True once the s2c stream is active and outbound payloads must be .
@ SSH_COMP_ZLIB_DELAYED
"zlib@openssh.com" - starts after SSH_MSG_USERAUTH_SUCCESS
Definition comp.h:29
@ SSH_COMP_ZLIB
"zlib" (RFC 4253) - starts right after NEWKEYS
Definition comp.h:28
@ SSH_COMP_NONE
no compression
Definition comp.h:27
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_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:34
void(* reset)(uint8_t *, uint8_t)
Definition comp.h:35
#define PROTOCORE_BEGIN_DECLS
Give a header's declarations C linkage, so their symbol names carry no parameter types.
Definition types.h:96
_Bool proto_bool
The truth value.
Definition types.h:64
#define PROTOCORE_END_DECLS
Definition types.h:97