ANALYSIS

Math does not negotiate

Cryptography is not magic. It is math with specific properties. Understanding the math is the difference between using crypto correctly and using it as a security placebo.

SECURITYADVANCED/16 MIN/+350 XP/ANALYSIS/by c. e. hirschauer
Photo: Brett Sayles / Pexels

Cryptography is not magic. It is math with specific properties. Understanding the math is the difference between using crypto correctly and using it as a security placebo.

— c. e. hirschauer

Cryptography is not magic. It is math with specific properties. Understanding the math is the difference between using crypto correctly and using it as a security placebo.

Every cryptographic primitive has a purpose. Symmetric encryption for confidentiality. Hashing for integrity. Asymmetric encryption for key exchange and signatures. Using the wrong primitive for the job is like using a hammer to turn a screw.

Attack Vector Model
Attack Vector Model

THE DEEP DIVE

Symmetric Encryption: AES-GCM

AES is the standard for symmetric encryption. GCM provides authenticated encryption — it encrypts and authenticates in one operation.

// AES-256-GCM: authenticated encryption
import { createCipheriv, createDecipheriv, randomBytes } from 'crypto';

function encrypt(plaintext: Buffer, key: Buffer): {
  ciphertext: Buffer; iv: Buffer; tag: Buffer;
} {
  const iv = randomBytes(12);  // 12 bytes recommended for GCM
  const cipher = createCipheriv('aes-256-gcm', key, iv);
  const ciphertext = Buffer.concat([cipher.update(plaintext), cipher.final()]);
  const tag = cipher.getAuthTag();
  return { ciphertext, iv, tag };
}

function decrypt(ciphertext: Buffer, key: Buffer, iv: Buffer, tag: Buffer): Buffer {
  const decipher = createDecipheriv('aes-256-gcm', key, iv);
  decipher.setAuthTag(tag);
  return Buffer.concat([decipher.update(ciphertext), decipher.final()]);
}

// Key derivation: never use raw keys
// Use PBKDF2, scrypt, or Argon2 to derive keys from passwords
// crypto.pbkdf2Sync(password, salt, 100000, 32, 'sha512')

Hashing: SHA-256 and Password Hashing

SHA-256 is for data integrity, not password storage. Passwords must be hashed with a slow, memory-hard algorithm.

// Password hashing with scrypt
import { scryptSync, randomBytes } from 'crypto';

function hashPassword(password: string): string {
  const salt = randomBytes(16);
  const key = scryptSync(password, salt, 65536, 64, 1);
  return salt.toString('hex') + ':' + key.toString('hex');
}

function verifyPassword(password: string, stored: string): boolean {
  const [saltHex, keyHex] = stored.split(':');
  const salt = Buffer.from(saltHex, 'hex');
  const key = Buffer.from(keyHex, 'hex');
  const derivedKey = scryptSync(password, salt, 65536, 64, 1);
  return key.equals(derivedKey);
}

Asymmetric Encryption: Ed25519

Asymmetric encryption is for key exchange and signatures, not for encrypting data. RSA is slower than symmetric encryption by 1000x.

// Ed25519 digital signatures
import { generateKeyPairSync, sign, verify } from 'crypto';

const { publicKey, privateKey } = generateKeyPairSync('ed25519');

const message = Buffer.from('Important data');
const signature = sign(null, message, privateKey);

const isValid = verify(null, message, publicKey, signature);
// isValid === true

What's happening right now

This analysis draws from 5 current intelligence signals:

CVE-1999-0095 — The debug command in Sendmail is enabled, allowing attackers to execute commands as root.

CVE-1999-1471 — Buffer overflow in passwd in BSD based operating systems 4.3 and earlier allows local users to gain root privileges by specifying a long shell or GECOS field.

CVE-1999-1122 — Vulnerability in restore in SunOS 4.0.3 and earlier allows local users to gain privileges.

CVE-1999-1506 — Vulnerability in SMI Sendmail 4.0 and earlier, on SunOS up to 4.0.3, allows remote attackers to access user bin.

CVE-1999-0084 — Certain NFS servers allow users to use mknod to gain privileges by creating a writable kmem device and setting the UID to 0.

PRINCIPLES

  1. Never roll your own crypto. Use established libraries (OpenSSL, libsodium, WebCrypto).
  2. AES-256-GCM for encryption. SHA-256 for hashing. Ed25519 for signatures.
  3. Key derivation is mandatory. Never use raw keys from passwords or entropy sources.
  4. IVs/nonces must be unique. Reusing an IV with the same key breaks encryption.
  5. Passwords are hashed with slow algorithms (bcrypt/scrypt/Argon2).

IN PRACTICE

Heartbleed (CVE-2014-0160)

A buffer over-read in OpenSSL's heartbeat extension leaked private keys, session tokens, and passwords. The vulnerability existed for two years. The fix was a bounds check.

WPA2 KRACK Attack

The KRACK attack exploited the WPA2 four-way handshake by reinstalling an already-in-use key. This reset the nonce counter, allowing packet decryption.

Current Landscape

CVE-1999-0095 — The debug command in Sendmail is enabled, allowing attackers to execute commands as root.

CVE-1999-1471 — Buffer overflow in passwd in BSD based operating systems 4.3 and earlier allows local users to gain root privileges by specifying a long shell or GECOS field.

CVE-1999-1122 — Vulnerability in restore in SunOS 4.0.3 and earlier allows local users to gain privileges.

Various tangled wires connected to system near black metal cases in server room
Photo by Brett Sayles on Pexels

LIVE SIGNALS

These items surfaced from the intelligence pipeline at generation time.

  • CVE-1999-0095 — The debug command in Sendmail is enabled, allowing attackers to execute commands as root. (NVD / CVE)
  • CVE-1999-1471 — Buffer overflow in passwd in BSD based operating systems 4.3 and earlier allows local users to gain root privileges by specifying a long shell or GECOS field. (NVD / CVE)
  • CVE-1999-1122 — Vulnerability in restore in SunOS 4.0.3 and earlier allows local users to gain privileges. (NVD / CVE)
  • CVE-1999-1506 — Vulnerability in SMI Sendmail 4.0 and earlier, on SunOS up to 4.0.3, allows remote attackers to access user bin. (NVD / CVE)
  • CVE-1999-0084 — Certain NFS servers allow users to use mknod to gain privileges by creating a writable kmem device and setting the UID to 0. (NVD / CVE)

ANTIPATTERNS

  • Using MD5 or SHA-1 for password hashing. They are too fast.
  • Encrypting data with RSA directly. Use RSA for key exchange, AES for data.
  • Hardcoding keys in source code.
  • Ignoring certificate validation. 'verify: false' disables security entirely.

CHECKLIST

  • Data encrypted at rest (AES-256-GCM)
  • Data encrypted in transit (TLS 1.3)
  • Passwords hashed with bcrypt/scrypt/Argon2
  • Keys derived from passwords (never raw)
  • No hardcoded secrets in source code
  • Certificate validation enabled on all connections

YOUR MOVE

Write a function that encrypts a file with AES-256-GCM and decrypts it. If you cannot do this correctly, you do not understand symmetric encryption.