aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Dunwoodie <ncon@noconroy.net>2020-02-26 00:53:04 +1100
committerMatt Dunwoodie <ncon@noconroy.net>2020-02-26 00:53:04 +1100
commitc3c2e84264208004e8161365406a9212c7e1e03c (patch)
tree5f7ea478230171c7bde9f4f89e7001d9b25813f5
parentSplit noise states (diff)
downloadwireguard-openbsd-c3c2e84264208004e8161365406a9212c7e1e03c.tar.xz
wireguard-openbsd-c3c2e84264208004e8161365406a9212c7e1e03c.zip
Fixup noise_counter bugs (identified by tests, to be committed)
Also, bump the window to 512 bits, and set the type to size_t in an attempt to choose the native CPU size.
-rw-r--r--src/noise.c4
-rw-r--r--src/noise.h4
2 files changed, 4 insertions, 4 deletions
diff --git a/src/noise.c b/src/noise.c
index 606e7b7..af8bea2 100644
--- a/src/noise.c
+++ b/src/noise.c
@@ -647,7 +647,7 @@ noise_keypair_counter_recv(struct noise_keypair *kp, uint64_t recv)
index_recv = recv / COUNTER_TYPE_BITS;
index_ctr = ctr->c_recv / COUNTER_TYPE_BITS;
- if (index_recv > index_ctr) {
+ if (recv > ctr->c_recv) {
top = MIN(index_recv - index_ctr, COUNTER_TYPE_NUM);
for (i = 1; i <= top; i++)
ctr->c_backtrack[
@@ -656,7 +656,7 @@ noise_keypair_counter_recv(struct noise_keypair *kp, uint64_t recv)
}
index_recv %= COUNTER_TYPE_NUM;
- bit = 1 << (recv % COUNTER_TYPE_BITS);
+ bit = ((COUNTER_TYPE)1) << (recv % COUNTER_TYPE_BITS);
if (ctr->c_backtrack[index_recv] & bit)
goto error;
diff --git a/src/noise.h b/src/noise.h
index 8eb6ab3..197ce03 100644
--- a/src/noise.h
+++ b/src/noise.h
@@ -242,8 +242,8 @@
#define NOISE_IDENTIFIER_NAME "WireGuard v1 zx2c4 Jason@zx2c4.com"
/* Constants for the counter */
-#define COUNTER_TYPE int
-#define COUNTER_BITS_TOTAL 256
+#define COUNTER_TYPE size_t
+#define COUNTER_BITS_TOTAL 512
#define COUNTER_TYPE_BITS (sizeof(COUNTER_TYPE) * 8)
#define COUNTER_TYPE_NUM (COUNTER_BITS_TOTAL / COUNTER_TYPE_BITS)
#define COUNTER_WINDOW_SIZE (COUNTER_BITS_TOTAL - COUNTER_TYPE_BITS)