8a591fa09ea3df8a90fb293b407ac29f28515ee5
[oweals/gnunet.git] / src / include / gnunet_crypto_lib.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2001-2013 GNUnet e.V.
4
5      GNUnet is free software: you can redistribute it and/or modify it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your option) any later version.
9
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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file include/gnunet_crypto_lib.h
21  * @brief cryptographic primitives for GNUnet
22  *
23  * @author Christian Grothoff
24  * @author Krista Bennett
25  * @author Gerd Knorr <kraxel@bytesex.org>
26  * @author Ioana Patrascu
27  * @author Tzvetan Horozov
28  * @author Jeffrey Burdges <burdges@gnunet.org>
29  *
30  * @defgroup crypto  Crypto library: cryptographic operations
31  * Provides cryptographic primitives.
32  *
33  * @see [Documentation](https://gnunet.org/crypto-api)
34  *
35  * @defgroup hash  Crypto library: hash operations
36  * Provides hashing and operations on hashes.
37  *
38  * @see [Documentation](https://gnunet.org/crypto-api)
39  */
40
41 #ifndef GNUNET_CRYPTO_LIB_H
42 #define GNUNET_CRYPTO_LIB_H
43
44 #ifdef __cplusplus
45 extern "C"
46 {
47 #if 0                           /* keep Emacsens' auto-indent happy */
48 }
49 #endif
50 #endif
51
52 /**
53  * @brief A 512-bit hashcode.  These are the default length for GNUnet, using SHA-512.
54  */
55 struct GNUNET_HashCode
56 {
57   uint32_t bits[512 / 8 / sizeof (uint32_t)];   /* = 16 */
58 };
59
60
61
62 /**
63  * @brief A 256-bit hashcode.  Used under special conditions, like when space
64  * is critical and security is not impacted by it.
65  */
66 struct GNUNET_ShortHashCode
67 {
68   uint32_t bits[256 / 8 / sizeof (uint32_t)];   /* = 8 */
69 };
70
71
72 /**
73  * The identity of the host (wraps the signing key of the peer).
74  */
75 struct GNUNET_PeerIdentity;
76
77 #include "gnunet_common.h"
78 #include <gcrypt.h>
79
80
81 /**
82  * Maximum length of an ECC signature.
83  * Note: round up to multiple of 8 minus 2 for alignment.
84  */
85 #define GNUNET_CRYPTO_ECC_SIGNATURE_DATA_ENCODING_LENGTH 126
86
87
88 /**
89  * Desired quality level for random numbers.
90  * @ingroup crypto
91  */
92 enum GNUNET_CRYPTO_Quality
93 {
94   /**
95    * No good quality of the operation is needed (i.e.,
96    * random numbers can be pseudo-random).
97    * @ingroup crypto
98    */
99   GNUNET_CRYPTO_QUALITY_WEAK,
100
101   /**
102    * High-quality operations are desired.
103    * @ingroup crypto
104    */
105   GNUNET_CRYPTO_QUALITY_STRONG,
106
107   /**
108    * Randomness for IVs etc. is required.
109    * @ingroup crypto
110    */
111   GNUNET_CRYPTO_QUALITY_NONCE
112 };
113
114
115 /**
116  * @brief length of the sessionkey in bytes (256 BIT sessionkey)
117  */
118 #define GNUNET_CRYPTO_AES_KEY_LENGTH (256/8)
119
120 /**
121  * Length of a hash value
122  */
123 #define GNUNET_CRYPTO_HASH_LENGTH (512/8)
124
125 /**
126  * How many characters (without 0-terminator) are our ASCII-encoded
127  * public keys (ECDSA/EDDSA/ECDHE).
128  */
129 #define GNUNET_CRYPTO_PKEY_ASCII_LENGTH 52
130
131 /**
132  * @brief 0-terminated ASCII encoding of a struct GNUNET_HashCode.
133  */
134 struct GNUNET_CRYPTO_HashAsciiEncoded
135 {
136   unsigned char encoding[104];
137 };
138
139
140 GNUNET_NETWORK_STRUCT_BEGIN
141
142
143 /**
144  * @brief header of what an ECC signature signs
145  *        this must be followed by "size - 8" bytes of
146  *        the actual signed data
147  */
148 struct GNUNET_CRYPTO_EccSignaturePurpose
149 {
150   /**
151    * How many bytes does this signature sign?
152    * (including this purpose header); in network
153    * byte order (!).
154    */
155   uint32_t size GNUNET_PACKED;
156
157   /**
158    * What does this signature vouch for?  This
159    * must contain a GNUNET_SIGNATURE_PURPOSE_XXX
160    * constant (from gnunet_signatures.h).  In
161    * network byte order!
162    */
163   uint32_t purpose GNUNET_PACKED;
164
165 };
166
167
168 /**
169  * @brief an ECC signature using EdDSA.
170  * See https://gnunet.org/ed25519
171  */
172 struct GNUNET_CRYPTO_EddsaSignature
173 {
174
175   /**
176    * R value.
177    */
178   unsigned char r[256 / 8];
179
180   /**
181    * S value.
182    */
183   unsigned char s[256 / 8];
184
185 };
186
187
188
189 /**
190  * @brief an ECC signature using ECDSA
191  */
192 struct GNUNET_CRYPTO_EcdsaSignature
193 {
194
195   /**
196    * R value.
197    */
198   unsigned char r[256 / 8];
199
200   /**
201    * S value.
202    */
203   unsigned char s[256 / 8];
204
205 };
206
207
208 /**
209  * Public ECC key (always for curve Ed25519) encoded in a format
210  * suitable for network transmission and EdDSA signatures.
211  */
212 struct GNUNET_CRYPTO_EddsaPublicKey
213 {
214   /**
215    * Point Q consists of a y-value mod p (256 bits); the x-value is
216    * always positive. The point is stored in Ed25519 standard
217    * compact format.
218    */
219   unsigned char q_y[256 / 8];
220
221 };
222
223
224 /**
225  * Public ECC key (always for Curve25519) encoded in a format suitable
226  * for network transmission and ECDSA signatures.
227  */
228 struct GNUNET_CRYPTO_EcdsaPublicKey
229 {
230   /**
231    * Q consists of an x- and a y-value, each mod p (256 bits), given
232    * here in affine coordinates and Ed25519 standard compact format.
233    */
234   unsigned char q_y[256 / 8];
235
236 };
237
238
239 /**
240  * The identity of the host (wraps the signing key of the peer).
241  */
242 struct GNUNET_PeerIdentity
243 {
244   struct GNUNET_CRYPTO_EddsaPublicKey public_key;
245 };
246
247
248 /**
249  * Public ECC key (always for Curve25519) encoded in a format suitable
250  * for network transmission and encryption (ECDH),
251  * See http://cr.yp.to/ecdh.html
252  */
253 struct GNUNET_CRYPTO_EcdhePublicKey
254 {
255   /**
256    * Q consists of an x- and a y-value, each mod p (256 bits), given
257    * here in affine coordinates and Ed25519 standard compact format.
258    */
259   unsigned char q_y[256 / 8];
260 };
261
262
263 /**
264  * Private ECC key encoded for transmission.  To be used only for ECDH
265  * key exchange (ECDHE to be precise).
266  */
267 struct GNUNET_CRYPTO_EcdhePrivateKey
268 {
269   /**
270    * d is a value mod n, where n has at most 256 bits.
271    */
272   unsigned char d[256 / 8];
273
274 };
275
276 /**
277  * Private ECC key encoded for transmission.  To be used only for ECDSA
278  * signatures.
279  */
280 struct GNUNET_CRYPTO_EcdsaPrivateKey
281 {
282   /**
283    * d is a value mod n, where n has at most 256 bits.
284    */
285   unsigned char d[256 / 8];
286
287 };
288
289 /**
290  * Private ECC key encoded for transmission.  To be used only for EdDSA
291  * signatures.
292  */
293 struct GNUNET_CRYPTO_EddsaPrivateKey
294 {
295   /**
296    * d is a value mod n, where n has at most 256 bits.
297    */
298   unsigned char d[256 / 8];
299
300 };
301
302
303 /**
304  * @brief type for session keys
305  */
306 struct GNUNET_CRYPTO_SymmetricSessionKey
307 {
308   /**
309    * Actual key for AES.
310    */
311   unsigned char aes_key[GNUNET_CRYPTO_AES_KEY_LENGTH];
312
313   /**
314    * Actual key for TwoFish.
315    */
316   unsigned char twofish_key[GNUNET_CRYPTO_AES_KEY_LENGTH];
317
318 };
319
320 GNUNET_NETWORK_STRUCT_END
321
322 /**
323  * @brief IV for sym cipher
324  *
325  * NOTE: must be smaller (!) in size than the
326  * `struct GNUNET_HashCode`.
327  */
328 struct GNUNET_CRYPTO_SymmetricInitializationVector
329 {
330   unsigned char aes_iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
331
332   unsigned char twofish_iv[GNUNET_CRYPTO_AES_KEY_LENGTH / 2];
333 };
334
335
336 /**
337  * @brief type for (message) authentication keys
338  */
339 struct GNUNET_CRYPTO_AuthKey
340 {
341   unsigned char key[GNUNET_CRYPTO_HASH_LENGTH];
342 };
343
344
345 /**
346  * Size of paillier plain texts and public keys.
347  * Private keys and ciphertexts are twice this size.
348  */
349 #define GNUNET_CRYPTO_PAILLIER_BITS 2048
350
351
352 /**
353  * Paillier public key.
354  */
355 struct GNUNET_CRYPTO_PaillierPublicKey
356 {
357   /**
358    * N value.
359    */
360   unsigned char n[GNUNET_CRYPTO_PAILLIER_BITS / 8];
361 };
362
363
364 /**
365  * Paillier private key.
366  */
367 struct GNUNET_CRYPTO_PaillierPrivateKey
368 {
369   /**
370    * Lambda-component of the private key.
371    */
372   unsigned char lambda[GNUNET_CRYPTO_PAILLIER_BITS / 8];
373   /**
374    * Mu-component of the private key.
375    */
376   unsigned char mu[GNUNET_CRYPTO_PAILLIER_BITS / 8];
377 };
378
379
380 /**
381  * Paillier ciphertext.
382  */
383 struct GNUNET_CRYPTO_PaillierCiphertext
384 {
385   /**
386    * Guaranteed minimum number of homomorphic operations with this ciphertext,
387    * in network byte order (NBO).
388    */
389   int32_t remaining_ops GNUNET_PACKED;
390
391   /**
392    * The bits of the ciphertext.
393    */
394   unsigned char bits[GNUNET_CRYPTO_PAILLIER_BITS * 2 / 8];
395 };
396
397
398 /* **************** Functions and Macros ************* */
399
400 /**
401  * @ingroup crypto
402  * Seed a weak random generator. Only #GNUNET_CRYPTO_QUALITY_WEAK-mode generator
403  * can be seeded.
404  *
405  * @param seed the seed to use
406  */
407 void
408 GNUNET_CRYPTO_seed_weak_random (int32_t seed);
409
410
411 /**
412  * @ingroup hash
413  * Calculate the checksum of a buffer in one step.
414  *
415  * @param buf buffer to calculate CRC over
416  * @param len number of bytes in @a buf
417  * @return crc8 value
418  */
419 uint8_t
420 GNUNET_CRYPTO_crc8_n (const void *buf,
421                       size_t len);
422
423
424 /**
425  * Perform an incremental step in a CRC16 (for TCP/IP) calculation.
426  *
427  * @param sum current sum, initially 0
428  * @param buf buffer to calculate CRC over (must be 16-bit aligned)
429  * @param len number of bytes in @a buf, must be multiple of 2
430  * @return updated crc sum (must be subjected to #GNUNET_CRYPTO_crc16_finish to get actual crc16)
431  */
432 uint32_t
433 GNUNET_CRYPTO_crc16_step (uint32_t sum,
434                           const void *buf,
435                           size_t len);
436
437
438 /**
439  * Convert results from GNUNET_CRYPTO_crc16_step to final crc16.
440  *
441  * @param sum cummulative sum
442  * @return crc16 value
443  */
444 uint16_t
445 GNUNET_CRYPTO_crc16_finish (uint32_t sum);
446
447
448 /**
449  * @ingroup hash
450  * Calculate the checksum of a buffer in one step.
451  *
452  * @param buf buffer to calculate CRC over (must be 16-bit aligned)
453  * @param len number of bytes in @a buf, must be multiple of 2
454  * @return crc16 value
455  */
456 uint16_t
457 GNUNET_CRYPTO_crc16_n (const void *buf,
458                        size_t len);
459
460
461
462
463 /**
464  * @ingroup hash
465  * Compute the CRC32 checksum for the first len
466  * bytes of the buffer.
467  *
468  * @param buf the data over which we're taking the CRC
469  * @param len the length of the buffer @a buf in bytes
470  * @return the resulting CRC32 checksum
471  */
472 int32_t
473 GNUNET_CRYPTO_crc32_n (const void *buf,
474                        size_t len);
475
476
477 /**
478  * @ingroup crypto
479  * Fill block with a random values.
480  *
481  * @param mode desired quality of the random number
482  * @param buffer the buffer to fill
483  * @param length buffer length
484  */
485 void
486 GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode,
487                             void *buffer,
488                             size_t length);
489
490 /**
491  * @ingroup crypto
492  * Produce a random value.
493  *
494  * @param mode desired quality of the random number
495  * @param i the upper limit (exclusive) for the random number
496  * @return a random value in the interval [0,@a i) (exclusive).
497  */
498 uint32_t
499 GNUNET_CRYPTO_random_u32 (enum GNUNET_CRYPTO_Quality mode,
500                           uint32_t i);
501
502
503 /**
504  * @ingroup crypto
505  * Random on unsigned 64-bit values.
506  *
507  * @param mode desired quality of the random number
508  * @param max value returned will be in range [0,@a max) (exclusive)
509  * @return random 64-bit number
510  */
511 uint64_t
512 GNUNET_CRYPTO_random_u64 (enum GNUNET_CRYPTO_Quality mode,
513                           uint64_t max);
514
515
516 /**
517  * @ingroup crypto
518  * Get an array with a random permutation of the
519  * numbers 0...n-1.
520  * @param mode #GNUNET_CRYPTO_QUALITY_STRONG if the strong (but expensive) PRNG should be used,
521  *             #GNUNET_CRYPTO_QUALITY_WEAK or #GNUNET_CRYPTO_QUALITY_NONCE otherwise
522  * @param n the size of the array
523  * @return the permutation array (allocated from heap)
524  */
525 unsigned int *
526 GNUNET_CRYPTO_random_permute (enum GNUNET_CRYPTO_Quality mode,
527                               unsigned int n);
528
529
530 /**
531  * @ingroup crypto
532  * Create a new random session key.
533  *
534  * @param key key to initialize
535  */
536 void
537 GNUNET_CRYPTO_symmetric_create_session_key (struct GNUNET_CRYPTO_SymmetricSessionKey *key);
538
539
540 /**
541  * @ingroup crypto
542  * Encrypt a block using a symmetric sessionkey.
543  *
544  * @param block the block to encrypt
545  * @param size the size of the @a block
546  * @param sessionkey the key used to encrypt
547  * @param iv the initialization vector to use, use INITVALUE
548  *        for streams.
549  * @return the size of the encrypted block, -1 for errors
550  */
551 ssize_t
552 GNUNET_CRYPTO_symmetric_encrypt (const void *block,
553                                  size_t size,
554                                  const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey,
555                                  const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
556                                  void *result);
557
558
559 /**
560  * @ingroup crypto
561  * Decrypt a given block using a symmetric sessionkey.
562  *
563  * @param block the data to decrypt, encoded as returned by encrypt
564  * @param size how big is the block?
565  * @param sessionkey the key used to decrypt
566  * @param iv the initialization vector to use
567  * @param result address to store the result at
568  * @return -1 on failure, size of decrypted block on success
569  */
570 ssize_t
571 GNUNET_CRYPTO_symmetric_decrypt (const void *block,
572                                  size_t size,
573                                  const struct GNUNET_CRYPTO_SymmetricSessionKey *sessionkey,
574                                  const struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
575                                  void *result);
576
577
578 /**
579  * @ingroup crypto
580  * @brief Derive an IV
581  * @param iv initialization vector
582  * @param skey session key
583  * @param salt salt for the derivation
584  * @param salt_len size of the @a salt
585  * @param ... pairs of void * & size_t for context chunks, terminated by NULL
586  */
587 void
588 GNUNET_CRYPTO_symmetric_derive_iv (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
589                                    const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
590                                    const void *salt,
591                                    size_t salt_len, ...);
592
593
594 /**
595  * @brief Derive an IV
596  * @param iv initialization vector
597  * @param skey session key
598  * @param salt salt for the derivation
599  * @param salt_len size of the @a salt
600  * @param argp pairs of void * & size_t for context chunks, terminated by NULL
601  */
602 void
603 GNUNET_CRYPTO_symmetric_derive_iv_v (struct GNUNET_CRYPTO_SymmetricInitializationVector *iv,
604                                      const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
605                                      const void *salt,
606                                      size_t salt_len,
607                                      va_list argp);
608
609
610 /**
611  * @ingroup hash
612  * Convert hash to ASCII encoding.
613  * @param block the hash code
614  * @param result where to store the encoding (struct GNUNET_CRYPTO_HashAsciiEncoded can be
615  *  safely cast to char*, a '\\0' termination is set).
616  */
617 void
618 GNUNET_CRYPTO_hash_to_enc (const struct GNUNET_HashCode *block,
619                            struct GNUNET_CRYPTO_HashAsciiEncoded *result);
620
621
622 /**
623  * @ingroup hash
624  * Convert ASCII encoding back to a 'struct GNUNET_HashCode'
625  *
626  * @param enc the encoding
627  * @param enclen number of characters in @a enc (without 0-terminator, which can be missing)
628  * @param result where to store the hash code
629  * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
630  */
631 int
632 GNUNET_CRYPTO_hash_from_string2 (const char *enc,
633                                  size_t enclen,
634                                  struct GNUNET_HashCode *result);
635
636
637 /**
638  * @ingroup hash
639  * Convert ASCII encoding back to `struct GNUNET_HashCode`
640  *
641  * @param enc the encoding
642  * @param result where to store the hash code
643  * @return #GNUNET_OK on success, #GNUNET_SYSERR if result has the wrong encoding
644  */
645 #define GNUNET_CRYPTO_hash_from_string(enc, result) \
646   GNUNET_CRYPTO_hash_from_string2 (enc, strlen(enc), result)
647
648
649 /**
650  * @ingroup hash
651  *
652  * Compute the distance between 2 hashcodes.  The
653  * computation must be fast, not involve @a a[0] or @a a[4] (they're used
654  * elsewhere), and be somewhat consistent. And of course, the result
655  * should be a positive number.
656  *
657  * @param a some hash code
658  * @param b some hash code
659  * @return number between 0 and UINT32_MAX
660  */
661 uint32_t
662 GNUNET_CRYPTO_hash_distance_u32 (const struct GNUNET_HashCode *a,
663                                  const struct GNUNET_HashCode *b);
664
665
666 /**
667  * @ingroup hash
668  * Compute hash of a given block.
669  *
670  * @param block the data to hash
671  * @param size size of the @a block
672  * @param ret pointer to where to write the hashcode
673  */
674 void
675 GNUNET_CRYPTO_hash (const void *block,
676                     size_t size,
677                     struct GNUNET_HashCode *ret);
678
679
680 /**
681  * Context for cummulative hashing.
682  */
683 struct GNUNET_HashContext;
684
685
686 /**
687  * Start incremental hashing operation.
688  *
689  * @return context for incremental hash computation
690  */
691 struct GNUNET_HashContext *
692 GNUNET_CRYPTO_hash_context_start (void);
693
694
695 /**
696  * Add data to be hashed.
697  *
698  * @param hc cummulative hash context
699  * @param buf data to add
700  * @param size number of bytes in @a buf
701  */
702 void
703 GNUNET_CRYPTO_hash_context_read (struct GNUNET_HashContext *hc,
704                                  const void *buf,
705                                  size_t size);
706
707
708 /**
709  * Finish the hash computation.
710  *
711  * @param hc hash context to use, is freed in the process
712  * @param r_hash where to write the latest / final hash code
713  */
714 void
715 GNUNET_CRYPTO_hash_context_finish (struct GNUNET_HashContext *hc,
716                                    struct GNUNET_HashCode *r_hash);
717
718
719 /**
720  * Abort hashing, do not bother calculating final result.
721  *
722  * @param hc hash context to destroy
723  */
724 void
725 GNUNET_CRYPTO_hash_context_abort (struct GNUNET_HashContext *hc);
726
727
728 /**
729  * Calculate HMAC of a message (RFC 2104)
730  * TODO: Shouldn' this be the standard hmac function and
731  * the above be renamed?
732  *
733  * @param key secret key
734  * @param key_len secret key length
735  * @param plaintext input plaintext
736  * @param plaintext_len length of @a plaintext
737  * @param hmac where to store the hmac
738  */
739 void
740 GNUNET_CRYPTO_hmac_raw (const void *key, size_t key_len,
741                     const void *plaintext, size_t plaintext_len,
742                     struct GNUNET_HashCode *hmac);
743
744
745 /**
746  * @ingroup hash
747  * Calculate HMAC of a message (RFC 2104)
748  *
749  * @param key secret key
750  * @param plaintext input plaintext
751  * @param plaintext_len length of @a plaintext
752  * @param hmac where to store the hmac
753  */
754 void
755 GNUNET_CRYPTO_hmac (const struct GNUNET_CRYPTO_AuthKey *key,
756                     const void *plaintext,
757                     size_t plaintext_len,
758                     struct GNUNET_HashCode *hmac);
759
760
761 /**
762  * Function called once the hash computation over the
763  * specified file has completed.
764  *
765  * @param cls closure
766  * @param res resulting hash, NULL on error
767  */
768 typedef void
769 (*GNUNET_CRYPTO_HashCompletedCallback) (void *cls,
770                                         const struct GNUNET_HashCode *res);
771
772
773 /**
774  * Handle to file hashing operation.
775  */
776 struct GNUNET_CRYPTO_FileHashContext;
777
778
779 /**
780  * @ingroup hash
781  * Compute the hash of an entire file.
782  *
783  * @param priority scheduling priority to use
784  * @param filename name of file to hash
785  * @param blocksize number of bytes to process in one task
786  * @param callback function to call upon completion
787  * @param callback_cls closure for @a callback
788  * @return NULL on (immediate) errror
789  */
790 struct GNUNET_CRYPTO_FileHashContext *
791 GNUNET_CRYPTO_hash_file (enum GNUNET_SCHEDULER_Priority priority,
792                          const char *filename,
793                          size_t blocksize,
794                          GNUNET_CRYPTO_HashCompletedCallback callback,
795                          void *callback_cls);
796
797
798 /**
799  * Cancel a file hashing operation.
800  *
801  * @param fhc operation to cancel (callback must not yet have been invoked)
802  */
803 void
804 GNUNET_CRYPTO_hash_file_cancel (struct GNUNET_CRYPTO_FileHashContext *fhc);
805
806
807 /**
808  * @ingroup hash
809  * Create a random hash code.
810  *
811  * @param mode desired quality level
812  * @param result hash code that is randomized
813  */
814 void
815 GNUNET_CRYPTO_hash_create_random (enum GNUNET_CRYPTO_Quality mode,
816                                   struct GNUNET_HashCode *result);
817
818
819 /**
820  * @ingroup hash
821  * compute @a result = @a b - @a a
822  *
823  * @param a some hash code
824  * @param b some hash code
825  * @param result set to @a b - @a a
826  */
827 void
828 GNUNET_CRYPTO_hash_difference (const struct GNUNET_HashCode *a,
829                                const struct GNUNET_HashCode *b,
830                                struct GNUNET_HashCode *result);
831
832
833 /**
834  * @ingroup hash
835  * compute @a result = @a a + @a delta
836  *
837  * @param a some hash code
838  * @param delta some hash code
839  * @param result set to @a a + @a delta
840  */
841 void
842 GNUNET_CRYPTO_hash_sum (const struct GNUNET_HashCode *a,
843                         const struct GNUNET_HashCode *delta,
844                         struct GNUNET_HashCode *result);
845
846
847 /**
848  * @ingroup hash
849  * compute result = a ^ b
850  *
851  * @param a some hash code
852  * @param b some hash code
853  * @param result set to @a a ^ @a b
854  */
855 void
856 GNUNET_CRYPTO_hash_xor (const struct GNUNET_HashCode *a,
857                         const struct GNUNET_HashCode *b,
858                         struct GNUNET_HashCode *result);
859
860
861 /**
862  * @ingroup hash
863  * Convert a hashcode into a key.
864  *
865  * @param hc hash code that serves to generate the key
866  * @param skey set to a valid session key
867  * @param iv set to a valid initialization vector
868  */
869 void
870 GNUNET_CRYPTO_hash_to_aes_key (const struct GNUNET_HashCode * hc,
871                                struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
872                                struct GNUNET_CRYPTO_SymmetricInitializationVector *iv);
873
874
875 /**
876  * @ingroup hash
877  * Obtain a bit from a hashcode.
878  *
879  * @param code the `struct GNUNET_HashCode` to index bit-wise
880  * @param bit index into the hashcode, [0...159]
881  * @return Bit \a bit from hashcode \a code, -1 for invalid index
882  */
883 int
884 GNUNET_CRYPTO_hash_get_bit (const struct GNUNET_HashCode *code,
885                             unsigned int bit);
886
887
888 /**
889  * @ingroup hash
890  * Determine how many low order bits match in two
891  * `struct GNUNET_HashCodes`.  i.e. - 010011 and 011111 share
892  * the first two lowest order bits, and therefore the
893  * return value is two (NOT XOR distance, nor how many
894  * bits match absolutely!).
895  *
896  * @param first the first hashcode
897  * @param second the hashcode to compare first to
898  * @return the number of bits that match
899  */
900 unsigned int
901 GNUNET_CRYPTO_hash_matching_bits (const struct GNUNET_HashCode *first,
902                                   const struct GNUNET_HashCode *second);
903
904
905 /**
906  * @ingroup hash
907  * Compare function for HashCodes, producing a total ordering
908  * of all hashcodes.
909  *
910  * @param h1 some hash code
911  * @param h2 some hash code
912  * @return 1 if @a h1 > @a h2, -1 if @a h1 < @a h2 and 0 if @a h1 == @a h2.
913  */
914 int
915 GNUNET_CRYPTO_hash_cmp (const struct GNUNET_HashCode *h1,
916                         const struct GNUNET_HashCode *h2);
917
918
919 /**
920  * @ingroup hash
921  * Find out which of the two GNUNET_CRYPTO_hash codes is closer to target
922  * in the XOR metric (Kademlia).
923  *
924  * @param h1 some hash code
925  * @param h2 some hash code
926  * @param target some hash code
927  * @return -1 if @a h1 is closer, 1 if @a h2 is closer and 0 if @a h1== @a h2.
928  */
929 int
930 GNUNET_CRYPTO_hash_xorcmp (const struct GNUNET_HashCode *h1,
931                            const struct GNUNET_HashCode *h2,
932                            const struct GNUNET_HashCode *target);
933
934
935 /**
936  * @ingroup hash
937  * @brief Derive an authentication key
938  * @param key authentication key
939  * @param rkey root key
940  * @param salt salt
941  * @param salt_len size of the salt
942  * @param argp pair of void * & size_t for context chunks, terminated by NULL
943  */
944 void
945 GNUNET_CRYPTO_hmac_derive_key_v (struct GNUNET_CRYPTO_AuthKey *key,
946                                  const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey,
947                                  const void *salt, size_t salt_len,
948                                  va_list argp);
949
950
951 /**
952  * @ingroup hash
953  * @brief Derive an authentication key
954  * @param key authentication key
955  * @param rkey root key
956  * @param salt salt
957  * @param salt_len size of the salt
958  * @param ... pair of void * & size_t for context chunks, terminated by NULL
959  */
960 void
961 GNUNET_CRYPTO_hmac_derive_key (struct GNUNET_CRYPTO_AuthKey *key,
962                                const struct GNUNET_CRYPTO_SymmetricSessionKey *rkey,
963                                const void *salt, size_t salt_len,
964                                ...);
965
966
967 /**
968  * @ingroup hash
969  * @brief Derive key
970  * @param result buffer for the derived key, allocated by caller
971  * @param out_len desired length of the derived key
972  * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
973  * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
974  * @param xts salt
975  * @param xts_len length of @a xts
976  * @param skm source key material
977  * @param skm_len length of @a skm
978  * @param ... pair of void * & size_t for context chunks, terminated by NULL
979  * @return #GNUNET_YES on success
980  */
981 int
982 GNUNET_CRYPTO_hkdf (void *result,
983                     size_t out_len,
984                     int xtr_algo,
985                     int prf_algo,
986                     const void *xts,
987                     size_t xts_len,
988                     const void *skm,
989                     size_t skm_len,
990                     ...);
991
992
993 /**
994  * @ingroup hash
995  * @brief Derive key
996  * @param result buffer for the derived key, allocated by caller
997  * @param out_len desired length of the derived key
998  * @param xtr_algo hash algorithm for the extraction phase, GCRY_MD_...
999  * @param prf_algo hash algorithm for the expansion phase, GCRY_MD_...
1000  * @param xts salt
1001  * @param xts_len length of @a xts
1002  * @param skm source key material
1003  * @param skm_len length of @a skm
1004  * @param argp va_list of void * & size_t pairs for context chunks
1005  * @return #GNUNET_YES on success
1006  */
1007 int
1008 GNUNET_CRYPTO_hkdf_v (void *result,
1009                       size_t out_len,
1010                       int xtr_algo,
1011                       int prf_algo,
1012                       const void *xts,
1013                       size_t xts_len,
1014                       const void *skm,
1015                       size_t skm_len,
1016                       va_list argp);
1017
1018
1019 /**
1020  * @brief Derive key
1021  * @param result buffer for the derived key, allocated by caller
1022  * @param out_len desired length of the derived key
1023  * @param xts salt
1024  * @param xts_len length of @a xts
1025  * @param skm source key material
1026  * @param skm_len length of @a skm
1027  * @param argp va_list of void * & size_t pairs for context chunks
1028  * @return #GNUNET_YES on success
1029  */
1030 int
1031 GNUNET_CRYPTO_kdf_v (void *result,
1032                      size_t out_len,
1033                      const void *xts,
1034                      size_t xts_len,
1035                      const void *skm,
1036                      size_t skm_len,
1037                      va_list argp);
1038
1039
1040 /**
1041  * Deterministically generate a pseudo-random number uniformly from the
1042  * integers modulo a libgcrypt mpi.
1043  *
1044  * @param[out] r MPI value set to the FDH
1045  * @param n MPI to work modulo
1046  * @param xts salt
1047  * @param xts_len length of @a xts
1048  * @param skm source key material
1049  * @param skm_len length of @a skm
1050  * @param ctx context string
1051  */
1052 void
1053 GNUNET_CRYPTO_kdf_mod_mpi (gcry_mpi_t *r,
1054                            gcry_mpi_t n,
1055                            const void *xts,  size_t xts_len,
1056                            const void *skm,  size_t skm_len,
1057                            const char *ctx);
1058
1059
1060 /**
1061  * @ingroup hash
1062  * @brief Derive key
1063  * @param result buffer for the derived key, allocated by caller
1064  * @param out_len desired length of the derived key
1065  * @param xts salt
1066  * @param xts_len length of @a xts
1067  * @param skm source key material
1068  * @param skm_len length of @a skm
1069  * @param ... void * & size_t pairs for context chunks
1070  * @return #GNUNET_YES on success
1071  */
1072 int
1073 GNUNET_CRYPTO_kdf (void *result,
1074                    size_t out_len,
1075                    const void *xts,
1076                    size_t xts_len,
1077                    const void *skm,
1078                    size_t skm_len,
1079                    ...);
1080
1081
1082 /**
1083  * @ingroup crypto
1084  * Extract the public key for the given private key.
1085  *
1086  * @param priv the private key
1087  * @param pub where to write the public key
1088  */
1089 void
1090 GNUNET_CRYPTO_ecdsa_key_get_public (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1091                                     struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
1092
1093 /**
1094  * @ingroup crypto
1095  * Extract the public key for the given private key.
1096  *
1097  * @param priv the private key
1098  * @param pub where to write the public key
1099  */
1100 void
1101 GNUNET_CRYPTO_eddsa_key_get_public (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1102                                     struct GNUNET_CRYPTO_EddsaPublicKey *pub);
1103
1104
1105
1106 /**
1107  * @ingroup crypto
1108  * Extract the public key for the given private key.
1109  *
1110  * @param priv the private key
1111  * @param pub where to write the public key
1112  */
1113 void
1114 GNUNET_CRYPTO_ecdhe_key_get_public (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1115                                     struct GNUNET_CRYPTO_EcdhePublicKey *pub);
1116
1117
1118 /**
1119  * Convert a public key to a string.
1120  *
1121  * @param pub key to convert
1122  * @return string representing @a pub
1123  */
1124 char *
1125 GNUNET_CRYPTO_ecdsa_public_key_to_string (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
1126
1127
1128 /**
1129  * Convert a private key to a string.
1130  *
1131  * @param priv key to convert
1132  * @return string representing @a pub
1133  */
1134 char *
1135 GNUNET_CRYPTO_eddsa_private_key_to_string (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv);
1136
1137
1138 /**
1139  * Convert a public key to a string.
1140  *
1141  * @param pub key to convert
1142  * @return string representing @a pub
1143  */
1144 char *
1145 GNUNET_CRYPTO_eddsa_public_key_to_string (const struct GNUNET_CRYPTO_EddsaPublicKey *pub);
1146
1147
1148 /**
1149  * Convert a string representing a public key to a public key.
1150  *
1151  * @param enc encoded public key
1152  * @param enclen number of bytes in @a enc (without 0-terminator)
1153  * @param pub where to store the public key
1154  * @return #GNUNET_OK on success
1155  */
1156 int
1157 GNUNET_CRYPTO_ecdsa_public_key_from_string (const char *enc,
1158                                             size_t enclen,
1159                                             struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
1160
1161
1162 /**
1163  * Convert a string representing a private key to a private key.
1164  *
1165  * @param enc encoded public key
1166  * @param enclen number of bytes in @a enc (without 0-terminator)
1167  * @param priv where to store the private key
1168  * @return #GNUNET_OK on success
1169  */
1170 int
1171 GNUNET_CRYPTO_eddsa_private_key_from_string (const char *enc,
1172                                              size_t enclen,
1173                                              struct GNUNET_CRYPTO_EddsaPrivateKey *pub);
1174
1175
1176 /**
1177  * Convert a string representing a public key to a public key.
1178  *
1179  * @param enc encoded public key
1180  * @param enclen number of bytes in @a enc (without 0-terminator)
1181  * @param pub where to store the public key
1182  * @return #GNUNET_OK on success
1183  */
1184 int
1185 GNUNET_CRYPTO_eddsa_public_key_from_string (const char *enc,
1186                                             size_t enclen,
1187                                             struct GNUNET_CRYPTO_EddsaPublicKey *pub);
1188
1189
1190 /**
1191  * @ingroup crypto
1192  * Create a new private key by reading it from a file.  If the
1193  * files does not exist, create a new key and write it to the
1194  * file.  Caller must free return value.  Note that this function
1195  * can not guarantee that another process might not be trying
1196  * the same operation on the same file at the same time.
1197  * If the contents of the file
1198  * are invalid the old file is deleted and a fresh key is
1199  * created.
1200  *
1201  * @param filename name of file to use to store the key
1202  * @return new private key, NULL on error (for example,
1203  *   permission denied); free using #GNUNET_free
1204  */
1205 struct GNUNET_CRYPTO_EcdsaPrivateKey *
1206 GNUNET_CRYPTO_ecdsa_key_create_from_file (const char *filename);
1207
1208
1209 /**
1210  * @ingroup crypto
1211  * Create a new private key by reading it from a file.  If the
1212  * files does not exist, create a new key and write it to the
1213  * file.  Caller must free return value.  Note that this function
1214  * can not guarantee that another process might not be trying
1215  * the same operation on the same file at the same time.
1216  * If the contents of the file
1217  * are invalid the old file is deleted and a fresh key is
1218  * created.
1219  *
1220  * @param filename name of file to use to store the key
1221  * @return new private key, NULL on error (for example,
1222  *   permission denied); free using #GNUNET_free
1223  */
1224 struct GNUNET_CRYPTO_EddsaPrivateKey *
1225 GNUNET_CRYPTO_eddsa_key_create_from_file (const char *filename);
1226
1227
1228 /**
1229  * Forward declaration to simplify #include-structure.
1230  */
1231 struct GNUNET_CONFIGURATION_Handle;
1232
1233
1234 /**
1235  * @ingroup crypto
1236  * Create a new private key by reading our peer's key from
1237  * the file specified in the configuration.
1238  *
1239  * @param cfg the configuration to use
1240  * @return new private key, NULL on error (for example,
1241  *   permission denied); free using #GNUNET_free
1242  */
1243 struct GNUNET_CRYPTO_EddsaPrivateKey *
1244 GNUNET_CRYPTO_eddsa_key_create_from_configuration (const struct GNUNET_CONFIGURATION_Handle *cfg);
1245
1246
1247 /**
1248  * @ingroup crypto
1249  * Create a new private key. Caller must free return value.
1250  *
1251  * @return fresh private key; free using #GNUNET_free
1252  */
1253 struct GNUNET_CRYPTO_EcdsaPrivateKey *
1254 GNUNET_CRYPTO_ecdsa_key_create (void);
1255
1256
1257 /**
1258  * @ingroup crypto
1259  * Create a new private key. Caller must free return value.
1260  *
1261  * @return fresh private key; free using #GNUNET_free
1262  */
1263 struct GNUNET_CRYPTO_EddsaPrivateKey *
1264 GNUNET_CRYPTO_eddsa_key_create (void);
1265
1266
1267 /**
1268  * @ingroup crypto
1269  * Create a new private key.  Clear with #GNUNET_CRYPTO_ecdhe_key_clear().
1270  *
1271  * @param[out] pk set to fresh private key;
1272  * @return #GNUNET_OK on success, #GNUNET_SYSERR on failure
1273  */
1274 int
1275 GNUNET_CRYPTO_ecdhe_key_create2 (struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
1276
1277
1278 /**
1279  * @ingroup crypto
1280  * Create a new private key. Caller must free return value.
1281  *
1282  * @return fresh private key; free using #GNUNET_free
1283  */
1284 struct GNUNET_CRYPTO_EcdhePrivateKey *
1285 GNUNET_CRYPTO_ecdhe_key_create (void);
1286
1287
1288 /**
1289  * @ingroup crypto
1290  * Clear memory that was used to store a private key.
1291  *
1292  * @param pk location of the key
1293  */
1294 void
1295 GNUNET_CRYPTO_eddsa_key_clear (struct GNUNET_CRYPTO_EddsaPrivateKey *pk);
1296
1297
1298 /**
1299  * @ingroup crypto
1300  * Clear memory that was used to store a private key.
1301  *
1302  * @param pk location of the key
1303  */
1304 void
1305 GNUNET_CRYPTO_ecdsa_key_clear (struct GNUNET_CRYPTO_EcdsaPrivateKey *pk);
1306
1307
1308 /**
1309  * @ingroup crypto
1310  * Clear memory that was used to store a private key.
1311  *
1312  * @param pk location of the key
1313  */
1314 void
1315 GNUNET_CRYPTO_ecdhe_key_clear (struct GNUNET_CRYPTO_EcdhePrivateKey *pk);
1316
1317
1318 /**
1319  * @ingroup crypto
1320  * Get the shared private key we use for anonymous users.
1321  *
1322  * @return "anonymous" private key; do not free
1323  */
1324 const struct GNUNET_CRYPTO_EcdsaPrivateKey *
1325 GNUNET_CRYPTO_ecdsa_key_get_anonymous (void);
1326
1327
1328 /**
1329  * @ingroup crypto
1330  * Setup a hostkey file for a peer given the name of the
1331  * configuration file (!).  This function is used so that
1332  * at a later point code can be certain that reading a
1333  * hostkey is fast (for example in time-dependent testcases).
1334 *
1335  * @param cfg_name name of the configuration file to use
1336  */
1337 void
1338 GNUNET_CRYPTO_eddsa_setup_hostkey (const char *cfg_name);
1339
1340
1341 /**
1342  * @ingroup crypto
1343  * Retrieve the identity of the host's peer.
1344  *
1345  * @param cfg configuration to use
1346  * @param dst pointer to where to write the peer identity
1347  * @return #GNUNET_OK on success, #GNUNET_SYSERR if the identity
1348  *         could not be retrieved
1349  */
1350 int
1351 GNUNET_CRYPTO_get_peer_identity (const struct GNUNET_CONFIGURATION_Handle *cfg,
1352                                  struct GNUNET_PeerIdentity *dst);
1353
1354
1355 /**
1356  * Compare two Peer Identities.
1357  *
1358  * @param first first peer identity
1359  * @param second second peer identity
1360  * @return bigger than 0 if first > second,
1361  *         0 if they are the same
1362  *         smaller than 0 if second > first
1363  */
1364 int
1365 GNUNET_CRYPTO_cmp_peer_identity (const struct GNUNET_PeerIdentity *first,
1366                                  const struct GNUNET_PeerIdentity *second);
1367
1368
1369 /**
1370  * Internal structure used to cache pre-calculated values for DLOG calculation.
1371  */
1372 struct GNUNET_CRYPTO_EccDlogContext;
1373
1374
1375 /**
1376  * Point on a curve (always for Curve25519) encoded in a format suitable
1377  * for network transmission (ECDH), see http://cr.yp.to/ecdh.html.
1378  */
1379 struct GNUNET_CRYPTO_EccPoint
1380 {
1381   /**
1382    * Q consists of an x- and a y-value, each mod p (256 bits), given
1383    * here in affine coordinates and Ed25519 standard compact format.
1384    */
1385   unsigned char q_y[256 / 8];
1386 };
1387
1388
1389 /**
1390  * Do pre-calculation for ECC discrete logarithm for small factors.
1391  *
1392  * @param max maximum value the factor can be
1393  * @param mem memory to use (should be smaller than @a max), must not be zero.
1394  * @return NULL on error
1395  */
1396 struct GNUNET_CRYPTO_EccDlogContext *
1397 GNUNET_CRYPTO_ecc_dlog_prepare (unsigned int max,
1398                                 unsigned int mem);
1399
1400
1401 /**
1402  * Calculate ECC discrete logarithm for small factors.
1403  * Opposite of #GNUNET_CRYPTO_ecc_dexp().
1404  *
1405  * @param dlc precalculated values, determine range of factors
1406  * @param input point on the curve to factor
1407  * @return INT_MAX if dlog failed, otherwise the factor
1408  */
1409 int
1410 GNUNET_CRYPTO_ecc_dlog (struct GNUNET_CRYPTO_EccDlogContext *edc,
1411                         gcry_mpi_point_t input);
1412
1413
1414 /**
1415  * Multiply the generator g of the elliptic curve by @a val
1416  * to obtain the point on the curve representing @a val.
1417  * Afterwards, point addition will correspond to integer
1418  * addition.  #GNUNET_CRYPTO_ecc_dlog() can be used to
1419  * convert a point back to an integer (as long as the
1420  * integer is smaller than the MAX of the @a edc context).
1421  *
1422  * @param edc calculation context for ECC operations
1423  * @param val value to encode into a point
1424  * @return representation of the value as an ECC point,
1425  *         must be freed using #GNUNET_CRYPTO_ecc_free()
1426  */
1427 gcry_mpi_point_t
1428 GNUNET_CRYPTO_ecc_dexp (struct GNUNET_CRYPTO_EccDlogContext *edc,
1429                         int val);
1430
1431
1432 /**
1433  * Multiply the generator g of the elliptic curve by @a val
1434  * to obtain the point on the curve representing @a val.
1435  *
1436  * @param edc calculation context for ECC operations
1437  * @param val (positive) value to encode into a point
1438  * @return representation of the value as an ECC point,
1439  *         must be freed using #GNUNET_CRYPTO_ecc_free()
1440  */
1441 gcry_mpi_point_t
1442 GNUNET_CRYPTO_ecc_dexp_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc,
1443                             gcry_mpi_t val);
1444
1445
1446 /**
1447  * Multiply the point @a p on the elliptic curve by @a val.
1448  *
1449  * @param edc calculation context for ECC operations
1450  * @param p point to multiply
1451  * @param val (positive) value to encode into a point
1452  * @return representation of the value as an ECC point,
1453  *         must be freed using #GNUNET_CRYPTO_ecc_free()
1454  */
1455 gcry_mpi_point_t
1456 GNUNET_CRYPTO_ecc_pmul_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc,
1457                             gcry_mpi_point_t p,
1458                             gcry_mpi_t val);
1459
1460
1461 /**
1462  * Convert point value to binary representation.
1463  *
1464  * @param edc calculation context for ECC operations
1465  * @param point computational point representation
1466  * @param[out] bin binary point representation
1467  */
1468 void
1469 GNUNET_CRYPTO_ecc_point_to_bin (struct GNUNET_CRYPTO_EccDlogContext *edc,
1470                                 gcry_mpi_point_t point,
1471                                 struct GNUNET_CRYPTO_EccPoint *bin);
1472
1473
1474 /**
1475  * Convert binary representation of a point to computational representation.
1476  *
1477  * @param edc calculation context for ECC operations
1478  * @param bin binary point representation
1479  * @return computational representation
1480  */
1481 gcry_mpi_point_t
1482 GNUNET_CRYPTO_ecc_bin_to_point (struct GNUNET_CRYPTO_EccDlogContext *edc,
1483                                 const struct GNUNET_CRYPTO_EccPoint *bin);
1484
1485
1486 /**
1487  * Add two points on the elliptic curve.
1488  *
1489  * @param edc calculation context for ECC operations
1490  * @param a some value
1491  * @param b some value
1492  * @return @a a + @a b, must be freed using #GNUNET_CRYPTO_ecc_free()
1493  */
1494 gcry_mpi_point_t
1495 GNUNET_CRYPTO_ecc_add (struct GNUNET_CRYPTO_EccDlogContext *edc,
1496                        gcry_mpi_point_t a,
1497                        gcry_mpi_point_t b);
1498
1499
1500 /**
1501  * Obtain a random point on the curve and its
1502  * additive inverse. Both returned values
1503  * must be freed using #GNUNET_CRYPTO_ecc_free().
1504  *
1505  * @param edc calculation context for ECC operations
1506  * @param[out] r set to a random point on the curve
1507  * @param[out] r_inv set to the additive inverse of @a r
1508  */
1509 void
1510 GNUNET_CRYPTO_ecc_rnd (struct GNUNET_CRYPTO_EccDlogContext *edc,
1511                        gcry_mpi_point_t *r,
1512                        gcry_mpi_point_t *r_inv);
1513
1514
1515 /**
1516  * Obtain a random scalar for point multiplication on the curve and
1517  * its multiplicative inverse.
1518  *
1519  * @param edc calculation context for ECC operations
1520  * @param[out] r set to a random scalar on the curve
1521  * @param[out] r_inv set to the multiplicative inverse of @a r
1522  */
1523 void
1524 GNUNET_CRYPTO_ecc_rnd_mpi (struct GNUNET_CRYPTO_EccDlogContext *edc,
1525                            gcry_mpi_t *r,
1526                            gcry_mpi_t *r_inv);
1527
1528
1529 /**
1530  * Generate a random value mod n.
1531  *
1532  * @param edc ECC context
1533  * @return random value mod n.
1534  */
1535 gcry_mpi_t
1536 GNUNET_CRYPTO_ecc_random_mod_n (struct GNUNET_CRYPTO_EccDlogContext *edc);
1537
1538
1539 /**
1540  * Free a point value returned by the API.
1541  *
1542  * @param p point to free
1543  */
1544 void
1545 GNUNET_CRYPTO_ecc_free (gcry_mpi_point_t p);
1546
1547
1548 /**
1549  * Release precalculated values.
1550  *
1551  * @param dlc dlog context
1552  */
1553 void
1554 GNUNET_CRYPTO_ecc_dlog_release (struct GNUNET_CRYPTO_EccDlogContext *dlc);
1555
1556
1557 /**
1558  * @ingroup crypto
1559  * Derive key material from a public and a private ECC key.
1560  *
1561  * @param priv private key to use for the ECDH (x)
1562  * @param pub public key to use for the ECDH (yG)
1563  * @param key_material where to write the key material (xyG)
1564  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1565  */
1566 int
1567 GNUNET_CRYPTO_ecc_ecdh (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1568                         const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1569                         struct GNUNET_HashCode *key_material);
1570
1571
1572 /**
1573  * @ingroup crypto
1574  * Derive key material from a ECDH public key and a private EdDSA key.
1575  * Dual to #GNUNET_CRRYPTO_ecdh_eddsa.
1576  *
1577  * @param priv private key from EdDSA to use for the ECDH (x)
1578  * @param pub public key to use for the ECDH (yG)
1579  * @param key_material where to write the key material H(h(x)yG)
1580  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1581  */
1582 int
1583 GNUNET_CRYPTO_eddsa_ecdh (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1584                           const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1585                           struct GNUNET_HashCode *key_material);
1586
1587 /**
1588  * @ingroup crypto
1589  * Derive key material from a ECDH public key and a private ECDSA key.
1590  * Dual to #GNUNET_CRRYPTO_ecdh_ecdsa.
1591  *
1592  * @param priv private key from ECDSA to use for the ECDH (x)
1593  * @param pub public key to use for the ECDH (yG)
1594  * @param key_material where to write the key material H(h(x)yG)
1595  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1596  */
1597 int
1598 GNUNET_CRYPTO_ecdsa_ecdh (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1599                           const struct GNUNET_CRYPTO_EcdhePublicKey *pub,
1600                           struct GNUNET_HashCode *key_material);
1601
1602
1603 /**
1604  * @ingroup crypto
1605  * Derive key material from a EdDSA public key and a private ECDH key.
1606  * Dual to #GNUNET_CRRYPTO_eddsa_ecdh.
1607  *
1608  * @param priv private key to use for the ECDH (y)
1609  * @param pub public key from EdDSA to use for the ECDH (X=h(x)G)
1610  * @param key_material where to write the key material H(yX)=H(h(x)yG)
1611  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1612  */
1613 int
1614 GNUNET_CRYPTO_ecdh_eddsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1615                           const struct GNUNET_CRYPTO_EddsaPublicKey *pub,
1616                           struct GNUNET_HashCode *key_material);
1617
1618 /**
1619  * @ingroup crypto
1620  * Derive key material from a EcDSA public key and a private ECDH key.
1621  * Dual to #GNUNET_CRRYPTO_ecdsa_ecdh.
1622  *
1623  * @param priv private key to use for the ECDH (y)
1624  * @param pub public key from ECDSA to use for the ECDH (X=h(x)G)
1625  * @param key_material where to write the key material H(yX)=H(h(x)yG)
1626  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1627  */
1628 int
1629 GNUNET_CRYPTO_ecdh_ecdsa (const struct GNUNET_CRYPTO_EcdhePrivateKey *priv,
1630                           const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
1631                           struct GNUNET_HashCode *key_material);
1632
1633
1634 /**
1635  * @ingroup crypto
1636  * EdDSA sign a given block.
1637  *
1638  * @param priv private key to use for the signing
1639  * @param purpose what to sign (size, purpose)
1640  * @param sig where to write the signature
1641  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1642  */
1643 int
1644 GNUNET_CRYPTO_eddsa_sign (const struct GNUNET_CRYPTO_EddsaPrivateKey *priv,
1645                           const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1646                           struct GNUNET_CRYPTO_EddsaSignature *sig);
1647
1648
1649 /**
1650  * @ingroup crypto
1651  * ECDSA Sign a given block.
1652  *
1653  * @param priv private key to use for the signing
1654  * @param purpose what to sign (size, purpose)
1655  * @param sig where to write the signature
1656  * @return #GNUNET_SYSERR on error, #GNUNET_OK on success
1657  */
1658 int
1659 GNUNET_CRYPTO_ecdsa_sign (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1660                           const struct GNUNET_CRYPTO_EccSignaturePurpose *purpose,
1661                           struct GNUNET_CRYPTO_EcdsaSignature *sig);
1662
1663 /**
1664  * @ingroup crypto
1665  * Verify EdDSA signature.
1666  *
1667  * @param purpose what is the purpose that the signature should have?
1668  * @param validate block to validate (size, purpose, data)
1669  * @param sig signature that is being validated
1670  * @param pub public key of the signer
1671  * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
1672  */
1673 int
1674 GNUNET_CRYPTO_eddsa_verify (uint32_t purpose,
1675                             const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
1676                             const struct GNUNET_CRYPTO_EddsaSignature *sig,
1677                             const struct GNUNET_CRYPTO_EddsaPublicKey *pub);
1678
1679
1680
1681 /**
1682  * @ingroup crypto
1683  * Verify ECDSA signature.
1684  *
1685  * @param purpose what is the purpose that the signature should have?
1686  * @param validate block to validate (size, purpose, data)
1687  * @param sig signature that is being validated
1688  * @param pub public key of the signer
1689  * @returns #GNUNET_OK if ok, #GNUNET_SYSERR if invalid
1690  */
1691 int
1692 GNUNET_CRYPTO_ecdsa_verify (uint32_t purpose,
1693                             const struct GNUNET_CRYPTO_EccSignaturePurpose *validate,
1694                             const struct GNUNET_CRYPTO_EcdsaSignature *sig,
1695                             const struct GNUNET_CRYPTO_EcdsaPublicKey *pub);
1696
1697
1698 /**
1699  * @ingroup crypto
1700  * Derive a private key from a given private key and a label.
1701  * Essentially calculates a private key 'h = H(l,P) * d mod n'
1702  * where n is the size of the ECC group and P is the public
1703  * key associated with the private key 'd'.
1704  *
1705  * @param priv original private key
1706  * @param label label to use for key deriviation
1707  * @param context additional context to use for HKDF of 'h';
1708  *        typically the name of the subsystem/application
1709  * @return derived private key
1710  */
1711 struct GNUNET_CRYPTO_EcdsaPrivateKey *
1712 GNUNET_CRYPTO_ecdsa_private_key_derive (const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv,
1713                                         const char *label,
1714                                         const char *context);
1715
1716
1717 /**
1718  * @ingroup crypto
1719  * Derive a public key from a given public key and a label.
1720  * Essentially calculates a public key 'V = H(l,P) * P'.
1721  *
1722  * @param pub original public key
1723  * @param label label to use for key deriviation
1724  * @param context additional context to use for HKDF of 'h'.
1725  *        typically the name of the subsystem/application
1726  * @param result where to write the derived public key
1727  */
1728 void
1729 GNUNET_CRYPTO_ecdsa_public_key_derive (const struct GNUNET_CRYPTO_EcdsaPublicKey *pub,
1730                                        const char *label,
1731                                        const char *context,
1732                                        struct GNUNET_CRYPTO_EcdsaPublicKey *result);
1733
1734
1735 /**
1736  * Output the given MPI value to the given buffer in network
1737  * byte order.  The MPI @a val may not be negative.
1738  *
1739  * @param buf where to output to
1740  * @param size number of bytes in @a buf
1741  * @param val value to write to @a buf
1742  */
1743 void
1744 GNUNET_CRYPTO_mpi_print_unsigned (void *buf,
1745                                   size_t size,
1746                                   gcry_mpi_t val);
1747
1748
1749 /**
1750  * Convert data buffer into MPI value.
1751  * The buffer is interpreted as network
1752  * byte order, unsigned integer.
1753  *
1754  * @param result where to store MPI value (allocated)
1755  * @param data raw data (GCRYMPI_FMT_USG)
1756  * @param size number of bytes in @a data
1757  */
1758 void
1759 GNUNET_CRYPTO_mpi_scan_unsigned (gcry_mpi_t *result,
1760                                  const void *data,
1761                                  size_t size);
1762
1763
1764 /**
1765  * Create a freshly generated paillier public key.
1766  *
1767  * @param[out] public_key Where to store the public key?
1768  * @param[out] private_key Where to store the private key?
1769  */
1770 void
1771 GNUNET_CRYPTO_paillier_create (struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1772                                struct GNUNET_CRYPTO_PaillierPrivateKey *private_key);
1773
1774
1775 /**
1776  * Encrypt a plaintext with a paillier public key.
1777  *
1778  * @param public_key Public key to use.
1779  * @param m Plaintext to encrypt.
1780  * @param desired_ops How many homomorphic ops the caller intends to use
1781  * @param[out] ciphertext Encrytion of @a plaintext with @a public_key.
1782  * @return guaranteed number of supported homomorphic operations >= 1,
1783  *         or desired_ops, in case that is lower,
1784  *         or -1 if less than one homomorphic operation is possible
1785  */
1786 int
1787 GNUNET_CRYPTO_paillier_encrypt (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1788                                 const gcry_mpi_t m,
1789                                 int desired_ops,
1790                                 struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext);
1791
1792
1793 /**
1794  * Decrypt a paillier ciphertext with a private key.
1795  *
1796  * @param private_key Private key to use for decryption.
1797  * @param public_key Public key to use for decryption.
1798  * @param ciphertext Ciphertext to decrypt.
1799  * @param[out] m Decryption of @a ciphertext with @private_key.
1800  */
1801 void
1802 GNUNET_CRYPTO_paillier_decrypt (const struct GNUNET_CRYPTO_PaillierPrivateKey *private_key,
1803                                 const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1804                                 const struct GNUNET_CRYPTO_PaillierCiphertext *ciphertext,
1805                                 gcry_mpi_t m);
1806
1807
1808 /**
1809  * Compute a ciphertext that represents the sum of the plaintext in @a x1 and @a x2
1810  *
1811  * Note that this operation can only be done a finite number of times
1812  * before an overflow occurs.
1813  *
1814  * @param public_key Public key to use for encryption.
1815  * @param c1 Paillier cipher text.
1816  * @param c2 Paillier cipher text.
1817  * @param[out] result Result of the homomorphic operation.
1818  * @return #GNUNET_OK if the result could be computed,
1819  *         #GNUNET_SYSERR if no more homomorphic operations are remaining.
1820  */
1821 int
1822 GNUNET_CRYPTO_paillier_hom_add (const struct GNUNET_CRYPTO_PaillierPublicKey *public_key,
1823                                 const struct GNUNET_CRYPTO_PaillierCiphertext *c1,
1824                                 const struct GNUNET_CRYPTO_PaillierCiphertext *c2,
1825                                 struct GNUNET_CRYPTO_PaillierCiphertext *result);
1826
1827
1828 /**
1829  * Get the number of remaining supported homomorphic operations.
1830  *
1831  * @param c Paillier cipher text.
1832  * @return the number of remaining homomorphic operations
1833  */
1834 int
1835 GNUNET_CRYPTO_paillier_hom_get_remaining (const struct GNUNET_CRYPTO_PaillierCiphertext *c);
1836
1837
1838 /* ********* Chaum-style RSA-based blind signatures ******************* */
1839
1840
1841
1842
1843 /**
1844  * The private information of an RSA key pair.
1845  */
1846 struct GNUNET_CRYPTO_RsaPrivateKey;
1847
1848 /**
1849  * The public information of an RSA key pair.
1850  */
1851 struct GNUNET_CRYPTO_RsaPublicKey;
1852
1853 /**
1854  * Constant-size pre-secret for blinding key generation.
1855  */
1856 struct GNUNET_CRYPTO_RsaBlindingKeySecret
1857 {
1858   /**
1859    * Bits used to generate the blinding key.  256 bits
1860    * of entropy is enough.
1861    */
1862   uint32_t pre_secret[8] GNUNET_PACKED;
1863 };
1864
1865 /**
1866  * @brief an RSA signature
1867  */
1868 struct GNUNET_CRYPTO_RsaSignature;
1869
1870
1871 /**
1872  * Create a new private key. Caller must free return value.
1873  *
1874  * @param len length of the key in bits (i.e. 2048)
1875  * @return fresh private key
1876  */
1877 struct GNUNET_CRYPTO_RsaPrivateKey *
1878 GNUNET_CRYPTO_rsa_private_key_create (unsigned int len);
1879
1880
1881 /**
1882  * Free memory occupied by the private key.
1883  *
1884  * @param key pointer to the memory to free
1885  */
1886 void
1887 GNUNET_CRYPTO_rsa_private_key_free (struct GNUNET_CRYPTO_RsaPrivateKey *key);
1888
1889
1890 /**
1891  * Encode the private key in a format suitable for
1892  * storing it into a file.
1893  *
1894  * @param key the private key
1895  * @param[out] buffer set to a buffer with the encoded key
1896  * @return size of memory allocatedin @a buffer
1897  */
1898 size_t
1899 GNUNET_CRYPTO_rsa_private_key_encode (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
1900                                       char **buffer);
1901
1902
1903 /**
1904  * Decode the private key from the data-format back
1905  * to the "normal", internal format.
1906  *
1907  * @param buf the buffer where the private key data is stored
1908  * @param len the length of the data in @a buf
1909  * @return NULL on error
1910  */
1911 struct GNUNET_CRYPTO_RsaPrivateKey *
1912 GNUNET_CRYPTO_rsa_private_key_decode (const char *buf,
1913                                       size_t len);
1914
1915
1916 /**
1917  * Duplicate the given private key
1918  *
1919  * @param key the private key to duplicate
1920  * @return the duplicate key; NULL upon error
1921  */
1922 struct GNUNET_CRYPTO_RsaPrivateKey *
1923 GNUNET_CRYPTO_rsa_private_key_dup (const struct GNUNET_CRYPTO_RsaPrivateKey *key);
1924
1925
1926 /**
1927  * Extract the public key of the given private key.
1928  *
1929  * @param priv the private key
1930  * @retur NULL on error, otherwise the public key
1931  */
1932 struct GNUNET_CRYPTO_RsaPublicKey *
1933 GNUNET_CRYPTO_rsa_private_key_get_public (const struct GNUNET_CRYPTO_RsaPrivateKey *priv);
1934
1935
1936 /**
1937  * Compute hash over the public key.
1938  *
1939  * @param key public key to hash
1940  * @param hc where to store the hash code
1941  */
1942 void
1943 GNUNET_CRYPTO_rsa_public_key_hash (const struct GNUNET_CRYPTO_RsaPublicKey *key,
1944                                    struct GNUNET_HashCode *hc);
1945
1946
1947 /**
1948  * Obtain the length of the RSA key in bits.
1949  *
1950  * @param key the public key to introspect
1951  * @return length of the key in bits
1952  */
1953 unsigned int
1954 GNUNET_CRYPTO_rsa_public_key_len (const struct GNUNET_CRYPTO_RsaPublicKey *key);
1955
1956
1957 /**
1958  * Free memory occupied by the public key.
1959  *
1960  * @param key pointer to the memory to free
1961  */
1962 void
1963 GNUNET_CRYPTO_rsa_public_key_free (struct GNUNET_CRYPTO_RsaPublicKey *key);
1964
1965
1966 /**
1967  * Encode the public key in a format suitable for
1968  * storing it into a file.
1969  *
1970  * @param key the private key
1971  * @param[out] buffer set to a buffer with the encoded key
1972  * @return size of memory allocated in @a buffer
1973  */
1974 size_t
1975 GNUNET_CRYPTO_rsa_public_key_encode (const struct GNUNET_CRYPTO_RsaPublicKey *key,
1976                                      char **buffer);
1977
1978
1979 /**
1980  * Decode the public key from the data-format back
1981  * to the "normal", internal format.
1982  *
1983  * @param buf the buffer where the public key data is stored
1984  * @param len the length of the data in @a buf
1985  * @return NULL on error
1986  */
1987 struct GNUNET_CRYPTO_RsaPublicKey *
1988 GNUNET_CRYPTO_rsa_public_key_decode (const char *buf,
1989                                      size_t len);
1990
1991
1992 /**
1993  * Duplicate the given public key
1994  *
1995  * @param key the public key to duplicate
1996  * @return the duplicate key; NULL upon error
1997  */
1998 struct GNUNET_CRYPTO_RsaPublicKey *
1999 GNUNET_CRYPTO_rsa_public_key_dup (const struct GNUNET_CRYPTO_RsaPublicKey *key);
2000
2001
2002 /**
2003  * Compare the values of two signatures.
2004  *
2005  * @param s1 one signature
2006  * @param s2 the other signature
2007  * @return 0 if the two are equal
2008  */
2009 int
2010 GNUNET_CRYPTO_rsa_signature_cmp (struct GNUNET_CRYPTO_RsaSignature *s1,
2011                                  struct GNUNET_CRYPTO_RsaSignature *s2);
2012
2013 /**
2014  * Compare the values of two private keys.
2015  *
2016  * @param p1 one private key
2017  * @param p2 the other private key
2018  * @return 0 if the two are equal
2019  */
2020 int
2021 GNUNET_CRYPTO_rsa_private_key_cmp (struct GNUNET_CRYPTO_RsaPrivateKey *p1,
2022                                   struct GNUNET_CRYPTO_RsaPrivateKey *p2);
2023
2024
2025 /**
2026  * Compare the values of two public keys.
2027  *
2028  * @param p1 one public key
2029  * @param p2 the other public key
2030  * @return 0 if the two are equal
2031  */
2032 int
2033 GNUNET_CRYPTO_rsa_public_key_cmp (struct GNUNET_CRYPTO_RsaPublicKey *p1,
2034                                   struct GNUNET_CRYPTO_RsaPublicKey *p2);
2035
2036
2037 /**
2038  * Blinds the given message with the given blinding key
2039  *
2040  * @param hash hash of the message to sign
2041  * @param bkey the blinding key
2042  * @param pkey the public key of the signer
2043  * @param[out] buf set to a buffer with the blinded message to be signed
2044  * @param[out] buf_size number of bytes stored in @a buf
2045  * @return #GNUNET_YES if successful, #GNUNET_NO if RSA key is malicious
2046  */
2047 int
2048 GNUNET_CRYPTO_rsa_blind (const struct GNUNET_HashCode *hash,
2049                          const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
2050                          struct GNUNET_CRYPTO_RsaPublicKey *pkey,
2051                          char **buf,
2052                          size_t *buf_size);
2053
2054
2055 /**
2056  * Sign a blinded value, which must be a full domain hash of a message.
2057  *
2058  * @param key private key to use for the signing
2059  * @param msg the (blinded) message to sign
2060  * @param msg_len number of bytes in @a msg to sign
2061  * @return NULL on error, signature on success
2062  */
2063 struct GNUNET_CRYPTO_RsaSignature *
2064 GNUNET_CRYPTO_rsa_sign_blinded (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2065                                 const void *msg,
2066                                 size_t msg_len);
2067
2068
2069 /**
2070  * Create and sign a full domain hash of a message.
2071  *
2072  * @param key private key to use for the signing
2073  * @param hash the hash of the message to sign
2074  * @return NULL on error, including a malicious RSA key, signature on success
2075  */
2076 struct GNUNET_CRYPTO_RsaSignature *
2077 GNUNET_CRYPTO_rsa_sign_fdh (const struct GNUNET_CRYPTO_RsaPrivateKey *key,
2078                             const struct GNUNET_HashCode *hash);
2079
2080
2081 /**
2082  * Free memory occupied by signature.
2083  *
2084  * @param sig memory to free
2085  */
2086 void
2087 GNUNET_CRYPTO_rsa_signature_free (struct GNUNET_CRYPTO_RsaSignature *sig);
2088
2089
2090 /**
2091  * Encode the given signature in a format suitable for storing it into a file.
2092  *
2093  * @param sig the signature
2094  * @param[out] buffer set to a buffer with the encoded key
2095  * @return size of memory allocated in @a buffer
2096  */
2097 size_t
2098 GNUNET_CRYPTO_rsa_signature_encode (const struct GNUNET_CRYPTO_RsaSignature *sig,
2099                                     char **buffer);
2100
2101
2102 /**
2103  * Decode the signature from the data-format back to the "normal", internal
2104  * format.
2105  *
2106  * @param buf the buffer where the public key data is stored
2107  * @param len the length of the data in @a buf
2108  * @return NULL on error
2109  */
2110 struct GNUNET_CRYPTO_RsaSignature *
2111 GNUNET_CRYPTO_rsa_signature_decode (const char *buf,
2112                                     size_t len);
2113
2114
2115 /**
2116  * Duplicate the given rsa signature
2117  *
2118  * @param sig the signature to duplicate
2119  * @return the duplicate key; NULL upon error
2120  */
2121 struct GNUNET_CRYPTO_RsaSignature *
2122 GNUNET_CRYPTO_rsa_signature_dup (const struct GNUNET_CRYPTO_RsaSignature *sig);
2123
2124
2125 /**
2126  * Unblind a blind-signed signature.  The signature should have been generated
2127  * with #GNUNET_CRYPTO_rsa_sign() using a hash that was blinded with
2128  * #GNUNET_CRYPTO_rsa_blind().
2129  *
2130  * @param sig the signature made on the blinded signature purpose
2131  * @param bks the blinding key secret used to blind the signature purpose
2132  * @param pkey the public key of the signer
2133  * @return unblinded signature on success, NULL if RSA key is bad or malicious.
2134  */
2135 struct GNUNET_CRYPTO_RsaSignature *
2136 GNUNET_CRYPTO_rsa_unblind (const struct GNUNET_CRYPTO_RsaSignature *sig,
2137                            const struct GNUNET_CRYPTO_RsaBlindingKeySecret *bks,
2138                            struct GNUNET_CRYPTO_RsaPublicKey *pkey);
2139
2140
2141 /**
2142  * Verify whether the given hash corresponds to the given signature and the
2143  * signature is valid with respect to the given public key.
2144  *
2145  * @param hash the message to verify to match the @a sig
2146  * @param sig signature that is being validated
2147  * @param public_key public key of the signer
2148  * @returns #GNUNET_YES if ok, #GNUNET_NO if RSA key is malicious, #GNUNET_SYSERR if signature
2149  */
2150 int
2151 GNUNET_CRYPTO_rsa_verify (const struct GNUNET_HashCode *hash,
2152                           const struct GNUNET_CRYPTO_RsaSignature *sig,
2153                           const struct GNUNET_CRYPTO_RsaPublicKey *public_key);
2154
2155
2156 #if 0                           /* keep Emacsens' auto-indent happy */
2157 {
2158 #endif
2159 #ifdef __cplusplus
2160 }
2161 #endif
2162
2163
2164 /* ifndef GNUNET_CRYPTO_LIB_H */
2165 #endif
2166 /* end of gnunet_crypto_lib.h */