5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 Pekka Riikonen
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.
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.
23 /****h* silccrypt/SILC PKCS Interface
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.
40 /****s* silccrypt/SilcPKCSAPI/SilcPKCS
44 * typedef struct SilcPKCSStruct *SilcPKCS;
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
54 typedef struct SilcPKCSStruct *SilcPKCS;
56 /* The default SILC PKCS (Public Key Cryptosystem) object to represent
58 typedef struct SilcPKCSObjectStruct {
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);
77 /****s* silccrypt/SilcPKCSAPI/SilcPublicKey
81 * typedef struct { ... } *SilcPublicKey;
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.
95 SilcUInt16 pk_type; /* Public key type (SilcSKEPKType) */
104 /****s* silccrypt/SilcPKCSAPI/SilcPublicKeyIdentifier
108 * typedef struct { ... } *SilcPublicKeyIdentifier;
112 * Decoded SILC Public Key identifier. Note that some of the fields
113 * may be NULL. This context is allcated by the function
114 * silc_pkcs_decode_identifier and freed by silc_pkcs_free_identifier.
115 * The identifier in SilcPublicKey is the 'identifier' field, which
116 * can be given as argument to silc_pkcs_decode_identifier.
127 } *SilcPublicKeyIdentifier;
130 /****s* silccrypt/SilcPKCSAPI/SilcPrivateKey
134 * typedef struct { ... } *SilcPrivateKey;
138 * SILC style private key object. Public key is read from file to this
139 * object. This object is allocated by silc_pkcs_private_key_alloc and
140 * freed by silc_pkcs_private_key_free. The object is given as argument
141 * to all silc_pkcs_private_key_* functions.
150 /* Public and private key file headers */
151 #define SILC_PKCS_PUBLIC_KEYFILE_BEGIN "-----BEGIN SILC PUBLIC KEY-----\n"
152 #define SILC_PKCS_PUBLIC_KEYFILE_END "\n-----END SILC PUBLIC KEY-----\n"
153 #define SILC_PKCS_PRIVATE_KEYFILE_BEGIN "-----BEGIN SILC PRIVATE KEY-----\n"
154 #define SILC_PKCS_PRIVATE_KEYFILE_END "\n-----END SILC PRIVATE KEY-----\n"
156 /* Public and private key file encoding types */
157 #define SILC_PKCS_FILE_BIN 0
158 #define SILC_PKCS_FILE_PEM 1
160 /* Marks for all PKCS in silc. This can be used in silc_pkcs_unregister
161 to unregister all PKCS at once. */
162 #define SILC_ALL_PKCS ((SilcPKCSObject *)1)
164 /* Static list of PKCS for silc_pkcs_register_default(). */
165 extern DLLAPI const SilcPKCSObject silc_default_pkcs[];
167 /* Default PKXS in the SILC protocol */
168 #define SILC_DEFAULT_PKCS "rsa"
172 /* Macros used to implement the SILC PKCS API */
174 /* XXX: This needs slight redesigning. These needs to be made even
175 more generic. I don't like that the actual prime generation is done
176 in PKCS_API_INIT. The primes used in key generation should be sent
177 as argument to the init function. By doing this we would achieve
178 that PKCS could be used as SIM's. The only requirement would be
179 that they are compiled against GMP (well, actually even that would
180 not be a requirement, but the most generic case anyway). The new init
181 would look something like this:
183 #define SILC_PKCS_API_INIT(pkcs) \
184 inline int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
187 Now we wouldn't have to send the SilcRng object since the primes are
188 provided as arguments. To send them as void * they could actually be
189 used as in anyway for real (MP_INT (SilcMPInt) or even something else
190 (the pointer could be kludged to be something else in the module))
191 (Plus, the SilcRng object management in prime generation would be
192 simpler and better what it is now (in silcprimegen.c, that is)).
195 #define SILC_PKCS_API_INIT(pkcs) \
196 int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
198 #define SILC_PKCS_API_CLEAR_KEYS(pkcs) \
199 void silc_##pkcs##_clear_keys(void *context)
200 #define SILC_PKCS_API_GET_PUBLIC_KEY(pkcs) \
201 unsigned char *silc_##pkcs##_get_public_key(void *context, \
203 #define SILC_PKCS_API_GET_PRIVATE_KEY(pkcs) \
204 unsigned char *silc_##pkcs##_get_private_key(void *context, \
206 #define SILC_PKCS_API_SET_PUBLIC_KEY(pkcs) \
207 SilcUInt32 silc_##pkcs##_set_public_key(void *context, unsigned char *key_data, \
209 #define SILC_PKCS_API_SET_PRIVATE_KEY(pkcs) \
210 SilcUInt32 silc_##pkcs##_set_private_key(void *context, unsigned char *key_data, \
212 #define SILC_PKCS_API_CONTEXT_LEN(pkcs) \
213 SilcUInt32 silc_##pkcs##_context_len()
214 #define SILC_PKCS_API_ENCRYPT(pkcs) \
215 int silc_##pkcs##_encrypt(void *context, \
216 unsigned char *src, \
217 SilcUInt32 src_len, \
218 unsigned char *dst, \
220 #define SILC_PKCS_API_DECRYPT(pkcs) \
221 int silc_##pkcs##_decrypt(void *context, \
222 unsigned char *src, \
223 SilcUInt32 src_len, \
224 unsigned char *dst, \
226 #define SILC_PKCS_API_SIGN(pkcs) \
227 int silc_##pkcs##_sign(void *context, \
228 unsigned char *src, \
229 SilcUInt32 src_len, \
230 unsigned char *dst, \
232 #define SILC_PKCS_API_VERIFY(pkcs) \
233 int silc_##pkcs##_verify(void *context, \
234 unsigned char *signature, \
235 SilcUInt32 signature_len, \
236 unsigned char *data, \
241 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register
245 * bool silc_pkcs_register(const SilcPKCSObject *pkcs);
249 * Registers a new PKCS into the SILC. This function is used
250 * at the initialization of the SILC. All registered PKCSs
251 * should be unregistered with silc_pkcs_unregister. The `pkcs' includes
252 * the name of the PKCS and member functions for the algorithm. Usually
253 * this function is not called directly. Instead, application can call
254 * the silc_pkcs_register_default to register all PKCSs that are
255 * builtin the sources. Returns FALSE on error.
258 bool silc_pkcs_register(const SilcPKCSObject *pkcs);
260 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister
264 * bool silc_pkcs_unregister(SilcPKCSObject *pkcs);
268 * Unregister a PKCS from the SILC. Returns FALSE on error.
271 bool silc_pkcs_unregister(SilcPKCSObject *pkcs);
273 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register_default
277 * bool silc_pkcs_register_default(void);
281 * Registers all the default PKCS (all builtin PKCS). The application may
282 * use this to register the default PKCS if specific PKCS in any specific
283 * order is not wanted. Returns FALSE on error.
286 bool silc_pkcs_register_default(void);
288 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister_all
292 * bool silc_pkcs_unregister_all(void);
296 * Returns FALSE on error.
299 bool silc_pkcs_unregister_all(void);
301 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_alloc
305 * bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
309 * Allocates a new SilcPKCS object. The new allocated object is returned
310 * to the 'new_pkcs' argument. Returns FALSE on error.
313 bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
315 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free
319 * void silc_pkcs_free(SilcPKCS pkcs);
323 * Frees the PKCS object.
326 void silc_pkcs_free(SilcPKCS pkcs);
328 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_is_supported
332 * bool silc_pkcs_is_supported(const unsigned char *name);
336 * Returns TRUE if PKCS algorithm `name' is supported.
339 bool silc_pkcs_is_supported(const unsigned char *name);
341 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_supported
345 * char *silc_pkcs_get_supported(void);
349 * Returns comma separated list of supported PKCS algorithms.
352 char *silc_pkcs_get_supported(void);
354 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_generate_key
358 * bool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
363 * Generate new key pair into the `pkcs' context. Returns FALSE on error.
366 bool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
369 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_key_len
373 * SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
377 * Returns the length of the key.
380 SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
382 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_name
386 * const char *silc_pkcs_get_name(SilcPKCS pkcs);
393 const char *silc_pkcs_get_name(SilcPKCS pkcs);
395 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_public_key
399 * unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
403 * Returns SILC style public key. The caller must free the returned
407 unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
409 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_private_key
413 * unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs,
418 * Returns SILC style private key. The caller must free the returned
419 * data and SHOULD zero the memory area before freeing.
422 unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, SilcUInt32 *len);
424 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_set
428 * SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs,
429 * SilcPublicKey public_key);
433 * Sets public key from SilcPublicKey. Returns the length of the key.
436 SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
438 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_set
442 * SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs,
444 * SilcUInt32 pk_len);
448 * Sets public key from data. Returns the length of the key.
451 SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
454 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_set
458 * SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs,
459 * SilcPrivateKey private_key);
463 * Sets private key from SilcPrivateKey. Returns the length of the key.
466 SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs, SilcPrivateKey private_key);
468 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_set
472 * SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs,
473 * unsigned char *prv,
474 * SilcUInt32 prv_len);
478 * Sets private key from data. Returns the length of the key.
481 SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs, unsigned char *prv,
484 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encrypt
488 * bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src,
489 * SilcUInt32 src_len, unsigned char *dst,
490 * SilcUInt32 *dst_len);
494 * Encrypts. Returns FALSE on error.
497 bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
498 unsigned char *dst, SilcUInt32 *dst_len);
500 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt
504 * bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src,
505 * SilcUInt32 src_len, unsigned char *dst,
506 * SilcUInt32 *dst_len);
510 * Decrypts. Returns FALSE on error.
513 bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
514 unsigned char *dst, SilcUInt32 *dst_len);
516 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign
520 * bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src,
521 * SilcUInt32 src_len, unsigned char *dst,
522 * SilcUInt32 *dst_len);
526 * Generates signature. Returns FALSE on error.
529 bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
530 unsigned char *dst, SilcUInt32 *dst_len);
532 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify
536 * bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
537 * SilcUInt32 signature_len, unsigned char *data,
538 * SilcUInt32 data_len);
542 * Verifies signature. Returns FALSE on error.
545 bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
546 SilcUInt32 signature_len, unsigned char *data,
547 SilcUInt32 data_len);
549 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign_with_hash
553 * bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
554 * unsigned char *src, SilcUInt32 src_len,
555 * unsigned char *dst, SilcUInt32 *dst_len);
559 * Generates signature with hash. The hash is signed. Returns FALSE on
563 bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
564 unsigned char *src, SilcUInt32 src_len,
565 unsigned char *dst, SilcUInt32 *dst_len);
567 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify_with_hash
571 * bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
572 * unsigned char *signature,
573 * SilcUInt32 signature_len,
574 * unsigned char *data,
575 * SilcUInt32 data_len);
579 * Verifies signature with hash. The `data' is hashed and verified against
580 * the `signature'. Returns FALSE on error.
583 bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
584 unsigned char *signature,
585 SilcUInt32 signature_len,
587 SilcUInt32 data_len);
589 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encode_identifier
593 * char *silc_pkcs_encode_identifier(char *username, char *host,
594 * char *realname, char *email,
595 * char *org, char *country);
599 * Encodes and returns SILC public key identifier. If some of the
600 * arguments is NULL those are not encoded into the identifier string.
601 * Protocol says that at least username and host must be provided.
604 char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
605 char *email, char *org, char *country);
607 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decode_identifier
611 * SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
615 * Decodes the provided `identifier' and returns allocated context for
619 SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
621 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free_identifier
625 * void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
629 * Frees decoded public key identifier context. Call this to free the
630 * context returned by the silc_pkcs_decode_identifier.
633 void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
635 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_alloc
639 * SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
640 * const char *identifier,
641 * const unsigned char *pk,
642 * SilcUInt32 pk_len);
646 * Allocates SILC style public key formed from sent arguments. All data
650 SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
651 const char *identifier,
652 const unsigned char *pk,
655 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_free
659 * void silc_pkcs_public_key_free(SilcPublicKey public_key);
666 void silc_pkcs_public_key_free(SilcPublicKey public_key);
668 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_alloc
672 * SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
673 * const unsigned char *prv,
674 * SilcUInt32 prv_len);
678 * Allocates SILC private key formed from sent arguments. All data is
682 SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
683 const unsigned char *prv,
686 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_free
690 * void silc_pkcs_private_key_free(SilcPrivateKey private_key);
697 void silc_pkcs_private_key_free(SilcPrivateKey private_key);
699 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_encode
704 * silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
708 * Encodes SILC style public key from SilcPublicKey. Returns the encoded
713 silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
715 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_encode
720 * silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
721 * char *pkcs, char *identifier,
726 * Encodes SILC style public key. Returns the encoded data.
730 silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
731 char *pkcs, char *identifier,
734 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
738 * bool silc_pkcs_public_key_decode(unsigned char *data,
739 * SilcUInt32 data_len,
740 * SilcPublicKey *public_key);
744 * Decodes SILC style public key. Returns TRUE if the decoding was
745 * successful. Allocates new public key as well.
748 bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
749 SilcPublicKey *public_key);
751 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
755 * bool silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
759 * Encodes the Public Key Payload from the public key indicated by
760 * `public_key' of type of `pk_type'. The type is SilcSKEPKType.
761 * Returns the encoded payload buffer.
764 SilcBuffer silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
766 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
771 * silc_pkcs_public_key_payload_decode(unsigned char *data,
772 * SilcUInt32 data_len,
773 * SilcPublicKey *public_key);
777 * Decodes Public Key Payload from `data' of `data_len' bytes in length
778 * data buffer into `public_key' pointer. Returns FALSE if the payload
782 bool silc_pkcs_public_key_payload_decode(unsigned char *data,
784 SilcPublicKey *public_key);
786 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_compare
790 * bool silc_pkcs_public_key_compare(SilcPublicKey key1,
791 * SilcPublicKey key2);
795 * Compares two public keys and returns TRUE if they are same key, and
796 * FALSE if they are not same.
799 bool silc_pkcs_public_key_compare(SilcPublicKey key1, SilcPublicKey key2);
801 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_copy
805 * SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
809 * Copies the public key indicated by `public_key' and returns new allocated
810 * public key which is indentical to the `public_key'.
813 SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
815 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_encode
820 * silc_pkcs_private_key_encode(SilcPrivateKey private_key,
825 * Encodes SILC private key from SilcPrivateKey. Returns the encoded data.
829 silc_pkcs_private_key_encode(SilcPrivateKey private_key, SilcUInt32 *len);
831 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_encode
836 * silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
837 * char *pkcs, SilcUInt32 *len);
841 * Encodes SILC private key. Returns the encoded data.
845 silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
846 char *pkcs, SilcUInt32 *len);
848 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_decode
852 * bool silc_pkcs_private_key_decode(unsigned char *data,
853 * SilcUInt32 data_len,
854 * SilcPrivateKey *private_key);
858 * Decodes SILC style private key. Returns TRUE if the decoding was
859 * successful. Allocates new private key as well.
862 bool silc_pkcs_private_key_decode(unsigned char *data, SilcUInt32 data_len,
863 SilcPrivateKey *private_key);
865 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key
869 * bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
870 * SilcUInt32 encoding);
874 * Saves public key into file. Returns FALSE on error.
877 bool silc_pkcs_save_public_key(char *filename, SilcPublicKey public_key,
878 SilcUInt32 encoding);
880 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key_data
884 * bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
885 * SilcUInt32 data_len,
886 * SilcUInt32 encoding);
890 * Saves public key into file. The public key is already encoded as
891 * data when calling this function. Returns FALSE on error.
894 bool silc_pkcs_save_public_key_data(char *filename, unsigned char *data,
896 SilcUInt32 encoding);
898 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key
902 * bool silc_pkcs_save_private_key(char *filename,
903 * SilcPrivateKey private_key,
904 * unsigned char *passphrase,
905 * SilcUInt32 passphrase_len,
906 * SilcUInt32 encoding);
910 * Saves private key into file. The private key is encrypted into
911 * the file with the `passphrase' as a key. The encryption algorithm
912 * is AES with 256 bit key in CBC mode. Returns FALSE on error.
915 bool silc_pkcs_save_private_key(char *filename, SilcPrivateKey private_key,
916 unsigned char *passphrase,
917 SilcUInt32 passphrase_len,
918 SilcUInt32 encoding);
920 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_public_key
924 * bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
925 * SilcUInt32 encoding);
929 * Loads public key from file and allocates new public key. Returns TRUE
930 * if loading was successful.
933 bool silc_pkcs_load_public_key(char *filename, SilcPublicKey *public_key,
934 SilcUInt32 encoding);
936 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_private_key
940 * bool silc_pkcs_load_private_key(char *filename,
941 * SilcPrivateKey *private_key,
942 * unsigned char *passphrase,
943 * SilcUInt32 passphrase_len,
944 * SilcUInt32 encoding);
948 * Load private key from file and allocates new private key. Returns TRUE
949 * if loading was successful. The `passphrase' is used as decryption
950 * key of the private key file.
953 bool silc_pkcs_load_private_key(char *filename, SilcPrivateKey *private_key,
954 unsigned char *passphrase,
955 SilcUInt32 passphrase_len,
956 SilcUInt32 encoding);
958 #endif /* SILCPKCS_H */