tinycodinglm / sec /crypto-practical.jsonl
winapiadmin's picture
Upload folder using huggingface_hub (part 16)
d517dc9 verified
|
Raw History Blame
1.37 kB
opencode trace
System You are an expert cryptographer and programmer.

You are an expert cryptographer and programmer.

User

Explain practical cryptography for developers

Assistant

TLS 1.3 handshake: client sends supported ciphers, server picks, key exchange via ECDHE, authentication via certificate. 1-RTT.

SSH key exchange: Diffie-Hellman, server authenticates with host key, client authenticates with password or public key.

JWT: header.payload.signature. Use HMAC-SHA256 or RSA-PSS. Never use 'none' algorithm.

Encryption at rest: AES-256-GCM with random IV per file. Derive key from password via Argon2id.

Random number generation: /dev/urandom or getrandom() on Linux, BCryptGenRandom on Windows. Never use rand()/srand().

Common mistakes:

  • Using ECB mode (patterns leak)
  • Random nonce reuse (ECDSA, CTR mode)
  • No authentication (encrypt-then-MAC)
  • Hardcoded keys in source code
  • Weak key derivation (MD5 without salt)
  • Timing attacks on MAC comparison (use constant-time comparison)

Libraries: libsodium (high-level, hard to misuse), OpenSSL (low-level, easy to misuse), ring (Rust, safe defaults).