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);
350 * Check that a new session key is well-formed.
352 * @param key key to check
353 * @return GNUNET_OK if the key is valid
356 GNUNET_CRYPTO_aes_check_session_key (const struct GNUNET_CRYPTO_AesSessionKey
361 * Encrypt a block with the public key of another
362 * host that uses the same cyper.
364 * @param block the block to encrypt
365 * @param len the size of the block
366 * @param sessionkey the key used to encrypt
367 * @param iv the initialization vector to use, use INITVALUE
369 * @return the size of the encrypted block, -1 for errors
372 GNUNET_CRYPTO_aes_encrypt (const void *block, size_t len,
373 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
374 const struct GNUNET_CRYPTO_AesInitializationVector
379 * Decrypt a given block with the sessionkey.
381 * @param block the data to decrypt, encoded as returned by encrypt
382 * @param size how big is the block?
383 * @param sessionkey the key used to decrypt
384 * @param iv the initialization vector to use
385 * @param result address to store the result at
386 * @return -1 on failure, size of decrypted block on success
389 GNUNET_CRYPTO_aes_decrypt (const void *block, size_t size,
390 const struct GNUNET_CRYPTO_AesSessionKey *sessionkey,
391 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);
424 * Convert hash to ASCII encoding.
425 * @param block the hash code
426 * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be
427 * safely cast to char*, a '\\0' termination is set).
430 GNUNET_CRYPTO_hash_to_enc (const GNUNET_HashCode * block,
431 struct GNUNET_CRYPTO_HashAsciiEncoded *result);
435 * Convert ASCII encoding back to GNUNET_CRYPTO_hash
437 * @param enc the encoding
438 * @param enclen number of characters in 'enc' (without 0-terminator, which can be missing)
439 * @param result where to store the GNUNET_CRYPTO_hash code
440 * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
443 GNUNET_CRYPTO_hash_from_string2 (const char *enc, size_t enclen,
444 GNUNET_HashCode * result);
448 * Convert ASCII encoding back to GNUNET_CRYPTO_hash
449 * @param enc the encoding
450 * @param result where to store the GNUNET_CRYPTO_hash code
451 * @return GNUNET_OK on success, GNUNET_SYSERR if result has the wrong encoding
453 #define GNUNET_CRYPTO_hash_from_string(enc, result) \
454 GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result)
458 * Compute the distance between 2 hashcodes.
459 * The computation must be fast, not involve
460 * a.a or a.e (they're used elsewhere), and
461 * be somewhat consistent. And of course, the
462 * result should be a positive number.
464 * @param a some hash code
465 * @param b some hash code
466 * @return number between 0 and UINT32_MAX
469 GNUNET_CRYPTO_hash_distance_u32 (const GNUNET_HashCode * a,
470 const GNUNET_HashCode * b);
474 * Compute hash of a given block.
476 * @param block the data to hash
477 * @param size size of the block
478 * @param ret pointer to where to write the hashcode
481 GNUNET_CRYPTO_hash (const void *block, size_t size, GNUNET_HashCode * ret);
485 * Calculate HMAC of a message (RFC 2104)
487 * @param key secret key
488 * @param plaintext input plaintext
489 * @param plaintext_len length of plaintext
490 * @param hmac where to store the hmac
493 GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
494 const void *plaintext, size_t plaintext_len,
495 GNUNET_HashCode * hmac);
499 * Function called once the hash computation over the
500 * specified file has completed.
503 * @param res resulting hash, NULL on error
505 typedef void (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
506 const GNUNET_HashCode *
511 * Handle to file hashing operation.
513 struct GNUNET_CRYPTO_FileHashContext;
516 * Compute the hash of an entire file.
518 * @param priority scheduling priority to use
519 * @param filename name of file to hash
520 * @param blocksize number of bytes to process in one task
521 * @param callback function to call upon completion
522 * @param callback_cls closure for callback
523 * @return NULL on (immediate) errror
525 struct GNUNET_CRYPTO_FileHashContext *
526 GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
527 const char *filename, size_t blocksize,
528 GNUNET_CRYPTO_HashCompletedCallback callback,
533 * Cancel a file hashing operation.
535 * @param fhc operation to cancel (callback must not yet have been invoked)
538 GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
542 * Create a random hash code.
544 * @param mode desired quality level
545 * @param result hash code that is randomized
548 GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
549 GNUNET_HashCode * result);
553 * compute result(delta) = b - a
555 * @param a some hash code
556 * @param b some hash code
557 * @param result set to b - a
560 GNUNET_CRYPTO_hash_difference (const GNUNET_HashCode * a,
561 const GNUNET_HashCode * b,
562 GNUNET_HashCode * result);
566 * compute result(b) = a + delta
568 * @param a some hash code
569 * @param delta some hash code
570 * @param result set to a + delta
573 GNUNET_CRYPTO_hash_sum (const GNUNET_HashCode * a,
574 const GNUNET_HashCode * delta,
575 GNUNET_HashCode * result);
579 * compute result = a ^ b
581 * @param a some hash code
582 * @param b some hash code
583 * @param result set to a ^ b
586 GNUNET_CRYPTO_hash_xor (const GNUNET_HashCode * a, const GNUNET_HashCode * b,
587 GNUNET_HashCode * result);
591 * Convert a hashcode into a key.
593 * @param hc hash code that serves to generate the key
594 * @param skey set to a valid session key
595 * @param iv set to a valid initialization vector
598 GNUNET_CRYPTO_hash_to_aes_key (const GNUNET_HashCode * hc,
599 struct GNUNET_CRYPTO_AesSessionKey *skey,
600 struct GNUNET_CRYPTO_AesInitializationVector
605 * Obtain a bit from a hashcode.
607 * @param code the GNUNET_CRYPTO_hash to index bit-wise
608 * @param bit index into the hashcode, [0...159]
609 * @return Bit \a bit from hashcode \a code, -1 for invalid index
612 GNUNET_CRYPTO_hash_get_bit (const GNUNET_HashCode * code, unsigned int bit);
615 * Determine how many low order bits match in two
616 * GNUNET_HashCodes. i.e. - 010011 and 011111 share
617 * the first two lowest order bits, and therefore the
618 * return value is two (NOT XOR distance, nor how many
619 * bits match absolutely!).
621 * @param first the first hashcode
622 * @param second the hashcode to compare first to
624 * @return the number of bits that match
627 GNUNET_CRYPTO_hash_matching_bits (const GNUNET_HashCode * first,
628 const GNUNET_HashCode * second);
632 * Compare function for HashCodes, producing a total ordering
635 * @param h1 some hash code
636 * @param h2 some hash code
637 * @return 1 if h1 > h2, -1 if h1 < h2 and 0 if h1 == h2.
640 GNUNET_CRYPTO_hash_cmp (const GNUNET_HashCode * h1, const GNUNET_HashCode * h2);
644 * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
645 * in the XOR metric (Kademlia).
647 * @param h1 some hash code
648 * @param h2 some hash code
649 * @param target some hash code
650 * @return -1 if h1 is closer, 1 if h2 is closer and 0 if h1==h2.
653 GNUNET_CRYPTO_hash_xorcmp (const GNUNET_HashCode * h1,
654 const GNUNET_HashCode * h2,
655 const GNUNET_HashCode * target);
659 * @brief Derive an authentication key
660 * @param key authentication key
661 * @param rkey root key
663 * @param salt_len size of the salt
664 * @param argp pair of void * & size_t for context chunks, terminated by NULL
667 GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
668 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
669 const void *salt, size_t salt_len,
674 * @brief Derive an authentication key
675 * @param key authentication key
676 * @param rkey root key
678 * @param salt_len size of the salt
679 * @param ... pair of void * & size_t for context chunks, terminated by NULL
682 GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
683 const struct GNUNET_CRYPTO_AesSessionKey *rkey,
684 const void *salt, size_t salt_len, ...);
688 * @param result buffer for the derived key, allocated by caller
689 * @param out_len desired length of the derived key
690 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
691 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
693 * @param xts_len length of xts
694 * @param skm source key material
695 * @param skm_len length of skm
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, ...);
706 * @param result buffer for the derived key, allocated by caller
707 * @param out_len desired length of the derived key
708 * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
709 * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
711 * @param xts_len length of xts
712 * @param skm source key material
713 * @param skm_len length of skm
714 * @param argp va_list of void * & size_t pairs for context chunks
715 * @return GNUNET_YES on success
718 GNUNET_CRYPTO_hkdf_v (void *result, size_t out_len, int xtr_algo, int prf_algo,
719 const void *xts, size_t xts_len, const void *skm,
720 size_t skm_len, va_list argp);
725 * @param result buffer for the derived key, allocated by caller
726 * @param out_len desired length of the derived key
728 * @param xts_len length of xts
729 * @param skm source key material
730 * @param skm_len length of skm
731 * @param argp va_list of void * & size_t pairs for context chunks
732 * @return GNUNET_YES on success
735 GNUNET_CRYPTO_kdf_v (void *result, size_t out_len, const void *xts,
736 size_t xts_len, const void *skm, size_t skm_len,
742 * @param result buffer for the derived key, allocated by caller
743 * @param out_len desired length of the derived key
745 * @param xts_len length of xts
746 * @param skm source key material
747 * @param skm_len length of skm
748 * @param ... void * & size_t pairs for context chunks
749 * @return GNUNET_YES on success
752 GNUNET_CRYPTO_kdf (void *result, size_t out_len, const void *xts,
753 size_t xts_len, const void *skm, size_t skm_len, ...);
757 * Create a new private key. Caller must free return value.
759 * @return fresh private key
761 struct GNUNET_CRYPTO_RsaPrivateKey *
762 GNUNET_CRYPTO_rsa_key_create (void);
766 * Convert a public key to a string.
768 * @param pub key to convert
769 * @return string representing 'pub'
772 GNUNET_CRYPTO_rsa_public_key_to_string (struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub);
776 * Convert a string representing a public key to a public key.
778 * @param enc encoded public key
779 * @param enclen number of bytes in enc (without 0-terminator)
780 * @param pub where to store the public key
781 * @return GNUNET_OK on success
784 GNUNET_CRYPTO_rsa_public_key_from_string (const char *enc,
786 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded *pub);
790 * Encode the private key in a format suitable for
791 * storing it into a file.
792 * @returns encoding of the private key.
793 * The first 4 bytes give the size of the array, as usual.
795 struct GNUNET_CRYPTO_RsaPrivateKeyBinaryEncoded *
796 GNUNET_CRYPTO_rsa_encode_key (const struct GNUNET_CRYPTO_RsaPrivateKey *hostkey);
799 * Decode the private key from the data-format back
800 * to the "normal", internal format.
802 * @param buf the buffer where the private key data is stored
803 * @param len the length of the data in 'buffer'
805 struct GNUNET_CRYPTO_RsaPrivateKey *
806 GNUNET_CRYPTO_rsa_decode_key (const char *buf, uint16_t len);
809 * Create a new private key by reading it from a file. If the
810 * files does not exist, create a new key and write it to the
811 * file. Caller must free return value. Note that this function
812 * can not guarantee that another process might not be trying
813 * the same operation on the same file at the same time.
814 * If the contents of the file
815 * are invalid the old file is deleted and a fresh key is
818 * @param filename name of file to use for storage
819 * @return new private key, NULL on error (for example,
822 struct GNUNET_CRYPTO_RsaPrivateKey *
823 GNUNET_CRYPTO_rsa_key_create_from_file (const char *filename);
827 * Setup a hostkey file for a peer given the name of the
828 * configuration file (!). This function is used so that
829 * at a later point code can be certain that reading a
830 * hostkey is fast (for example in time-dependent testcases).
832 * @param cfg_name name of the configuration file to use
835 GNUNET_CRYPTO_setup_hostkey (const char *cfg_name);
839 * Deterministically (!) create a private key using only the
840 * given HashCode as input to the PRNG.
842 * @param hc "random" input to PRNG
843 * @return some private key purely dependent on input
845 struct GNUNET_CRYPTO_RsaPrivateKey *
846 GNUNET_CRYPTO_rsa_key_create_from_hash (const GNUNET_HashCode * hc);
850 * Free memory occupied by the private key.
851 * @param hostkey pointer to the memory to free
854 GNUNET_CRYPTO_rsa_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *hostkey);
858 * Extract the public key of the host.
860 * @param priv the private key
861 * @param pub where to write the public key
864 GNUNET_CRYPTO_rsa_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey
866 struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
871 * Encrypt a block with the public key of another host that uses the
874 * @param block the block to encrypt
875 * @param size the size of block
876 * @param publicKey the encoded public key used to encrypt
877 * @param target where to store the encrypted block
878 * @return GNUNET_SYSERR on error, GNUNET_OK if ok
881 GNUNET_CRYPTO_rsa_encrypt (const void *block, size_t size,
882 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
884 struct GNUNET_CRYPTO_RsaEncryptedData *target);
888 * Decrypt a given block with the hostkey.
890 * @param key the key to use
891 * @param block the data to decrypt, encoded as returned by encrypt, not consumed
892 * @param result pointer to a location where the result can be stored
893 * @param max how many bytes of a result are expected? Must be exact.
894 * @return the size of the decrypted block (that is, size) or -1 on error
897 GNUNET_CRYPTO_rsa_decrypt (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
898 const struct GNUNET_CRYPTO_RsaEncryptedData *block,
899 void *result, size_t max);
903 * Sign a given block.
905 * @param key private key to use for the signing
906 * @param purpose what to sign (size, purpose)
907 * @param sig where to write the signature
908 * @return GNUNET_SYSERR on error, GNUNET_OK on success
911 GNUNET_CRYPTO_rsa_sign (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
912 const struct GNUNET_CRYPTO_RsaSignaturePurpose *purpose,
913 struct GNUNET_CRYPTO_RsaSignature *sig);
917 * Verify signature. Note that the caller MUST have already
918 * checked that "validate->size" bytes are actually available.
920 * @param purpose what is the purpose that validate should have?
921 * @param validate block to validate (size, purpose, data)
922 * @param sig signature that is being validated
923 * @param publicKey public key of the signer
924 * @return GNUNET_OK if ok, GNUNET_SYSERR if invalid
927 GNUNET_CRYPTO_rsa_verify (uint32_t purpose,
928 const struct GNUNET_CRYPTO_RsaSignaturePurpose
930 const struct GNUNET_CRYPTO_RsaSignature *sig,
931 const struct GNUNET_CRYPTO_RsaPublicKeyBinaryEncoded
937 * This function should only be called in testcases
938 * where strong entropy gathering is not desired
939 * (for example, for hostkey generation).
942 GNUNET_CRYPTO_random_disable_entropy_gathering (void);
945 #if 0 /* keep Emacsens' auto-indent happy */
953 /* ifndef GNUNET_CRYPTO_LIB_H */
955 /* end of gnunet_crypto_lib.h */