ref: 4a47b264ac6c072cc180176f84297a93a38e4631
parent: a57a6e511f15c02b4fd2690197b6f1333b171193
author: cinap_lenrek <[email protected]>
date: Thu Jan 14 18:39:29 EST 2016
wifi: check tkip/ccmp mac and crc in constant time avoiding timing side channels
--- a/sys/src/9/pc/wifi.c
+++ b/sys/src/9/pc/wifi.c
@@ -1429,8 +1429,7 @@
(ulong)b->wp[2]<<16 |
(ulong)b->wp[3]<<24;
crc = ~crc;
- if(ethercrc(b->rp, BLEN(b)) != crc)
- return -1;
+ crc ^= ethercrc(b->rp, BLEN(b));
b->wp -= 8;
micsetup(&ms, k->key+16);
@@ -1440,7 +1439,7 @@
micupdate(&ms, b->rp, BLEN(b));
micfinish(&ms, mic);
- return memcmp(b->wp, mic, 8) != 0;
+ return tsmemcmp(b->wp, mic, 8) | crc;
}
static uchar*
@@ -1561,7 +1560,7 @@
for(p = sblock(L, N, 0, b, s), x = t; p < &b[M]; x++, p++)
*x ^= *p;
- return memcmp(m, t, M) != 0;
+ return tsmemcmp(m, t, M);
}
static int