Cryptanalysis and Security Proofs Questions
Evaluating the strength of cryptographic constructions: attack techniques, cryptanalysis of ciphers and protocols, reduction-based security proofs, and formal analysis. Covers reasoning about what an adversary can and cannot do and how security guarantees are argued rigorously. The offensive-and-verification counterpart to scheme design.
A hash function is built using the Merkle–Damgård construction with a 64-bit chaining value and no finalization transform; you need to evaluate security. Determine generic collision and preimage complexities, explain the implications of length-extension attacks for using this hash as a MAC, and recommend specific mitigations (for example HMAC, wide-pipe design) with justification.
Sample Answer
Direct answer
A 64-bit chaining value with no finalization transform is broken on two independent axes: generic collision resistance falls to about 2^32 (the birthday bound on a 64-bit state) and preimage resistance to about 2^64, both far too weak for modern use, and separately, an unfinalized Merkle-Damgard (MD) hash leaks its exact internal state as its output, so anyone who knows H(secret || known_message) can extend that message and compute a valid hash of a longer message they choose, without ever learning the secret. That second property, called a length-extension attack, means this hash is completely unsafe as a MAC (message authentication code, a tag proving a message came from someone holding a secret key) via the naive construction H(key || message); the fix is HMAC (a specific keyed construction that resists length extension even when built from a vulnerable hash) or a genuine wide-pipe redesign.
Structured elaboration
Generic complexities from the raw chaining-value width alone:
collision work≈264/2=232,preimage work≈264Why length extension works: in plain MD construction, a message is padded and processed block by block through a compression function f, where each block's output becomes the exact internal chaining-value state fed into the next block. With no separate finalization step, the FINAL block's output is presented directly as the digest. So if an attacker knows D = H(secret || m) but not secret, D is exactly the correct internal state after processing secret || m. The attacker appends the standard MD padding for that (unknown-length, but guessable in small increments) input, then feeds their own chosen extra data as further compression-function blocks starting from state D, producing a valid H(secret || m || padding || extra) without ever knowing secret. This is precisely how a naive keyed-hash MAC gets forged.
Mitigations, with justification for each:
- HMAC: computes H((key XOR opad) || H((key XOR ipad) || message)). The OUTER hash call means the attacker never observes the raw internal state after the sensitive (key-dependent) computation; extending the outer digest would require inverting the outer hash first, which the hash's own preimage resistance already prevents. This is why HMAC is proven to resist length extension even when H itself does not.
- Wide-pipe design: use an internal chaining state substantially larger than the final output (for example, double the output width), then truncate at the very end through a genuine finalization transform distinct from ordinary chaining. This both raises internal collision resistance above the OUTPUT size's birthday bound and, critically, means the digest no longer equals the raw internal state, closing the length-extension gap directly.
- Fix the fundamental undersizing: independent of the length-extension issue, a 64-bit chaining value is far too small for any modern target; any redesign needs at least a 256-bit internal state.
Worked example
At 64 bits, the birthday-bound collision work is 2^32 = 4,294,967,296 evaluations. At a modest 10 million evaluations per second (well within reach of ordinary commodity hardware), that is:
107232≈429.5 seconds≈7.2 minutesA collision in a system relying on this hash's integrity (for example a naive content-addressed store, or a signature scheme trusting the hash for collision resistance) is trivially findable in the time it takes to make coffee, on a single laptop.
Trade-offs and pitfalls
A common wrong turn is thinking "just use a bigger Merkle-Damgard hash with no finalization, that fixes it." It does not: length extension is a structural property of unfinalized MD chaining regardless of state size. This is exactly why SHA-256, a strong, properly-sized modern hash, is still technically vulnerable to length extension in practice (it uses plain MD-style chaining with no distinct finalization step), unlike SHA-3 (a sponge construction, which does not expose raw internal state as output by design) or BLAKE2/BLAKE3 (which use a different finalization). Another wrong turn is trying to defend against extension by simply prepending a length field; it does not close the gap the way HMAC's nested double-hash structure does, because the attacker still has direct access to the vulnerable internal state as the digest.
You need to prove security for a two-party authenticated key exchange protocol and are deciding between the CK model, the eCK model, and full Universal Composability. Walk through what's actually different about the adversary each one lets you model, for example ephemeral-key or session-state reveal, and which of those differences change whether you can even express properties like perfect forward secrecy or key-compromise impersonation.
Sample Answer
Direct answer
For a standalone two-party authenticated key exchange (AKE) protocol, the extended Canetti-Krawczyk model (eCK) is the right default: it is the first of the three that lets you actually express and prove resistance to ephemeral-key leakage and key-compromise impersonation (KCI). Reach for the original Canetti-Krawczyk model (CK) only where you are confident ephemeral-state exposure is out of scope, and reach for full Universal Composability (UC) only when the protocol has to be proven secure while composed with other protocols running concurrently, since UC's stronger guarantee comes with a heavier proof and a real setup-assumption cost.
Structured elaboration
All three models let the adversary reveal a completed session's key and corrupt a party's long-term secret key; what differs is exactly what else the adversary can touch, and that difference is what determines which properties you can even state:
- CK. Models session-key reveal and long-term key corruption, but does not model exposing a session's internal ephemeral state before it completes. It can express a form of perfect forward secrecy (PFS: past session keys stay secure even after a party's long-term key is later revealed), but only for the class of attacks it can see; it has no way to express an attacker who separately compromises a session's ephemeral randomness (a bad random-number generator or a side-channel leak), because that action is not in its adversary's toolbox at all.
- eCK. Adds explicit ephemeral-key/session-state reveal to the adversary's toolbox, alongside long-term key reveal, including combinations (long-term key of one party plus ephemeral key of the other) that CK cannot model. That extra query lets eCK state and prove KCI-resistance as a first-class property (an attacker who holds a victim's long-term key but not the honest peer's ephemeral secret for the tested session still cannot break it) and a stronger form of forward secrecy that covers ephemeral-state leakage.
- UC. Does not fix a specific set of adversary queries at all; instead you define an ideal functionality that specifies exactly what the protocol should guarantee, and prove the real protocol "emulates" that functionality under an arbitrary environment, including arbitrary concurrent composition with other protocols. PFS and KCI-resistance are expressible in UC exactly to the extent you build them into the ideal functionality, and the guarantee then survives composition, which neither CK nor eCK promises at all.
Worked example
Two concrete deployment scenarios make the choice mechanical. If the protocol is the sole key-exchange mechanism and the realistic threat is a device whose stored ephemeral randomness might leak separately from its long-term identity key (a bad local RNG, a side-channel), that is exactly the eCK threat model: you would formalize adversary queries as Send, SessionKeyReveal, EphemeralKeyReveal, LongTermKeyReveal, and Test, and prove no PPT (probabilistic polynomial-time, an algorithm whose running time is bounded by a polynomial in the security parameter and that may use randomness) adversary distinguishes the Test session's key from random unless it has queried both LongTermKeyReveal and EphemeralKeyReveal on the same party in the same tested session (the standard eCK "freshness" condition), which directly captures both KCI-resistance and ephemeral-leakage forward secrecy. If instead this protocol will be embedded as a sub-component inside a larger system, run concurrently with many other protocol instances, the standalone eCK guarantee does not automatically survive that composition, so the proof needs to move to UC: define an ideal key-exchange functionality FKE that hands each session a uniformly random key unless the adversary corrupts a party, show the real protocol UC-realizes FKE (typically requiring a setup assumption such as a public-key infrastructure or a common reference string), and the UC composition theorem then gives security for free no matter what surrounds it.
Trade-offs and pitfalls
None of this is a free strength upgrade. eCK's freshness condition has known subtleties, and some published eCK-secure protocols were later found to have gaps in exactly how that condition was stated; eCK security also does not by itself guarantee anything under concurrent composition, so "eCK-secure" is not automatically "safe to embed anywhere." UC gets composition for free but only for whatever the ideal functionality actually specifies; an under-specified FKE silently fails to capture the property you actually wanted, and UC proofs often force real changes to the protocol to accommodate the needed setup assumption. The pitfall to avoid is treating "we proved it secure in CK" as if it already implies the eCK or UC guarantees; it explicitly does not, because CK's adversary was never given the ability to touch ephemeral state in the first place.
Given two sequential reductions: Adv_S(A) <= a1 * Adv_P(B) + b1 and Adv_P(B) <= a2 * Adv_Q(C) + b2 with constants a1=2^10, b1=2^-30, a2=2^20, b2=2^-40, compute the maximum Adv_Q(C) required to ensure Adv_S(A) <= 2^-60. Show full algebraic steps, identify which constants dominate the loss, and discuss the practicality of meeting the resulting Adv_Q(C) bound in terms of hardness assumptions and parameter sizes.
Sample Answer
Direct answer
Plugging the constants straight in, the two additive loss terms alone already sum to 2−29, and that floor sits far above the 2−60 target before AdvQ(C) contributes anything at all. So there is no non-negative value of AdvQ(C) that makes the chain meet the target: the additive losses, not the multiplicative blow-up, are what kill this bound.
Structured elaboration
An "advantage" AdvX(A) is the probability, above a pure-guessing baseline, that adversary A wins security game X; it is a probability, so it always sits in [0,1] and every term below shares that same basis. A chained (sequential) reduction composes two hops by substituting the inner bound into the outer one:
AdvS(A)≤a1⋅AdvP(B)+b1,AdvP(B)≤a2⋅AdvQ(C)+b2 ⇒AdvS(A)≤a1a2⋅AdvQ(C)+(a1b2+b1)The multiplicative constants (a1,a2) typically come from "guess which of several oracle queries matters" style steps in a reduction (the same q-factor loss pattern that shows up in reductions built around guessing which oracle query matters); the additive constants (b1,b2) are usually structural floors, such as a birthday-style collision probability or a statistical simulation gap, that do not shrink no matter how small the underlying hard-problem advantage is driven.
Worked example
a1a2=210⋅220=230,a1b2=210⋅2−40=2−30 a1b2+b1=2−30+2−30=2−29 AdvS(A)≤230⋅AdvQ(C)+2−29Requiring AdvS(A)≤2−60 means we need
230⋅AdvQ(C)≤2−60−2−29The right-hand side is negative (since 2−60≪2−29), so the inequality has no solution with AdvQ(C)≥0: even setting AdvQ(C)=0 only gets AdvS(A)≤2−29, which is about 231 times larger than the 2−60 target (2−29/2−60=231). The dominant constants are b1 and a1b2, each contributing exactly 2−30 to the additive floor; the multiplicative term a1a2=230 never even enters the feasibility question, because the chain is infeasible before it gets a chance to matter.
Trade-offs and pitfalls
The common wrong move here is to react to an infeasible bound by "making Q harder", i.e. assuming a larger security parameter for the base problem C. That does nothing, because AdvQ(C) only ever appears through the multiplicative term; shrinking it toward 0 still leaves the 2−29 additive floor untouched. Reaching a genuine 2−60 bound requires either (a) a strictly tighter proof for at least one hop, so that its additive loss term is itself close to 2−60 or smaller (for a birthday-style term this usually means increasing an internal parameter, since such terms scale like q2/2n in the number of queries q and a state size n, not like q/2n), or (b) accepting that the composed proof only supports a much weaker concrete bound and relying on asymptotic ("negligible") security language instead of a specific numeric target. Chained reductions are common in real proofs (a scheme reduces to a primitive, which reduces to a hardness assumption), and every hop can independently contribute both a multiplicative and an additive term; auditing which term dominates before recommending a parameter fix is exactly the discipline this problem is testing.
A custom key-exchange uses ephemeral ECDH to derive session keys but does not include explicit key confirmation and binds only long-term public keys to identities off-band. Analyze protocol-level attacks that this design enables, such as man-in-the-middle, unknown-key-share, replay, downgrade, and key-compromise impersonation. For each attack provide a concrete scenario, severity, and a precise protocol-level countermeasure.
Sample Answer
Direct answer
An ephemeral ECDH (Elliptic Curve Diffie-Hellman, a way for two parties to derive a shared secret from public/private key pairs on an elliptic curve) handshake with no key confirmation and no cryptographic binding between the exchanged ephemeral keys and authenticated identities is vulnerable to a full active man-in-the-middle (MITM), plus several subtler protocol-level attacks: unknown-key-share, replay, downgrade, and key-compromise impersonation (KCI). Every one of these traces back to the same design gap, nothing in the exchanged bytes proves which identity chose which ephemeral key, right now, for this specific session, and every fix adds explicit authentication (a signature or MAC over the transcript) and freshness, not just an off-band identity binding.
Structured elaboration
| Attack | Concrete scenario | Severity | Precise countermeasure |
|---|---|---|---|
| Man-in-the-middle | Attacker M intercepts Alice's ephemeral key and substitutes her own to Bob, and intercepts Bob's reply and substitutes another of her own to Alice. M now shares one ECDH secret with Alice and a separate one with Bob, decrypting and re-encrypting everything while both sides believe they are talking directly to each other. | Critical: silent, total loss of confidentiality and integrity. | Sign the ephemeral public key (ideally the full transcript of both parties' ephemeral keys) with each party's long-term identity key before either side trusts it, so M cannot produce a valid signature over her own substituted key. |
| Unknown key-share | The protocol never binds WHICH identity's key material was used inside the derived secret, only loosely off-band. Alice believes she is exchanging keys with "Eve," but the actual Diffie-Hellman computation ties to Bob's key material, so a message Alice intends for Eve ends up authenticated under Bob's identity context. | High: authorization/attribution bypass, ciphertext itself can look fine end to end. | Bind both parties' identities explicitly into the signed transcript or the key-derivation context (for example an HKDF info parameter), so the derived key depends on who both sides believe they are talking to, not just the raw Diffie-Hellman values. |
| Replay | Attacker captures a full valid handshake and replays Alice's old ephemeral public key (with no freshness input) into a new session. Bob re-derives the same shared secret as the earlier session, letting old encrypted traffic be replayed and accepted, or causing catastrophic key or nonce reuse in the symmetric layer above it. | Medium to high, depending on what gets replayed. | Bind a fresh, unpredictable nonce chosen by the receiving side (not just the sender) into the signed transcript or key-confirmation MAC, so any replayed handshake produces a mismatch the receiver rejects as stale. |
| Downgrade | Attacker manipulates the initial parameter negotiation so both sides "agree" to a weaker curve or a deprecated fallback mode with known weaknesses, which the attacker can then break far more cheaply. | High, if a genuinely weaker fallback exists and is not independently hardened. | Sign or MAC the full negotiation transcript, including both the offered and the chosen parameter lists, as part of an authenticated finish step, exactly the pattern TLS uses in its Finished message. |
| Key-compromise impersonation | An attacker who has compromised Bob's long-term private key (but not Alice's) actively impersonates Alice to Bob in a new session, because the scheme's authentication of "this message is from Alice" implicitly relies on Bob's own static key material rather than requiring Alice's own signature. | High, but conditional on the responder's static key already being compromised, a strong precondition, though exactly the case a well-designed scheme should still resist. | Authenticate each party's messages with that party's OWN signature key exclusively (a true signed-DH design), rather than a construction where knowledge of the responder's static key alone is sufficient to forge messages "from" the initiator. |
Worked example
A minimal fix, in the style of a SIGMA (SIGn-and-MAc) handshake, addresses all five rows at once:
A -> B: eA
B -> A: eB, Sig_B(eA || eB || "B"), MAC_Kconf("B confirms")
A -> B: Sig_A(eA || eB || "A"), MAC_Kconf("A confirms")
where Kconf is derived (via a KDF, key derivation function) from the raw Diffie-Hellman secret Z = ECDH(eA, eB), and each side verifies the other's signature over the FULL transcript plus their own identity label before accepting the session. MITM fails because M cannot forge either party's signature; unknown-key-share fails because identity strings are bound into the signed transcript; replay fails because fresh ephemeral keys (and, if reuse across sessions is a concern, explicit nonces) make old transcripts invalid; downgrade fails because the full negotiated-parameter transcript is signed; KCI fails because each party authenticates with its own key, never the other party's.
Trade-offs and pitfalls
The fix costs real round trips and computation (signature generation and verification on both sides) versus the original lighter design, a genuine latency and complexity trade-off. The most common wrong turn is trusting off-band binding of LONG-TERM identity keys as sufficient; it authenticates who owns a long-term key, but says nothing about which ephemeral key or session that identity actually consented to right now. An equally common wrong turn: adding key confirmation alone without transcript-binding signatures still leaves MITM open, because confirmation only proves both sides derived the SAME secret, which is true independently on each of M's two legs, M simply completes confirmation correctly and separately with Alice and with Bob.
Explain the game-hopping technique commonly used in reductionist proofs. Describe how to construct a sequence of games, what constitutes a valid hop between games, how to bound the adversary's advantage change across hops, and demonstrate with a short example of two hybrid games and their advantage differences.
Sample Answer
Direct answer
Game-hopping proves two games are indistinguishable by building a chain of intermediate games between them, changing one small, individually justifiable thing at each step, and then adding up the (small) advantage change from every step; if every hop is provably small, the total gap between the first and last game is provably small too.
Structured elaboration
Constructing the sequence. Start with G0, the real game (or protocol) you actually care about, and end with Gk, a simplified "ideal" game whose security is obvious by inspection (for example, one where the challenge bit is information-theoretically hidden from the adversary). Each hop Gi→Gi+1 changes exactly one localized, analyzable component, such as replacing a keyed pseudorandom function (PRF, a keyed function family no efficient adversary can distinguish from a truly random function on chosen inputs) with a genuinely random function, or replacing a real plaintext with an all-zero placeholder.
What makes a hop valid. A hop is valid if you can exhibit a reduction: an algorithm B that uses any adversary A distinguishing Gi from Gi+1 to either break an underlying primitive or trigger a bounded, negligible statistical event (such as a collision). The hop is only as trustworthy as that reduction.
Bounding the total advantage. Because each hop only changes the adversary's view by a small amount, the triangle inequality bounds the total gap by the sum of the per-hop gaps:
AdvA(G0,Gk) ≤ i=0∑k−1AdvA(Gi,Gi+1)and each term in that sum is itself bounded by a reduction to a primitive plus a negligible slack term ϵi:
AdvA(Gi,Gi+1) ≤ AdvBi(primitive)+ϵiWorked example
A two-hop instance: G0 derives a nonce as r=Fk(s) using a keyed PRF F. G1 replaces Fk with a truly random function R; any adversary that distinguishes G0 from G1 directly yields a PRF distinguisher B (just forward its queries to Fk or R and relay the answer), so
AdvA(G0,G1) ≤ AdvB(PRF)G2 goes one step further and replaces r with a value drawn uniformly at random, independent of s entirely (removing the functional dependence). This differs from G1 only in the rare event that two different inputs s,s′ collide under R's independent-sampling behavior, bounded by some negligible ϵ; combining both hops,
AdvA(G0,G2) ≤ AdvB(PRF)+ϵTo see this bound as real numbers instead of symbols, instantiate it: suppose the PRF F has distinguishing advantage at most AdvB(PRF)≤2−64, R's output range (the nonce space) has size 280, and up to q=220 distinct values of s get used across all sessions. The collision event bounding the G1→G2 hop follows a standard birthday-style bound:
ϵ ≤ 2⋅280q2 = 281240 = 2−41so
AdvA(G0,G2) ≤ 2−64+2−41 ≈ 2−41Because 2−64 is astronomically smaller than 2−41, it is the second hop's collision term, not the first hop's PRF term, that actually dominates the final bound: with only two hops here, the weakest hop sets the overall security level, not some average of the two.
Trade-offs and pitfalls
Two hops here composed cleanly because each one was independently justifiable and the events they relied on (a PRF distinguisher, a sampling collision) don't interact; with many hops, the pitfalls concentrate in exactly that interaction. First, adaptive adversaries can make a hop that looked safe in isolation actually leak information across hops if later game changes depend on earlier adversary choices, so each reduction has to be checked against the full adaptive adversary, not a simplified non-adaptive one. Second, it is easy to under-count how many hops are really needed (silently skipping a step that looks "obviously fine") and end up with an unjustified reduction hiding inside what looks like a single valid hop. Third, summing many hops, even small ones, can itself blow up the bound (an n-hop argument with per-hop loss ϵ gives total loss nϵ, exactly the same mechanism behind an n-hop hybrid-argument bound), so counting the number of hops is part of judging whether the final concrete bound is actually useful.
Unlock Full Question Bank
Get access to all Cryptanalysis and Security Proofs interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.