aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/gnunet_revocation_service.h73
-rw-r--r--src/revocation/gnunet-revocation.c92
-rw-r--r--src/revocation/gnunet-service-revocation.c9
-rw-r--r--src/revocation/revocation_api.c84
-rw-r--r--src/revocation/test_revocation.c17
5 files changed, 125 insertions, 150 deletions
diff --git a/src/include/gnunet_revocation_service.h b/src/include/gnunet_revocation_service.h
index 6bd2e88d3..e8824bd8a 100644
--- a/src/include/gnunet_revocation_service.h
+++ b/src/include/gnunet_revocation_service.h
@@ -69,7 +69,7 @@ struct GNUNET_REVOCATION_Pow
69 /** 69 /**
70 * The TTL of this revocation (purely informational) 70 * The TTL of this revocation (purely informational)
71 */ 71 */
72 uint64_t ttl GNUNET_PACKED; 72 struct GNUNET_TIME_RelativeNBO ttl GNUNET_PACKED;
73 73
74 /** 74 /**
75 * The PoWs 75 * The PoWs
@@ -82,6 +82,18 @@ struct GNUNET_REVOCATION_Pow
82 struct GNUNET_CRYPTO_EcdsaSignature signature; 82 struct GNUNET_CRYPTO_EcdsaSignature signature;
83 83
84 /** 84 /**
85 * The revoked public key
86 */
87 struct GNUNET_CRYPTO_EcdsaPublicKey key;
88};
89
90
91/**
92 * The signature object we use for the PoW
93 */
94struct GNUNET_REVOCATION_SignaturePurpose
95{
96 /**
85 * The signature purpose 97 * The signature purpose
86 */ 98 */
87 struct GNUNET_CRYPTO_EccSignaturePurpose purpose; 99 struct GNUNET_CRYPTO_EccSignaturePurpose purpose;
@@ -90,11 +102,19 @@ struct GNUNET_REVOCATION_Pow
90 * The revoked public key 102 * The revoked public key
91 */ 103 */
92 struct GNUNET_CRYPTO_EcdsaPublicKey key; 104 struct GNUNET_CRYPTO_EcdsaPublicKey key;
105
106 /**
107 * The timestamp of the revocation
108 */
109 struct GNUNET_TIME_AbsoluteNBO timestamp;
93}; 110};
94 111
95GNUNET_NETWORK_STRUCT_END 112GNUNET_NETWORK_STRUCT_END
96 113
97 114
115/**
116 * Handle to a running proof-of-work calculation.
117 */
98struct GNUNET_REVOCATION_PowCalculationHandle; 118struct GNUNET_REVOCATION_PowCalculationHandle;
99 119
100/** 120/**
@@ -112,7 +132,8 @@ struct GNUNET_REVOCATION_Query;
112 * 132 *
113 */ 133 */
114typedef void (*GNUNET_REVOCATION_Callback) (void *cls, 134typedef void (*GNUNET_REVOCATION_Callback) (void *cls,
115 int is_valid); 135 enum GNUNET_GenericReturnValue
136 is_valid);
116 137
117 138
118/** 139/**
@@ -151,7 +172,7 @@ struct GNUNET_REVOCATION_Handle;
151 * @param cfg the configuration to use 172 * @param cfg the configuration to use
152 * @param pow proof of work to use (should have been created by 173 * @param pow proof of work to use (should have been created by
153 * iteratively calling #GNUNET_REVOCATION_pow_round) 174 * iteratively calling #GNUNET_REVOCATION_pow_round)
154 * @param func funtion to call with the result of the check 175 * @param func function to call with the result of the check
155 * (called with `is_valid` being #GNUNET_NO if 176 * (called with `is_valid` being #GNUNET_NO if
156 * the revocation worked). 177 * the revocation worked).
157 * @param func_cls closure to pass to @a func 178 * @param func_cls closure to pass to @a func
@@ -177,40 +198,37 @@ GNUNET_REVOCATION_revoke_cancel (struct GNUNET_REVOCATION_Handle *h);
177 * 198 *
178 * @param pow proof of work 199 * @param pow proof of work
179 * @param matching_bits how many bits must match (configuration) 200 * @param matching_bits how many bits must match (configuration)
180 * @param epoch_length length of single epoch in configuration 201 * @param epoch_duration length of single epoch in configuration
181 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not 202 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
182 */ 203 */
183int 204enum GNUNET_GenericReturnValue
184GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, 205GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
185 unsigned int matching_bits, 206 unsigned int matching_bits,
186 struct GNUNET_TIME_Relative epoch_length); 207 struct GNUNET_TIME_Relative epoch_duration);
187
188 208
189 209
190/** 210/**
191 * Initializes a fresh PoW computation 211 * Initializes a fresh PoW computation.
192 * 212 *
193 * @param key the key to calculate the PoW for. 213 * @param key the key to calculate the PoW for.
194 * @param epochs the number of epochs for which the PoW must be valid. 214 * @param pow the pow object to work with in the calculation.
195 * @param difficulty the base difficulty of the PoW
196 * @return a handle for use in PoW rounds
197 */ 215 */
198struct GNUNET_REVOCATION_PowCalculationHandle* 216void
199GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 217GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
200 int epochs, 218 struct GNUNET_REVOCATION_Pow *pow);
201 unsigned int difficulty);
202 219
203 220
204/** 221/**
205 * Initializes PoW computation based on an existing PoW. 222 * Starts a proof-of-work calculation given the pow object as well as
223 * target epochs and difficulty.
206 * 224 *
207 * @param pow the PoW to continue the calculations from. 225 * @param pow the PoW to based calculations on.
208 * @param epochs the number of epochs for which the PoW must be valid. 226 * @param epochs the number of epochs for which the PoW must be valid.
209 * @param difficulty the base difficulty of the PoW 227 * @param difficulty the base difficulty of the PoW.
210 * @return a handle for use in PoW rounds 228 * @return a handle for use in PoW rounds
211 */ 229 */
212struct GNUNET_REVOCATION_PowCalculationHandle* 230struct GNUNET_REVOCATION_PowCalculationHandle*
213GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow, 231GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow,
214 int epochs, 232 int epochs,
215 unsigned int difficulty); 233 unsigned int difficulty);
216 234
@@ -221,29 +239,18 @@ GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
221 * @param pc handle to the PoW, initially called with NULL. 239 * @param pc handle to the PoW, initially called with NULL.
222 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not 240 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not
223 */ 241 */
224int 242enum GNUNET_GenericReturnValue
225GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc); 243GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc);
226 244
227 245
228/** 246/**
229 * Return the current PoW state from the calculation
230 *
231 * @param pc the calculation to get it from
232 * @return a pointer to the PoW
233 */
234const struct GNUNET_REVOCATION_Pow*
235GNUNET_REVOCATION_pow_get (const struct
236 GNUNET_REVOCATION_PowCalculationHandle *pc);
237
238
239/**
240 * Cleanup a PoW calculation 247 * Cleanup a PoW calculation
241 * 248 *
242 * @param pc the calculation to clean up 249 * @param pc the calculation to clean up
243 */ 250 */
244void 251void
245GNUNET_REVOCATION_pow_cleanup (struct 252GNUNET_REVOCATION_pow_cleanup (
246 GNUNET_REVOCATION_PowCalculationHandle *pc); 253 struct GNUNET_REVOCATION_PowCalculationHandle *pc);
247 254
248#if 0 /* keep Emacsens' auto-indent happy */ 255#if 0 /* keep Emacsens' auto-indent happy */
249{ 256{
diff --git a/src/revocation/gnunet-revocation.c b/src/revocation/gnunet-revocation.c
index d290d34c7..2230114ae 100644
--- a/src/revocation/gnunet-revocation.c
+++ b/src/revocation/gnunet-revocation.c
@@ -93,6 +93,10 @@ static struct GNUNET_TIME_Relative epoch_length;
93 */ 93 */
94static struct GNUNET_SCHEDULER_Task *pow_task; 94static struct GNUNET_SCHEDULER_Task *pow_task;
95 95
96/**
97 * Proof-of-work object
98 */
99static struct GNUNET_REVOCATION_Pow proof_of_work;
96 100
97/** 101/**
98 * Function run if the user aborts with CTRL-C. 102 * Function run if the user aborts with CTRL-C.
@@ -198,40 +202,13 @@ print_revocation_result (void *cls, int is_valid)
198 202
199 203
200/** 204/**
201 * Data needed to perform a revocation.
202 */
203struct RevocationData
204{
205 /**
206 * Public key.
207 */
208 struct GNUNET_CRYPTO_EcdsaPublicKey key;
209
210 /**
211 * Revocation signature data.
212 */
213 struct GNUNET_CRYPTO_EcdsaSignature sig;
214
215 /**
216 * Time of revocation
217 */
218 struct GNUNET_TIME_AbsoluteNBO ts;
219
220 /**
221 * Proof of work (in NBO).
222 */
223 uint64_t pow GNUNET_PACKED;
224};
225
226
227/**
228 * Perform the revocation. 205 * Perform the revocation.
229 */ 206 */
230static void 207static void
231perform_revocation (const struct GNUNET_REVOCATION_Pow *pow) 208perform_revocation ()
232{ 209{
233 h = GNUNET_REVOCATION_revoke (cfg, 210 h = GNUNET_REVOCATION_revoke (cfg,
234 pow, 211 &proof_of_work,
235 &print_revocation_result, 212 &print_revocation_result,
236 NULL); 213 NULL);
237} 214}
@@ -244,12 +221,12 @@ perform_revocation (const struct GNUNET_REVOCATION_Pow *pow)
244 * @param rd data to sync 221 * @param rd data to sync
245 */ 222 */
246static void 223static void
247sync_pow (const struct GNUNET_REVOCATION_Pow *pow) 224sync_pow ()
248{ 225{
249 if ((NULL != filename) && 226 if ((NULL != filename) &&
250 (sizeof(struct GNUNET_REVOCATION_Pow) != 227 (sizeof(struct GNUNET_REVOCATION_Pow) !=
251 GNUNET_DISK_fn_write (filename, 228 GNUNET_DISK_fn_write (filename,
252 pow, 229 &proof_of_work,
253 sizeof(struct GNUNET_REVOCATION_Pow), 230 sizeof(struct GNUNET_REVOCATION_Pow),
254 GNUNET_DISK_PERM_USER_READ 231 GNUNET_DISK_PERM_USER_READ
255 | GNUNET_DISK_PERM_USER_WRITE))) 232 | GNUNET_DISK_PERM_USER_WRITE)))
@@ -267,7 +244,7 @@ calculate_pow_shutdown (void *cls)
267{ 244{
268 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls; 245 struct GNUNET_REVOCATION_PowCalculationHandle *ph = cls;
269 fprintf (stderr, "%s", _ ("Cancelling calculation.\n")); 246 fprintf (stderr, "%s", _ ("Cancelling calculation.\n"));
270 sync_pow (GNUNET_REVOCATION_pow_get (ph)); 247 sync_pow ();
271 if (NULL != pow_task) 248 if (NULL != pow_task)
272 { 249 {
273 GNUNET_SCHEDULER_cancel (pow_task); 250 GNUNET_SCHEDULER_cancel (pow_task);
@@ -290,22 +267,21 @@ calculate_pow (void *cls)
290 /* store temporary results */ 267 /* store temporary results */
291 pow_task = NULL; 268 pow_task = NULL;
292 if (0 == (pow_passes % 128)) 269 if (0 == (pow_passes % 128))
293 sync_pow (GNUNET_REVOCATION_pow_get(ph)); 270 sync_pow ();
294 /* actually do POW calculation */ 271 /* actually do POW calculation */
295 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph)) 272 if (GNUNET_OK == GNUNET_REVOCATION_pow_round (ph))
296 { 273 {
297 const struct GNUNET_REVOCATION_Pow *pow = GNUNET_REVOCATION_pow_get (ph);
298 if ((NULL != filename) && 274 if ((NULL != filename) &&
299 (sizeof(struct GNUNET_REVOCATION_Pow) != 275 (sizeof(struct GNUNET_REVOCATION_Pow) !=
300 GNUNET_DISK_fn_write (filename, 276 GNUNET_DISK_fn_write (filename,
301 pow, 277 &proof_of_work,
302 sizeof(struct GNUNET_REVOCATION_Pow), 278 sizeof(struct GNUNET_REVOCATION_Pow),
303 GNUNET_DISK_PERM_USER_READ 279 GNUNET_DISK_PERM_USER_READ
304 | GNUNET_DISK_PERM_USER_WRITE))) 280 | GNUNET_DISK_PERM_USER_WRITE)))
305 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename); 281 GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, "write", filename);
306 if (perform) 282 if (perform)
307 { 283 {
308 perform_revocation (pow); 284 perform_revocation ();
309 } 285 }
310 else 286 else
311 { 287 {
@@ -343,7 +319,6 @@ calculate_pow (void *cls)
343static void 319static void
344ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego) 320ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
345{ 321{
346 struct GNUNET_REVOCATION_Pow *pow;
347 struct GNUNET_CRYPTO_EcdsaPublicKey key; 322 struct GNUNET_CRYPTO_EcdsaPublicKey key;
348 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; 323 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
349 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL; 324 struct GNUNET_REVOCATION_PowCalculationHandle *ph = NULL;
@@ -357,32 +332,29 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
357 } 332 }
358 GNUNET_IDENTITY_ego_get_public_key (ego, &key); 333 GNUNET_IDENTITY_ego_get_public_key (ego, &key);
359 privkey = GNUNET_IDENTITY_ego_get_private_key (ego); 334 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
360 pow = GNUNET_new (struct GNUNET_REVOCATION_Pow); 335 memset(&proof_of_work, 0, sizeof (proof_of_work));
361 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) && 336 if ((NULL != filename) && (GNUNET_YES == GNUNET_DISK_file_test (filename)) &&
362 (sizeof(struct GNUNET_REVOCATION_Pow) == 337 (sizeof(proof_of_work) ==
363 GNUNET_DISK_fn_read (filename, pow, sizeof(struct 338 GNUNET_DISK_fn_read (filename, &proof_of_work, sizeof(proof_of_work))))
364 GNUNET_REVOCATION_Pow))))
365 { 339 {
366 if (0 != GNUNET_memcmp (&pow->key, &key)) 340 if (0 != GNUNET_memcmp (&proof_of_work.key, &key))
367 { 341 {
368 fprintf (stderr, 342 fprintf (stderr,
369 _ ("Error: revocation certificate in `%s' is not for `%s'\n"), 343 _ ("Error: revocation certificate in `%s' is not for `%s'\n"),
370 filename, 344 filename,
371 revoke_ego); 345 revoke_ego);
372 GNUNET_free (pow);
373 return; 346 return;
374 } 347 }
375 if (GNUNET_YES == 348 if (GNUNET_YES ==
376 GNUNET_REVOCATION_check_pow (pow, 349 GNUNET_REVOCATION_check_pow (&proof_of_work,
377 (unsigned int) matching_bits, 350 (unsigned int) matching_bits,
378 epoch_length)) 351 epoch_length))
379 { 352 {
380 fprintf (stderr, "%s", _ ("Revocation certificate ready\n")); 353 fprintf (stderr, "%s", _ ("Revocation certificate ready\n"));
381 if (perform) 354 if (perform)
382 perform_revocation (pow); 355 perform_revocation ();
383 else 356 else
384 GNUNET_SCHEDULER_shutdown (); 357 GNUNET_SCHEDULER_shutdown ();
385 GNUNET_free (pow);
386 return; 358 return;
387 } 359 }
388 /** 360 /**
@@ -391,18 +363,21 @@ ego_callback (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
391 fprintf (stderr, 363 fprintf (stderr,
392 "%s", 364 "%s",
393 _("Continuing calculation where left off...\n")); 365 _("Continuing calculation where left off...\n"));
394 ph = GNUNET_REVOCATION_pow_init2 (pow, 366 ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
395 1, /* Epochs */ 367 1, /* Epochs */
396 matching_bits); 368 matching_bits);
397 GNUNET_free (pow);
398 } 369 }
399 fprintf (stderr, 370 fprintf (stderr,
400 "%s", 371 "%s",
401 _ ("Revocation certificate not ready, calculating proof of work\n")); 372 _ ("Revocation certificate not ready, calculating proof of work\n"));
402 if (NULL == ph) 373 if (NULL == ph)
403 ph = GNUNET_REVOCATION_pow_init (privkey, 374 {
404 1, /* Epochs */ 375 GNUNET_REVOCATION_pow_init (privkey,
405 matching_bits); 376 &proof_of_work);
377 ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
378 1, /* Epochs */
379 matching_bits);
380 }
406 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 381 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
407 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); 382 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
408} 383}
@@ -423,7 +398,6 @@ run (void *cls,
423 const struct GNUNET_CONFIGURATION_Handle *c) 398 const struct GNUNET_CONFIGURATION_Handle *c)
424{ 399{
425 struct GNUNET_CRYPTO_EcdsaPublicKey pk; 400 struct GNUNET_CRYPTO_EcdsaPublicKey pk;
426 struct GNUNET_REVOCATION_Pow pow;
427 401
428 cfg = c; 402 cfg = c;
429 if (NULL != test_ego) 403 if (NULL != test_ego)
@@ -483,7 +457,9 @@ run (void *cls,
483 } 457 }
484 if ((NULL != filename) && (perform)) 458 if ((NULL != filename) && (perform))
485 { 459 {
486 if (sizeof(pow) != GNUNET_DISK_fn_read (filename, &pow, sizeof(pow))) 460 if (sizeof(proof_of_work) != GNUNET_DISK_fn_read (filename,
461 &proof_of_work,
462 sizeof(proof_of_work)))
487 { 463 {
488 fprintf (stderr, 464 fprintf (stderr,
489 _ ("Failed to read revocation certificate from `%s'\n"), 465 _ ("Failed to read revocation certificate from `%s'\n"),
@@ -492,20 +468,20 @@ run (void *cls,
492 } 468 }
493 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); 469 GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL);
494 if (GNUNET_YES != 470 if (GNUNET_YES !=
495 GNUNET_REVOCATION_check_pow (&pow, 471 GNUNET_REVOCATION_check_pow (&proof_of_work,
496 (unsigned int) matching_bits, 472 (unsigned int) matching_bits,
497 epoch_length)) 473 epoch_length))
498 { 474 {
499 struct GNUNET_REVOCATION_PowCalculationHandle *ph; 475 struct GNUNET_REVOCATION_PowCalculationHandle *ph;
500 ph = GNUNET_REVOCATION_pow_init2 (&pow, 476 ph = GNUNET_REVOCATION_pow_start (&proof_of_work,
501 1, /* Epochs */ 477 1, /* Epochs */
502 matching_bits); 478 matching_bits);
503 479
504 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph); 480 pow_task = GNUNET_SCHEDULER_add_now (&calculate_pow, ph);
505 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph); 481 GNUNET_SCHEDULER_add_shutdown (&calculate_pow_shutdown, ph);
506 return; 482 return;
507 } 483 }
508 perform_revocation (&pow); 484 perform_revocation ();
509 return; 485 return;
510 } 486 }
511 fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n")); 487 fprintf (stderr, "%s", _ ("No action specified. Nothing to do.\n"));
diff --git a/src/revocation/gnunet-service-revocation.c b/src/revocation/gnunet-service-revocation.c
index bd35b1055..a9fbd57a7 100644
--- a/src/revocation/gnunet-service-revocation.c
+++ b/src/revocation/gnunet-service-revocation.c
@@ -181,15 +181,6 @@ verify_revoke_message (const struct RevokeMessage *rm)
181 GNUNET_break_op (0); 181 GNUNET_break_op (0);
182 return GNUNET_NO; 182 return GNUNET_NO;
183 } 183 }
184 if (GNUNET_OK !=
185 GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION,
186 &rm->proof_of_work.purpose,
187 &rm->proof_of_work.signature,
188 &rm->proof_of_work.key))
189 {
190 GNUNET_break_op (0);
191 return GNUNET_NO;
192 }
193 return GNUNET_YES; 184 return GNUNET_YES;
194} 185}
195 186
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c
index 291c58dd8..7bf7799de 100644
--- a/src/revocation/revocation_api.c
+++ b/src/revocation/revocation_api.c
@@ -83,7 +83,7 @@ struct GNUNET_REVOCATION_PowCalculationHandle
83 /** 83 /**
84 * The final PoW result data structure. 84 * The final PoW result data structure.
85 */ 85 */
86 struct GNUNET_REVOCATION_Pow pow; 86 struct GNUNET_REVOCATION_Pow *pow;
87 87
88 /** 88 /**
89 * The current nonce to try 89 * The current nonce to try
@@ -421,23 +421,22 @@ calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph)
421 421
422 422
423/** 423/**
424 * Check if the given proof-of-work value 424 * Check if the given proof-of-work is valid.
425 * would be acceptable for revoking the given key.
426 * 425 *
427 * @param key key to check for 426 * @param pow proof of work
428 * @param ts revocation timestamp
429 * @param pow proof of work value
430 * @param matching_bits how many bits must match (configuration) 427 * @param matching_bits how many bits must match (configuration)
431 * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not 428 * @param epoch_duration length of single epoch in configuration
429 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
432 */ 430 */
433int 431enum GNUNET_GenericReturnValue
434GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow, 432GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
435 unsigned int difficulty, 433 unsigned int difficulty,
436 struct GNUNET_TIME_Relative epoch_length) 434 struct GNUNET_TIME_Relative epoch_length)
437{ 435{
438 char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) 436 char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
439 + sizeof (uint64_t) 437 + sizeof (struct GNUNET_TIME_AbsoluteNBO)
440 + sizeof (uint64_t)] GNUNET_ALIGN; 438 + sizeof (uint64_t)] GNUNET_ALIGN;
439 struct GNUNET_REVOCATION_SignaturePurpose spurp;
441 struct GNUNET_HashCode result; 440 struct GNUNET_HashCode result;
442 struct GNUNET_TIME_Absolute ts; 441 struct GNUNET_TIME_Absolute ts;
443 struct GNUNET_TIME_Absolute exp; 442 struct GNUNET_TIME_Absolute exp;
@@ -451,9 +450,15 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
451 /** 450 /**
452 * Check if signature valid 451 * Check if signature valid
453 */ 452 */
453 spurp.key = pow->key;
454 spurp.timestamp = pow->timestamp;
455 spurp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
456 spurp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
457 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
458 + sizeof (struct GNUNET_TIME_AbsoluteNBO));
454 if (GNUNET_OK != 459 if (GNUNET_OK !=
455 GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, 460 GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION,
456 &pow->purpose, 461 &spurp.purpose,
457 &pow->signature, 462 &pow->signature,
458 &pow->key)) 463 &pow->key))
459 { 464 {
@@ -527,20 +532,17 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_Pow *pow,
527 532
528 533
529/** 534/**
530 * Initializes a fresh PoW computation 535 * Initializes a fresh PoW computation.
531 * 536 *
532 * @param key the key to calculate the PoW for. 537 * @param key the key to calculate the PoW for.
533 * @param epochs the number of epochs for which the PoW must be valid. 538 * @param[out] pow starting point for PoW calculation (not yet valid)
534 * @param difficulty the base difficulty of the PoW
535 * @return a handle for use in PoW rounds
536 */ 539 */
537struct GNUNET_REVOCATION_PowCalculationHandle* 540void
538GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, 541GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
539 int epochs, 542 struct GNUNET_REVOCATION_Pow *pow)
540 unsigned int difficulty)
541{ 543{
542 struct GNUNET_REVOCATION_PowCalculationHandle *pc;
543 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); 544 struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get ();
545 struct GNUNET_REVOCATION_SignaturePurpose rp;
544 546
545 /** 547 /**
546 * Predate the validity period to prevent rejections due to 548 * Predate the validity period to prevent rejections due to
@@ -549,42 +551,39 @@ GNUNET_REVOCATION_pow_init (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key,
549 ts = GNUNET_TIME_absolute_subtract (ts, 551 ts = GNUNET_TIME_absolute_subtract (ts,
550 GNUNET_TIME_UNIT_WEEKS); 552 GNUNET_TIME_UNIT_WEEKS);
551 553
552 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); 554 pow->timestamp = GNUNET_TIME_absolute_hton (ts);
553 pc->pow.timestamp = GNUNET_TIME_absolute_hton (ts); 555 rp.timestamp = pow->timestamp;
554 pc->pow.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); 556 rp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION);
555 pc->pow.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) 557 rp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose)
556 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 558 + sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
557 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pc->pow.key); 559 + sizeof (struct GNUNET_TIME_AbsoluteNBO));
560 GNUNET_CRYPTO_ecdsa_key_get_public (key, &pow->key);
561 rp.key = pow->key;
558 GNUNET_assert (GNUNET_OK == 562 GNUNET_assert (GNUNET_OK ==
559 GNUNET_CRYPTO_ecdsa_sign_ (key, 563 GNUNET_CRYPTO_ecdsa_sign_ (key,
560 &pc->pow.purpose, 564 &rp.purpose,
561 &pc->pow.signature)); 565 &pow->signature));
562 pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
563 UINT64_MAX);
564 pc->difficulty = difficulty;
565 pc->epochs = epochs;
566 return pc;
567} 566}
568 567
569 568
570/** 569/**
571 * Initializes PoW computation based on an existing PoW. 570 * Starts a proof-of-work calculation given the pow object as well as
571 * target epochs and difficulty.
572 * 572 *
573 * @param pow the PoW to continue the calculations from. 573 * @param pow the PoW to based calculations on.
574 * @param epochs the number of epochs for which the PoW must be valid. 574 * @param epochs the number of epochs for which the PoW must be valid.
575 * @param difficulty the base difficulty of the PoW 575 * @param difficulty the base difficulty of the PoW.
576 * @return a handle for use in PoW rounds 576 * @return a handle for use in PoW rounds
577 */ 577 */
578struct GNUNET_REVOCATION_PowCalculationHandle* 578struct GNUNET_REVOCATION_PowCalculationHandle*
579GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow, 579GNUNET_REVOCATION_pow_start (struct GNUNET_REVOCATION_Pow *pow,
580 int epochs, 580 int epochs,
581 unsigned int difficulty) 581 unsigned int difficulty)
582{ 582{
583 struct GNUNET_REVOCATION_PowCalculationHandle *pc; 583 struct GNUNET_REVOCATION_PowCalculationHandle *pc;
584 584
585 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle); 585 pc = GNUNET_new (struct GNUNET_REVOCATION_PowCalculationHandle);
586 pc->pow.key = pow->key; 586 pc->pow = pow;
587 pc->pow.timestamp = pow->timestamp;
588 pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK, 587 pc->current_pow = GNUNET_CRYPTO_random_u64 (GNUNET_CRYPTO_QUALITY_WEAK,
589 UINT64_MAX); 588 UINT64_MAX);
590 pc->difficulty = difficulty; 589 pc->difficulty = difficulty;
@@ -593,7 +592,6 @@ GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
593} 592}
594 593
595 594
596
597/** 595/**
598 * Calculate a key revocation valid for broadcasting for a number 596 * Calculate a key revocation valid for broadcasting for a number
599 * of epochs. 597 * of epochs.
@@ -604,7 +602,7 @@ GNUNET_REVOCATION_pow_init2 (const struct GNUNET_REVOCATION_Pow *pow,
604 * @param difficulty current base difficulty to achieve 602 * @param difficulty current base difficulty to achieve
605 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not 603 * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not
606 */ 604 */
607int 605enum GNUNET_GenericReturnValue
608GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc) 606GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
609{ 607{
610 char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey) 608 char buf[sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)
@@ -624,10 +622,10 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
624 622
625 GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t)); 623 GNUNET_memcpy (buf, &pc->current_pow, sizeof(uint64_t));
626 GNUNET_memcpy (&buf[sizeof(uint64_t)], 624 GNUNET_memcpy (&buf[sizeof(uint64_t)],
627 &pc->pow.timestamp, 625 &pc->pow->timestamp,
628 sizeof (uint64_t)); 626 sizeof (uint64_t));
629 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2], 627 GNUNET_memcpy (&buf[sizeof(uint64_t) * 2],
630 &pc->pow.key, 628 &pc->pow->key,
631 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey)); 629 sizeof(struct GNUNET_CRYPTO_EcdsaPublicKey));
632 GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work", 630 GNUNET_CRYPTO_pow_hash ("gnunet-revocation-proof-of-work",
633 buf, 631 buf,
@@ -640,7 +638,7 @@ GNUNET_REVOCATION_pow_round (struct GNUNET_REVOCATION_PowCalculationHandle *pc)
640 { 638 {
641 pc->best[i].bits = zeros; 639 pc->best[i].bits = zeros;
642 pc->best[i].pow = pc->current_pow; 640 pc->best[i].pow = pc->current_pow;
643 pc->pow.pow[i] = GNUNET_htonll (pc->current_pow); 641 pc->pow->pow[i] = GNUNET_htonll (pc->current_pow);
644 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 642 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
645 "New best score %u with %" PRIu64 " (#%u)\n", 643 "New best score %u with %" PRIu64 " (#%u)\n",
646 zeros, pc->current_pow, i); 644 zeros, pc->current_pow, i);
@@ -662,7 +660,7 @@ const struct GNUNET_REVOCATION_Pow*
662GNUNET_REVOCATION_pow_get (const struct 660GNUNET_REVOCATION_pow_get (const struct
663 GNUNET_REVOCATION_PowCalculationHandle *pc) 661 GNUNET_REVOCATION_PowCalculationHandle *pc)
664{ 662{
665 return &pc->pow; 663 return pc->pow;
666} 664}
667 665
668 666
diff --git a/src/revocation/test_revocation.c b/src/revocation/test_revocation.c
index 07f5e6e61..84f90fe54 100644
--- a/src/revocation/test_revocation.c
+++ b/src/revocation/test_revocation.c
@@ -131,7 +131,7 @@ check_revocation (void *cls)
131 131
132 132
133static void 133static void
134revocation_cb (void *cls, int is_valid) 134revocation_cb (void *cls, enum GNUNET_GenericReturnValue is_valid)
135{ 135{
136 testpeers[1].revok_handle = NULL; 136 testpeers[1].revok_handle = NULL;
137 if (GNUNET_NO == is_valid) 137 if (GNUNET_NO == is_valid)
@@ -147,6 +147,8 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
147{ 147{
148 static int completed = 0; 148 static int completed = 0;
149 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey; 149 const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey;
150 struct GNUNET_REVOCATION_Pow proof_of_work;
151
150 152
151 if ((NULL != ego) && (cls == &testpeers[0])) 153 if ((NULL != ego) && (cls == &testpeers[0]))
152 { 154 {
@@ -162,9 +164,12 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
162 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey); 164 GNUNET_IDENTITY_ego_get_public_key (ego, &testpeers[1].pubkey);
163 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n"); 165 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Calculating proof of work...\n");
164 privkey = GNUNET_IDENTITY_ego_get_private_key (ego); 166 privkey = GNUNET_IDENTITY_ego_get_private_key (ego);
165 testpeers[1].pow = GNUNET_REVOCATION_pow_init (privkey, 167 memset (&proof_of_work, 0, sizeof (proof_of_work));
166 1, 168 GNUNET_REVOCATION_pow_init (privkey,
167 5); 169 &proof_of_work);
170 testpeers[1].pow = GNUNET_REVOCATION_pow_start (&proof_of_work,
171 1,
172 5);
168 int res = 173 int res =
169 GNUNET_REVOCATION_pow_round (testpeers[1].pow); 174 GNUNET_REVOCATION_pow_round (testpeers[1].pow);
170 while (GNUNET_OK != res) 175 while (GNUNET_OK != res)
@@ -177,11 +182,9 @@ ego_cb (void *cls, const struct GNUNET_IDENTITY_Ego *ego)
177 } 182 }
178 if (2 == completed) 183 if (2 == completed)
179 { 184 {
180 const struct GNUNET_REVOCATION_Pow *pow;
181 pow = GNUNET_REVOCATION_pow_get (testpeers[1].pow);
182 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n"); 185 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Egos retrieved\n");
183 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg, 186 testpeers[1].revok_handle = GNUNET_REVOCATION_revoke (testpeers[1].cfg,
184 pow, 187 &proof_of_work,
185 &revocation_cb, 188 &revocation_cb,
186 NULL); 189 NULL);
187 GNUNET_REVOCATION_pow_cleanup (testpeers[1].pow); 190 GNUNET_REVOCATION_pow_cleanup (testpeers[1].pow);