aboutsummaryrefslogtreecommitdiff
path: root/src/revocation/revocation_api.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-21 11:52:12 +0200
committerSchanzenbach, Martin <mschanzenbach@posteo.de>2020-04-21 11:52:12 +0200
commit19b772329cb8968e5e96e33d5238f172f5553dc4 (patch)
treeefc2631a96f2e903fb4469d894cfa10d89dc49bd /src/revocation/revocation_api.c
parentd4fd97e693e462f3bd16425f4e803fe5a99b9d62 (diff)
downloadgnunet-19b772329cb8968e5e96e33d5238f172f5553dc4.tar.gz
gnunet-19b772329cb8968e5e96e33d5238f172f5553dc4.zip
new pass API
Diffstat (limited to 'src/revocation/revocation_api.c')
-rw-r--r--src/revocation/revocation_api.c84
1 files changed, 41 insertions, 43 deletions
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