Compute the key for a seed
Implement a shift-and-XOR seed and key algorithm of the kind ECUs use for SecurityAccess. An easy embedded C problem (UDS: security access, routines and…
easy · UDS: security access, routines and reset · uds · security · automotive · bits · shifts
SecurityAccess is a challenge and response: the ECU sends a seed, and the tester must answer with the key that a secret algorithm makes from it. The ECU runs the same algorithm to check the answer.
Implement this ECU's algorithm, key_for(seed), on 32-bit values:
- Start with
key = seed. - Repeat 35 times: if the top bit of
keyis set, shiftkeyleft by one and XOR it with the constant 0x5F3A9C17; otherwise only shift it left by one. - The result is the key.
Everything stays in 32 bits: bits shifted out of the top are lost.
Starter code
uint32_t key_for(uint32_t seed) {
uint32_t key = seed;
for (int i = 0; i < 35; i++) {
key = (key << 1) ^ 0x5F3A9C17u;
}
return key;
}Example tests
Two seeds
show(0x00000001);
show(0x12345678);Expected output:
seed 00000001 -> key 47A1D896
seed 12345678 -> key 1AFC069ELearn it first
- UDS: security access, routines and reset · Seed and key, attempt counters and delays, RoutineControl, ECUReset, and what real security needs.
More UDS: security access, routines and reset problems
- Security access with a lockout · The server side of SecurityAccess: one key a seed, three attempts, then a delay.