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 sources of randomness and entropy relevant to secure key generation in production systems. Compare hardware TRNGs, OS-provided CSPRNGs such as getrandom or /dev/urandom, and pitfalls of using non-cryptographic PRNGs or predictable seeding.
Sample Answer
Direct answer
Secure key generation needs randomness an attacker cannot predict or reproduce. Hardware true
random number generators (TRNGs) harvest genuine physical noise; operating-system CSPRNGs
(cryptographically secure pseudo-random number generators) mix that hardware entropy into a
pool and stretch it safely for applications to consume; ordinary, non-cryptographic PRNGs and
predictably-seeded generators are unsafe for key material because their output can be
predicted or reconstructed.
Structured elaboration
- Hardware TRNGs: derive bits directly from unpredictable physical phenomena, thermal
noise, electronic jitter, dedicated noise diodes on modern CPUs. These are a genuine entropy
source but are typically used to seed and periodically refresh a CSPRNG rather than being
read directly for every key, since a raw physical source can have subtle biases. - OS-provided CSPRNGs: the operating system maintains an entropy pool fed by hardware
sources plus unpredictable system events (interrupt timing, and similar), and exposes it
through an interface designed for cryptographic use, thegetrandom()system call on Linux,
or reading from/dev/urandom. Once the pool has been initialized (early in boot), these are
the correct, safe source for generating keys and nonces. - Pitfalls of non-cryptographic PRNGs: general-purpose generators like a language's
defaultrandom()(commonly a Mersenne Twister variant) are built for statistical spread in
simulations, not unpredictability against an adversary. Their internal state can often be
reconstructed from a modest number of observed outputs, after which every past and future
output becomes predictable, which is catastrophic if that generator ever produced a key or
nonce. - Pitfalls of predictable seeding: seeding any generator, including a good one, from a
low-entropy value like the current time in seconds collapses the effective search space to
the number of plausible seed values (how many seconds an attacker has to guess), letting
them brute-force the seed itself rather than the full key space, no matter how strong the
algorithm downstream looks.
Worked example, grounded in real incidents
The 2008 Debian OpenSSL bug (CVE-2008-0166) is the canonical case: a change intended to quiet
a memory-analysis warning accidentally removed most of the entropy sources feeding the
package's key generation, leaving only the process ID as effective variation. On Linux, that
reduced the practical keyspace for every SSH and TLS key generated on affected systems during
that window to roughly 32,768 possibilities, small enough to enumerate directly rather than
attack cryptographically. Separately, Sony's PlayStation 3 signing system reused the same
fixed value for the "random" nonce in every ECDSA signature it produced instead of generating
a fresh one each time; because ECDSA's security depends on that nonce never repeating, two
signed messages were enough for researchers to recover Sony's private signing key entirely.
Trade-offs & pitfalls
- The failure in both real incidents above was never a broken algorithm; OpenSSL and ECDSA
are both sound. The break was entirely in how randomness was sourced and used, which is
precisely why the sub-area matters even though it can feel like the "boring" part of a
cryptography question. - Do not reach for
Math.random(),random.random(), or similar in any language when
generating a key, nonce, or salt; use the CSPRNG interface your platform provides for
cryptography specifically.
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.
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.
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.
Give a high-level walkthrough of a TLS handshake: what happens at each step, which cryptographic primitives are used where (certificates, asymmetric key exchange, symmetric session keys, MAC/AEAD), and what properties TLS is actually trying to guarantee. What's one common way this can fail in practice?
Sample Answer
Direct answer
A TLS (Transport Layer Security) handshake lets a client and server who have never met agree
on a shared symmetric key, authenticate the server (and optionally the client), and start
exchanging data, with confidentiality, integrity, and (with modern configuration) forward
secrecy. It works by combining asymmetric key exchange and certificate-based identity checks
up front, then switching to fast symmetric encryption for the actual traffic.
Structured elaboration
sequenceDiagram
participant C as Client
participant S as Server
C->>S: ClientHello (supported versions, cipher suites, key share, random)
S->>C: ServerHello (chosen cipher suite, key share, random)
S->>C: Certificate (server public key, signed by a CA)
S->>C: Finished (proves possession of the certificate's private key)
Note over C,S: Both derive the same shared secret via ECDHE, then a session key via a KDF
C->>S: Finished (handshake integrity check)
C->>S: Application data (encrypted with the negotiated AEAD cipher)
S->>C: Application data (encrypted with the negotiated AEAD cipher)
- ClientHello / ServerHello: negotiate protocol version, cipher suite, and exchange
ephemeral key-exchange material (an elliptic-curve public value for ECDHE) plus random
nonces that feed the key derivation. - Certificate: the server presents its certificate, a public key bound to an identity and
signed by a certificate authority (CA), so the client can authenticate who it is actually
talking to (see PKI/certificate chains for how that trust is validated). - Key derivation: both sides combine the ECDHE exchange output through a KDF (key
derivation function) to produce the actual symmetric session keys, never sending the
session key itself over the wire. - Application data: all subsequent traffic is encrypted and authenticated with an AEAD
cipher (typically AES-GCM or ChaCha20-Poly1305) under the derived session key; older TLS
versions could instead pair a plain block cipher with a separate MAC (message
authentication code) computed over each record, a split that AEAD replaces with one
combined operation. - Properties TLS is guaranteeing: confidentiality (only the endpoints can read the data),
integrity/authenticity (tampering is detected), server authentication (the certificate
chain proves identity), and, with an ephemeral key-exchange suite, forward secrecy.
Worked example / common failure
The most common real-world failure is not a cryptographic break, it is trust management:
an expired certificate. Everything about the handshake's math can be flawless and the
connection will still be rejected (or a warning shown) the moment the leaf certificate's
validity window has passed, because clients check expiration as part of chain validation
before they will trust the negotiated key exchange at all. This is a frequent cause of
sudden, otherwise-unexplained outages, and is why certificate expiry monitoring is treated as
an operational, not just a security, concern.
Trade-offs & pitfalls
- TLS 1.3 (RFC 8446) simplified this flow and removed insecure options entirely (no more
static-RSA key exchange, no more weak cipher suites), which is why upgrading from TLS 1.2
is itself a meaningful security improvement, not just a version bump. - A valid, unexpired certificate chain proves identity, it does not by itself prove the
identity is trustworthy; certificate validation and business-level trust are separate
concerns.
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.