summaryrefslogtreecommitdiff
path: root/security/nss/lib/dev/nssdevt.h
blob: 1c2352d4185f0d44abf3a9fb1945ae422109aa78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
/* 
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Original Code is the Netscape security libraries.
 * 
 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are 
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 * Rights Reserved.
 * 
 * Contributor(s):
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL"), in which case the provisions of the GPL are applicable 
 * instead of those above.  If you wish to allow use of your 
 * version of this file only under the terms of the GPL and not to
 * allow others to use your version of this file under the MPL,
 * indicate your decision by deleting the provisions above and
 * replace them with the notice and other provisions required by
 * the GPL.  If you do not delete the provisions above, a recipient
 * may use your version of this file under either the MPL or the
 * GPL.
 */

#ifndef NSSDEVT_H
#define NSSDEVT_H

#ifdef DEBUG
static const char NSSDEVT_CVS_ID[] = "@(#) $RCSfile$ $Revision$ $Date$ $Name$";
#endif /* DEBUG */

/*
 * nssdevt.h
 *
 * This file contains definitions for the low-level cryptoki devices.
 */

#ifndef NSSBASET_H
#include "nssbaset.h"
#endif /* NSSBASET_H */

PR_BEGIN_EXTERN_C

typedef struct NSSModuleStr NSSModule;

typedef struct NSSSlotStr NSSSlot;

typedef struct NSSTokenStr NSSToken;

/*
 * NSSAlgNParam
 *
 * Algorithm is an OID
 * Parameters depend on the algorithm
 */

typedef struct NSSAlgNParamStr NSSAlgNParam;

/*
 * NSSCallback
 *
 * At minimum, a "challenge" method and a closure argument.
 * Usually the challenge will just be prompting for a password.
 * How OO do we want to make it?
 */

typedef struct NSSCallbackStr NSSCallback;

struct NSSCallbackStr {
    /* Prompt for a password to initialize a slot.  */
    PRStatus (* getInitPW)(NSSUTF8 *slotName, void *arg, NSSUTF8 **password); 
    /* Prompt for slot password.  */
    PRStatus (* getPW)(NSSUTF8 *slotName, PRBool *retry, void *arg,
                       NSSUTF8 **password); 
    void *arg;
};

typedef enum {
  NSSCertType_Unknown = 0,
  NSSCertType_PKIX = 1
} NSSCertType;

typedef enum
{
  NSSKeyPairType_Unknown = 0,
  NSSKeyPairType_RSA = 1,
  NSSKeyPairType_DSA = 2,
  NSSKeyPairType_DH = 3
} NSSKeyPairType;

typedef struct NSSRSAPublicKeyInfoStr
{
  NSSItem modulus;
  NSSItem publicExponent;
}
NSSRSAPublicKeyInfo;

typedef struct NSSDSAPublicKeyInfoStr
{
#if 0
  NSSPQGParameters params;
#endif
  NSSItem publicValue;
}
NSSDSAPublicKeyInfo;

typedef struct NSSDHPublicKeyInfoStr
{
  NSSItem prime;
  NSSItem base;
  NSSItem publicValue;
}
NSSDHPublicKeyInfo;

typedef struct NSSPublicKeyInfoStr
{
  NSSKeyPairType kind;
  union {
    NSSRSAPublicKeyInfo rsa;
    NSSDSAPublicKeyInfo dsa;
    NSSDHPublicKeyInfo  dh;
  } u;
}
NSSPublicKeyInfo;

typedef enum
{
  NSSSymKeyType_Unknown = 0,
  NSSSymKeyType_DES = 1,
  NSSSymKeyType_TripleDES = 2,
  NSSSymKeyType_RC2 = 3,
  NSSSymKeyType_RC4 = 4,
  NSSSymKeyType_RC5 = 5,
  NSSSymKeyType_AES = 6,
  NSSSymKeyType_SSLPMS = 7,
  NSSSymKeyType_SSLMS = 8
} NSSSymKeyType;

/*
 * RSA
 */

/* key generation */
typedef struct NSSRSAKeyGenParametersStr
{
  PRUint32 modulusBits;
  NSSItem publicExponent; /* Big-Endian */
}
NSSRSAKeyGenParameters;

/*
 * DSA
 */

/* key generation */
typedef struct NSSDSAKeyGenParametersStr
{
  PRUint32 primeBits;
  NSSItem p, q, g;          /* set of PQG parameters (can be zero)    */
}
NSSDSAKeyGenParameters;

/*
 * Diffie-Hellman
 */

/*
 * key generation
 *
 * Note: the size of p and g in Diffie-Hellman is not bounded above.
 * The parameters must use an unconstrained datum to represent p and g.
 * The memory used for p and g below is within the scope of the caller,
 * any NSS function will copy as necessary.
 */
typedef struct NSSDHParametersStr 
{
  PRUint32 valueBits;
  PRUint32 primeBits;
  NSSItem p, g; /* P and G values (can be zero) */
}
NSSDHKeyGenParameters;

/*
 * DES and Triple-DES
 *
 * only IV when in CBC mode
 */

/*
 * AES
 *
 * PKCS #11 is assuming 128-bit blocks, so no params for now
 * except IV when in CBC mode
 */

/*
 * RC2
 */

/* encryption/decryption parameters */
typedef struct NSSRC2ParametersStr
{
  PRUint32 effectiveKeySizeInBits;
  NSSItem iv;
  NSSItem version; /* IGNORE */
}
NSSRC2Parameters;

/*
 * RC4
 *
 * no params
 */

/*
 * RC5
 */

/* encryption/decryption parameters */
typedef struct NSSRC5ParametersStr
{
  PRUint32 wordSize;
  PRUint32 numRounds;
  NSSItem iv;
}
NSSRC5Parameters;

/*
 * HMAC
 *
 * DEFAULT: maximum length, specific to hash algorithm
 */

typedef PRUint32 NSSHMACParameters; /* length in bytes of desired output */

/*
 * Key derivation
 */

#if 0
typedef struct NSSKeyDerivationParametersStr
{
}
NSSKeyDerivationParameters;
#endif

/*
 * PBE key generation
 */

#define PBE_IV_LENGTH 8

typedef struct NSSPBEParametersStr
{
  unsigned char iv[PBE_IV_LENGTH];
  NSSItem salt;
  PRUint32 iteration;
  NSSItem iterIt; /* XXX until ASN.1 decodes ints */
}
NSSPBEParameters;

/*
 * SSL
 */

/* XXX */
typedef enum {
  NSSSSLVersion_SSLv2 = 0,
  NSSSSLVersion_SSLv3 = 1,
  NSSSSLVersion_TLS = 2
} NSSSSLVersion;

typedef NSSSSLVersion NSSSSLPMSParameters;

typedef struct NSSSSLMSParametersStr 
{
  NSSItem clientRandom;
  NSSItem serverRandom;
  NSSSSLVersion version;
  PRBool isDH;
} 
NSSSSLMSParameters;

typedef struct NSSSSLSessionKeyParametersStr
{
  NSSSSLVersion version;
  PRUint32 macSizeInBits;
  PRUint32 keySizeInBits;
  PRUint32 ivSizeInBits;
  PRBool isExport;
  NSSItem clientRandom;
  NSSItem serverRandom;
  PRUint8 *clientIV;
  PRUint8 *serverIV;
} 
NSSSSLSessionKeyParameters;


typedef union
{
  NSSItem                iv; /* for all generic CBC ciphers */
  NSSRSAKeyGenParameters rsakg;
  NSSDSAKeyGenParameters dsakg;
  NSSDHKeyGenParameters  dhkg;
  NSSRC2Parameters       rc2;
  NSSRC5Parameters       rc5;
  NSSHMACParameters      hmac;
  NSSPBEParameters       pbe;
  NSSSSLPMSParameters    sslpms;
  NSSSSLMSParameters     sslms;
}
NSSParameters;

typedef PRUint32 NSSOperations;
/* 1) Do we want these to be preprocessor definitions or constants? */
/* 2) What is the correct and complete list? */

#define NSSOperations_ENCRYPT           0x0001
#define NSSOperations_DECRYPT           0x0002
#define NSSOperations_WRAP              0x0004
#define NSSOperations_UNWRAP            0x0008
#define NSSOperations_SIGN              0x0010
#define NSSOperations_SIGN_RECOVER      0x0020
#define NSSOperations_VERIFY            0x0040
#define NSSOperations_VERIFY_RECOVER    0x0080
#define NSSOperations_DERIVE            0x0100

typedef PRUint32 NSSProperties;

#define NSSProperties_PRIVATE          0x0001
#define NSSProperties_READ_ONLY        0x0002
#define NSSProperties_SENSITIVE        0x0004 /* keys only */
#define NSSProperties_EXTRACTABLE      0x0008 /* keys only */

struct version_str
{
  PRUint32 major;
  PRUint32 minor;
};


typedef struct
{
  NSSUTF8 *name;
  NSSUTF8 *libraryName;
  PRBool isThreadSafe;
  PRBool isInternal;
  PRBool isFIPS;
  PRBool isModuleDB;
  PRBool isModuleDBOnly;
  PRBool isCritical;
  struct version_str cryptokiVersion;
  NSSUTF8 *manufacturerID;
  NSSUTF8 *libraryDescription;
  struct version_str libraryVersion;
  NSSUTF8 **slotNames;
  PRUint32 numSlots;
} 
NSSModuleInfo;

typedef struct 
{
  NSSUTF8 *name;
  NSSUTF8 *description;
  NSSUTF8 *manufacturerID;
  struct version_str hardwareVersion;
  struct version_str firmwareVersion;
  NSSUTF8 *moduleName;
  NSSUTF8 *tokenName;
  PRBool isTokenPresent;
  PRBool isTokenRemovable;
  PRBool isHardware;
} 
NSSSlotInfo;

typedef struct 
{
  NSSUTF8 *name;
  NSSUTF8 *manufacturerID;
  NSSUTF8 *model;
  NSSUTF8 *serialNumber;
  struct {
    PRUint32 maximum;
    PRUint32 active;
  } sessions;
  struct {
    PRUint32 maximum;
    PRUint32 active;
  } readWriteSessions;
  struct {
    PRUint32 minimum;
    PRUint32 maximum;
  } pinRange;
  struct {
    PRUint32 total;
    PRUint32 free;
  } publicMemory;
  struct {
    PRUint32 total;
    PRUint32 free;
  } privateMemory;
  struct version_str hardwareVersion;
  struct version_str firmwareVersion;
  NSSUTF8 *utcTime;
  PRBool hasRNG;
  PRBool isWriteProtected;
  PRBool isLoginRequired;
  PRBool isPINInitialized;
  PRBool hasClock;
  PRBool hasProtectedAuthPath;
  PRBool supportsDualCrypto;
} 
NSSTokenInfo;

PR_END_EXTERN_C

#endif /* NSSDEVT_H */