summaryrefslogtreecommitdiffstats
path: root/src/methods/common.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2013-12-01 03:49:55 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2013-12-01 03:49:55 +0100
commit5ea41672d71086aec005310600965d9cc3e6ce9c (patch)
tree582b399481da83d21af0a0184a21e2e9fa9d5139 /src/methods/common.c
parente8d93e2c7a95a61d433507947ae25a2b5f21cb73 (diff)
downloadfastd-5ea41672d71086aec005310600965d9cc3e6ce9c.tar
fastd-5ea41672d71086aec005310600965d9cc3e6ce9c.zip
Change common packet header: flags comes first, nonce is big endian
Diffstat (limited to 'src/methods/common.c')
-rw-r--r--src/methods/common.c16
1 files changed, 8 insertions, 8 deletions
diff --git a/src/methods/common.c b/src/methods/common.c
index 9308332..7118ef4 100644
--- a/src/methods/common.c
+++ b/src/methods/common.c
@@ -37,11 +37,11 @@ void fastd_method_common_init(fastd_context_t *ctx, fastd_method_common_t *sessi
session->refresh_after.tv_sec += ctx->conf->key_refresh - fastd_rand(ctx, 0, ctx->conf->key_refresh_splay);
if (initiator) {
- session->send_nonce[0] = 3;
+ session->send_nonce[COMMON_NONCEBYTES-1] = 3;
}
else {
- session->send_nonce[0] = 2;
- session->receive_nonce[0] = 1;
+ session->send_nonce[COMMON_NONCEBYTES-1] = 2;
+ session->receive_nonce[COMMON_NONCEBYTES-1] = 1;
}
}
@@ -49,15 +49,15 @@ bool fastd_method_is_nonce_valid(fastd_context_t *ctx, const fastd_method_common
if ((nonce[0] & 1) != (session->receive_nonce[0] & 1))
return false;
- int i;
+ size_t i;
*age = 0;
- for (i = COMMON_NONCEBYTES-1; i >= 0; i--) {
- *age *= 256;
- *age += session->receive_nonce[i]-nonce[i];
+ for (i = 0; i < COMMON_NONCEBYTES; i++) {
+ *age <<= 8;
+ *age += session->receive_nonce[i] - nonce[i];
}
- *age /= 2;
+ *age >>= 1;
if (*age >= 0) {
if (timespec_diff(&ctx->now, &session->receive_last) > (int)ctx->conf->reorder_time*1000)