PageRenderTime 195ms CodeModel.GetById 94ms app.highlight 13ms RepoModel.GetById 58ms app.codeStats 0ms

/gecko_api/include/keythi.h

http://firefox-mac-pdf.googlecode.com/
C++ Header | 258 lines | 150 code | 34 blank | 74 comment | 4 complexity | 6b4564f84e36cea4c2a7083a18d55e2e MD5 | raw file
  1/* ***** BEGIN LICENSE BLOCK *****
  2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  3 *
  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/
  8 *
  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.
 13 *
 14 * The Original Code is the Netscape security libraries.
 15 *
 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.
 20 *
 21 * Contributor(s):
 22 *   Dr Vipul Gupta <vipul.gupta@sun.com>, Sun Microsystems Laboratories
 23 *
 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.
 35 *
 36 * ***** END LICENSE BLOCK ***** */
 37#ifndef _KEYTHI_H_
 38#define _KEYTHI_H_ 1
 39
 40#include "plarena.h"
 41#include "pkcs11t.h"
 42#include "secmodt.h"
 43#include "prclist.h"
 44
 45typedef enum { 
 46    nullKey = 0, 
 47    rsaKey = 1, 
 48    dsaKey = 2, 
 49    fortezzaKey = 3,
 50    dhKey = 4, 
 51    keaKey = 5,
 52    ecKey = 6
 53} KeyType;
 54
 55/*
 56** Template Definitions
 57**/
 58
 59SEC_BEGIN_PROTOS
 60extern const SEC_ASN1Template SECKEY_RSAPublicKeyTemplate[];
 61extern const SEC_ASN1Template SECKEY_DSAPublicKeyTemplate[];
 62extern const SEC_ASN1Template SECKEY_DHPublicKeyTemplate[];
 63extern const SEC_ASN1Template SECKEY_DHParamKeyTemplate[];
 64extern const SEC_ASN1Template SECKEY_PQGParamsTemplate[];
 65extern const SEC_ASN1Template SECKEY_DSAPrivateKeyExportTemplate[];
 66
 67/* Windows DLL accessor functions */
 68extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_DSAPublicKeyTemplate;
 69extern SEC_ASN1TemplateChooser NSS_Get_SECKEY_RSAPublicKeyTemplate;
 70SEC_END_PROTOS
 71
 72
 73/*
 74** RSA Public Key structures
 75** member names from PKCS#1, section 7.1 
 76*/
 77
 78struct SECKEYRSAPublicKeyStr {
 79    PRArenaPool * arena;
 80    SECItem modulus;
 81    SECItem publicExponent;
 82};
 83typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey;
 84
 85
 86/*
 87** DSA Public Key and related structures
 88*/
 89
 90struct 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) */
 96};
 97typedef struct SECKEYPQGParamsStr SECKEYPQGParams;
 98
 99struct SECKEYDSAPublicKeyStr {
100    SECKEYPQGParams params;
101    SECItem publicValue;
102};
103typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey;
104
105
106/*
107** Diffie-Hellman Public Key structure
108** Structure member names suggested by PKCS#3.
109*/
110struct SECKEYDHParamsStr {
111    PRArenaPool * arena;
112    SECItem prime; /* p */
113    SECItem base; /* g */
114};
115typedef struct SECKEYDHParamsStr SECKEYDHParams;
116
117struct SECKEYDHPublicKeyStr {
118    PRArenaPool * arena;
119    SECItem prime;
120    SECItem base;
121    SECItem publicValue;
122};
123typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey;
124
125/*
126** Elliptic curve Public Key structure
127** The PKCS#11 layer needs DER encoding of ANSI X9.62
128** parameters value
129*/
130typedef SECItem SECKEYECParams;
131
132struct 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.
141     */
142};
143typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey;
144
145/*
146** FORTEZZA Public Key structures
147*/
148struct 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;
159};
160typedef struct SECKEYFortezzaPublicKeyStr SECKEYFortezzaPublicKey;
161
162struct SECKEYDiffPQGParamsStr {
163    SECKEYPQGParams DiffKEAParams;
164    SECKEYPQGParams DiffDSAParams;
165};
166typedef struct SECKEYDiffPQGParamsStr SECKEYDiffPQGParams;
167
168struct SECKEYPQGDualParamsStr {
169    SECKEYPQGParams CommParams;
170    SECKEYDiffPQGParams DiffParams;
171};
172typedef struct SECKEYPQGDualParamsStr SECKEYPQGDualParams;
173
174struct SECKEYKEAParamsStr {
175    PLArenaPool *arena;
176    SECItem hash;
177};
178typedef struct SECKEYKEAParamsStr SECKEYKEAParams;
179 
180struct SECKEYKEAPublicKeyStr {
181    SECKEYKEAParams params;
182    SECItem publicValue;
183};
184typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey;
185
186/*
187** A Generic  public key object.
188*/
189struct 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;
202};
203typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
204
205#define CachedAttribute(attribute,setbit) \
206static const PRUint32 SECKEY_##attribute = 1 << setbit;
207
208/* bit flag definitions for staticflags */
209#define SECKEY_Attributes_Cached 0x1    /* bit 0 states
210                                           whether attributes are cached */
211CachedAttribute(CKA_PRIVATE,1) /* bit 1 is the value of CKA_PRIVATE */
212
213#define SECKEY_ATTRIBUTES_CACHED(key) \
214     (0 != (key->staticflags & SECKEY_Attributes_Cached))
215
216#define SECKEY_ATTRIBUTE_VALUE(key,attribute) \
217     (0 != (key->staticflags & SECKEY_##attribute))
218
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)
223
224/*
225** A generic key structure
226*/ 
227struct 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 */
235};
236typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey;
237
238typedef struct {
239    PRCList links;
240    SECKEYPrivateKey *key;
241} SECKEYPrivateKeyListNode;
242
243typedef struct {
244    PRCList list;
245    PRArenaPool *arena;
246} SECKEYPrivateKeyList;
247
248typedef struct {
249    PRCList links;
250    SECKEYPublicKey *key;
251} SECKEYPublicKeyListNode;
252
253typedef struct {
254    PRCList list;
255    PRArenaPool *arena;
256} SECKEYPublicKeyList;
257#endif /* _KEYTHI_H_ */
258