mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-14 17:47:33 -05:00
Use a timing-safe memory compare to verify MACs.
Now that we have modes in which the MAC verification happens before
any other crypto operation and hence will be the only thing seen by an
attacker, it seems like about time we got round to doing it in a
cautious way that tries to prevent the attacker from using our memcmp
as a timing oracle.
So, here's an smemeq() function which has the semantics of !memcmp but
attempts to run in time dependent only on the length parameter. All
the MAC implementations now use this in place of !memcmp to verify the
MAC on input data.
(cherry picked from commit 9d5a164021
)
Cherry-picker's notes: the above commit comment isn't really true on
this branch, since the ETM packet protocol changes haven't been
cherry-picked. But it seemed silly to deliberately leave out even a
small safety measure.
This commit is contained in:
12
misc.h
12
misc.h
@ -64,8 +64,20 @@ int validate_manual_hostkey(char *key);
|
||||
|
||||
struct tm ltime(void);
|
||||
|
||||
/* Wipe sensitive data out of memory that's about to be freed. Simpler
|
||||
* than memset because we don't need the fill char parameter; also
|
||||
* attempts (by fiddly use of volatile) to inhibit the compiler from
|
||||
* over-cleverly trying to optimise the memset away because it knows
|
||||
* the variable is going out of scope. */
|
||||
void smemclr(void *b, size_t len);
|
||||
|
||||
/* Compare two fixed-length chunks of memory for equality, without
|
||||
* data-dependent control flow (so an attacker with a very accurate
|
||||
* stopwatch can't try to guess where the first mismatching byte was).
|
||||
* Returns 0 for mismatch or 1 for equality (unlike memcmp), hinted at
|
||||
* by the 'eq' in the name. */
|
||||
int smemeq(const void *av, const void *bv, size_t len);
|
||||
|
||||
/*
|
||||
* Debugging functions.
|
||||
*
|
||||
|
Reference in New Issue
Block a user