ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
tls13_rpk.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_TLS13_RPK_H
5#define PROTOCORE_TLS13_RPK_H
6
7#include "protocore_config.h" // the entry point: protocore_types.h for the widths
8
10
11/**
12 * @file tls13_rpk.h
13 * @brief The RFC 7250 RawPublicKey credential a TLS 1.3 Certificate message carries.
14 *
15 * A RawPublicKey Certificate carries a bare DER SubjectPublicKeyInfo where an X.509 chain would go
16 * (RFC 7250 sec 3). This module is that credential: the Ed25519 SubjectPublicKeyInfo of RFC 8410
17 * sec 4 in both directions, and the Certificate message built over it. The messages themselves,
18 * the server_certificate_type extension that selects this credential, and the handshake that
19 * negotiates it are tls13_msg's.
20 *
21 * @c work is bytes the CALLER holds. This module reads none of them: it carries nothing
22 * between calls, so there is no state to keep and nothing to wipe. The parameter is there so
23 * a caller drives every namespace the same way.
24 *
25 * @author Douglas Quigg (dstroy0)
26 * @date 2026
27 */
28
29// PROTOCORE_TLS13_RPK_BORROW - the bytes this module runs out of - is stated in protocore_config.h, which sums
30// it into its arena. Its size and its offset are each a static_assert, so a feature
31// combination that does not fit fails to compile rather than overrunning at run time.
32
33#define PROTOCORE_TLS13_ED25519_SPKI_LEN 44 ///< DER SubjectPublicKeyInfo for an Ed25519 key (RFC 8410 sec 4)
34
35/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
36typedef struct
37{
38 size_t (*ed25519_spki)(uint8_t *, uint8_t *, size_t, const uint8_t *);
39 proto_bool (*ed25519_from_spki)(uint8_t *, const uint8_t *, size_t, const uint8_t **);
40 size_t (*build_certificate)(uint8_t *, uint8_t *, size_t, const uint8_t *);
42PROTOCORE_NS_LAYOUT(Tls13RpkNs, ed25519_spki, ed25519_from_spki, build_certificate);
43
44/**
45 * @brief Write the 44-byte DER SubjectPublicKeyInfo for the Ed25519 key pub .
46 * @param work PROTOCORE_TLS13_RPK_BORROW bytes the caller took. Not held past the call.
47 * @param out Out
48 * @param cap Cap
49 * @param pub 32 bytes
50 * @return The size_t.
51 */
52size_t protocore_tls13_rpk_ed25519_spki(uint8_t *work, uint8_t *out, size_t cap, const uint8_t *pub);
53/**
54 * @brief The 32-byte Ed25519 key inside a DER SubjectPublicKeyInfo (RFC 8410 .
55 * @param work PROTOCORE_TLS13_RPK_BORROW bytes the caller took. Not held past the call.
56 * @param spki Spki
57 * @param len Len
58 * @param pub Pub
59 * @return PROTO_TRUE on success.
60 */
61proto_bool protocore_tls13_rpk_ed25519_from_spki(uint8_t *work, const uint8_t *spki, size_t len, const uint8_t **pub);
62/**
63 * @brief Build a Certificate message (RFC 8446 sec 4.4.2) carrying an RFC .
64 * @param work PROTOCORE_TLS13_RPK_BORROW bytes the caller took. Not held past the call.
65 * @param out Out
66 * @param cap Cap
67 * @param ed25519_pub 32 bytes
68 * @return The size_t.
69 */
70size_t protocore_tls13_rpk_build_certificate(uint8_t *work, uint8_t *out, size_t cap, const uint8_t *ed25519_pub);
71
72/** @brief Module namespace. */
76
78
79#endif // PROTOCORE_TLS13_RPK_H
#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 tls13_rpk.h:37
size_t(* ed25519_spki)(uint8_t *, uint8_t *, size_t, const uint8_t *)
Definition tls13_rpk.h:38
PROTOCORE_NS Tls13RpkNs Tls13Rpk PROTOCORE_UNUSED
Module namespace.
Definition tls13_rpk.h:73
size_t protocore_tls13_rpk_build_certificate(uint8_t *work, uint8_t *out, size_t cap, const uint8_t *ed25519_pub)
Build a Certificate message (RFC 8446 sec 4.4.2) carrying an RFC .
size_t protocore_tls13_rpk_ed25519_spki(uint8_t *work, uint8_t *out, size_t cap, const uint8_t *pub)
Write the 44-byte DER SubjectPublicKeyInfo for the Ed25519 key pub .
proto_bool protocore_tls13_rpk_ed25519_from_spki(uint8_t *work, const uint8_t *spki, size_t len, const uint8_t **pub)
The 32-byte Ed25519 key inside a DER SubjectPublicKeyInfo (RFC 8410 .
#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