ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
sha1.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_SHA1_H
5#define PROTOCORE_SHA1_H
6
7#include "protocore_config.h" // the entry point: protocore_types.h for the widths
8
10
11/**
12 * @file sha1.h
13 * @brief SHA-1 (FIPS 180-4) - one-shot digest.
14 *
15 * The shared SHA-1 primitive. On Arduino (ESP32) delegates to the hardware SHA accelerator; on native
16 * builds a portable software implementation is used. Used for the WebSocket opening handshake
17 * (RFC 6455 ยง4.2.2) and other legacy digest needs. Output is always 20 bytes.
18 *
19 * @c work is PROTOCORE_SHA1_BORROW secure bytes the CALLER took, at an address it knows. It is not held past the call,
20 * so nothing here aliases it. The caller releases it, and the pool wipes on release; this module neither takes it,
21 * holds it, releases it, nor wipes it.
22 *
23 * @author Douglas Quigg (dstroy0)
24 * @date 2026
25 */
26
27/** @brief SHA-1 digest length in bytes. */
28#define PROTOCORE_SHA1_DIGEST_LEN 20
29
30/** @brief Dispatch table. Addressed by offset, so the layout is asserted below. */
31typedef struct
32{
33 proto_bool (*hash)(uint8_t *, const uint8_t *, size_t, uint8_t *);
34} Sha1Ns;
36
37/**
38 * @brief Digest the whole message in one call.
39 * @param work PROTOCORE_SHA1_BORROW bytes the caller took. Not held past the call.
40 * @param data the bytes
41 * @param len how many
42 * @param out PROTOCORE_SHA1_DIGEST_LEN bytes
43 * @return PROTO_TRUE on success.
44 */
45proto_bool protocore_sha1_hash(uint8_t *work, const uint8_t *data, size_t len, uint8_t *out);
46
47/** @brief Module namespace. */
49
51
52#endif // PROTOCORE_SHA1_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.
proto_bool protocore_sha1_hash(uint8_t *work, const uint8_t *data, size_t len, uint8_t *out)
Digest the whole message in one call.
PROTOCORE_NS Sha1Ns Sha1 PROTOCORE_UNUSED
Module namespace.
Definition sha1.h:48
Dispatch table. Addressed by offset, so the layout is asserted below.
Definition sha1.h:32
proto_bool(* hash)(uint8_t *, const uint8_t *, size_t, uint8_t *)
Definition sha1.h:33
#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