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 ***** */
46 ** RFC 4055 Section 1.2 specifies three different RSA key types.
48 ** rsaKey maps to keys with SEC_OID_PKCS1_RSA_ENCRYPTION and can be used for
49 ** both encryption and signatures with old (PKCS #1 v1.5) and new (PKCS #1
50 ** v2.1) padding schemes.
52 ** rsaPssKey maps to keys with SEC_OID_PKCS1_RSA_PSS_SIGNATURE and may only
53 ** be used for signatures with PSS padding (PKCS #1 v2.1).
55 ** rsaOaepKey maps to keys with SEC_OID_PKCS1_RSA_OAEP_ENCRYPTION and may only
56 ** be used for encryption with OAEP padding (PKCS #1 v2.1).
63 fortezzaKey = 3, /* deprecated */
65 keaKey = 5, /* deprecated */
72 ** Template Definitions
76 extern const SEC_ASN1Template SECKEY_RSAPublicKeyTemplate[];
77 extern const SEC_ASN1Template SECKEY_RSAPSSParamsTemplate[];
78 extern const SEC_ASN1Template SECKEY_DSAPublicKeyTemplate[];
79 extern const SEC_ASN1Template SECKEY_DHPublicKeyTemplate[];
80 extern const SEC_ASN1Template SECKEY_DHParamKeyTemplate[];
81 extern const SEC_ASN1Template SECKEY_PQGParamsTemplate[];
82 extern const SEC_ASN1Template SECKEY_DSAPrivateKeyExportTemplate[];
84 /* Windows DLL accessor functions */
85 SEC_ASN1_CHOOSER_DECLARE(SECKEY_DSAPublicKeyTemplate)
86 SEC_ASN1_CHOOSER_DECLARE(SECKEY_RSAPublicKeyTemplate)
87 SEC_ASN1_CHOOSER_DECLARE(SECKEY_RSAPSSParamsTemplate)
92 ** RSA Public Key structures
93 ** member names from PKCS#1, section 7.1
96 struct SECKEYRSAPublicKeyStr {
99 SECItem publicExponent;
101 typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey;
104 ** RSA-PSS parameters
106 struct SECKEYRSAPSSParamsStr {
107 SECAlgorithmID *hashAlg;
108 SECAlgorithmID *maskAlg;
110 SECItem trailerField;
112 typedef struct SECKEYRSAPSSParamsStr SECKEYRSAPSSParams;
115 ** DSA Public Key and related structures
118 struct SECKEYPQGParamsStr {
120 SECItem prime; /* p */
121 SECItem subPrime; /* q */
122 SECItem base; /* g */
123 /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2459 7.3.2) */
125 typedef struct SECKEYPQGParamsStr SECKEYPQGParams;
127 struct SECKEYDSAPublicKeyStr {
128 SECKEYPQGParams params;
131 typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey;
135 ** Diffie-Hellman Public Key structure
136 ** Structure member names suggested by PKCS#3.
138 struct SECKEYDHParamsStr {
140 SECItem prime; /* p */
141 SECItem base; /* g */
143 typedef struct SECKEYDHParamsStr SECKEYDHParams;
145 struct SECKEYDHPublicKeyStr {
151 typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey;
154 ** Elliptic curve Public Key structure
155 ** The PKCS#11 layer needs DER encoding of ANSI X9.62
158 typedef SECItem SECKEYECParams;
160 struct SECKEYECPublicKeyStr {
161 SECKEYECParams DEREncodedParams;
162 int size; /* size in bits */
163 SECItem publicValue; /* encoded point */
164 /* XXX Even though the PKCS#11 interface takes encoded parameters,
165 * we may still wish to decode them above PKCS#11 for things like
166 * printing key information. For named curves, which is what
167 * we initially support, we ought to have the curve name at the
171 typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey;
174 ** FORTEZZA Public Key structures
176 struct SECKEYFortezzaPublicKeyStr {
179 unsigned char KMID[8];
181 SECItem KEApriviledge;
182 SECItem DSSpriviledge;
185 SECKEYPQGParams params;
186 SECKEYPQGParams keaParams;
188 typedef struct SECKEYFortezzaPublicKeyStr SECKEYFortezzaPublicKey;
189 #define KEAprivilege KEApriviledge /* corrected spelling */
190 #define DSSprivilege DSSpriviledge /* corrected spelling */
192 struct SECKEYDiffPQGParamsStr {
193 SECKEYPQGParams DiffKEAParams;
194 SECKEYPQGParams DiffDSAParams;
196 typedef struct SECKEYDiffPQGParamsStr SECKEYDiffPQGParams;
198 struct SECKEYPQGDualParamsStr {
199 SECKEYPQGParams CommParams;
200 SECKEYDiffPQGParams DiffParams;
202 typedef struct SECKEYPQGDualParamsStr SECKEYPQGDualParams;
204 struct SECKEYKEAParamsStr {
208 typedef struct SECKEYKEAParamsStr SECKEYKEAParams;
210 struct SECKEYKEAPublicKeyStr {
211 SECKEYKEAParams params;
214 typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey;
217 ** A Generic public key object.
219 struct SECKEYPublicKeyStr {
222 PK11SlotInfo *pkcs11Slot;
223 CK_OBJECT_HANDLE pkcs11ID;
225 SECKEYRSAPublicKey rsa;
226 SECKEYDSAPublicKey dsa;
227 SECKEYDHPublicKey dh;
228 SECKEYKEAPublicKey kea;
229 SECKEYFortezzaPublicKey fortezza;
230 SECKEYECPublicKey ec;
233 typedef struct SECKEYPublicKeyStr SECKEYPublicKey;
235 /* bit flag definitions for staticflags */
236 #define SECKEY_Attributes_Cached 0x1 /* bit 0 states
237 whether attributes are cached */
238 #define SECKEY_CKA_PRIVATE (1U << 1) /* bit 1 is the value of CKA_PRIVATE */
240 #define SECKEY_ATTRIBUTES_CACHED(key) \
241 (0 != (key->staticflags & SECKEY_Attributes_Cached))
243 #define SECKEY_ATTRIBUTE_VALUE(key,attribute) \
244 (0 != (key->staticflags & SECKEY_##attribute))
246 #define SECKEY_HAS_ATTRIBUTE_SET(key,attribute) \
247 (0 != (key->staticflags & SECKEY_Attributes_Cached)) ? \
248 (0 != (key->staticflags & SECKEY_##attribute)) : \
249 PK11_HasAttributeSet(key->pkcs11Slot,key->pkcs11ID,attribute)
252 ** A generic key structure
254 struct SECKEYPrivateKeyStr {
257 PK11SlotInfo *pkcs11Slot; /* pkcs11 slot this key lives in */
258 CK_OBJECT_HANDLE pkcs11ID; /* ID of pkcs11 object */
259 PRBool pkcs11IsTemp; /* temp pkcs11 object, delete it when done */
260 void *wincx; /* context for errors and pw prompts */
261 PRUint32 staticflags; /* bit flag of cached PKCS#11 attributes */
263 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey;
267 SECKEYPrivateKey *key;
268 } SECKEYPrivateKeyListNode;
273 } SECKEYPrivateKeyList;
277 SECKEYPublicKey *key;
278 } SECKEYPublicKeyListNode;
283 } SECKEYPublicKeyList;
284 #endif /* _KEYTHI_H_ */