Skip to main content
Be Bitwise

What Are Side Channels?

Side-Channel Attacks · Advanced Exploitation track

6 min read

In this module

Secrets Leak Through Physics

Imagine a locked safe with a combination dial. The obvious attack is to try every combination until the safe opens. But a skilled safecracker does not do this. Instead, they listen to the clicks, feel for subtle resistance in the dial, and use these physical clues to determine the combination. They never break the lock mechanism itself - they extract information from the physical side effects of the lock's operation.

Side-channel attacks work on the same principle. Rather than attacking a cryptographic algorithm mathematically, the attacker observes the physical and behavioural characteristics of the device running it. How long does the operation take? How much power does the chip draw? What electromagnetic signals does it emit? What data ends up in the CPU cache?

These observable properties leak information about the secret data being processed. The algorithm might be mathematically unbreakable. The physical device executing it, however, can't stop narrating what it's doing.

Categories of Side Channels

Side channels can be broadly categorised by what the attacker observes:

Timing: How long an operation takes. If a cryptographic operation takes different amounts of time depending on the secret key, measuring the execution time reveals information about the key.

Power consumption: How much electrical power the chip draws during computation. Different operations (multiplying by zero vs. multiplying by one) consume different amounts of power. By measuring power consumption over time, the attacker can determine what operations were performed and what data was processed.

Electromagnetic emanation: The electromagnetic radiation emitted by electrical circuits during operation. Like power consumption, EM emissions correlate with the data being processed and the operations being performed. The attacker measures these emissions with an antenna placed near the device.

Cache behaviour: Which memory addresses have been recently accessed, as revealed by cache timing differences. In a shared computing environment (multi-core CPUs, cloud servers), one process can observe another process's cache usage patterns.

Acoustic: The sounds produced by electronic components. Researchers have demonstrated extracting cryptographic keys from the acoustic emissions of capacitors on a laptop's motherboard during RSA decryption.

Fault behaviour: How the system responds when deliberately subjected to abnormal conditions (voltage glitches, clock manipulations, extreme temperatures). Faulty computations can reveal internal state.

Side Channel

A side channel is any unintended information pathway that leaks data about a system's internal operations through observable physical or behavioural properties. Side channels exist because computation is a physical process, and physical processes have measurable effects beyond their intended outputs.

Why Side Channels Matter

Side-channel attacks are fundamentally different from algorithmic attacks. AES-256 has no known practical mathematical attack. Nobody has proved it secure; it has simply survived decades of cryptanalysis. But even that track record says nothing about the physical implementation. If the hardware leaks the key through power consumption, mathematical security is irrelevant.

This is the gap that bites security engineers:

  • Algorithm designers focus on mathematical security: brute force, differential cryptanalysis, linear cryptanalysis.
  • Implementation engineers must also fight side channels: constant-time execution, power masking, randomised internal operations.

A secure algorithm running on a leaky implementation is insecure in practice. That's why cryptographic engineering is so much harder than cryptographic algorithm design — the hard part isn't the maths, it's the physics.

A Simple Timing Attack Example

Consider a password verification function that compares a user-provided password against the stored hash, byte by byte:

c
bool verify_password(const char *provided, const char *stored, int len) {
for (int i = 0; i < len; i++) {
if (provided[i] != stored[i]) {
return false; // Stop at first mismatch
}
}
return true;
}

This function takes longer when more leading bytes match. If the password is 8 bytes:

  • Wrong first byte: ~1 comparison, very fast
  • Correct first byte, wrong second: ~2 comparisons, slightly slower
  • All bytes correct: ~8 comparisons, slowest

By trying all 256 possible values for the first byte and measuring which one produces the longest execution time, the attacker determines the first byte. They fix that byte and repeat for the second, and so on. Instead of 256^8 guesses (astronomical), the attacker needs at most 256 * 8 = 2048 guesses to recover the entire password.

Research has demonstrated that timing differences of a few nanoseconds can be reliably extracted over a network with enough repetitions and statistical analysis.

The Constant-Time Discipline

The primary defence against timing side channels is constant-time programming: writing code that takes exactly the same amount of time regardless of the secret data it processes.

This is harder than it sounds. The programmer must avoid:

  • Data-dependent branches: if (secret_bit == 1) { do_something(); } takes different time depending on the bit
  • Data-dependent memory access: Accessing different array indices based on secret data causes different cache behaviour
  • Data-dependent operations: Some CPUs execute multiplication faster when one operand is small
  • Early exit: Returning early when a mismatch is found (as in the password example above)

Constant-time code uses bitwise operations and arithmetic to avoid branches:

c
/* Constant-time comparison */
bool verify_password_safe(const char *provided, const char *stored, int len) {
unsigned char result = 0;
for (int i = 0; i < len; i++) {
result |= provided[i] ^ stored[i];
}
return result == 0;
}

This always processes all bytes, always performs the same operations, and reveals nothing about where the first mismatch occurred. One caveat: an optimising compiler is free to spot that result can't go back to 0 once it's non-zero and add an early exit of its own, so production code uses a vetted routine such as OpenSSL's CRYPTO_memcmp or the BSDs' timingsafe_bcmp.

Measure it yourself. The runner times both functions against a 64-byte secret for guesses that match none, half and all of it. Your numbers will differ from run to run on a shared machine, so look at the pattern rather than the values, and predict it before you run.

Try itPredict how each column grows as more of the guess matches, then shrink LEN to 8 and see how much harder the leak is to spot.
C (GCC 9.2.0)

The Scope of the Problem

Side-channel attacks are not theoretical curiosities. They have been used to:

  • Extract secret keys from smart cards and hardware security modules
  • Read kernel memory from user-space processes (Meltdown)
  • Leak data across security boundaries in CPUs (Spectre)
  • Extract encryption keys from SSL/TLS servers over the network
  • Break the security of encrypted USB drives
  • Recover signing keys from cryptocurrency hardware wallets

The following lessons dig into specific techniques: cache-based attacks, speculative execution attacks, and physical side channels. Each exploits a different physical property, but they all trace back to the same fact: computation leaks information through channels the algorithm designer never imagined.