summaryrefslogtreecommitdiff
path: root/src/revocation
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-19 20:25:17 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-19 20:25:17 +0200
commit814b19c0b7621e7fb32446fa2996f838f56e45f8 (patch)
tree2bd4f118ac3937c69ce89bd48bf3b1a29429ceb4 /src/revocation
parent8f9a45e853d9759f04a5f4fe9aa0146ed3f3fb17 (diff)
no diplicate nonces
Diffstat (limited to 'src/revocation')
-rw-r--r--src/revocation/revocation_api.c28
1 files changed, 22 insertions, 6 deletions
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 6510f9583..c817e612a 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -27,8 +27,7 @@
#include "gnunet_signatures.h"
#include "gnunet_protocols.h"
#include "revocation.h"
-#include <gcrypt.h>
-
+#include <inttypes.h>
/**
* Handle for the key revocation query.
@@ -389,6 +388,16 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
unsigned int epochs;
uint64_t pow_val;
+ /**
+ * First, check if any duplicates are in the PoW set
+ */
+ for (unsigned int i = 0; i < POW_COUNT; i++)
+ {
+ for (unsigned int j = i+1; j < POW_COUNT; j++) {
+ if (pow->pow[i] == pow->pow[j])
+ return GNUNET_NO;
+ }
+ }
GNUNET_memcpy (&buf[sizeof(uint64_t)],
&pow->timestamp,
sizeof (uint64_t));
@@ -405,8 +414,8 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
&result);
tmp_score = count_leading_zeroes (&result);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "Score %u (#%u)\n",
- tmp_score, i);
+ "Score %u with %"PRIu64" (#%u)\n",
+ tmp_score, pow_val, i);
score += tmp_score;
}
@@ -460,6 +469,13 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
pc->current_pow++;
+ /**
+ * Do not try duplicates
+ */
+ for (unsigned int i = 0; i < POW_COUNT; i++)
+ if (pc->current_pow == pc->best[i].pow)
+ return GNUNET_NO;
+
GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t));
GNUNET_memcpy (&buf[sizeof(uint64_t)],
&pc->pow.timestamp,
@@ -480,8 +496,8 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
pc->best[i].pow = pc->current_pow;
pc->pow.pow[i] = GNUNET_htonll (pc->current_pow);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- "New best score %u (#%u)\n",
- zeros, i);
+ "New best score %u with %"PRIu64" (#%u)\n",
+ zeros, pc->current_pow, i);
break;
}
}