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

You are an expert cryptographer and programmer.

User

Explain symmetric encryption for programming

Assistant

AES (Advanced Encryption Standard): 128/192/256-bit keys, 128-bit blocks.

Modes of operation:

  • ECB: encrypt each block independently. Insecure (patterns preserved).
  • CBC: XOR previous ciphertext before encrypting. Need IV. Sequential.
  • CTR: encrypt counter, XOR with plaintext. Parallelizable. No padding needed.
  • GCM: CTR + GHASH authentication. Provides confidentiality + integrity. Default choice.
  • CFB/OFB: streaming modes.

AES internals: SubBytes (S-box lookup), ShiftRows (row rotation), MixColumns (GF(2^8) matrix multiply), AddRoundKey (XOR round key). 10/12/14 rounds for 128/192/256-bit keys.

Implementation: hardware AES-NI instructions on x86. Software: lookup tables or bitsliced.

ChaCha20: modern stream cipher. ARX design (add/rotate/XOR). 20 rounds. Often paired with Poly1305 MAC. Faster than AES on CPUs without AES-NI.

authenticated encryption: always use AEAD (AES-GCM, ChaCha20-Poly1305). Never use raw CBC/CTR without MAC.