Lesson 2 of 4 Cryptanalytic and Credential Attacks

Implementation and Side-Channel Attacks

Many real cryptographic failures come from how cryptography is built and run, not from weak algorithms. This lesson covers implementation flaws, side channels, timing attacks and fault injection.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain implementation, side-channel, timing and fault injection attacks.
  • Identify countermeasures for each.

Implementation attacks

Implementation attacks exploit flaws in the code or configuration around an algorithm: predictable random number generators, reused nonces, keys left in memory or logs, missing certificate validation, downgrade negotiation, padding oracles and memory-safety bugs in cryptographic libraries. Defences include using mature, well-reviewed libraries rather than custom code, FIPS 140-3 validated modules where required, secure configuration, code review and prompt patching.

Nonce reuse illustrates how a small implementation mistake can destroy a strong algorithm. In a stream cipher or a counter-based mode such as CTR or GCM, the key and nonce together produce a keystream that is combined with the plaintext. If two messages are encrypted with the same key and nonce, combining the two ciphertexts cancels the keystream and leaves the combination of the two plaintexts, which can often be separated using known structure. With GCM, nonce reuse also allows the attacker to forge authenticated messages. The algorithm is unbroken; the failure is entirely in how it was used.

Weak random number generation is another classic failure. If a device generates keys from a predictable seed, such as the time of start-up, an attacker can reproduce the generation and obtain the same keys. Embedded devices that generate keys immediately after their first boot, before they have gathered enough randomness, have been found to share keys or key factors with thousands of other devices. Cryptographically secure random number generators, seeded from hardware sources of randomness, prevent this.

Downgrade attacks exploit negotiation. When a client and server support several protocol versions or cipher suites, an attacker in the middle may interfere with the negotiation so that both sides fall back to the weakest option they share, which the attacker can break. The defence is to disable obsolete versions and suites entirely and to use protocols, such as TLS 1.3, that protect the negotiation itself from tampering.

Match the pairs

Implementation failures

Exam skills 3.7.6

Match each implementation flaw with its consequence.

Log in to try this activity Interactive activities are free with an account.

Side channels, timing and faults

Side-channel attacks extract secrets from physical effects of computation. Power analysis (simple and differential) measures a device's power consumption while it uses a key; electromagnetic analysis measures emanations; acoustic and cache-based attacks observe sound or processor cache behaviour. Countermeasures include shielding (TEMPEST standards), power filtering, masking and constant-power implementations.

Timing attacks measure how long operations take. If a comparison stops at the first incorrect byte, response times reveal how many bytes were correct; enough measurements can recover a secret, even over a network. Constant-time implementations defend against this. Fault injection deliberately induces errors through voltage or clock glitches, lasers or temperature extremes, causing faulty outputs that reveal keys or skipping security checks such as signature verification during boot. Defences include sensors that detect abnormal conditions, redundant computation and checking results before releasing them.

Side-channel attacks matter most for devices that an attacker can hold or get close to, such as smart cards, hardware tokens, payment terminals and IoT devices, and for shared computing environments where an attacker's code runs on the same physical processor as the victim's, as in cache timing attacks between virtual machines. This is one reason why highly sensitive workloads are sometimes placed on dedicated hardware rather than shared hosts, and why HSMs and smart cards are evaluated for side-channel resistance.

The following diagram compares brute force with a timing attack on an early-exit comparison.

Why an early-exit comparison leaks a secret code. A guess with a correct first character takes slightly longer to reject, so the attacker finds each position in turn: for an eight-character code of letters and digits, at most 62 values per position, about 496 guesses, instead of 62 to the power 8. A constant-time comparison removes the signal.
The band lengths are not to scale.
Sort into groups

Which physical attack?

Exam skills 3.7.7 · 3.7.8 · 3.7.9

Classify each attack by the physical effect it exploits or induces.

Log in to try this activity Interactive activities are free with an account.
Worked example

A timing attack on a code check

A device compares an entered eight-character code with the stored code one character at a time and rejects the input at the first mismatch. How can an attacker exploit this, and what is the defence?

A guess whose first character is correct takes slightly longer to reject than one whose first character is wrong. By trying each possible first character and measuring the responses many times, an attacker finds the correct first character, then the second, and so on. Instead of trying every combination of eight characters, the attacker tests the possible values one position at a time, at most 62 values per position for letters and digits, each measured repeatedly to average out noise.

A constant-time comparison always examines every character before answering, so the response time reveals nothing.

Worked example

A smart card attack

Researchers recover the PIN-protected key from a payment smart card by repeatedly measuring its power consumption during transactions. Which attack is this, and which defence addresses it?

Measuring power consumption to derive a key is a side-channel attack (power analysis). The defence is in the card's hardware and implementation: masking and constant-power operations that make consumption independent of the key, plus noise generation and tamper resistance. A longer PIN or a stronger algorithm would not help, because the attack observes the computation rather than guessing inputs.

Check yourself

Which coding technique defends against timing attacks?

Show answer

Constant-time implementations, so execution time does not depend on secret data.

Exam Tips

Remember for the exam

  • Most cryptographic failures are implementation failures.
  • Use constant-time code to defeat timing attacks.
  • Side-channel and fault attacks usually need physical access.