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 unsigned char q_y[256 / 8];
166 * Public ECC key (always for NIST P-521) encoded in a format suitable
167 * for network transmission and encryption (ECDH).
169 struct GNUNET_CRYPTO_EccPublicEncryptKey
172 * Q consists of an x- and a y-value, each mod p (256 bits),
173 * given here in affine coordinates.
175 unsigned char q_x[256 / 8];
181 * Private ECC key encoded for transmission.
183 struct GNUNET_CRYPTO_EccPrivateKey
186 * d is a value mod n, where n has at most 256 bits.
188 unsigned char d[256 / 8];
194 * @brief type for session keys
196 struct GNUNET_CRYPTO_AesSessionKey
201 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH];
204 GNUNET_NETWORK_STRUCT_END
207 * @brief IV for sym cipher
209 * NOTE: must be smaller (!) in size than the
210 * struct GNUNET_HashCode.
212 struct GNUNET_CRYPTO_AesInitializationVector
214 unsigned char iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
219 * @brief type for (message) authentication keys
221 struct GNUNET_CRYPTO_AuthKey
223 unsigned char key[GNUNET_CRYPTO_HASH_LENGTH];
227 /* **************** Functions and Macros ************* */
231 * Seed a weak random generator. Only #GNUNET_CRYPTO_QUALITY_WEAK-mode generator
234 * @param seed the seed to use
237 GNUNET_CRYPTO_seed_weak_random (int32_t seed);
241 * Perform an incremental step in a CRC16 (for TCP/IP) calculation.
243 * @param sum current sum, initially 0
244 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
245 * @param len number of bytes in @a buf, must be multiple of 2
246 * @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16)
249 GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len);
253 * Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
255 * @param sum cummulative sum
256 * @return crc16 value
259 GNUNET_CRYPTO_crc16_finish (uint32_t sum);
264 * Calculate the checksum of a buffer in one step.
266 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
267 * @param len number of bytes in @a buf, must be multiple of 2
268 * @return crc16 value
271 GNUNET_CRYPTO_crc16_n (const void *buf, size_t len);
276 * Compute the CRC32 checksum for the first len
277 * bytes of the buffer.
279 * @param buf the data over which we're taking the CRC
280 * @param len the length of the buffer @a buf in bytes
281 * @return the resulting CRC32 checksum
284 GNUNET_CRYPTO_crc32_n (const void *buf, size_t len);
289 * Produce a random value.
291 * @param mode desired quality of the random number
292 * @param i the upper limit (exclusive) for the random number
293 * @return a random value in the interval [0,@a i) (exclusive).
296 GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
301 * Random on unsigned 64-bit values.
303 * @param mode desired quality of the random number
304 * @param max value returned will be in range [0,@a max) (exclusive)
305 * @return random 64-bit number
308 GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max);
313 * Get an array with a random permutation of the
315 * @param mode #GNUNET_CRYPTO_QUALITY_STRONG if the strong (but expensive) PRNG should be used,
316 * #GNUNET_CRYPTO_QUALITY_WEAK or #GNUNET_CRYPTO_QUALITY_NONCE otherwise
317 * @param n the size of the array
318 * @return the permutation array (allocated from heap)
321 GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n);
326 * Create a new random session key.
328 * @param key key to initialize
331 GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key);
336 * Encrypt a block using a symmetric sessionkey.
338 * @param block the block to encrypt
339 * @param len the size of the block
340 * @param sessionkey the key used to encrypt
341 * @param iv the initialization vector to use, use INITVALUE
343 * @return the size of the encrypted block, -1 for errors
346 GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
347 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
348 const struct GNUNET_CRYPTO_AesInitializationVector
354 * Decrypt a given block using a symmetric sessionkey.
356 * @param block the data to decrypt, encoded as returned by encrypt
357 * @param size how big is the block?
358 * @param sessionkey the key used to decrypt
359 * @param iv the initialization vector to use
360 * @param result address to store the result at
361 * @return -1 on failure, size of decrypted block on success
364 GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
365 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
366 const struct GNUNET_CRYPTO_AesInitializationVector
372 * @brief Derive an IV
373 * @param iv initialization vector
374 * @param skey session key
375 * @param salt salt for the derivation
376 * @param salt_len size of the salt
377 * @param ... pairs of void * & size_t for context chunks, terminated by NULL
380 GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
381 const struct GNUNET_CRYPTO_AesSessionKey *skey,
382 const void *salt, size_t salt_len, ...);
386 * @brief Derive an IV
387 * @param iv initialization vector
388 * @param skey session key
389 * @param salt salt for the derivation
390 * @param salt_len size of the salt
391 * @param argp pairs of void * & size_t for context chunks, terminated by NULL
394 GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
395 const struct GNUNET_CRYPTO_AesSessionKey *skey,
396 const void *salt, size_t salt_len, va_list argp);
401 * Convert hash to ASCII encoding.
402 * @param block the hash code
403 * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be
404 * safely cast to char*, a '\\0' termination is set).
407 GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode * block,
408 struct GNUNET_CRYPTO_HashAsciiEncoded *result);
413 * Convert ASCII encoding back to a 'struct GNUNET_HashCode'
415 * @param enc the encoding
416 * @param enclen number of characters in @a enc (without 0-terminator, which can be missing)
417 * @param result where to store the hash code
418 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
421 GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
422 struct GNUNET_HashCode *result);
427 * Convert ASCII encoding back to `struct GNUNET_HashCode`
429 * @param enc the encoding
430 * @param result where to store the hash code
431 * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
433 #define GNUNET_CRYPTO_hash_from_string(enc, result) \
434 GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result)
440 * Compute the distance between 2 hashcodes. The
441 * computation must be fast, not involve a[0] or a[4] (they're used
442 * elsewhere), and be somewhat consistent. And of course, the result
443 * should be a positive number.
445 * @param a some hash code
446 * @param b some hash code
447 * @return number between 0 and UINT32_MAX
450 GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode * a,
451 const struct GNUNET_HashCode * b);
456 * Compute hash of a given block.
458 * @param block the data to hash
459 * @param size size of the @a block
460 * @param ret pointer to where to write the hashcode
463 GNUNET_CRYPTO_hash (const void *block, size_t size, struct GNUNET_HashCode * ret);
468 * Calculate HMAC of a message (RFC 2104)
470 * @param key secret key
471 * @param plaintext input plaintext
472 * @param plaintext_len length of @a plaintext
473 * @param hmac where to store the hmac
476 GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
477 const void *plaintext, size_t plaintext_len,
478 struct GNUNET_HashCode * hmac);
482 * Function called once the hash computation over the
483 * specified file has completed.
486 * @param res resulting hash, NULL on error
488 typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
489 const struct GNUNET_HashCode *
494 * Handle to file hashing operation.
496 struct GNUNET_CRYPTO_FileHashContext;
501 * Compute the hash of an entire file.
503 * @param priority scheduling priority to use
504 * @param filename name of file to hash
505 * @param blocksize number of bytes to process in one task
506 * @param callback function to call upon completion
507 * @param callback_cls closure for @a callback
508 * @return NULL on (immediate) errror
510 struct GNUNET_CRYPTO_FileHashContext *
511 GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
512 const char *filename, size_t blocksize,
513 GNUNET_CRYPTO_HashCompletedCallback callback,
518 * Cancel a file hashing operation.
520 * @param fhc operation to cancel (callback must not yet have been invoked)
523 GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
528 * Create a random hash code.
530 * @param mode desired quality level
531 * @param result hash code that is randomized
534 GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
535 struct GNUNET_HashCode * result);
540 * compute result(delta) = b - a
542 * @param a some hash code
543 * @param b some hash code
544 * @param result set to @a b - @a a
547 GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode * a,
548 const struct GNUNET_HashCode * b,
549 struct GNUNET_HashCode * result);
554 * compute result(b) = a + delta
556 * @param a some hash code
557 * @param delta some hash code
558 * @param result set to @a a + @a delta
561 GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode * a,
562 const struct GNUNET_HashCode * delta,
563 struct GNUNET_HashCode * result);
568 * compute result = a ^ b
570 * @param a some hash code
571 * @param b some hash code
572 * @param result set to @a a ^ @a b
575 GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode * a, const struct GNUNET_HashCode * b,
576 struct GNUNET_HashCode * result);
581 * Convert a hashcode into a key.
583 * @param hc hash code that serves to generate the key
584 * @param skey set to a valid session key
585 * @param iv set to a valid initialization vector
588 GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc,
589 struct GNUNET_CRYPTO_AesSessionKey *skey,
590 struct GNUNET_CRYPTO_AesInitializationVector
596 * Obtain a bit from a hashcode.
598 * @param code the `struct GNUNET_HashCode` to index bit-wise
599 * @param bit index into the hashcode, [0...159]
600 * @return Bit \a bit from hashcode \a code, -1 for invalid index
603 GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
609 * Determine how many low order bits match in two
610 * struct GNUNET_HashCodes. i.e. - 010011 and 011111 share
611 * the first two lowest order bits, and therefore the
612 * return value is two (NOT XOR distance, nor how many
613 * bits match absolutely!).
615 * @param first the first hashcode
616 * @param second the hashcode to compare first to
617 * @return the number of bits that match
620 GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode * first,
621 const struct GNUNET_HashCode * second);
626 * Compare function for HashCodes, producing a total ordering
629 * @param h1 some hash code
630 * @param h2 some hash code
631 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
634 GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode * h1, const struct GNUNET_HashCode * h2);
639 * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
640 * in the XOR metric (Kademlia).
642 * @param h1 some hash code
643 * @param h2 some hash code
644 * @param target some hash code
645 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2.
648 GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode * h1,
649 const struct GNUNET_HashCode * h2,
650 const struct GNUNET_HashCode * target);
655 * @brief Derive an authentication key
656 * @param key authentication key
657 * @param rkey root key
659 * @param salt_len size of the salt
660 * @param argp pair of void * & size_t for context chunks, terminated by NULL
663 GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
664 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
665 const void *salt, size_t salt_len,
671 * @brief Derive an authentication key
672 * @param key authentication key
673 * @param rkey root key
675 * @param salt_len size of the salt
676 * @param ... pair of void * & size_t for context chunks, terminated by NULL
679 GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
680 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
681 const void *salt, size_t salt_len, ...);
687 * @param result buffer for the derived key, allocated by caller
688 * @param out_len desired length of the derived key
689 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
690 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
692 * @param xts_len length of xts
693 * @param skm source key material
694 * @param skm_len length of skm
695 * @param ... pair of void * & size_t for context chunks, terminated by NULL
696 * @return GNUNET_YES on success
699 GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
700 const void *xts, size_t xts_len, const void *skm,
701 size_t skm_len, ...);
707 * @param result buffer for the derived key, allocated by caller
708 * @param out_len desired length of the derived key
709 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
710 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
712 * @param xts_len length of xts
713 * @param skm source key material
714 * @param skm_len length of skm
715 * @param argp va_list of void * & size_t pairs for context chunks
716 * @return GNUNET_YES on success
719 GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
720 const void *xts, size_t xts_len, const void *skm,
721 size_t skm_len, va_list argp);
726 * @param result buffer for the derived key, allocated by caller
727 * @param out_len desired length of the derived key
729 * @param xts_len length of xts
730 * @param skm source key material
731 * @param skm_len length of skm
732 * @param argp va_list of void * & size_t pairs for context chunks
733 * @return GNUNET_YES on success
736 GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
737 size_t xts_len, const void *skm, size_t skm_len,
744 * @param result buffer for the derived key, allocated by caller
745 * @param out_len desired length of the derived key
747 * @param xts_len length of xts
748 * @param skm source key material
749 * @param skm_len length of skm
750 * @param ... void * & size_t pairs for context chunks
751 * @return #GNUNET_YES on success
754 GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
755 size_t xts_len, const void *skm, size_t skm_len, ...);
759 * Function called upon completion of 'GNUNET_CRYPTO_ecc_key_create_async'.
762 * @param pk NULL on error, otherwise the private key (which must be free'd by the callee)
763 * @param emsg NULL on success, otherwise an error message
765 typedef void (*GNUNET_CRYPTO_EccKeyCallback)(void *cls,
766 struct GNUNET_CRYPTO_EccPrivateKey *pk,
772 * Extract the public key for the given private key.
774 * @param priv the private key
775 * @param pub where to write the public key
778 GNUNET_CRYPTO_ecc_key_get_public_for_signature (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
779 struct GNUNET_CRYPTO_EccPublicSignKey *pub);
785 * Extract the public key for the given private key.
787 * @param priv the private key
788 * @param pub where to write the public key
791 GNUNET_CRYPTO_ecc_key_get_public_for_encryption (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
792 struct GNUNET_CRYPTO_EccPublicEncryptKey *pub);
796 * Convert a public key to a string.
798 * @param pub key to convert
799 * @return string representing @a pub
802 GNUNET_CRYPTO_ecc_public_sign_key_to_string (const struct GNUNET_CRYPTO_EccPublicSignKey *pub);
806 * Convert a string representing a public key to a public key.
808 * @param enc encoded public key
809 * @param enclen number of bytes in @a enc (without 0-terminator)
810 * @param pub where to store the public key
811 * @return #GNUNET_OK on success
814 GNUNET_CRYPTO_ecc_public_sign_key_from_string (const char *enc,
816 struct GNUNET_CRYPTO_EccPublicSignKey *pub);
821 * Convert a public key to a string.
823 * @param pub key to convert
824 * @return string representing @a pub
827 GNUNET_CRYPTO_ecc_public_encrypt_key_to_string (const struct GNUNET_CRYPTO_EccPublicEncryptKey *pub);
831 * Convert a string representing a public key to a public key.
833 * @param enc encoded public key
834 * @param enclen number of bytes in @a enc (without 0-terminator)
835 * @param pub where to store the public key
836 * @return #GNUNET_OK on success
839 GNUNET_CRYPTO_ecc_public_encrypt_key_from_string (const char *enc,
841 struct GNUNET_CRYPTO_EccPublicEncryptKey *pub);
846 * Create a new private key by reading it from a file. If the
847 * files does not exist, create a new key and write it to the
848 * file. Caller must free return value. Note that this function
849 * can not guarantee that another process might not be trying
850 * the same operation on the same file at the same time.
851 * If the contents of the file
852 * are invalid the old file is deleted and a fresh key is
855 * @param filename name of file to use to store the key
856 * @return new private key, NULL on error (for example,
857 * permission denied); free using #GNUNET_free
859 struct GNUNET_CRYPTO_EccPrivateKey *
860 GNUNET_CRYPTO_ecc_key_create_from_file (const char *filename);
865 * Create a new private key by reading our peer's key from
866 * the file specified in the configuration.
868 * @param cfg the configuration to use
869 * @return new private key, NULL on error (for example,
870 * permission denied); free using #GNUNET_free
872 struct GNUNET_CRYPTO_EccPrivateKey *
873 GNUNET_CRYPTO_ecc_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg);
878 * Create a new private key. Caller must free return value.
880 * @return fresh private key; free using #GNUNET_free
882 struct GNUNET_CRYPTO_EccPrivateKey *
883 GNUNET_CRYPTO_ecc_key_create (void);
888 * Clear memory that was used to store a private key.
890 * @param pk location of the key
893 GNUNET_CRYPTO_ecc_key_clear (struct GNUNET_CRYPTO_EccPrivateKey *pk);
898 * Get the shared private key we use for anonymous users.
900 * @return "anonymous" private key; do not free
902 const struct GNUNET_CRYPTO_EccPrivateKey *
903 GNUNET_CRYPTO_ecc_key_get_anonymous (void);
908 * Setup a hostkey file for a peer given the name of the
909 * configuration file (!). This function is used so that
910 * at a later point code can be certain that reading a
911 * hostkey is fast (for example in time-dependent testcases).
913 * @param cfg_name name of the configuration file to use
916 GNUNET_CRYPTO_ecc_setup_hostkey (const char *cfg_name);
921 * Retrieve the identity of the host's peer.
923 * @param cfg configuration to use
924 * @param dst pointer to where to write the peer identity
925 * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
926 * could not be retrieved
929 GNUNET_CRYPTO_get_host_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
930 struct GNUNET_PeerIdentity *dst);
935 * Derive key material from a public and a private ECC key.
937 * @param priv private key to use for the ECDH (x)
938 * @param pub public key to use for the ECDY (yG)
939 * @param key_material where to write the key material (xyG)
940 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
943 GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
944 const struct GNUNET_CRYPTO_EccPublicEncryptKey *pub,
945 struct GNUNET_HashCode *key_material);
950 * Sign a given block.
952 * @param priv private key to use for the signing
953 * @param purpose what to sign (size, purpose)
954 * @param sig where to write the signature
955 * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
958 GNUNET_CRYPTO_ecc_sign (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
959 const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
960 struct GNUNET_CRYPTO_EccSignature *sig);
967 * @param purpose what is the purpose that the signature should have?
968 * @param validate block to validate (size, purpose, data)
969 * @param sig signature that is being validated
970 * @param pub public key of the signer
971 * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
974 GNUNET_CRYPTO_ecc_verify (uint32_t purpose,
975 const struct GNUNET_CRYPTO_EccSignaturePurpose
977 const struct GNUNET_CRYPTO_EccSignature *sig,
978 const struct GNUNET_CRYPTO_EccPublicSignKey *pub);
983 * Derive a private key from a given private key and a label.
984 * Essentially calculates a private key 'h = H(l,P) * d mod n'
985 * where n is the size of the ECC group and P is the public
986 * key associated with the private key 'd'.
988 * @param priv original private key
989 * @param label label to use for key deriviation
990 * @param context additional context to use for HKDF of 'h';
991 * typically the name of the subsystem/application
992 * @return derived private key
994 struct GNUNET_CRYPTO_EccPrivateKey *
995 GNUNET_CRYPTO_ecc_key_derive (const struct GNUNET_CRYPTO_EccPrivateKey *priv,
997 const char *context);
1002 * Derive a public key from a given public key and a label.
1003 * Essentially calculates a public key 'V = H(l,P) * P'.
1005 * @param pub original public key
1006 * @param label label to use for key deriviation
1007 * @param context additional context to use for HKDF of 'h'.
1008 * typically the name of the subsystem/application
1009 * @param result where to write the derived public key
1012 GNUNET_CRYPTO_ecc_public_key_derive (const struct GNUNET_CRYPTO_EccPublicSignKey *pub,
1014 const char *context,
1015 struct GNUNET_CRYPTO_EccPublicSignKey *result);
1018 #if 0 /* keep Emacsens' auto-indent happy */
1026 /* ifndef GNUNET_CRYPTO_LIB_H */
1028 /* end of gnunet_crypto_lib.h */