Fault Injection Guard Macros

Hard C Safety Asked at Siemens
Solve this problem

Safety-critical code must resist single-event upsets that skip a branch. Implement a redundant-check pattern where a security decision is verified twice with inverted logic before acting.

Constraints

  • `int authorize(uint32_t key)` must return 1 only when the key matches on both independent checks.
  • The two checks must use different comparisons, not a repeated identical test.
  • A mismatch between the two checks must call `fault_handler()` and never return 1.
  • No compiler-removable dead code: use volatile where needed.
  • No dynamic memory.
Starter codeC
1#include <stdint.h>2 3extern void fault_handler(void);4 5#define EXPECTED_KEY 0xA5A5A5A5u6 7int authorize(uint32_t key) {8    // TODO: redundant, glitch-resistant check9    return 0;10}