30#include <mbedtls/gcm.h>
43 "mbedtls_gcm_context outgrew PC_WORK_AESGCM - raise it in protocore_config.h, which derives "
44 "PC_SECURE_ARENA_SIZE from it");
48 mbedtls_gcm_context *g =
reinterpret_cast<mbedtls_gcm_context *
>(storage);
50 if (mbedtls_gcm_setkey(g, MBEDTLS_CIPHER_ID_AES, key, 256) != 0)
55 return reinterpret_cast<pc_aesgcm_key *
>(g);
60 mbedtls_gcm_context *g =
reinterpret_cast<mbedtls_gcm_context *
>(k);
62 pc_secure_wipe(
reinterpret_cast<uint8_t *
>(g),
sizeof(mbedtls_gcm_context));
66 const uint8_t *pt,
size_t pt_len, uint8_t *ct_out, uint8_t tag_out[
PC_AESGCM_TAG_LEN])
68 mbedtls_gcm_context *g =
reinterpret_cast<mbedtls_gcm_context *
>(k);
69 if (mbedtls_gcm_crypt_and_tag(g, MBEDTLS_GCM_ENCRYPT, pt_len, nonce,
PC_AESGCM_IV_LEN, aad, aad_len, pt, ct_out,
78 const uint8_t *ct,
size_t ct_len,
const uint8_t tag[
PC_AESGCM_TAG_LEN], uint8_t *out)
80 mbedtls_gcm_context *g =
reinterpret_cast<mbedtls_gcm_context *
>(k);
AES-256-GCM AEAD (RFC 5116) - stateless, detached-tag API.
#define PC_AESGCM_TAG_LEN
GCM authentication tag length (bytes).
#define PC_AESGCM_IV_LEN
GCM nonce length (bytes) = fixed_field(4) || invocation_counter(8).
#define PC_AESGCM_KEY_LEN
AES-256-GCM key length (bytes).
Per-translation-unit optimization override for hot, pure-integer crypto.
bool pc_aesgcm_open(pc_aesgcm_key *k, const uint8_t nonce[PC_AESGCM_IV_LEN], const uint8_t *aad, size_t aad_len, const uint8_t *ct, size_t ct_len, const uint8_t tag[PC_AESGCM_TAG_LEN], uint8_t *out)
Open one record: verify tag over aad || ct in constant time, then (only on success) decrypt ct into o...
pc_aesgcm_key * pc_aesgcm_key_init(void *storage, const uint8_t key[PC_AESGCM_KEY_LEN])
Bind storage as a context keyed with key.
pc_cspan pc_aesgcm_seal(pc_aesgcm_key *k, const uint8_t nonce[PC_AESGCM_IV_LEN], const uint8_t *aad, size_t aad_len, const uint8_t *pt, size_t pt_len, uint8_t *ct_out, uint8_t tag_out[PC_AESGCM_TAG_LEN])
Seal one record under k and nonce.
void pc_aesgcm_key_wipe(pc_aesgcm_key *k)
Wipe the expanded schedule. Call on rekey and on close; the storage stays the caller's.
Secure pool accessor - borrows that hold key material.
pc_cspan pc_cspan_from(const uint8_t *p, size_t len)
Bind a read-only span to memory whose extent is only known at run time.