aboutsummaryrefslogtreecommitdiff
path: root/src/include/gnunet_gnsrecord_lib.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/include/gnunet_gnsrecord_lib.h')
-rw-r--r--src/include/gnunet_gnsrecord_lib.h164
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 */
495const char * 496const char *
496GNUNET_GNSRECORD_z2s (const struct GNUNET_IDENTITY_PublicKey *z); 497GNUNET_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 */
509const char * 510const char *
510GNUNET_GNSRECORD_pkey_to_zkey (const struct GNUNET_IDENTITY_PublicKey *pkey); 511GNUNET_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 */
522int 523int
523GNUNET_GNSRECORD_zkey_to_pkey (const char *zkey, 524GNUNET_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 */
534void 535void
535GNUNET_GNSRECORD_query_from_private_key ( 536GNUNET_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 */
548void 549void
549GNUNET_GNSRECORD_query_from_public_key ( 550GNUNET_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 */
562ssize_t 563ssize_t
563GNUNET_GNSRECORD_block_calculate_size (const struct 564GNUNET_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 */
576enum GNUNET_GenericReturnValue 577enum GNUNET_GenericReturnValue
577GNUNET_GNSRECORD_block_sign (const struct 578GNUNET_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 */
593enum GNUNET_GenericReturnValue 594enum GNUNET_GenericReturnValue
594GNUNET_GNSRECORD_block_create (const struct GNUNET_IDENTITY_PrivateKey *key, 595GNUNET_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 */
617enum GNUNET_GenericReturnValue 618enum GNUNET_GenericReturnValue
618GNUNET_GNSRECORD_block_create_unsigned (const struct 619GNUNET_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 */
640enum GNUNET_GenericReturnValue 641enum GNUNET_GenericReturnValue
641GNUNET_GNSRECORD_block_create2 (const struct GNUNET_IDENTITY_PrivateKey *key, 642GNUNET_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 */
656int 657enum GNUNET_GenericReturnValue
657GNUNET_GNSRECORD_block_verify (const struct GNUNET_GNSRECORD_Block *block); 658GNUNET_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 */
671int 672enum GNUNET_GenericReturnValue
672GNUNET_GNSRECORD_block_decrypt ( 673GNUNET_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 */
685int 686enum GNUNET_GenericReturnValue
686GNUNET_GNSRECORD_records_cmp (const struct GNUNET_GNSRECORD_Data *a, 687GNUNET_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
751GNUNET_GNSRECORD_identity_from_data (const char *data, 752GNUNET_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 */
766enum GNUNET_GenericReturnValue 767enum GNUNET_GenericReturnValue
767GNUNET_GNSRECORD_data_from_identity (const struct 768GNUNET_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,
828enum GNUNET_GenericReturnValue 829enum GNUNET_GenericReturnValue
829GNUNET_GNSRECORD_label_check (const char*label, char **emsg); 830GNUNET_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
846GNUNET_NETWORK_STRUCT_BEGIN
847
848/**
849 * Struct for a proof of work as part of the revocation.
850 */
851struct 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 */
875struct 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
890GNUNET_NETWORK_STRUCT_END
891
892
893/**
894 * Handle to a running proof-of-work calculation.
895 */
896struct 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 */
907enum GNUNET_GenericReturnValue
908GNUNET_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 */
919void
920GNUNET_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 */
933struct GNUNET_GNSRECORD_PowCalculationHandle*
934GNUNET_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 */
945enum GNUNET_GenericReturnValue
946GNUNET_GNSRECORD_pow_round (struct GNUNET_GNSRECORD_PowCalculationHandle *pc);
947
948size_t
949GNUNET_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 */
958void
959GNUNET_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