5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2007 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.
24 #error "Do not include this header directly"
27 /* The PKCS Algorithm object to represent any PKCS algorithm. This context
28 implements the PKCS algorithm, such as RSA, DSA, etc. */
29 struct SilcPKCSAlgorithmStruct {
30 /* Algorithm name and scheme */
31 char *name; /* Eg. rsa, dsa, etc. */
32 char *scheme; /* Eg. pkcs1, openpgp, etc. */
34 /* Supported hash functions, comma separated list */
37 /* Generate new key pair. Returns PKCS algorithm specific public key
38 and private key contexts. */
39 SilcBool (*generate_key)(const struct SilcPKCSAlgorithmStruct *pkcs,
42 void **ret_public_key,
43 void **ret_private_key);
45 /* Public key routines. */
47 /* Import/create new public key. Returns the length of the data that was
48 imported from `key' or 0 on error. Returns the PKCS algorithm specific
49 public key to `ret_public_key'. */
50 int (*import_public_key)(const struct SilcPKCSAlgorithmStruct *pkcs,
51 void *key, SilcUInt32 key_len,
52 void **ret_public_key);
54 /* Export/encode public key. Returns the encoded public key buffer that
55 the caller must free. */
57 (*export_public_key)(const struct SilcPKCSAlgorithmStruct *pkcs,
62 /* Returns the bit length of public key */
63 SilcUInt32 (*public_key_bitlen)(const struct SilcPKCSAlgorithmStruct *pkcs,
66 /* Duplicated public key */
67 void *(*public_key_copy)(const struct SilcPKCSAlgorithmStruct *pkcs,
70 /* Compares two public keys. Returns TRUE if they are identical. */
71 SilcBool (*public_key_compare)(const struct SilcPKCSAlgorithmStruct *pkcs,
72 void *key1, void *key2);
75 void (*public_key_free)(const struct SilcPKCSAlgorithmStruct *pkcs,
78 /* Private key routines. */
80 /* Import/create new private key. Returns the length of the data that was
81 imported from `key' or 0 on error. Returns the PKCS algorithm specific
82 private key to `ret_private_key'. */
83 int (*import_private_key)(const struct SilcPKCSAlgorithmStruct *pkcs,
86 void **ret_private_key);
88 /* Export/encode private key. Returns the encoded private key buffer that
89 the caller must free. */
91 (*export_private_key)(const struct SilcPKCSAlgorithmStruct *pkcs,
96 /* Returns the bi length of private key */
97 SilcUInt32 (*private_key_bitlen)(const struct SilcPKCSAlgorithmStruct *pkcs,
100 /* Free private key */
101 void (*private_key_free)(const struct SilcPKCSAlgorithmStruct *pkcs,
104 /* Encrypt and decrypt operations */
105 SilcAsyncOperation (*encrypt)(const struct SilcPKCSAlgorithmStruct *pkcs,
110 SilcPKCSEncryptCb encrypt_cb,
112 SilcAsyncOperation (*decrypt)(const struct SilcPKCSAlgorithmStruct *pkcs,
116 SilcPKCSDecryptCb decrypt_cb,
119 /* Signature and verification operations */
120 SilcAsyncOperation (*sign)(const struct SilcPKCSAlgorithmStruct *pkcs,
124 SilcBool compute_hash,
126 SilcPKCSSignCb sign_cb,
128 SilcAsyncOperation (*verify)(const struct SilcPKCSAlgorithmStruct *pkcs,
130 unsigned char *signature,
131 SilcUInt32 signature_len,
135 SilcPKCSVerifyCb verify_cb,
139 /* The PKCS (Public Key Cryptosystem) object to represent any PKCS. This
140 context implements the PKCS, such as SILC public keys, X.509 certificates,
141 OpenPGP certificates, etc. under a common API. */
142 struct SilcPKCSObjectStruct {
146 /* Public key routines */
148 /* Returns PKCS algorithm context from public key */
149 const SilcPKCSAlgorithm *
150 (*get_algorithm)(const struct SilcPKCSObjectStruct *pkcs,
153 /* Imports from public key file */
154 SilcBool (*import_public_key_file)(const struct SilcPKCSObjectStruct *pkcs,
155 unsigned char *filedata,
156 SilcUInt32 filedata_len,
157 SilcPKCSFileEncoding encoding,
158 void **ret_public_key);
160 /* Imports from public key binary data. Returns the amount of bytes
161 imported from `key' or 0 on error. */
162 int (*import_public_key)(const struct SilcPKCSObjectStruct *pkcs,
165 void **ret_public_key);
167 /* Exports public key to file */
169 (*export_public_key_file)(const struct SilcPKCSObjectStruct *pkcs,
172 SilcPKCSFileEncoding encoding,
173 SilcUInt32 *ret_len);
175 /* Export public key as binary data */
176 unsigned char *(*export_public_key)(const struct SilcPKCSObjectStruct *pkcs,
179 SilcUInt32 *ret_len);
181 /* Returns key length in bits */
182 SilcUInt32 (*public_key_bitlen)(const struct SilcPKCSObjectStruct *pkcs,
185 /* Copy public key */
186 void *(*public_key_copy)(const struct SilcPKCSObjectStruct *pkcs,
189 /* Compares public keys */
190 SilcBool (*public_key_compare)(const struct SilcPKCSObjectStruct *pkcs,
191 void *key1, void *key2);
193 /* Free public key */
194 void (*public_key_free)(const struct SilcPKCSObjectStruct *pkcs,
197 /* Private key routines */
199 /* Imports from private key file */
200 SilcBool (*import_private_key_file)(const struct SilcPKCSObjectStruct *pkcs,
201 unsigned char *filedata,
202 SilcUInt32 filedata_len,
203 const char *passphrase,
204 SilcUInt32 passphrase_len,
205 SilcPKCSFileEncoding encoding,
206 void **ret_private_key);
208 /* Imports from private key binary data. Returns the amount of bytes
209 imported from `key' or 0 on error. */
210 int (*import_private_key)(const struct SilcPKCSObjectStruct *pkcs,
213 void **ret_private_key);
215 /* Exports private key to file */
217 (*export_private_key_file)(const struct SilcPKCSObjectStruct *pkcs,
220 const char *passphrase,
221 SilcUInt32 passphrase_len,
222 SilcPKCSFileEncoding encoding,
224 SilcUInt32 *ret_len);
226 /* Export private key as binary data */
227 unsigned char *(*export_private_key)(const struct SilcPKCSObjectStruct *pkcs,
230 SilcUInt32 *ret_len);
232 /* Returns key length in bits */
233 SilcUInt32 (*private_key_bitlen)(const struct SilcPKCSObjectStruct *pkcs,
236 /* Free private key */
237 void (*private_key_free)(const struct SilcPKCSObjectStruct *pkcs,
240 /* Encrypt and decrypt operations */
241 SilcAsyncOperation (*encrypt)(const struct SilcPKCSObjectStruct *pkcs,
246 SilcPKCSEncryptCb encrypt_cb,
248 SilcAsyncOperation (*decrypt)(const struct SilcPKCSObjectStruct *pkcs,
252 SilcPKCSDecryptCb decrypt_cb,
255 /* Signature and verification operations */
256 SilcAsyncOperation (*sign)(const struct SilcPKCSObjectStruct *pkcs,
260 SilcBool compute_hash,
262 SilcPKCSSignCb sign_cb,
264 SilcAsyncOperation (*verify)(const struct SilcPKCSObjectStruct *pkcs,
266 unsigned char *signature,
267 SilcUInt32 signature_len,
271 SilcPKCSVerifyCb verify_cb,
275 #endif /* SILCPKCS_I_H */