NIX // Architecture Cheatsheet

Senior Engineering Reference Guide for Applied Cryptography

AES-GCM

SYMMETRIC AEAD
PROTOCOL
Authenticated Encryption with Associated Data (AEAD)
KEY PARAMETERS
Keys: 128, 192, 256 bits. (256-bit recommended for long-term data; post-quantum safe).
ARCHITECTURE
Galois/Counter Mode provides both confidentiality (via CTR mode) and integrity (via GHASH polynomial MAC). It is highly parallelizable and hardware-accelerated (AES-NI), making it significantly faster and safer than AES-CBC. Appends a 128-bit authentication tag.
IMPLEMENTATION
Requires an Initialization Vector (IV). The NIST-recommended optimal IV length is strictly 96 bits (12 bytes) to avoid additional internal GHASH processing overhead.
CRITICAL WARNING: Never reuse an IV (nonce) under the same key. Nonce reuse in AES-GCM catastrophically breaks the authentication key, allowing attackers to forge tags and recover plaintext via XOR.

SHA-2 / SHA-3 Family

CRYPTOGRAPHIC HASH
PROTOCOL
Deterministic One-Way Hash Function
OUTPUT SIZE
SHA-256 (32 bytes), SHA-384 (48 bytes), SHA-512 (64 bytes)
ARCHITECTURE
Mathematically infeasible to reverse (preimage resistance) or find two inputs producing the same output (collision resistance). Used for file integrity, digital signature digests, and blockchain proof-of-work.
IMPLEMENTATION
SHA-2 is vulnerable to Length Extension Attacks. Never use Hash(Secret || Message) for authentication; use HMAC instead.
CRITICAL WARNING: NEVER use raw SHA-256 for password storage. It is designed to be extremely fast and hardware-optimized, allowing attackers to brute-force billions of hashes per second using GPUs. Always wrap passwords in memory-hard Key Derivation Functions (KDFs) like Argon2id, bcrypt, or PBKDF2 with high iteration counts and unique salts.

ECDSA & EdDSA

ASYMMETRIC SIGNATURES
PROTOCOL
Elliptic Curve Digital Signature Algorithm
CURVES
NIST P-256 (secp256r1), secp256k1 (Bitcoin), Curve25519 (Ed25519)
ARCHITECTURE
Used to prove authenticity and non-repudiation. The owner Signs a payload (usually a SHA-256 digest of the message) using their Private Key. Anyone can Verify the signature using the exposed Public Key. Standard for JWTs (ES256), software updates, and blockchains.
IMPLEMENTATION
ECDSA requires generating a random integer (nonce k) for every signature.
CRITICAL WARNING: Using a predictable nonce, or reusing a nonce across two different signatures, allows trivial mathematical extraction of the Private Key (e.g., the 2010 Sony PS3 hack). Best Practice: Use Deterministic ECDSA (RFC 6979) or migrate to Ed25519, which is deterministic by design and immune to timing attacks.

ECDH(E)

KEY EXCHANGE
PROTOCOL
Elliptic Curve Diffie-Hellman (Ephemeral)
ARCHITECTURE
Allows two parties to negotiate a shared symmetric secret over a fully public, monitored channel. Party A mixes their Private Key with Party B's Public Key. Party B does the inverse. The resulting math yields the exact same shared secret.
IMPLEMENTATION
Always use the Ephemeral (ECDHE) variant. By generating a fresh, temporary key pair for each session, you guarantee Perfect Forward Secrecy (PFS). If a long-term private key is compromised in the future, past traffic cannot be decrypted.
CRITICAL WARNING: ECDH provides zero authentication. It is entirely vulnerable to Man-in-the-Middle (MitM) attacks. You must combine ECDH with digital signatures (RSA/ECDSA) to cryptographically verify the identity of the peer you are exchanging keys with (e.g., TLS 1.3 Handshake).

HMAC

MESSAGE AUTHENTICATION
PROTOCOL
Hash-based Message Authentication Code (RFC 2104)
ARCHITECTURE
Provides both data integrity and authenticity. Uses a shared secret key combined with a cryptographic hash function (e.g., HMAC-SHA256) via a two-pass structure: H(Key ^ opad || H(Key ^ ipad || Message)). Immune to length extension attacks.
IMPLEMENTATION
Used heavily for validating API webhooks, generating stateless session tokens, and preventing parameter tampering.
CRITICAL WARNING: When verifying an HMAC tag, you must use a constant-time comparison function (e.g., crypto.subtle.verify or Node's timingSafeEqual). Using standard string comparison (==) fails fast, allowing attackers to forge tags byte-by-byte via timing attacks.

RSA (Rivest-Shamir-Adleman)

ASYMMETRIC ENCRYPTION
PROTOCOL
Public-Key Cryptography System
KEY PARAMETERS
Keys: 2048 or 4096 bits. (2048 is minimum safe, 4096 recommended for extended life).
ARCHITECTURE
Relies on the mathematical difficulty of factoring the product of two extremely large prime numbers. Supports both Encryption (Public Key encrypts, Private Key decrypts) and Digital Signatures (Private Key signs, Public Key verifies).
IMPLEMENTATION
RSA is computationally expensive and has strict payload size limits. CRITICAL WARNING: Never use RSA for bulk data encryption. Instead, use RSA to securely transmit an AES-GCM symmetric key (Key Wrapping), and then encrypt the actual data using that fast symmetric key. Always use RSA-OAEP padding for encryption to prevent Chosen Ciphertext Attacks.

PKI & X.509 Certificates

TRUST INFRASTRUCTURE
PROTOCOL
Public Key Infrastructure (RFC 5280)
ARCHITECTURE
Certificates bind a Public Key to a specific identity (e.g., a domain name). A Certificate Authority (CA) digitally signs the certificate, proving they validated the identity.
IMPLEMENTATION
Trust is established via the Certificate Chain. Your OS/Browser hardcodes "Root CAs". A Root CA signs an Intermediate CA, which signs the end-server certificate. If any link in the chain breaks, or if the certificate expires, or if the SHA-256 fingerprint doesn't match the signature, the TLS handshake fails.

Cryptanalytic Attack Vectors

THREAT MODELING
BRUTE-FORCE
Dictionary Attacks & Rainbow Tables: Systematically hashing every word in a dictionary list to crack a stolen hash database. Defense: Prevented by using memory-hard KDFs (Argon2id) combined with a unique, cryptographically random Salt for every user, which completely invalidates precomputed Rainbow Tables.
COLLISIONS
The Birthday Paradox: The probability of finding two different inputs that produce the exact same hash. Because of probability mechanics, you only need to hash roughly 2(N/2) inputs to find a collision in an N-bit hash, dramatically reducing the mathematical security of the hash function by half.

Steganography

DATA OBFUSCATION
PROTOCOL
Least Significant Bit (LSB) Encoding
ARCHITECTURE
Cryptography hides the meaning of a message. Steganography hides the existence of the message entirely.
IMPLEMENTATION
By modifying the Least Significant Bit of the Red, Green, and Blue channels of an image pixel, you can embed an encrypted binary payload without visibly altering the image to the human eye. Defense: Statistical analysis (Steganalysis) can detect unnatural LSB distributions.

DEPRECATED PRIMITIVES

DO NOT USE
MD5
Catastrophically Broken. Collision resistance is destroyed. Modern GPUs can brute-force 100+ billion MD5 hashes per second. Safe only for non-cryptographic checksums to detect accidental file transmission errors.
SHA-1
Mathematically Broken. Vulnerable to chosen-prefix collision attacks (SHAttered, 2017). Completely deprecated globally by NIST and major browser vendors for digital signatures and TLS certificates. Upgrade to SHA-256 or SHA-3.
AES-ECB
Electronic Codebook Mode. Does not use an Initialization Vector (IV). Identical plaintext blocks produce identical ciphertext blocks, revealing structural data patterns (the famous "ECB Penguin" image). Never use.
AES-CBC
Cipher Block Chaining without MAC. Unless strictly paired with an HMAC via Encrypt-then-MAC, CBC mode is highly vulnerable to Padding Oracle Attacks (e.g., POODLE). Modern architectures should exclusively use authenticated modes like AES-GCM or ChaCha20-Poly1305.