A decision one glitch cannot flip
Turn a check into a result that a skipped instruction or a zeroed register cannot make into success. A medium embedded C problem (Side channels and…
medium · Side channels and glitches · security · glitching · fault-injection
A glitch makes the chip skip one instruction or read one wrong value. A check that returns 1 or 0 and is tested once falls to a single well-timed fault.
Write pin_decision(guess, pin, n). It returns GRANTED (0x3CA5) when the n bytes match and DENIED (0xC35A) otherwise, and it must hold up against faults the tests simulate:
- The result starts as
DENIEDand only becomesGRANTEDafter the comparison. - The comparison is constant time (every byte, OR of XORs).
- It counts each byte it compared in the global
steps(written for you); if the count is notnat the end, something was skipped: returnFAULT(0xDEAD). - It compares a second time, independently, and returns
FAULTif the two comparisons disagree.
The test's glitch_at makes the support's read_byte() return 0 for the byte at that position in one comparison only (as a glitch corrupting one load would): a correct guess must then come out as FAULT, never GRANTED, and a wrong one never as GRANTED.
Starter code
unsigned pin_decision(const uint8_t *guess, const uint8_t *pin, unsigned n) {
for (unsigned i = 0; i < n; i++) {
if (read_byte(guess, i) != pin[i]) return DENIED;
}
return GRANTED;
}Example tests
No glitch
const uint8_t pin[4] = { 4, 7, 1, 1 }, right[4] = { 4, 7, 1, 1 }, wrong[4] = { 4, 7, 1, 2 };
try_pin(right, pin, -1);
try_pin(wrong, pin, -1);Expected output:
granted
deniedA glitch during the right PIN is caught
const uint8_t pin[4] = { 4, 7, 1, 1 }, right[4] = { 4, 7, 1, 1 };
try_pin(right, pin, 2);Expected output:
faultLearn it first
- Side channels and glitches · Timing and power side channels, constant-time code, glitching single decisions, and lockouts that hold.
More Side channels and glitches problems
- A constant-time compare · Combine every byte's difference without stopping early, so the time says nothing about the secret.