Symmetric Encryption
Symmetric encryption algorithms, focusing on authenticated encryption (AEAD) modes.
Authenticated Encryption (AEAD)
Provides both confidentiality AND authenticity. Always use these for encryption.
AES-GCM ⭐ Recommended
Advanced Encryption Standard with Galois/Counter Mode
- NIST SP 800-38D mode, used in TLS 1.3 and IPsec ESP [1][2][3]
- Hardware accelerated where the CPU supports it (AES-NI, ARMv8, Power8) [4]
- Parallelizable encryption and decryption [1]
- 128, 192, or 256-bit keys [5]
- 12-byte IVs; random IVs limited to 2^32 messages per key [1]
XAES-256-GCM
Extended-nonce variant of AES-256-GCM
- 24-byte nonce designed for random generation [6]
- 2^80 random-nonce messages per key at a 2^-32 collision risk, against 2^32 messages for random GCM IVs [1][6]
- Follows the C2SP XAES-256-GCM specification [6]
ChaCha20-Poly1305
RFC 8439 authenticated encryption
- Around three times as fast as AES on platforms without AES hardware, per RFC 8439 [7]
- Designed to be easy to implement in constant time [7]
- 256-bit keys only [7]
- 12-byte nonce that must not repeat and must not be random; use a counter [7]
- Used in TLS 1.3 and WireGuard [2][8]
XChaCha20-Poly1305
Extended nonce variant of ChaCha20-Poly1305
- 24-byte nonce intended for random generation
- 2^80 random-nonce messages per key at a 2^-32 collision risk
- Specified in an IRTF Internet-Draft, not an RFC [9]
- No counter tracking required
AES-CCM
Counter with CBC-MAC mode
- NIST SP 800-38C; AES-CCM cipher suites exist for TLS 1.2 and TLS 1.3 [10][11][2]
- Two-pass mode [12]
- Requires pre-specified data lengths [10]
- Nonce size 7-13 bytes [10]
AES-EAX
EAX authenticated encryption mode
- Two-pass, on-line design with a security proof
- Built from CTR mode and OMAC
- Nonce of any length [12]
AES-CTR-HMAC
AES-CTR with HMAC authentication (Encrypt-then-MAC)
- Automatic key derivation via HKDF (single master key)
- SHA-256 or SHA-512 variants
- Format defined by this library, not an external standard [13]
Low-Level Primitives
Warning: These are building blocks. Use AEAD modes above instead.
AES, ChaCha20, Twofish, and other block/stream ciphers are available as raw primitives, but you should almost always use the AEAD modes above.
Legacy Modes (Require Separate MAC)
Warning: These modes don’t provide authentication [15]. Prefer AEAD modes like GCM, ChaCha20-Poly1305, XChaCha20-Poly1305, EAX, or CCM instead.
- AES-CBC with HMAC - Legacy Encrypt-then-MAC
- AES-CTR - Counter mode
- AES-CBC - Cipher Block Chaining
For storage devices, NIST approves XTS-AES, available as XTS_Mode in xts.h [16][17].
Don’t use ECB mode; under one key it encrypts identical plaintext blocks to identical ciphertext blocks [15].
Quick Comparison
| Mode/Cipher | Authentication | Nonce / IV rule | Recommended |
|---|---|---|---|
| AES-GCM | ✅ Yes | 12 bytes, unique; random at most 2^32 per key [1] | ⭐ Primary choice |
| XAES-256-GCM | ✅ Yes | 24 bytes, random [6] | Random nonces (AES) |
| ChaCha20-Poly1305 | ✅ Yes | 12 bytes, counter, never random [7] | Software systems |
| XChaCha20-Poly1305 | ✅ Yes | 24 bytes, random [9] | Random nonces |
| AES-CCM | ✅ Yes | 7-13 bytes, unique [10] | Protocol compatibility |
| AES-EAX | ✅ Yes | Any length, unique [12] | Simple AEAD |
| AES-CTR-HMAC | ✅ Yes | 12 bytes, unique [13] | Single-key EtM |
| AES-CBC | ❌ No | 16 bytes, unpredictable [15] | Legacy only |
| AES-CTR | ❌ No | Counter blocks unique across all messages [15] | With HMAC only |
Choosing an Algorithm
For New Systems
AES-GCM (primary recommendation)
- Hardware acceleration available on target platform
- A NIST-specified mode is required [1]
ChaCha20-Poly1305 (alternative)
- No AES hardware acceleration
- Constant-time software implementation preferred
- The protocol keeps a message counter for the nonce [7]
XAES-256-GCM or XChaCha20-Poly1305
For Legacy Systems
- Upgrading from AES-CBC: Migrate to AES-GCM
- Upgrading from AES-CTR+HMAC: Migrate to AES-GCM
- Cannot change: Add HMAC authentication if not present
Security Best Practices
- Always use authenticated encryption (AES-GCM, XAES-256-GCM, ChaCha20-Poly1305, XChaCha20-Poly1305, AES-CTR-HMAC, EAX, CCM)
- Never reuse a nonce or IV with the same key [1][7][15]
- Follow each mode’s IV rule: random 12-byte IVs are allowed for AES-GCM up to 2^32 messages per key [1]; ChaCha20-Poly1305 nonces must come from a counter, not a random generator [7]; CBC IVs must be unpredictable, for example random from
AutoSeededRandomPool[15]; CTR counter blocks must never repeat under a key [15] - Use 256-bit keys for new systems (our recommendation; see Security Levels)
- Verify authentication tags - failed verification = tampered data
- Store IVs with ciphertext (IVs don’t need to be secret) [15]
- Use
SecByteBlockfor keys; its allocator wipes the memory before freeing it [18] - For random nonces at scale, prefer XAES-256-GCM or XChaCha20-Poly1305 [6][9]
Performance Notes
RFC 8439 gives ChaCha20 a speed advantage over AES on platforms without AES hardware [7]. To see whether the library is using a hardware path for AES, check AlgorithmProvider().
Hardware Acceleration Detection
#include <cryptopp/aes.h>
#include <iostream>
int main() {
using namespace CryptoPP;
std::cout << "AES Provider: "
<< AES::Encryption().AlgorithmProvider()
<< std::endl;
// Possible values:
// "AESNI" - x86/x64 AES-NI instructions
// "SSE2" - x86/x64 SSE2 assembly
// "ARMv8" - ARMv8 AES instructions
// "ARMv7" - ARMv7 assembly
// "Power8" - POWER8 AES instructions
// "C++" - portable implementation
return 0;
}The provider strings are the ones Rijndael::Base::AlgorithmProvider() returns [4].
See Also
- Symmetric Encryption - Conceptual overview
- Security Concepts - Understanding cryptography
- Algorithm Selection Guide - Choosing between the commonly used algorithms
- Message Authentication - MAC algorithms (HMAC, etc.)
References
- NIST SP 800-38D: Galois/Counter Mode (GCM) and GMAC, sections 3, 5.2.1.1, 8 and 8.3.
- RFC 8446: The Transport Layer Security (TLS) Protocol Version 1.3, appendix B.4.
- RFC 4106: The Use of Galois/Counter Mode (GCM) in IPsec Encapsulating Security Payload (ESP), abstract.
- rijndael.cpp at 2026.11.0, AES provider selection.
- FIPS 197: Advanced Encryption Standard (AES), section 5, table 3.
- C2SP: The XAES-256-GCM extended-nonce AEAD, introduction.
- RFC 8439: ChaCha20 and Poly1305 for IETF Protocols, sections 1, 2.6, 2.8 and 4.
- WireGuard: Protocol and Cryptography, list of primitives.
- draft-irtf-cfrg-xchacha-03: XChaCha: eXtended-nonce ChaCha and AEAD_XChaCha20_Poly1305, status and section 2.1.
- NIST SP 800-38C: The CCM Mode for Authentication and Confidentiality, section 3 and appendix A.1.
- RFC 6655: AES-CCM Cipher Suites for Transport Layer Security (TLS), sections 3 and 4.
- Bellare, Rogaway and Wagner: The EAX Mode of Operation, abstract and section 1.
- aes_ctr_hmac.h at 2026.11.0, design notes, and lines 235-241, typedefs.
- Nechvatal et al.: Report on the Development of the Advanced Encryption Standard (AES), J. Res. NIST 106(3), 2001, abstract.
- NIST SP 800-38A: Recommendation for Block Cipher Modes of Operation, sections 5.3, 6.1, 6.2 and 6.5, appendices B and C.
- NIST SP 800-38E: The XTS-AES Mode for Confidentiality on Storage Devices, abstract.
- xts.h at 2026.11.0,
XTSmode and theXTS_Modealias. - secblock.h at 2026.11.0,
AllocatorWithCleanup::deallocatewipes before freeing.