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, SilcPublicKeyStruct;
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) */
101 } *SilcPublicKey, SilcPublicKeyStruct;
104 /****s* silccrypt/SilcPKCSAPI/SilcPublicKeyIdentifier
108 * typedef struct { ... } *SilcPublicKeyIdentifier,
109 * SilcPublicKeyIdentifierStruct;
113 * Decoded SILC Public Key identifier. Note that some of the fields
114 * may be NULL. This context is allocated by the function
115 * silc_pkcs_decode_identifier and freed by silc_pkcs_free_identifier.
116 * The identifier in SilcPublicKey is the `identifier' field, which
117 * can be given as argument to silc_pkcs_decode_identifier.
128 } *SilcPublicKeyIdentifier, SilcPublicKeyIdentifierStruct;
131 /****s* silccrypt/SilcPKCSAPI/SilcPrivateKey
135 * typedef struct { ... } *SilcPrivateKey, SilcPrivateKeyStruct;
139 * SILC style private key object. Public key is read from file to this
140 * object. This object is allocated by silc_pkcs_private_key_alloc and
141 * freed by silc_pkcs_private_key_free. The object is given as argument
142 * to all silc_pkcs_private_key_* functions.
149 } *SilcPrivateKey, SilcPrivateKeyStruct;
151 /* Public and private key file headers */
152 #define SILC_PKCS_PUBLIC_KEYFILE_BEGIN "-----BEGIN SILC PUBLIC KEY-----\n"
153 #define SILC_PKCS_PUBLIC_KEYFILE_END "\n-----END SILC PUBLIC KEY-----\n"
154 #define SILC_PKCS_PRIVATE_KEYFILE_BEGIN "-----BEGIN SILC PRIVATE KEY-----\n"
155 #define SILC_PKCS_PRIVATE_KEYFILE_END "\n-----END SILC PRIVATE KEY-----\n"
157 /* Public and private key file encoding types */
158 #define SILC_PKCS_FILE_BIN 0
159 #define SILC_PKCS_FILE_PEM 1
161 /* Marks for all PKCS in silc. This can be used in silc_pkcs_unregister
162 to unregister all PKCS at once. */
163 #define SILC_ALL_PKCS ((SilcPKCSObject *)1)
165 /* Static list of PKCS for silc_pkcs_register_default(). */
166 extern DLLAPI const SilcPKCSObject silc_default_pkcs[];
168 /* Default PKXS in the SILC protocol */
169 #define SILC_DEFAULT_PKCS "rsa"
173 /* Macros used to implement the SILC PKCS API */
175 /* XXX: This needs slight redesigning. These needs to be made even
176 more generic. I don't like that the actual prime generation is done
177 in PKCS_API_INIT. The primes used in key generation should be sent
178 as argument to the init function. By doing this we would achieve
179 that PKCS could be used as SIM's. The only requirement would be
180 that they are compiled against GMP (well, actually even that would
181 not be a requirement, but the most generic case anyway). The new init
182 would look something like this:
184 #define SILC_PKCS_API_INIT(pkcs) \
185 inline int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
188 Now we wouldn't have to send the SilcRng object since the primes are
189 provided as arguments. To send them as void * they could actually be
190 used as in anyway for real (MP_INT (SilcMPInt) or even something else
191 (the pointer could be kludged to be something else in the module))
192 (Plus, the SilcRng object management in prime generation would be
193 simpler and better what it is now (in silcprimegen.c, that is)).
196 #define SILC_PKCS_API_INIT(pkcs) \
197 int silc_##pkcs##_init(void *context, SilcUInt32 keylen, \
199 #define SILC_PKCS_API_CLEAR_KEYS(pkcs) \
200 void silc_##pkcs##_clear_keys(void *context)
201 #define SILC_PKCS_API_GET_PUBLIC_KEY(pkcs) \
202 unsigned char *silc_##pkcs##_get_public_key(void *context, \
204 #define SILC_PKCS_API_GET_PRIVATE_KEY(pkcs) \
205 unsigned char *silc_##pkcs##_get_private_key(void *context, \
207 #define SILC_PKCS_API_SET_PUBLIC_KEY(pkcs) \
208 SilcUInt32 silc_##pkcs##_set_public_key(void *context, unsigned char *key_data, \
210 #define SILC_PKCS_API_SET_PRIVATE_KEY(pkcs) \
211 SilcUInt32 silc_##pkcs##_set_private_key(void *context, unsigned char *key_data, \
213 #define SILC_PKCS_API_CONTEXT_LEN(pkcs) \
214 SilcUInt32 silc_##pkcs##_context_len()
215 #define SILC_PKCS_API_ENCRYPT(pkcs) \
216 int silc_##pkcs##_encrypt(void *context, \
217 unsigned char *src, \
218 SilcUInt32 src_len, \
219 unsigned char *dst, \
221 #define SILC_PKCS_API_DECRYPT(pkcs) \
222 int silc_##pkcs##_decrypt(void *context, \
223 unsigned char *src, \
224 SilcUInt32 src_len, \
225 unsigned char *dst, \
227 #define SILC_PKCS_API_SIGN(pkcs) \
228 int silc_##pkcs##_sign(void *context, \
229 unsigned char *src, \
230 SilcUInt32 src_len, \
231 unsigned char *dst, \
233 #define SILC_PKCS_API_VERIFY(pkcs) \
234 int silc_##pkcs##_verify(void *context, \
235 unsigned char *signature, \
236 SilcUInt32 signature_len, \
237 unsigned char *data, \
242 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register
246 * bool silc_pkcs_register(const SilcPKCSObject *pkcs);
250 * Registers a new PKCS into the SILC. This function is used
251 * at the initialization of the SILC. All registered PKCSs
252 * should be unregistered with silc_pkcs_unregister. The `pkcs' includes
253 * the name of the PKCS and member functions for the algorithm. Usually
254 * this function is not called directly. Instead, application can call
255 * the silc_pkcs_register_default to register all PKCSs that are
256 * builtin the sources. Returns FALSE on error.
259 bool silc_pkcs_register(const SilcPKCSObject *pkcs);
261 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister
265 * bool silc_pkcs_unregister(SilcPKCSObject *pkcs);
269 * Unregister a PKCS from the SILC. Returns FALSE on error.
272 bool silc_pkcs_unregister(SilcPKCSObject *pkcs);
274 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register_default
278 * bool silc_pkcs_register_default(void);
282 * Registers all the default PKCS (all builtin PKCS). The application may
283 * use this to register the default PKCS if specific PKCS in any specific
284 * order is not wanted. Returns FALSE on error.
287 bool silc_pkcs_register_default(void);
289 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister_all
293 * bool silc_pkcs_unregister_all(void);
297 * Returns FALSE on error.
300 bool silc_pkcs_unregister_all(void);
302 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_alloc
306 * bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
310 * Allocates a new SilcPKCS object. The new allocated object is returned
311 * to the 'new_pkcs' argument. Returns FALSE on error.
314 bool silc_pkcs_alloc(const unsigned char *name, SilcPKCS *new_pkcs);
316 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free
320 * void silc_pkcs_free(SilcPKCS pkcs);
324 * Frees the PKCS object.
327 void silc_pkcs_free(SilcPKCS pkcs);
329 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_is_supported
333 * bool silc_pkcs_is_supported(const unsigned char *name);
337 * Returns TRUE if PKCS algorithm `name' is supported.
340 bool silc_pkcs_is_supported(const unsigned char *name);
342 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_supported
346 * char *silc_pkcs_get_supported(void);
350 * Returns comma separated list of supported PKCS algorithms.
353 char *silc_pkcs_get_supported(void);
355 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_generate_key
359 * bool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
364 * Generate new key pair into the `pkcs' context. Returns FALSE on error.
367 bool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
370 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_key_len
374 * SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
378 * Returns the length of the key.
381 SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
383 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_name
387 * const char *silc_pkcs_get_name(SilcPKCS pkcs);
394 const char *silc_pkcs_get_name(SilcPKCS pkcs);
396 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_public_key
400 * unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
404 * Returns SILC style public key. The caller must free the returned
408 unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
410 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_private_key
414 * unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs,
419 * Returns SILC style private key. The caller must free the returned
420 * data and SHOULD zero the memory area before freeing.
423 unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, SilcUInt32 *len);
425 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_set
429 * SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs,
430 * SilcPublicKey public_key);
434 * Sets public key from SilcPublicKey. Returns the length of the key.
437 SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
439 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_set
443 * SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs,
445 * SilcUInt32 pk_len);
449 * Sets public key from data. Returns the length of the key.
452 SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
455 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_set
459 * SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs,
460 * SilcPrivateKey private_key);
464 * Sets private key from SilcPrivateKey. Returns the length of the key.
467 SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs, SilcPrivateKey private_key);
469 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_set
473 * SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs,
474 * unsigned char *prv,
475 * SilcUInt32 prv_len);
479 * Sets private key from data. Returns the length of the key.
482 SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs, unsigned char *prv,
485 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encrypt
489 * bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src,
490 * SilcUInt32 src_len, unsigned char *dst,
491 * SilcUInt32 *dst_len);
495 * Encrypts. Returns FALSE on error.
498 bool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
499 unsigned char *dst, SilcUInt32 *dst_len);
501 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt
505 * bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src,
506 * SilcUInt32 src_len, unsigned char *dst,
507 * SilcUInt32 *dst_len);
511 * Decrypts. Returns FALSE on error.
514 bool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
515 unsigned char *dst, SilcUInt32 *dst_len);
517 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign
521 * bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src,
522 * SilcUInt32 src_len, unsigned char *dst,
523 * SilcUInt32 *dst_len);
527 * Generates signature. Returns FALSE on error.
530 bool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
531 unsigned char *dst, SilcUInt32 *dst_len);
533 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify
537 * bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
538 * SilcUInt32 signature_len, unsigned char *data,
539 * SilcUInt32 data_len);
543 * Verifies signature. Returns FALSE on error.
546 bool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
547 SilcUInt32 signature_len, unsigned char *data,
548 SilcUInt32 data_len);
550 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign_with_hash
554 * bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
555 * unsigned char *src, SilcUInt32 src_len,
556 * unsigned char *dst, SilcUInt32 *dst_len);
560 * Generates signature with hash. The hash is signed. Returns FALSE on
564 bool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
565 unsigned char *src, SilcUInt32 src_len,
566 unsigned char *dst, SilcUInt32 *dst_len);
568 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify_with_hash
572 * bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
573 * unsigned char *signature,
574 * SilcUInt32 signature_len,
575 * unsigned char *data,
576 * SilcUInt32 data_len);
580 * Verifies signature with hash. The `data' is hashed and verified against
581 * the `signature'. Returns FALSE on error.
584 bool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
585 unsigned char *signature,
586 SilcUInt32 signature_len,
588 SilcUInt32 data_len);
590 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encode_identifier
594 * char *silc_pkcs_encode_identifier(char *username, char *host,
595 * char *realname, char *email,
596 * char *org, char *country);
600 * Encodes and returns SILC public key identifier. If some of the
601 * arguments is NULL those are not encoded into the identifier string.
602 * Protocol says that at least username and host must be provided.
605 char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
606 char *email, char *org, char *country);
608 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decode_identifier
612 * SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
616 * Decodes the provided `identifier' and returns allocated context for
620 SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
622 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free_identifier
626 * void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
630 * Frees decoded public key identifier context. Call this to free the
631 * context returned by the silc_pkcs_decode_identifier.
634 void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
636 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_alloc
640 * SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
641 * const char *identifier,
642 * const unsigned char *pk,
643 * SilcUInt32 pk_len);
647 * Allocates SILC style public key formed from sent arguments. All data
651 SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
652 const char *identifier,
653 const unsigned char *pk,
656 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_free
660 * void silc_pkcs_public_key_free(SilcPublicKey public_key);
667 void silc_pkcs_public_key_free(SilcPublicKey public_key);
669 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_alloc
673 * SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
674 * const unsigned char *prv,
675 * SilcUInt32 prv_len);
679 * Allocates SILC private key formed from sent arguments. All data is
683 SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
684 const unsigned char *prv,
687 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_free
691 * void silc_pkcs_private_key_free(SilcPrivateKey private_key);
698 void silc_pkcs_private_key_free(SilcPrivateKey private_key);
700 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_encode
705 * silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
709 * Encodes SILC style public key from SilcPublicKey. Returns the encoded
714 silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
716 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_encode
721 * silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
722 * char *pkcs, char *identifier,
727 * Encodes SILC style public key. Returns the encoded data.
731 silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
732 char *pkcs, char *identifier,
735 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
739 * bool silc_pkcs_public_key_decode(unsigned char *data,
740 * SilcUInt32 data_len,
741 * SilcPublicKey *public_key);
745 * Decodes SILC style public key. Returns TRUE if the decoding was
746 * successful. Allocates new public key as well.
749 bool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
750 SilcPublicKey *public_key);
752 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_payload_encode
756 * bool silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
760 * Encodes the Public Key Payload from the public key indicated by
761 * `public_key' of type of `pk_type'. The type is SilcSKEPKType.
762 * Returns the encoded payload buffer.
765 SilcBuffer silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
767 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_payload_decode
771 * bool 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(const char *filename,
870 * SilcPublicKey public_key,
871 * SilcUInt32 encoding);
875 * Saves public key into file. Returns FALSE on error.
878 bool silc_pkcs_save_public_key(const char *filename, SilcPublicKey public_key,
879 SilcUInt32 encoding);
881 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key_data
885 * bool silc_pkcs_save_public_key_data(const char *filename,
886 * unsigned char *data,
887 * SilcUInt32 data_len,
888 * SilcUInt32 encoding);
892 * Saves public key into file. The public key is already encoded as
893 * data when calling this function. Returns FALSE on error.
896 bool silc_pkcs_save_public_key_data(const char *filename, unsigned char *data,
897 SilcUInt32 data_len, SilcUInt32 encoding);
899 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key
903 * bool silc_pkcs_save_private_key(const char *filename,
904 * SilcPrivateKey private_key,
905 * unsigned char *passphrase,
906 * SilcUInt32 passphrase_len,
907 * SilcUInt32 encoding);
911 * Saves private key into file. The private key is encrypted into
912 * the file with the `passphrase' as a key. The encryption algorithm
913 * is AES with 256 bit key in CBC mode. Returns FALSE on error.
916 bool silc_pkcs_save_private_key(const char *filename,
917 SilcPrivateKey private_key,
918 unsigned char *passphrase,
919 SilcUInt32 passphrase_len,
920 SilcUInt32 encoding);
922 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_public_key
926 * bool silc_pkcs_load_public_key(const char *filename,
927 * SilcPublicKey *public_key,
928 * SilcUInt32 encoding);
932 * Loads public key from file and allocates new public key. Returns TRUE
933 * if loading was successful.
936 bool silc_pkcs_load_public_key(const char *filename, SilcPublicKey *public_key,
937 SilcUInt32 encoding);
939 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_private_key
943 * bool silc_pkcs_load_private_key(const char *filename,
944 * SilcPrivateKey *private_key,
945 * unsigned char *passphrase,
946 * SilcUInt32 passphrase_len,
947 * SilcUInt32 encoding);
951 * Loads private key from file and allocates new private key. Returns TRUE
952 * if loading was successful. The `passphrase' is used as decryption
953 * key of the private key file.
956 bool silc_pkcs_load_private_key(const char *filename,
957 SilcPrivateKey *private_key,
958 unsigned char *passphrase,
959 SilcUInt32 passphrase_len,
960 SilcUInt32 encoding);
962 #endif /* !SILCPKCS_H */