diff options
Diffstat (limited to 'src/revocation/revocation_api.c')
-rw-r--r-- | src/revocation/revocation_api.c | 104 |
1 files changed, 45 insertions, 59 deletions
diff --git a/src/revocation/revocation_api.c b/src/revocation/revocation_api.c index 94fbc7022..791c3d008 100644 --- a/src/revocation/revocation_api.c +++ b/src/revocation/revocation_api.c | |||
@@ -423,33 +423,33 @@ calculate_score (const struct GNUNET_REVOCATION_PowCalculationHandle *ph) | |||
423 | 423 | ||
424 | 424 | ||
425 | enum GNUNET_GenericReturnValue | 425 | enum GNUNET_GenericReturnValue |
426 | check_signature_ecdsa (const struct GNUNET_REVOCATION_PowP *pow, | 426 | check_signature_identity (const struct GNUNET_REVOCATION_PowP *pow, |
427 | const struct GNUNET_CRYPTO_EcdsaPublicKey *key) | 427 | const struct GNUNET_IDENTITY_PublicKey *key) |
428 | { | 428 | { |
429 | struct GNUNET_REVOCATION_EcdsaSignaturePurposePS spurp; | 429 | struct GNUNET_REVOCATION_SignaturePurposePS *spurp; |
430 | struct GNUNET_CRYPTO_EcdsaSignature *sig; | 430 | struct GNUNET_IDENTITY_Signature *sig; |
431 | const struct GNUNET_IDENTITY_PublicKey *pk; | 431 | const struct GNUNET_IDENTITY_PublicKey *pk; |
432 | size_t ksize; | 432 | size_t ksize; |
433 | 433 | ||
434 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | 434 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
435 | ksize = GNUNET_IDENTITY_key_get_length (pk); | 435 | ksize = GNUNET_IDENTITY_key_get_length (pk); |
436 | 436 | ||
437 | spurp.ktype = pk->type; | 437 | spurp = GNUNET_malloc (sizeof (*spurp) + ksize); |
438 | spurp.key = pk->ecdsa_key; | 438 | spurp->timestamp = pow->timestamp; |
439 | spurp.timestamp = pow->timestamp; | 439 | spurp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); |
440 | spurp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | 440 | spurp->purpose.size = htonl (sizeof(*spurp) + ksize); |
441 | spurp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 441 | GNUNET_IDENTITY_write_key_to_buffer (pk, |
442 | + GNUNET_IDENTITY_key_get_length (pk) | 442 | (char*) &spurp[1], |
443 | + sizeof (struct GNUNET_TIME_AbsoluteNBO)); | 443 | ksize); |
444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 444 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
445 | "Expected signature payload len: %u\n", | 445 | "Expected signature payload len: %u\n", |
446 | ntohl (spurp.purpose.size)); | 446 | ntohl (spurp->purpose.size)); |
447 | sig = (struct GNUNET_CRYPTO_EcdsaSignature *) ((char*)&pow[1] + ksize); | 447 | sig = (struct GNUNET_IDENTITY_Signature *) ((char*) &pow[1] + ksize); |
448 | if (GNUNET_OK != | 448 | if (GNUNET_OK != |
449 | GNUNET_CRYPTO_ecdsa_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, | 449 | GNUNET_IDENTITY_signature_verify_ (GNUNET_SIGNATURE_PURPOSE_REVOCATION, |
450 | &spurp.purpose, | 450 | &spurp->purpose, |
451 | sig, | 451 | sig, |
452 | key)) | 452 | key)) |
453 | { | 453 | { |
454 | return GNUNET_SYSERR; | 454 | return GNUNET_SYSERR; |
455 | } | 455 | } |
@@ -463,14 +463,7 @@ check_signature (const struct GNUNET_REVOCATION_PowP *pow) | |||
463 | const struct GNUNET_IDENTITY_PublicKey *pk; | 463 | const struct GNUNET_IDENTITY_PublicKey *pk; |
464 | 464 | ||
465 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | 465 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
466 | switch (ntohl (pk->type)) | 466 | return check_signature_identity (pow, pk); |
467 | { | ||
468 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
469 | return check_signature_ecdsa (pow, &pk->ecdsa_key); | ||
470 | default: | ||
471 | return GNUNET_SYSERR; | ||
472 | } | ||
473 | return GNUNET_SYSERR; | ||
474 | } | 467 | } |
475 | 468 | ||
476 | 469 | ||
@@ -576,11 +569,11 @@ GNUNET_REVOCATION_check_pow (const struct GNUNET_REVOCATION_PowP *pow, | |||
576 | 569 | ||
577 | 570 | ||
578 | enum GNUNET_GenericReturnValue | 571 | enum GNUNET_GenericReturnValue |
579 | sign_pow_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | 572 | sign_pow_identity (const struct GNUNET_IDENTITY_PrivateKey *key, |
580 | struct GNUNET_REVOCATION_PowP *pow) | 573 | struct GNUNET_REVOCATION_PowP *pow) |
581 | { | 574 | { |
582 | struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); | 575 | struct GNUNET_TIME_Absolute ts = GNUNET_TIME_absolute_get (); |
583 | struct GNUNET_REVOCATION_EcdsaSignaturePurposePS rp; | 576 | struct GNUNET_REVOCATION_SignaturePurposePS *rp; |
584 | const struct GNUNET_IDENTITY_PublicKey *pk; | 577 | const struct GNUNET_IDENTITY_PublicKey *pk; |
585 | size_t ksize; | 578 | size_t ksize; |
586 | char *sig; | 579 | char *sig; |
@@ -594,21 +587,24 @@ sign_pow_ecdsa (const struct GNUNET_CRYPTO_EcdsaPrivateKey *key, | |||
594 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | 587 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
595 | ksize = GNUNET_IDENTITY_key_get_length (pk); | 588 | ksize = GNUNET_IDENTITY_key_get_length (pk); |
596 | pow->timestamp = GNUNET_TIME_absolute_hton (ts); | 589 | pow->timestamp = GNUNET_TIME_absolute_hton (ts); |
597 | rp.timestamp = pow->timestamp; | 590 | rp = GNUNET_malloc (sizeof (*rp) + ksize); |
598 | rp.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); | 591 | rp->timestamp = pow->timestamp; |
599 | rp.purpose.size = htonl (sizeof(struct GNUNET_CRYPTO_EccSignaturePurpose) | 592 | rp->purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_REVOCATION); |
600 | + ksize | 593 | rp->purpose.size = htonl (sizeof(*rp) + ksize); |
601 | + sizeof (struct GNUNET_TIME_AbsoluteNBO)); | ||
602 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 594 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
603 | "Signature payload len: %u\n", | 595 | "Signature payload len: %u\n", |
604 | ntohl (rp.purpose.size)); | 596 | ntohl (rp->purpose.size)); |
605 | rp.ktype = pk->type; | 597 | GNUNET_IDENTITY_write_key_to_buffer (pk, |
606 | rp.key = pk->ecdsa_key; | 598 | ((char*) &rp[1]), |
607 | sig = ((char*)&pow[1]) + ksize; | 599 | ksize); |
608 | return GNUNET_CRYPTO_ecdsa_sign_ (key, | 600 | sig = ((char*) &pow[1]) + ksize; |
609 | &rp.purpose, | 601 | int result = GNUNET_IDENTITY_sign_ (key, |
610 | (void*) sig); | 602 | &rp->purpose, |
611 | 603 | (void*) sig); | |
604 | if (result == GNUNET_SYSERR) | ||
605 | return GNUNET_NO; | ||
606 | else | ||
607 | return result; | ||
612 | } | 608 | } |
613 | 609 | ||
614 | 610 | ||
@@ -620,14 +616,7 @@ sign_pow (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
620 | 616 | ||
621 | pk = (struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | 617 | pk = (struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
622 | GNUNET_IDENTITY_key_get_public (key, pk); | 618 | GNUNET_IDENTITY_key_get_public (key, pk); |
623 | switch (ntohl (pk->type)) | 619 | return sign_pow_identity (key, pow); |
624 | { | ||
625 | case GNUNET_IDENTITY_TYPE_ECDSA: | ||
626 | return sign_pow_ecdsa (&key->ecdsa_key, pow); | ||
627 | default: | ||
628 | return GNUNET_NO; | ||
629 | } | ||
630 | return GNUNET_NO; | ||
631 | } | 620 | } |
632 | 621 | ||
633 | 622 | ||
@@ -777,20 +766,17 @@ size_t | |||
777 | GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow) | 766 | GNUNET_REVOCATION_proof_get_size (const struct GNUNET_REVOCATION_PowP *pow) |
778 | { | 767 | { |
779 | size_t size; | 768 | size_t size; |
769 | size_t ksize; | ||
780 | const struct GNUNET_IDENTITY_PublicKey *pk; | 770 | const struct GNUNET_IDENTITY_PublicKey *pk; |
771 | const struct GNUNET_IDENTITY_Signature *sig; | ||
781 | 772 | ||
782 | size = sizeof (struct GNUNET_REVOCATION_PowP); | 773 | size = sizeof (struct GNUNET_REVOCATION_PowP); |
783 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; | 774 | pk = (const struct GNUNET_IDENTITY_PublicKey *) &pow[1]; |
784 | size += GNUNET_IDENTITY_key_get_length (pk); | 775 | ksize = GNUNET_IDENTITY_key_get_length (pk); |
785 | 776 | size += ksize; | |
786 | switch (ntohl (pk->type)) | 777 | sig = (struct GNUNET_IDENTITY_Signature *) ((char*) &pow[1] + ksize); |
787 | { | 778 | size += GNUNET_IDENTITY_signature_get_length (sig); |
788 | case GNUNET_IDENTITY_TYPE_ECDSA: | 779 | return size; |
789 | return size + sizeof (struct GNUNET_CRYPTO_EcdsaSignature); | ||
790 | default: | ||
791 | return 0; | ||
792 | } | ||
793 | return 0; | ||
794 | } | 780 | } |
795 | 781 | ||
796 | 782 | ||