mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-01 03:22:48 -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.
This commit is contained in:
@ -307,7 +307,7 @@ static int hmacsha256_verresult(void *handle, unsigned char const *hmac)
|
||||
{
|
||||
unsigned char correct[32];
|
||||
hmacsha256_genresult(handle, correct);
|
||||
return !memcmp(correct, hmac, 32);
|
||||
return smemeq(correct, hmac, 32);
|
||||
}
|
||||
|
||||
static int sha256_verify(void *handle, unsigned char *blk, int len,
|
||||
@ -315,7 +315,7 @@ static int sha256_verify(void *handle, unsigned char *blk, int len,
|
||||
{
|
||||
unsigned char correct[32];
|
||||
sha256_do_hmac(handle, blk, len, seq, correct);
|
||||
return !memcmp(correct, blk + len, 32);
|
||||
return smemeq(correct, blk + len, 32);
|
||||
}
|
||||
|
||||
const struct ssh_mac ssh_hmac_sha256 = {
|
||||
|
Reference in New Issue
Block a user