ROBODoc documented. A patch by Ville Räsänen.
[silc.git] / lib / silccrypt / silcpkcs.h
1 /*
2
3   silcpkcs.h 
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2002 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 #ifndef SILCPKCS_H
21 #define SILCPKCS_H
22
23 /****h* silccrypt/SILC PKCS Interface
24  *
25  * DESCRIPTION
26  *
27  *    This is the interface for public key cryptosystems, and various
28  *    utility functions related to public keys and private keys.  This
29  *    interface also defines the actual PKCS objects, public keys and
30  *    private keys.  The interface is generic PKCS interface, which has
31  *    capability of supporting any kind of public key algorithm.  This
32  *    interface also implements the SILC Public Key and routines for
33  *    encoding and decoding SILC Public Key (as defined by the SILC
34  *    protocol specification).  Interface or encrypting, decrypting,
35  *    producing digital signatures and verifying digital signatures are
36  *    also defined in this header.
37  *
38  ***/
39
40 /****s* silccrypt/SilcPKCSAPI/SilcPKCS
41  *
42  * NAME
43  * 
44  *    typedef struct SilcPKCSStruct *SilcPKCS;
45  *
46  * DESCRIPTION
47  *
48  *    This context is the actual PKCS context and is allocated
49  *    by silc_pkcs_alloc and given as argument usually to all
50  *    silc_pkcs _* functions.  It is freed by the silc_pkcs_free
51  *    function.
52  *
53  ***/
54 typedef struct SilcPKCSStruct *SilcPKCS;
55
56 /* The default SILC PKCS (Public Key Cryptosystem) object to represent
57    any PKCS in SILC. */
58 typedef struct SilcPKCSObjectStruct {
59   char *name;
60   int (*init)(void *, SilcUInt32, SilcRng);
61   void (*clear_keys)(void *);
62   unsigned char *(*get_public_key)(void *, SilcUInt32 *);
63   unsigned char *(*get_private_key)(void *, SilcUInt32 *);
64   SilcUInt32 (*set_public_key)(void *, unsigned char *, SilcUInt32);
65   SilcUInt32 (*set_private_key)(void *, unsigned char *, SilcUInt32);
66   SilcUInt32 (*context_len)();
67   int (*encrypt)(void *, unsigned char *, SilcUInt32,
68                  unsigned char *, SilcUInt32 *);
69   int (*decrypt)(void *, unsigned char *, SilcUInt32,
70                  unsigned char *, SilcUInt32 *);
71   int (*sign)(void *, unsigned char *, SilcUInt32,
72               unsigned char *, SilcUInt32 *);
73   int (*verify)(void *, unsigned char *, SilcUInt32,
74                 unsigned char *, SilcUInt32);
75 } SilcPKCSObject;
76
77 /****s* silccrypt/SilcPKCSAPI/SilcPublicKey
78  *
79  * NAME
80  * 
81  *    typedef struct { ... } *SilcPublicKey;
82  *
83  * DESCRIPTION
84  *
85  *    SILC style public key object.  Public key is read from file to this
86  *    object.  Public keys received from network must be in this format as 
87  *    well.  The format is defined by the SILC protocol specification.
88  *    This object is allocated by silc_pkcs_public_key_alloc and freed
89  *    by silc_pkcs_public_key_free.  The object is given as argument to
90  *    all silc_pkcs_public_key_* functions.
91  *
92  * SOURCE
93  */
94 typedef struct {
95   SilcUInt32 len;
96   char *name;
97   char *identifier;
98   unsigned char *pk;
99   SilcUInt32 pk_len;
100 } *SilcPublicKey;
101 /***/
102
103 /****s* silccrypt/SilcPKCSAPI/SilcPublicKeyIdentifier
104  *
105  * NAME
106  * 
107  *    typedef struct { ... } *SilcPublicKeyIdentifier;
108  *
109  * DESCRIPTION
110  *
111  *    Decoded SILC Public Key identifier.  Note that some of the fields 
112  *    may be NULL.  This context is allcated by the function
113  *    silc_pkcs_decode_identifier and freed by silc_pkcs_free_identifier.
114  *    The identifier in SilcPublicKey is the 'identifier' field, which
115  *    can be given as argument to silc_pkcs_decode_identifier.
116  *
117  * SOURCE
118  */
119 typedef struct {
120   char *username;
121   char *host;
122   char *realname;
123   char *email;
124   char *org;
125   char *country;
126 } *SilcPublicKeyIdentifier;
127 /***/
128
129 /****s* silccrypt/SilcPKCSAPI/SilcPrivateKey
130  *
131  * NAME
132  * 
133  *    typedef struct { ... } *SilcPrivateKey;
134  *
135  * DESCRIPTION
136  *
137  *    SILC style private key object.  Public key is read from file to this
138  *    object.  This object is allocated by silc_pkcs_private_key_alloc and
139  *    freed by silc_pkcs_private_key_free.  The object is given as argument
140  *    to all silc_pkcs_private_key_* functions.
141  *
142  ***/
143 typedef struct {
144   char *name;
145   unsigned char *prv;
146   SilcUInt32 prv_len;
147 } *SilcPrivateKey;
148
149 /* Public and private key file headers */
150 #define SILC_PKCS_PUBLIC_KEYFILE_BEGIN "-----BEGIN SILC PUBLIC KEY-----\n"
151 #define SILC_PKCS_PUBLIC_KEYFILE_END "\n-----END SILC PUBLIC KEY-----\n"
152 #define SILC_PKCS_PRIVATE_KEYFILE_BEGIN "-----BEGIN SILC PRIVATE KEY-----\n"
153 #define SILC_PKCS_PRIVATE_KEYFILE_END "\n-----END SILC PRIVATE KEY-----\n"
154
155 /* Public and private key file encoding types */
156 #define SILC_PKCS_FILE_BIN 0
157 #define SILC_PKCS_FILE_PEM 1
158
159 /* Marks for all PKCS in silc. This can be used in silc_pkcs_unregister
160    to unregister all PKCS at once. */
161 #define SILC_ALL_PKCS ((SilcPKCSObject *)1)
162
163 /* Static list of PKCS for silc_pkcs_register_default(). */
164 extern DLLAPI const SilcPKCSObject silc_default_pkcs[];
165
166 /* Default PKXS in the SILC protocol */
167 #define SILC_DEFAULT_PKCS "rsa"
168
169 /* Macros */
170
171 /* Macros used to implement the SILC PKCS API */
172
173 /* XXX: This needs slight redesigning. These needs to be made even
174    more generic. I don't like that the actual prime generation is done
175    in PKCS_API_INIT. The primes used in key generation should be sent
176    as argument to the init function. By doing this we would achieve
177    that PKCS could be used as SIM's. The only requirement would be
178    that they are compiled against GMP (well, actually even that would
179    not be a requirement, but the most generic case anyway). The new init 
180    would look something like this:
181
182    #define SILC_PKCS_API_INIT(pkcs) \
183    inline int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
184                                  void *p1, void *p2)
185
186    Now we wouldn't have to send the SilcRng object since the primes are 
187    provided as arguments. To send them as void * they could actually be 
188    used as in anyway for real (MP_INT (SilcMPInt) or even something else 
189    (the pointer could be kludged to be something else in the module))
190    (Plus, the SilcRng object management in prime generation would be
191    simpler and better what it is now (in silcprimegen.c, that is)).
192 */
193
194 #define SILC_PKCS_API_INIT(pkcs) \
195 int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
196                        SilcRng rng)
197 #define SILC_PKCS_API_CLEAR_KEYS(pkcs) \
198 void silc_##pkcs##_clear_keys(void *context)
199 #define SILC_PKCS_API_GET_PUBLIC_KEY(pkcs) \
200 unsigned char *silc_##pkcs##_get_public_key(void *context, \
201                                             SilcUInt32 *ret_len)
202 #define SILC_PKCS_API_GET_PRIVATE_KEY(pkcs) \
203 unsigned char *silc_##pkcs##_get_private_key(void *context, \
204                                              SilcUInt32 *ret_len)
205 #define SILC_PKCS_API_SET_PUBLIC_KEY(pkcs) \
206 SilcUInt32 silc_##pkcs##_set_public_key(void *context, unsigned char *key_data, \
207                                         SilcUInt32 key_len)
208 #define SILC_PKCS_API_SET_PRIVATE_KEY(pkcs) \
209 SilcUInt32 silc_##pkcs##_set_private_key(void *context, unsigned char *key_data, \
210                                          SilcUInt32 key_len)
211 #define SILC_PKCS_API_CONTEXT_LEN(pkcs) \
212 SilcUInt32 silc_##pkcs##_context_len()
213 #define SILC_PKCS_API_ENCRYPT(pkcs) \
214 int silc_##pkcs##_encrypt(void *context, \
215                           unsigned char *src, \
216                           SilcUInt32 src_len, \
217                           unsigned char *dst, \
218                           SilcUInt32 *dst_len)
219 #define SILC_PKCS_API_DECRYPT(pkcs) \
220 int silc_##pkcs##_decrypt(void *context, \
221                           unsigned char *src, \
222                           SilcUInt32 src_len, \
223                           unsigned char *dst, \
224                           SilcUInt32 *dst_len)
225 #define SILC_PKCS_API_SIGN(pkcs) \
226 int silc_##pkcs##_sign(void *context, \
227                        unsigned char *src, \
228                        SilcUInt32 src_len, \
229                        unsigned char *dst, \
230                        SilcUInt32 *dst_len)
231 #define SILC_PKCS_API_VERIFY(pkcs) \
232 int silc_##pkcs##_verify(void *context, \
233                          unsigned char *signature, \
234                          SilcUInt32 signature_len, \
235                          unsigned char *data, \
236                          SilcUInt32 data_len)
237
238 /* Prototypes */
239
240 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register
241  *
242  * SYNOPSIS
243  *
244  *    bool silc_pkcs_register(const SilcPKCSObject *pkcs);
245  *
246  * DESCRIPTION
247  *
248  *    Registers a new PKCS into the SILC.  This function is used
249  *    at the initialization of the SILC.  All registered PKCSs
250  *    should be unregistered with silc_pkcs_unregister.  The `pkcs' includes
251  *    the name of the PKCS and member functions for the algorithm.  Usually
252  *    this function is not called directly.  Instead, application can call
253  *    the silc_pkcs_register_default to register all PKCSs that are
254  *    builtin the sources.  Returns FALSE on error.
255  *
256  ***/
257 bool silc_pkcs_register(const SilcPKCSObject *pkcs);
258
259 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister
260  *
261  * SYNOPSIS
262  *
263  *    bool silc_pkcs_unregister(SilcPKCSObject *pkcs);
264  *
265  * DESCRIPTION
266  *
267  *    Unregister a PKCS from the SILC. Returns FALSE on error.
268  *
269  ***/
270 bool silc_pkcs_unregister(SilcPKCSObject *pkcs);
271
272 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register_default
273  *
274  * SYNOPSIS
275  *
276  *    bool silc_pkcs_register_default(void);
277  *
278  * DESCRIPTION
279  *
280  *    Registers all the default PKCS (all builtin PKCS).  The application may
281  *    use this to register the default PKCS if specific PKCS in any specific
282  *    order is not wanted. Returns FALSE on error.
283  *
284  ***/
285 bool silc_pkcs_register_default(void);
286
287 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister_all
288  *
289  * SYNOPSIS
290  *
291  *    bool silc_pkcs_unregister_all(void);
292  *
293  * DESCRIPTION
294  *
295  *    Returns FALSE on error.
296  *
297  ***/
298 bool silc_pkcs_unregister_all(void);
299
300 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_alloc
301  *
302  * SYNOPSIS
303  *
304  *    bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
305  *
306  * DESCRIPTION
307  *
308  *    Allocates a new SilcPKCS object. The new allocated object is returned
309  *    to the 'new_pkcs' argument. Returns FALSE on error.
310  *
311  ***/
312 bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
313
314 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free
315  *
316  * SYNOPSIS
317  *
318  *    void silc_pkcs_free(SilcPKCS pkcs);
319  *
320  * DESCRIPTION
321  *
322  *    Frees the PKCS object.
323  *
324  ***/
325 void silc_pkcs_free(SilcPKCS pkcs);
326
327 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_is_supported
328  *
329  * SYNOPSIS
330  *
331  *    bool silc_pkcs_is_supported(const unsigned char *name);
332  *
333  * DESCRIPTION
334  *
335  *    Returns TRUE if PKCS algorithm `name' is supported.
336  *
337  ***/
338 bool silc_pkcs_is_supported(const unsigned char *name);
339
340 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_supported
341  *
342  * SYNOPSIS
343  *
344  *    char *silc_pkcs_get_supported(void);
345  *
346  * DESCRIPTION
347  *
348  *    Returns comma separated list of supported PKCS algorithms.
349  *
350  ***/
351 char *silc_pkcs_get_supported(void);
352
353 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_generate_key
354  *
355  * SYNOPSIS
356  *
357  *    bool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
358  *                                SilcRng rng);
359  *
360  * DESCRIPTION
361  *
362  *    Generate new key pair into the `pkcs' context. Returns FALSE on error.
363  *
364  ***/
365 bool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
366                             SilcRng rng);
367
368 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_key_len
369  *
370  * SYNOPSIS
371  *
372  *    SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
373  *
374  * DESCRIPTION
375  *
376  *    Returns the length of the key.
377  *
378  ***/
379 SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
380
381 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_name
382  *
383  * SYNOPSIS
384  *
385  *    const char *silc_pkcs_get_name(SilcPKCS pkcs);
386  *
387  * DESCRIPTION
388  *
389  *    Returns PKCS name.
390  *
391  ***/
392 const char *silc_pkcs_get_name(SilcPKCS pkcs);
393
394 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_public_key
395  *
396  * SYNOPSIS
397  *
398  *    unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
399  *
400  * DESCRIPTION
401  *
402  *    Returns SILC style public key.
403  *
404  ***/
405 unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
406
407 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_private_key
408  *
409  * SYNOPSIS
410  *
411  *    unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs,
412  *                                             SilcUInt32 *len);
413  *
414  * DESCRIPTION
415  *
416  *    Returns SILC style private key.
417  *
418  ***/
419 unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, SilcUInt32 *len);
420
421 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_set
422  *
423  * SYNOPSIS
424  *
425  *    SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs,
426  *                                        SilcPublicKey public_key);
427  *
428  * DESCRIPTION
429  *
430  *    Sets public key from SilcPublicKey. Returns the length of the key.
431  *
432  ***/
433 SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
434
435 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_set
436  *
437  * SYNOPSIS
438  *
439  *    SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs,
440  *                                             unsigned char *pk,
441  *                                             SilcUInt32 pk_len);
442  *
443  * DESCRIPTION
444  *
445  *    Sets public key from data. Returns the length of the key.
446  *
447  ***/
448 SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
449                                          SilcUInt32 pk_len);
450
451 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_set
452  *
453  * SYNOPSIS
454  *
455  *    SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs,
456  *                                         SilcPrivateKey private_key);
457  *
458  * DESCRIPTION
459  *
460  *    Sets private key from SilcPrivateKey. Returns the length of the key.
461  *
462  ***/
463 SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs, SilcPrivateKey private_key);
464
465 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_set
466  *
467  * SYNOPSIS
468  *
469  *    SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs,
470  *                                              unsigned char *prv,
471  *                                              SilcUInt32 prv_len);
472  *
473  * DESCRIPTION
474  *
475  *    Sets private key from data. Returns the length of the key.
476  *
477  ***/
478 SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs, unsigned char *prv,
479                                           SilcUInt32 prv_len);
480
481 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encrypt
482  *
483  * SYNOPSIS
484  *
485  *    bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src,
486  *                           SilcUInt32 src_len, unsigned char *dst,
487  *                           SilcUInt32 *dst_len);
488  *
489  * DESCRIPTION
490  *
491  *    Encrypts. Returns FALSE on error.
492  *
493  ***/
494 bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
495                        unsigned char *dst, SilcUInt32 *dst_len);
496
497 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt
498  *
499  * SYNOPSIS
500  *
501  *    bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src,
502  *                           SilcUInt32 src_len, unsigned char *dst,
503  *                           SilcUInt32 *dst_len);
504  *
505  * DESCRIPTION
506  *
507  *    Decrypts. Returns FALSE on error.
508  *
509  ***/
510 bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
511                        unsigned char *dst, SilcUInt32 *dst_len);
512
513 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign
514  *
515  * SYNOPSIS
516  *
517  *    bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src,
518  *                        SilcUInt32 src_len, unsigned char *dst,
519  *                        SilcUInt32 *dst_len);
520  *
521  * DESCRIPTION
522  *
523  *    Generates signature. Returns FALSE on error.
524  *
525  ***/
526 bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
527                     unsigned char *dst, SilcUInt32 *dst_len);
528
529 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify
530  *
531  * SYNOPSIS
532  *
533  *    bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
534  *                          SilcUInt32 signature_len, unsigned char *data,
535  *                          SilcUInt32 data_len);
536  *
537  * DESCRIPTION
538  *
539  *    Verifies signature. Returns FALSE on error.
540  *
541  ***/
542 bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
543                       SilcUInt32 signature_len, unsigned char *data,
544                       SilcUInt32 data_len);
545
546 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign_with_hash
547  *
548  * SYNOPSIS
549  *
550  *    bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
551  *                                  unsigned char *src, SilcUInt32 src_len,
552  *                                  unsigned char *dst, SilcUInt32 *dst_len);
553  *
554  * DESCRIPTION
555  *
556  *    Generates signature with hash. The hash is signed. Returns FALSE on
557  *    error.
558  *
559  ***/
560 bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
561                               unsigned char *src, SilcUInt32 src_len,
562                               unsigned char *dst, SilcUInt32 *dst_len);
563
564 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify_with_hash
565  *
566  * SYNOPSIS
567  *
568  *    bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
569  *                                    unsigned char *signature,
570  *                                    SilcUInt32 signature_len,
571  *                                    unsigned char *data,
572  *                                    SilcUInt32 data_len);
573  *
574  * DESCRIPTION
575  *
576  *    Verifies signature with hash. The `data' is hashed and verified against
577  *    the `signature'. Returns FALSE on error.
578  *
579  ***/
580 bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
581                                 unsigned char *signature,
582                                 SilcUInt32 signature_len,
583                                 unsigned char *data,
584                                 SilcUInt32 data_len);
585
586 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encode_identifier
587  *
588  * SYNOPSIS
589  *
590  *    char *silc_pkcs_encode_identifier(char *username, char *host,
591  *                                      char *realname, char *email,
592  *                                      char *org, char *country);
593  *
594  * DESCRIPTION
595  *
596  *    Encodes and returns SILC public key identifier. If some of the
597  *    arguments is NULL those are not encoded into the identifier string.
598  *    Protocol says that at least username and host must be provided.
599  *
600  ***/
601 char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
602                                   char *email, char *org, char *country);
603
604 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decode_identifier
605  *
606  * SYNOPSIS
607  *
608  *    SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
609  *
610  * DESCRIPTION
611  *
612  *    Decodes the provided `identifier' and returns allocated context for
613  *    the identifier.
614  *
615  ***/
616 SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
617
618 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free_identifier
619  *
620  * SYNOPSIS
621  *
622  *    void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
623  *
624  * DESCRIPTION
625  *
626  *    Frees decoded public key identifier context. Call this to free the
627  *    context returned by the silc_pkcs_decode_identifier.
628  *
629  ***/
630 void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
631
632 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_alloc
633  *
634  * SYNOPSIS
635  *
636  *    SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
637  *                                             const char *identifier,
638  *                                             const unsigned char *pk,
639  *                                             SilcUInt32 pk_len);
640  *
641  * DESCRIPTION
642  *
643  *    Allocates SILC style public key formed from sent arguments. All data
644  *    is duplicated.
645  *
646  ***/
647 SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
648                                          const char *identifier,
649                                          const unsigned char *pk,
650                                          SilcUInt32 pk_len);
651
652 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_free
653  *
654  * SYNOPSIS
655  *
656  *    void silc_pkcs_public_key_free(SilcPublicKey public_key);
657  *
658  * DESCRIPTION
659  *
660  *    Frees public key.
661  *
662  ***/
663 void silc_pkcs_public_key_free(SilcPublicKey public_key);
664
665 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_alloc
666  *
667  * SYNOPSIS
668  *
669  *    SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
670  *                                               const unsigned char *prv,
671  *                                               SilcUInt32 prv_len);
672  *
673  * DESCRIPTION
674  *
675  *    Allocates SILC private key formed from sent arguments. All data is
676  *    duplicated.
677  *
678  ***/
679 SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
680                                            const unsigned char *prv,
681                                            SilcUInt32 prv_len);
682
683 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_free
684  *
685  * SYNOPSIS
686  *
687  *    void silc_pkcs_private_key_free(SilcPrivateKey private_key);
688  *
689  * DESCRIPTION
690  *
691  *    Frees private key.
692  *
693  ***/
694 void silc_pkcs_private_key_free(SilcPrivateKey private_key);
695
696 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_encode
697  *
698  * SYNOPSIS
699  *
700  *    unsigned char *
701  *    silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
702  *
703  * DESCRIPTION
704  *
705  *    Encodes SILC style public key from SilcPublicKey. Returns the encoded
706  *    data.
707  *
708  ***/
709 unsigned char *
710 silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
711
712 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_encode
713  *
714  * SYNOPSIS
715  *
716  *    unsigned char *
717  *    silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
718  *                                     char *pkcs, char *identifier,
719  *                                     SilcUInt32 *len);
720  *
721  * DESCRIPTION
722  *
723  *    Encodes SILC style public key. Returns the encoded data.
724  *
725  ***/
726 unsigned char *
727 silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
728                                  char *pkcs, char *identifier,
729                                  SilcUInt32 *len);
730
731 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
732  *
733  * SYNOPSIS
734  *
735  *    bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
736  *                                     SilcPublicKey *public_key);
737  *
738  * DESCRIPTION
739  *
740  *    Decodes SILC style public key. Returns TRUE if the decoding was
741  *    successful. Allocates new public key as well.
742  *
743  ***/
744 bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
745                                  SilcPublicKey *public_key);
746
747 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_compare
748  *
749  * SYNOPSIS
750  *
751  *    bool silc_pkcs_public_key_compare(SilcPublicKey key1,
752  *                                      SilcPublicKey key2);
753  *
754  * DESCRIPTION
755  *
756  *    Compares two public keys and returns TRUE if they are same key, and
757  *    FALSE if they are not same.
758  *
759  ***/
760 bool silc_pkcs_public_key_compare(SilcPublicKey key1, SilcPublicKey key2);
761
762 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_copy
763  *
764  * SYNOPSIS
765  *
766  *    SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
767  *
768  * DESCRIPTION
769  *
770  *    Copies the public key indicated by `public_key' and returns new allocated
771  *    public key which is indentical to the `public_key'.
772  *
773  ***/
774 SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
775
776 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_encode
777  *
778  * SYNOPSIS
779  *
780  *    unsigned char *
781  *    silc_pkcs_private_key_encode(SilcPrivateKey private_key,
782  *                                 SilcUInt32 *len);
783  *
784  * DESCRIPTION
785  *
786  *    Encodes SILC private key from SilcPrivateKey. Returns the encoded data.
787  *
788  ***/
789 unsigned char *
790 silc_pkcs_private_key_encode(SilcPrivateKey private_key, SilcUInt32 *len);
791
792 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_encode
793  *
794  * SYNOPSIS
795  *
796  *    unsigned char *
797  *    silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
798  *                                      char *pkcs, SilcUInt32 *len);
799  *
800  * DESCRIPTION
801  *
802  *    Encodes SILC private key. Returns the encoded data.
803  *
804  ***/
805 unsigned char *
806 silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
807                                   char *pkcs, SilcUInt32 *len);
808
809 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_decode
810  *
811  * SYNOPSIS
812  *
813  *    bool silc_pkcs_private_key_decode(unsigned char *data,
814  *                                      SilcUInt32 data_len,
815  *                                      SilcPrivateKey *private_key);
816  *
817  * DESCRIPTION
818  *
819  *    Decodes SILC style private key. Returns TRUE if the decoding was
820  *    successful. Allocates new private key as well.
821  *
822  ***/
823 bool silc_pkcs_private_key_decode(unsigned char *data, SilcUInt32 data_len,
824                                   SilcPrivateKey *private_key);
825
826 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key
827  *
828  * SYNOPSIS
829  *
830  *    bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
831  *                                   SilcUInt32 encoding);
832  *
833  * DESCRIPTION
834  *
835  *    Saves public key into file. Returns FALSE on error.
836  *
837  ***/
838 bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
839                                SilcUInt32 encoding);
840
841 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key_data
842  *
843  * SYNOPSIS
844  *
845  *    bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
846  *                                        SilcUInt32 data_len,
847  *                                        SilcUInt32 encoding);
848  *
849  * DESCRIPTION
850  *
851  *    Saves public key into file. Returns FALSE on error.
852  *
853  ***/
854 bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
855                                     SilcUInt32 data_len,
856                                     SilcUInt32 encoding);
857
858 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key
859  *
860  * SYNOPSIS
861  *
862  *    bool silc_pkcs_save_private_key(char *filename,
863  *                                    SilcPrivateKey private_key,
864  *                                    unsigned char *passphrase,
865  *                                    SilcUInt32 encoding);
866  *
867  * DESCRIPTION
868  *
869  *    Saves private key into file. Returns FALSE on error.
870  *
871  ***/
872 bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key, 
873                                 unsigned char *passphrase,
874                                 SilcUInt32 encoding);
875
876 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key_data
877  *
878  * SYNOPSIS
879  *
880  *    bool silc_pkcs_save_private_key_data(char *filename, unsigned char *data,
881  *                                         SilcUInt32 data_len,
882  *                                         unsigned char *passphrase,
883  *                                         SilcUInt32 encoding);
884  *
885  * DESCRIPTION
886  *
887  *    Saves private key into file. Returns FALSE on error.
888  *
889  ***/
890 bool silc_pkcs_save_private_key_data(char *filename, unsigned char *data, 
891                                      SilcUInt32 data_len,
892                                      unsigned char *passphrase,
893                                      SilcUInt32 encoding);
894
895 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_public_key
896  *
897  * SYNOPSIS
898  *
899  *    bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
900  *                                   SilcUInt32 encoding);
901  *
902  * DESCRIPTION
903  *
904  *    Loads public key from file and allocates new public key. Returns TRUE
905  *    if loading was successful.
906  *
907  ***/
908 bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
909                                SilcUInt32 encoding);
910
911 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_private_key
912  *
913  * SYNOPSIS
914  *
915  *    bool silc_pkcs_load_private_key(char *filename,
916  *                                    SilcPrivateKey *private_key,
917  *                                    SilcUInt32 encoding);
918  *
919  * DESCRIPTION
920  *
921  *    Load private key from file and allocates new private key. Returns TRUE
922  *    if loading was successful.
923  *
924  ***/
925 bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
926                                 SilcUInt32 encoding);
927
928 #endif /* SILCPKCS_H */