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