New SILC PKCS API, enabling support for other public keys/certs.
[silc.git] / lib / silccrypt / silcpk.h
1 /*
2
3   silcpk.h
4
5   Author: Pekka Riikonen <priikone@silcnet.org>
6
7   Copyright (C) 1997 - 2005 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 /****h* silccrypt/SILC Public Key Interface
21  *
22  * DESCRIPTION
23  *
24  * This interface implements the SILC protocol style public key, as defined
25  * by the SILC protocol specification.
26  *
27  ***/
28
29 #ifndef SILCPK_H
30 #define SILCPK_H
31
32 /****s* silccrypt/SilcPubkeyAPI/SilcPublicKeyIdentifier
33  *
34  * NAME
35  *
36  *    typedef struct { ... } *SilcPublicKeyIdentifier,
37  *                            SilcPublicKeyIdentifierStruct;
38  *
39  * DESCRIPTION
40  *
41  *    This structure contains the SILC Public Key identifier.  Note that
42  *    some of the fields may be NULL.
43  *
44  * SOURCE
45  */
46 typedef struct {
47   char *username;
48   char *host;
49   char *realname;
50   char *email;
51   char *org;
52   char *country;
53 } *SilcPublicKeyIdentifier, SilcPublicKeyIdentifierStruct;
54 /***/
55
56 /****s* silccrypt/SilcPubkeyAPI/SilcSILCPublicKey
57  *
58  * NAME
59  *
60  *    typedef struct { ... } *SilcSILCPublicKey;
61  *
62  * DESCRIPTION
63  *
64  *    This structure defines the SILC protocol style public key.  User
65  *    doesn't have to access this structure usually, except when access to
66  *    the identifier is required.  The silc_pkcs_get_context for the
67  *    PKCS type SILC_PKCS_SILC returns this context.
68  *
69  * SOURCE
70  */
71 typedef struct {
72   SilcPublicKeyIdentifierStruct identifier;
73   const SilcPKCSAlgorithm *pkcs;   /* PKCS algorithm */
74   void *public_key;                /* MPKCS algorithm specific public key */
75 } *SilcSILCPublicKey;
76 /***/
77
78 /****s* silccrypt/SilcPubkeyAPI/SilcSILCPrivateKey
79  *
80  * NAME
81  *
82  *    typedef struct { ... } *SilcSILCPrivateKey;
83  *
84  * DESCRIPTION
85  *
86  *    This structure defines the SILC protocol implementation specific
87  *    private key.  This structure isn't usually needed by the user.
88  *
89  * SOURCE
90  */
91 typedef struct {
92   const SilcPKCSAlgorithm *pkcs;   /* PKCS algorithm */
93   void *private_key;               /* PKCS algorithm specific private key */
94 } *SilcSILCPrivateKey;
95 /***/
96
97 /****f* silccrypt/SilcPubkeyAPI/silc_pkcs_silc_generate_key
98  *
99  * SYNOPSIS
100  *
101  *    SilcBool silc_pkcs_silc_generate_key(const char *algorithm,
102  *                                         const char *scheme,
103  *                                         SilcUInt32 bits_key_len,
104  *                                         SilcRng rng,
105  *                                         SilcPublicKey *ret_public_key,
106  *                                         SilcPrivateKey *ret_private_key)
107  *
108  * DESCRIPTION
109  *
110  *    Generate a new SILC key pair of the algorithm type `algorithm' with
111  *    the key length in bits of `bits_key_len'.  The `scheme' may be NULL.
112  *    Returns FALSE if key generation failed.
113  *
114  * EXAMPLE
115  *
116  *    // Generate RSA key pair with 2048 bit key length, using PKCS #1
117  *    // no OID scheme.
118  *    silc_pkcs_silc_generate_key("rsa", "pkcs1-no-oid", 2048,
119  *                                rng, &public_key, &private_key);
120  *
121  ***/
122 SilcBool silc_pkcs_silc_generate_key(const char *algorithm,
123                                      const char *scheme,
124                                      SilcUInt32 bits_key_len,
125                                      const char *identifier,
126                                      SilcRng rng,
127                                      SilcPublicKey *ret_public_key,
128                                      SilcPrivateKey *ret_private_key);
129
130 /****f* silccrypt/SilcPubkeyAPI/silc_pkcs_silc_decode_identifier
131  *
132  * SYNOPSIS
133  *
134  *    char *silc_pkcs_silc_encode_identifier(char *username, char *host,
135  *                                           char *realname, char *email,
136  *                                           char *org, char *country)
137  *
138  * DESCRIPTION
139  *
140  *    Encodes and returns SILC public key identifier.  If some of the
141  *    arguments are NULL those are not encoded into the identifier string.
142  *    Protocol says that at least username and host must be provided.
143  *    Caller must free the returned identifier string.
144  *
145  ***/
146 char *silc_pkcs_silc_encode_identifier(char *username, char *host,
147                                        char *realname, char *email,
148                                        char *org, char *country);
149
150 /****f* silccrypt/SilcPubkeyAPI/silc_pkcs_silc_decode_identifier
151  *
152  * SYNOPSIS
153  *
154  *    SilcBool silc_pkcs_silc_decode_identifier(const char *identifier,
155  *                                              SilcPublicKeyIdentifier ident);
156  *
157  * DESCRIPTION
158  *
159  *    Decodes SILC protocol public key identifier `identifier' into the
160  *    the `ident' structure.  Returns FALSE if the identifier is not valid
161  *    identifier string.
162  *
163  ***/
164 SilcBool silc_pkcs_silc_decode_identifier(const char *identifier,
165                                           SilcPublicKeyIdentifier ident);
166
167 #endif /* SILCPK_H */