diff options
Diffstat (limited to 'src/include/gnunet_gnsrecord_lib.h')
-rw-r--r-- | src/include/gnunet_gnsrecord_lib.h | 164 |
1 files changed, 147 insertions, 17 deletions
diff --git a/src/include/gnunet_gnsrecord_lib.h b/src/include/gnunet_gnsrecord_lib.h index 3aee30117..3f1830498 100644 --- a/src/include/gnunet_gnsrecord_lib.h +++ b/src/include/gnunet_gnsrecord_lib.h | |||
@@ -38,6 +38,7 @@ | |||
38 | #define GNUNET_GNSRECORD_LIB_H | 38 | #define GNUNET_GNSRECORD_LIB_H |
39 | 39 | ||
40 | 40 | ||
41 | #include "gnunet_common.h" | ||
41 | #include "gnunet_identity_service.h" | 42 | #include "gnunet_identity_service.h" |
42 | 43 | ||
43 | #ifdef __cplusplus | 44 | #ifdef __cplusplus |
@@ -338,7 +339,7 @@ struct GNUNET_GNSRECORD_ReverseRecord | |||
338 | /** | 339 | /** |
339 | * The public key of the namespace the is delegating to our namespace | 340 | * The public key of the namespace the is delegating to our namespace |
340 | */ | 341 | */ |
341 | struct GNUNET_IDENTITY_PublicKey pkey; | 342 | struct GNUNET_CRYPTO_PublicKey pkey; |
342 | 343 | ||
343 | /** | 344 | /** |
344 | * The expiration time of the delegation | 345 | * The expiration time of the delegation |
@@ -493,7 +494,7 @@ GNUNET_GNSRECORD_string_normalize (const char *src); | |||
493 | * #GNUNET_GNSRECORD_z2s. | 494 | * #GNUNET_GNSRECORD_z2s. |
494 | */ | 495 | */ |
495 | const char * | 496 | const char * |
496 | GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); | 497 | GNUNET_GNSRECORD_z2s (const struct GNUNET_CRYPTO_PublicKey *z); |
497 | 498 | ||
498 | 499 | ||
499 | /** | 500 | /** |
@@ -507,7 +508,7 @@ GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); | |||
507 | * key in an encoding suitable for DNS labels. | 508 | * key in an encoding suitable for DNS labels. |
508 | */ | 509 | */ |
509 | const char * | 510 | const char * |
510 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); | 511 | GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_CRYPTO_PublicKey *pkey); |
511 | 512 | ||
512 | 513 | ||
513 | /** | 514 | /** |
@@ -521,7 +522,7 @@ GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); | |||
521 | */ | 522 | */ |
522 | int | 523 | int |
523 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | 524 | GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, |
524 | struct GNUNET_IDENTITY_PublicKey *pkey); | 525 | struct GNUNET_CRYPTO_PublicKey *pkey); |
525 | 526 | ||
526 | 527 | ||
527 | /** | 528 | /** |
@@ -533,7 +534,7 @@ GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, | |||
533 | */ | 534 | */ |
534 | void | 535 | void |
535 | GNUNET_GNSRECORD_query_from_private_key ( | 536 | GNUNET_GNSRECORD_query_from_private_key ( |
536 | const struct GNUNET_IDENTITY_PrivateKey *zone, const char *label, | 537 | const struct GNUNET_CRYPTO_PrivateKey *zone, const char *label, |
537 | struct GNUNET_HashCode *query); | 538 | struct GNUNET_HashCode *query); |
538 | 539 | ||
539 | 540 | ||
@@ -547,7 +548,7 @@ GNUNET_GNSRECORD_query_from_private_key ( | |||
547 | */ | 548 | */ |
548 | void | 549 | void |
549 | GNUNET_GNSRECORD_query_from_public_key ( | 550 | GNUNET_GNSRECORD_query_from_public_key ( |
550 | const struct GNUNET_IDENTITY_PublicKey *pub, const char *label, | 551 | const struct GNUNET_CRYPTO_PublicKey *pub, const char *label, |
551 | struct GNUNET_HashCode *query); | 552 | struct GNUNET_HashCode *query); |
552 | 553 | ||
553 | 554 | ||
@@ -561,7 +562,7 @@ GNUNET_GNSRECORD_query_from_public_key ( | |||
561 | */ | 562 | */ |
562 | ssize_t | 563 | ssize_t |
563 | GNUNET_GNSRECORD_block_calculate_size (const struct | 564 | GNUNET_GNSRECORD_block_calculate_size (const struct |
564 | GNUNET_IDENTITY_PrivateKey *key, | 565 | GNUNET_CRYPTO_PrivateKey *key, |
565 | const struct GNUNET_GNSRECORD_Data *rd, | 566 | const struct GNUNET_GNSRECORD_Data *rd, |
566 | unsigned int rd_count); | 567 | unsigned int rd_count); |
567 | 568 | ||
@@ -575,7 +576,7 @@ GNUNET_GNSRECORD_block_calculate_size (const struct | |||
575 | */ | 576 | */ |
576 | enum GNUNET_GenericReturnValue | 577 | enum GNUNET_GenericReturnValue |
577 | GNUNET_GNSRECORD_block_sign (const struct | 578 | GNUNET_GNSRECORD_block_sign (const struct |
578 | GNUNET_IDENTITY_PrivateKey *key, | 579 | GNUNET_CRYPTO_PrivateKey *key, |
579 | const char *label, | 580 | const char *label, |
580 | struct GNUNET_GNSRECORD_Block *block); | 581 | struct GNUNET_GNSRECORD_Block *block); |
581 | 582 | ||
@@ -591,7 +592,7 @@ GNUNET_GNSRECORD_block_sign (const struct | |||
591 | * @return GNUNET_OK on success | 592 | * @return GNUNET_OK on success |
592 | */ | 593 | */ |
593 | enum GNUNET_GenericReturnValue | 594 | enum GNUNET_GenericReturnValue |
594 | GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | 595 | GNUNET_GNSRECORD_block_create (const struct GNUNET_CRYPTO_PrivateKey *key, |
595 | struct GNUNET_TIME_Absolute expire, | 596 | struct GNUNET_TIME_Absolute expire, |
596 | const char *label, | 597 | const char *label, |
597 | const struct GNUNET_GNSRECORD_Data *rd, | 598 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -616,7 +617,7 @@ GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
616 | */ | 617 | */ |
617 | enum GNUNET_GenericReturnValue | 618 | enum GNUNET_GenericReturnValue |
618 | GNUNET_GNSRECORD_block_create_unsigned (const struct | 619 | GNUNET_GNSRECORD_block_create_unsigned (const struct |
619 | GNUNET_IDENTITY_PrivateKey *key, | 620 | GNUNET_CRYPTO_PrivateKey *key, |
620 | struct GNUNET_TIME_Absolute expire, | 621 | struct GNUNET_TIME_Absolute expire, |
621 | const char *label, | 622 | const char *label, |
622 | const struct GNUNET_GNSRECORD_Data *rd, | 623 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -638,7 +639,7 @@ GNUNET_GNSRECORD_block_create_unsigned (const struct | |||
638 | * @return GNUNET_OK on success. | 639 | * @return GNUNET_OK on success. |
639 | */ | 640 | */ |
640 | enum GNUNET_GenericReturnValue | 641 | enum GNUNET_GenericReturnValue |
641 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, | 642 | GNUNET_GNSRECORD_block_create2 (const struct GNUNET_CRYPTO_PrivateKey *key, |
642 | struct GNUNET_TIME_Absolute expire, | 643 | struct GNUNET_TIME_Absolute expire, |
643 | const char *label, | 644 | const char *label, |
644 | const struct GNUNET_GNSRECORD_Data *rd, | 645 | const struct GNUNET_GNSRECORD_Data *rd, |
@@ -653,7 +654,7 @@ GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, | |||
653 | * @param block block to verify | 654 | * @param block block to verify |
654 | * @return #GNUNET_OK if the signature is valid | 655 | * @return #GNUNET_OK if the signature is valid |
655 | */ | 656 | */ |
656 | int | 657 | enum GNUNET_GenericReturnValue |
657 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | 658 | GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); |
658 | 659 | ||
659 | 660 | ||
@@ -668,10 +669,10 @@ GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); | |||
668 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was | 669 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if the block was |
669 | * not well-formed | 670 | * not well-formed |
670 | */ | 671 | */ |
671 | int | 672 | enum GNUNET_GenericReturnValue |
672 | GNUNET_GNSRECORD_block_decrypt ( | 673 | GNUNET_GNSRECORD_block_decrypt ( |
673 | const struct GNUNET_GNSRECORD_Block *block, | 674 | const struct GNUNET_GNSRECORD_Block *block, |
674 | const struct GNUNET_IDENTITY_PublicKey *zone_key, const char *label, | 675 | const struct GNUNET_CRYPTO_PublicKey *zone_key, const char *label, |
675 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); | 676 | GNUNET_GNSRECORD_RecordCallback proc, void *proc_cls); |
676 | 677 | ||
677 | 678 | ||
@@ -682,7 +683,7 @@ GNUNET_GNSRECORD_block_decrypt ( | |||
682 | * @param b another record | 683 | * @param b another record |
683 | * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. | 684 | * @return #GNUNET_YES if the records are equal, or #GNUNET_NO if not. |
684 | */ | 685 | */ |
685 | int | 686 | enum GNUNET_GenericReturnValue |
686 | GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, | 687 | GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, |
687 | const struct GNUNET_GNSRECORD_Data *b); | 688 | const struct GNUNET_GNSRECORD_Data *b); |
688 | 689 | ||
@@ -751,7 +752,7 @@ enum GNUNET_GenericReturnValue | |||
751 | GNUNET_GNSRECORD_identity_from_data (const char *data, | 752 | GNUNET_GNSRECORD_identity_from_data (const char *data, |
752 | size_t data_size, | 753 | size_t data_size, |
753 | uint32_t type, | 754 | uint32_t type, |
754 | struct GNUNET_IDENTITY_PublicKey *key); | 755 | struct GNUNET_CRYPTO_PublicKey *key); |
755 | 756 | ||
756 | 757 | ||
757 | /** | 758 | /** |
@@ -765,7 +766,7 @@ GNUNET_GNSRECORD_identity_from_data (const char *data, | |||
765 | */ | 766 | */ |
766 | enum GNUNET_GenericReturnValue | 767 | enum GNUNET_GenericReturnValue |
767 | GNUNET_GNSRECORD_data_from_identity (const struct | 768 | GNUNET_GNSRECORD_data_from_identity (const struct |
768 | GNUNET_IDENTITY_PublicKey *key, | 769 | GNUNET_CRYPTO_PublicKey *key, |
769 | char **data, | 770 | char **data, |
770 | size_t *data_size, | 771 | size_t *data_size, |
771 | uint32_t *type); | 772 | uint32_t *type); |
@@ -828,6 +829,135 @@ GNUNET_GNSRECORD_normalize_record_set (const char *label, | |||
828 | enum GNUNET_GenericReturnValue | 829 | enum GNUNET_GenericReturnValue |
829 | GNUNET_GNSRECORD_label_check (const char*label, char **emsg); | 830 | GNUNET_GNSRECORD_label_check (const char*label, char **emsg); |
830 | 831 | ||
832 | /** | ||
833 | * Maximum length of a revocation | ||
834 | */ | ||
835 | #define GNUNET_MAX_POW_SIZE sizeof(struct GNUNET_GNSRECORD_PowP) +\ | ||
836 | sizeof(struct GNUNET_CRYPTO_PublicKey) +\ | ||
837 | 1024 //FIXME max sig_len | ||
838 | |||
839 | /** | ||
840 | * The proof-of-work narrowing factor. | ||
841 | * The number of PoWs that are calculates as part of revocation. | ||
842 | */ | ||
843 | #define POW_COUNT 32 | ||
844 | |||
845 | |||
846 | GNUNET_NETWORK_STRUCT_BEGIN | ||
847 | |||
848 | /** | ||
849 | * Struct for a proof of work as part of the revocation. | ||
850 | */ | ||
851 | struct GNUNET_GNSRECORD_PowP | ||
852 | { | ||
853 | /** | ||
854 | * The timestamp of the revocation | ||
855 | */ | ||
856 | struct GNUNET_TIME_AbsoluteNBO timestamp; | ||
857 | |||
858 | /** | ||
859 | * The TTL of this revocation (purely informational) | ||
860 | */ | ||
861 | struct GNUNET_TIME_RelativeNBO ttl; | ||
862 | |||
863 | /** | ||
864 | * The PoWs | ||
865 | */ | ||
866 | uint64_t pow[POW_COUNT] GNUNET_PACKED; | ||
867 | |||
868 | /** followed by the public key type, the key and a signature **/ | ||
869 | }; | ||
870 | |||
871 | |||
872 | /** | ||
873 | * The signature object we use for the PoW | ||
874 | */ | ||
875 | struct GNUNET_GNSRECORD_SignaturePurposePS | ||
876 | { | ||
877 | /** | ||
878 | * The signature purpose | ||
879 | */ | ||
880 | struct GNUNET_CRYPTO_EccSignaturePurpose purpose; | ||
881 | |||
882 | /** | ||
883 | * The timestamp of the revocation | ||
884 | */ | ||
885 | struct GNUNET_TIME_AbsoluteNBO timestamp; | ||
886 | |||
887 | /** Followed by the zone public key type and key **/ | ||
888 | }; | ||
889 | |||
890 | GNUNET_NETWORK_STRUCT_END | ||
891 | |||
892 | |||
893 | /** | ||
894 | * Handle to a running proof-of-work calculation. | ||
895 | */ | ||
896 | struct GNUNET_GNSRECORD_PowCalculationHandle; | ||
897 | |||
898 | |||
899 | /** | ||
900 | * Check if the given proof-of-work is valid. | ||
901 | * | ||
902 | * @param pow proof of work | ||
903 | * @param matching_bits how many bits must match (configuration) | ||
904 | * @param epoch_duration length of single epoch in configuration | ||
905 | * @return #GNUNET_YES if the @a pow is acceptable, #GNUNET_NO if not | ||
906 | */ | ||
907 | enum GNUNET_GenericReturnValue | ||
908 | GNUNET_GNSRECORD_check_pow (const struct GNUNET_GNSRECORD_PowP *pow, | ||
909 | unsigned int matching_bits, | ||
910 | struct GNUNET_TIME_Relative epoch_duration); | ||
911 | |||
912 | |||
913 | /** | ||
914 | * Initializes a fresh PoW computation. | ||
915 | * | ||
916 | * @param key the key to calculate the PoW for. | ||
917 | * @param pow the pow object to work with in the calculation. | ||
918 | */ | ||
919 | void | ||
920 | GNUNET_GNSRECORD_pow_init (const struct GNUNET_CRYPTO_PrivateKey *key, | ||
921 | struct GNUNET_GNSRECORD_PowP *pow); | ||
922 | |||
923 | |||
924 | /** | ||
925 | * Starts a proof-of-work calculation given the pow object as well as | ||
926 | * target epochs and difficulty. | ||
927 | * | ||
928 | * @param pow the PoW to based calculations on. | ||
929 | * @param epochs the number of epochs for which the PoW must be valid. | ||
930 | * @param difficulty the base difficulty of the PoW. | ||
931 | * @return a handle for use in PoW rounds | ||
932 | */ | ||
933 | struct GNUNET_GNSRECORD_PowCalculationHandle* | ||
934 | GNUNET_GNSRECORD_pow_start (struct GNUNET_GNSRECORD_PowP *pow, | ||
935 | int epochs, | ||
936 | unsigned int difficulty); | ||
937 | |||
938 | |||
939 | /** | ||
940 | * Calculate a single round in the key revocation PoW. | ||
941 | * | ||
942 | * @param pc handle to the PoW, initially called with NULL. | ||
943 | * @return GNUNET_YES if the @a pow is acceptable, GNUNET_NO if not | ||
944 | */ | ||
945 | enum GNUNET_GenericReturnValue | ||
946 | GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc); | ||
947 | |||
948 | size_t | ||
949 | GNUNET_GNSRECORD_proof_get_size (const struct GNUNET_GNSRECORD_PowP *pow); | ||
950 | |||
951 | /** | ||
952 | * Stop a PoW calculation | ||
953 | * | ||
954 | * @param pc the calculation to clean up | ||
955 | * @return #GNUNET_YES if pow valid, #GNUNET_NO if pow was set but is not | ||
956 | * valid | ||
957 | */ | ||
958 | void | ||
959 | GNUNET_GNSRECORD_pow_stop (struct GNUNET_GNSRECORD_PowCalculationHandle *pc); | ||
960 | |||
831 | #if 0 /* keep Emacsens' auto-indent happy */ | 961 | #if 0 /* keep Emacsens' auto-indent happy */ |
832 | { | 962 | { |
833 | #endif | 963 | #endif |