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
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.
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 ***** */
56 ** Template Definitions
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
;
74 ** RSA Public Key structures
75 ** member names from PKCS#1, section 7.1
78 struct SECKEYRSAPublicKeyStr
{
81 SECItem publicExponent
;
83 typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey
;
87 ** DSA Public Key and related structures
90 struct SECKEYPQGParamsStr
{
92 SECItem prime
; /* p */
93 SECItem subPrime
; /* q */
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
;
103 typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey
;
107 ** Diffie-Hellman Public Key structure
108 ** Structure member names suggested by PKCS#3.
110 struct SECKEYDHParamsStr
{
112 SECItem prime
; /* p */
113 SECItem base
; /* g */
115 typedef struct SECKEYDHParamsStr SECKEYDHParams
;
117 struct SECKEYDHPublicKeyStr
{
123 typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey
;
126 ** Elliptic curve Public Key structure
127 ** The PKCS#11 layer needs DER encoding of ANSI X9.62
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
143 typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey
;
146 ** FORTEZZA Public Key structures
148 struct SECKEYFortezzaPublicKeyStr
{
151 unsigned char KMID
[8];
153 SECItem KEApriviledge
;
154 SECItem DSSpriviledge
;
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
{
178 typedef struct SECKEYKEAParamsStr SECKEYKEAParams
;
180 struct SECKEYKEAPublicKeyStr
{
181 SECKEYKEAParams params
;
184 typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey
;
187 ** A Generic public key object.
189 struct SECKEYPublicKeyStr
{
192 PK11SlotInfo
*pkcs11Slot
;
193 CK_OBJECT_HANDLE pkcs11ID
;
195 SECKEYRSAPublicKey rsa
;
196 SECKEYDSAPublicKey dsa
;
197 SECKEYDHPublicKey dh
;
198 SECKEYKEAPublicKey kea
;
199 SECKEYFortezzaPublicKey fortezza
;
200 SECKEYECPublicKey ec
;
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
{
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
;
240 SECKEYPrivateKey
*key
;
241 } SECKEYPrivateKeyListNode
;
246 } SECKEYPrivateKeyList
;
250 SECKEYPublicKey
*key
;
251 } SECKEYPublicKeyListNode
;
256 } SECKEYPublicKeyList
;
257 #endif /* _KEYTHI_H_ */