Import from 1.9a8 tarball
[mozilla-nss.git] / security / nss / lib / cryptohi / keythi.h
blob0b7dad693bdf95948d074ddbc382dfd7e51fa859
1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
12 * License.
14 * The Original Code is the Netscape security libraries.
16 * The Initial Developer of the Original Code is
17 * Netscape Communications Corporation.
18 * Portions created by the Initial Developer are Copyright (C) 1994-2000
19 * the Initial Developer. All Rights Reserved.
21 * Contributor(s):
22 * Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
37 #ifndef _KEYTHI_H_
38 #define _KEYTHI_H_ 1
40 #include "plarena.h"
41 #include "pkcs11t.h"
42 #include "secmodt.h"
43 #include "prclist.h"
45 typedef enum {
46 nullKey = 0,
47 rsaKey = 1,
48 dsaKey = 2,
49 fortezzaKey = 3,
50 dhKey = 4,
51 keaKey = 5,
52 ecKey = 6
53 } KeyType;
56 ** Template Definitions
57 **/
59 SEC_BEGIN_PROTOS
60 extern const SEC_ASN1Template SECKEY_RSAPublicKeyTemplate[];
61 extern const SEC_ASN1Template SECKEY_DSAPublicKeyTemplate[];
62 extern const SEC_ASN1Template SECKEY_DHPublicKeyTemplate[];
63 extern const SEC_ASN1Template SECKEY_DHParamKeyTemplate[];
64 extern const SEC_ASN1Template SECKEY_PQGParamsTemplate[];
65 extern const SEC_ASN1Template SECKEY_DSAPrivateKeyExportTemplate[];
67 /* Windows DLL accessor functions */
68 extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_DSAPublicKeyTemplate;
69 extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_RSAPublicKeyTemplate;
70 SEC_END_PROTOS
74 ** RSA Public Key structures
75 ** member names from PKCS#1, section 7.1
78 struct SECKEYRSAPublicKeyStr {
79 PRArenaPool * arena;
80 SECItem modulus;
81 SECItem publicExponent;
83 typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey;
87 ** DSA Public Key and related structures
90 struct SECKEYPQGParamsStr {
91 PRArenaPool *arena;
92 SECItem prime; /* p */
93 SECItem subPrime; /* q */
94 SECItem base; /* g */
95 /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2459 7.3.2) */
97 typedef struct SECKEYPQGParamsStr SECKEYPQGParams;
99 struct SECKEYDSAPublicKeyStr {
100 SECKEYPQGParams params;
101 SECItem publicValue;
103 typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey;
107 ** Diffie-Hellman Public Key structure
108 ** Structure member names suggested by PKCS#3.
110 struct SECKEYDHParamsStr {
111 PRArenaPool * arena;
112 SECItem prime; /* p */
113 SECItem base; /* g */
115 typedef struct SECKEYDHParamsStr SECKEYDHParams;
117 struct SECKEYDHPublicKeyStr {
118 PRArenaPool * arena;
119 SECItem prime;
120 SECItem base;
121 SECItem publicValue;
123 typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey;
126 ** Elliptic curve Public Key structure
127 ** The PKCS#11 layer needs DER encoding of ANSI X9.62
128 ** parameters value
130 typedef SECItem SECKEYECParams;
132 struct SECKEYECPublicKeyStr {
133 SECKEYECParams DEREncodedParams;
134 int size; /* size in bits */
135 SECItem publicValue; /* encoded point */
136 /* XXX Even though the PKCS#11 interface takes encoded parameters,
137 * we may still wish to decode them above PKCS#11 for things like
138 * printing key information. For named curves, which is what
139 * we initially support, we ought to have the curve name at the
140 * very least.
143 typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey;
146 ** FORTEZZA Public Key structures
148 struct SECKEYFortezzaPublicKeyStr {
149 int KEAversion;
150 int DSSversion;
151 unsigned char KMID[8];
152 SECItem clearance;
153 SECItem KEApriviledge;
154 SECItem DSSpriviledge;
155 SECItem KEAKey;
156 SECItem DSSKey;
157 SECKEYPQGParams params;
158 SECKEYPQGParams keaParams;
160 typedef struct SECKEYFortezzaPublicKeyStr SECKEYFortezzaPublicKey;
162 struct SECKEYDiffPQGParamsStr {
163 SECKEYPQGParams DiffKEAParams;
164 SECKEYPQGParams DiffDSAParams;
166 typedef struct SECKEYDiffPQGParamsStr SECKEYDiffPQGParams;
168 struct SECKEYPQGDualParamsStr {
169 SECKEYPQGParams CommParams;
170 SECKEYDiffPQGParams DiffParams;
172 typedef struct SECKEYPQGDualParamsStr SECKEYPQGDualParams;
174 struct SECKEYKEAParamsStr {
175 PLArenaPool *arena;
176 SECItem hash;
178 typedef struct SECKEYKEAParamsStr SECKEYKEAParams;
180 struct SECKEYKEAPublicKeyStr {
181 SECKEYKEAParams params;
182 SECItem publicValue;
184 typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey;
187 ** A Generic public key object.
189 struct SECKEYPublicKeyStr {
190 PLArenaPool *arena;
191 KeyType keyType;
192 PK11SlotInfo *pkcs11Slot;
193 CK_OBJECT_HANDLE pkcs11ID;
194 union {
195 SECKEYRSAPublicKey rsa;
196 SECKEYDSAPublicKey dsa;
197 SECKEYDHPublicKey dh;
198 SECKEYKEAPublicKey kea;
199 SECKEYFortezzaPublicKey fortezza;
200 SECKEYECPublicKey ec;
201 } u;
203 typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
205 #define CachedAttribute(attribute,setbit) \
206 static const PRUint32 SECKEY_##attribute = 1 << setbit;
208 /* bit flag definitions for staticflags */
209 #define SECKEY_Attributes_Cached 0x1 /* bit 0 states
210 whether attributes are cached */
211 CachedAttribute(CKA_PRIVATE,1) /* bit 1 is the value of CKA_PRIVATE */
213 #define SECKEY_ATTRIBUTES_CACHED(key) \
214 (0 != (key->staticflags & SECKEY_Attributes_Cached))
216 #define SECKEY_ATTRIBUTE_VALUE(key,attribute) \
217 (0 != (key->staticflags & SECKEY_##attribute))
219 #define SECKEY_HAS_ATTRIBUTE_SET(key,attribute) \
220 (0 != (key->staticflags & SECKEY_Attributes_Cached)) ? \
221 (0 != (key->staticflags & SECKEY_##attribute)) : \
222 PK11_HasAttributeSet(key->pkcs11Slot,key->pkcs11ID,attribute)
225 ** A generic key structure
227 struct SECKEYPrivateKeyStr {
228 PLArenaPool *arena;
229 KeyType keyType;
230 PK11SlotInfo *pkcs11Slot; /* pkcs11 slot this key lives in */
231 CK_OBJECT_HANDLE pkcs11ID; /* ID of pkcs11 object */
232 PRBool pkcs11IsTemp; /* temp pkcs11 object, delete it when done */
233 void *wincx; /* context for errors and pw prompts */
234 PRUint32 staticflags; /* bit flag of cached PKCS#11 attributes */
236 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey;
238 typedef struct {
239 PRCList links;
240 SECKEYPrivateKey *key;
241 } SECKEYPrivateKeyListNode;
243 typedef struct {
244 PRCList list;
245 PRArenaPool *arena;
246 } SECKEYPrivateKeyList;
248 typedef struct {
249 PRCList links;
250 SECKEYPublicKey *key;
251 } SECKEYPublicKeyListNode;
253 typedef struct {
254 PRCList list;
255 PRArenaPool *arena;
256 } SECKEYPublicKeyList;
257 #endif /* _KEYTHI_H_ */