| OLD | NEW |
| (Empty) |
| 1 /* This Source Code Form is subject to the terms of the Mozilla Public | |
| 2 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
| 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | |
| 4 #ifndef _KEYTHI_H_ | |
| 5 #define _KEYTHI_H_ 1 | |
| 6 | |
| 7 #include "plarena.h" | |
| 8 #include "pkcs11t.h" | |
| 9 #include "secmodt.h" | |
| 10 #include "prclist.h" | |
| 11 | |
| 12 /* | |
| 13 ** RFC 4055 Section 1.2 specifies three different RSA key types. | |
| 14 ** | |
| 15 ** rsaKey maps to keys with SEC_OID_PKCS1_RSA_ENCRYPTION and can be used for | |
| 16 ** both encryption and signatures with old (PKCS #1 v1.5) and new (PKCS #1 | |
| 17 ** v2.1) padding schemes. | |
| 18 ** | |
| 19 ** rsaPssKey maps to keys with SEC_OID_PKCS1_RSA_PSS_SIGNATURE and may only | |
| 20 ** be used for signatures with PSS padding (PKCS #1 v2.1). | |
| 21 ** | |
| 22 ** rsaOaepKey maps to keys with SEC_OID_PKCS1_RSA_OAEP_ENCRYPTION and may only | |
| 23 ** be used for encryption with OAEP padding (PKCS #1 v2.1). | |
| 24 */ | |
| 25 | |
| 26 typedef enum { | |
| 27 nullKey = 0, | |
| 28 rsaKey = 1, | |
| 29 dsaKey = 2, | |
| 30 fortezzaKey = 3, /* deprecated */ | |
| 31 dhKey = 4, | |
| 32 keaKey = 5, /* deprecated */ | |
| 33 ecKey = 6, | |
| 34 rsaPssKey = 7, | |
| 35 rsaOaepKey = 8 | |
| 36 } KeyType; | |
| 37 | |
| 38 /* | |
| 39 ** Template Definitions | |
| 40 **/ | |
| 41 | |
| 42 SEC_BEGIN_PROTOS | |
| 43 extern const SEC_ASN1Template SECKEY_RSAPublicKeyTemplate[]; | |
| 44 extern const SEC_ASN1Template SECKEY_RSAPSSParamsTemplate[]; | |
| 45 extern const SEC_ASN1Template SECKEY_DSAPublicKeyTemplate[]; | |
| 46 extern const SEC_ASN1Template SECKEY_DHPublicKeyTemplate[]; | |
| 47 extern const SEC_ASN1Template SECKEY_DHParamKeyTemplate[]; | |
| 48 extern const SEC_ASN1Template SECKEY_PQGParamsTemplate[]; | |
| 49 extern const SEC_ASN1Template SECKEY_DSAPrivateKeyExportTemplate[]; | |
| 50 | |
| 51 /* Windows DLL accessor functions */ | |
| 52 SEC_ASN1_CHOOSER_DECLARE(SECKEY_DSAPublicKeyTemplate) | |
| 53 SEC_ASN1_CHOOSER_DECLARE(SECKEY_RSAPublicKeyTemplate) | |
| 54 SEC_ASN1_CHOOSER_DECLARE(SECKEY_RSAPSSParamsTemplate) | |
| 55 SEC_END_PROTOS | |
| 56 | |
| 57 /* | |
| 58 ** RSA Public Key structures | |
| 59 ** member names from PKCS#1, section 7.1 | |
| 60 */ | |
| 61 | |
| 62 struct SECKEYRSAPublicKeyStr { | |
| 63 PLArenaPool *arena; | |
| 64 SECItem modulus; | |
| 65 SECItem publicExponent; | |
| 66 }; | |
| 67 typedef struct SECKEYRSAPublicKeyStr SECKEYRSAPublicKey; | |
| 68 | |
| 69 /* | |
| 70 ** RSA-PSS parameters | |
| 71 */ | |
| 72 struct SECKEYRSAPSSParamsStr { | |
| 73 SECAlgorithmID *hashAlg; | |
| 74 SECAlgorithmID *maskAlg; | |
| 75 SECItem saltLength; | |
| 76 SECItem trailerField; | |
| 77 }; | |
| 78 typedef struct SECKEYRSAPSSParamsStr SECKEYRSAPSSParams; | |
| 79 | |
| 80 /* | |
| 81 ** DSA Public Key and related structures | |
| 82 */ | |
| 83 | |
| 84 struct SECKEYPQGParamsStr { | |
| 85 PLArenaPool *arena; | |
| 86 SECItem prime; /* p */ | |
| 87 SECItem subPrime; /* q */ | |
| 88 SECItem base; /* g */ | |
| 89 /* XXX chrisk: this needs to be expanded to hold j and validationParms (RFC2
459 7.3.2) */ | |
| 90 }; | |
| 91 typedef struct SECKEYPQGParamsStr SECKEYPQGParams; | |
| 92 | |
| 93 struct SECKEYDSAPublicKeyStr { | |
| 94 SECKEYPQGParams params; | |
| 95 SECItem publicValue; | |
| 96 }; | |
| 97 typedef struct SECKEYDSAPublicKeyStr SECKEYDSAPublicKey; | |
| 98 | |
| 99 /* | |
| 100 ** Diffie-Hellman Public Key structure | |
| 101 ** Structure member names suggested by PKCS#3. | |
| 102 */ | |
| 103 struct SECKEYDHParamsStr { | |
| 104 PLArenaPool *arena; | |
| 105 SECItem prime; /* p */ | |
| 106 SECItem base; /* g */ | |
| 107 }; | |
| 108 typedef struct SECKEYDHParamsStr SECKEYDHParams; | |
| 109 | |
| 110 struct SECKEYDHPublicKeyStr { | |
| 111 PLArenaPool *arena; | |
| 112 SECItem prime; | |
| 113 SECItem base; | |
| 114 SECItem publicValue; | |
| 115 }; | |
| 116 typedef struct SECKEYDHPublicKeyStr SECKEYDHPublicKey; | |
| 117 | |
| 118 /* | |
| 119 ** Elliptic curve Public Key structure | |
| 120 ** The PKCS#11 layer needs DER encoding of ANSI X9.62 | |
| 121 ** parameters value | |
| 122 */ | |
| 123 typedef SECItem SECKEYECParams; | |
| 124 | |
| 125 struct SECKEYECPublicKeyStr { | |
| 126 SECKEYECParams DEREncodedParams; | |
| 127 int size; /* size in bits */ | |
| 128 SECItem publicValue; /* encoded point */ | |
| 129 /* XXX Even though the PKCS#11 interface takes encoded parameters, | |
| 130 * we may still wish to decode them above PKCS#11 for things like | |
| 131 * printing key information. For named curves, which is what | |
| 132 * we initially support, we ought to have the curve name at the | |
| 133 * very least. | |
| 134 */ | |
| 135 }; | |
| 136 typedef struct SECKEYECPublicKeyStr SECKEYECPublicKey; | |
| 137 | |
| 138 /* | |
| 139 ** FORTEZZA Public Key structures | |
| 140 */ | |
| 141 struct SECKEYFortezzaPublicKeyStr { | |
| 142 int KEAversion; | |
| 143 int DSSversion; | |
| 144 unsigned char KMID[8]; | |
| 145 SECItem clearance; | |
| 146 SECItem KEApriviledge; | |
| 147 SECItem DSSpriviledge; | |
| 148 SECItem KEAKey; | |
| 149 SECItem DSSKey; | |
| 150 SECKEYPQGParams params; | |
| 151 SECKEYPQGParams keaParams; | |
| 152 }; | |
| 153 typedef struct SECKEYFortezzaPublicKeyStr SECKEYFortezzaPublicKey; | |
| 154 #define KEAprivilege KEApriviledge /* corrected spelling */ | |
| 155 #define DSSprivilege DSSpriviledge /* corrected spelling */ | |
| 156 | |
| 157 struct SECKEYDiffPQGParamsStr { | |
| 158 SECKEYPQGParams DiffKEAParams; | |
| 159 SECKEYPQGParams DiffDSAParams; | |
| 160 }; | |
| 161 typedef struct SECKEYDiffPQGParamsStr SECKEYDiffPQGParams; | |
| 162 | |
| 163 struct SECKEYPQGDualParamsStr { | |
| 164 SECKEYPQGParams CommParams; | |
| 165 SECKEYDiffPQGParams DiffParams; | |
| 166 }; | |
| 167 typedef struct SECKEYPQGDualParamsStr SECKEYPQGDualParams; | |
| 168 | |
| 169 struct SECKEYKEAParamsStr { | |
| 170 PLArenaPool *arena; | |
| 171 SECItem hash; | |
| 172 }; | |
| 173 typedef struct SECKEYKEAParamsStr SECKEYKEAParams; | |
| 174 | |
| 175 struct SECKEYKEAPublicKeyStr { | |
| 176 SECKEYKEAParams params; | |
| 177 SECItem publicValue; | |
| 178 }; | |
| 179 typedef struct SECKEYKEAPublicKeyStr SECKEYKEAPublicKey; | |
| 180 | |
| 181 /* | |
| 182 ** A Generic public key object. | |
| 183 */ | |
| 184 struct SECKEYPublicKeyStr { | |
| 185 PLArenaPool *arena; | |
| 186 KeyType keyType; | |
| 187 PK11SlotInfo *pkcs11Slot; | |
| 188 CK_OBJECT_HANDLE pkcs11ID; | |
| 189 union { | |
| 190 SECKEYRSAPublicKey rsa; | |
| 191 SECKEYDSAPublicKey dsa; | |
| 192 SECKEYDHPublicKey dh; | |
| 193 SECKEYKEAPublicKey kea; | |
| 194 SECKEYFortezzaPublicKey fortezza; | |
| 195 SECKEYECPublicKey ec; | |
| 196 } u; | |
| 197 }; | |
| 198 typedef struct SECKEYPublicKeyStr SECKEYPublicKey; | |
| 199 | |
| 200 /* bit flag definitions for staticflags */ | |
| 201 #define SECKEY_Attributes_Cached 0x1 /* bit 0 states \ | |
| 202 whether attributes are cached */ | |
| 203 #define SECKEY_CKA_PRIVATE (1U << 1) /* bit 1 is the value of CKA_PRIVATE */ | |
| 204 #define SECKEY_CKA_ALWAYS_AUTHENTICATE (1U << 2) | |
| 205 | |
| 206 #define SECKEY_ATTRIBUTES_CACHED(key) \ | |
| 207 (0 != (key->staticflags & SECKEY_Attributes_Cached)) | |
| 208 | |
| 209 #define SECKEY_ATTRIBUTE_VALUE(key,attribute) \ | |
| 210 (0 != (key->staticflags & SECKEY_##attribute)) | |
| 211 | |
| 212 #define SECKEY_HAS_ATTRIBUTE_SET(key,attribute) \ | |
| 213 (0 != (key->staticflags & SECKEY_Attributes_Cached)) ? \ | |
| 214 (0 != (key->staticflags & SECKEY_##attribute)) : \ | |
| 215 PK11_HasAttributeSet(key->pkcs11Slot,key->pkcs11ID,attribute, PR_FALSE) | |
| 216 | |
| 217 #define SECKEY_HAS_ATTRIBUTE_SET_LOCK(key,attribute, haslock) \ | |
| 218 (0 != (key->staticflags & SECKEY_Attributes_Cached)) ? \ | |
| 219 (0 != (key->staticflags & SECKEY_##attribute)) : \ | |
| 220 PK11_HasAttributeSet(key->pkcs11Slot,key->pkcs11ID,attribute, haslock) | |
| 221 | |
| 222 /* | |
| 223 ** A generic key structure | |
| 224 */ | |
| 225 struct SECKEYPrivateKeyStr { | |
| 226 PLArenaPool *arena; | |
| 227 KeyType keyType; | |
| 228 PK11SlotInfo *pkcs11Slot; /* pkcs11 slot this key lives in */ | |
| 229 CK_OBJECT_HANDLE pkcs11ID; /* ID of pkcs11 object */ | |
| 230 PRBool pkcs11IsTemp; /* temp pkcs11 object, delete it when done */ | |
| 231 void *wincx; /* context for errors and pw prompts */ | |
| 232 PRUint32 staticflags; /* bit flag of cached PKCS#11 attributes */ | |
| 233 }; | |
| 234 typedef struct SECKEYPrivateKeyStr SECKEYPrivateKey; | |
| 235 | |
| 236 typedef struct { | |
| 237 PRCList links; | |
| 238 SECKEYPrivateKey *key; | |
| 239 } SECKEYPrivateKeyListNode; | |
| 240 | |
| 241 typedef struct { | |
| 242 PRCList list; | |
| 243 PLArenaPool *arena; | |
| 244 } SECKEYPrivateKeyList; | |
| 245 | |
| 246 typedef struct { | |
| 247 PRCList links; | |
| 248 SECKEYPublicKey *key; | |
| 249 } SECKEYPublicKeyListNode; | |
| 250 | |
| 251 typedef struct { | |
| 252 PRCList list; | |
| 253 PLArenaPool *arena; | |
| 254 } SECKEYPublicKeyList; | |
| 255 #endif /* _KEYTHI_H_ */ | |
| OLD | NEW |