Rewrote crypto library init/uninit. Added silc_crypto_init
[silc.git] / lib / silccrypt / silcpkcs.h
1 /*
2
3   silcpkcs.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2007 Pekka Riikonen
8
9   This program is free software; you can redistribute it and/or modify
10   it under the terms of the GNU General Public License as published by
11   the Free Software Foundation; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 /****h* silccrypt/SILC PKCS Interface
21  *
22  * DESCRIPTION
23  *
24  * SILC PKCS API provides generic interface for performing various
25  * public key cryptography related operations with different types of
26  * public and private keys.  Support for loading and saving of different
27  * types of public key and private keys are also provided.
28  *
29  ***/
30
31 #ifndef SILCPKCS_H
32 #define SILCPKCS_H
33
34 /* Forward declarations */
35 typedef struct SilcPKCSAlgorithmStruct SilcPKCSAlgorithm;
36 typedef struct SilcPKCSObjectStruct SilcPKCSObject;
37
38 /****d* silccrypt/SilcPKCSAPI/SilcPKCSType
39  *
40  * NAME
41  *
42  *    typedef enum { ... } SilcPKCSType;
43  *
44  * DESCRIPTION
45  *
46  *    Supported public key cryptosystem types.
47  *
48  * SOURCE
49  */
50 typedef enum {
51   SILC_PKCS_SILC    = 1,        /* SILC PKCS */
52   SILC_PKCS_SSH2    = 2,        /* SSH2 PKCS (not supported) */
53   SILC_PKCS_X509V3  = 3,        /* X.509v3 PKCS (not supported) */
54   SILC_PKCS_OPENPGP = 4,        /* OpenPGP PKCS (not supported) */
55   SILC_PKCS_SPKI    = 5,        /* SPKI PKCS (not supported) */
56 } SilcPKCSType;
57 /***/
58
59 /****s* silccrypt/SilcPKCSAPI/SilcPublicKey
60  *
61  * NAME
62  *
63  *    typedef struct { ... } *SilcPublicKey;
64  *
65  * DESCRIPTION
66  *
67  *    This context represents any kind of PKCS public key.  It can be
68  *    allocated by silc_pkcs_public_key_alloc and is freed by the
69  *    silc_pkcs_public_key_free.  The PKCS specific public key context
70  *    can be retrieved by calling silc_pkcs_get_context.
71  *
72  * SOURCE
73  */
74 typedef struct SilcPublicKeyStruct {
75   const SilcPKCSObject *pkcs;   /* PKCS */
76   void *public_key;             /* PKCS specific public key */
77 } *SilcPublicKey;
78 /***/
79
80 /****s* silccrypt/SilcPKCSAPI/SilcPrivateKey
81  *
82  * NAME
83  *
84  *    typedef struct { ... } *SilcPrivateKey;
85  *
86  * DESCRIPTION
87  *
88  *    This context represents any kind of PKCS private key.
89  *
90  * SOURCE
91  */
92 typedef struct SilcPrivateKeyStruct {
93   const SilcPKCSObject *pkcs;   /* PKCS */
94   void *private_key;            /* PKCS specific private key */
95 } *SilcPrivateKey;
96 /***/
97
98 /****d* silccrypt/SilcPKCSAPI/SilcPKCSFileEncoding
99  *
100  * NAME
101  *
102  *    typedef enum { ... } SilcPKCSType
103  *
104  * DESCRIPTION
105  *
106  *    Public and private key file encoding types.
107  *
108  * SOURCE
109  */
110 typedef enum {
111   SILC_PKCS_FILE_BIN,           /* Binary encoding */
112   SILC_PKCS_FILE_BASE64         /* Base64 encoding */
113 } SilcPKCSFileEncoding;
114 /***/
115
116 /****f* silccrypt/SilcPKCSAPI/SilcPKCSEncryptCb
117  *
118  * SYNOPSIS
119  *
120  *    typedef void (*SilcPKCSEncryptCb)(SilcBool success,
121  *                                      const unsigned char *encrypted,
122  *                                      SilcUInt32 encrypted_len,
123  *                                      void *context);
124  *
125  * DESCRIPTION
126  *
127  *    Encryption callback.  This callback is given as argument to the
128  *    silc_pkcs_encrypt and the encrypted data is delivered to the caller
129  *    in this callback.  The `encrypted' is the encrypted data.  If the
130  *    `success' is FALSE the encryption operation failed.
131  *
132  ***/
133 typedef void (*SilcPKCSEncryptCb)(SilcBool success,
134                                   const unsigned char *encrypted,
135                                   SilcUInt32 encrypted_len,
136                                   void *context);
137
138 /****f* silccrypt/SilcPKCSAPI/SilcPKCSDecryptCb
139  *
140  * SYNOPSIS
141  *
142  *    typedef void (*SilcPKCSDecryptCb)(SilcBool success,
143  *                                      const unsigned char *decrypted,
144  *                                      SilcUInt32 decrypted_len,
145  *                                      void *context);
146  *
147  * DESCRIPTION
148  *
149  *    Decryption callback.  This callback is given as argument to the
150  *    silc_pkcs_decrypt and the decrypted data is delivered to the caller
151  *    in this callback.  The `decrypted' is the decrypted data.  If the
152  *    `success' is FALSE the decryption operation failed.
153  *
154  ***/
155 typedef void (*SilcPKCSDecryptCb)(SilcBool success,
156                                   const unsigned char *decrypted,
157                                   SilcUInt32 decrypted_len,
158                                   void *context);
159
160 /****f* silccrypt/SilcPKCSAPI/SilcPKCSSignCb
161  *
162  * SYNOPSIS
163  *
164  *    typedef void (*SilcPKCSSignCb)(SilcBool success,
165  *                                   const unsigned char *signature,
166  *                                   SilcUInt32 signature_len,
167  *                                   void *context);
168  *
169  * DESCRIPTION
170  *
171  *    Signature callback.  This callback is given as argument to the
172  *    silc_pkcs_sign and the digitally signed data is delivered to the caller
173  *    in this callback.  The `signature' is the signature data.  If the
174  *    `success' is FALSE the signature operation failed.
175  *
176  ***/
177 typedef void (*SilcPKCSSignCb)(SilcBool success,
178                                const unsigned char *signature,
179                                SilcUInt32 signature_len,
180                                void *context);
181
182 /****f* silccrypt/SilcPKCSAPI/SilcPKCSVerifyCb
183  *
184  * SYNOPSIS
185  *
186  *    typedef void (*SilcPKCSVerifyCb)(SilcBool success, void *context);
187  *
188  * DESCRIPTION
189  *
190  *    Verification callback.  This callback is given as argument to the
191  *    silc_pkcs_verify and the result of the signature verification is
192  *    deliver to the caller in this callback.  If the `success' is FALSE
193  *    the signature verification failed.
194  *
195  ***/
196 typedef void (*SilcPKCSVerifyCb)(SilcBool success, void *context);
197
198 #include "silcpkcs_i.h"
199
200 /* Marks for all PKCS in. This can be used in silc_pkcs_unregister to
201    unregister all PKCS at once. */
202 #define SILC_ALL_PKCS ((SilcPKCSObject *)1)
203 #define SILC_ALL_PKCS_ALG ((SilcPKCSAlgorithm *)1)
204
205 /* Static lists of PKCS and PKCS algorithms. */
206 extern DLLAPI const SilcPKCSObject silc_default_pkcs[];
207 extern DLLAPI const SilcPKCSAlgorithm silc_default_pkcs_alg[];
208
209 /* Prototypes */
210
211 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register
212  *
213  * SYNOPSIS
214  *
215  *    SilcBool silc_pkcs_register(const SilcPKCSObject *pkcs);
216  *
217  * DESCRIPTION
218  *
219  *    Registers a new PKCS into the crypto library.  This function is used
220  *    at the initialization of an application.  All registered PKCSs
221  *    should be unregistered with silc_pkcs_unregister.  The `pkcs' includes
222  *    the name of the PKCS and member functions for the algorithm.  Usually
223  *    this function is not called directly.  Instead, application can call
224  *    the silc_pkcs_register_default to register all PKCSs that are
225  *    builtin the sources.  Returns FALSE on error.
226  *
227  ***/
228 SilcBool silc_pkcs_register(const SilcPKCSObject *pkcs);
229
230 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister
231  *
232  * SYNOPSIS
233  *
234  *    SilcBool silc_pkcs_unregister(SilcPKCSObject *pkcs);
235  *
236  * DESCRIPTION
237  *
238  *    Unregister a PKCS from the crypto library. Returns FALSE on error.
239  *
240  ***/
241 SilcBool silc_pkcs_unregister(SilcPKCSObject *pkcs);
242
243 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_algorithm_register
244  *
245  * SYNOPSIS
246  *
247  *    SilcBool silc_pkcs_algorithm_register(const SilcPKCSAlgorithm *pkcs);
248  *
249  * DESCRIPTION
250  *
251  *    Registers a new PKCS Algorithm into crypto library.  This function
252  *    is used at the initialization of an application.  All registered PKCS
253 *     algorithms should be unregistered with silc_pkcs_unregister.
254  *
255  ***/
256 SilcBool silc_pkcs_algorithm_register(const SilcPKCSAlgorithm *pkcs);
257
258 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_algorithm_unregister
259  *
260  * SYNOPSIS
261  *
262  *    SilcBool silc_pkcs_algorithm_unregister(SilcPKCSAlgorithm *pkcs);
263  *
264  * DESCRIPTION
265  *
266  *    Unregister a PKCS from the crypto library. Returns FALSE on error.
267  *
268  ***/
269 SilcBool silc_pkcs_algorithm_unregister(SilcPKCSAlgorithm *pkcs);
270
271 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register_default
272  *
273  * SYNOPSIS
274  *
275  *    SilcBool silc_pkcs_register_default(void);
276  *
277  * DESCRIPTION
278  *
279  *    Registers all the default PKCS (all builtin PKCS) and PKCS algorithms.
280  *    The application may use this to register the default PKCS if specific
281  *    PKCS in any specific order is not wanted.  Returns FALSE on error.
282  *
283  ***/
284 SilcBool silc_pkcs_register_default(void);
285
286 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister_all
287  *
288  * SYNOPSIS
289  *
290  *    SilcBool silc_pkcs_unregister_all(void);
291  *
292  * DESCRIPTION
293  *
294  *    Unregister all PKCS and PKCS algorithms. Returns FALSE on error.
295  *
296  ***/
297 SilcBool silc_pkcs_unregister_all(void);
298
299 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_supported
300  *
301  * SYNOPSIS
302  *
303  *    char *silc_pkcs_get_supported(void);
304  *
305  * DESCRIPTION
306  *
307  *    Returns comma separated list of supported PKCS algorithms.
308  *
309  ***/
310 char *silc_pkcs_get_supported(void);
311
312 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_find_pkcs
313  *
314  * SYNOPSIS
315  *
316  *    const SilcPKCSObject *silc_pkcs_get_pkcs(SilcPKCSType type);
317  *
318  * DESCRIPTION
319  *
320  *    Finds PKCS context by the PKCS type.
321  *
322  ***/
323 const SilcPKCSObject *silc_pkcs_find_pkcs(SilcPKCSType type);
324
325 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_find_algorithm
326  *
327  * SYNOPSIS
328  *
329  *    const SilcPKCSAlgorithm *silc_pkcs_find_algorithm(const char *algorithm,
330  *                                                      const char *scheme);
331  *
332  * DESCRIPTION
333  *
334  *    Finds PKCS algorithm context by the algorithm name `algorithm' and
335  *    the algorithm scheme `scheme'.  The `scheme' may be NULL.
336  *
337  ***/
338 const SilcPKCSAlgorithm *silc_pkcs_find_algorithm(const char *algorithm,
339                                                   const char *scheme);
340
341 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_pkcs
342  *
343  * SYNOPSIS
344  *
345  *    const SilcPKCSObject *silc_pkcs_get_pkcs(void *key);
346  *
347  * DESCRIPTION
348  *
349  *    Returns the PKCS object from `key', which may be SilcPublicKey or
350  *    SilcPrivateKey pointer.
351  *
352  ***/
353 const SilcPKCSObject *silc_pkcs_get_pkcs(void *key);
354
355 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_algorithm
356  *
357  * SYNOPSIS
358  *
359  *    const SilcPKCSAlgorithm *silc_pkcs_get_algorithm(void *key);
360  *
361  * DESCRIPTION
362  *
363  *    Returns the PKCS algorithm object from `key', which may be SilcPublicKey
364  *    or SilcPrivateKey pointer.
365  *
366  ***/
367 const SilcPKCSAlgorithm *silc_pkcs_get_algorithm(void *key);
368
369 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_name
370  *
371  * SYNOPSIS
372  *
373  *    const char *silc_pkcs_get_name(void *key);
374  *
375  * DESCRIPTION
376  *
377  *    Returns PKCS algorithm name from the `key', which may be SilcPublicKey
378  *    or SilcPrivateKey pointer.
379  *
380  ***/
381 const char *silc_pkcs_get_name(void *key);
382
383 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_type
384  *
385  * SYNOPSIS
386  *
387  *    SilcPKCSType silc_pkcs_get_type(void *key);
388  *
389  * DESCRIPTION
390  *
391  *    Returns PKCS type from the `key', which may be SilcPublicKey or
392  *    SilcPrivateKey pointer.
393  *
394  ***/
395 SilcPKCSType silc_pkcs_get_type(void *key);
396
397 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_context
398  *
399  * SYNOPSIS
400  *
401  *    void *silc_pkcs_get_context(SilcPKCSType type, SilcPublicKey public_key);
402  *
403  * DESCRIPTION
404  *
405  *    Returns the internal PKCS `type' specific public key context from the
406  *    `public_key'.  The caller needs to explicitly type cast it to correct
407  *    type.  Returns NULL on error.
408  *
409  *    For SILC_PKCS_SILC the returned context is SilcSILCPublicKey.
410  *
411  ***/
412 void *silc_pkcs_get_context(SilcPKCSType type, SilcPublicKey public_key);
413
414 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_alloc
415  *
416  * SYNOPSIS
417  *
418  *    SilcBool silc_pkcs_public_key_alloc(SilcPKCSType type,
419  *                                        unsigned char *key,
420  *                                        SilcUInt32 key_len
421  *                                        SilcPublicKey *ret_public_key);
422  *
423  * DESCRIPTION
424  *
425  *    Allocates SilcPublicKey of the type of `type' from the key data
426  *    `key' of length of `key_len' bytes.  Returns FALSE if the `key'
427  *    is malformed or unsupported public key type.  This function can be
428  *    used to create public key from any kind of PKCS public keys that
429  *    the implementation supports.
430  *
431  ***/
432 SilcBool silc_pkcs_public_key_alloc(SilcPKCSType type,
433                                     unsigned char *key,
434                                     SilcUInt32 key_len,
435                                     SilcPublicKey *ret_public_key);
436
437 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_free
438  *
439  * SYNOPSIS
440  *
441  *    void silc_pkcs_public_key_free(SilcPublicKey public_key);
442  *
443  * DESCRIPTION
444  *
445  *    Frees the public key.
446  *
447  ***/
448 void silc_pkcs_public_key_free(SilcPublicKey public_key);
449
450 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_export
451  *
452  * SYNOPSIS
453  *
454  *    unsigned char *silc_pkcs_public_key_encode(SilcStack stack,
455  *                                               SilcPublicKey public_key,
456  *                                               SilcUInt32 *ret_len);
457  *
458  * DESCRIPTION
459  *
460  *    Encodes the `public_key' into a binary format and returns it.  Returns
461  *    NULL on error.  Caller must free the returned buffer.
462  *
463  *    If the `stack' is non-NULL the returned buffer is allocated from the
464  *    `stack'.  This call will consume `stack' so caller should push the stack
465  *    before calling and then later pop it.
466  *
467  ***/
468 unsigned char *silc_pkcs_public_key_encode(SilcStack stack,
469                                            SilcPublicKey public_key,
470                                            SilcUInt32 *ret_len);
471
472 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_get_len
473  *
474  * SYNOPSIS
475  *
476  *    SilcUInt32 silc_pkcs_public_key_get_len(SilcPublicKey public_key);
477  *
478  * DESCRIPTION
479  *
480  *    Returns the key length in bits from the public key.
481  *
482  ***/
483 SilcUInt32 silc_pkcs_public_key_get_len(SilcPublicKey public_key);
484
485 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_compare
486  *
487  * SYNOPSIS
488  *
489  *    SilcBool silc_pkcs_public_key_compare(SilcPublicKey key1,
490  *                                          SilcPublicKey key2);
491  *
492  * DESCRIPTION
493  *
494  *    Compares two public keys and returns TRUE if they are same key, and
495  *    FALSE if they are not same.
496  *
497  ***/
498 SilcBool silc_pkcs_public_key_compare(SilcPublicKey key1, SilcPublicKey key2);
499
500 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_copy
501  *
502  * SYNOPSIS
503  *
504  *    SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
505  *
506  * DESCRIPTION
507  *
508  *    Copies the public key indicated by `public_key' and returns new
509  *    allocated public key which is indentical to the `public_key'.
510  *
511  ***/
512 SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
513
514 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_alloc
515  *
516  * SYNOPSIS
517  *
518  *    SilcBool silc_pkcs_private_key_alloc(SilcPKCSType type,
519  *                                         unsigned char *key,
520  *                                         SilcUInt32 key_len,
521  *                                         SilcPrivateKey *ret_private_key);
522  *
523  * DESCRIPTION
524  *
525  *    Allocates SilcPrivateKey of the type of `type' from the key data
526  *    `key' of length of `key_len' bytes.  Returns FALSE if the `key'
527  *    is malformed or unsupported private key type.
528  *
529  ***/
530 SilcBool silc_pkcs_private_key_alloc(SilcPKCSType type,
531                                      unsigned char *key,
532                                      SilcUInt32 key_len,
533                                      SilcPrivateKey *ret_private_key);
534
535 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_get_len
536  *
537  * SYNOPSIS
538  *
539  *    SilcUInt32 silc_pkcs_private_key_get_len(SilcPrivateKey private_key);
540  *
541  * DESCRIPTION
542  *
543  *    Returns the key length in bits from the private key.
544  *
545  ***/
546 SilcUInt32 silc_pkcs_private_key_get_len(SilcPrivateKey private_key);
547
548 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_free
549  *
550  * SYNOPSIS
551  *
552  *    void silc_pkcs_private_key_free(SilcPrivateKey private_key;
553  *
554  * DESCRIPTION
555  *
556  *    Frees the private key.
557  *
558  ***/
559 void silc_pkcs_private_key_free(SilcPrivateKey private_key);
560
561 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encrypt
562  *
563  * SYNOPSIS
564  *
565  *    SilcAsyncOperation silc_pkcs_encrypt(SilcPublicKey public_key,
566  *                                         unsigned char *src,
567  *                                         SilcUInt32 src_len, SilcRng rng,
568  *                                         SilcPKCSEncryptCb encrypt_cb,
569  *                                         void *context);
570  *
571  * DESCRIPTION
572  *
573  *    Encrypts with the public key.  The `encrypt_cb' will be called to
574  *    deliver the encrypted data.  The encryption operation may be asynchronous
575  *    if the `public_key' is accelerated public key.  If this returns NULL
576  *    the asynchronous operation cannot be controlled.
577  *
578  ***/
579 SilcAsyncOperation silc_pkcs_encrypt(SilcPublicKey public_key,
580                                      unsigned char *src,
581                                      SilcUInt32 src_len, SilcRng rng,
582                                      SilcPKCSEncryptCb encrypt_cb,
583                                      void *context);
584
585 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt
586  *
587  * SYNOPSIS
588  *
589  *    SilcAsyncOperation silc_pkcs_decrypt(SilcPrivateKey private_key,
590  *                                         unsigned char *src,
591  *                                         SilcUInt32 src_len,
592  *                                         SilcPKCSDecryptCb decrypt_cb,
593  *                                         void *context);
594  *
595  * DESCRIPTION
596  *
597  *    Decrypts with the private key.  The `decrypt_cb' will be called to
598  *    deliver the decrypted data.  The decryption operation may be asynchronous
599  *    if the `private_key' is accelerated private key.  If this returns NULL
600  *    the asynchronous operation cannot be controlled.
601  *
602  ***/
603 SilcAsyncOperation silc_pkcs_decrypt(SilcPrivateKey private_key,
604                                      unsigned char *src, SilcUInt32 src_len,
605                                      SilcPKCSDecryptCb decrypt_cb,
606                                      void *context);
607
608 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign
609  *
610  * SYNOPSIS
611  *
612  *    SilcAsyncOperation silc_pkcs_sign(SilcPrivateKey private_key,
613  *                                      unsigned char *src,
614  *                                      SilcUInt32 src_len,
615  *                                      SilcBool compute_hash,
616  *                                      SilcHash hash,
617  *                                      SilcPKCSSignCb sign_cb,
618  *                                      void *context);
619  *
620  * DESCRIPTION
621  *
622  *    Computes signature with the private key.  The `sign_cb' will be called
623  *    to deliver the signature data.  If `compute_hash' is TRUE the `hash'
624  *    will be used to compute a message digest over the `src'.  The `hash'
625  *    must always be valid.  The signature operation may be asynchronous if
626  *    the `private_key' is accelerated private key.  If this returns NULL the
627  *    asynchronous operation cannot be controlled.
628  *
629  ***/
630 SilcAsyncOperation silc_pkcs_sign(SilcPrivateKey private_key,
631                                   unsigned char *src,
632                                   SilcUInt32 src_len,
633                                   SilcBool compute_hash,
634                                   SilcHash hash,
635                                   SilcPKCSSignCb sign_cb,
636                                   void *context);
637
638 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify
639  *
640  * SYNOPSIS
641  *
642  *    SilcAsyncOperation silc_pkcs_verify(SilcPublicKey public_key,
643  *                                        unsigned char *signature,
644  *                                        SilcUInt32 signature_len,
645  *                                        unsigned char *data,
646  *                                        SilcUInt32 data_len,
647  *                                        SilcHash hash,
648  *                                        SilcPKCSVerifyCb verify_cb,
649  *                                        void *context);
650  *
651  * DESCRIPTION
652  *
653  *    Verifies signature.  The `verify_cb' will be called to deliver the
654  *    result of the verification process.  The 'signature' is verified against
655  *    the 'data'.  If the `hash' is non-NULL then the `data' will hashed
656  *    before verification.  If the `hash' is NULL, then the hash algorithm
657  *    to be used is retrieved from the signature.  If it isn't present in the
658  *    signature the verification is done as is without hashing.  If this
659  *    returns NULL the asynchronous operation cannot be controlled.
660  *
661  ***/
662 SilcAsyncOperation silc_pkcs_verify(SilcPublicKey public_key,
663                                     unsigned char *signature,
664                                     SilcUInt32 signature_len,
665                                     unsigned char *data,
666                                     SilcUInt32 data_len,
667                                     SilcHash hash,
668                                     SilcPKCSVerifyCb verify_cb,
669                                     void *context);
670
671 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_public_key
672  *
673  * SYNOPSIS
674  *
675  *    SilcBool silc_pkcs_load_public_key(const char *filename,
676  *                                       SilcPublicKey *ret_public_key);
677  *
678  * DESCRIPTION
679  *
680  *    Loads public key from file and allocates new public key.  Returns TRUE
681  *    if loading was successful.
682  *
683  ***/
684 SilcBool silc_pkcs_load_public_key(const char *filename,
685                                    SilcPublicKey *ret_public_key);
686
687 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key
688  *
689  * SYNOPSIS
690  *
691  *    SilcBool silc_pkcs_save_public_key(const char *filename,
692  *                                       SilcPublicKey public_key,
693  *                                       SilcPKCSFileEncoding encoding);
694  *
695  * DESCRIPTION
696  *
697  *    Saves public key into file with specified encoding.  Returns FALSE
698  *    on error.
699  *
700  ***/
701 SilcBool silc_pkcs_save_public_key(const char *filename,
702                                    SilcPublicKey public_key,
703                                    SilcPKCSFileEncoding encoding);
704
705 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_private_key
706  *
707  * SYNOPSIS
708  *
709  *    SilcBool silc_pkcs_load_private_key(const char *filename,
710  *                                        const unsigned char *passphrase,
711  *                                        SilcUInt32 passphrase_len,
712  *                                        SilcPrivateKey *ret_private_key);
713  *
714  * DESCRIPTION
715  *
716  *    Loads private key from file and allocates new private key.  Returns TRUE
717  *    if loading was successful.  The `passphrase' is used as decryption
718  *    key of the private key file, in case it is encrypted.
719  *
720  ***/
721 SilcBool silc_pkcs_load_private_key(const char *filename,
722                                     const unsigned char *passphrase,
723                                     SilcUInt32 passphrase_len,
724                                     SilcPrivateKey *ret_private_key);
725
726 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key
727  *
728  * SYNOPSIS
729  *
730  *    SilcBool silc_pkcs_save_private_key(const char *filename,
731  *                                        SilcPrivateKey private_key,
732  *                                        const unsigned char *passphrase,
733  *                                        SilcUInt32 passphrase_len,
734  *                                        SilcPKCSFileEncoding encoding,
735  *                                        SilcRng rng);
736  *
737  * DESCRIPTION
738  *
739  *    Saves private key into file.  The private key is encrypted into
740  *    the file with the `passphrase' as a key, if PKCS supports encrypted
741  *    private keys.  Returns FALSE on error.
742  *
743  ***/
744 SilcBool silc_pkcs_save_private_key(const char *filename,
745                                     SilcPrivateKey private_key,
746                                     const unsigned char *passphrase,
747                                     SilcUInt32 passphrase_len,
748                                     SilcPKCSFileEncoding encoding,
749                                     SilcRng rng);
750
751 /****f* silccrypt/SilcPKCSAPI/silc_hash_public_key
752  *
753  * SYNOPSIS
754  *
755  *    SilcUInt32 silc_hash_public_key(void *key, void *user_context);
756  *
757  * DESCRIPTION
758  *
759  *    An utility function for hashing public key for SilcHashTable.  Give
760  *    this as argument as the hash function for SilcHashTable.
761  *
762  ***/
763 SilcUInt32 silc_hash_public_key(void *key, void *user_context);
764
765 /****f* silccrypt/SilcPKCSAPI/silc_hash_public_key_compare
766  *
767  * SYNOPSIS
768  *
769  *    SilcBool silc_hash_public_key_compare(void *key1, void *key2,
770  *                                          void *user_context);
771  *
772  * DESCRIPTION
773  *
774  *    An utility function for comparing public keys for SilcHashTable.  Give
775  *    this as argument as the compare function for SilcHashTable.
776  *
777  ***/
778 SilcBool silc_hash_public_key_compare(void *key1, void *key2,
779                                       void *user_context);
780
781 #endif  /* !SILCPKCS_H */