3 ms·
Even with HMAC you have to be careful! A contrived example: HMAC(secret, username || email) Imagine you have `bob` and `bob@example.com` as inputs. This H
by stouset 3y ago
Even with HMAC you have to be careful! A contrived example:
HMAC(secret, username || email)
Imagine you have `bob` and `bob@example.com` as inputs. This HMAC can trivially be reused (or learned) by registering `bobb` and `ob@example.com`.
If you ever have multiple fields being concatenated, use fixed-width length prefixes before each field:
HMAC(secret, 0x0003 || bytes("bob") || 0x000e || bytes("bob@example.com"))
- erhaetherth 3y agoDoes this really work? Any arbitrary fixed-length prefix? I always just serialize the inputs with JSON or something. Any weirdness an attacker might try would just be escaped so they'll never be able to match the original input.