Cryptography Fundamentals Questions
Core concepts and vocabulary of cryptography: confidentiality, integrity, authentication, and non-repudiation; the difference between symmetric and asymmetric primitives; and how standard algorithms, libraries, and protocols fit together. Covers threat models, common standards, and applying primitives and cryptographic libraries correctly to real-world security problems. The entry point for the cryptography track.
Describe Public Key Infrastructure (PKI) fundamentals: what a certificate is, what a Certificate Authority (CA) does, certificate chains and trust anchors, and a typical use of certificates in TLS. Keep the explanation high-level but include how trust is established and how certificate expiration affects secure channels.
Sample Answer
Direct answer
Public Key Infrastructure (PKI) is the system of certificates, certificate authorities, and
trust chains that lets a stranger's public key be trusted without meeting them first. A
certificate authority (CA) signs a certificate binding a public key to an identity; anyone who
already trusts that CA can then trust the certificate, and by extension the key inside it.
Structured elaboration
flowchart TD
Root["Root CA (trust anchor, pre-installed in OS/browser)"]
Inter["Intermediate CA (signed by Root)"]
Leaf["Server certificate (signed by Intermediate)"]
Root -->|signs| Inter
Inter -->|signs| Leaf
Leaf -->|presented during TLS handshake| Client["Client validates the whole chain"]
- Certificate: a data structure containing a public key, an identity (like a domain
name), a validity window, and a signature from whoever issued it. - Certificate authority (CA): a party trusted to verify identity claims before signing a
certificate. Trust in a CA is not proven cryptographically from scratch each time, it comes
from the CA's root certificate being pre-installed as a trust anchor in operating systems
and browsers. - Certificate chains: in practice, a root CA rarely signs end-entity (leaf) certificates
directly; it signs intermediate CAs, which sign the leaf certificates servers actually
present. Validating a certificate means walking this chain, checking each signature, until
reaching a root the client already trusts. - Use in TLS: during the handshake, the server presents its certificate (and usually the
intermediate chain); the client verifies the signature chain up to a trusted root, checks
the domain name matches, and checks the validity window, before it will trust the public
key for the key exchange.
Worked example
A browser connecting to example.com receives a leaf certificate for example.com signed by
"Intermediate CA X," which is itself signed by "Root CA R." The browser already has Root CA
R's certificate baked into its trust store. It verifies Intermediate CA X's signature using
Root CA R's public key, then verifies the leaf certificate's signature using Intermediate CA
X's public key. Only after both signatures check out, the domain name matches, and the
current date falls inside the leaf certificate's validity window does the browser proceed to
trust that public key for the handshake.
Trade-offs & pitfalls
- Certificate expiration: every certificate in the chain has a validity window; if the
leaf certificate's window ends and it is not renewed, clients will refuse the connection (or
warn loudly) even though nothing about the underlying keys has actually changed. This is a
frequent, entirely avoidable cause of production outages, which is why certificate expiry is
tracked as an operational alert, not just a one-time setup step. - Self-signed certificates skip the CA entirely (the certificate signs itself), which is fine
for internal testing but provides no independent identity verification for anyone who
hasn't been told in advance to trust that specific certificate.
Explain the core security properties a cryptographic hash function must have (preimage resistance, second-preimage resistance, collision resistance), name a couple of common algorithms, and give one example each of where a hash is the right tool (integrity checks, content-addressing) and where it is not (storing passwords without salting and stretching).
Sample Answer
Direct answer
A cryptographic hash function must be preimage resistant (given an output, you cannot find
an input that produces it), second-preimage resistant (given one input, you cannot find a
different input with the same output), and collision resistant (you cannot find any two
distinct inputs that share an output at all). Common algorithms today are SHA-256 and SHA-3;
MD5 and SHA-1 are broken for collision resistance and should not be used where that property
matters.
Structured elaboration
- Preimage resistance: given
H(m) = h, it should be computationally infeasible to find
anymthat producesh. This is what makes a hash "one-way." - Second-preimage resistance: given a specific
m1, it should be infeasible to find a
differentm2withH(m1) = H(m2). - Collision resistance: it should be infeasible to find any pair
m1 != m2with
H(m1) = H(m2), without fixing either input in advance. This is the property MD5 and SHA-1
have both practically broken (real collision attacks have been demonstrated for both). - Where a hash is the right tool: integrity checks (comparing a downloaded file's hash
against a published one to detect corruption or tampering), content-addressing (Git commit
hashes, package registries keying content by its digest so identical content always maps to
the same address), and as the digest step inside a digital signature: signing algorithms
sign a fixed-size hash of a message rather than the message itself, since asymmetric
operations are expensive on large inputs. - Where it is not the right tool: storing passwords with a bare, unsalted hash. Hash
functions are deliberately fast, which is exactly wrong for password storage: an attacker
with a stolen hash dump can try billions of guesses per second on commodity GPUs. Password
storage needs a slow, memory-hard key derivation function (Argon2id, scrypt, bcrypt), not a
general-purpose hash used directly.
Worked example
To see why collision resistance is the strongest property, compare a real hash to a toy,
clearly-broken one: H(x) = x mod 97. Take m1 = 5 and m2 = 102. 102 mod 97 = 5, so
H(5) = H(102) = 5: a collision found by inspection, with no search at all. That is exactly
what "not collision resistant" looks like. A real hash like SHA-256 produces a 256-bit output,
so the best known way to find any colliding pair is a generic birthday-bound search of roughly
2^128 attempts (the square root of 2^256 possible outputs), which is computationally out
of reach with current or foreseeable hardware. The mod-97 toy fails instantly because its
output space is only 97 values; a cryptographic hash needs both a large output space and no
structural shortcut into it.
Trade-offs & pitfalls
- Collision resistance and preimage resistance are different properties; a function can lose
one without immediately losing the other, which is why "MD5 has collisions" does not
automatically mean "MD5 leaks passwords," but it does mean you should not trust MD5 for
anything where an attacker choosing two colliding inputs would matter (like forging a signed
document). - "Hashing" and "encryption" are often confused: hashing is one-way and not meant to be
reversed at all, encryption is two-way and meant to be reversed with the right key. A hash
cannot be "decrypted" back to the original input, by design.
Walk through the hybrid (envelope) encryption pattern for protecting a large file or a message sent to multiple recipients: how the symmetric session key is generated, how it is wrapped with each recipient's public key, what integrity/authenticity protection you'd add, and how you'd support forward secrecy for recipients if the file might be re-shared later.
Sample Answer
Direct answer
Hybrid (envelope) encryption solves "encrypt this once for many recipients" by splitting the
job in two: generate one random symmetric key to encrypt the actual data, then encrypt
("wrap") that small key separately for each recipient using their public key. The body is
encrypted once; only the tiny key gets encrypted N times.
Structured elaboration
- Generate the session key. Pull a fresh, random key from a CSPRNG (cryptographically
secure pseudo-random number generator), for example a 256-bit AES key. Call this the
Data Encryption Key (DEK). It exists only for this file/message. - Encrypt the payload once with an AEAD cipher. Use the DEK with AES-256-GCM or
XChaCha20-Poly1305 and a fresh nonce. AEAD (authenticated encryption with associated
data) gives you confidentiality (the data is unreadable without the key) and
integrity/authenticity (a forged or tampered ciphertext fails to decrypt) in one pass,
which directly answers the "what integrity protection" part: you do not bolt on a
separate MAC, the AEAD tag already is one. - Wrap the DEK per recipient. For each recipient, encrypt the small DEK with that
recipient's public key: RSA-OAEP is the simple choice, or (better for many recipients or
small devices) an ECDH-based wrap, ECIES-style: derive a one-time wrapping key from
ECDH(sender_ephemeral, recipient_public) and use it to encrypt the DEK. Store one small
wrapped-key blob per recipient next to the single ciphertext body. This is the
multi-recipient piece: the expensive part (encrypting the file) happens once; only the
cheap part (wrapping ~32 bytes) repeats per recipient, so adding a recipient never means
re-encrypting the file. - Forward secrecy for later re-shares. A plain RSA-OAEP wrap is not forward secret: if
the recipient's long-term private key leaks years later, every DEK ever wrapped for them
can be recovered and every past file decrypted retroactively. If a file might be
re-shared later, wrap with a fresh ephemeral key exchange per share event instead of a
static wrap: generate a one-time ephemeral key pair, run ECDH against the recipient's
long-term public key, derive the wrap key through a KDF (key derivation function, e.g.
HKDF) over that shared secret, and never persist the ephemeral private key anywhere.
Each share event is now cryptographically independent: compromising one wrap does not
expose any other share of the same file, because there is no single long-lived
server-side wrapping secret that unlocks all of them at once. - Avoid full re-encryption on re-share. None of this requires touching the ciphertext
body again. Keep the DEK and the AEAD ciphertext exactly as they are; a re-share only
adds a new wrapped-DEK entry for the new recipient (fresh ephemeral wrap as in step 4).
You only rotate the DEK itself, which does mean re-encrypting the body, if you need to
revoke an earlier recipient's access to future reads.
Worked example
A 2 GB backup file needs to go to 3 recipients. You generate one 256-bit DEK, run AES-256-GCM
once over the 2 GB (one pass over the large data), then wrap that same 32-byte DEK three
times, once per recipient's public key. Total asymmetric operations: 3, regardless of file
size. If a 4th person needs access next month, you do one more 32-byte wrap using a fresh
ephemeral exchange; the 2 GB ciphertext is never touched again.
Trade-offs & pitfalls
- RSA-OAEP wrapping is simpler to implement and audit; ECDH-based wrapping is smaller and
cheaper per recipient, which matters more as recipient count grows, but adds an extra
ephemeral-key-handling step. - This exact pattern is what OpenPGP's multi-recipient encryption and cloud KMS "envelope
encryption" (wrapping a data key with a master key) both do. - Common mistake: reusing the AEAD nonce across re-encryptions of the same DEK, or reusing
one static wrap key across shares when forward secrecy was actually required. Both quietly
remove the protection the design was supposed to provide.
Explain the differences between collision resistance, preimage resistance, and second-preimage resistance in hash functions. Provide practical attack complexity estimates for MD5, SHA-1, and SHA-256, and state at what point you would mandate deprecation of a hashing algorithm within an organization.
Sample Answer
Direct answer
A cryptographic hash function is supposed to make three different attacks infeasible, and they are genuinely different properties, not three names for the same thing: collision resistance (hard to find any two distinct inputs that hash to the same output), preimage resistance (given a hash output, hard to find any input that produces it), and second-preimage resistance (given one specific input, hard to find a different input that hashes to the same value). MD5 and SHA-1 (Secure Hash Algorithm 1) have both had their collision resistance broken in practice; SHA-256 has not, at either a theoretical or practical level, and remains the safe current default.
Telling the three properties apart
| Property | Attacker is given | Attacker must find |
|---|---|---|
| Collision resistance | nothing specific | any two inputs x1 != x2 with hash(x1) == hash(x2) |
| Preimage resistance | a hash value h | any input x with hash(x) == h |
| Second-preimage resistance | a specific input x1 | a different input x2 with hash(x2) == hash(x1) |
Collision resistance is the weakest guarantee to break, because the attacker has complete freedom to choose both inputs, which is exactly what makes it vulnerable to the birthday paradox: you don't need to search anywhere near the full output space, only until any two outputs among many attempts happen to match.
Worked example: why collisions are so much cheaper than preimages
For a hash with an n-bit output, the generic (structure-agnostic) cost to find a collision by brute force is about 2n/2 attempts, while a generic preimage or second-preimage attack costs about 2n:
2128/2=264≈1.8×1019 (MD5’s generic collision bound) 2160/2=280≈1.2×1024 (SHA-1’s generic collision bound) 2256/2=2128≈3.4×1038 (SHA-256’s generic collision bound)Real cryptanalysis has done far better than these generic bounds for the two broken algorithms:
- MD5: differential collision attacks (Wang et al., refined repeatedly since 2004) make finding a collision practical in well under a second on an ordinary laptop, vastly cheaper than the generic 264 bound. MD5's preimage resistance is comparatively less damaged; no practical preimage attack is known, but its collision break alone rules it out for anything security-relevant.
- SHA-1: a real, published collision (the "SHAttered" attack, 2017) was demonstrated at a complexity of roughly 263.1 operations, about 100,000 times cheaper than the generic 280 birthday bound for its 160-bit output, and a cheaper chosen-prefix variant followed in 2020 at a small fraction of the original attack's cost. SHA-1's preimage resistance is not known to be practically broken, but its collision break is sufficient reason to treat it as unsafe for anything that depends on collision resistance, most notably digital signatures.
- SHA-256: no attack better than the generic birthday and brute-force bounds is known against either its collision or preimage resistance; it remains the safe, current default for new systems.
When to mandate deprecation
Don't wait for a public, practical break to start migrating, cryptographers had already been flagging MD5's collision weaknesses years before 2004's practical attacks, and SHA-1's theoretical weaknesses were known well before the 2017 demonstration. A defensible organizational policy is to mandate deprecation once a hash's best known attack (not just the generic bound) drops to a complexity a well-resourced attacker could plausibly reach within your data's required confidentiality or integrity lifetime, treating "cryptographers have found a meaningfully-better-than-generic attack at all" as the trigger to start planning migration, and "a practical, demonstrated break exists" as the trigger to have already finished it.
Trade-offs and pitfalls
A common mistake is judging a hash function purely by its output length rather than by known attacks against it: SHA-1's 160-bit output sounds larger and safer than MD5's 128-bit output, but its real collision resistance today is a demonstrated practical break, not a theoretical margin. Always check the current state of published cryptanalysis for the specific algorithm and use case (collision resistance failing matters enormously for signatures, much less for some non-adversarial checksums), rather than trusting the nominal output size alone.
Define initialization vector (IV) and nonce as used in block/stream cipher modes. What properties must each satisfy (randomness vs uniqueness), and what happens in practice if a nonce is reused with a mode like GCM?
Sample Answer
Direct answer
An initialization vector (IV) or nonce ("number used once") is extra, non-secret input
combined with the key so that encrypting the same plaintext twice under the same key does not
produce the same ciphertext twice. Different cipher modes need different properties from it:
some need it unpredictable, all of them need it to never repeat under the same key. Reusing a
nonce with GCM is not a minor bug, it is a full break of that key's confidentiality and
authenticity.
Structured elaboration
- CBC mode: the IV should be unpredictable (ideally generated by a CSPRNG) and must never
repeat under the same key. It does not need to be secret, it is normally sent alongside the
ciphertext. - CTR and GCM modes: the nonce's essential property is uniqueness per key, not secrecy or
even unpredictability. GCM's internal encryption is CTR-mode-like: the nonce plus a
block counter generates a "keystream" that gets XORed with the plaintext. - Why nonce reuse under GCM is catastrophic: if the same key and nonce encrypt two
different messages, both use the identical keystream. XORing the two ciphertexts together
cancels the keystream out entirely, leaving the XOR of the two plaintexts, a classic
"two-time pad" break: an attacker who knows or guesses one plaintext immediately recovers
the other. GCM reuse is worse still: it can also expose the authentication subkey, letting
an attacker forge arbitrary valid messages for that key going forward.
Worked example
Say a reused keystream (from encrypting two different messages under the same key and nonce)
happens to be the bytes A5 3C 91 77. Encrypting "HELP" (48 45 4C 50 in hex) with it gives
ciphertext C1 = 48^A5, 45^3C, 4C^91, 50^77 = ED 79 DD 27. Encrypting "RUN!" (52 55 4E 21)
with the same keystream gives C2 = 52^A5, 55^3C, 4E^91, 21^77 = F7 69 DF 56. Now XOR the
two ciphertexts: C1 xor C2 = ED^F7, 79^69, DD^DF, 27^56 = 1A 10 02 71. That is exactly
"HELP" xor "RUN!" (48^52, 45^55, 4C^4E, 50^21 = 1A 10 02 71), with the keystream fully
canceled out. If an attacker already knows or can guess one plaintext ("HELP"), they recover
the other directly: M2 = M1 xor (C1 xor C2) = 48^1A, 45^10, 4C^02, 50^71 = 52 55 4E 21, which
decodes back to "RUN!". No key was ever recovered, and none was needed.
Trade-offs & pitfalls
- "Random" is a stronger property than "unique," but for GCM specifically, uniqueness is the
requirement that must never be violated; a random-but-short (96-bit) nonce chosen fresh
every time is standard practice precisely because random values are very unlikely to
collide at reasonable message volumes, not because randomness itself is the requirement. - A common real mistake is initializing a nonce counter to zero on every server restart or
every new connection, silently creating repeats across restarts or connections that share a
key.
Unlock Full Question Bank
Get access to all 30 Cryptography Fundamentals interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.