/**
* The TTL of this revocation (purely informational)
*/
- uint64_t ttl GNUNET_PACKED;
+ struct GNUNET_TIME_RelativeNBO ttl GNUNET_PACKED;
/**
* The PoWs
*/
struct GNUNET_CRYPTO_EcdsaSignature signature;
+ /**
+ * The revoked public key
+ */
+ struct GNUNET_CRYPTO_EcdsaPublicKey key;
+};
+
+
+/**
+ * The signature object we use for the PoW
+ */
+struct GNUNET_REVOCATION_SignaturePurpose
+{
/**
* The signature purpose
*/
* The revoked public key
*/
struct GNUNET_CRYPTO_EcdsaPublicKey key;
+
+ /**
+ * The timestamp of the revocation
+ */
+ struct GNUNET_TIME_AbsoluteNBO timestamp;
};
GNUNET_NETWORK_STRUCT_END
+/**
+ * Handle to a running proof-of-work calculation.
+ */
struct GNUNET_REVOCATION_PowCalculationHandle;
/**
*
*/
typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
- int is_valid);
+ enum GNUNET_GenericReturnValue
+ is_valid);
/**
* @param cfg the configuration to use
* @param pow proof of work to use (should have been created by
* iteratively calling #GNUNET_REVOCATION_pow_round)
- * @param func funtion to call with the result of the check
+ * @param func function to call with the result of the check
* (called with `is_valid` being #GNUNET_NO if
* the revocation worked).
* @param func_cls closure to pass to @a func
*
* @param pow proof of work
* @param matching_bits how many bits must match (configuration)
- * @param epoch_length length of single epoch in configuration
- * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
+ * @param epoch_duration length of single epoch in configuration
+ * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
unsigned int matching_bits,
- struct GNUNET_TIME_Relative epoch_length);
-
+ struct GNUNET_TIME_Relative epoch_duration);
/**
- * Initializes a fresh PoW computation
+ * Initializes a fresh PoW computation.
*
* @param key the key to calculate the PoW for.
- * @param epochs the number of epochs for which the PoW must be valid.
- * @param difficulty the base difficulty of the PoW
- * @return a handle for use in PoW rounds
+ * @param pow the pow object to work with in the calculation.
*/
-struct GNUNET_REVOCATION_PowCalculationHandle*
+void
GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
- int epochs,
- unsigned int difficulty);
+ struct GNUNET_REVOCATION_Pow *pow);
/**
- * Initializes PoW computation based on an existing PoW.
+ * Starts a proof-of-work calculation given the pow object as well as
+ * target epochs and difficulty.
*
- * @param pow the PoW to continue the calculations from.
+ * @param pow the PoW to based calculations on.
* @param epochs the number of epochs for which the PoW must be valid.
- * @param difficulty the base difficulty of the PoW
+ * @param difficulty the base difficulty of the PoW.
* @return a handle for use in PoW rounds
*/
struct GNUNET_REVOCATION_PowCalculationHandle*
-GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
+GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow,
int epochs,
unsigned int difficulty);
* @param pc handle to the PoW, initially called with NULL.
* @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
-/**
- * Return the current PoW state from the calculation
- *
- * @param pc the calculation to get it from
- * @return a pointer to the PoW
- */
-const struct GNUNET_REVOCATION_Pow*
-GNUNET_REVOCATION_pow_get (const struct
- GNUNET_REVOCATION_PowCalculationHandle *pc);
-
-
/**
* Cleanup a PoW calculation
*
* @param pc the calculation to clean up
*/
void
-GNUNET_REVOCATION_pow_cleanup (struct
- GNUNET_REVOCATION_PowCalculationHandle *pc);
+GNUNET_REVOCATION_pow_cleanup (
+ struct GNUNET_REVOCATION_PowCalculationHandle *pc);
#if 0 /* keep Emacsens' auto-indent happy */
{
*/
static struct GNUNET_SCHEDULER_Task *pow_task;
+/**
+ * Proof-of-work object
+ */
+static struct GNUNET_REVOCATION_Pow proof_of_work;
/**
* Function run if the user aborts with CTRL-C.
}
-/**
- * Data needed to perform a revocation.
- */
-struct RevocationData
-{
- /**
- * Public key.
- */
- struct GNUNET_CRYPTO_EcdsaPublicKey key;
-
- /**
- * Revocation signature data.
- */
- struct GNUNET_CRYPTO_EcdsaSignature sig;
-
- /**
- * Time of revocation
- */
- struct GNUNET_TIME_AbsoluteNBO ts;
-
- /**
- * Proof of work (in NBO).
- */
- uint64_t pow GNUNET_PACKED;
-};
-
-
/**
* Perform the revocation.
*/
static void
-perform_revocation (const struct GNUNET_REVOCATION_Pow *pow)
+perform_revocation ()
{
h = GNUNET_REVOCATION_revoke (cfg,
- pow,
+ &proof_of_work,
&print_revocation_result,
NULL);
}
* @param rd data to sync
*/
static void
-sync_pow (const struct GNUNET_REVOCATION_Pow *pow)
+sync_pow ()
{
if ((NULL != filename) &&
(sizeof(struct GNUNET_REVOCATION_Pow) !=
GNUNET_DISK_fn_write (filename,
- pow,
+ &proof_of_work,
sizeof(struct GNUNET_REVOCATION_Pow),
GNUNET_DISK_PERM_USER_READ
| GNUNET_DISK_PERM_USER_WRITE)))
{
struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls;
fprintf (stderr, "%s", _ ("Cancelling calculation.\n"));
- sync_pow (GNUNET_REVOCATION_pow_get (ph));
+ sync_pow ();
if (NULL != pow_task)
{
GNUNET_SCHEDULER_cancel (pow_task);
/* store temporary results */
pow_task = NULL;
if (0 == (pow_passes % 128))
- sync_pow (GNUNET_REVOCATION_pow_get(ph));
+ sync_pow ();
/* actually do POW calculation */
if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
{
- const struct GNUNET_REVOCATION_Pow *pow = GNUNET_REVOCATION_pow_get (ph);
if ((NULL != filename) &&
(sizeof(struct GNUNET_REVOCATION_Pow) !=
GNUNET_DISK_fn_write (filename,
- pow,
+ &proof_of_work,
sizeof(struct GNUNET_REVOCATION_Pow),
GNUNET_DISK_PERM_USER_READ
| GNUNET_DISK_PERM_USER_WRITE)))
GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
if (perform)
{
- perform_revocation (pow);
+ perform_revocation ();
}
else
{
static void
ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
{
- struct GNUNET_REVOCATION_Pow *pow;
struct GNUNET_CRYPTO_EcdsaPublicKey key;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
}
GNUNET_IDENTITY_ego_get_public_key (ego, &key);
privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
- pow = GNUNET_new (struct GNUNET_REVOCATION_Pow);
+ memset(&proof_of_work, 0, sizeof (proof_of_work));
if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
- (sizeof(struct GNUNET_REVOCATION_Pow) ==
- GNUNET_DISK_fn_read (filename, pow, sizeof(struct
- GNUNET_REVOCATION_Pow))))
+ (sizeof(proof_of_work) ==
+ GNUNET_DISK_fn_read (filename, &proof_of_work, sizeof(proof_of_work))))
{
- if (0 != GNUNET_memcmp (&pow->key, &key))
+ if (0 != GNUNET_memcmp (&proof_of_work.key, &key))
{
fprintf (stderr,
_ ("Error: revocation certificate in `%s' is not for `%s'\n"),
filename,
revoke_ego);
- GNUNET_free (pow);
return;
}
if (GNUNET_YES ==
- GNUNET_REVOCATION_check_pow (pow,
+ GNUNET_REVOCATION_check_pow (&proof_of_work,
(unsigned int) matching_bits,
epoch_length))
{
fprintf (stderr, "%s", _ ("Revocation certificate ready\n"));
if (perform)
- perform_revocation (pow);
+ perform_revocation ();
else
GNUNET_SCHEDULER_shutdown ();
- GNUNET_free (pow);
return;
}
/**
fprintf (stderr,
"%s",
_("Continuing calculation where left off...\n"));
- ph = GNUNET_REVOCATION_pow_init2 (pow,
+ ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
1, /* Epochs */
matching_bits);
- GNUNET_free (pow);
}
fprintf (stderr,
"%s",
_ ("Revocation certificate not ready, calculating proof of work\n"));
if (NULL == ph)
- ph = GNUNET_REVOCATION_pow_init (privkey,
- 1, /* Epochs */
- matching_bits);
+ {
+ GNUNET_REVOCATION_pow_init (privkey,
+ &proof_of_work);
+ ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
+ 1, /* Epochs */
+ matching_bits);
+ }
pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
}
const struct GNUNET_CONFIGURATION_Handle *c)
{
struct GNUNET_CRYPTO_EcdsaPublicKey pk;
- struct GNUNET_REVOCATION_Pow pow;
cfg = c;
if (NULL != test_ego)
}
if ((NULL != filename) && (perform))
{
- if (sizeof(pow) != GNUNET_DISK_fn_read (filename, &pow, sizeof(pow)))
+ if (sizeof(proof_of_work) != GNUNET_DISK_fn_read (filename,
+ &proof_of_work,
+ sizeof(proof_of_work)))
{
fprintf (stderr,
_ ("Failed to read revocation certificate from `%s'\n"),
}
GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
if (GNUNET_YES !=
- GNUNET_REVOCATION_check_pow (&pow,
+ GNUNET_REVOCATION_check_pow (&proof_of_work,
(unsigned int) matching_bits,
epoch_length))
{
struct GNUNET_REVOCATION_PowCalculationHandle *ph;
- ph = GNUNET_REVOCATION_pow_init2 (&pow,
- 1, /* Epochs */
- matching_bits);
+ ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
+ 1, /* Epochs */
+ matching_bits);
pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
return;
}
- perform_revocation (&pow);
+ perform_revocation ();
return;
}
fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n"));
GNUNET_break_op (0);
return GNUNET_NO;
}
- if (GNUNET_OK !=
- GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION,
- &rm->proof_of_work.purpose,
- &rm->proof_of_work.signature,
- &rm->proof_of_work.key))
- {
- GNUNET_break_op (0);
- return GNUNET_NO;
- }
return GNUNET_YES;
}
/**
* The final PoW result data structure.
*/
- struct GNUNET_REVOCATION_Pow pow;
+ struct GNUNET_REVOCATION_Pow *pow;
/**
* The current nonce to try
/**
- * Check if the given proof-of-work value
- * would be acceptable for revoking the given key.
+ * Check if the given proof-of-work is valid.
*
- * @param key key to check for
- * @param ts revocation timestamp
- * @param pow proof of work value
+ * @param pow proof of work
* @param matching_bits how many bits must match (configuration)
- * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
+ * @param epoch_duration length of single epoch in configuration
+ * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
unsigned int difficulty,
struct GNUNET_TIME_Relative epoch_length)
{
char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
- + sizeof (uint64_t)
+ + sizeof (struct GNUNET_TIME_AbsoluteNBO)
+ sizeof (uint64_t)] GNUNET_ALIGN;
+ struct GNUNET_REVOCATION_SignaturePurpose spurp;
struct GNUNET_HashCode result;
struct GNUNET_TIME_Absolute ts;
struct GNUNET_TIME_Absolute exp;
/**
* Check if signature valid
*/
+ spurp.key = pow->key;
+ spurp.timestamp = pow->timestamp;
+ spurp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
+ spurp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
+ + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
+ + sizeof (struct GNUNET_TIME_AbsoluteNBO));
if (GNUNET_OK !=
GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION,
- &pow->purpose,
+ &spurp.purpose,
&pow->signature,
&pow->key))
{
/**
- * Initializes a fresh PoW computation
+ * Initializes a fresh PoW computation.
*
* @param key the key to calculate the PoW for.
- * @param epochs the number of epochs for which the PoW must be valid.
- * @param difficulty the base difficulty of the PoW
- * @return a handle for use in PoW rounds
+ * @param[out] pow starting point for PoW calculation (not yet valid)
*/
-struct GNUNET_REVOCATION_PowCalculationHandle*
+void
GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
- int epochs,
- unsigned int difficulty)
+ struct GNUNET_REVOCATION_Pow *pow)
{
- struct GNUNET_REVOCATION_PowCalculationHandle *pc;
struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
+ struct GNUNET_REVOCATION_SignaturePurpose rp;
/**
* Predate the validity period to prevent rejections due to
ts = GNUNET_TIME_absolute_subtract (ts,
GNUNET_TIME_UNIT_WEEKS);
- pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
- pc->pow.timestamp = GNUNET_TIME_absolute_hton (ts);
- pc->pow.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
- pc->pow.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
- + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
- GNUNET_CRYPTO_ecdsa_key_get_public (key, &pc->pow.key);
+ pow->timestamp = GNUNET_TIME_absolute_hton (ts);
+ rp.timestamp = pow->timestamp;
+ rp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
+ rp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
+ + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
+ + sizeof (struct GNUNET_TIME_AbsoluteNBO));
+ GNUNET_CRYPTO_ecdsa_key_get_public (key, &pow->key);
+ rp.key = pow->key;
GNUNET_assert (GNUNET_OK ==
GNUNET_CRYPTO_ecdsa_sign_ (key,
- &pc->pow.purpose,
- &pc->pow.signature));
- pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
- UINT64_MAX);
- pc->difficulty = difficulty;
- pc->epochs = epochs;
- return pc;
+ &rp.purpose,
+ &pow->signature));
}
/**
- * Initializes PoW computation based on an existing PoW.
+ * Starts a proof-of-work calculation given the pow object as well as
+ * target epochs and difficulty.
*
- * @param pow the PoW to continue the calculations from.
+ * @param pow the PoW to based calculations on.
* @param epochs the number of epochs for which the PoW must be valid.
- * @param difficulty the base difficulty of the PoW
+ * @param difficulty the base difficulty of the PoW.
* @return a handle for use in PoW rounds
*/
struct GNUNET_REVOCATION_PowCalculationHandle*
-GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
+GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow,
int epochs,
unsigned int difficulty)
{
struct GNUNET_REVOCATION_PowCalculationHandle *pc;
pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
- pc->pow.key = pow->key;
- pc->pow.timestamp = pow->timestamp;
+ pc->pow = pow;
pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
UINT64_MAX);
pc->difficulty = difficulty;
}
-
/**
* Calculate a key revocation valid for broadcasting for a number
* of epochs.
* @param difficulty current base difficulty to achieve
* @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
*/
-int
+enum GNUNET_GenericReturnValue
GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
{
char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t));
GNUNET_memcpy (&buf[sizeof(uint64_t)],
- &pc->pow.timestamp,
+ &pc->pow->timestamp,
sizeof (uint64_t));
GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
- &pc->pow.key,
+ &pc->pow->key,
sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
buf,
{
pc->best[i].bits = zeros;
pc->best[i].pow = pc->current_pow;
- pc->pow.pow[i] = GNUNET_htonll (pc->current_pow);
+ pc->pow->pow[i] = GNUNET_htonll (pc->current_pow);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"New best score %u with %" PRIu64 " (#%u)\n",
zeros, pc->current_pow, i);
GNUNET_REVOCATION_pow_get (const struct
GNUNET_REVOCATION_PowCalculationHandle *pc)
{
- return &pc->pow;
+ return pc->pow;
}
static void
-revocation_cb (void *cls, int is_valid)
+revocation_cb (void *cls, enum GNUNET_GenericReturnValue is_valid)
{
testpeers[1].revok_handle = NULL;
if (GNUNET_NO == is_valid)
{
static int completed = 0;
const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
+ struct GNUNET_REVOCATION_Pow proof_of_work;
+
if ((NULL != ego) && (cls == &testpeers[0]))
{
GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
- testpeers[1].pow = GNUNET_REVOCATION_pow_init (privkey,
- 1,
- 5);
+ memset (&proof_of_work, 0, sizeof (proof_of_work));
+ GNUNET_REVOCATION_pow_init (privkey,
+ &proof_of_work);
+ testpeers[1].pow = GNUNET_REVOCATION_pow_start (&proof_of_work,
+ 1,
+ 5);
int res =
GNUNET_REVOCATION_pow_round (testpeers[1].pow);
while (GNUNET_OK != res)
}
if (2 == completed)
{
- const struct GNUNET_REVOCATION_Pow *pow;
- pow = GNUNET_REVOCATION_pow_get (testpeers[1].pow);
GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n");
testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
- pow,
+ &proof_of_work,
&revocation_cb,
NULL);
GNUNET_REVOCATION_pow_cleanup (testpeers[1].pow);