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 
5 #ifndef _PKCS11N_H_
6 #define _PKCS11N_H_
7 
8 /*
9  * pkcs11n.h
10  *
11  * This file contains the NSS-specific type definitions for Cryptoki
12  * (PKCS#11).
13  */
14 
15 /*
16  * NSSCK_VENDOR_NSS
17  *
18  * Cryptoki reserves the high half of all the number spaces for
19  * vendor-defined use.  I'd like to keep all of our NSS-
20  * specific values together, but not in the oh-so-obvious
21  * 0x80000001, 0x80000002, etc. area.  So I've picked an offset,
22  * and constructed values for the beginnings of our spaces.
23  *
24  * Note that some "historical" Netscape values don't fall within
25  * this range.
26  */
27 #define NSSCK_VENDOR_NSS 0x4E534350 /* NSCP */
28 
29 /*
30  * NSS-defined object classes
31  *
32  */
33 #define CKO_NSS (CKO_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
34 
35 #define CKO_NSS_CRL (CKO_NSS + 1)
36 #define CKO_NSS_SMIME (CKO_NSS + 2)
37 #define CKO_NSS_TRUST (CKO_NSS + 3)
38 #define CKO_NSS_BUILTIN_ROOT_LIST (CKO_NSS + 4)
39 #define CKO_NSS_NEWSLOT (CKO_NSS + 5)
40 #define CKO_NSS_DELSLOT (CKO_NSS + 6)
41 
42 /*
43  * NSS-defined key types
44  *
45  */
46 #define CKK_NSS (CKK_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
47 
48 #define CKK_NSS_PKCS8 (CKK_NSS + 1)
49 
50 #define CKK_NSS_JPAKE_ROUND1 (CKK_NSS + 2)
51 #define CKK_NSS_JPAKE_ROUND2 (CKK_NSS + 3)
52 
53 #define CKK_NSS_CHACHA20 (CKK_NSS + 4)
54 
55 /*
56  * NSS-defined certificate types
57  *
58  */
59 #define CKC_NSS (CKC_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
60 
61 /* FAKE PKCS #11 defines */
62 #define CKA_DIGEST 0x81000000L
63 #define CKA_NSS_MESSAGE 0x82000000L
64 #define CKA_NSS_MESSAGE_MASK 0xff000000L
65 #define CKA_FLAGS_ONLY 0 /* CKA_CLASS */
66 
67 /*
68  * NSS-defined object attributes
69  *
70  */
71 #define CKA_NSS (CKA_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
72 
73 #define CKA_NSS_URL (CKA_NSS + 1)
74 #define CKA_NSS_EMAIL (CKA_NSS + 2)
75 #define CKA_NSS_SMIME_INFO (CKA_NSS + 3)
76 #define CKA_NSS_SMIME_TIMESTAMP (CKA_NSS + 4)
77 #define CKA_NSS_PKCS8_SALT (CKA_NSS + 5)
78 #define CKA_NSS_PASSWORD_CHECK (CKA_NSS + 6)
79 #define CKA_NSS_EXPIRES (CKA_NSS + 7)
80 #define CKA_NSS_KRL (CKA_NSS + 8)
81 
82 #define CKA_NSS_PQG_COUNTER (CKA_NSS + 20)
83 #define CKA_NSS_PQG_SEED (CKA_NSS + 21)
84 #define CKA_NSS_PQG_H (CKA_NSS + 22)
85 #define CKA_NSS_PQG_SEED_BITS (CKA_NSS + 23)
86 #define CKA_NSS_MODULE_SPEC (CKA_NSS + 24)
87 #define CKA_NSS_OVERRIDE_EXTENSIONS (CKA_NSS + 25)
88 
89 #define CKA_NSS_JPAKE_SIGNERID (CKA_NSS + 26)
90 #define CKA_NSS_JPAKE_PEERID (CKA_NSS + 27)
91 #define CKA_NSS_JPAKE_GX1 (CKA_NSS + 28)
92 #define CKA_NSS_JPAKE_GX2 (CKA_NSS + 29)
93 #define CKA_NSS_JPAKE_GX3 (CKA_NSS + 30)
94 #define CKA_NSS_JPAKE_GX4 (CKA_NSS + 31)
95 #define CKA_NSS_JPAKE_X2 (CKA_NSS + 32)
96 #define CKA_NSS_JPAKE_X2S (CKA_NSS + 33)
97 
98 #define CKA_NSS_MOZILLA_CA_POLICY (CKA_NSS + 34)
99 #define CKA_NSS_SERVER_DISTRUST_AFTER (CKA_NSS + 35)
100 #define CKA_NSS_EMAIL_DISTRUST_AFTER (CKA_NSS + 36)
101 
102 /*
103  * Trust attributes:
104  *
105  * If trust goes standard, these probably will too.  So I'll
106  * put them all in one place.
107  */
108 
109 #define CKA_TRUST (CKA_NSS + 0x2000)
110 
111 /* "Usage" key information */
112 #define CKA_TRUST_DIGITAL_SIGNATURE (CKA_TRUST + 1)
113 #define CKA_TRUST_NON_REPUDIATION (CKA_TRUST + 2)
114 #define CKA_TRUST_KEY_ENCIPHERMENT (CKA_TRUST + 3)
115 #define CKA_TRUST_DATA_ENCIPHERMENT (CKA_TRUST + 4)
116 #define CKA_TRUST_KEY_AGREEMENT (CKA_TRUST + 5)
117 #define CKA_TRUST_KEY_CERT_SIGN (CKA_TRUST + 6)
118 #define CKA_TRUST_CRL_SIGN (CKA_TRUST + 7)
119 
120 /* "Purpose" trust information */
121 #define CKA_TRUST_SERVER_AUTH (CKA_TRUST + 8)
122 #define CKA_TRUST_CLIENT_AUTH (CKA_TRUST + 9)
123 #define CKA_TRUST_CODE_SIGNING (CKA_TRUST + 10)
124 #define CKA_TRUST_EMAIL_PROTECTION (CKA_TRUST + 11)
125 #define CKA_TRUST_IPSEC_END_SYSTEM (CKA_TRUST + 12)
126 #define CKA_TRUST_IPSEC_TUNNEL (CKA_TRUST + 13)
127 #define CKA_TRUST_IPSEC_USER (CKA_TRUST + 14)
128 #define CKA_TRUST_TIME_STAMPING (CKA_TRUST + 15)
129 #define CKA_TRUST_STEP_UP_APPROVED (CKA_TRUST + 16)
130 
131 #define CKA_CERT_SHA1_HASH (CKA_TRUST + 100)
132 #define CKA_CERT_MD5_HASH (CKA_TRUST + 101)
133 
134 /* NSS trust stuff */
135 
136 /* HISTORICAL: define used to pass in the database key for DSA private keys */
137 #define CKA_NSS_DB 0xD5A0DB00L
138 #define CKA_NSS_TRUST 0x80000001L
139 
140 /* FAKE PKCS #11 defines */
141 #define CKM_FAKE_RANDOM 0x80000efeUL
142 #define CKM_INVALID_MECHANISM 0xffffffffUL
143 #define CKT_INVALID_TYPE 0xffffffffUL
144 
145 /*
146  * NSS-defined crypto mechanisms
147  *
148  */
149 #define CKM_NSS (CKM_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
150 
151 #define CKM_NSS_AES_KEY_WRAP (CKM_NSS + 1)
152 #define CKM_NSS_AES_KEY_WRAP_PAD (CKM_NSS + 2)
153 
154 /* HKDF key derivation mechanisms. See CK_NSS_HKDFParams for documentation. */
155 #define CKM_NSS_HKDF_SHA1 (CKM_NSS + 3)
156 #define CKM_NSS_HKDF_SHA256 (CKM_NSS + 4)
157 #define CKM_NSS_HKDF_SHA384 (CKM_NSS + 5)
158 #define CKM_NSS_HKDF_SHA512 (CKM_NSS + 6)
159 
160 /* J-PAKE round 1 key generation mechanisms.
161  *
162  * Required template attributes: CKA_PRIME, CKA_SUBPRIME, CKA_BASE,
163  *                               CKA_NSS_JPAKE_SIGNERID
164  * Output key type: CKK_NSS_JPAKE_ROUND1
165  * Output key class: CKO_PRIVATE_KEY
166  * Parameter type: CK_NSS_JPAKERound1Params
167  *
168  */
169 #define CKM_NSS_JPAKE_ROUND1_SHA1 (CKM_NSS + 7)
170 #define CKM_NSS_JPAKE_ROUND1_SHA256 (CKM_NSS + 8)
171 #define CKM_NSS_JPAKE_ROUND1_SHA384 (CKM_NSS + 9)
172 #define CKM_NSS_JPAKE_ROUND1_SHA512 (CKM_NSS + 10)
173 
174 /* J-PAKE round 2 key derivation mechanisms.
175  *
176  * Required template attributes: CKA_NSS_JPAKE_PEERID
177  * Input key type:  CKK_NSS_JPAKE_ROUND1
178  * Output key type: CKK_NSS_JPAKE_ROUND2
179  * Output key class: CKO_PRIVATE_KEY
180  * Parameter type: CK_NSS_JPAKERound2Params
181  */
182 #define CKM_NSS_JPAKE_ROUND2_SHA1 (CKM_NSS + 11)
183 #define CKM_NSS_JPAKE_ROUND2_SHA256 (CKM_NSS + 12)
184 #define CKM_NSS_JPAKE_ROUND2_SHA384 (CKM_NSS + 13)
185 #define CKM_NSS_JPAKE_ROUND2_SHA512 (CKM_NSS + 14)
186 
187 /* J-PAKE final key material derivation mechanisms
188  *
189  * Input key type:  CKK_NSS_JPAKE_ROUND2
190  * Output key type: CKK_GENERIC_SECRET
191  * Output key class: CKO_SECRET_KEY
192  * Parameter type: CK_NSS_JPAKEFinalParams
193  *
194  * You must apply a KDF (e.g. CKM_NSS_HKDF_*) to resultant keying material
195  * to get a key with uniformly distributed bits.
196  */
197 #define CKM_NSS_JPAKE_FINAL_SHA1 (CKM_NSS + 15)
198 #define CKM_NSS_JPAKE_FINAL_SHA256 (CKM_NSS + 16)
199 #define CKM_NSS_JPAKE_FINAL_SHA384 (CKM_NSS + 17)
200 #define CKM_NSS_JPAKE_FINAL_SHA512 (CKM_NSS + 18)
201 
202 /* Constant-time MAC mechanisms:
203  *
204  * These operations verify a padded, MAC-then-encrypt block of data in
205  * constant-time. Because of the order of operations, the padding bytes are not
206  * protected by the MAC. However, disclosing the value of the padding bytes
207  * gives an attacker the ability to decrypt ciphertexts. Such disclosure can be
208  * as subtle as taking slightly less time to perform the MAC when the padding
209  * is one byte longer. See https://www.isg.rhul.ac.uk/tls/
210  *
211  * CKM_NSS_HMAC_CONSTANT_TIME: performs an HMAC authentication.
212  * CKM_NSS_SSL3_MAC_CONSTANT_TIME: performs an authentication with SSLv3 MAC.
213  *
214  * Parameter type: CK_NSS_MAC_CONSTANT_TIME_PARAMS
215  */
216 #define CKM_NSS_HMAC_CONSTANT_TIME (CKM_NSS + 19)
217 #define CKM_NSS_SSL3_MAC_CONSTANT_TIME (CKM_NSS + 20)
218 
219 /* TLS 1.2 mechanisms */
220 #define CKM_NSS_TLS_PRF_GENERAL_SHA256 (CKM_NSS + 21)
221 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_SHA256 (CKM_NSS + 22)
222 #define CKM_NSS_TLS_KEY_AND_MAC_DERIVE_SHA256 (CKM_NSS + 23)
223 #define CKM_NSS_TLS_MASTER_KEY_DERIVE_DH_SHA256 (CKM_NSS + 24)
224 
225 /* TLS extended master secret derivation */
226 #define CKM_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE (CKM_NSS + 25)
227 #define CKM_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE_DH (CKM_NSS + 26)
228 
229 #define CKM_NSS_CHACHA20_KEY_GEN (CKM_NSS + 27)
230 #define CKM_NSS_CHACHA20_POLY1305 (CKM_NSS + 28)
231 
232 /* Additional PKCS #12 PBE algorithms defined in v1.1 */
233 #define CKM_NSS_PKCS12_PBE_SHA224_HMAC_KEY_GEN (CKM_NSS + 29)
234 #define CKM_NSS_PKCS12_PBE_SHA256_HMAC_KEY_GEN (CKM_NSS + 30)
235 #define CKM_NSS_PKCS12_PBE_SHA384_HMAC_KEY_GEN (CKM_NSS + 31)
236 #define CKM_NSS_PKCS12_PBE_SHA512_HMAC_KEY_GEN (CKM_NSS + 32)
237 
238 #define CKM_NSS_CHACHA20_CTR (CKM_NSS + 33)
239 
240 /* IKE mechanism (to be proposed to PKCS #11 */
241 #define CKM_NSS_IKE_PRF_PLUS_DERIVE (CKM_NSS + 34)
242 #define CKM_NSS_IKE_PRF_DERIVE (CKM_NSS + 35)
243 #define CKM_NSS_IKE1_PRF_DERIVE (CKM_NSS + 36)
244 #define CKM_NSS_IKE1_APP_B_PRF_DERIVE (CKM_NSS + 37)
245 
246 #define CKM_NSS_PUB_FROM_PRIV (CKM_NSS + 40)
247 
248 /* SP800-108 NSS mechanism with support for data object derivation */
249 #define CKM_NSS_SP800_108_COUNTER_KDF_DERIVE_DATA (CKM_NSS + 42)
250 #define CKM_NSS_SP800_108_FEEDBACK_KDF_DERIVE_DATA (CKM_NSS + 43)
251 #define CKM_NSS_SP800_108_DOUBLE_PIPELINE_KDF_DERIVE_DATA (CKM_NSS + 44)
252 
253 /*
254  * HISTORICAL:
255  * Do not attempt to use these. They are only used by NSS's internal
256  * PKCS #11 interface. Most of these are place holders for other mechanism
257  * and will change in the future.
258  */
259 #define CKM_NSS_PBE_SHA1_DES_CBC 0x80000002UL
260 #define CKM_NSS_PBE_SHA1_TRIPLE_DES_CBC 0x80000003UL
261 #define CKM_NSS_PBE_SHA1_40_BIT_RC2_CBC 0x80000004UL
262 #define CKM_NSS_PBE_SHA1_128_BIT_RC2_CBC 0x80000005UL
263 #define CKM_NSS_PBE_SHA1_40_BIT_RC4 0x80000006UL
264 #define CKM_NSS_PBE_SHA1_128_BIT_RC4 0x80000007UL
265 #define CKM_NSS_PBE_SHA1_FAULTY_3DES_CBC 0x80000008UL
266 #define CKM_NSS_PBE_SHA1_HMAC_KEY_GEN 0x80000009UL
267 #define CKM_NSS_PBE_MD5_HMAC_KEY_GEN 0x8000000aUL
268 #define CKM_NSS_PBE_MD2_HMAC_KEY_GEN 0x8000000bUL
269 
270 #define CKM_TLS_PRF_GENERAL 0x80000373UL
271 
272 /* FIPS Indicator defines */
273 #define CKS_NSS_UNINITIALIZED 0xffffffffUL
274 #define CKS_NSS_FIPS_NOT_OK 0UL
275 #define CKS_NSS_FIPS_OK 1UL
276 
277 #define CKT_NSS_SESSION_CHECK 1UL
278 #define CKT_NSS_OBJECT_CHECK 2UL
279 #define CKT_NSS_BOTH_CHECK 3UL
280 #define CKT_NSS_SESSION_LAST_CHECK 4UL
281 
282 typedef struct CK_NSS_JPAKEPublicValue {
283     CK_BYTE *pGX;
284     CK_ULONG ulGXLen;
285     CK_BYTE *pGV;
286     CK_ULONG ulGVLen;
287     CK_BYTE *pR;
288     CK_ULONG ulRLen;
289 } CK_NSS_JPAKEPublicValue;
290 
291 typedef struct CK_NSS_JPAKERound1Params {
292     CK_NSS_JPAKEPublicValue gx1; /* out */
293     CK_NSS_JPAKEPublicValue gx2; /* out */
294 } CK_NSS_JPAKERound1Params;
295 
296 typedef struct CK_NSS_JPAKERound2Params {
297     CK_BYTE *pSharedKey;         /* in */
298     CK_ULONG ulSharedKeyLen;     /* in */
299     CK_NSS_JPAKEPublicValue gx3; /* in */
300     CK_NSS_JPAKEPublicValue gx4; /* in */
301     CK_NSS_JPAKEPublicValue A;   /* out */
302 } CK_NSS_JPAKERound2Params;
303 
304 typedef struct CK_NSS_JPAKEFinalParams {
305     CK_NSS_JPAKEPublicValue B; /* in */
306 } CK_NSS_JPAKEFinalParams;
307 
308 /* macAlg: the MAC algorithm to use. This determines the hash function used in
309  *     the HMAC/SSLv3 MAC calculations.
310  * ulBodyTotalLen: the total length of the data, including padding bytes and
311  *     padding length.
312  * pHeader: points to a block of data that contains additional data to
313  *     authenticate. For TLS this includes the sequence number etc. For SSLv3,
314  *     this also includes the initial padding bytes.
315  *
316  * NOTE: the softoken's implementation of CKM_NSS_HMAC_CONSTANT_TIME and
317  * CKM_NSS_SSL3_MAC_CONSTANT_TIME requires that the sum of ulBodyTotalLen
318  * and ulHeaderLen be much smaller than 2^32 / 8 bytes because it uses an
319  * unsigned int variable to represent the length in bits. This should not
320  * be a problem because the SSL/TLS protocol limits the size of an SSL
321  * record to something considerably less than 2^32 bytes.
322  */
323 typedef struct CK_NSS_MAC_CONSTANT_TIME_PARAMS {
324     CK_MECHANISM_TYPE macAlg; /* in */
325     CK_ULONG ulBodyTotalLen;  /* in */
326     CK_BYTE *pHeader;         /* in */
327     CK_ULONG ulHeaderLen;     /* in */
328 } CK_NSS_MAC_CONSTANT_TIME_PARAMS;
329 
330 typedef struct CK_NSS_AEAD_PARAMS {
331     CK_BYTE_PTR pNonce;
332     CK_ULONG ulNonceLen;
333     CK_BYTE_PTR pAAD;
334     CK_ULONG ulAADLen;
335     CK_ULONG ulTagLen;
336 } CK_NSS_AEAD_PARAMS;
337 
338 /*
339  * NSS-defined return values
340  *
341  */
342 #define CKR_NSS (CKM_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
343 
344 #define CKR_NSS_CERTDB_FAILED (CKR_NSS + 1)
345 #define CKR_NSS_KEYDB_FAILED (CKR_NSS + 2)
346 
347 /* Mandatory parameter for the CKM_NSS_HKDF_* key deriviation mechanisms.
348    See RFC 5869.
349 
350     bExtract: If set, HKDF-Extract will be applied to the input key. If
351               the optional salt is given, it is used; otherwise, the salt is
352               set to a sequence of zeros equal in length to the HMAC output.
353               If bExpand is not set, then the key template given to
354               C_DeriveKey must indicate an output key size less than or equal
355               to the output size of the HMAC.
356 
357     bExpand:  If set, HKDF-Expand will be applied to the input key (if
358               bExtract is not set) or to the result of HKDF-Extract (if
359               bExtract is set). Any info given in the optional pInfo field will
360               be included in the calculation.
361 
362     The size of the output key must be specified in the template passed to
363     C_DeriveKey.
364 */
365 typedef struct CK_NSS_HKDFParams {
366     CK_BBOOL bExtract;
367     CK_BYTE_PTR pSalt;
368     CK_ULONG ulSaltLen;
369     CK_BBOOL bExpand;
370     CK_BYTE_PTR pInfo;
371     CK_ULONG ulInfoLen;
372 } CK_NSS_HKDFParams;
373 
374 /*
375  * CK_NSS_IKE_PRF_PLUS_PARAMS is a structure that provides the parameters to
376  * the CKM_NSS_IKE_PRF_PLUS_DERIVE mechanism.
377  * The fields of the structure have the following meanings:
378  *      prfMechanism    underlying MAC mechanism used to generate the prf.
379  *      bHasSeedKey     hSeed key is present.
380  *      hSeedKey        optional seed from key
381  *      pSeedData       optional seed from data.
382  *      ulSeedDataLen   length of optional seed data.
383  *        If no seed data is present this value is NULL.
384  */
385 typedef struct CK_NSS_IKE_PRF_PLUS_DERIVE_PARAMS {
386     CK_MECHANISM_TYPE prfMechanism;
387     CK_BBOOL bHasSeedKey;
388     CK_OBJECT_HANDLE hSeedKey;
389     CK_BYTE_PTR pSeedData;
390     CK_ULONG ulSeedDataLen;
391 } CK_NSS_IKE_PRF_PLUS_DERIVE_PARAMS;
392 
393 /* CK_NSS_IKE_PRF_DERIVE_PARAMS is a structure that provides the parameters to
394  *  the CKM_NSS_IKE_PRF_DERIVE mechanism.
395  *
396  * The fields of the structure have the following meanings:
397  *     prfMechanism underlying MAC mechanism used to generate the prf.
398  *     bRekey       hNewKey is present.
399  *     pNi          Ni value
400  *     ulNiLen      length of Ni
401  *     pNr          Nr value
402  *     ulNrLen      length of Nr
403  *     hNewKey      New key value to drive the rekey.
404  */
405 typedef struct CK_NSS_IKE_PRF_DERIVE_PARAMS {
406     CK_MECHANISM_TYPE prfMechanism;
407     CK_BBOOL bDataAsKey;
408     CK_BBOOL bRekey;
409     CK_BYTE_PTR pNi;
410     CK_ULONG ulNiLen;
411     CK_BYTE_PTR pNr;
412     CK_ULONG ulNrLen;
413     CK_OBJECT_HANDLE hNewKey;
414 } CK_NSS_IKE_PRF_DERIVE_PARAMS;
415 
416 /* CK_NSS_IKE1_PRF_DERIVE_PARAMS is a structure that provides the parameters
417  * to the CKM_NSS_IKE_PRF_DERIVE mechanism.
418  *
419  * The fields of the structure have the following meanings:
420  *     prfMechanism  underlying MAC mechanism used to generate the prf.
421  *     bRekey        hNewKey is present.
422  *     pCKYi         CKYi value
423  *     ulCKYiLen     length of CKYi
424  *     pCKYr         CKYr value
425  *     ulCKYrLen     length of CKYr
426  *     hNewKey       New key value to drive the rekey.
427  */
428 typedef struct CK_NSS_IKE1_PRF_DERIVE_PARAMS {
429     CK_MECHANISM_TYPE prfMechanism;
430     CK_BBOOL bHasPrevKey;
431     CK_OBJECT_HANDLE hKeygxy;
432     CK_OBJECT_HANDLE hPrevKey;
433     CK_BYTE_PTR pCKYi;
434     CK_ULONG ulCKYiLen;
435     CK_BYTE_PTR pCKYr;
436     CK_ULONG ulCKYrLen;
437     CK_BYTE keyNumber;
438 } CK_NSS_IKE1_PRF_DERIVE_PARAMS;
439 
440 /* CK_NSS_IKE1_APP_B_PRF_DERIVE_PARAMS is a structure that provides the
441  * parameters to the CKM_NSS_IKE_APP_B_PRF_DERIVE mechanism.
442  *
443  * The fields of the structure have the following meanings:
444  *     prfMechanism  underlying MAC mechanism used to generate the prf.
445  *     bHasKeygxy    hKeygxy exists
446  *     hKeygxy       optional key to hash in the prf
447  *     pExtraData    optional extra data to hash in the prf
448  *     ulExtraData   length of the optional extra data.
449  *
450  * CK_NSS_IKE_APP_B_PRF_DERIVE can take wither CK_NSS_IKE1_APP_B_PRF_DRIVE_PARAMS
451  * or a single CK_MECHANISM_TYPE. In the latter cases bHashKeygx is assumed to
452  * be false and ulExtraDataLen is assumed to be '0'.
453  */
454 typedef struct CK_NSS_IKE1_APP_B_PRF_DERIVE_PARAMS {
455     CK_MECHANISM_TYPE prfMechanism;
456     CK_BBOOL bHasKeygxy;
457     CK_OBJECT_HANDLE hKeygxy;
458     CK_BYTE_PTR pExtraData;
459     CK_ULONG ulExtraDataLen;
460 } CK_NSS_IKE1_APP_B_PRF_DERIVE_PARAMS;
461 
462 /*
463  * Parameter for the TLS extended master secret key derivation mechanisms:
464  *
465  *  * CKM_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE
466  *  * CKM_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE_DH
467  *
468  * For the TLS 1.2 PRF, the prfHashMechanism parameter determines the hash
469  * function used. For earlier versions of the PRF, set the prfHashMechanism
470  * value to CKM_TLS_PRF.
471  *
472  * The session hash input is expected to be the output of the same hash
473  * function as the PRF uses (as required by draft-ietf-tls-session-hash).  So
474  * the ulSessionHashLen member must be equal the output length of the hash
475  * function specified by the prfHashMechanism member (or, for pre-TLS 1.2 PRF,
476  * the length of concatenated MD5 and SHA-1 digests).
477  *
478  */
479 typedef struct CK_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE_PARAMS {
480     CK_MECHANISM_TYPE prfHashMechanism;
481     CK_BYTE_PTR pSessionHash;
482     CK_ULONG ulSessionHashLen;
483     CK_VERSION_PTR pVersion;
484 } CK_NSS_TLS_EXTENDED_MASTER_KEY_DERIVE_PARAMS;
485 
486 /*
487  * Trust info
488  *
489  * This isn't part of the Cryptoki standard (yet), so I'm putting
490  * all the definitions here.  Some of this would move to nssckt.h
491  * if trust info were made part of the standard.  In view of this
492  * possibility, I'm putting my (NSS) values in the NSS
493  * vendor space, like everything else.
494  */
495 
496 typedef CK_ULONG CK_TRUST;
497 
498 /* The following trust types are defined: */
499 #define CKT_VENDOR_DEFINED 0x80000000
500 
501 #define CKT_NSS (CKT_VENDOR_DEFINED | NSSCK_VENDOR_NSS)
502 
503 /* If trust goes standard, these'll probably drop out of vendor space. */
504 #define CKT_NSS_TRUSTED (CKT_NSS + 1)
505 #define CKT_NSS_TRUSTED_DELEGATOR (CKT_NSS + 2)
506 #define CKT_NSS_MUST_VERIFY_TRUST (CKT_NSS + 3)
507 #define CKT_NSS_NOT_TRUSTED (CKT_NSS + 10)
508 #define CKT_NSS_TRUST_UNKNOWN (CKT_NSS + 5) /* default */
509 
510 /*
511  * These may well remain NSS-specific; I'm only using them
512  * to cache resolution data.
513  */
514 #define CKT_NSS_VALID_DELEGATOR (CKT_NSS + 11)
515 
516 /*
517  * old definitions. They still exist, but the plain meaning of the
518  * labels have never been accurate to what was really implemented.
519  * The new labels correctly reflect what the values effectively mean.
520  */
521 #if defined(__GNUC__) && (__GNUC__ > 3)
522 /* make GCC warn when we use these #defines */
523 /*
524  *  This is really painful because GCC doesn't allow us to mark random
525  *  #defines as deprecated. We can only mark the following:
526  *      functions, variables, and types.
527  *  const variables will create extra storage for everyone including this
528  *       header file, so it's undesirable.
529  *  functions could be inlined to prevent storage creation, but will fail
530  *       when constant values are expected (like switch statements).
531  *  enum types do not seem to pay attention to the deprecated attribute.
532  *
533  *  That leaves typedefs. We declare new types that we then deprecate, then
534  *  cast the resulting value to the deprecated type in the #define, thus
535  *  producting the warning when the #define is used.
536  */
537 #if (__GNUC__ == 4) && (__GNUC_MINOR__ < 5)
538 /* The mac doesn't like the friendlier deprecate messages. I'm assuming this
539  * is a gcc version issue rather than mac or ppc specific */
540 typedef CK_TRUST __CKT_NSS_UNTRUSTED __attribute__((deprecated));
541 typedef CK_TRUST __CKT_NSS_VALID __attribute__((deprecated));
542 typedef CK_TRUST __CKT_NSS_MUST_VERIFY __attribute__((deprecated));
543 #else
544 /* when possible, get a full deprecation warning. This works on gcc 4.5
545  * it may work on earlier versions of gcc */
546 typedef CK_TRUST __CKT_NSS_UNTRUSTED __attribute__((deprecated("CKT_NSS_UNTRUSTED really means CKT_NSS_MUST_VERIFY_TRUST")));
547 typedef CK_TRUST __CKT_NSS_VALID __attribute__((deprecated("CKT_NSS_VALID really means CKT_NSS_NOT_TRUSTED")));
548 typedef CK_TRUST __CKT_NSS_MUST_VERIFY __attribute__((deprecated("CKT_NSS_MUST_VERIFY really functions as CKT_NSS_TRUST_UNKNOWN")));
549 #endif
550 #define CKT_NSS_UNTRUSTED ((__CKT_NSS_UNTRUSTED)CKT_NSS_MUST_VERIFY_TRUST)
551 #define CKT_NSS_VALID ((__CKT_NSS_VALID)CKT_NSS_NOT_TRUSTED)
552 /* keep the old value for compatibility reasons*/
553 #define CKT_NSS_MUST_VERIFY ((__CKT_NSS_MUST_VERIFY)(CKT_NSS + 4))
554 #else
555 #ifdef _WIN32
556 /* This magic gets the windows compiler to give us a deprecation
557  * warning */
558 #pragma deprecated(CKT_NSS_UNTRUSTED, CKT_NSS_MUST_VERIFY, CKT_NSS_VALID)
559 #endif
560 /* CKT_NSS_UNTRUSTED really means CKT_NSS_MUST_VERIFY_TRUST */
561 #define CKT_NSS_UNTRUSTED CKT_NSS_MUST_VERIFY_TRUST
562 /* CKT_NSS_VALID really means CKT_NSS_NOT_TRUSTED */
563 #define CKT_NSS_VALID CKT_NSS_NOT_TRUSTED
564 /* CKT_NSS_MUST_VERIFY was always treated as CKT_NSS_TRUST_UNKNOWN */
565 #define CKT_NSS_MUST_VERIFY (CKT_NSS + 4) /*really means trust unknown*/
566 #endif
567 
568 /*
569  * These are not really PKCS #11 values specifically. They are the 'loadable'
570  * module spec NSS uses. They are available for others to use as well, but not
571  * part of the formal PKCS #11 spec.
572  *
573  * The function 'FIND' returns an array of PKCS #11 initialization strings
574  * The function 'ADD' takes a PKCS #11 initialization string and stores it.
575  * The function 'DEL' takes a 'name= library=' value and deletes the associated
576  *  string.
577  * The function 'RELEASE' frees the array returned by 'FIND'
578  */
579 #define SECMOD_MODULE_DB_FUNCTION_FIND 0
580 #define SECMOD_MODULE_DB_FUNCTION_ADD 1
581 #define SECMOD_MODULE_DB_FUNCTION_DEL 2
582 #define SECMOD_MODULE_DB_FUNCTION_RELEASE 3
583 typedef char **(PR_CALLBACK *SECMODModuleDBFunc)(unsigned long function,
584                                                  char *parameters, void *moduleSpec);
585 
586 /* softoken slot ID's */
587 #define SFTK_MIN_USER_SLOT_ID 4
588 #define SFTK_MAX_USER_SLOT_ID 100
589 #define SFTK_MIN_FIPS_USER_SLOT_ID 101
590 #define SFTK_MAX_FIPS_USER_SLOT_ID 127
591 
592 /* Module Interface. This is the old NSS private module interface, now exported
593  * as a PKCS #11 v3 interface. It's interface name is
594  * "Vendor NSS Module Interface" */
595 typedef char **(*CK_NSS_ModuleDBFunc)(unsigned long function,
596                                       char *parameters, void *args);
597 typedef struct CK_NSS_MODULE_FUNCTIONS {
598     CK_VERSION version;
599     CK_NSS_ModuleDBFunc NSC_ModuleDBFunc;
600 } CK_NSS_MODULE_FUNCTIONS;
601 
602 /* FIPS Indicator Interface. This may move to the normal PKCS #11 table
603  * in the future. For now it's called "Vendor NSS FIPS Interface" */
604 typedef CK_RV (*CK_NSS_GetFIPSStatus)(CK_SESSION_HANDLE hSession,
605                                       CK_OBJECT_HANDLE hObject,
606                                       CK_ULONG ulOperationType,
607                                       CK_ULONG *pulFIPSStatus);
608 
609 typedef struct CK_NSS_FIPS_FUNCTIONS {
610     CK_VERSION version;
611     CK_NSS_GetFIPSStatus NSC_NSSGetFIPSStatus;
612 } CK_NSS_FIPS_FUNCTIONS;
613 
614 /* There was an inconsistency between the spec and the header file in defining
615  * the CK_GCM_PARAMS structure. The authoritative reference is the header file,
616  * but NSS used the spec when adding it to its own header. In V3 we've
617  * corrected it, but we need to handle the old case for devices that followed
618  * us in using the incorrect specification. */
619 typedef struct CK_NSS_GCM_PARAMS {
620     CK_BYTE_PTR pIv;
621     CK_ULONG ulIvLen;
622     CK_BYTE_PTR pAAD;
623     CK_ULONG ulAADLen;
624     CK_ULONG ulTagBits;
625 } CK_NSS_GCM_PARAMS;
626 
627 typedef CK_NSS_GCM_PARAMS CK_PTR CK_NSS_GCM_PARAMS_PTR;
628 
629 /* deprecated #defines. Drop in future NSS releases */
630 #ifdef NSS_PKCS11_2_0_COMPAT
631 
632 /* defines that were changed between NSS's PKCS #11 and the Oasis headers */
633 #define CKF_EC_FP CKF_EC_F_P
634 #define CKO_KG_PARAMETERS CKO_DOMAIN_PARAMETERS
635 #define CK_INVALID_SESSION CK_INVALID_HANDLE
636 #define CKR_KEY_PARAMS_INVALID 0x0000006B
637 
638 /* use the old wrong CK_GCM_PARAMS if NSS_PCKS11_2_0_COMPAT is defined */
639 typedef struct CK_NSS_GCM_PARAMS CK_GCM_PARAMS;
640 typedef CK_NSS_GCM_PARAMS CK_PTR CK_GCM_PARAMS_PTR;
641 
642 /* don't leave old programs in a lurch just yet, give them the old NETSCAPE
643  * synonym if NSS_PKCS11_2_0_COMPAT is defined*/
644 #define CKO_NETSCAPE_CRL CKO_NSS_CRL
645 #define CKO_NETSCAPE_SMIME CKO_NSS_SMIME
646 #define CKO_NETSCAPE_TRUST CKO_NSS_TRUST
647 #define CKO_NETSCAPE_BUILTIN_ROOT_LIST CKO_NSS_BUILTIN_ROOT_LIST
648 #define CKO_NETSCAPE_NEWSLOT CKO_NSS_NEWSLOT
649 #define CKO_NETSCAPE_DELSLOT CKO_NSS_DELSLOT
650 #define CKK_NETSCAPE_PKCS8 CKK_NSS_PKCS8
651 #define CKA_NETSCAPE_URL CKA_NSS_URL
652 #define CKA_NETSCAPE_EMAIL CKA_NSS_EMAIL
653 #define CKA_NETSCAPE_SMIME_INFO CKA_NSS_SMIME_INFO
654 #define CKA_NETSCAPE_SMIME_TIMESTAMP CKA_NSS_SMIME_TIMESTAMP
655 #define CKA_NETSCAPE_PKCS8_SALT CKA_NSS_PKCS8_SALT
656 #define CKA_NETSCAPE_PASSWORD_CHECK CKA_NSS_PASSWORD_CHECK
657 #define CKA_NETSCAPE_EXPIRES CKA_NSS_EXPIRES
658 #define CKA_NETSCAPE_KRL CKA_NSS_KRL
659 #define CKA_NETSCAPE_PQG_COUNTER CKA_NSS_PQG_COUNTER
660 #define CKA_NETSCAPE_PQG_SEED CKA_NSS_PQG_SEED
661 #define CKA_NETSCAPE_PQG_H CKA_NSS_PQG_H
662 #define CKA_NETSCAPE_PQG_SEED_BITS CKA_NSS_PQG_SEED_BITS
663 #define CKA_NETSCAPE_MODULE_SPEC CKA_NSS_MODULE_SPEC
664 #define CKA_NETSCAPE_DB CKA_NSS_DB
665 #define CKA_NETSCAPE_TRUST CKA_NSS_TRUST
666 #define CKM_NETSCAPE_AES_KEY_WRAP CKM_NSS_AES_KEY_WRAP
667 #define CKM_NETSCAPE_AES_KEY_WRAP_PAD CKM_NSS_AES_KEY_WRAP_PAD
668 #define CKM_NETSCAPE_PBE_SHA1_DES_CBC CKM_NSS_PBE_SHA1_DES_CBC
669 #define CKM_NETSCAPE_PBE_SHA1_TRIPLE_DES_CBC CKM_NSS_PBE_SHA1_TRIPLE_DES_CBC
670 #define CKM_NETSCAPE_PBE_SHA1_40_BIT_RC2_CBC CKM_NSS_PBE_SHA1_40_BIT_RC2_CBC
671 #define CKM_NETSCAPE_PBE_SHA1_128_BIT_RC2_CBC CKM_NSS_PBE_SHA1_128_BIT_RC2_CBC
672 #define CKM_NETSCAPE_PBE_SHA1_40_BIT_RC4 CKM_NSS_PBE_SHA1_40_BIT_RC4
673 #define CKM_NETSCAPE_PBE_SHA1_128_BIT_RC4 CKM_NSS_PBE_SHA1_128_BIT_RC4
674 #define CKM_NETSCAPE_PBE_SHA1_FAULTY_3DES_CBC CKM_NSS_PBE_SHA1_FAULTY_3DES_CBC
675 #define CKM_NETSCAPE_PBE_SHA1_HMAC_KEY_GEN CKM_NSS_PBE_SHA1_HMAC_KEY_GEN
676 #define CKM_NETSCAPE_PBE_MD5_HMAC_KEY_GEN CKM_NSS_PBE_MD5_HMAC_KEY_GEN
677 #define CKM_NETSCAPE_PBE_MD2_HMAC_KEY_GEN CKM_NSS_PBE_MD2_HMAC_KEY_GEN
678 #define CKR_NETSCAPE_CERTDB_FAILED CKR_NSS_CERTDB_FAILED
679 #define CKR_NETSCAPE_KEYDB_FAILED CKR_NSS_KEYDB_FAILED
680 
681 #define CKT_NETSCAPE_TRUSTED CKT_NSS_TRUSTED
682 #define CKT_NETSCAPE_TRUSTED_DELEGATOR CKT_NSS_TRUSTED_DELEGATOR
683 #define CKT_NETSCAPE_UNTRUSTED CKT_NSS_UNTRUSTED
684 #define CKT_NETSCAPE_MUST_VERIFY CKT_NSS_MUST_VERIFY
685 #define CKT_NETSCAPE_TRUST_UNKNOWN CKT_NSS_TRUST_UNKNOWN
686 #define CKT_NETSCAPE_VALID CKT_NSS_VALID
687 #define CKT_NETSCAPE_VALID_DELEGATOR CKT_NSS_VALID_DELEGATOR
688 #else
689 /* use the new CK_GCM_PARAMS if NSS_PKCS11_2_0_COMPAT is not defined */
690 typedef struct CK_GCM_PARAMS_V3 CK_GCM_PARAMS;
691 typedef CK_GCM_PARAMS_V3 CK_PTR CK_GCM_PARAMS_PTR;
692 #endif
693 
694 #endif /* _PKCS11N_H_ */
695