5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2003 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 * SilcBool 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 SilcBool silc_pkcs_register(const SilcPKCSObject *pkcs);
261 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister
265 * SilcBool silc_pkcs_unregister(SilcPKCSObject *pkcs);
269 * Unregister a PKCS from the SILC. Returns FALSE on error.
272 SilcBool silc_pkcs_unregister(SilcPKCSObject *pkcs);
274 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_register_default
278 * SilcBool 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 SilcBool silc_pkcs_register_default(void);
289 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_unregister_all
293 * SilcBool silc_pkcs_unregister_all(void);
297 * Returns FALSE on error.
300 SilcBool silc_pkcs_unregister_all(void);
302 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_alloc
306 * SilcBool 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 SilcBool 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 * SilcBool silc_pkcs_is_supported(const unsigned char *name);
337 * Returns TRUE if PKCS algorithm `name' is supported.
340 SilcBool 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 * SilcBool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
364 * Generate new key pair into the `pkcs' context. Returns FALSE on error.
365 * If the `rng' is NULL global SILC RNG will be used.
368 SilcBool silc_pkcs_generate_key(SilcPKCS pkcs, SilcUInt32 bits_key_len,
371 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_key_len
375 * SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
379 * Returns the length of the key in bits.
382 SilcUInt32 silc_pkcs_get_key_len(SilcPKCS self);
384 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_name
388 * const char *silc_pkcs_get_name(SilcPKCS pkcs);
395 const char *silc_pkcs_get_name(SilcPKCS pkcs);
397 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_public_key
401 * unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
405 * Returns SILC style public key for the PKCS. Note that this is not
406 * the SILC Public Key, but the raw public key data from the PKCS.
407 * The caller must free the returned data.
410 unsigned char *silc_pkcs_get_public_key(SilcPKCS pkcs, SilcUInt32 *len);
412 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_get_private_key
416 * unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs,
421 * Returns SILC style private key. Note that this is not SilcPrivateKey
422 * but the raw private key bits from the PKCS. The caller must free the
423 * returned data and SHOULD zero the memory area before freeing.
426 unsigned char *silc_pkcs_get_private_key(SilcPKCS pkcs, SilcUInt32 *len);
428 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_set
432 * SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs,
433 * SilcPublicKey public_key);
437 * Sets public key from SilcPublicKey. Returns the length of the key in
441 SilcUInt32 silc_pkcs_public_key_set(SilcPKCS pkcs, SilcPublicKey public_key);
443 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_set
447 * SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs,
449 * SilcUInt32 pk_len);
453 * Sets public key from data. Returns the length of the key.
456 SilcUInt32 silc_pkcs_public_key_data_set(SilcPKCS pkcs, unsigned char *pk,
459 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_set
463 * SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs,
464 * SilcPrivateKey private_key);
468 * Sets private key from SilcPrivateKey. Returns the length of the key
472 SilcUInt32 silc_pkcs_private_key_set(SilcPKCS pkcs,
473 SilcPrivateKey private_key);
475 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_set
479 * SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs,
480 * unsigned char *prv,
481 * SilcUInt32 prv_len);
485 * Sets private key from data. Returns the length of the key.
488 SilcUInt32 silc_pkcs_private_key_data_set(SilcPKCS pkcs, unsigned char *prv,
491 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encrypt
495 * SilcBool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src,
496 * SilcUInt32 src_len, unsigned char *dst,
497 * SilcUInt32 *dst_len);
501 * Encrypts. Returns FALSE on error.
504 SilcBool silc_pkcs_encrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
505 unsigned char *dst, SilcUInt32 *dst_len);
507 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decrypt
511 * SilcBool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src,
512 * SilcUInt32 src_len, unsigned char *dst,
513 * SilcUInt32 *dst_len);
517 * Decrypts. Returns FALSE on error.
520 SilcBool silc_pkcs_decrypt(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
521 unsigned char *dst, SilcUInt32 *dst_len);
523 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign
527 * SilcBool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src,
528 * SilcUInt32 src_len, unsigned char *dst,
529 * SilcUInt32 *dst_len);
533 * Generates signature. Returns FALSE on error.
536 SilcBool silc_pkcs_sign(SilcPKCS pkcs, unsigned char *src, SilcUInt32 src_len,
537 unsigned char *dst, SilcUInt32 *dst_len);
539 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify
543 * SilcBool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
544 * SilcUInt32 signature_len, unsigned char *data,
545 * SilcUInt32 data_len);
549 * Verifies signature. Returns FALSE on error. The 'signature' is
550 * verified against the 'data'.
553 SilcBool silc_pkcs_verify(SilcPKCS pkcs, unsigned char *signature,
554 SilcUInt32 signature_len, unsigned char *data,
555 SilcUInt32 data_len);
557 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_sign_with_hash
561 * SilcBool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
562 * unsigned char *src, SilcUInt32 src_len,
563 * unsigned char *dst, SilcUInt32 *dst_len);
567 * Generates signature with hash. The hash is signed. Returns FALSE on
571 SilcBool silc_pkcs_sign_with_hash(SilcPKCS pkcs, SilcHash hash,
572 unsigned char *src, SilcUInt32 src_len,
573 unsigned char *dst, SilcUInt32 *dst_len);
575 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_verify_with_hash
579 * SilcBool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
580 * unsigned char *signature,
581 * SilcUInt32 signature_len,
582 * unsigned char *data,
583 * SilcUInt32 data_len);
587 * Verifies signature with hash. The `data' is hashed and verified against
588 * the `signature'. Returns FALSE on error.
591 SilcBool silc_pkcs_verify_with_hash(SilcPKCS pkcs, SilcHash hash,
592 unsigned char *signature,
593 SilcUInt32 signature_len,
595 SilcUInt32 data_len);
597 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_encode_identifier
601 * char *silc_pkcs_encode_identifier(char *username, char *host,
602 * char *realname, char *email,
603 * char *org, char *country);
607 * Encodes and returns SILC public key identifier. If some of the
608 * arguments is NULL those are not encoded into the identifier string.
609 * Protocol says that at least username and host must be provided.
612 char *silc_pkcs_encode_identifier(char *username, char *host, char *realname,
613 char *email, char *org, char *country);
615 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_decode_identifier
619 * SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
623 * Decodes the provided `identifier' and returns allocated context for
627 SilcPublicKeyIdentifier silc_pkcs_decode_identifier(char *identifier);
629 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_free_identifier
633 * void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
637 * Frees decoded public key identifier context. Call this to free the
638 * context returned by the silc_pkcs_decode_identifier.
641 void silc_pkcs_free_identifier(SilcPublicKeyIdentifier identifier);
643 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_alloc
647 * SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
648 * const char *identifier,
649 * const unsigned char *pk,
650 * SilcUInt32 pk_len);
654 * Allocates SILC style public key formed from sent arguments. The
655 * 'name' is the algorithm (PKCS) name, the 'identifier' is the public
656 * key identifier generated with silc_pkcs_encode_identifier, and the
657 * 'pk' and 'pk_len' are the raw public key data returned for example
658 * by silc_pkcs_get_public_key.
661 SilcPublicKey silc_pkcs_public_key_alloc(const char *name,
662 const char *identifier,
663 const unsigned char *pk,
666 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_free
670 * void silc_pkcs_public_key_free(SilcPublicKey public_key);
674 * Frees public key and all data in it.
677 void silc_pkcs_public_key_free(SilcPublicKey public_key);
679 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_alloc
683 * SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
684 * const unsigned char *prv,
685 * SilcUInt32 prv_len);
689 * Allocates SILC private key formed from sent arguments. The 'name'
690 * is the algorithm name, and the 'prv' and 'prv_len' are the raw
691 * private key bits returned by silc_pkcs_get_private_key.
694 SilcPrivateKey silc_pkcs_private_key_alloc(const char *name,
695 const unsigned char *prv,
698 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_free
702 * void silc_pkcs_private_key_free(SilcPrivateKey private_key);
706 * Frees private key and all data in it. The private key is zeroed
707 * before it is freed.
710 void silc_pkcs_private_key_free(SilcPrivateKey private_key);
712 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_encode
717 * silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
721 * Encodes SILC style public key from SilcPublicKey. Returns the encoded
726 silc_pkcs_public_key_encode(SilcPublicKey public_key, SilcUInt32 *len);
728 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_data_encode
733 * silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
734 * char *pkcs, char *identifier,
739 * Encodes SILC style public key. Returns the encoded data.
743 silc_pkcs_public_key_data_encode(unsigned char *pk, SilcUInt32 pk_len,
744 char *pkcs, char *identifier,
747 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_decode
751 * SilcBool silc_pkcs_public_key_decode(unsigned char *data,
752 * SilcUInt32 data_len,
753 * SilcPublicKey *public_key);
757 * Decodes SILC style public key. Returns TRUE if the decoding was
758 * successful. Allocates new public key as well.
761 SilcBool silc_pkcs_public_key_decode(unsigned char *data, SilcUInt32 data_len,
762 SilcPublicKey *public_key);
764 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_payload_encode
768 * SilcBool silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
772 * Encodes the Public Key Payload from the public key indicated by
773 * `public_key' of type of `pk_type'. The type is SilcSKEPKType.
774 * Returns the encoded payload buffer.
777 SilcBuffer silc_pkcs_public_key_payload_encode(SilcPublicKey public_key);
779 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_payload_decode
783 * SilcBool silc_pkcs_public_key_payload_decode(unsigned char *data,
784 * SilcUInt32 data_len,
785 * SilcPublicKey *public_key);
789 * Decodes Public Key Payload from `data' of `data_len' bytes in length
790 * data buffer into `public_key' pointer. Returns FALSE if the payload
794 SilcBool silc_pkcs_public_key_payload_decode(unsigned char *data,
796 SilcPublicKey *public_key);
798 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_compare
802 * SilcBool silc_pkcs_public_key_compare(SilcPublicKey key1,
803 * SilcPublicKey key2);
807 * Compares two public keys and returns TRUE if they are same key, and
808 * FALSE if they are not same.
811 SilcBool silc_pkcs_public_key_compare(SilcPublicKey key1, SilcPublicKey key2);
813 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_public_key_copy
817 * SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
821 * Copies the public key indicated by `public_key' and returns new allocated
822 * public key which is indentical to the `public_key'.
825 SilcPublicKey silc_pkcs_public_key_copy(SilcPublicKey public_key);
827 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_encode
832 * silc_pkcs_private_key_encode(SilcPrivateKey private_key,
837 * Encodes SILC private key from SilcPrivateKey. Returns the encoded data.
841 silc_pkcs_private_key_encode(SilcPrivateKey private_key, SilcUInt32 *len);
843 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_data_encode
848 * silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
849 * char *pkcs, SilcUInt32 *len);
853 * Encodes SILC private key. Returns the encoded data.
857 silc_pkcs_private_key_data_encode(unsigned char *prv, SilcUInt32 prv_len,
858 char *pkcs, SilcUInt32 *len);
860 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_private_key_decode
864 * SilcBool silc_pkcs_private_key_decode(unsigned char *data,
865 * SilcUInt32 data_len,
866 * SilcPrivateKey *private_key);
870 * Decodes SILC style private key. Returns TRUE if the decoding was
871 * successful. Allocates new private key as well.
874 SilcBool silc_pkcs_private_key_decode(unsigned char *data, SilcUInt32 data_len,
875 SilcPrivateKey *private_key);
877 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key
881 * SilcBool silc_pkcs_save_public_key(const char *filename,
882 * SilcPublicKey public_key,
883 * SilcUInt32 encoding);
887 * Saves public key into file. Returns FALSE on error.
890 SilcBool silc_pkcs_save_public_key(const char *filename, SilcPublicKey public_key,
891 SilcUInt32 encoding);
893 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_public_key_data
897 * SilcBool silc_pkcs_save_public_key_data(const char *filename,
898 * unsigned char *data,
899 * SilcUInt32 data_len,
900 * SilcUInt32 encoding);
904 * Saves public key into file. The public key is already encoded as
905 * data when calling this function. Returns FALSE on error.
908 SilcBool silc_pkcs_save_public_key_data(const char *filename, unsigned char *data,
909 SilcUInt32 data_len, SilcUInt32 encoding);
911 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_save_private_key
915 * SilcBool silc_pkcs_save_private_key(const char *filename,
916 * SilcPrivateKey private_key,
917 * unsigned char *passphrase,
918 * SilcUInt32 passphrase_len,
919 * SilcUInt32 encoding);
923 * Saves private key into file. The private key is encrypted into
924 * the file with the `passphrase' as a key. The encryption algorithm
925 * is AES with 256 bit key in CBC mode. Returns FALSE on error.
928 SilcBool silc_pkcs_save_private_key(const char *filename,
929 SilcPrivateKey private_key,
930 unsigned char *passphrase,
931 SilcUInt32 passphrase_len,
932 SilcUInt32 encoding);
934 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_public_key
938 * SilcBool silc_pkcs_load_public_key(const char *filename,
939 * SilcPublicKey *public_key,
940 * SilcUInt32 encoding);
944 * Loads public key from file and allocates new public key. Returns TRUE
945 * if loading was successful.
948 SilcBool silc_pkcs_load_public_key(const char *filename, SilcPublicKey *public_key,
949 SilcUInt32 encoding);
951 /****f* silccrypt/SilcPKCSAPI/silc_pkcs_load_private_key
955 * SilcBool silc_pkcs_load_private_key(const char *filename,
956 * SilcPrivateKey *private_key,
957 * unsigned char *passphrase,
958 * SilcUInt32 passphrase_len,
959 * SilcUInt32 encoding);
963 * Loads private key from file and allocates new private key. Returns TRUE
964 * if loading was successful. The `passphrase' is used as decryption
965 * key of the private key file.
968 SilcBool silc_pkcs_load_private_key(const char *filename,
969 SilcPrivateKey *private_key,
970 unsigned char *passphrase,
971 SilcUInt32 passphrase_len,
972 SilcUInt32 encoding);
974 #endif /* !SILCPKCS_H */