2 This file is part of GNUnet.
3 (C) 2001-2013 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file include/gnunet_crypto_lib.h
23 * @brief cryptographic primitives for GNUnet
25 * @author Christian Grothoff
26 * @author Krista Bennett
27 * @author Gerd Knorr <kraxel@bytesex.org>
28 * @author Ioana Patrascu
29 * @author Tzvetan Horozov
31 * @defgroup crypto Cryptographic operations
32 * @defgroup hash Hashing and operations on hashes
35 #ifndef GNUNET_CRYPTO_LIB_H
36 #define GNUNET_CRYPTO_LIB_H
41 #if 0 /* keep Emacsens' auto-indent happy */
46 #include "gnunet_common.h"
47 #include "gnunet_scheduler_lib.h"
51 * Maximum length of an ECC signature.
52 * Note: round up to multiple of 8 minus 2 for alignment.
54 #define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 126
58 * Desired quality level for random numbers.
61 enum GNUNET_CRYPTO_Quality
64 * No good quality of the operation is needed (i.e.,
65 * random numbers can be pseudo-random).
68 GNUNET_CRYPTO_QUALITY_WEAK,
71 * High-quality operations are desired.
74 GNUNET_CRYPTO_QUALITY_STRONG,
77 * Randomness for IVs etc. is required.
80 GNUNET_CRYPTO_QUALITY_NONCE
85 * @brief length of the sessionkey in bytes (256 BIT sessionkey)
87 #define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8)
90 * Length of a hash value
92 #define GNUNET_CRYPTO_HASH_LENGTH (512/8)
95 * @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode.
97 struct GNUNET_CRYPTO_HashAsciiEncoded
99 unsigned char encoding[104];
103 GNUNET_NETWORK_STRUCT_BEGIN
107 * @brief header of what an ECC signature signs
108 * this must be followed by "size - 8" bytes of
109 * the actual signed data
111 struct GNUNET_CRYPTO_EccSignaturePurpose
114 * How many bytes does this signature sign?
115 * (including this purpose header); in network
118 uint32_t size GNUNET_PACKED;
121 * What does this signature vouch for? This
122 * must contain a GNUNET_SIGNATURE_PURPOSE_XXX
123 * constant (from gnunet_signatures.h). In
124 * network byte order!
126 uint32_t purpose GNUNET_PACKED;
132 * @brief an ECC signature
134 struct GNUNET_CRYPTO_EccSignature
140 unsigned char r[256 / 8];
145 unsigned char s[256 / 8];
151 * Public ECC key (always for NIST P-521) encoded in a format suitable
152 * for network transmission and signatures (ECDSA/EdDSA).
154 struct GNUNET_CRYPTO_EccPublicSignKey
157 * Q consists of an x- and a y-value, each mod p (256 bits),
158 * given here in affine coordinates.
160 * FIXME: this coordinate will be removed in the future (compressed point!).
162 unsigned char q_x[256 / 8];
165 * Q consists of an x- and a y-value, each mod p (256 bits),
166 * given here in affine coordinates.
168 unsigned char q_y[256 / 8];
174 * Public ECC key (always for NIST P-521) encoded in a format suitable
175 * for network transmission and encryption (ECDH).
177 struct GNUNET_CRYPTO_EccPublicEncryptKey
180 * Q consists of an x- and a y-value, each mod p (256 bits),
181 * given here in affine coordinates.
183 unsigned char q_x[256 / 8];
186 * Q consists of an x- and a y-value, each mod p (256 bits),
187 * given here in affine coordinates.
189 * FIXME: this coordinate will be removed in the future (compressed point!).
191 unsigned char q_y[256 / 8];
197 * Private ECC key encoded for transmission.
199 struct GNUNET_CRYPTO_EccPrivateKey
202 * d is a value mod n, where n has at most 256 bits.
204 unsigned char d[256 / 8];
210 * @brief type for session keys
212 struct GNUNET_CRYPTO_AesSessionKey
215 * Actual key for AES.
217 unsigned char aes_key[GNUNET_CRYPTO_AES_KEY_LENGTH];
220 * Actual key for TwoFish.
222 unsigned char twofish_key[GNUNET_CRYPTO_AES_KEY_LENGTH];
226 GNUNET_NETWORK_STRUCT_END
229 * @brief IV for sym cipher
231 * NOTE: must be smaller (!) in size than the
232 * `struct GNUNET_HashCode`.
234 struct GNUNET_CRYPTO_AesInitializationVector
236 unsigned char aes_iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
238 unsigned char twofish_iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
243 * @brief type for (message) authentication keys
245 struct GNUNET_CRYPTO_AuthKey
247 unsigned char key[GNUNET_CRYPTO_HASH_LENGTH];
251 /* **************** Functions and Macros ************* */
255 * Seed a weak random generator. Only #GNUNET_CRYPTO_QUALITY_WEAK-mode generator
258 * @param seed the seed to use
261 GNUNET_CRYPTO_seed_weak_random (int32_t seed);
265 * Perform an incremental step in a CRC16 (for TCP/IP) calculation.
267 * @param sum current sum, initially 0
268 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
269 * @param len number of bytes in @a buf, must be multiple of 2
270 * @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16)
273 GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len);
277 * Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
279 * @param sum cummulative sum
280 * @return crc16 value
283 GNUNET_CRYPTO_crc16_finish (uint32_t sum);
288 * Calculate the checksum of a buffer in one step.
290 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
291 * @param len number of bytes in @a buf, must be multiple of 2
292 * @return crc16 value
295 GNUNET_CRYPTO_crc16_n (const void *buf, size_t len);
300 * Compute the CRC32 checksum for the first len
301 * bytes of the buffer.
303 * @param buf the data over which we're taking the CRC
304 * @param len the length of the buffer @a buf in bytes
305 * @return the resulting CRC32 checksum
308 GNUNET_CRYPTO_crc32_n (const void *buf, size_t len);
313 * Produce a random value.
315 * @param mode desired quality of the random number
316 * @param i the upper limit (exclusive) for the random number
317 * @return a random value in the interval [0,@a i) (exclusive).
320 GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
325 * Random on unsigned 64-bit values.
327 * @param mode desired quality of the random number
328 * @param max value returned will be in range [0,@a max) (exclusive)
329 * @return random 64-bit number
332 GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max);
337 * Get an array with a random permutation of the
339 * @param mode #GNUNET_CRYPTO_QUALITY_STRONG if the strong (but expensive) PRNG should be used,
340 * #GNUNET_CRYPTO_QUALITY_WEAK or #GNUNET_CRYPTO_QUALITY_NONCE otherwise
341 * @param n the size of the array
342 * @return the permutation array (allocated from heap)
345 GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n);
350 * Create a new random session key.
352 * @param key key to initialize
355 GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key);
360 * Encrypt a block using a symmetric sessionkey.
362 * @param block the block to encrypt
363 * @param len the size of the block
364 * @param sessionkey the key used to encrypt
365 * @param iv the initialization vector to use, use INITVALUE
367 * @return the size of the encrypted block, -1 for errors
370 GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
371 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
372 const struct GNUNET_CRYPTO_AesInitializationVector
378 * Decrypt a given block using a symmetric sessionkey.
380 * @param block the data to decrypt, encoded as returned by encrypt
381 * @param size how big is the block?
382 * @param sessionkey the key used to decrypt
383 * @param iv the initialization vector to use
384 * @param result address to store the result at
385 * @return -1 on failure, size of decrypted block on success
388 GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
389 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
390 const struct GNUNET_CRYPTO_AesInitializationVector
396 * @brief Derive an IV
397 * @param iv initialization vector
398 * @param skey session key
399 * @param salt salt for the derivation
400 * @param salt_len size of the salt
401 * @param ... pairs of void * & size_t for context chunks, terminated by NULL
404 GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
405 const struct GNUNET_CRYPTO_AesSessionKey *skey,
406 const void *salt, size_t salt_len, ...);
410 * @brief Derive an IV
411 * @param iv initialization vector
412 * @param skey session key
413 * @param salt salt for the derivation
414 * @param salt_len size of the salt
415 * @param argp pairs of void * & size_t for context chunks, terminated by NULL
418 GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
419 const struct GNUNET_CRYPTO_AesSessionKey *skey,
420 const void *salt, size_t salt_len, va_list argp);
425 * Convert hash to ASCII encoding.
426 * @param block the hash code
427 * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be
428 * safely cast to char*, a '\\0' termination is set).
431 GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode * block,
432 struct GNUNET_CRYPTO_HashAsciiEncoded *result);
437 * Convert ASCII encoding back to a 'struct GNUNET_HashCode'
439 * @param enc the encoding
440 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing)
441 * @param result where to store the hash code
442 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
445 GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
446 struct GNUNET_HashCode *result);
451 * Convert ASCII encoding back to `struct GNUNET_HashCode`
453 * @param enc the encoding
454 * @param result where to store the hash code
455 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
457 #define GNUNET_CRYPTO_hash_from_string(enc, result) \
458 GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result)
464 * Compute the distance between 2 hashcodes. The
465 * computation must be fast, not involve a[0] or a[4] (they're used
466 * elsewhere), and be somewhat consistent. And of course, the result
467 * should be a positive number.
469 * @param a some hash code
470 * @param b some hash code
471 * @return number between 0 and UINT32_MAX
474 GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode * a,
475 const struct GNUNET_HashCode * b);
480 * Compute hash of a given block.
482 * @param block the data to hash
483 * @param size size of the @a block
484 * @param ret pointer to where to write the hashcode
487 GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret);
492 * Calculate HMAC of a message (RFC 2104)
494 * @param key secret key
495 * @param plaintext input plaintext
496 * @param plaintext_len length of @a plaintext
497 * @param hmac where to store the hmac
500 GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
501 const void *plaintext, size_t plaintext_len,
502 struct GNUNET_HashCode * hmac);
506 * Function called once the hash computation over the
507 * specified file has completed.
510 * @param res resulting hash, NULL on error
512 typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
513 const struct GNUNET_HashCode *
518 * Handle to file hashing operation.
520 struct GNUNET_CRYPTO_FileHashContext;
525 * Compute the hash of an entire file.
527 * @param priority scheduling priority to use
528 * @param filename name of file to hash
529 * @param blocksize number of bytes to process in one task
530 * @param callback function to call upon completion
531 * @param callback_cls closure for @a callback
532 * @return NULL on (immediate) errror
534 struct GNUNET_CRYPTO_FileHashContext *
535 GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
536 const char *filename, size_t blocksize,
537 GNUNET_CRYPTO_HashCompletedCallback callback,
542 * Cancel a file hashing operation.
544 * @param fhc operation to cancel (callback must not yet have been invoked)
547 GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
552 * Create a random hash code.
554 * @param mode desired quality level
555 * @param result hash code that is randomized
558 GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
559 struct GNUNET_HashCode * result);
564 * compute result(delta) = b - a
566 * @param a some hash code
567 * @param b some hash code
568 * @param result set to @a b - @a a
571 GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode * a,
572 const struct GNUNET_HashCode * b,
573 struct GNUNET_HashCode * result);
578 * compute result(b) = a + delta
580 * @param a some hash code
581 * @param delta some hash code
582 * @param result set to @a a + @a delta
585 GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a,
586 const struct GNUNET_HashCode * delta,
587 struct GNUNET_HashCode * result);
592 * compute result = a ^ b
594 * @param a some hash code
595 * @param b some hash code
596 * @param result set to @a a ^ @a b
599 GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode * a, const struct GNUNET_HashCode * b,
600 struct GNUNET_HashCode * result);
605 * Convert a hashcode into a key.
607 * @param hc hash code that serves to generate the key
608 * @param skey set to a valid session key
609 * @param iv set to a valid initialization vector
612 GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc,
613 struct GNUNET_CRYPTO_AesSessionKey *skey,
614 struct GNUNET_CRYPTO_AesInitializationVector
620 * Obtain a bit from a hashcode.
622 * @param code the `struct GNUNET_HashCode` to index bit-wise
623 * @param bit index into the hashcode, [0...159]
624 * @return Bit \a bit from hashcode \a code, -1 for invalid index
627 GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
633 * Determine how many low order bits match in two
634 * struct GNUNET_HashCodes. i.e. - 010011 and 011111 share
635 * the first two lowest order bits, and therefore the
636 * return value is two (NOT XOR distance, nor how many
637 * bits match absolutely!).
639 * @param first the first hashcode
640 * @param second the hashcode to compare first to
641 * @return the number of bits that match
644 GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first,
645 const struct GNUNET_HashCode * second);
650 * Compare function for HashCodes, producing a total ordering
653 * @param h1 some hash code
654 * @param h2 some hash code
655 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
658 GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode * h1, const struct GNUNET_HashCode * h2);
663 * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
664 * in the XOR metric (Kademlia).
666 * @param h1 some hash code
667 * @param h2 some hash code
668 * @param target some hash code
669 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2.
672 GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode * h1,
673 const struct GNUNET_HashCode * h2,
674 const struct GNUNET_HashCode * target);
679 * @brief Derive an authentication key
680 * @param key authentication key
681 * @param rkey root key
683 * @param salt_len size of the salt
684 * @param argp pair of void * & size_t for context chunks, terminated by NULL
687 GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
688 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
689 const void *salt, size_t salt_len,
695 * @brief Derive an authentication key
696 * @param key authentication key
697 * @param rkey root key
699 * @param salt_len size of the salt
700 * @param ... pair of void * & size_t for context chunks, terminated by NULL
703 GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
704 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
705 const void *salt, size_t salt_len, ...);
711 * @param result buffer for the derived key, allocated by caller
712 * @param out_len desired length of the derived key
713 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
714 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
716 * @param xts_len length of xts
717 * @param skm source key material
718 * @param skm_len length of skm
719 * @param ... pair of void * & size_t for context chunks, terminated by NULL
720 * @return GNUNET_YES on success
723 GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
724 const void *xts, size_t xts_len, const void *skm,
725 size_t skm_len, ...);
731 * @param result buffer for the derived key, allocated by caller
732 * @param out_len desired length of the derived key
733 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
734 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
736 * @param xts_len length of xts
737 * @param skm source key material
738 * @param skm_len length of skm
739 * @param argp va_list of void * & size_t pairs for context chunks
740 * @return GNUNET_YES on success
743 GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
744 const void *xts, size_t xts_len, const void *skm,
745 size_t skm_len, va_list argp);
750 * @param result buffer for the derived key, allocated by caller
751 * @param out_len desired length of the derived key
753 * @param xts_len length of xts
754 * @param skm source key material
755 * @param skm_len length of skm
756 * @param argp va_list of void * & size_t pairs for context chunks
757 * @return GNUNET_YES on success
760 GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
761 size_t xts_len, const void *skm, size_t skm_len,
768 * @param result buffer for the derived key, allocated by caller
769 * @param out_len desired length of the derived key
771 * @param xts_len length of xts
772 * @param skm source key material
773 * @param skm_len length of skm
774 * @param ... void * & size_t pairs for context chunks
775 * @return #GNUNET_YES on success
778 GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
779 size_t xts_len, const void *skm, size_t skm_len, ...);
783 * Function called upon completion of 'GNUNET_CRYPTO_ecc_key_create_async'.
786 * @param pk NULL on error, otherwise the private key (which must be free'd by the callee)
787 * @param emsg NULL on success, otherwise an error message
789 typedef void (*GNUNET_CRYPTO_EccKeyCallback)(void *cls,
790 struct GNUNET_CRYPTO_EccPrivateKey *pk,
796 * Extract the public key for the given private key.
798 * @param priv the private key
799 * @param pub where to write the public key
802 GNUNET_CRYPTO_ecc_key_get_public_for_signature (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
803 struct GNUNET_CRYPTO_EccPublicSignKey *pub);
809 * Extract the public key for the given private key.
811 * @param priv the private key
812 * @param pub where to write the public key
815 GNUNET_CRYPTO_ecc_key_get_public_for_encryption (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
816 struct GNUNET_CRYPTO_EccPublicEncryptKey *pub);
820 * Convert a public key to a string.
822 * @param pub key to convert
823 * @return string representing @a pub
826 GNUNET_CRYPTO_ecc_public_sign_key_to_string (const struct GNUNET_CRYPTO_EccPublicSignKey *pub);
830 * Convert a string representing a public key to a public key.
832 * @param enc encoded public key
833 * @param enclen number of bytes in @a enc (without 0-terminator)
834 * @param pub where to store the public key
835 * @return #GNUNET_OK on success
838 GNUNET_CRYPTO_ecc_public_sign_key_from_string (const char *enc,
840 struct GNUNET_CRYPTO_EccPublicSignKey *pub);
845 * Convert a public key to a string.
847 * @param pub key to convert
848 * @return string representing @a pub
851 GNUNET_CRYPTO_ecc_public_encrypt_key_to_string (const struct GNUNET_CRYPTO_EccPublicEncryptKey *pub);
855 * Convert a string representing a public key to a public key.
857 * @param enc encoded public key
858 * @param enclen number of bytes in @a enc (without 0-terminator)
859 * @param pub where to store the public key
860 * @return #GNUNET_OK on success
863 GNUNET_CRYPTO_ecc_public_encrypt_key_from_string (const char *enc,
865 struct GNUNET_CRYPTO_EccPublicEncryptKey *pub);
870 * Create a new private key by reading it from a file. If the
871 * files does not exist, create a new key and write it to the
872 * file. Caller must free return value. Note that this function
873 * can not guarantee that another process might not be trying
874 * the same operation on the same file at the same time.
875 * If the contents of the file
876 * are invalid the old file is deleted and a fresh key is
879 * @param filename name of file to use to store the key
880 * @return new private key, NULL on error (for example,
881 * permission denied); free using #GNUNET_free
883 struct GNUNET_CRYPTO_EccPrivateKey *
884 GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename);
889 * Create a new private key by reading our peer's key from
890 * the file specified in the configuration.
892 * @param cfg the configuration to use
893 * @return new private key, NULL on error (for example,
894 * permission denied); free using #GNUNET_free
896 struct GNUNET_CRYPTO_EccPrivateKey *
897 GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg);
902 * Create a new private key. Caller must free return value.
904 * @return fresh private key; free using #GNUNET_free
906 struct GNUNET_CRYPTO_EccPrivateKey *
907 GNUNET_CRYPTO_ecc_key_create (void);
912 * Clear memory that was used to store a private key.
914 * @param pk location of the key
917 GNUNET_CRYPTO_ecc_key_clear (struct GNUNET_CRYPTO_EccPrivateKey *pk);
922 * Get the shared private key we use for anonymous users.
924 * @return "anonymous" private key; do not free
926 const struct GNUNET_CRYPTO_EccPrivateKey *
927 GNUNET_CRYPTO_ecc_key_get_anonymous (void);
932 * Setup a hostkey file for a peer given the name of the
933 * configuration file (!). This function is used so that
934 * at a later point code can be certain that reading a
935 * hostkey is fast (for example in time-dependent testcases).
937 * @param cfg_name name of the configuration file to use
940 GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name);
945 * Retrieve the identity of the host's peer.
947 * @param cfg configuration to use
948 * @param dst pointer to where to write the peer identity
949 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
950 * could not be retrieved
953 GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
954 struct GNUNET_PeerIdentity *dst);
959 * Derive key material from a public and a private ECC key.
961 * @param priv private key to use for the ECDH (x)
962 * @param pub public key to use for the ECDY (yG)
963 * @param key_material where to write the key material (xyG)
964 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
967 GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
968 const struct GNUNET_CRYPTO_EccPublicEncryptKey *pub,
969 struct GNUNET_HashCode *key_material);
974 * Sign a given block.
976 * @param priv private key to use for the signing
977 * @param purpose what to sign (size, purpose)
978 * @param sig where to write the signature
979 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
982 GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
983 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
984 struct GNUNET_CRYPTO_EccSignature *sig);
991 * @param purpose what is the purpose that the signature should have?
992 * @param validate block to validate (size, purpose, data)
993 * @param sig signature that is being validated
994 * @param pub public key of the signer
995 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
998 GNUNET_CRYPTO_ecc_verify (uint32_t purpose,
999 const struct GNUNET_CRYPTO_EccSignaturePurpose
1001 const struct GNUNET_CRYPTO_EccSignature *sig,
1002 const struct GNUNET_CRYPTO_EccPublicSignKey *pub);
1007 * Derive a private key from a given private key and a label.
1008 * Essentially calculates a private key 'h = H(l,P) * d mod n'
1009 * where n is the size of the ECC group and P is the public
1010 * key associated with the private key 'd'.
1012 * @param priv original private key
1013 * @param label label to use for key deriviation
1014 * @param context additional context to use for HKDF of 'h';
1015 * typically the name of the subsystem/application
1016 * @return derived private key
1018 struct GNUNET_CRYPTO_EccPrivateKey *
1019 GNUNET_CRYPTO_ecc_key_derive (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
1021 const char *context);
1026 * Derive a public key from a given public key and a label.
1027 * Essentially calculates a public key 'V = H(l,P) * P'.
1029 * @param pub original public key
1030 * @param label label to use for key deriviation
1031 * @param context additional context to use for HKDF of 'h'.
1032 * typically the name of the subsystem/application
1033 * @param result where to write the derived public key
1036 GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicSignKey *pub,
1038 const char *context,
1039 struct GNUNET_CRYPTO_EccPublicSignKey *result);
1042 #if 0 /* keep Emacsens' auto-indent happy */
1050 /* ifndef GNUNET_CRYPTO_LIB_H */
1052 /* end of gnunet_crypto_lib.h */