From 923d6438f34babecfb53c3925d83afa5178641bd Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Tue, 4 Jun 2013 14:52:36 +0200 Subject: taia: move taia evaluation out of curve. This is not really related to curve functions, so move it out from there. Signed-off-by: Daniel Borkmann --- curve.c | 2 +- curvetun/Makefile | 1 + taia.c | 27 +++++++++++++++++++++++++++ taia.h | 7 +++++++ 4 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 taia.c diff --git a/curve.c b/curve.c index b7d5b4f..e45c529 100644 --- a/curve.c +++ b/curve.c @@ -254,7 +254,7 @@ ssize_t curve25519_decode(struct curve25519_struct *curve, struct curve25519_pro } taia_unpack(chipertext + crypto_box_boxzerobytes - NONCE_LENGTH, &packet_taia); - if (is_good_taia(arrival_taia, &packet_taia) == 0) { + if (taia_looks_good(arrival_taia, &packet_taia) == 0) { syslog(LOG_ERR, "Bad packet time! Dropping connection!\n"); done = 0; goto out; diff --git a/curvetun/Makefile b/curvetun/Makefile index f13c8c7..aebc642 100644 --- a/curvetun/Makefile +++ b/curvetun/Makefile @@ -12,6 +12,7 @@ curvetun-objs = xmalloc.o \ patricia.o \ corking.o \ trie.o \ + taia.o \ hash.o \ rnd.o \ curve.o \ diff --git a/taia.c b/taia.c new file mode 100644 index 0000000..4d02dd9 --- /dev/null +++ b/taia.c @@ -0,0 +1,27 @@ +#include + +#include "taia.h" + +static const struct taia tolerance_taia = { + .sec.x = 0, + .nano = 700000000ULL, + .atto = 0, +}; + +bool taia_looks_good(struct taia *arr_taia, struct taia *pkt_taia) +{ + bool good = false; + struct taia tmp; + + if (taia_less(arr_taia, pkt_taia)) { + taia_sub(&tmp, pkt_taia, arr_taia); + if (taia_less(&tmp, &tolerance_taia)) + good = true; + } else { + taia_sub(&tmp, arr_taia, pkt_taia); + if (taia_less(&tmp, &tolerance_taia)) + good = true; + } + + return good; +} diff --git a/taia.h b/taia.h index 227321d..7440418 100644 --- a/taia.h +++ b/taia.h @@ -2,6 +2,11 @@ #define TAIA_H #include +#include +#include +#include + +#include "rnd.h" struct tai { uint64_t x; @@ -156,4 +161,6 @@ static inline int taia_less(const struct taia *t, const struct taia *u) return t->atto < u->atto; } +extern bool taia_looks_good(struct taia *arr_taia, struct taia *pkt_taia); + #endif /* TAIA_H */ -- cgit v1.2.3-54-g00ecf