diff options
Diffstat (limited to 'src/include/gnunet_crypto_lib.h')
-rw-r--r-- | src/include/gnunet_crypto_lib.h | 111 |
1 files changed, 88 insertions, 23 deletions
diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 033803978..6c4a65543 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h | |||
@@ -149,13 +149,15 @@ struct GNUNET_CRYPTO_EccSignature | |||
149 | 149 | ||
150 | /** | 150 | /** |
151 | * Public ECC key (always for NIST P-521) encoded in a format suitable | 151 | * Public ECC key (always for NIST P-521) encoded in a format suitable |
152 | * for network transmission. | 152 | * for network transmission and signatures (ECDSA/EdDSA). |
153 | */ | 153 | */ |
154 | struct GNUNET_CRYPTO_EccPublicKey | 154 | struct GNUNET_CRYPTO_EccPublicSignKey |
155 | { | 155 | { |
156 | /** | 156 | /** |
157 | * Q consists of an x- and a y-value, each mod p (256 bits), | 157 | * Q consists of an x- and a y-value, each mod p (256 bits), |
158 | * given here in affine coordinates. | 158 | * given here in affine coordinates. |
159 | * | ||
160 | * FIXME: this coordinate will be removed in the future (compressed point!). | ||
159 | */ | 161 | */ |
160 | unsigned char q_x[256 / 8]; | 162 | unsigned char q_x[256 / 8]; |
161 | 163 | ||
@@ -169,6 +171,29 @@ struct GNUNET_CRYPTO_EccPublicKey | |||
169 | 171 | ||
170 | 172 | ||
171 | /** | 173 | /** |
174 | * Public ECC key (always for NIST P-521) encoded in a format suitable | ||
175 | * for network transmission and encryption (ECDH). | ||
176 | */ | ||
177 | struct GNUNET_CRYPTO_EccPublicEncryptKey | ||
178 | { | ||
179 | /** | ||
180 | * Q consists of an x- and a y-value, each mod p (256 bits), | ||
181 | * given here in affine coordinates. | ||
182 | */ | ||
183 | unsigned char q_x[256 / 8]; | ||
184 | |||
185 | /** | ||
186 | * Q consists of an x- and a y-value, each mod p (256 bits), | ||
187 | * given here in affine coordinates. | ||
188 | * | ||
189 | * FIXME: this coordinate will be removed in the future (compressed point!). | ||
190 | */ | ||
191 | unsigned char q_y[256 / 8]; | ||
192 | |||
193 | }; | ||
194 | |||
195 | |||
196 | /** | ||
172 | * Private ECC key encoded for transmission. | 197 | * Private ECC key encoded for transmission. |
173 | */ | 198 | */ |
174 | struct GNUNET_CRYPTO_EccPrivateKey | 199 | struct GNUNET_CRYPTO_EccPrivateKey |
@@ -415,11 +440,11 @@ GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen, | |||
415 | 440 | ||
416 | /** | 441 | /** |
417 | * @ingroup hash | 442 | * @ingroup hash |
418 | * Convert ASCII encoding back to struct GNUNET_HashCode | 443 | * Convert ASCII encoding back to `struct GNUNET_HashCode` |
419 | * | 444 | * |
420 | * @param enc the encoding | 445 | * @param enc the encoding |
421 | * @param result where to store the hash code | 446 | * @param result where to store the hash code |
422 | * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding | 447 | * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding |
423 | */ | 448 | */ |
424 | #define GNUNET_CRYPTO_hash_from_string(enc, result) \ | 449 | #define GNUNET_CRYPTO_hash_from_string(enc, result) \ |
425 | GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result) | 450 | GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result) |
@@ -495,7 +520,7 @@ struct GNUNET_CRYPTO_FileHashContext; | |||
495 | * @param filename name of file to hash | 520 | * @param filename name of file to hash |
496 | * @param blocksize number of bytes to process in one task | 521 | * @param blocksize number of bytes to process in one task |
497 | * @param callback function to call upon completion | 522 | * @param callback function to call upon completion |
498 | * @param callback_cls closure for callback | 523 | * @param callback_cls closure for @a callback |
499 | * @return NULL on (immediate) errror | 524 | * @return NULL on (immediate) errror |
500 | */ | 525 | */ |
501 | struct GNUNET_CRYPTO_FileHashContext * | 526 | struct GNUNET_CRYPTO_FileHashContext * |
@@ -586,12 +611,13 @@ GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc, | |||
586 | * @ingroup hash | 611 | * @ingroup hash |
587 | * Obtain a bit from a hashcode. | 612 | * Obtain a bit from a hashcode. |
588 | * | 613 | * |
589 | * @param code the GNUNET_CRYPTO_hash to index bit-wise | 614 | * @param code the `struct GNUNET_HashCode` to index bit-wise |
590 | * @param bit index into the hashcode, [0...159] | 615 | * @param bit index into the hashcode, [0...159] |
591 | * @return Bit \a bit from hashcode \a code, -1 for invalid index | 616 | * @return Bit \a bit from hashcode \a code, -1 for invalid index |
592 | */ | 617 | */ |
593 | int | 618 | int |
594 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode * code, unsigned int bit); | 619 | GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code, |
620 | unsigned int bit); | ||
595 | 621 | ||
596 | 622 | ||
597 | /** | 623 | /** |
@@ -738,7 +764,7 @@ GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts, | |||
738 | * @param skm source key material | 764 | * @param skm source key material |
739 | * @param skm_len length of skm | 765 | * @param skm_len length of skm |
740 | * @param ... void * & size_t pairs for context chunks | 766 | * @param ... void * & size_t pairs for context chunks |
741 | * @return GNUNET_YES on success | 767 | * @return #GNUNET_YES on success |
742 | */ | 768 | */ |
743 | int | 769 | int |
744 | GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, | 770 | GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts, |
@@ -765,32 +791,70 @@ typedef void (*GNUNET_CRYPTO_EccKeyCallback)(void *cls, | |||
765 | * @param pub where to write the public key | 791 | * @param pub where to write the public key |
766 | */ | 792 | */ |
767 | void | 793 | void |
768 | GNUNET_CRYPTO_ecc_key_get_public (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | 794 | GNUNET_CRYPTO_ecc_key_get_public_for_signature (const struct GNUNET_CRYPTO_EccPrivateKey *priv, |
769 | struct GNUNET_CRYPTO_EccPublicKey *pub); | 795 | struct GNUNET_CRYPTO_EccPublicSignKey *pub); |
796 | |||
797 | |||
798 | |||
799 | /** | ||
800 | * @ingroup crypto | ||
801 | * Extract the public key for the given private key. | ||
802 | * | ||
803 | * @param priv the private key | ||
804 | * @param pub where to write the public key | ||
805 | */ | ||
806 | void | ||
807 | GNUNET_CRYPTO_ecc_key_get_public_for_encryption (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | ||
808 | struct GNUNET_CRYPTO_EccPublicEncryptKey *pub); | ||
770 | 809 | ||
771 | 810 | ||
772 | /** | 811 | /** |
773 | * Convert a public key to a string. | 812 | * Convert a public key to a string. |
774 | * | 813 | * |
775 | * @param pub key to convert | 814 | * @param pub key to convert |
776 | * @return string representing 'pub' | 815 | * @return string representing @a pub |
777 | */ | 816 | */ |
778 | char * | 817 | char * |
779 | GNUNET_CRYPTO_ecc_public_key_to_string (const struct GNUNET_CRYPTO_EccPublicKey *pub); | 818 | GNUNET_CRYPTO_ecc_public_sign_key_to_string (const struct GNUNET_CRYPTO_EccPublicSignKey *pub); |
780 | 819 | ||
781 | 820 | ||
782 | /** | 821 | /** |
783 | * Convert a string representing a public key to a public key. | 822 | * Convert a string representing a public key to a public key. |
784 | * | 823 | * |
785 | * @param enc encoded public key | 824 | * @param enc encoded public key |
786 | * @param enclen number of bytes in enc (without 0-terminator) | 825 | * @param enclen number of bytes in @a enc (without 0-terminator) |
787 | * @param pub where to store the public key | 826 | * @param pub where to store the public key |
788 | * @return GNUNET_OK on success | 827 | * @return #GNUNET_OK on success |
789 | */ | 828 | */ |
790 | int | 829 | int |
791 | GNUNET_CRYPTO_ecc_public_key_from_string (const char *enc, | 830 | GNUNET_CRYPTO_ecc_public_sign_key_from_string (const char *enc, |
792 | size_t enclen, | 831 | size_t enclen, |
793 | struct GNUNET_CRYPTO_EccPublicKey *pub); | 832 | struct GNUNET_CRYPTO_EccPublicSignKey *pub); |
833 | |||
834 | |||
835 | |||
836 | /** | ||
837 | * Convert a public key to a string. | ||
838 | * | ||
839 | * @param pub key to convert | ||
840 | * @return string representing @a pub | ||
841 | */ | ||
842 | char * | ||
843 | GNUNET_CRYPTO_ecc_public_encrypt_key_to_string (const struct GNUNET_CRYPTO_EccPublicEncryptKey *pub); | ||
844 | |||
845 | |||
846 | /** | ||
847 | * Convert a string representing a public key to a public key. | ||
848 | * | ||
849 | * @param enc encoded public key | ||
850 | * @param enclen number of bytes in @a enc (without 0-terminator) | ||
851 | * @param pub where to store the public key | ||
852 | * @return #GNUNET_OK on success | ||
853 | */ | ||
854 | int | ||
855 | GNUNET_CRYPTO_ecc_public_encrypt_key_from_string (const char *enc, | ||
856 | size_t enclen, | ||
857 | struct GNUNET_CRYPTO_EccPublicEncryptKey *pub); | ||
794 | 858 | ||
795 | 859 | ||
796 | /** | 860 | /** |
@@ -817,6 +881,7 @@ GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename); | |||
817 | * Create a new private key by reading our peer's key from | 881 | * Create a new private key by reading our peer's key from |
818 | * the file specified in the configuration. | 882 | * the file specified in the configuration. |
819 | * | 883 | * |
884 | * @param cfg the configuration to use | ||
820 | * @return new private key, NULL on error (for example, | 885 | * @return new private key, NULL on error (for example, |
821 | * permission denied); free using #GNUNET_free | 886 | * permission denied); free using #GNUNET_free |
822 | */ | 887 | */ |
@@ -830,8 +895,8 @@ GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATI | |||
830 | * | 895 | * |
831 | * @return fresh private key; free using #GNUNET_free | 896 | * @return fresh private key; free using #GNUNET_free |
832 | */ | 897 | */ |
833 | struct GNUNET_CRYPTO_EccPrivateKey * | 898 | struct GNUNET_CRYPTO_EccPrivateEncryptKey * |
834 | GNUNET_CRYPTO_ecc_key_create (void); | 899 | GNUNET_CRYPTO_ecc_key_encrypt_create (void); |
835 | 900 | ||
836 | 901 | ||
837 | /** | 902 | /** |
@@ -882,7 +947,7 @@ GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
882 | */ | 947 | */ |
883 | int | 948 | int |
884 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | 949 | GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv, |
885 | const struct GNUNET_CRYPTO_EccPublicKey *pub, | 950 | const struct GNUNET_CRYPTO_EccPublicEncryptKey *pub, |
886 | struct GNUNET_HashCode *key_material); | 951 | struct GNUNET_HashCode *key_material); |
887 | 952 | ||
888 | 953 | ||
@@ -916,7 +981,7 @@ GNUNET_CRYPTO_ecc_verify (uint32_t purpose, | |||
916 | const struct GNUNET_CRYPTO_EccSignaturePurpose | 981 | const struct GNUNET_CRYPTO_EccSignaturePurpose |
917 | *validate, | 982 | *validate, |
918 | const struct GNUNET_CRYPTO_EccSignature *sig, | 983 | const struct GNUNET_CRYPTO_EccSignature *sig, |
919 | const struct GNUNET_CRYPTO_EccPublicKey *pub); | 984 | const struct GNUNET_CRYPTO_EccPublicSignKey *pub); |
920 | 985 | ||
921 | 986 | ||
922 | /** | 987 | /** |
@@ -950,10 +1015,10 @@ GNUNET_CRYPTO_ecc_key_derive (const struct GNUNET_CRYPTO_EccPrivateKey *priv, | |||
950 | * @param result where to write the derived public key | 1015 | * @param result where to write the derived public key |
951 | */ | 1016 | */ |
952 | void | 1017 | void |
953 | GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicKey *pub, | 1018 | GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicSignKey *pub, |
954 | const char *label, | 1019 | const char *label, |
955 | const char *context, | 1020 | const char *context, |
956 | struct GNUNET_CRYPTO_EccPublicKey *result); | 1021 | struct GNUNET_CRYPTO_EccPublicSignKey *result); |
957 | 1022 | ||
958 | 1023 | ||
959 | #if 0 /* keep Emacsens' auto-indent happy */ | 1024 | #if 0 /* keep Emacsens' auto-indent happy */ |