ProtoCore v0.0.1
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
aesgcm.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file aesgcm.cpp
6 * @brief AES-256-GCM AEAD - stateless implementation (see aesgcm.h).
7 *
8 * All working memory (AES key schedule, GHASH table, keystream, accumulator, tag mask, counters) lives in
9 * the secure pool, laid out as a GcmWork on the software path or an
10 * The working set is a pool borrow, wiped when released. No cipher
11 * state ever touches the stack or BSS.
12 *
13 * The implementation lives in a backend under board_drivers/, chosen by the vendor's
14 * PC_HAS_HW_AESGCM: the accelerated AEAD where the silicon has one, the portable software
15 * AES + table GHASH where it does not. This file names no vendor and no cipher
16 * + GF(2^8) xtime) + software GHASH. The GF(2^128) reduction mirrors aes128gcm.cpp.
17 */
18
19#include "crypto/aead/aesgcm.h"
20#include "crypto/crypto_opt.h"
21#include "crypto/crypto_scratch.h" // pc_ct_eq
22#include "crypto/mac/ghash.h"
23#include "server/mmgr/secure.h"
24#include <string.h>
25
27
28// Advance the RFC 5647 invocation counter: the low 8 bytes of the 12-byte nonce, big-endian; the 4-byte
29// fixed field never changes. Shared by both paths and exposed publicly for the SSH packet layer.
31{
32 for (int j = PC_AESGCM_IV_LEN - 1; j >= 4; j--)
33 {
34 if (++iv[j])
35 {
36 break;
37 }
38 }
39}
PC_CRYPTO_HOT void pc_aesgcm_iv_increment(uint8_t iv[PC_AESGCM_IV_LEN])
Advance the RFC 5647 invocation counter: the low 8 bytes of the 12-byte nonce as a big-endian integer...
Definition aesgcm.cpp:30
AES-256-GCM AEAD (RFC 5116) - stateless, detached-tag API.
#define PC_AESGCM_IV_LEN
GCM nonce length (bytes) = fixed_field(4) || invocation_counter(8).
Definition aesgcm.h:40
Per-translation-unit optimization override for hot, pure-integer crypto.
Constant-time comparison for secret-dependent checks.
GHASH (the GF(2^128) universal hash under AES-GCM, NIST SP 800-38D sec 6.3), 4-bit table.
Secure pool accessor - borrows that hold key material.