2 This file is part of GNUnet.
3 (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 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 2, 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
32 #ifndef GNUNET_CRYPTO_LIB_H
33 #define GNUNET_CRYPTO_LIB_H
38 #if 0 /* keep Emacsens' auto-indent happy */
43 #include "gnunet_common.h"
44 #include "gnunet_scheduler_lib.h"
47 * Desired quality level for cryptographic operations.
49 enum GNUNET_CRYPTO_Quality
52 * No good quality of the operation is needed (i.e.,
53 * random numbers can be pseudo-random).
55 GNUNET_CRYPTO_QUALITY_WEAK,
58 * High-quality operations are desired.
60 GNUNET_CRYPTO_QUALITY_STRONG,
63 * Randomness for IVs etc. is required.
65 GNUNET_CRYPTO_QUALITY_NONCE
70 * @brief length of the sessionkey in bytes (256 BIT sessionkey)
72 #define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8)
76 * @brief Length of RSA encrypted data (2048 bit)
78 * We currently do not handle encryption of data
79 * that can not be done in a single call to the
80 * RSA methods (read: large chunks of data).
81 * We should never need that, as we can use
82 * the GNUNET_CRYPTO_hash for larger pieces of data for signing,
83 * and for encryption, we only need to encode sessionkeys!
85 #define GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH 256
89 * Length of an RSA KEY (n,e,len), 2048 bit (=256 octests) key n, 2 byte e
91 #define GNUNET_CRYPTO_RSA_KEY_LENGTH 258
95 * Length of a hash value
97 #define GNUNET_CRYPTO_HASH_LENGTH 512/8
100 * The private information of an RSA key pair.
102 struct GNUNET_CRYPTO_RsaPrivateKey;
104 GNUNET_NETWORK_STRUCT_BEGIN
107 * GNUnet mandates a certain format for the encoding
108 * of private RSA key information that is provided
109 * by the RSA implementations. This format is used
110 * to serialize a private RSA key (typically when
111 * writing it to disk).
113 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded
116 * Total size of the structure, in bytes, in big-endian!
118 uint16_t len GNUNET_PACKED;
119 uint16_t sizen GNUNET_PACKED; /* in big-endian! */
120 uint16_t sizee GNUNET_PACKED; /* in big-endian! */
121 uint16_t sized GNUNET_PACKED; /* in big-endian! */
122 uint16_t sizep GNUNET_PACKED; /* in big-endian! */
123 uint16_t sizeq GNUNET_PACKED; /* in big-endian! */
124 uint16_t sizedmp1 GNUNET_PACKED; /* in big-endian! */
125 uint16_t sizedmq1 GNUNET_PACKED; /* in big-endian! */
126 /* followed by the actual values */
128 GNUNET_NETWORK_STRUCT_END
132 * @brief 0-terminated ASCII encoding of a GNUNET_HashCode.
134 struct GNUNET_CRYPTO_HashAsciiEncoded
136 unsigned char encoding[104];
142 * @brief an RSA signature
144 struct GNUNET_CRYPTO_RsaSignature
146 unsigned char sig[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH];
150 GNUNET_NETWORK_STRUCT_BEGIN
153 * @brief header of what an RSA signature signs
154 * this must be followed by "size - 8" bytes of
155 * the actual signed data
157 struct GNUNET_CRYPTO_RsaSignaturePurpose
160 * How many bytes does this signature sign?
161 * (including this purpose header); in network
164 uint32_t size GNUNET_PACKED;
167 * What does this signature vouch for? This
168 * must contain a GNUNET_SIGNATURE_PURPOSE_XXX
169 * constant (from gnunet_signatures.h). In
170 * network byte order!
172 uint32_t purpose GNUNET_PACKED;
178 * @brief A public key.
180 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
183 * In big-endian, must be GNUNET_CRYPTO_RSA_KEY_LENGTH+4
185 uint16_t len GNUNET_PACKED;
188 * Size of n in key; in big-endian!
190 uint16_t sizen GNUNET_PACKED;
193 * The key itself, contains n followed by e.
195 unsigned char key[GNUNET_CRYPTO_RSA_KEY_LENGTH];
198 * Padding (must be 0)
200 uint16_t padding GNUNET_PACKED;
205 * RSA Encrypted data.
207 struct GNUNET_CRYPTO_RsaEncryptedData
209 unsigned char encoding[GNUNET_CRYPTO_RSA_DATA_ENCODING_LENGTH];
214 * @brief type for session keys
216 struct GNUNET_CRYPTO_AesSessionKey
221 unsigned char key[GNUNET_CRYPTO_AES_KEY_LENGTH];
226 uint32_t crc32 GNUNET_PACKED;
228 GNUNET_NETWORK_STRUCT_END
231 * @brief IV for sym cipher
233 * NOTE: must be smaller (!) in size than the
236 struct GNUNET_CRYPTO_AesInitializationVector
238 unsigned char 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 ************* */
254 * Seed a weak random generator. Only GNUNET_CRYPTO_QUALITY_WEAK-mode generator
257 * @param seed the seed to use
260 GNUNET_CRYPTO_seed_weak_random (int32_t seed);
264 * Perform an incremental step in a CRC16 (for TCP/IP) calculation.
266 * @param sum current sum, initially 0
267 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
268 * @param len number of bytes in hdr, must be multiple of 2
269 * @return updated crc sum (must be subjected to GNUNET_CRYPTO_crc16_finish to get actual crc16)
272 GNUNET_CRYPTO_crc16_step (uint32_t sum, const void *buf, size_t len);
276 * Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
278 * @param sum cummulative sum
279 * @return crc16 value
282 GNUNET_CRYPTO_crc16_finish (uint32_t sum);
286 * Calculate the checksum of a buffer in one step.
288 * @param buf buffer to calculate CRC over (must be 16-bit aligned)
289 * @param len number of bytes in hdr, must be multiple of 2
290 * @return crc16 value
293 GNUNET_CRYPTO_crc16_n (const void *buf, size_t len);
297 * Compute the CRC32 checksum for the first len
298 * bytes of the buffer.
300 * @param buf the data over which we're taking the CRC
301 * @param len the length of the buffer in bytes
302 * @return the resulting CRC32 checksum
305 GNUNET_CRYPTO_crc32_n (const void *buf, size_t len);
309 * Produce a random value.
311 * @param mode desired quality of the random number
312 * @param i the upper limit (exclusive) for the random number
313 * @return a random value in the interval [0,i) (exclusive).
316 GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode, uint32_t i);
320 * Random on unsigned 64-bit values.
322 * @param mode desired quality of the random number
323 * @param max value returned will be in range [0,max) (exclusive)
324 * @return random 64-bit number
327 GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode, uint64_t max);
331 * Get an array with a random permutation of the
333 * @param mode GNUNET_CRYPTO_QUALITY_STRONG if the strong (but expensive) PRNG should be used, GNUNET_CRYPTO_QUALITY_WEAK otherwise
334 * @param n the size of the array
335 * @return the permutation array (allocated from heap)
338 GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode, unsigned int n);
342 * Create a new Session key.
344 * @param key key to initialize
347 GNUNET_CRYPTO_aes_create_session_key (struct GNUNET_CRYPTO_AesSessionKey *key);
351 * Check that a new session key is well-formed.
353 * @param key key to check
354 * @return GNUNET_OK if the key is valid
357 GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
362 * Encrypt a block with the public key of another
363 * host that uses the same cyper.
365 * @param block the block to encrypt
366 * @param len the size of the block
367 * @param sessionkey the key used to encrypt
368 * @param iv the initialization vector to use, use INITVALUE
370 * @return the size of the encrypted block, -1 for errors
373 GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
374 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
375 const struct GNUNET_CRYPTO_AesInitializationVector
380 * Decrypt a given block with the sessionkey.
382 * @param block the data to decrypt, encoded as returned by encrypt
383 * @param size how big is the block?
384 * @param sessionkey the key used to decrypt
385 * @param iv the initialization vector to use
386 * @param result address to store the result at
387 * @return -1 on failure, size of decrypted block on success
390 GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
391 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
392 const struct GNUNET_CRYPTO_AesInitializationVector
397 * @brief Derive an IV
398 * @param iv initialization vector
399 * @param skey session key
400 * @param salt salt for the derivation
401 * @param salt_len size of the salt
402 * @param ... pairs of void * & size_t for context chunks, terminated by NULL
405 GNUNET_CRYPTO_aes_derive_iv (struct GNUNET_CRYPTO_AesInitializationVector *iv,
406 const struct GNUNET_CRYPTO_AesSessionKey *skey,
407 const void *salt, size_t salt_len, ...);
411 * @brief Derive an IV
412 * @param iv initialization vector
413 * @param skey session key
414 * @param salt salt for the derivation
415 * @param salt_len size of the salt
416 * @param argp pairs of void * & size_t for context chunks, terminated by NULL
419 GNUNET_CRYPTO_aes_derive_iv_v (struct GNUNET_CRYPTO_AesInitializationVector *iv,
420 const struct GNUNET_CRYPTO_AesSessionKey *skey,
421 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 GNUNET_HashCode * block,
432 struct GNUNET_CRYPTO_HashAsciiEncoded *result);
436 * Convert ASCII encoding back to GNUNET_CRYPTO_hash
438 * @param enc the encoding
439 * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing)
440 * @param result where to store the GNUNET_CRYPTO_hash code
441 * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
444 GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
445 GNUNET_HashCode * result);
449 * Convert ASCII encoding back to GNUNET_CRYPTO_hash
450 * @param enc the encoding
451 * @param result where to store the GNUNET_CRYPTO_hash code
452 * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
454 #define GNUNET_CRYPTO_hash_from_string(enc, result) \
455 GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result)
459 * Compute the distance between 2 hashcodes.
460 * The computation must be fast, not involve
461 * a.a or a.e (they're used elsewhere), and
462 * be somewhat consistent. And of course, the
463 * result should be a positive number.
465 * @param a some hash code
466 * @param b some hash code
467 * @return number between 0 and UINT32_MAX
470 GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
471 const GNUNET_HashCode * b);
475 * Compute hash of a given block.
477 * @param block the data to hash
478 * @param size size of the block
479 * @param ret pointer to where to write the hashcode
482 GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret);
486 * Calculate HMAC of a message (RFC 2104)
488 * @param key secret key
489 * @param plaintext input plaintext
490 * @param plaintext_len length of plaintext
491 * @param hmac where to store the hmac
494 GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
495 const void *plaintext, size_t plaintext_len,
496 GNUNET_HashCode * hmac);
500 * Function called once the hash computation over the
501 * specified file has completed.
504 * @param res resulting hash, NULL on error
506 typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
507 const GNUNET_HashCode *
512 * Handle to file hashing operation.
514 struct GNUNET_CRYPTO_FileHashContext;
517 * Compute the hash of an entire file.
519 * @param priority scheduling priority to use
520 * @param filename name of file to hash
521 * @param blocksize number of bytes to process in one task
522 * @param callback function to call upon completion
523 * @param callback_cls closure for callback
524 * @return NULL on (immediate) errror
526 struct GNUNET_CRYPTO_FileHashContext *
527 GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
528 const char *filename, size_t blocksize,
529 GNUNET_CRYPTO_HashCompletedCallback callback,
534 * Cancel a file hashing operation.
536 * @param fhc operation to cancel (callback must not yet have been invoked)
539 GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
543 * Create a random hash code.
545 * @param mode desired quality level
546 * @param result hash code that is randomized
549 GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
550 GNUNET_HashCode * result);
554 * compute result(delta) = b - a
556 * @param a some hash code
557 * @param b some hash code
558 * @param result set to b - a
561 GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
562 const GNUNET_HashCode * b,
563 GNUNET_HashCode * result);
567 * compute result(b) = a + delta
569 * @param a some hash code
570 * @param delta some hash code
571 * @param result set to a + delta
574 GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
575 const GNUNET_HashCode * delta,
576 GNUNET_HashCode * result);
580 * compute result = a ^ b
582 * @param a some hash code
583 * @param b some hash code
584 * @param result set to a ^ b
587 GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
588 GNUNET_HashCode * result);
592 * Convert a hashcode into a key.
594 * @param hc hash code that serves to generate the key
595 * @param skey set to a valid session key
596 * @param iv set to a valid initialization vector
599 GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
600 struct GNUNET_CRYPTO_AesSessionKey *skey,
601 struct GNUNET_CRYPTO_AesInitializationVector
606 * Obtain a bit from a hashcode.
608 * @param code the GNUNET_CRYPTO_hash to index bit-wise
609 * @param bit index into the hashcode, [0...159]
610 * @return Bit \a bit from hashcode \a code, -1 for invalid index
613 GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit);
616 * Determine how many low order bits match in two
617 * GNUNET_HashCodes. i.e. - 010011 and 011111 share
618 * the first two lowest order bits, and therefore the
619 * return value is two (NOT XOR distance, nor how many
620 * bits match absolutely!).
622 * @param first the first hashcode
623 * @param second the hashcode to compare first to
625 * @return the number of bits that match
628 GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
629 const GNUNET_HashCode * second);
633 * Compare function for HashCodes, producing a total ordering
636 * @param h1 some hash code
637 * @param h2 some hash code
638 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
641 GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2);
645 * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
646 * in the XOR metric (Kademlia).
648 * @param h1 some hash code
649 * @param h2 some hash code
650 * @param target some hash code
651 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2.
654 GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
655 const GNUNET_HashCode * h2,
656 const GNUNET_HashCode * target);
660 * @brief Derive an authentication key
661 * @param key authentication key
662 * @param rkey root key
664 * @param salt_len size of the salt
665 * @param argp pair of void * & size_t for context chunks, terminated by NULL
668 GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
669 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
670 const void *salt, size_t salt_len,
675 * @brief Derive an authentication key
676 * @param key authentication key
677 * @param rkey root key
679 * @param salt_len size of the salt
680 * @param ... pair of void * & size_t for context chunks, terminated by NULL
683 GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
684 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
685 const void *salt, size_t salt_len, ...);
689 * @param result buffer for the derived key, allocated by caller
690 * @param out_len desired length of the derived key
691 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
692 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
694 * @param xts_len length of xts
695 * @param skm source key material
696 * @param skm_len length of skm
697 * @return GNUNET_YES on success
700 GNUNET_CRYPTO_hkdf (void *result, size_t out_len, int xtr_algo, int prf_algo,
701 const void *xts, size_t xts_len, const void *skm,
702 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,
743 * @param result buffer for the derived key, allocated by caller
744 * @param out_len desired length of the derived key
746 * @param xts_len length of xts
747 * @param skm source key material
748 * @param skm_len length of skm
749 * @param ... void * & size_t pairs for context chunks
750 * @return GNUNET_YES on success
753 GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
754 size_t xts_len, const void *skm, size_t skm_len, ...);
758 * Create a new private key. Caller must free return value.
760 * @return fresh private key
762 struct GNUNET_CRYPTO_RsaPrivateKey *
763 GNUNET_CRYPTO_rsa_key_create (void);
767 * Convert a public key to a string.
769 * @param pub key to convert
770 * @return string representing 'pub'
773 GNUNET_CRYPTO_rsa_public_key_to_string (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub);
777 * Convert a string representing a public key to a public key.
779 * @param enc encoded public key
780 * @param enclen number of bytes in enc (without 0-terminator)
781 * @param pub where to store the public key
782 * @return GNUNET_OK on success
785 GNUNET_CRYPTO_rsa_public_key_from_string (const char *enc,
787 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub);
791 * Encode the private key in a format suitable for
792 * storing it into a file.
793 * @returns encoding of the private key.
794 * The first 4 bytes give the size of the array, as usual.
796 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *
797 GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey);
800 * Decode the private key from the data-format back
801 * to the "normal", internal format.
803 * @param buf the buffer where the private key data is stored
804 * @param len the length of the data in 'buffer'
806 struct GNUNET_CRYPTO_RsaPrivateKey *
807 GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len);
810 * Create a new private key by reading it from a file. If the
811 * files does not exist, create a new key and write it to the
812 * file. Caller must free return value. Note that this function
813 * can not guarantee that another process might not be trying
814 * the same operation on the same file at the same time.
815 * If the contents of the file
816 * are invalid the old file is deleted and a fresh key is
819 * @param filename name of file to use for storage
820 * @return new private key, NULL on error (for example,
823 struct GNUNET_CRYPTO_RsaPrivateKey *
824 GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
828 * Setup a hostkey file for a peer given the name of the
829 * configuration file (!). This function is used so that
830 * at a later point code can be certain that reading a
831 * hostkey is fast (for example in time-dependent testcases).
833 * @param cfg_name name of the configuration file to use
836 GNUNET_CRYPTO_setup_hostkey (const char *cfg_name);
840 * Deterministically (!) create a private key using only the
841 * given HashCode as input to the PRNG.
843 * @param hc "random" input to PRNG
844 * @return some private key purely dependent on input
846 struct GNUNET_CRYPTO_RsaPrivateKey *
847 GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc);
851 * Free memory occupied by the private key.
852 * @param hostkey pointer to the memory to free
855 GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey);
859 * Extract the public key of the host.
861 * @param priv the private key
862 * @param pub where to write the public key
865 GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
867 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
872 * Encrypt a block with the public key of another host that uses the
875 * @param block the block to encrypt
876 * @param size the size of block
877 * @param publicKey the encoded public key used to encrypt
878 * @param target where to store the encrypted block
879 * @return GNUNET_SYSERR on error, GNUNET_OK if ok
882 GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
883 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
885 struct GNUNET_CRYPTO_RsaEncryptedData *target);
889 * Decrypt a given block with the hostkey.
891 * @param key the key to use
892 * @param block the data to decrypt, encoded as returned by encrypt, not consumed
893 * @param result pointer to a location where the result can be stored
894 * @param max how many bytes of a result are expected? Must be exact.
895 * @return the size of the decrypted block (that is, size) or -1 on error
898 GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
899 const struct GNUNET_CRYPTO_RsaEncryptedData *block,
900 void *result, size_t max);
904 * Sign a given block.
906 * @param key private key to use for the signing
907 * @param purpose what to sign (size, purpose)
908 * @param sig where to write the signature
909 * @return GNUNET_SYSERR on error, GNUNET_OK on success
912 GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
913 const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose,
914 struct GNUNET_CRYPTO_RsaSignature *sig);
918 * Verify signature. Note that the caller MUST have already
919 * checked that "validate->size" bytes are actually available.
921 * @param purpose what is the purpose that validate should have?
922 * @param validate block to validate (size, purpose, data)
923 * @param sig signature that is being validated
924 * @param publicKey public key of the signer
925 * @return GNUNET_OK if ok, GNUNET_SYSERR if invalid
928 GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
929 const struct GNUNET_CRYPTO_RsaSignaturePurpose
931 const struct GNUNET_CRYPTO_RsaSignature *sig,
932 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
938 * This function should only be called in testcases
939 * where strong entropy gathering is not desired
940 * (for example, for hostkey generation).
943 GNUNET_CRYPTO_random_disable_entropy_gathering (void);
946 #if 0 /* keep Emacsens' auto-indent happy */
954 /* ifndef GNUNET_CRYPTO_LIB_H */
956 /* end of gnunet_crypto_lib.h */