Signet Forge 0.1.0
C++20 Parquet library with AI-native extensions
DEMO
Loading...
Searching...
No Matches
signet::forge::crypto::AesGcmCipher Class Referencefinal

AES-256-GCM adapter – wraps the low-level AesGcm class behind ICipher. More...

#include <cipher_interface.hpp>

Inheritance diagram for signet::forge::crypto::AesGcmCipher:
signet::forge::crypto::ICipher

Public Types

using RotationCallback = std::function< void(uint64_t invocation_count)>
 Callback type for key rotation notification.
 

Public Member Functions

 AesGcmCipher (const std::vector< uint8_t > &key)
 Construct from a key vector (must be 32 bytes for AES-256).
 
 AesGcmCipher (const uint8_t *key, size_t key_len)
 Construct from a raw key pointer and length.
 
void set_rotation_callback (RotationCallback cb, uint64_t threshold=DEFAULT_ROTATION_THRESHOLD)
 Register a callback invoked when the key approaches its invocation limit.
 
uint64_t invocation_count () const noexcept
 Get the current number of encrypt() invocations on this key.
 
expected< std::vector< uint8_t > > encrypt (const uint8_t *data, size_t size, const std::string &aad="") const override
 Encrypt data.
 
expected< std::vector< uint8_t > > decrypt (const uint8_t *data, size_t size, const std::string &aad="") const override
 Decrypt data produced by encrypt().
 
 ~AesGcmCipher () override
 Destructor: securely zeroes key material (CWE-244: heap inspection).
 
bool is_authenticated () const noexcept override
 Whether this cipher provides authentication (GCM=true, CTR=false).
 
size_t key_size () const noexcept override
 Key size in bytes (32 for AES-256).
 
std::string_view algorithm_name () const noexcept override
 Human-readable algorithm name.
 
- Public Member Functions inherited from signet::forge::crypto::ICipher
virtual ~ICipher ()=default
 
 ICipher ()=default
 
 ICipher (const ICipher &)=delete
 
ICipheroperator= (const ICipher &)=delete
 
 ICipher (ICipher &&)=default
 
ICipheroperator= (ICipher &&)=default
 

Static Public Attributes

static constexpr uint64_t MAX_INVOCATIONS = UINT64_C(0xFFFFFFFF)
 NIST SP 800-38D §8.2: With random 96-bit IVs, the probability of IV collision exceeds 2^-32 after 2^32 invocations (birthday bound).
 
static constexpr uint64_t DEFAULT_ROTATION_THRESHOLD
 Default warning threshold: trigger rotation callback at 75% of max.
 

Detailed Description

AES-256-GCM adapter – wraps the low-level AesGcm class behind ICipher.

Provides authenticated encryption with AAD support. Generates a random 12-byte IV per encrypt() call and prepends it to the output.

Gap C-3 (NIST SP 800-38D §8.2): Tracks invocation count per key and enforces the 2^32 limit on GCM invocations with a single key (with random 96-bit IVs, birthday bound for IV collision is ~2^32). Callers can register a key rotation callback to be notified when approaching the limit.

Note
The destructor securely zeroes key material using volatile writes.
See also
AesCtrCipher for the unauthenticated counterpart

Definition at line 387 of file cipher_interface.hpp.

Member Typedef Documentation

◆ RotationCallback

Callback type for key rotation notification.

Called when invocation count reaches the rotation threshold. The parameter is the current invocation count.

Definition at line 401 of file cipher_interface.hpp.

Constructor & Destructor Documentation

◆ AesGcmCipher() [1/2]

signet::forge::crypto::AesGcmCipher::AesGcmCipher ( const std::vector< uint8_t > &  key)
inlineexplicit

Construct from a key vector (must be 32 bytes for AES-256).

Definition at line 404 of file cipher_interface.hpp.

◆ AesGcmCipher() [2/2]

signet::forge::crypto::AesGcmCipher::AesGcmCipher ( const uint8_t *  key,
size_t  key_len 
)
inlineexplicit

Construct from a raw key pointer and length.

Definition at line 411 of file cipher_interface.hpp.

◆ ~AesGcmCipher()

signet::forge::crypto::AesGcmCipher::~AesGcmCipher ( )
inlineoverride

Destructor: securely zeroes key material (CWE-244: heap inspection).

Uses volatile write + compiler barrier to prevent dead-store elimination.

Definition at line 493 of file cipher_interface.hpp.

Member Function Documentation

◆ algorithm_name()

std::string_view signet::forge::crypto::AesGcmCipher::algorithm_name ( ) const
inlineoverridevirtualnoexcept

Human-readable algorithm name.

Implements signet::forge::crypto::ICipher.

Definition at line 503 of file cipher_interface.hpp.

◆ decrypt()

expected< std::vector< uint8_t > > signet::forge::crypto::AesGcmCipher::decrypt ( const uint8_t *  data,
size_t  size,
const std::string &  aad = "" 
) const
inlineoverridevirtual

Decrypt data produced by encrypt().

Implements signet::forge::crypto::ICipher.

Definition at line 469 of file cipher_interface.hpp.

◆ encrypt()

expected< std::vector< uint8_t > > signet::forge::crypto::AesGcmCipher::encrypt ( const uint8_t *  data,
size_t  size,
const std::string &  aad = "" 
) const
inlineoverridevirtual

Encrypt data.

For authenticated ciphers, aad is bound into the tag. For unauthenticated ciphers, aad is ignored. Returns: [iv_size(1)] [iv] [ciphertext] [tag if authenticated]

Implements signet::forge::crypto::ICipher.

Definition at line 433 of file cipher_interface.hpp.

◆ invocation_count()

uint64_t signet::forge::crypto::AesGcmCipher::invocation_count ( ) const
inlinenoexcept

Get the current number of encrypt() invocations on this key.

Definition at line 429 of file cipher_interface.hpp.

◆ is_authenticated()

bool signet::forge::crypto::AesGcmCipher::is_authenticated ( ) const
inlineoverridevirtualnoexcept

Whether this cipher provides authentication (GCM=true, CTR=false).

Implements signet::forge::crypto::ICipher.

Definition at line 501 of file cipher_interface.hpp.

◆ key_size()

size_t signet::forge::crypto::AesGcmCipher::key_size ( ) const
inlineoverridevirtualnoexcept

Key size in bytes (32 for AES-256).

Implements signet::forge::crypto::ICipher.

Definition at line 502 of file cipher_interface.hpp.

◆ set_rotation_callback()

void signet::forge::crypto::AesGcmCipher::set_rotation_callback ( RotationCallback  cb,
uint64_t  threshold = DEFAULT_ROTATION_THRESHOLD 
)
inline

Register a callback invoked when the key approaches its invocation limit.

NIST SP 800-38D §8.2 requires key rotation before 2^32 random-IV GCM invocations to maintain the collision bound.

Parameters
cbCallback receiving the current invocation count.
thresholdInvocation count at which to trigger (default: 75% of 2^32).

Definition at line 422 of file cipher_interface.hpp.

Member Data Documentation

◆ DEFAULT_ROTATION_THRESHOLD

constexpr uint64_t signet::forge::crypto::AesGcmCipher::DEFAULT_ROTATION_THRESHOLD
staticconstexpr
Initial value:
=
static_cast<uint64_t>(MAX_INVOCATIONS * 0.75)
static constexpr uint64_t MAX_INVOCATIONS
NIST SP 800-38D §8.2: With random 96-bit IVs, the probability of IV collision exceeds 2^-32 after 2^3...

Default warning threshold: trigger rotation callback at 75% of max.

Definition at line 395 of file cipher_interface.hpp.

◆ MAX_INVOCATIONS

constexpr uint64_t signet::forge::crypto::AesGcmCipher::MAX_INVOCATIONS = UINT64_C(0xFFFFFFFF)
staticconstexpr

NIST SP 800-38D §8.2: With random 96-bit IVs, the probability of IV collision exceeds 2^-32 after 2^32 invocations (birthday bound).

Key must be rotated before reaching this limit.

Definition at line 392 of file cipher_interface.hpp.


The documentation for this class was generated from the following file: