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