CSS411 Cryptography

Cheat Sheet

One dense page for last-minute revision across the whole crypto course.

24 min read

FoundationsSearch on YouTube

Security modelSearch on YouTube

ItemOne line
Security dimensionsSecurity attack (action), security mechanism (detect, prevent, recover), security service (counters attacks)
Passive attacksEavesdropping, traffic analysis — read, no change
Active attacksMasquerade, replay, modification of messages, denial of service
Five security servicesAuthentication (peer entity / data origin), Access control, Confidentiality, Integrity, Non-repudiation — AACIN
Specific mechanismsEncipherment, digital signature, access control, data integrity, authentication exchange, traffic padding, routing control, notarization
Network model, 4 tasksDesign algorithm, generate key material, distribute and share the secrets, specify the protocol

Classical ciphersSearch on YouTube

CipherRule to remember
CaesarReplace each letter 3 places down: C=(P+3) mod 26C = (P+3) \bmod 26
MonoalphabeticAny permutation; key space 26!26!; broken by frequency analysis
Playfair5x5 keyword matrix, I/J share a cell, encrypt a digram at a time. Rules: filler X for repeats, same row → right, same column → below, else rectangle corners
VigenèreCi=(Pi+Ki) mod 26C_i = (P_i + K_i) \bmod 26 with the keyword repeated; key length hides it imperfectly (repeated patterns leak)
AutokeyKey = keyword prefixed to the plaintext (Vigenère's idea); still period-1 frequencies once the key becomes plaintext
One-time padC=(P+K) mod 26C = (P+K) \bmod 26, KK truly random as long as PP, used once. Unbreakable; unusable because of key distribution
Rail fenceWrite diagonally on r rails, read off row by row
Row transpositionKey = column order; read the matrix column by column. Transposition keeps the letter frequencies
Product / rotorMultiple stages (confusion + diffusion); rotor machines rotate wirings every key press

Symmetric ciphersSearch on YouTube

S-DES and DESSearch on YouTube

s-DESDES
Block8-bit plaintext64-bit
Key10-bit key64-bit key carrying 8 parity bits, real key 56 bits (256=7.2×10162^{56} = 7.2\times10^{16})
SubkeysTwo 8-bit: P10, split 5+5, LS-1, P8 = K1K_1; LS-2, P8 = K2K_216 x 48-bit: PC-1 (56 bits), shifts in halves, PC-2 (48 bits)
PipelineIP, fK1f_{K_1}, SW, fK2f_{K_2}, IP−1^{-1}IP, 16 Feistel rounds, 32-bit swap, IP−1^{-1}
fKf_KfK(L,R)=(L⊕F(R,SK), R)f_K(L,R) = (L \oplus F(R, SK),\ R); F = E/P (4→8), XOR subkey, S0+S1 (4→2 each), P4Round function on Li,Ri: expansion E (32→48), XOR KiK_i, 8 S-boxes (6→4 each, 32 bits), permutation P
DecryptionSame functions, same order, keys swappedSame pipeline with K1..K16K_1..K_{16} reversed

S-box rule both scales: leading and trailing bit give the row, the middle two give the column.

AES layersSearch on YouTube

ItemOne line
Parameters128-bit block (4x4 byte state), keys 128/192/256, rounds 10/12/14 (key 10 words, round key expands)
Round (nr-1 times)SubBytes → ShiftRows → MixColumns → AddRoundKey
Final roundSubBytes → ShiftRows → AddRoundKey (no MixColumns)
SubBytesS-box: multiplicative inverse in GF 282^8, then affine transform; byte-wise confusion
ShiftRowsRow r rotates left r bytes
MixColumnsColumn mixes; diffusion over 4 bytes
AddRoundKeyXOR the round key; the only layer that uses the key
DecryptionInvert each layer (InvSubBytes, InvShiftRows, InvMixColumns), key schedule reversed

GF(2^8) arithmeticSearch on YouTube

  • GF 282^8 = bytes with irreducible polynomial m(x)=x8+x4+x3+x+1m(x) = x^8 + x^4 + x^3 + x + 1 = 0x11B; arithmetic is polynomial mod m(x)m(x), addition and subtraction are both XOR.
  • Multiply by 02 (xtime): shift left; if the MSB was 1, XOR with 0x1b.
  • Examples: 02⋅63=C602 \cdot 63 = C6 (MSB 0, shift only). 02⋅87=1502 \cdot 87 = 15 (MSB 1: 0E⊕1B=150E \oplus 1B = 15). 03⋅x=(02⋅x)⊕x03 \cdot x = (02 \cdot x) \oplus x.
  • MixColumns per column, with input b0..b3b_0..b_3:

c0=02b0⊕03b1⊕01b2⊕01b3c1=01b0⊕02b1⊕03b2⊕01b3c2=01b0⊕01b1⊕02b2⊕03b3c3=03b0⊕01b1⊕01b2⊕02b3\begin{aligned} c_0 &= 02b_0 \oplus 03b_1 \oplus 01b_2 \oplus 01b_3 \\ c_1 &= 01b_0 \oplus 02b_1 \oplus 03b_2 \oplus 01b_3 \\ c_2 &= 01b_0 \oplus 01b_1 \oplus 02b_2 \oplus 03b_3 \\ c_3 &= 03b_0 \oplus 01b_1 \oplus 01b_2 \oplus 02b_3 \end{aligned}

Matrix is circulant with the row 02 03 01 0102\ 03\ 01\ 01. Multiply by 03 = XOR of xtime (02) and the identity (01).

Modes of operationSearch on YouTube

ModeFormulaNotes
ECBCi=EK[Pi]C_i = E_K[P_i]Simple, parallel; repeated plaintext blocks give repeated ciphertext blocks; do not use for long messages
CBCCi=EK[Pi⊕Ci−1]C_i = E_K[P_i \oplus C_{i-1}], C0=IVC_0 = IVChained; needs full blocks; sequential; error hits 2 blocks
CFBCi=Pi⊕EK[Ci−1]C_i = P_i \oplus E_K[C_{i-1}], C0=IVC_0 = IVStream mode (s bits); uses only the encryption function; errors spread over several blocks
OFBOi=EK[Oi−1]O_i = E_K[O_{i-1}], O0=IVO_0 = IV; Ci=Pi⊕OiC_i = P_i \oplus O_iKeystream independent of the message; bit errors stay put; never reuse the IV
CTROi=EK[CNTi]O_i = E_K[\mathrm{CNT}_i]; Ci=Pi⊕OiC_i = P_i \oplus O_iParallel, random access, preprocessing for both O and C

Hooks: Every Code Breaker Crashes One Counter (mode order). Errors: ECB one, CBC two, CFB several, OFB/CTR clean.

Public-key ciphersSearch on YouTube

RSA, DH and ECCSearch on YouTube

ItemFormula
RSA setupn=pqn = pq, ϕ(n)=(p−1)(q−1)\phi(n) = (p-1)(q-1), ee with gcd⁡(e,ϕ(n))=1\gcd(e,\phi(n))=1, d≡e−1(modϕ(n))d \equiv e^{-1} \pmod{\phi(n)}
RSA encrypt / decryptC=Me mod nC = M^{e} \bmod n; M=Cd mod nM = C^{d} \bmod n; keys PU={e,n}PU=\{e,n\}, PR={d,n}PR=\{d,n\}
RSA checkMed≡M mod nM^{ed} \equiv M \bmod n (Euler: ed=1+kϕ(n)ed = 1 + k\phi(n))
DH setupPublic: prime qq, primitive root aa. Private: xA<qx_A < q. Public key: yA=axA mod qy_A = a^{x_A} \bmod q
DH shared keyK=yBxA mod q=yAxB mod q=axAxB mod qK = y_B^{x_A} \bmod q = y_A^{x_B} \bmod q = a^{x_A x_B} \bmod q
DH exampleq=353q=353, a=3a=3, xA=97x_A=97, xB=233x_B=233: yA=40y_A = 40, yB=248y_B = 248, K=160K = 160
ECC setupCurve Eq(a,b)E_q(a,b), point GG of order nn; private nA<nn_A < n, public PA=nAGP_A = n_A G
ECC DHK=nAPB=nBPA=nAnBGK = n_A P_B = n_B P_A = n_A n_B G
ECC encryptCm={kG, Pm+kPb}C_m = \{kG,\ P_m + kP_b\}; decrypt: subtract nb(kG)n_b(kG)
ECC sizesECC nn = symmetric key x2 = RSA modulus x2: 112/160/224/256/384/512 ↔ 512/1024/2048/3072/7680/15360

RSA attacks: brute force, mathematical (factor nn / find ϕ(n)\phi(n) / find dd), timing (defences: constant time, random delays, blinding), chosen ciphertext (OAEP).

Integrity and signaturesSearch on YouTube

Hash and SHA-1Search on YouTube

ItemOne line
6 propertiesAny input size; fixed output; fast; one-way; weak collision (given xx, no y≠xy\ne x with H(y)=H(x)H(y)=H(x)); strong collision (no pair at all). 1-5 weak, 1-6 strong
UsesMIC, MAC (keyed hash), signatures, passwords, integrity anchors C=H(SAB∥M)C = H(S_{AB}\Vert M)
Birthday attackFind a pair with equal hashes; effort ≈2n/2\approx 2^{n/2} for an nn-bit digest. SHA-1 160 bits → 2802^{80}; brute force preimage 21602^{160}
SHA-1 paddingPad with 1 bit + zeros to length ≡448 mod 512\equiv 448 \bmod 512, append 64-bit length, message is a multiple of 512 bits
SHA-1 bufferA=67452301A=67452301, B=EFCDAB89B=EFCDAB89, C=98BADCFEC=98BADCFE, D=10325476D=10325476, E=C3D2E1F0E=C3D2E1F0
SHA-1 rounds4 rounds x 20 steps; KtK_t: 5A827999 / 6ED9EBA1 / 8F1BBCDC / CA62C1D6
Round functionsf1=(B∧C)∨(¬B∧D)f_1 = (B\wedge C) \vee (\neg B \wedge D), f2=B⊕C⊕Df_2 = B \oplus C \oplus D, f3=(B∧C)∨(B∧D)∨(C∧D)f_3 = (B\wedge C)\vee(B\wedge D)\vee(C\wedge D), f4=B⊕C⊕Df_4 = B \oplus C \oplus D
OutputCVq+1=SUM32(CVq,ABCDEq)CV_{q+1} = SUM_{32}(CV_q, ABCDE_q), MD=CVLMD = CV_L; SHA-1 160-bit digest, phased out after 2005

DSASearch on YouTube

GroupFormula
Globalqq = 160-bit prime, pp prime with 2L−1<p<2L2^{L-1} < p < 2^L, LL = 512..1024 multiple of 64, and q∣(p−1)q \mid (p-1)
Generatorg=h(p−1)/q mod p>1g = h^{(p-1)/q} \bmod p > 1
Keys0<x<q0 < x < q private; y=gx mod py = g^{x} \bmod p public
Sign (random kk, 0<k<q0<k<q, use once)r=(gk mod p) mod qr = (g^{k} \bmod p) \bmod q; s=k−1(H(M)+xr) mod qs = k^{-1}(H(M) + xr) \bmod q; signature (r,s)(r,s), 320 bits total
Verifyw=s−1 mod qw = s^{-1} \bmod q; u1=H(M)w mod qu_1 = H(M)w \bmod q; u2=rw mod qu_2 = rw \bmod q; v=[(gu1yu2) mod p] mod qv = [(g^{u_1} y^{u_2}) \bmod p] \bmod q; accept iff v=rv = r

Same-key-two-signatures reveals xx: never reuse kk (ElGamal behaves the same).

HMACSearch on YouTube

HMACK(M)=H(K+⊕ opad ∥ H(K+⊕ ipad ∥ M))\text{HMAC}_K(M) = H\big(K^+ \oplus\ \text{opad}\ \Vert\ H(K^+ \oplus\ \text{ipad} \ \Vert\ M)\big)

ipad = 3636..., opad = 5C5C..., key padded to the block size. Two-pass order: inner with ipad, outer with opad. Design objectives: use existing hash functions, cheap, easy to swap, keep performance, simple, sound interaction mechanics with hash behaviour.

Keys and authenticationSearch on YouTube

Key managementSearch on YouTube

ItemOne line
HierarchyMaster key (KDC only) → session key per connection
Symmetric via KDCOne master per party; KDC issues session keys; nonce + timestamps stop replays
Public-key distributionAnnouncement, publicly available directory, public-key authority, public-key certificates
CertificateBinds subject to public key, signed by CA; CA-only modification, anyone reads it
X.509 fieldsV, SN, AI, issuer X.500 name, TA (validity period), subject X.500 name, subject public-key info, issuer/subject unique ID (v2+), extensions (v3), signature
ChainCAs form a hierarchy: forward certificates to clients, backward to parents. User checks the issuer's certificate with a higher CA until a trusted one
RevocationCRL: compromised key, no longer certified by CA, CA certificate compromised

User authenticationSearch on YouTube

ItemOne line
Means K-P-I-DKnows (password, PIN), Possesses (token, smartcard), Is (static biometrics: fingerprint, retina), Does (dynamic: voice, signature). Combine card + PIN; all have issues
Replay defencesSequence numbers (impractical), timestamps (need synced clocks), challenge/response nonce (number used once, f(N)≠Nf(N) \ne N)
One-way (email)Header stays clear, body protected and sender authenticated inside the message
Needham-SchroederKDC exchange with nonces N1N_1, N2N_2; flaw: a replayed old ticket with a compromised session key is accepted. Fix: add timestamps (Denning)

Kerberos v4Search on YouTube

Kerberos v4 uses DES and symmetric keys only. The exchange has four steps:

  1. C→ASC \to AS: IDC∥IDtgs∥TS1ID_C \Vert ID_{tgs} \Vert TS_1 (once per logon).
  2. AS→CAS \to C: E(KC,[Kc,tgs∥IDtgs∥TS2∥Lifetime2∥Tickettgs])E(K_C,[K_{c,tgs} \Vert ID_{tgs} \Vert TS_2 \Vert Lifetime_2 \Vert Ticket_{tgs}]) — KCK_C comes from the password.
  3. C→TGSC \to TGS: IDV∥Tickettgs∥AuthenticatorCID_V \Vert Ticket_{tgs} \Vert Authenticator_C (once per service type); Authenticator carries TS3TS_3 against replays.
  4. C→VC \to V: TicketV∥AuthenticatorCTicket_V \Vert Authenticator_C; for mutual authentication V→CV \to C: E(Kc,v,[TS5+1])E(K_{c,v},[TS_5 + 1]).

Network securitySearch on YouTube

PGP message formatSearch on YouTube

Outer chain: ZIP → E(K_s) → R64 (radix-64 armour). Three content components, learn K-Sig-M:

ComponentFields
Session key componentKey ID of recipient's PUbPU_b; session key KsK_s, both inside E(PUb,⋅)E(PU_b, \cdot)
SignatureTimestamp; Key ID of sender's PUaPU_a; leading two octets of the digest; message digest, inside E(PRa,⋅)E(PR_a,\cdot)
MessageFilename; timestamp; data (compressed by ZIP, encrypted by E(Ks,⋅)E(K_s,\cdot))

SSL/TLSSearch on YouTube

ThingOne line
ArchitectureRecord protocol (confidentiality + integrity) under handshake, change cipher spec, alert, heartbeat
Record formatContent type, major, minor, compressed length (8/8/8/16 bits); fragment 214=163842^{14} = 16384 B; MAC 0/16/20 B via HMAC; total ≤214+2048\le 2^{14}+2048
Handshake, 4 phases1: client_hello / server_hello (version, session ID, cipher suite, compression, randoms). 2: certificate, server_key_exchange, certificate_request, server_hello_done. 3: certificate, client_key_exchange, certificate_verify. 4: change_cipher_spec + finished both ways
Change cipher spec1 message, 1 byte, value 1: pending state → current state
Alert2 bytes: level (warning 1, fatal 2) + code. Fatal kills the connection
Master secret48 bytes: PRF(pre_master_secret, "master secret", ClientHello.random ∥\Vert ServerHello.random); pre_master via RSA (48 B encrypted with server PU) or DH
Heartbeatheartbeat_request / response, set at Phase 1; proves liveness, keeps firewalls from idling out
TLS versionsSSL 2.0 1995, SSL 3.0 1996, TLS 1.0 RFC 2246 1999, 1.1 RFC 4346 2006, 1.2 RFC 5246 2008, 1.3 RFC 8446 2018

IPSecSearch on YouTube

ItemOne line
RFCs4301 architecture, 4302 AH, 4303 ESP, 4306 IKEv2
ServicesAccess control, connectionless integrity, data origin authentication, replay rejection, confidentiality, limited traffic flow confidentiality
Mode compareTransport: payload protection, host-to-host, outer IP header visible. Tunnel: whole packet encrypted under a new IP header, VPNs, gateways
SALogical one-way connection: algorithms, keys, lifetime; identified by SPI + IP destination + security protocol identifier; stored in the SAD
ESP layoutSPI, seq no, IV (optional), payload, TFC padding, padding 0-255, pad length, next header — encrypted; ICV after encryption, not encrypted
AH vs ESPAH authenticates all but mutable IP fields, no encryption (protocol 51); ESP encrypts + optional auth (protocol 50)
Anti-replaySeq counter from 0, +1 per packet, limit 232−12^{32}-1; receiver window (N−W+1)…N(N-W+1) \dots N
BundlesTransport adjacency or iterated tunneling; ESP+auth, inner ESP + outer AH, inner transport + outer ESP
IKEv2Negotiate SA parameters, authenticate endpoints, derive keys, rekey before lifetimes expire
  • Model: attacks → mechanisms → services (AACIN); the network model needs algorithm, keys, distribution, protocol.
  • Classical: substitution ciphers die to frequency analysis (Caesar, Playfair, Vigenère, autokey), OTP is unbreakable, transposition keeps frequencies, product ciphers stack confusion and diffusion.
  • s-DES: 8/10 bits, P10-LS1-P8 then LS2-P8, fKf_K with E/P, S0/S1, P4. DES: 64-bit block, 56-bit key, 16 Feistel rounds with 48-bit subkeys, S-boxes 6→4. AES: 128-bit state, 10/12/14 rounds, SubBytes-ShiftRows-MixColumns-AddRoundKey, final round without MixColumns, GF 282^8 arithmetic mod 0x11B and xtime with 0x1b.
  • Modes: ECB, CBC, CFB, OFB, CTR — formulas above, error behaviour and parallelism hooks.
  • Asymmetric: RSA Me mod nM^e \bmod n over factoring; DH axAxB mod qa^{x_A x_B} \bmod q (q=353q=353 example lands K=160K=160); ECC point arithmetic, K=nAnBGK = n_A n_B G, far smaller keys.
  • Signatures and integrity: hash 6 properties, SHA-1 4x20 steps with fixed KtK_t and magic buffer; DSA (r,s)(r,s) with v=rv = r; HMAC double-hash with ipad/opad.
  • Distribution and users: key hierarchy, X.509 fields and CA chains with CRLs, K-P-I-D authentication. Kerberos AS/TGS/V four steps with tickets and authenticators. PGP K-Sig-M inside R64.
  • Network security: TLS record + 4-phase handshake + 48-byte master secret through the PRF. IPSec AH (51, integrity only) vs ESP (50, encryption), transport/tunnel modes. SPI+destination+protocol SAs, 232−12^{32}-1 replay ceiling, IKEv2 keys.