Unit 6: Cryptographic Protocols - Subjective Questions
MTH381 — Number Theory And Cryptography • Practice Questions with Detailed Answers
20 questions
Define a cryptographic hash function and explain its role in ensuring data integrity.
A cryptographic hash function is a function that takes an input (message) of arbitrary length and produces a fixed-size output , called the hash value, message digest, or fingerprint.
Key characteristics:
- Deterministic: The same input always produces the same output.
- Fixed output length: Regardless of input size, output is fixed (e.g., 256 bits for SHA-256).
- Efficient: Fast to compute for any given .
- One-way: Computationally infeasible to reverse.
Role in data integrity:
- When data is transmitted or stored, its hash value is computed and kept.
- Later, the hash is recomputed and compared with the stored value.
- If the values match, the data is unaltered; if they differ, the data has been modified (accidentally or maliciously).
For example, software downloads often publish a SHA-256 digest so users can verify the file has not been tampered with. Thus hash functions act as a compact, verifiable summary that detects any change in the underlying data.
Explain the three main security properties required of a cryptographic hash function.
A secure cryptographic hash function must satisfy the following three properties:
-
Preimage Resistance (One-wayness):
- Given a hash value , it should be computationally infeasible to find any message such that .
- Protects against reversing the digest to recover the input.
-
Second Preimage Resistance (Weak Collision Resistance):
- Given an input , it should be infeasible to find a different input such that .
- Prevents substituting a message while keeping the same digest.
-
Collision Resistance (Strong Collision Resistance):
- It should be infeasible to find any two distinct inputs with .
- Stronger than second preimage resistance since the attacker is free to choose both messages.
Relationship: Collision resistance implies second preimage resistance, but not vice versa. For an -bit hash, a brute-force preimage attack takes about operations, while a collision can be found in about operations due to the birthday paradox.
Describe the birthday attack on hash functions and explain how it affects the choice of hash output length.
The birthday attack is a generic attack that exploits the birthday paradox to find collisions in a hash function faster than brute force.
Birthday paradox intuition:
- In a group of just 23 people, there is a greater than 50% chance that two share a birthday, even though there are 365 possible days.
- This is because the number of pairs grows quadratically.
Applied to hash functions:
- For a hash function with an -bit output, there are possible digests.
- To find a collision by brute force (fixing one message) requires about tries.
- Using the birthday attack, only about randomly chosen messages are needed to find some collision with high probability.
Mathematical estimate: The probability of at least one collision among messages is approximately:
Setting gives .
Impact on output length:
- Because collision search costs only , the output must be twice as long as the desired security level.
- To achieve 128-bit collision security, a hash must produce at least a 256-bit output (e.g., SHA-256).
- This is why modern standards moved away from 128-bit MD5 and 160-bit SHA-1 toward SHA-256 and beyond.
Distinguish between preimage resistance and collision resistance with examples.
Both are security properties of hash functions but differ in the attacker's freedom and difficulty.
| Aspect | Preimage Resistance | Collision Resistance |
|---|---|---|
| Definition | Given , hard to find with | Hard to find any with |
| Attacker input | A target hash value is fixed | Attacker freely chooses both messages |
| Brute-force cost | (birthday) | |
| Difficulty | Harder to break | Easier to break |
Example of preimage resistance:
- A password system stores . An attacker who steals the digest cannot easily recover the original password.
Example of collision resistance:
- In digital signatures, if an attacker could find two documents (benign) and (malicious) with the same hash, they could get a signature on and reuse it on . Collision resistance prevents this.
Summary: Preimage resistance protects a specific target, while collision resistance protects against any matching pair, making it a stronger and more critical requirement for signatures.
Explain the general structure of the Merkle–Damgård construction used in building hash functions.
The Merkle–Damgård construction is a method to build a collision-resistant hash function that accepts arbitrary-length input from a fixed-size compression function .
Steps:
-
Padding: The message is padded so its length is a multiple of the block size. The padding usually encodes the original message length (length padding / Merkle–Damgård strengthening).
-
Splitting: The padded message is divided into blocks .
-
Initialization: A fixed initialization vector is set as the initial chaining value: .
-
Iteration: Each block is processed with the compression function:
-
Output: The final chaining value (optionally passed through a finalization function) is the hash digest.
Key property:
- Merkle–Damgård theorem: If the compression function is collision resistant, then the overall hash function is also collision resistant.
Usage: MD5, SHA-1, and SHA-2 are based on this construction. A known weakness is the length-extension attack, which newer designs (e.g., SHA-3's sponge construction) avoid.
What is a Message Authentication Code (MAC)? Explain how it provides both integrity and authenticity.
A Message Authentication Code (MAC) is a short piece of information (a tag) generated from a message and a secret key, used to verify both the integrity and the authenticity of the message.
Formal description:
- Generation: where is a shared secret key and is the message.
- Verification: The receiver recomputes and checks whether .
How it provides security:
- Integrity: Any change to (or ) causes the recomputed tag to differ, revealing tampering.
- Authenticity: Since the key is shared only between sender and receiver, only a party holding could have generated a valid tag. This proves the message came from a legitimate holder of the key.
Key points:
- MACs use symmetric (shared) keys, unlike digital signatures which use asymmetric keys.
- A MAC cannot provide non-repudiation because both parties know the same key — either could have produced the tag.
- Common constructions: HMAC (hash-based) and CMAC (cipher-based).
Describe the HMAC construction and explain why a simple keyed hash is insecure.
HMAC (Hash-based Message Authentication Code) is a widely used MAC construction that securely combines a cryptographic hash function with a secret key.
HMAC definition:
where:
- is the key padded (or hashed then padded) to the hash block size.
- = inner pad (byte
0x36repeated). - = outer pad (byte
0x5crepeated). - denotes concatenation, denotes XOR.
Why the naive is insecure:
- For hash functions built with the Merkle–Damgård construction (MD5, SHA-1, SHA-256), is vulnerable to a length-extension attack.
- An attacker who knows and the length of can compute for an appended message without knowing the key .
- This lets the attacker forge a valid tag for an extended message.
Why HMAC is safe:
- The nested (double) hashing with two different key-derived pads prevents the length-extension attack.
- HMAC's security has been formally proven under the assumption that the underlying compression function behaves like a pseudorandom function.
Compare Message Authentication Codes (MACs) and Digital Signatures.
Both MACs and digital signatures authenticate messages and ensure integrity, but they differ fundamentally in their key model and properties.
| Feature | MAC | Digital Signature |
|---|---|---|
| Key type | Symmetric (shared secret key) | Asymmetric (private/public key pair) |
| Who can generate | Anyone holding the shared key | Only the holder of the private key |
| Who can verify | Anyone holding the shared key | Anyone using the public key |
| Integrity | Yes | Yes |
| Authenticity | Yes | Yes |
| Non-repudiation | No | Yes |
| Computation cost | Fast (hash/cipher based) | Slower (public-key operations) |
| Examples | HMAC, CMAC | RSA, DSA, ECDSA |
Key distinctions:
- Non-repudiation: A digital signature binds the message to a unique private key, so the signer cannot later deny signing. A MAC uses a shared key, so either party could have created the tag — no non-repudiation.
- Scalability: MACs require a shared key between each pair of communicating parties; signatures rely on published public keys, easing key management across many parties.
- Performance: MACs are far faster, so they are preferred for high-volume symmetric-key communication, while signatures suit open, multi-party settings.
Explain the working of a digital signature scheme including the roles of signing and verification.
A digital signature is a cryptographic mechanism that lets a signer bind their identity to a message using a private key, allowing anyone with the corresponding public key to verify authenticity.
Components of a signature scheme:
- Key Generation: Produces a key pair — a public key and a private (secret) key .
- Signing algorithm: .
- Verification algorithm: .
Typical process (hash-then-sign):
- The signer computes the hash of the message: .
- The signer encrypts/transforms the hash with their private key to produce the signature .
- The signer sends to the receiver.
- The verifier computes from the received message.
- The verifier uses the public key on to recover/compare the hash and checks .
- If they match, the signature is valid.
Security services provided:
- Authentication: Confirms the message came from the holder of .
- Integrity: Any change to invalidates the signature.
- Non-repudiation: The signer cannot deny having signed, since only they possess .
Why hash first? Signing the fixed-size hash instead of the whole message improves efficiency and, with a collision-resistant hash, preserves security.
Explain the RSA digital signature scheme with its mathematical steps.
The RSA signature scheme uses the RSA trapdoor function in reverse: signing with the private key and verifying with the public key.
Key Generation:
- Choose two large primes and ; compute .
- Compute Euler's totient: .
- Choose public exponent with .
- Compute private exponent such that .
- Public key: ; Private key: .
Signing (using hash-then-sign):
- Compute the message digest .
- Compute the signature:
- Send .
Verification:
- Compute from the received message.
- Recover the hash from the signature:
- Accept the signature if .
Correctness: Since (because ), verification succeeds for genuine signatures.
Security basis: Relies on the difficulty of factoring and computing without the primes. In practice, padding schemes such as RSA-PSS are used to prevent forgery attacks on textbook RSA.
List and explain the essential security requirements for a digital signature scheme.
A secure digital signature scheme must satisfy several requirements to be trustworthy:
-
Authenticity:
- The signature must verifiably prove that the message originated from the claimed signer.
-
Integrity:
- Any alteration of the signed message must invalidate the signature, ensuring the message has not been changed.
-
Non-repudiation:
- The signer must not be able to deny having signed the message later, since only they hold the private key.
-
Unforgeability:
- It must be computationally infeasible for an attacker to create a valid signature for any message without the private key. The strongest notion is Existential Unforgeability under Chosen Message Attack (EUF-CMA).
-
Non-reusability:
- A signature must be tied to a specific message and cannot be detached and reattached to a different message.
-
Signer authentication / key binding:
- The public key must be reliably bound to the signer's identity (usually via a certificate from a trusted CA).
These requirements ensure the scheme resists impersonation, tampering, and repudiation, forming the foundation of trust in electronic transactions.
Define the EUF-CMA security notion for signature schemes and explain the attacker model.
EUF-CMA stands for Existential Unforgeability under Chosen Message Attack, the standard security definition for digital signature schemes.
The security game:
- The challenger generates a key pair and gives the public key to the adversary.
- The adversary may adaptively request signatures on messages of its choice (the chosen message attack / signing oracle access).
- The adversary outputs a message-signature pair .
Winning condition:
- The adversary wins if and was never queried to the signing oracle.
Security definition:
- A scheme is EUF-CMA secure if for every efficient (probabilistic polynomial-time) adversary, the probability of winning this game is negligible.
Interpretation:
- Existential forgery means the attacker only needs to forge a signature on some message (not a chosen meaningful one).
- Chosen message attack gives the attacker strong power — access to legitimate signatures on messages of its choosing.
- Because this model grants the attacker great freedom yet still demands security, a scheme meeting EUF-CMA is considered robust for real-world use.
Explain what a length-extension attack is and which hash constructions are vulnerable.
A length-extension attack exploits the internal structure of certain hash functions to append data to a message and compute a valid hash without knowing the original message.
How it works:
- For a Merkle–Damgård hash, the final output equals the internal chaining state after processing all blocks.
- Given and the length of (but not itself), an attacker can:
- Treat as the intermediate chaining state.
- Continue the hashing process with additional data .
- Produce a valid .
Why it matters:
- If a MAC is naively built as , an attacker can forge tags for extended messages, breaking authentication.
Vulnerable constructions:
- MD5, SHA-1, SHA-256, SHA-512 — all based on the Merkle–Damgård construction.
Resistant constructions:
- SHA-3 (Keccak) — uses the sponge construction, which does not expose the full internal state.
- HMAC — its nested structure defeats the attack.
- SHA-512/256 and truncated variants also resist it because the full state is not revealed.
Mitigation: Use HMAC for keyed hashing, or use hash functions/modes designed to resist length extension.
Describe how hash functions are used in password storage and why plain hashing is insufficient.
Hash functions are used to store passwords securely so that the plaintext password is never kept on the server.
Basic approach:
- Instead of storing the password , the system stores .
- At login, the entered password is hashed and compared to the stored digest.
- Due to preimage resistance, an attacker who steals the database cannot easily recover the original passwords.
Why plain hashing is insufficient:
- Precomputed / Rainbow table attacks: Attackers precompute hashes of common passwords. If two users share a password, they get identical hashes.
- Fast hashing: General-purpose hashes (SHA-256) are fast, enabling billions of guesses per second in brute-force/dictionary attacks.
Recommended defenses:
- Salting: Add a unique random salt to each password before hashing: . This defeats rainbow tables and ensures identical passwords have different stored digests.
- Slow / memory-hard functions: Use dedicated password hashing functions like bcrypt, scrypt, Argon2, or PBKDF2 which are deliberately slow and resource-intensive, drastically increasing attack cost.
- Pepper: An additional secret value stored separately from the database can add another layer.
Conclusion: Secure password storage combines a salt, optionally a pepper, and a slow adaptive hashing algorithm rather than a plain fast cryptographic hash.
Explain the concept of non-repudiation and how digital signatures achieve it while MACs cannot.
Non-repudiation is the security property that prevents a party from denying the authenticity of their actions, such as sending or signing a message.
How digital signatures provide non-repudiation:
- Signatures use an asymmetric key pair .
- Only the signer possesses the private key used to create the signature.
- Anyone can verify the signature with the public key .
- Since only the signer could have produced a valid signature, they cannot credibly deny having created it — providing legally meaningful proof of origin.
Why MACs cannot provide non-repudiation:
- MACs use a shared symmetric key known to both the sender and receiver.
- Because both parties hold the same key, either could have generated a valid tag.
- If a dispute arises, a receiver could have forged the MAC just as easily as the sender, so the tag proves nothing about which party created it.
Summary:
- Signatures: private key is unique to the signer → non-repudiation achieved.
- MACs: key is shared → only integrity and authenticity between trusting parties, no non-repudiation.
This distinction is why digital signatures are required for contracts, legal documents, and financial transactions where accountability matters.
Distinguish between unconditional (information-theoretic) and computational security in the context of MACs and hash functions.
Security of cryptographic primitives can be evaluated under two different models:
1. Unconditional (Information-Theoretic) Security:
- Security holds even against an adversary with unlimited computing power.
- Based on probability theory, not on the hardness of computational problems.
- Example: A one-time MAC based on universal hashing (e.g., using pairwise independent functions) can be provably secure for a single message.
- Limitation: Usually requires keys as long as the message and cannot be reused, making it impractical for many messages.
2. Computational Security:
- Security holds only against adversaries with bounded (polynomial-time) resources.
- Based on assumptions that certain problems are computationally infeasible (e.g., finding hash collisions, factoring large integers).
- Example: HMAC is computationally secure assuming the compression function is a pseudorandom function.
- Advantage: Practical — short reusable keys, efficient operations.
Comparison:
| Aspect | Unconditional | Computational |
|---|---|---|
| Adversary power | Unlimited | Polynomial-time |
| Basis | Probability | Hardness assumptions |
| Key reuse | Limited (often one-time) | Reusable |
| Practicality | Low | High |
Conclusion: Real-world hash functions and MACs (SHA-256, HMAC) rely on computational security, since information-theoretic security is impractical for general use.
Describe the DSA (Digital Signature Algorithm) and its signing and verification steps.
The Digital Signature Algorithm (DSA) is a federal standard (FIPS 186) based on the difficulty of the discrete logarithm problem.
Domain parameters:
- : a large prime.
- : a prime divisor of .
- : a generator of order modulo , i.e., .
Key generation:
- Private key: random with .
- Public key: .
Signing message (with hash ):
- Choose a random per-message secret , with .
- Compute .
- Compute .
- The signature is the pair . (If or , choose a new .)
Verification of on :
- Compute .
- Compute and .
- Compute .
- Accept the signature if .
Important note: The random value must be unique and secret for each signature. Reusing or leaking allows recovery of the private key . This is why deterministic nonce generation (RFC 6979) is often used.
Explain why the hash-then-sign paradigm is used in digital signatures and what security property of the hash is critical.
The hash-then-sign paradigm means that a signer first computes the hash of the message and then applies the signing operation to rather than to the full message .
Reasons for hash-then-sign:
-
Efficiency: Public-key signing operations are slow. Signing a short fixed-size digest (e.g., 256 bits) is far faster than signing a large message.
-
Handling arbitrary message lengths: Signature algorithms like RSA operate on inputs bounded by the modulus size. Hashing maps any length message to a fixed short value that fits.
-
Security structure: It cleanly separates the compression (hash) from the signing (public-key) operation.
Critical hash property — Collision Resistance:
- If the hash function is not collision resistant, an attacker could find two messages with .
- The attacker could then get a legitimate signature on and present it as a valid signature on , since both share the same digest.
- This would break the scheme's unforgeability.
Therefore: Collision resistance is the essential property. This is also why the collision attacks on MD5 and SHA-1 forced their retirement from signature use, in favor of SHA-256 and stronger hashes.
Compare CBC-MAC and HMAC as message authentication techniques.
Both CBC-MAC and HMAC are widely used MAC constructions but are built on different primitives.
CBC-MAC (Cipher Block Chaining MAC):
- Built from a block cipher (e.g., AES) operating in CBC mode.
- The message is split into blocks; each block is XORed with the previous ciphertext output and encrypted.
- The final ciphertext block becomes the MAC tag.
- , tag .
HMAC (Hash-based MAC):
- Built from a cryptographic hash function (e.g., SHA-256).
- Uses nested hashing with inner and outer key pads:
Comparison:
| Aspect | CBC-MAC | HMAC |
|---|---|---|
| Underlying primitive | Block cipher | Hash function |
| Security caveat | Insecure for variable-length messages unless fixed (e.g., CMAC/EMAC) | Secure for arbitrary-length messages |
| Performance | Efficient with hardware AES | Efficient with fast hashes |
| Standardization | CMAC (NIST) is the fixed variant | RFC 2104, FIPS 198 |
Key points:
- Plain CBC-MAC is insecure for variable-length messages — an attacker can forge tags by concatenating messages. This is fixed in CMAC by using derived subkeys on the last block.
- HMAC is provably secure and naturally handles arbitrary lengths, making it the more common general-purpose choice.
Conclusion: Choose CMAC when a block cipher is already available (e.g., in constrained/hardware environments), and HMAC when a strong hash function is preferred and variable-length security is needed out of the box.
Explain the avalanche effect in hash functions and why it is important for data integrity.
The avalanche effect is a desirable property of cryptographic hash functions (and block ciphers) whereby a small change in the input produces a drastic, unpredictable change in the output.
Definition:
- Ideally, flipping a single input bit should flip each output bit with probability .
- On average, about half of the output bits change for any single-bit input change.
Example:
- Consider hashing two nearly identical strings:
H("hello")andH("hellp")
- Even though the inputs differ by one letter, their digests will look completely unrelated, with roughly 50% of bits differing.
Why it matters for data integrity:
-
Tamper detection: Any minor modification of the data — even a single bit flip — produces a completely different hash, making tampering easy to detect.
-
Unpredictability: An attacker cannot make controlled small changes to the output by making small input changes, which helps resist manipulation.
-
Supports collision resistance: Strong diffusion makes it hard to engineer two inputs that map to the same output.
Conclusion: The avalanche effect ensures that hash outputs are highly sensitive to input changes, which is fundamental to using hashes as reliable integrity fingerprints.
Define a cryptographic hash function and explain its role in ensuring data integrity.
A cryptographic hash function is a function that takes an input (message) of arbitrary length and produces a fixed-size output , called the hash value, message digest, or fingerprint.
Key characteristics:
- Deterministic: The same input always produces the same output.
- Fixed output length: Regardless of input size, output is fixed (e.g., 256 bits for SHA-256).
- Efficient: Fast to compute for any given .
- One-way: Computationally infeasible to reverse.
Role in data integrity:
- When data is transmitted or stored, its hash value is computed and kept.
- Later, the hash is recomputed and compared with the stored value.
- If the values match, the data is unaltered; if they differ, the data has been modified (accidentally or maliciously).
For example, software downloads often publish a SHA-256 digest so users can verify the file has not been tampered with. Thus hash functions act as a compact, verifiable summary that detects any change in the underlying data.
Did this save you a night before the exam?
LPU Notes is free, and it stays free. Ads cover part of the server bill. The rest comes out of a student's own pocket: the domain, the storage, and keeping the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason. to try again.
Nothing here is ever locked, and nothing unlocks. Chip in only if it was worth it. What it pays for →