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.
What is authenticated encryption (AEAD) in practical terms? Describe the API shape (plaintext, associated data, nonce in; ciphertext and authentication tag out), the security properties it provides, and give a concrete example of an attack that becomes possible if you use plain (unauthenticated) encryption instead.
Sample Answer
Direct answer
Authenticated encryption (AEAD, authenticated encryption with associated data) is encryption
that also proves the ciphertext was not tampered with. The API takes plaintext, a nonce (a
number used once), and optional associated data (AD, extra context that must be visible and
authenticated but not itself encrypted, like a protocol version byte); it returns ciphertext
plus an authentication tag. On decrypt, if the tag does not verify, you get no plaintext at
all, not a corrupted one.
Structured elaboration
- Inputs: plaintext, a nonce (unique per encryption under a given key, does not need to
be secret), and associated data (AD): data you want authenticated but left in cleartext,
for example a message header or routing metadata a middlebox needs to read. - Outputs: ciphertext (same length as the plaintext) and an authentication tag (a fixed
size, typically 16 bytes for AES-GCM), which travels alongside the ciphertext. - Security properties: confidentiality of the plaintext, and integrity/authenticity of
both the ciphertext and the associated data. Decryption is a single atomic operation:
verify the tag first, and only release plaintext if it matches. Common real
implementations are AES-GCM and ChaCha20-Poly1305.
Worked example
Contrast this with plain, unauthenticated encryption, say AES in CBC mode (CBC, Cipher Block Chaining, is a mode that splits the data into fixed-size chunks called blocks and chains each block onto the previous one) with no separate
integrity check. CBC decryption XORs each ciphertext block with the previous ciphertext block
(or the IV for the first block, where IV means initialization vector, a random starting block used because the very first block has no previous ciphertext block to chain onto) after a block-cipher decrypt (a block cipher, such as AES, is the core algorithm that transforms one fixed-size block at a time). An attacker who can flip bits in
a ciphertext block causes a predictable, corresponding bit flip in the next decrypted
plaintext block, with no error raised, because CBC decryption has no way to detect tampering
on its own. This is the mechanism behind real padding-oracle attacks (Vaudenay's 2002 attack,
and the 2014 POODLE attack on SSLv3's CBC handling): by sending crafted ciphertexts and
watching whether the server complains about bad padding, an attacker recovers the plaintext
one byte at a time without ever learning the key. AEAD closes this off structurally: any bit
flip anywhere in the ciphertext or associated data changes the tag, so a tampered message is
rejected before any plaintext is returned, and there is no padding-error side channel to
probe in the first place.
Trade-offs & pitfalls
- AD is authenticated but not confidential: do not put anything secret in it expecting
encryption; it is meant for routing/context fields that must stay legible. - Reusing a nonce under the same key breaks the security guarantee entirely for most AEAD
modes (this is worse for GCM specifically, where it can also leak the authentication
subkey). - "Encrypt, then separately compute an HMAC yourself" (encrypt-then-MAC) achieves the same
goal as AEAD but pushes the correctness burden onto you; AEAD ciphers bundle it so there is
one call to get right instead of two to sequence correctly.
Describe elliptic curve cryptography (ECC) conceptually and explain why modern systems favor it over RSA for equivalent security: key sizes, computational cost, bandwidth, and typical use cases (signatures, key exchange). Name a couple of widely-used curves and any trade-offs worth flagging.
Sample Answer
Direct answer
Elliptic curve cryptography (ECC) does the same job as RSA, public-key encryption and
signatures, using the algebraic structure of points on an elliptic curve instead of large
integer factorization. It reaches the same security level as RSA with much smaller keys,
because the best known attack against the underlying elliptic-curve discrete-log problem has
no sub-exponential shortcut, unlike RSA's factorization problem.
Structured elaboration
- Key sizes: a 256-bit elliptic-curve key (P-256) provides roughly the same security as a
3072-bit RSA key; a 384-bit curve (P-384) roughly matches a 7680-bit RSA key. The gap widens
as the target security level rises. - Computational cost: ECC signing and key-generation operations are cheap compared to RSA
at an equivalent security level, since RSA's cost grows faster than ECC's as key size
increases. RSA public-key verification is actually cheap in absolute terms (a small public
exponent keeps that operation fast), but RSA's private-key operations and key generation get
noticeably expensive at 3072+ bits. - Bandwidth: ECC keys and signatures are dramatically smaller, a P-256 ECDSA signature is
roughly 64 bytes versus roughly 256 to 384 bytes for an RSA-2048/3072 signature. This matters
directly for TLS handshake size, mobile bandwidth, and embedded/IoT devices with tight memory
budgets. - Use cases: ECDSA for digital signatures, ECDH (and its ephemeral form, ECDHE) for key
exchange, both filling the same roles RSA and classic Diffie-Hellman fill, just cheaper. - Named curves: P-256 (also called secp256r1, a NIST-standardized curve) is the most
widely deployed; Curve25519 (used for X25519 key exchange) and Ed25519 (its signature
counterpart) are increasingly preferred, in part because their parameters were generated
through a fully documented, deterministic process, addressing concerns some practitioners
raised about the opacity of how certain NIST curve constants were originally chosen.
Worked example
A mobile app performs 1,000,000 TLS handshakes a day against its API. Each handshake carries
one server certificate signature. An RSA-3072 signature runs roughly 384 bytes; a P-256 ECDSA
signature runs roughly 64 bytes, a saving of 320 bytes per handshake. Across a day:
1,000,000 x 320 bytes = 320,000,000 bytes, that is, about 320 MB of signature bytes saved
daily just from the certificate switch, before counting any of the other handshake fields ECC
also shrinks. For a bandwidth-constrained mobile client population, that is a real, measurable
reason to prefer ECDSA over RSA beyond the abstract "smaller keys" framing.
Trade-offs & pitfalls
- ECC implementations are more delicate than RSA's: incorrect point validation, timing
side-channels during scalar multiplication, and "invalid curve" attacks are all
ECC-specific implementation pitfalls that a naive from-scratch implementation is likely to
get wrong. "Don't roll your own crypto" applies even more strongly to ECC than to RSA. - Choice of curve matters beyond raw key size: Curve25519/Ed25519 are designed to make
several classes of implementation mistakes (like weak point validation) structurally harder
to make than the older NIST curves do.
Explain the fundamental differences between symmetric and asymmetric encryption. Name real algorithms in each category, describe typical enterprise use cases for each (data at rest, key exchange, code signing, TLS), and give one concrete advantage and one limitation of each approach.
Sample Answer
Direct answer
Symmetric encryption uses one shared secret key for both encrypting and decrypting; it is
fast but requires that key to somehow reach every party who needs it. Asymmetric (public-key)
encryption uses a mathematically linked key pair, a public key anyone can have and a private
key only the owner holds, which solves the distribution problem but at a real performance
cost.
Structured elaboration
- Symmetric algorithms: AES (Advanced Encryption Standard), ChaCha20. Typical enterprise
use: encrypting data at rest (a database, a disk volume) and encrypting bulk traffic once a
session key exists.- Advantage: very fast, cheap enough to encrypt gigabytes of data with negligible overhead.
- Limitation: both sides need the same key beforehand; there is no built-in mechanism for
two parties who have never met to agree on one safely over an open channel.
- Asymmetric algorithms: RSA, ECDSA/ECDH (elliptic curve variants). Typical enterprise
use: key exchange (establishing a shared secret over an untrusted network), and code/document
signing (proving who published something, and that it was not altered).- Advantage: solves key distribution; the public key can be published openly and only the
matching private key can decrypt or sign. - Limitation: orders of magnitude slower than symmetric ciphers and produces much larger
ciphertext relative to the data size, which makes it impractical for encrypting bulk data
directly.
- Advantage: solves key distribution; the public key can be published openly and only the
Worked example
TLS (the protocol behind HTTPS) is the everyday case: a browser and a server have never
shared a secret in advance, so they use asymmetric key exchange (ECDHE, backed by the
server's certificate) to agree on a fresh symmetric session key, then switch to a symmetric
AEAD cipher like AES-GCM for the actual page data. Neither algorithm family alone does the
whole job well: symmetric alone cannot solve "how do two strangers agree on a key," and
asymmetric alone is too slow to encrypt a multi-megabyte response.
Trade-offs & pitfalls
- Almost no production system uses pure asymmetric encryption for bulk data; if you see it
proposed, that is usually a design smell. - Symmetric key management (rotating and distributing shared secrets safely) is its own hard
problem and does not disappear just because the algorithm is fast; it is why systems like
KMS (key management service) and PKI (public key infrastructure) exist.
State recommended key length guidance for common algorithms: AES (symmetric), RSA (classical public-key), and elliptic curve algorithms (ECDSA/ECDH). Explain why key length matters and what operational considerations (performance, lifespan, algorithm migration) influence your choice of length.
Sample Answer
Direct answer
Roughly: AES-128 or AES-256 for symmetric keys, at least RSA-2048 with RSA-3072 preferred for
longer-lived data, and a 256-bit elliptic curve (like P-256) for ECDSA/ECDH. These are not
interchangeable "bit strengths": because the underlying hard problems differ, RSA needs a
much larger key than AES or ECC to reach the same practical security level.
Structured elaboration
Key length matters because it determines how expensive the best known attack is. For a
symmetric cipher, the best general attack is brute force over the key space, so security
scales directly and exponentially with key bits. RSA's security instead rests on integer
factorization, which has sub-exponential algorithms (the General Number Field Sieve), so RSA
needs a much larger key to match a given symmetric strength. Elliptic-curve cryptography
relies on the discrete logarithm problem over an elliptic curve, which has no known
sub-exponential attack, so it reaches strong security with much smaller keys than RSA.
Roughly matched security levels (NIST SP 800-57 style guidance):
| Symmetric-equivalent strength | AES | RSA | ECC (ECDSA/ECDH) |
|---|---|---|---|
| ~128-bit | AES-128 | RSA-3072 | P-256 |
| ~192-bit | AES-192 | RSA-7680 | P-384 |
| ~256-bit | AES-256 | RSA-15360 | P-521 |
Operational considerations that influence the choice:
- Performance: RSA key generation and private-key operations get noticeably slower as key
size grows; ECC stays comparatively cheap even at higher security levels, which is why TLS
handshakes favor ECDHE over large-RSA key exchange today. - Lifespan: a key protecting data that must stay confidential for decades (a root CA, an
archival encryption key) should sit at a higher security margin than a short-lived TLS
session key, since attacker capability only improves over time. - Algorithm migration headroom: teams often deliberately keep some headroom above the
current minimum recommendation, so that a future algorithm migration (moving to a larger
key size, or off an algorithm entirely) can happen on a planned schedule rather than as an
emergency re-key after a break is announced.
Worked example
A document-signing service needs signatures that remain verifiable for 20-year regulatory
retention. A TLS session key, by contrast, only needs to resist attack for the minutes the
connection is open. Both could technically use "128-bit class" security today, but the
signing service deliberately picks RSA-3072 over RSA-2048 (or a 384-bit curve over a 256-bit
one) precisely because of the lifespan consideration: a 20-year window gives attacker capability
two decades to improve, so the team spends a bit more compute per signature now to buy margin
that a short-lived session key does not need.
Trade-offs & pitfalls
- RSA-2048 is still widely deployed and considered acceptable for most near-term use, but
guidance is trending toward RSA-3072 for anything expected to remain secure for many years;
treat any bare "RSA-2048 is fine forever" claim with suspicion. - Bumping AES from 128 to 256 bits has essentially no practical performance cost on modern
hardware (AES-NI accelerates both equally), so the "just use AES-256 to be safe" instinct is
cheap here in a way it is not for RSA.
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.
Unlock Full Question Bank
Get access to all 17 Cryptography Fundamentals interview questions and detailed answers.
Sign in to ContinueJoin thousands of developers preparing for their dream job.