Coverage Report

Created: 2018-09-25 14:53

/src/mozilla-central/security/nss/lib/pk11wrap/debug_module.c
Line
Count
Source (jump to first uncovered line)
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
#include "prlog.h"
5
#include <stdio.h>
6
#include "cert.h" /* for CERT_DerNameToAscii & CERT_Hexify */
7
8
static PRLogModuleInfo *modlog = NULL;
9
10
static CK_FUNCTION_LIST_PTR module_functions;
11
12
static CK_FUNCTION_LIST debug_functions;
13
14
static void print_final_statistics(void);
15
16
#define STRING static const char
17
18
STRING fmt_flags[] = "  flags = 0x%x";
19
STRING fmt_hKey[] = "  hKey = 0x%x";
20
STRING fmt_hObject[] = "  hObject = 0x%x";
21
STRING fmt_hSession[] = "  hSession = 0x%x";
22
STRING fmt_manufacturerID[] = "  manufacturerID = \"%.32s\"";
23
STRING fmt_pData[] = "  pData = 0x%p";
24
STRING fmt_pDigest[] = "  pDigest = 0x%p";
25
STRING fmt_pEncryptedData[] = "  pEncryptedData = 0x%p";
26
STRING fmt_pEncryptedPart[] = "  pEncryptedPart = 0x%p";
27
STRING fmt_pInfo[] = "  pInfo = 0x%p";
28
STRING fmt_pMechanism[] = "  pMechanism = 0x%p";
29
STRING fmt_pOperationState[] = "  pOperationState = 0x%p";
30
STRING fmt_pPart[] = "  pPart = 0x%p";
31
STRING fmt_pPin[] = "  pPin = 0x%p";
32
STRING fmt_pSignature[] = "  pSignature = 0x%p";
33
STRING fmt_pTemplate[] = "  pTemplate = 0x%p";
34
STRING fmt_pWrappedKey[] = "  pWrappedKey = 0x%p";
35
STRING fmt_phKey[] = "  phKey = 0x%p";
36
STRING fmt_phObject[] = "  phObject = 0x%p";
37
STRING fmt_pulCount[] = "  pulCount = 0x%p";
38
STRING fmt_pulDataLen[] = "  pulDataLen = 0x%p";
39
STRING fmt_pulDigestLen[] = "  pulDigestLen = 0x%p";
40
STRING fmt_pulEncryptedPartLen[] = "  pulEncryptedPartLen = 0x%p";
41
STRING fmt_pulPartLen[] = "  pulPartLen = 0x%p";
42
STRING fmt_pulSignatureLen[] = "  pulSignatureLen = 0x%p";
43
STRING fmt_slotID[] = "  slotID = 0x%x";
44
STRING fmt_sphKey[] = "  *phKey = 0x%x";
45
STRING fmt_spulCount[] = "  *pulCount = 0x%x";
46
STRING fmt_spulDataLen[] = "  *pulDataLen = 0x%x";
47
STRING fmt_spulDigestLen[] = "  *pulDigestLen = 0x%x";
48
STRING fmt_spulEncryptedPartLen[] = "  *pulEncryptedPartLen = 0x%x";
49
STRING fmt_spulPartLen[] = "  *pulPartLen = 0x%x";
50
STRING fmt_spulSignatureLen[] = "  *pulSignatureLen = 0x%x";
51
STRING fmt_ulAttributeCount[] = "  ulAttributeCount = %d";
52
STRING fmt_ulCount[] = "  ulCount = %d";
53
STRING fmt_ulDataLen[] = "  ulDataLen = %d";
54
STRING fmt_ulEncryptedPartLen[] = "  ulEncryptedPartLen = %d";
55
STRING fmt_ulPartLen[] = "  ulPartLen = %d";
56
STRING fmt_ulPinLen[] = "  ulPinLen = %d";
57
STRING fmt_ulSignatureLen[] = "  ulSignatureLen = %d";
58
59
STRING fmt_fwVersion[] = "  firmware version: %d.%d";
60
STRING fmt_hwVersion[] = "  hardware version: %d.%d";
61
STRING fmt_s_qsq_d[] = "    %s = \"%s\" [%d]";
62
STRING fmt_s_s_d[] = "    %s = %s [%d]";
63
STRING fmt_s_lu[] = "    %s = %lu";
64
STRING fmt_invalid_handle[] = " (CK_INVALID_HANDLE)";
65
66
static void
67
get_attr_type_str(CK_ATTRIBUTE_TYPE atype, char *str, int len)
68
0
{
69
0
#define CASE(attr) \
70
0
    case attr:     \
71
0
        a = #attr; \
72
0
        break
73
0
74
0
    const char *a = NULL;
75
0
76
0
    switch (atype) {
77
0
        CASE(CKA_CLASS);
78
0
        CASE(CKA_TOKEN);
79
0
        CASE(CKA_PRIVATE);
80
0
        CASE(CKA_LABEL);
81
0
        CASE(CKA_APPLICATION);
82
0
        CASE(CKA_VALUE);
83
0
        CASE(CKA_OBJECT_ID);
84
0
        CASE(CKA_CERTIFICATE_TYPE);
85
0
        CASE(CKA_CERTIFICATE_CATEGORY);
86
0
        CASE(CKA_ISSUER);
87
0
        CASE(CKA_SERIAL_NUMBER);
88
0
        CASE(CKA_AC_ISSUER);
89
0
        CASE(CKA_OWNER);
90
0
        CASE(CKA_ATTR_TYPES);
91
0
        CASE(CKA_TRUSTED);
92
0
        CASE(CKA_KEY_TYPE);
93
0
        CASE(CKA_SUBJECT);
94
0
        CASE(CKA_ID);
95
0
        CASE(CKA_SENSITIVE);
96
0
        CASE(CKA_ENCRYPT);
97
0
        CASE(CKA_DECRYPT);
98
0
        CASE(CKA_WRAP);
99
0
        CASE(CKA_UNWRAP);
100
0
        CASE(CKA_SIGN);
101
0
        CASE(CKA_SIGN_RECOVER);
102
0
        CASE(CKA_VERIFY);
103
0
        CASE(CKA_VERIFY_RECOVER);
104
0
        CASE(CKA_DERIVE);
105
0
        CASE(CKA_START_DATE);
106
0
        CASE(CKA_END_DATE);
107
0
        CASE(CKA_MODULUS);
108
0
        CASE(CKA_MODULUS_BITS);
109
0
        CASE(CKA_PUBLIC_EXPONENT);
110
0
        CASE(CKA_PRIVATE_EXPONENT);
111
0
        CASE(CKA_PRIME_1);
112
0
        CASE(CKA_PRIME_2);
113
0
        CASE(CKA_EXPONENT_1);
114
0
        CASE(CKA_EXPONENT_2);
115
0
        CASE(CKA_COEFFICIENT);
116
0
        CASE(CKA_PRIME);
117
0
        CASE(CKA_SUBPRIME);
118
0
        CASE(CKA_BASE);
119
0
        CASE(CKA_PRIME_BITS);
120
0
        CASE(CKA_SUBPRIME_BITS);
121
0
        CASE(CKA_VALUE_BITS);
122
0
        CASE(CKA_VALUE_LEN);
123
0
        CASE(CKA_EXTRACTABLE);
124
0
        CASE(CKA_LOCAL);
125
0
        CASE(CKA_NEVER_EXTRACTABLE);
126
0
        CASE(CKA_ALWAYS_SENSITIVE);
127
0
        CASE(CKA_KEY_GEN_MECHANISM);
128
0
        CASE(CKA_MODIFIABLE);
129
0
        CASE(CKA_ECDSA_PARAMS);
130
0
        CASE(CKA_EC_POINT);
131
0
        CASE(CKA_SECONDARY_AUTH);
132
0
        CASE(CKA_AUTH_PIN_FLAGS);
133
0
        CASE(CKA_HW_FEATURE_TYPE);
134
0
        CASE(CKA_RESET_ON_INIT);
135
0
        CASE(CKA_HAS_RESET);
136
0
        CASE(CKA_VENDOR_DEFINED);
137
0
        CASE(CKA_NSS_URL);
138
0
        CASE(CKA_NSS_EMAIL);
139
0
        CASE(CKA_NSS_SMIME_INFO);
140
0
        CASE(CKA_NSS_SMIME_TIMESTAMP);
141
0
        CASE(CKA_NSS_PKCS8_SALT);
142
0
        CASE(CKA_NSS_PASSWORD_CHECK);
143
0
        CASE(CKA_NSS_EXPIRES);
144
0
        CASE(CKA_NSS_KRL);
145
0
        CASE(CKA_NSS_PQG_COUNTER);
146
0
        CASE(CKA_NSS_PQG_SEED);
147
0
        CASE(CKA_NSS_PQG_H);
148
0
        CASE(CKA_NSS_PQG_SEED_BITS);
149
0
        CASE(CKA_TRUST);
150
0
        CASE(CKA_TRUST_DIGITAL_SIGNATURE);
151
0
        CASE(CKA_TRUST_NON_REPUDIATION);
152
0
        CASE(CKA_TRUST_KEY_ENCIPHERMENT);
153
0
        CASE(CKA_TRUST_DATA_ENCIPHERMENT);
154
0
        CASE(CKA_TRUST_KEY_AGREEMENT);
155
0
        CASE(CKA_TRUST_KEY_CERT_SIGN);
156
0
        CASE(CKA_TRUST_CRL_SIGN);
157
0
        CASE(CKA_TRUST_SERVER_AUTH);
158
0
        CASE(CKA_TRUST_CLIENT_AUTH);
159
0
        CASE(CKA_TRUST_CODE_SIGNING);
160
0
        CASE(CKA_TRUST_EMAIL_PROTECTION);
161
0
        CASE(CKA_TRUST_IPSEC_END_SYSTEM);
162
0
        CASE(CKA_TRUST_IPSEC_TUNNEL);
163
0
        CASE(CKA_TRUST_IPSEC_USER);
164
0
        CASE(CKA_TRUST_TIME_STAMPING);
165
0
        CASE(CKA_CERT_SHA1_HASH);
166
0
        CASE(CKA_CERT_MD5_HASH);
167
0
        CASE(CKA_NETSCAPE_DB);
168
0
        CASE(CKA_NETSCAPE_TRUST);
169
0
        default:
170
0
            break;
171
0
    }
172
0
    if (a)
173
0
        PR_snprintf(str, len, "%s", a);
174
0
    else
175
0
        PR_snprintf(str, len, "0x%p", atype);
176
0
}
177
178
static void
179
get_obj_class(CK_OBJECT_CLASS objClass, char *str, int len)
180
0
{
181
0
182
0
    const char *a = NULL;
183
0
184
0
    switch (objClass) {
185
0
        CASE(CKO_DATA);
186
0
        CASE(CKO_CERTIFICATE);
187
0
        CASE(CKO_PUBLIC_KEY);
188
0
        CASE(CKO_PRIVATE_KEY);
189
0
        CASE(CKO_SECRET_KEY);
190
0
        CASE(CKO_HW_FEATURE);
191
0
        CASE(CKO_DOMAIN_PARAMETERS);
192
0
        CASE(CKO_NSS_CRL);
193
0
        CASE(CKO_NSS_SMIME);
194
0
        CASE(CKO_NSS_TRUST);
195
0
        CASE(CKO_NSS_BUILTIN_ROOT_LIST);
196
0
        default:
197
0
            break;
198
0
    }
199
0
    if (a)
200
0
        PR_snprintf(str, len, "%s", a);
201
0
    else
202
0
        PR_snprintf(str, len, "0x%p", objClass);
203
0
}
204
205
static void
206
get_trust_val(CK_TRUST trust, char *str, int len)
207
0
{
208
0
    const char *a = NULL;
209
0
210
0
    switch (trust) {
211
0
        CASE(CKT_NSS_TRUSTED);
212
0
        CASE(CKT_NSS_TRUSTED_DELEGATOR);
213
0
        CASE(CKT_NSS_NOT_TRUSTED);
214
0
        CASE(CKT_NSS_MUST_VERIFY_TRUST);
215
0
        CASE(CKT_NSS_TRUST_UNKNOWN);
216
0
        CASE(CKT_NSS_VALID_DELEGATOR);
217
0
        default:
218
0
            break;
219
0
    }
220
0
    if (a)
221
0
        PR_snprintf(str, len, "%s", a);
222
0
    else
223
0
        PR_snprintf(str, len, "0x%p", trust);
224
0
}
225
226
static void
227
log_rv(CK_RV rv)
228
0
{
229
0
    const char *a = NULL;
230
0
231
0
    switch (rv) {
232
0
        CASE(CKR_OK);
233
0
        CASE(CKR_CANCEL);
234
0
        CASE(CKR_HOST_MEMORY);
235
0
        CASE(CKR_SLOT_ID_INVALID);
236
0
        CASE(CKR_GENERAL_ERROR);
237
0
        CASE(CKR_FUNCTION_FAILED);
238
0
        CASE(CKR_ARGUMENTS_BAD);
239
0
        CASE(CKR_NO_EVENT);
240
0
        CASE(CKR_NEED_TO_CREATE_THREADS);
241
0
        CASE(CKR_CANT_LOCK);
242
0
        CASE(CKR_ATTRIBUTE_READ_ONLY);
243
0
        CASE(CKR_ATTRIBUTE_SENSITIVE);
244
0
        CASE(CKR_ATTRIBUTE_TYPE_INVALID);
245
0
        CASE(CKR_ATTRIBUTE_VALUE_INVALID);
246
0
        CASE(CKR_DATA_INVALID);
247
0
        CASE(CKR_DATA_LEN_RANGE);
248
0
        CASE(CKR_DEVICE_ERROR);
249
0
        CASE(CKR_DEVICE_MEMORY);
250
0
        CASE(CKR_DEVICE_REMOVED);
251
0
        CASE(CKR_ENCRYPTED_DATA_INVALID);
252
0
        CASE(CKR_ENCRYPTED_DATA_LEN_RANGE);
253
0
        CASE(CKR_FUNCTION_CANCELED);
254
0
        CASE(CKR_FUNCTION_NOT_PARALLEL);
255
0
        CASE(CKR_FUNCTION_NOT_SUPPORTED);
256
0
        CASE(CKR_KEY_HANDLE_INVALID);
257
0
        CASE(CKR_KEY_SIZE_RANGE);
258
0
        CASE(CKR_KEY_TYPE_INCONSISTENT);
259
0
        CASE(CKR_KEY_NOT_NEEDED);
260
0
        CASE(CKR_KEY_CHANGED);
261
0
        CASE(CKR_KEY_NEEDED);
262
0
        CASE(CKR_KEY_INDIGESTIBLE);
263
0
        CASE(CKR_KEY_FUNCTION_NOT_PERMITTED);
264
0
        CASE(CKR_KEY_NOT_WRAPPABLE);
265
0
        CASE(CKR_KEY_UNEXTRACTABLE);
266
0
        CASE(CKR_MECHANISM_INVALID);
267
0
        CASE(CKR_MECHANISM_PARAM_INVALID);
268
0
        CASE(CKR_OBJECT_HANDLE_INVALID);
269
0
        CASE(CKR_OPERATION_ACTIVE);
270
0
        CASE(CKR_OPERATION_NOT_INITIALIZED);
271
0
        CASE(CKR_PIN_INCORRECT);
272
0
        CASE(CKR_PIN_INVALID);
273
0
        CASE(CKR_PIN_LEN_RANGE);
274
0
        CASE(CKR_PIN_EXPIRED);
275
0
        CASE(CKR_PIN_LOCKED);
276
0
        CASE(CKR_SESSION_CLOSED);
277
0
        CASE(CKR_SESSION_COUNT);
278
0
        CASE(CKR_SESSION_HANDLE_INVALID);
279
0
        CASE(CKR_SESSION_PARALLEL_NOT_SUPPORTED);
280
0
        CASE(CKR_SESSION_READ_ONLY);
281
0
        CASE(CKR_SESSION_EXISTS);
282
0
        CASE(CKR_SESSION_READ_ONLY_EXISTS);
283
0
        CASE(CKR_SESSION_READ_WRITE_SO_EXISTS);
284
0
        CASE(CKR_SIGNATURE_INVALID);
285
0
        CASE(CKR_SIGNATURE_LEN_RANGE);
286
0
        CASE(CKR_TEMPLATE_INCOMPLETE);
287
0
        CASE(CKR_TEMPLATE_INCONSISTENT);
288
0
        CASE(CKR_TOKEN_NOT_PRESENT);
289
0
        CASE(CKR_TOKEN_NOT_RECOGNIZED);
290
0
        CASE(CKR_TOKEN_WRITE_PROTECTED);
291
0
        CASE(CKR_UNWRAPPING_KEY_HANDLE_INVALID);
292
0
        CASE(CKR_UNWRAPPING_KEY_SIZE_RANGE);
293
0
        CASE(CKR_UNWRAPPING_KEY_TYPE_INCONSISTENT);
294
0
        CASE(CKR_USER_ALREADY_LOGGED_IN);
295
0
        CASE(CKR_USER_NOT_LOGGED_IN);
296
0
        CASE(CKR_USER_PIN_NOT_INITIALIZED);
297
0
        CASE(CKR_USER_TYPE_INVALID);
298
0
        CASE(CKR_USER_ANOTHER_ALREADY_LOGGED_IN);
299
0
        CASE(CKR_USER_TOO_MANY_TYPES);
300
0
        CASE(CKR_WRAPPED_KEY_INVALID);
301
0
        CASE(CKR_WRAPPED_KEY_LEN_RANGE);
302
0
        CASE(CKR_WRAPPING_KEY_HANDLE_INVALID);
303
0
        CASE(CKR_WRAPPING_KEY_SIZE_RANGE);
304
0
        CASE(CKR_WRAPPING_KEY_TYPE_INCONSISTENT);
305
0
        CASE(CKR_RANDOM_SEED_NOT_SUPPORTED);
306
0
        CASE(CKR_RANDOM_NO_RNG);
307
0
        CASE(CKR_DOMAIN_PARAMS_INVALID);
308
0
        CASE(CKR_BUFFER_TOO_SMALL);
309
0
        CASE(CKR_SAVED_STATE_INVALID);
310
0
        CASE(CKR_INFORMATION_SENSITIVE);
311
0
        CASE(CKR_STATE_UNSAVEABLE);
312
0
        CASE(CKR_CRYPTOKI_NOT_INITIALIZED);
313
0
        CASE(CKR_CRYPTOKI_ALREADY_INITIALIZED);
314
0
        CASE(CKR_MUTEX_BAD);
315
0
        CASE(CKR_MUTEX_NOT_LOCKED);
316
0
        CASE(CKR_FUNCTION_REJECTED);
317
0
        CASE(CKR_KEY_PARAMS_INVALID);
318
0
        default:
319
0
            break;
320
0
    }
321
0
    if (a)
322
0
        PR_LOG(modlog, 1, ("  rv = %s\n", a));
323
0
    else
324
0
        PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
325
0
}
326
327
static void
328
log_state(CK_STATE state)
329
0
{
330
0
    const char *a = NULL;
331
0
332
0
    switch (state) {
333
0
        CASE(CKS_RO_PUBLIC_SESSION);
334
0
        CASE(CKS_RO_USER_FUNCTIONS);
335
0
        CASE(CKS_RW_PUBLIC_SESSION);
336
0
        CASE(CKS_RW_USER_FUNCTIONS);
337
0
        CASE(CKS_RW_SO_FUNCTIONS);
338
0
        default:
339
0
            break;
340
0
    }
341
0
    if (a)
342
0
        PR_LOG(modlog, 1, ("  state = %s\n", a));
343
0
    else
344
0
        PR_LOG(modlog, 1, ("  state = 0x%x\n", state));
345
0
}
346
347
static void
348
log_handle(int level, const char *format, CK_ULONG handle)
349
0
{
350
0
    char fmtBuf[80];
351
0
    if (handle)
352
0
        PR_LOG(modlog, level, (format, handle));
353
0
    else {
354
0
        PL_strncpyz(fmtBuf, format, sizeof fmtBuf);
355
0
        PL_strcatn(fmtBuf, sizeof fmtBuf, fmt_invalid_handle);
356
0
        PR_LOG(modlog, level, (fmtBuf, handle));
357
0
    }
358
0
}
359
360
static void
361
print_mechanism(CK_MECHANISM_PTR m)
362
0
{
363
0
364
0
    const char *a = NULL;
365
0
366
0
    switch (m->mechanism) {
367
0
        CASE(CKM_AES_CBC);
368
0
        CASE(CKM_AES_CBC_ENCRYPT_DATA);
369
0
        CASE(CKM_AES_CBC_PAD);
370
0
        CASE(CKM_AES_CCM);
371
0
        CASE(CKM_AES_CTR);
372
0
        CASE(CKM_AES_CTS);
373
0
        CASE(CKM_AES_GCM);
374
0
        CASE(CKM_AES_ECB);
375
0
        CASE(CKM_AES_ECB_ENCRYPT_DATA);
376
0
        CASE(CKM_AES_KEY_GEN);
377
0
        CASE(CKM_AES_MAC);
378
0
        CASE(CKM_AES_MAC_GENERAL);
379
0
        CASE(CKM_CAMELLIA_CBC);
380
0
        CASE(CKM_CAMELLIA_CBC_ENCRYPT_DATA);
381
0
        CASE(CKM_CAMELLIA_CBC_PAD);
382
0
        CASE(CKM_CAMELLIA_ECB);
383
0
        CASE(CKM_CAMELLIA_ECB_ENCRYPT_DATA);
384
0
        CASE(CKM_CAMELLIA_KEY_GEN);
385
0
        CASE(CKM_CAMELLIA_MAC);
386
0
        CASE(CKM_CAMELLIA_MAC_GENERAL);
387
0
        CASE(CKM_CDMF_CBC);
388
0
        CASE(CKM_CDMF_CBC_PAD);
389
0
        CASE(CKM_CDMF_ECB);
390
0
        CASE(CKM_CDMF_KEY_GEN);
391
0
        CASE(CKM_CDMF_MAC);
392
0
        CASE(CKM_CDMF_MAC_GENERAL);
393
0
        CASE(CKM_CMS_SIG);
394
0
        CASE(CKM_CONCATENATE_BASE_AND_DATA);
395
0
        CASE(CKM_CONCATENATE_BASE_AND_KEY);
396
0
        CASE(CKM_CONCATENATE_DATA_AND_BASE);
397
0
        CASE(CKM_DES2_KEY_GEN);
398
0
        CASE(CKM_DES3_CBC);
399
0
        CASE(CKM_DES3_CBC_ENCRYPT_DATA);
400
0
        CASE(CKM_DES3_CBC_PAD);
401
0
        CASE(CKM_DES3_ECB);
402
0
        CASE(CKM_DES3_ECB_ENCRYPT_DATA);
403
0
        CASE(CKM_DES3_KEY_GEN);
404
0
        CASE(CKM_DES3_MAC);
405
0
        CASE(CKM_DES3_MAC_GENERAL);
406
0
        CASE(CKM_DES_CBC);
407
0
        CASE(CKM_DES_CBC_ENCRYPT_DATA);
408
0
        CASE(CKM_DES_CBC_PAD);
409
0
        CASE(CKM_DES_CFB64);
410
0
        CASE(CKM_DES_CFB8);
411
0
        CASE(CKM_DES_ECB);
412
0
        CASE(CKM_DES_ECB_ENCRYPT_DATA);
413
0
        CASE(CKM_DES_KEY_GEN);
414
0
        CASE(CKM_DES_MAC);
415
0
        CASE(CKM_DES_MAC_GENERAL);
416
0
        CASE(CKM_DES_OFB64);
417
0
        CASE(CKM_DES_OFB8);
418
0
        CASE(CKM_DH_PKCS_DERIVE);
419
0
        CASE(CKM_DH_PKCS_KEY_PAIR_GEN);
420
0
        CASE(CKM_DH_PKCS_PARAMETER_GEN);
421
0
        CASE(CKM_DSA);
422
0
        CASE(CKM_DSA_KEY_PAIR_GEN);
423
0
        CASE(CKM_DSA_PARAMETER_GEN);
424
0
        CASE(CKM_DSA_SHA1);
425
0
        CASE(CKM_ECDH1_COFACTOR_DERIVE);
426
0
        CASE(CKM_ECDH1_DERIVE);
427
0
        CASE(CKM_ECDSA);
428
0
        CASE(CKM_ECDSA_SHA1);
429
0
        CASE(CKM_ECMQV_DERIVE);
430
0
        CASE(CKM_EC_KEY_PAIR_GEN); /* also CASE(CKM_ECDSA_KEY_PAIR_GEN); */
431
0
        CASE(CKM_EXTRACT_KEY_FROM_KEY);
432
0
        CASE(CKM_FASTHASH);
433
0
        CASE(CKM_FORTEZZA_TIMESTAMP);
434
0
        CASE(CKM_GENERIC_SECRET_KEY_GEN);
435
0
        CASE(CKM_IDEA_CBC);
436
0
        CASE(CKM_IDEA_CBC_PAD);
437
0
        CASE(CKM_IDEA_ECB);
438
0
        CASE(CKM_IDEA_KEY_GEN);
439
0
        CASE(CKM_IDEA_MAC);
440
0
        CASE(CKM_IDEA_MAC_GENERAL);
441
0
        CASE(CKM_KEA_KEY_DERIVE);
442
0
        CASE(CKM_KEA_KEY_PAIR_GEN);
443
0
        CASE(CKM_KEY_WRAP_LYNKS);
444
0
        CASE(CKM_KEY_WRAP_SET_OAEP);
445
0
        CASE(CKM_MD2);
446
0
        CASE(CKM_MD2_HMAC);
447
0
        CASE(CKM_MD2_HMAC_GENERAL);
448
0
        CASE(CKM_MD2_KEY_DERIVATION);
449
0
        CASE(CKM_MD2_RSA_PKCS);
450
0
        CASE(CKM_MD5);
451
0
        CASE(CKM_MD5_HMAC);
452
0
        CASE(CKM_MD5_HMAC_GENERAL);
453
0
        CASE(CKM_MD5_KEY_DERIVATION);
454
0
        CASE(CKM_MD5_RSA_PKCS);
455
0
        CASE(CKM_PBA_SHA1_WITH_SHA1_HMAC);
456
0
        CASE(CKM_PBE_MD2_DES_CBC);
457
0
        CASE(CKM_PBE_MD5_DES_CBC);
458
0
        CASE(CKM_PBE_SHA1_DES2_EDE_CBC);
459
0
        CASE(CKM_PBE_SHA1_DES3_EDE_CBC);
460
0
        CASE(CKM_PBE_SHA1_RC2_128_CBC);
461
0
        CASE(CKM_PBE_SHA1_RC2_40_CBC);
462
0
        CASE(CKM_PBE_SHA1_RC4_128);
463
0
        CASE(CKM_PBE_SHA1_RC4_40);
464
0
        CASE(CKM_PKCS5_PBKD2);
465
0
        CASE(CKM_RC2_CBC);
466
0
        CASE(CKM_RC2_CBC_PAD);
467
0
        CASE(CKM_RC2_ECB);
468
0
        CASE(CKM_RC2_KEY_GEN);
469
0
        CASE(CKM_RC2_MAC);
470
0
        CASE(CKM_RC2_MAC_GENERAL);
471
0
        CASE(CKM_RC4);
472
0
        CASE(CKM_RC4_KEY_GEN);
473
0
        CASE(CKM_RC5_CBC);
474
0
        CASE(CKM_RC5_CBC_PAD);
475
0
        CASE(CKM_RC5_ECB);
476
0
        CASE(CKM_RC5_KEY_GEN);
477
0
        CASE(CKM_RC5_MAC);
478
0
        CASE(CKM_RC5_MAC_GENERAL);
479
0
        CASE(CKM_RIPEMD128);
480
0
        CASE(CKM_RIPEMD128_HMAC);
481
0
        CASE(CKM_RIPEMD128_HMAC_GENERAL);
482
0
        CASE(CKM_RIPEMD128_RSA_PKCS);
483
0
        CASE(CKM_RIPEMD160);
484
0
        CASE(CKM_RIPEMD160_HMAC);
485
0
        CASE(CKM_RIPEMD160_HMAC_GENERAL);
486
0
        CASE(CKM_RIPEMD160_RSA_PKCS);
487
0
        CASE(CKM_RSA_9796);
488
0
        CASE(CKM_RSA_PKCS);
489
0
        CASE(CKM_RSA_PKCS_KEY_PAIR_GEN);
490
0
        CASE(CKM_RSA_PKCS_OAEP);
491
0
        CASE(CKM_RSA_PKCS_PSS);
492
0
        CASE(CKM_RSA_X9_31);
493
0
        CASE(CKM_RSA_X9_31_KEY_PAIR_GEN);
494
0
        CASE(CKM_RSA_X_509);
495
0
        CASE(CKM_SHA1_KEY_DERIVATION);
496
0
        CASE(CKM_SHA1_RSA_PKCS);
497
0
        CASE(CKM_SHA1_RSA_PKCS_PSS);
498
0
        CASE(CKM_SHA1_RSA_X9_31);
499
0
        CASE(CKM_SHA224);
500
0
        CASE(CKM_SHA224_HMAC);
501
0
        CASE(CKM_SHA224_HMAC_GENERAL);
502
0
        CASE(CKM_SHA224_KEY_DERIVATION);
503
0
        CASE(CKM_SHA224_RSA_PKCS);
504
0
        CASE(CKM_SHA224_RSA_PKCS_PSS);
505
0
        CASE(CKM_SHA256);
506
0
        CASE(CKM_SHA256_HMAC);
507
0
        CASE(CKM_SHA256_HMAC_GENERAL);
508
0
        CASE(CKM_SHA256_KEY_DERIVATION);
509
0
        CASE(CKM_SHA256_RSA_PKCS);
510
0
        CASE(CKM_SHA256_RSA_PKCS_PSS);
511
0
        CASE(CKM_SHA384);
512
0
        CASE(CKM_SHA384_HMAC);
513
0
        CASE(CKM_SHA384_HMAC_GENERAL);
514
0
        CASE(CKM_SHA384_KEY_DERIVATION);
515
0
        CASE(CKM_SHA384_RSA_PKCS);
516
0
        CASE(CKM_SHA384_RSA_PKCS_PSS);
517
0
        CASE(CKM_SHA512);
518
0
        CASE(CKM_SHA512_HMAC);
519
0
        CASE(CKM_SHA512_HMAC_GENERAL);
520
0
        CASE(CKM_SHA512_KEY_DERIVATION);
521
0
        CASE(CKM_SHA512_RSA_PKCS);
522
0
        CASE(CKM_SHA512_RSA_PKCS_PSS);
523
0
        CASE(CKM_SHA_1);
524
0
        CASE(CKM_SHA_1_HMAC);
525
0
        CASE(CKM_SHA_1_HMAC_GENERAL);
526
0
        CASE(CKM_SKIPJACK_CBC64);
527
0
        CASE(CKM_SKIPJACK_CFB16);
528
0
        CASE(CKM_SKIPJACK_CFB32);
529
0
        CASE(CKM_SKIPJACK_CFB64);
530
0
        CASE(CKM_SKIPJACK_CFB8);
531
0
        CASE(CKM_SKIPJACK_ECB64);
532
0
        CASE(CKM_SKIPJACK_KEY_GEN);
533
0
        CASE(CKM_SKIPJACK_OFB64);
534
0
        CASE(CKM_SKIPJACK_PRIVATE_WRAP);
535
0
        CASE(CKM_SKIPJACK_RELAYX);
536
0
        CASE(CKM_SKIPJACK_WRAP);
537
0
        CASE(CKM_SSL3_KEY_AND_MAC_DERIVE);
538
0
        CASE(CKM_SSL3_MASTER_KEY_DERIVE);
539
0
        CASE(CKM_SSL3_MASTER_KEY_DERIVE_DH);
540
0
        CASE(CKM_SSL3_MD5_MAC);
541
0
        CASE(CKM_SSL3_PRE_MASTER_KEY_GEN);
542
0
        CASE(CKM_SSL3_SHA1_MAC);
543
0
        CASE(CKM_TLS_KEY_AND_MAC_DERIVE);
544
0
        CASE(CKM_TLS_MASTER_KEY_DERIVE);
545
0
        CASE(CKM_TLS_MASTER_KEY_DERIVE_DH);
546
0
        CASE(CKM_TLS_PRE_MASTER_KEY_GEN);
547
0
        CASE(CKM_TLS_PRF);
548
0
        CASE(CKM_TWOFISH_CBC);
549
0
        CASE(CKM_TWOFISH_KEY_GEN);
550
0
        CASE(CKM_X9_42_DH_DERIVE);
551
0
        CASE(CKM_X9_42_DH_HYBRID_DERIVE);
552
0
        CASE(CKM_X9_42_DH_KEY_PAIR_GEN);
553
0
        CASE(CKM_X9_42_DH_PARAMETER_GEN);
554
0
        CASE(CKM_X9_42_MQV_DERIVE);
555
0
        CASE(CKM_XOR_BASE_AND_DATA);
556
0
        default:
557
0
            break;
558
0
    }
559
0
    if (a)
560
0
        PR_LOG(modlog, 4, ("      mechanism = %s", a));
561
0
    else
562
0
        PR_LOG(modlog, 4, ("      mechanism = 0x%p", m->mechanism));
563
0
}
564
565
static void
566
get_key_type(CK_KEY_TYPE keyType, char *str, int len)
567
0
{
568
0
569
0
    const char *a = NULL;
570
0
571
0
    switch (keyType) {
572
0
        CASE(CKK_AES);
573
0
        CASE(CKK_CAMELLIA);
574
0
        CASE(CKK_CDMF);
575
0
        CASE(CKK_DES);
576
0
        CASE(CKK_DES2);
577
0
        CASE(CKK_DES3);
578
0
        CASE(CKK_DH);
579
0
        CASE(CKK_DSA);
580
0
        CASE(CKK_EC); /* also CASE(CKK_ECDSA); */
581
0
        CASE(CKK_GENERIC_SECRET);
582
0
        CASE(CKK_IDEA);
583
0
        CASE(CKK_INVALID_KEY_TYPE);
584
0
        CASE(CKK_KEA);
585
0
        CASE(CKK_RC2);
586
0
        CASE(CKK_RC4);
587
0
        CASE(CKK_RC5);
588
0
        CASE(CKK_RSA);
589
0
        CASE(CKK_SKIPJACK);
590
0
        CASE(CKK_TWOFISH);
591
0
        CASE(CKK_X9_42_DH);
592
0
        default:
593
0
            break;
594
0
    }
595
0
    if (a)
596
0
        PR_snprintf(str, len, "%s", a);
597
0
    else
598
0
        PR_snprintf(str, len, "0x%p", keyType);
599
0
}
600
601
static void
602
print_attr_value(CK_ATTRIBUTE_PTR attr)
603
0
{
604
0
    char atype[48];
605
0
    char valstr[49];
606
0
    int len;
607
0
608
0
    get_attr_type_str(attr->type, atype, sizeof atype);
609
0
    switch (attr->type) {
610
0
        case CKA_ALWAYS_SENSITIVE:
611
0
        case CKA_DECRYPT:
612
0
        case CKA_DERIVE:
613
0
        case CKA_ENCRYPT:
614
0
        case CKA_EXTRACTABLE:
615
0
        case CKA_LOCAL:
616
0
        case CKA_MODIFIABLE:
617
0
        case CKA_NEVER_EXTRACTABLE:
618
0
        case CKA_PRIVATE:
619
0
        case CKA_SENSITIVE:
620
0
        case CKA_SIGN:
621
0
        case CKA_SIGN_RECOVER:
622
0
        case CKA_TOKEN:
623
0
        case CKA_UNWRAP:
624
0
        case CKA_VERIFY:
625
0
        case CKA_VERIFY_RECOVER:
626
0
        case CKA_WRAP:
627
0
            if (attr->ulValueLen > 0 && attr->pValue) {
628
0
                CK_BBOOL tf = *((CK_BBOOL *)attr->pValue);
629
0
                PR_LOG(modlog, 4, (fmt_s_s_d,
630
0
                                   atype, tf ? "CK_TRUE" : "CK_FALSE", attr->ulValueLen));
631
0
                break;
632
0
            }
633
0
        case CKA_CLASS:
634
0
            if (attr->ulValueLen > 0 && attr->pValue) {
635
0
                CK_OBJECT_CLASS objClass = *((CK_OBJECT_CLASS *)attr->pValue);
636
0
                get_obj_class(objClass, valstr, sizeof valstr);
637
0
                PR_LOG(modlog, 4, (fmt_s_s_d,
638
0
                                   atype, valstr, attr->ulValueLen));
639
0
                break;
640
0
            }
641
0
        case CKA_TRUST_CLIENT_AUTH:
642
0
        case CKA_TRUST_CODE_SIGNING:
643
0
        case CKA_TRUST_EMAIL_PROTECTION:
644
0
        case CKA_TRUST_SERVER_AUTH:
645
0
            if (attr->ulValueLen > 0 && attr->pValue) {
646
0
                CK_TRUST trust = *((CK_TRUST *)attr->pValue);
647
0
                get_trust_val(trust, valstr, sizeof valstr);
648
0
                PR_LOG(modlog, 4, (fmt_s_s_d,
649
0
                                   atype, valstr, attr->ulValueLen));
650
0
                break;
651
0
            }
652
0
        case CKA_KEY_TYPE:
653
0
            if (attr->ulValueLen > 0 && attr->pValue) {
654
0
                CK_KEY_TYPE keyType = *((CK_KEY_TYPE *)attr->pValue);
655
0
                get_key_type(keyType, valstr, sizeof valstr);
656
0
                PR_LOG(modlog, 4, (fmt_s_s_d,
657
0
                                   atype, valstr, attr->ulValueLen));
658
0
                break;
659
0
            }
660
0
        case CKA_PIXEL_X:
661
0
        case CKA_PIXEL_Y:
662
0
        case CKA_RESOLUTION:
663
0
        case CKA_CHAR_ROWS:
664
0
        case CKA_CHAR_COLUMNS:
665
0
        case CKA_BITS_PER_PIXEL:
666
0
        case CKA_CERTIFICATE_CATEGORY:      /* should print as enum/string */
667
0
        case CKA_JAVA_MIDP_SECURITY_DOMAIN: /* should print as enum/string */
668
0
        case CKA_MODULUS_BITS:
669
0
        case CKA_PRIME_BITS:
670
0
        case CKA_SUBPRIME_BITS:
671
0
        case CKA_VALUE_BITS:
672
0
        case CKA_VALUE_LEN:
673
0
            if (attr->ulValueLen > 0 && attr->pValue) {
674
0
                CK_ULONG valueLen = *((CK_ULONG *)attr->pValue);
675
0
                /* XXX check for the special value CK_UNAVAILABLE_INFORMATION */
676
0
                PR_LOG(modlog, 4, (fmt_s_lu, atype, (PRUint32)valueLen));
677
0
                break;
678
0
            }
679
0
        case CKA_LABEL:
680
0
        case CKA_NSS_EMAIL:
681
0
        case CKA_NSS_URL:
682
0
            if (attr->ulValueLen > 0 && attr->pValue) {
683
0
                len = PR_MIN(attr->ulValueLen + 1, sizeof valstr);
684
0
                PR_snprintf(valstr, len, "%s", attr->pValue);
685
0
                PR_LOG(modlog, 4, (fmt_s_qsq_d,
686
0
                                   atype, valstr, attr->ulValueLen));
687
0
                break;
688
0
            }
689
0
        case CKA_ISSUER:
690
0
        case CKA_SUBJECT:
691
0
            if (attr->ulValueLen > 0 && attr->pValue) {
692
0
                char *asciiName;
693
0
                SECItem derName;
694
0
                derName.type = siDERNameBuffer;
695
0
                derName.data = attr->pValue;
696
0
                derName.len = attr->ulValueLen;
697
0
                asciiName = CERT_DerNameToAscii(&derName);
698
0
                if (asciiName) {
699
0
                    PR_LOG(modlog, 4, (fmt_s_s_d,
700
0
                                       atype, asciiName, attr->ulValueLen));
701
0
                    PORT_Free(asciiName);
702
0
                    break;
703
0
                }
704
0
                /* else treat like a binary buffer */
705
0
                goto binary_buffer;
706
0
            }
707
0
        case CKA_ID:
708
0
            if (attr->ulValueLen > 0 && attr->pValue) {
709
0
                unsigned char *pV = attr->pValue;
710
0
                for (len = (int)attr->ulValueLen; len > 0; --len) {
711
0
                    unsigned int ch = *pV++;
712
0
                    if (ch >= 0x20 && ch < 0x7f)
713
0
                        continue;
714
0
                    if (!ch && len == 1) /* will ignore NUL if last character */
715
0
                        continue;
716
0
                    break;
717
0
                }
718
0
                if (!len) { /* entire string is printable */
719
0
                    len = PR_MIN(attr->ulValueLen + 1, sizeof valstr);
720
0
                    PR_snprintf(valstr, len, "%s", attr->pValue);
721
0
                    PR_LOG(modlog, 4, (fmt_s_qsq_d,
722
0
                                       atype, valstr, attr->ulValueLen));
723
0
                    break;
724
0
                }
725
0
                /* else fall through and treat like a binary buffer */
726
0
            }
727
0
        binary_buffer:
728
0
        case CKA_SERIAL_NUMBER:
729
0
        default:
730
0
            if (attr->ulValueLen > 0 && attr->pValue) {
731
0
                char *hexBuf;
732
0
                SECItem attrBuf;
733
0
                attrBuf.type = siDERNameBuffer;
734
0
                attrBuf.data = attr->pValue;
735
0
                attrBuf.len = PR_MIN(attr->ulValueLen, (sizeof valstr) / 2);
736
0
737
0
                hexBuf = CERT_Hexify(&attrBuf, PR_FALSE);
738
0
                if (hexBuf) {
739
0
                    PR_LOG(modlog, 4, (fmt_s_s_d,
740
0
                                       atype, hexBuf, attr->ulValueLen));
741
0
                    PORT_Free(hexBuf);
742
0
                    break;
743
0
                }
744
0
                /* else fall through and show only the address. :( */
745
0
            }
746
0
            PR_LOG(modlog, 4, ("    %s = [0x%p] [%d]",
747
0
                               atype, attr->pValue, attr->ulValueLen));
748
0
            break;
749
0
    }
750
0
}
751
752
static void
753
print_template(CK_ATTRIBUTE_PTR templ, CK_ULONG tlen)
754
0
{
755
0
    CK_ULONG i;
756
0
    for (i = 0; i < tlen; i++) {
757
0
        print_attr_value(&templ[i]);
758
0
    }
759
0
}
760
761
struct nssdbg_prof_str {
762
    PRUint32 time;
763
    PRUint32 calls;
764
    char *function;
765
};
766
767
#define NSSDBG_DEFINE(func) \
768
    {                       \
769
        0, 0, #func         \
770
    }
771
772
struct nssdbg_prof_str nssdbg_prof_data[] = {
773
0
#define FUNC_C_INITIALIZE 0
774
    NSSDBG_DEFINE(C_Initialize),
775
0
#define FUNC_C_FINALIZE 1
776
    NSSDBG_DEFINE(C_Finalize),
777
0
#define FUNC_C_GETINFO 2
778
    NSSDBG_DEFINE(C_GetInfo),
779
0
#define FUNC_C_GETFUNCITONLIST 3
780
    NSSDBG_DEFINE(C_GetFunctionList),
781
0
#define FUNC_C_GETSLOTLIST 4
782
    NSSDBG_DEFINE(C_GetSlotList),
783
0
#define FUNC_C_GETSLOTINFO 5
784
    NSSDBG_DEFINE(C_GetSlotInfo),
785
0
#define FUNC_C_GETTOKENINFO 6
786
    NSSDBG_DEFINE(C_GetTokenInfo),
787
0
#define FUNC_C_GETMECHANISMLIST 7
788
    NSSDBG_DEFINE(C_GetMechanismList),
789
0
#define FUNC_C_GETMECHANISMINFO 8
790
    NSSDBG_DEFINE(C_GetMechanismInfo),
791
0
#define FUNC_C_INITTOKEN 9
792
    NSSDBG_DEFINE(C_InitToken),
793
0
#define FUNC_C_INITPIN 10
794
    NSSDBG_DEFINE(C_InitPIN),
795
0
#define FUNC_C_SETPIN 11
796
    NSSDBG_DEFINE(C_SetPIN),
797
0
#define FUNC_C_OPENSESSION 12
798
    NSSDBG_DEFINE(C_OpenSession),
799
0
#define FUNC_C_CLOSESESSION 13
800
    NSSDBG_DEFINE(C_CloseSession),
801
0
#define FUNC_C_CLOSEALLSESSIONS 14
802
    NSSDBG_DEFINE(C_CloseAllSessions),
803
0
#define FUNC_C_GETSESSIONINFO 15
804
    NSSDBG_DEFINE(C_GetSessionInfo),
805
0
#define FUNC_C_GETOPERATIONSTATE 16
806
    NSSDBG_DEFINE(C_GetOperationState),
807
0
#define FUNC_C_SETOPERATIONSTATE 17
808
    NSSDBG_DEFINE(C_SetOperationState),
809
0
#define FUNC_C_LOGIN 18
810
    NSSDBG_DEFINE(C_Login),
811
0
#define FUNC_C_LOGOUT 19
812
    NSSDBG_DEFINE(C_Logout),
813
0
#define FUNC_C_CREATEOBJECT 20
814
    NSSDBG_DEFINE(C_CreateObject),
815
0
#define FUNC_C_COPYOBJECT 21
816
    NSSDBG_DEFINE(C_CopyObject),
817
0
#define FUNC_C_DESTROYOBJECT 22
818
    NSSDBG_DEFINE(C_DestroyObject),
819
0
#define FUNC_C_GETOBJECTSIZE 23
820
    NSSDBG_DEFINE(C_GetObjectSize),
821
0
#define FUNC_C_GETATTRIBUTEVALUE 24
822
    NSSDBG_DEFINE(C_GetAttributeValue),
823
0
#define FUNC_C_SETATTRIBUTEVALUE 25
824
    NSSDBG_DEFINE(C_SetAttributeValue),
825
0
#define FUNC_C_FINDOBJECTSINIT 26
826
    NSSDBG_DEFINE(C_FindObjectsInit),
827
0
#define FUNC_C_FINDOBJECTS 27
828
    NSSDBG_DEFINE(C_FindObjects),
829
0
#define FUNC_C_FINDOBJECTSFINAL 28
830
    NSSDBG_DEFINE(C_FindObjectsFinal),
831
0
#define FUNC_C_ENCRYPTINIT 29
832
    NSSDBG_DEFINE(C_EncryptInit),
833
0
#define FUNC_C_ENCRYPT 30
834
    NSSDBG_DEFINE(C_Encrypt),
835
0
#define FUNC_C_ENCRYPTUPDATE 31
836
    NSSDBG_DEFINE(C_EncryptUpdate),
837
0
#define FUNC_C_ENCRYPTFINAL 32
838
    NSSDBG_DEFINE(C_EncryptFinal),
839
0
#define FUNC_C_DECRYPTINIT 33
840
    NSSDBG_DEFINE(C_DecryptInit),
841
0
#define FUNC_C_DECRYPT 34
842
    NSSDBG_DEFINE(C_Decrypt),
843
0
#define FUNC_C_DECRYPTUPDATE 35
844
    NSSDBG_DEFINE(C_DecryptUpdate),
845
0
#define FUNC_C_DECRYPTFINAL 36
846
    NSSDBG_DEFINE(C_DecryptFinal),
847
0
#define FUNC_C_DIGESTINIT 37
848
    NSSDBG_DEFINE(C_DigestInit),
849
0
#define FUNC_C_DIGEST 38
850
    NSSDBG_DEFINE(C_Digest),
851
0
#define FUNC_C_DIGESTUPDATE 39
852
    NSSDBG_DEFINE(C_DigestUpdate),
853
0
#define FUNC_C_DIGESTKEY 40
854
    NSSDBG_DEFINE(C_DigestKey),
855
0
#define FUNC_C_DIGESTFINAL 41
856
    NSSDBG_DEFINE(C_DigestFinal),
857
0
#define FUNC_C_SIGNINIT 42
858
    NSSDBG_DEFINE(C_SignInit),
859
0
#define FUNC_C_SIGN 43
860
    NSSDBG_DEFINE(C_Sign),
861
0
#define FUNC_C_SIGNUPDATE 44
862
    NSSDBG_DEFINE(C_SignUpdate),
863
0
#define FUNC_C_SIGNFINAL 45
864
    NSSDBG_DEFINE(C_SignFinal),
865
0
#define FUNC_C_SIGNRECOVERINIT 46
866
    NSSDBG_DEFINE(C_SignRecoverInit),
867
0
#define FUNC_C_SIGNRECOVER 47
868
    NSSDBG_DEFINE(C_SignRecover),
869
0
#define FUNC_C_VERIFYINIT 48
870
    NSSDBG_DEFINE(C_VerifyInit),
871
0
#define FUNC_C_VERIFY 49
872
    NSSDBG_DEFINE(C_Verify),
873
0
#define FUNC_C_VERIFYUPDATE 50
874
    NSSDBG_DEFINE(C_VerifyUpdate),
875
0
#define FUNC_C_VERIFYFINAL 51
876
    NSSDBG_DEFINE(C_VerifyFinal),
877
0
#define FUNC_C_VERIFYRECOVERINIT 52
878
    NSSDBG_DEFINE(C_VerifyRecoverInit),
879
0
#define FUNC_C_VERIFYRECOVER 53
880
    NSSDBG_DEFINE(C_VerifyRecover),
881
0
#define FUNC_C_DIGESTENCRYPTUPDATE 54
882
    NSSDBG_DEFINE(C_DigestEncryptUpdate),
883
0
#define FUNC_C_DECRYPTDIGESTUPDATE 55
884
    NSSDBG_DEFINE(C_DecryptDigestUpdate),
885
0
#define FUNC_C_SIGNENCRYPTUPDATE 56
886
    NSSDBG_DEFINE(C_SignEncryptUpdate),
887
0
#define FUNC_C_DECRYPTVERIFYUPDATE 57
888
    NSSDBG_DEFINE(C_DecryptVerifyUpdate),
889
0
#define FUNC_C_GENERATEKEY 58
890
    NSSDBG_DEFINE(C_GenerateKey),
891
0
#define FUNC_C_GENERATEKEYPAIR 59
892
    NSSDBG_DEFINE(C_GenerateKeyPair),
893
0
#define FUNC_C_WRAPKEY 60
894
    NSSDBG_DEFINE(C_WrapKey),
895
0
#define FUNC_C_UNWRAPKEY 61
896
    NSSDBG_DEFINE(C_UnWrapKey),
897
0
#define FUNC_C_DERIVEKEY 62
898
    NSSDBG_DEFINE(C_DeriveKey),
899
0
#define FUNC_C_SEEDRANDOM 63
900
    NSSDBG_DEFINE(C_SeedRandom),
901
0
#define FUNC_C_GENERATERANDOM 64
902
    NSSDBG_DEFINE(C_GenerateRandom),
903
0
#define FUNC_C_GETFUNCTIONSTATUS 65
904
    NSSDBG_DEFINE(C_GetFunctionStatus),
905
0
#define FUNC_C_CANCELFUNCTION 66
906
    NSSDBG_DEFINE(C_CancelFunction),
907
0
#define FUNC_C_WAITFORSLOTEVENT 67
908
    NSSDBG_DEFINE(C_WaitForSlotEvent)
909
};
910
911
int nssdbg_prof_size = sizeof(nssdbg_prof_data) / sizeof(nssdbg_prof_data[0]);
912
913
static void
914
nssdbg_finish_time(PRInt32 fun_number, PRIntervalTime start)
915
0
{
916
0
    PRIntervalTime ival;
917
0
    PRIntervalTime end = PR_IntervalNow();
918
0
919
0
    ival = end - start;
920
0
    /* sigh, lie to PRAtomic add and say we are using signed values */
921
0
    PR_ATOMIC_ADD((PRInt32 *)&nssdbg_prof_data[fun_number].time, (PRInt32)ival);
922
0
}
923
924
static void
925
nssdbg_start_time(PRInt32 fun_number, PRIntervalTime *start)
926
0
{
927
0
    PR_ATOMIC_INCREMENT((PRInt32 *)&nssdbg_prof_data[fun_number].calls);
928
0
    *start = PR_IntervalNow();
929
0
}
930
931
#define COMMON_DEFINITIONS \
932
0
    CK_RV rv;              \
933
0
    PRIntervalTime start
934
935
CK_RV
936
NSSDBGC_Initialize(
937
    CK_VOID_PTR pInitArgs)
938
0
{
939
0
    COMMON_DEFINITIONS;
940
0
941
0
    PR_LOG(modlog, 1, ("C_Initialize"));
942
0
    PR_LOG(modlog, 3, ("  pInitArgs = 0x%p", pInitArgs));
943
0
    nssdbg_start_time(FUNC_C_INITIALIZE, &start);
944
0
    rv = module_functions->C_Initialize(pInitArgs);
945
0
    nssdbg_finish_time(FUNC_C_INITIALIZE, start);
946
0
    log_rv(rv);
947
0
    return rv;
948
0
}
949
950
CK_RV
951
NSSDBGC_Finalize(
952
    CK_VOID_PTR pReserved)
953
0
{
954
0
    COMMON_DEFINITIONS;
955
0
956
0
    PR_LOG(modlog, 1, ("C_Finalize"));
957
0
    PR_LOG(modlog, 3, ("  pReserved = 0x%p", pReserved));
958
0
    nssdbg_start_time(FUNC_C_FINALIZE, &start);
959
0
    rv = module_functions->C_Finalize(pReserved);
960
0
    nssdbg_finish_time(FUNC_C_FINALIZE, start);
961
0
    log_rv(rv);
962
0
    return rv;
963
0
}
964
965
CK_RV
966
NSSDBGC_GetInfo(
967
    CK_INFO_PTR pInfo)
968
0
{
969
0
    COMMON_DEFINITIONS;
970
0
971
0
    PR_LOG(modlog, 1, ("C_GetInfo"));
972
0
    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
973
0
    nssdbg_start_time(FUNC_C_GETINFO, &start);
974
0
    rv = module_functions->C_GetInfo(pInfo);
975
0
    nssdbg_finish_time(FUNC_C_GETINFO, start);
976
0
    if (rv == CKR_OK) {
977
0
        PR_LOG(modlog, 4, ("  cryptoki version: %d.%d",
978
0
                           pInfo->cryptokiVersion.major,
979
0
                           pInfo->cryptokiVersion.minor));
980
0
        PR_LOG(modlog, 4, (fmt_manufacturerID, pInfo->manufacturerID));
981
0
        PR_LOG(modlog, 4, ("  library description = \"%.32s\"",
982
0
                           pInfo->libraryDescription));
983
0
        PR_LOG(modlog, 4, ("  library version: %d.%d",
984
0
                           pInfo->libraryVersion.major,
985
0
                           pInfo->libraryVersion.minor));
986
0
    }
987
0
    log_rv(rv);
988
0
    return rv;
989
0
}
990
991
CK_RV
992
NSSDBGC_GetFunctionList(
993
    CK_FUNCTION_LIST_PTR_PTR ppFunctionList)
994
0
{
995
0
    COMMON_DEFINITIONS;
996
0
997
0
    PR_LOG(modlog, 1, ("C_GetFunctionList"));
998
0
    PR_LOG(modlog, 3, ("  ppFunctionList = 0x%p", ppFunctionList));
999
0
    nssdbg_start_time(FUNC_C_GETFUNCITONLIST, &start);
1000
0
    rv = module_functions->C_GetFunctionList(ppFunctionList);
1001
0
    nssdbg_finish_time(FUNC_C_GETFUNCITONLIST, start);
1002
0
    log_rv(rv);
1003
0
    return rv;
1004
0
}
1005
1006
CK_RV
1007
NSSDBGC_GetSlotList(
1008
    CK_BBOOL tokenPresent,
1009
    CK_SLOT_ID_PTR pSlotList,
1010
    CK_ULONG_PTR pulCount)
1011
0
{
1012
0
    COMMON_DEFINITIONS;
1013
0
1014
0
    CK_ULONG i;
1015
0
    PR_LOG(modlog, 1, ("C_GetSlotList"));
1016
0
    PR_LOG(modlog, 3, ("  tokenPresent = 0x%x", tokenPresent));
1017
0
    PR_LOG(modlog, 3, ("  pSlotList = 0x%p", pSlotList));
1018
0
    PR_LOG(modlog, 3, (fmt_pulCount, pulCount));
1019
0
    nssdbg_start_time(FUNC_C_GETSLOTLIST, &start);
1020
0
    rv = module_functions->C_GetSlotList(tokenPresent, pSlotList, pulCount);
1021
0
    nssdbg_finish_time(FUNC_C_GETSLOTLIST, start);
1022
0
    PR_LOG(modlog, 4, (fmt_spulCount, *pulCount));
1023
0
    if (pSlotList) {
1024
0
        for (i = 0; i < *pulCount; i++) {
1025
0
            PR_LOG(modlog, 4, ("  slotID[%d] = %x", i, pSlotList[i]));
1026
0
        }
1027
0
    }
1028
0
    log_rv(rv);
1029
0
    return rv;
1030
0
}
1031
1032
CK_RV
1033
NSSDBGC_GetSlotInfo(
1034
    CK_SLOT_ID slotID,
1035
    CK_SLOT_INFO_PTR pInfo)
1036
0
{
1037
0
    COMMON_DEFINITIONS;
1038
0
1039
0
    PR_LOG(modlog, 1, ("C_GetSlotInfo"));
1040
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1041
0
    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1042
0
    nssdbg_start_time(FUNC_C_GETSLOTINFO, &start);
1043
0
    rv = module_functions->C_GetSlotInfo(slotID, pInfo);
1044
0
    nssdbg_finish_time(FUNC_C_GETSLOTINFO, start);
1045
0
    if (rv == CKR_OK) {
1046
0
        PR_LOG(modlog, 4, ("  slotDescription = \"%.64s\"",
1047
0
                           pInfo->slotDescription));
1048
0
        PR_LOG(modlog, 4, (fmt_manufacturerID, pInfo->manufacturerID));
1049
0
        PR_LOG(modlog, 4, ("  flags = %s %s %s",
1050
0
                           pInfo->flags & CKF_HW_SLOT ? "CKF_HW_SLOT" : "",
1051
0
                           pInfo->flags & CKF_REMOVABLE_DEVICE ? "CKF_REMOVABLE_DEVICE" : "",
1052
0
                           pInfo->flags & CKF_TOKEN_PRESENT ? "CKF_TOKEN_PRESENT" : ""));
1053
0
        PR_LOG(modlog, 4, (fmt_hwVersion,
1054
0
                           pInfo->hardwareVersion.major,
1055
0
                           pInfo->hardwareVersion.minor));
1056
0
        PR_LOG(modlog, 4, (fmt_fwVersion,
1057
0
                           pInfo->firmwareVersion.major,
1058
0
                           pInfo->firmwareVersion.minor));
1059
0
    }
1060
0
    log_rv(rv);
1061
0
    return rv;
1062
0
}
1063
1064
CK_RV
1065
NSSDBGC_GetTokenInfo(
1066
    CK_SLOT_ID slotID,
1067
    CK_TOKEN_INFO_PTR pInfo)
1068
0
{
1069
0
    COMMON_DEFINITIONS;
1070
0
1071
0
    PR_LOG(modlog, 1, ("C_GetTokenInfo"));
1072
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1073
0
    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1074
0
    nssdbg_start_time(FUNC_C_GETTOKENINFO, &start);
1075
0
    rv = module_functions->C_GetTokenInfo(slotID, pInfo);
1076
0
    nssdbg_finish_time(FUNC_C_GETTOKENINFO, start);
1077
0
    if (rv == CKR_OK) {
1078
0
        PR_LOG(modlog, 4, ("  label = \"%.32s\"", pInfo->label));
1079
0
        PR_LOG(modlog, 4, (fmt_manufacturerID, pInfo->manufacturerID));
1080
0
        PR_LOG(modlog, 4, ("  model = \"%.16s\"", pInfo->model));
1081
0
        PR_LOG(modlog, 4, ("  serial = \"%.16s\"", pInfo->serialNumber));
1082
0
        PR_LOG(modlog, 4, ("  flags = %s %s %s %s",
1083
0
                           pInfo->flags & CKF_RNG ? "CKF_RNG" : "",
1084
0
                           pInfo->flags & CKF_WRITE_PROTECTED ? "CKF_WRITE_PROTECTED" : "",
1085
0
                           pInfo->flags & CKF_LOGIN_REQUIRED ? "CKF_LOGIN_REQUIRED" : "",
1086
0
                           pInfo->flags & CKF_USER_PIN_INITIALIZED ? "CKF_USER_PIN_INIT" : ""));
1087
0
        PR_LOG(modlog, 4, ("  maxSessions = %u, Sessions = %u",
1088
0
                           pInfo->ulMaxSessionCount, pInfo->ulSessionCount));
1089
0
        PR_LOG(modlog, 4, ("  maxRwSessions = %u, RwSessions = %u",
1090
0
                           pInfo->ulMaxRwSessionCount,
1091
0
                           pInfo->ulRwSessionCount));
1092
0
        /* ignore Max & Min Pin Len, Public and Private Memory */
1093
0
        PR_LOG(modlog, 4, (fmt_hwVersion,
1094
0
                           pInfo->hardwareVersion.major,
1095
0
                           pInfo->hardwareVersion.minor));
1096
0
        PR_LOG(modlog, 4, (fmt_fwVersion,
1097
0
                           pInfo->firmwareVersion.major,
1098
0
                           pInfo->firmwareVersion.minor));
1099
0
    }
1100
0
    log_rv(rv);
1101
0
    return rv;
1102
0
}
1103
1104
CK_RV
1105
NSSDBGC_GetMechanismList(
1106
    CK_SLOT_ID slotID,
1107
    CK_MECHANISM_TYPE_PTR pMechanismList,
1108
    CK_ULONG_PTR pulCount)
1109
0
{
1110
0
    COMMON_DEFINITIONS;
1111
0
1112
0
    PR_LOG(modlog, 1, ("C_GetMechanismList"));
1113
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1114
0
    PR_LOG(modlog, 3, ("  pMechanismList = 0x%p", pMechanismList));
1115
0
    PR_LOG(modlog, 3, (fmt_pulCount, pulCount));
1116
0
    nssdbg_start_time(FUNC_C_GETMECHANISMLIST, &start);
1117
0
    rv = module_functions->C_GetMechanismList(slotID,
1118
0
                                              pMechanismList,
1119
0
                                              pulCount);
1120
0
    nssdbg_finish_time(FUNC_C_GETMECHANISMLIST, start);
1121
0
    PR_LOG(modlog, 4, (fmt_spulCount, *pulCount));
1122
0
    log_rv(rv);
1123
0
    return rv;
1124
0
}
1125
1126
CK_RV
1127
NSSDBGC_GetMechanismInfo(
1128
    CK_SLOT_ID slotID,
1129
    CK_MECHANISM_TYPE type,
1130
    CK_MECHANISM_INFO_PTR pInfo)
1131
0
{
1132
0
    COMMON_DEFINITIONS;
1133
0
1134
0
    PR_LOG(modlog, 1, ("C_GetMechanismInfo"));
1135
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1136
0
    PR_LOG(modlog, 3, ("  type = 0x%x", type));
1137
0
    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1138
0
    nssdbg_start_time(FUNC_C_GETMECHANISMINFO, &start);
1139
0
    rv = module_functions->C_GetMechanismInfo(slotID,
1140
0
                                              type,
1141
0
                                              pInfo);
1142
0
    nssdbg_finish_time(FUNC_C_GETMECHANISMINFO, start);
1143
0
    log_rv(rv);
1144
0
    return rv;
1145
0
}
1146
1147
CK_RV
1148
NSSDBGC_InitToken(
1149
    CK_SLOT_ID slotID,
1150
    CK_CHAR_PTR pPin,
1151
    CK_ULONG ulPinLen,
1152
    CK_CHAR_PTR pLabel)
1153
0
{
1154
0
    COMMON_DEFINITIONS;
1155
0
1156
0
    PR_LOG(modlog, 1, ("C_InitToken"));
1157
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1158
0
    PR_LOG(modlog, 3, (fmt_pPin, pPin));
1159
0
    PR_LOG(modlog, 3, (fmt_ulPinLen, ulPinLen));
1160
0
    PR_LOG(modlog, 3, ("  pLabel = 0x%p", pLabel));
1161
0
    nssdbg_start_time(FUNC_C_INITTOKEN, &start);
1162
0
    rv = module_functions->C_InitToken(slotID,
1163
0
                                       pPin,
1164
0
                                       ulPinLen,
1165
0
                                       pLabel);
1166
0
    nssdbg_finish_time(FUNC_C_INITTOKEN, start);
1167
0
    log_rv(rv);
1168
0
    return rv;
1169
0
}
1170
1171
CK_RV
1172
NSSDBGC_InitPIN(
1173
    CK_SESSION_HANDLE hSession,
1174
    CK_CHAR_PTR pPin,
1175
    CK_ULONG ulPinLen)
1176
0
{
1177
0
    COMMON_DEFINITIONS;
1178
0
1179
0
    PR_LOG(modlog, 1, ("C_InitPIN"));
1180
0
    log_handle(3, fmt_hSession, hSession);
1181
0
    PR_LOG(modlog, 3, (fmt_pPin, pPin));
1182
0
    PR_LOG(modlog, 3, (fmt_ulPinLen, ulPinLen));
1183
0
    nssdbg_start_time(FUNC_C_INITPIN, &start);
1184
0
    rv = module_functions->C_InitPIN(hSession,
1185
0
                                     pPin,
1186
0
                                     ulPinLen);
1187
0
    nssdbg_finish_time(FUNC_C_INITPIN, start);
1188
0
    log_rv(rv);
1189
0
    return rv;
1190
0
}
1191
1192
CK_RV
1193
NSSDBGC_SetPIN(
1194
    CK_SESSION_HANDLE hSession,
1195
    CK_CHAR_PTR pOldPin,
1196
    CK_ULONG ulOldLen,
1197
    CK_CHAR_PTR pNewPin,
1198
    CK_ULONG ulNewLen)
1199
0
{
1200
0
    COMMON_DEFINITIONS;
1201
0
1202
0
    PR_LOG(modlog, 1, ("C_SetPIN"));
1203
0
    log_handle(3, fmt_hSession, hSession);
1204
0
    PR_LOG(modlog, 3, ("  pOldPin = 0x%p", pOldPin));
1205
0
    PR_LOG(modlog, 3, ("  ulOldLen = %d", ulOldLen));
1206
0
    PR_LOG(modlog, 3, ("  pNewPin = 0x%p", pNewPin));
1207
0
    PR_LOG(modlog, 3, ("  ulNewLen = %d", ulNewLen));
1208
0
    nssdbg_start_time(FUNC_C_SETPIN, &start);
1209
0
    rv = module_functions->C_SetPIN(hSession,
1210
0
                                    pOldPin,
1211
0
                                    ulOldLen,
1212
0
                                    pNewPin,
1213
0
                                    ulNewLen);
1214
0
    nssdbg_finish_time(FUNC_C_SETPIN, start);
1215
0
    log_rv(rv);
1216
0
    return rv;
1217
0
}
1218
1219
static PRUint32 numOpenSessions = 0;
1220
static PRUint32 maxOpenSessions = 0;
1221
1222
CK_RV
1223
NSSDBGC_OpenSession(
1224
    CK_SLOT_ID slotID,
1225
    CK_FLAGS flags,
1226
    CK_VOID_PTR pApplication,
1227
    CK_NOTIFY Notify,
1228
    CK_SESSION_HANDLE_PTR phSession)
1229
0
{
1230
0
    COMMON_DEFINITIONS;
1231
0
1232
0
    PR_ATOMIC_INCREMENT((PRInt32 *)&numOpenSessions);
1233
0
    maxOpenSessions = PR_MAX(numOpenSessions, maxOpenSessions);
1234
0
    PR_LOG(modlog, 1, ("C_OpenSession"));
1235
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1236
0
    PR_LOG(modlog, 3, (fmt_flags, flags));
1237
0
    PR_LOG(modlog, 3, ("  pApplication = 0x%p", pApplication));
1238
0
    PR_LOG(modlog, 3, ("  Notify = 0x%x", Notify));
1239
0
    PR_LOG(modlog, 3, ("  phSession = 0x%p", phSession));
1240
0
    nssdbg_start_time(FUNC_C_OPENSESSION, &start);
1241
0
    rv = module_functions->C_OpenSession(slotID,
1242
0
                                         flags,
1243
0
                                         pApplication,
1244
0
                                         Notify,
1245
0
                                         phSession);
1246
0
    nssdbg_finish_time(FUNC_C_OPENSESSION, start);
1247
0
    log_handle(4, "  *phSession = 0x%x", *phSession);
1248
0
    log_rv(rv);
1249
0
    return rv;
1250
0
}
1251
1252
CK_RV
1253
NSSDBGC_CloseSession(
1254
    CK_SESSION_HANDLE hSession)
1255
0
{
1256
0
    COMMON_DEFINITIONS;
1257
0
1258
0
    PR_ATOMIC_DECREMENT((PRInt32 *)&numOpenSessions);
1259
0
    PR_LOG(modlog, 1, ("C_CloseSession"));
1260
0
    log_handle(3, fmt_hSession, hSession);
1261
0
    nssdbg_start_time(FUNC_C_CLOSESESSION, &start);
1262
0
    rv = module_functions->C_CloseSession(hSession);
1263
0
    nssdbg_finish_time(FUNC_C_CLOSESESSION, start);
1264
0
    log_rv(rv);
1265
0
    return rv;
1266
0
}
1267
1268
CK_RV
1269
NSSDBGC_CloseAllSessions(
1270
    CK_SLOT_ID slotID)
1271
0
{
1272
0
    COMMON_DEFINITIONS;
1273
0
1274
0
    PR_LOG(modlog, 1, ("C_CloseAllSessions"));
1275
0
    PR_LOG(modlog, 3, (fmt_slotID, slotID));
1276
0
    nssdbg_start_time(FUNC_C_CLOSEALLSESSIONS, &start);
1277
0
    rv = module_functions->C_CloseAllSessions(slotID);
1278
0
    nssdbg_finish_time(FUNC_C_CLOSEALLSESSIONS, start);
1279
0
    log_rv(rv);
1280
0
    return rv;
1281
0
}
1282
1283
CK_RV
1284
NSSDBGC_GetSessionInfo(
1285
    CK_SESSION_HANDLE hSession,
1286
    CK_SESSION_INFO_PTR pInfo)
1287
0
{
1288
0
    COMMON_DEFINITIONS;
1289
0
1290
0
    PR_LOG(modlog, 1, ("C_GetSessionInfo"));
1291
0
    log_handle(3, fmt_hSession, hSession);
1292
0
    PR_LOG(modlog, 3, (fmt_pInfo, pInfo));
1293
0
    nssdbg_start_time(FUNC_C_GETSESSIONINFO, &start);
1294
0
    rv = module_functions->C_GetSessionInfo(hSession,
1295
0
                                            pInfo);
1296
0
    nssdbg_finish_time(FUNC_C_GETSESSIONINFO, start);
1297
0
    if (rv == CKR_OK) {
1298
0
        PR_LOG(modlog, 4, (fmt_slotID, pInfo->slotID));
1299
0
        log_state(pInfo->state);
1300
0
        PR_LOG(modlog, 4, ("  flags = %s %s",
1301
0
                           pInfo->flags & CKF_RW_SESSION ? "CKF_RW_SESSION" : "",
1302
0
                           pInfo->flags & CKF_SERIAL_SESSION ? "CKF_SERIAL_SESSION" : ""));
1303
0
        PR_LOG(modlog, 4, ("  deviceError = 0x%x", pInfo->ulDeviceError));
1304
0
    }
1305
0
    log_rv(rv);
1306
0
    return rv;
1307
0
}
1308
1309
CK_RV
1310
NSSDBGC_GetOperationState(
1311
    CK_SESSION_HANDLE hSession,
1312
    CK_BYTE_PTR pOperationState,
1313
    CK_ULONG_PTR pulOperationStateLen)
1314
0
{
1315
0
    COMMON_DEFINITIONS;
1316
0
1317
0
    PR_LOG(modlog, 1, ("C_GetOperationState"));
1318
0
    log_handle(3, fmt_hSession, hSession);
1319
0
    PR_LOG(modlog, 3, (fmt_pOperationState, pOperationState));
1320
0
    PR_LOG(modlog, 3, ("  pulOperationStateLen = 0x%p", pulOperationStateLen));
1321
0
    nssdbg_start_time(FUNC_C_GETOPERATIONSTATE, &start);
1322
0
    rv = module_functions->C_GetOperationState(hSession,
1323
0
                                               pOperationState,
1324
0
                                               pulOperationStateLen);
1325
0
    nssdbg_finish_time(FUNC_C_GETOPERATIONSTATE, start);
1326
0
    PR_LOG(modlog, 4, ("  *pulOperationStateLen = 0x%x", *pulOperationStateLen));
1327
0
    log_rv(rv);
1328
0
    return rv;
1329
0
}
1330
1331
CK_RV
1332
NSSDBGC_SetOperationState(
1333
    CK_SESSION_HANDLE hSession,
1334
    CK_BYTE_PTR pOperationState,
1335
    CK_ULONG ulOperationStateLen,
1336
    CK_OBJECT_HANDLE hEncryptionKey,
1337
    CK_OBJECT_HANDLE hAuthenticationKey)
1338
0
{
1339
0
    COMMON_DEFINITIONS;
1340
0
1341
0
    PR_LOG(modlog, 1, ("C_SetOperationState"));
1342
0
    log_handle(3, fmt_hSession, hSession);
1343
0
    PR_LOG(modlog, 3, (fmt_pOperationState, pOperationState));
1344
0
    PR_LOG(modlog, 3, ("  ulOperationStateLen = %d", ulOperationStateLen));
1345
0
    log_handle(3, "  hEncryptionKey = 0x%x", hEncryptionKey);
1346
0
    log_handle(3, "  hAuthenticationKey = 0x%x", hAuthenticationKey);
1347
0
    nssdbg_start_time(FUNC_C_SETOPERATIONSTATE, &start);
1348
0
    rv = module_functions->C_SetOperationState(hSession,
1349
0
                                               pOperationState,
1350
0
                                               ulOperationStateLen,
1351
0
                                               hEncryptionKey,
1352
0
                                               hAuthenticationKey);
1353
0
    nssdbg_finish_time(FUNC_C_SETOPERATIONSTATE, start);
1354
0
    log_rv(rv);
1355
0
    return rv;
1356
0
}
1357
1358
CK_RV
1359
NSSDBGC_Login(
1360
    CK_SESSION_HANDLE hSession,
1361
    CK_USER_TYPE userType,
1362
    CK_CHAR_PTR pPin,
1363
    CK_ULONG ulPinLen)
1364
0
{
1365
0
    COMMON_DEFINITIONS;
1366
0
1367
0
    PR_LOG(modlog, 1, ("C_Login"));
1368
0
    log_handle(3, fmt_hSession, hSession);
1369
0
    PR_LOG(modlog, 3, ("  userType = 0x%x", userType));
1370
0
    PR_LOG(modlog, 3, (fmt_pPin, pPin));
1371
0
    PR_LOG(modlog, 3, (fmt_ulPinLen, ulPinLen));
1372
0
    nssdbg_start_time(FUNC_C_LOGIN, &start);
1373
0
    rv = module_functions->C_Login(hSession,
1374
0
                                   userType,
1375
0
                                   pPin,
1376
0
                                   ulPinLen);
1377
0
    nssdbg_finish_time(FUNC_C_LOGIN, start);
1378
0
    log_rv(rv);
1379
0
    return rv;
1380
0
}
1381
1382
CK_RV
1383
NSSDBGC_Logout(
1384
    CK_SESSION_HANDLE hSession)
1385
0
{
1386
0
    COMMON_DEFINITIONS;
1387
0
1388
0
    PR_LOG(modlog, 1, ("C_Logout"));
1389
0
    log_handle(3, fmt_hSession, hSession);
1390
0
    nssdbg_start_time(FUNC_C_LOGOUT, &start);
1391
0
    rv = module_functions->C_Logout(hSession);
1392
0
    nssdbg_finish_time(FUNC_C_LOGOUT, start);
1393
0
    log_rv(rv);
1394
0
    return rv;
1395
0
}
1396
1397
CK_RV
1398
NSSDBGC_CreateObject(
1399
    CK_SESSION_HANDLE hSession,
1400
    CK_ATTRIBUTE_PTR pTemplate,
1401
    CK_ULONG ulCount,
1402
    CK_OBJECT_HANDLE_PTR phObject)
1403
0
{
1404
0
    COMMON_DEFINITIONS;
1405
0
1406
0
    PR_LOG(modlog, 1, ("C_CreateObject"));
1407
0
    log_handle(3, fmt_hSession, hSession);
1408
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1409
0
    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1410
0
    PR_LOG(modlog, 3, (fmt_phObject, phObject));
1411
0
    print_template(pTemplate, ulCount);
1412
0
    nssdbg_start_time(FUNC_C_CREATEOBJECT, &start);
1413
0
    rv = module_functions->C_CreateObject(hSession,
1414
0
                                          pTemplate,
1415
0
                                          ulCount,
1416
0
                                          phObject);
1417
0
    nssdbg_finish_time(FUNC_C_CREATEOBJECT, start);
1418
0
    log_handle(4, "  *phObject = 0x%x", *phObject);
1419
0
    log_rv(rv);
1420
0
    return rv;
1421
0
}
1422
1423
CK_RV
1424
NSSDBGC_CopyObject(
1425
    CK_SESSION_HANDLE hSession,
1426
    CK_OBJECT_HANDLE hObject,
1427
    CK_ATTRIBUTE_PTR pTemplate,
1428
    CK_ULONG ulCount,
1429
    CK_OBJECT_HANDLE_PTR phNewObject)
1430
0
{
1431
0
    COMMON_DEFINITIONS;
1432
0
1433
0
    PR_LOG(modlog, 1, ("C_CopyObject"));
1434
0
    log_handle(3, fmt_hSession, hSession);
1435
0
    log_handle(3, fmt_hObject, hObject);
1436
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1437
0
    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1438
0
    PR_LOG(modlog, 3, ("  phNewObject = 0x%p", phNewObject));
1439
0
    print_template(pTemplate, ulCount);
1440
0
    nssdbg_start_time(FUNC_C_COPYOBJECT, &start);
1441
0
    rv = module_functions->C_CopyObject(hSession,
1442
0
                                        hObject,
1443
0
                                        pTemplate,
1444
0
                                        ulCount,
1445
0
                                        phNewObject);
1446
0
    nssdbg_finish_time(FUNC_C_COPYOBJECT, start);
1447
0
    log_handle(4, "  *phNewObject = 0x%x", *phNewObject);
1448
0
    log_rv(rv);
1449
0
    return rv;
1450
0
}
1451
1452
CK_RV
1453
NSSDBGC_DestroyObject(
1454
    CK_SESSION_HANDLE hSession,
1455
    CK_OBJECT_HANDLE hObject)
1456
0
{
1457
0
    COMMON_DEFINITIONS;
1458
0
1459
0
    PR_LOG(modlog, 1, ("C_DestroyObject"));
1460
0
    log_handle(3, fmt_hSession, hSession);
1461
0
    log_handle(3, fmt_hObject, hObject);
1462
0
    nssdbg_start_time(FUNC_C_DESTROYOBJECT, &start);
1463
0
    rv = module_functions->C_DestroyObject(hSession,
1464
0
                                           hObject);
1465
0
    nssdbg_finish_time(FUNC_C_DESTROYOBJECT, start);
1466
0
    log_rv(rv);
1467
0
    return rv;
1468
0
}
1469
1470
CK_RV
1471
NSSDBGC_GetObjectSize(
1472
    CK_SESSION_HANDLE hSession,
1473
    CK_OBJECT_HANDLE hObject,
1474
    CK_ULONG_PTR pulSize)
1475
0
{
1476
0
    COMMON_DEFINITIONS;
1477
0
1478
0
    PR_LOG(modlog, 1, ("C_GetObjectSize"));
1479
0
    log_handle(3, fmt_hSession, hSession);
1480
0
    log_handle(3, fmt_hObject, hObject);
1481
0
    PR_LOG(modlog, 3, ("  pulSize = 0x%p", pulSize));
1482
0
    nssdbg_start_time(FUNC_C_GETOBJECTSIZE, &start);
1483
0
    rv = module_functions->C_GetObjectSize(hSession,
1484
0
                                           hObject,
1485
0
                                           pulSize);
1486
0
    nssdbg_finish_time(FUNC_C_GETOBJECTSIZE, start);
1487
0
    PR_LOG(modlog, 4, ("  *pulSize = 0x%x", *pulSize));
1488
0
    log_rv(rv);
1489
0
    return rv;
1490
0
}
1491
1492
CK_RV
1493
NSSDBGC_GetAttributeValue(
1494
    CK_SESSION_HANDLE hSession,
1495
    CK_OBJECT_HANDLE hObject,
1496
    CK_ATTRIBUTE_PTR pTemplate,
1497
    CK_ULONG ulCount)
1498
0
{
1499
0
    COMMON_DEFINITIONS;
1500
0
1501
0
    PR_LOG(modlog, 1, ("C_GetAttributeValue"));
1502
0
    log_handle(3, fmt_hSession, hSession);
1503
0
    log_handle(3, fmt_hObject, hObject);
1504
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1505
0
    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1506
0
    nssdbg_start_time(FUNC_C_GETATTRIBUTEVALUE, &start);
1507
0
    rv = module_functions->C_GetAttributeValue(hSession,
1508
0
                                               hObject,
1509
0
                                               pTemplate,
1510
0
                                               ulCount);
1511
0
    nssdbg_finish_time(FUNC_C_GETATTRIBUTEVALUE, start);
1512
0
    print_template(pTemplate, ulCount);
1513
0
    log_rv(rv);
1514
0
    return rv;
1515
0
}
1516
1517
CK_RV
1518
NSSDBGC_SetAttributeValue(
1519
    CK_SESSION_HANDLE hSession,
1520
    CK_OBJECT_HANDLE hObject,
1521
    CK_ATTRIBUTE_PTR pTemplate,
1522
    CK_ULONG ulCount)
1523
0
{
1524
0
    COMMON_DEFINITIONS;
1525
0
1526
0
    PR_LOG(modlog, 1, ("C_SetAttributeValue"));
1527
0
    log_handle(3, fmt_hSession, hSession);
1528
0
    log_handle(3, fmt_hObject, hObject);
1529
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1530
0
    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1531
0
    print_template(pTemplate, ulCount);
1532
0
    nssdbg_start_time(FUNC_C_SETATTRIBUTEVALUE, &start);
1533
0
    rv = module_functions->C_SetAttributeValue(hSession,
1534
0
                                               hObject,
1535
0
                                               pTemplate,
1536
0
                                               ulCount);
1537
0
    nssdbg_finish_time(FUNC_C_SETATTRIBUTEVALUE, start);
1538
0
    log_rv(rv);
1539
0
    return rv;
1540
0
}
1541
1542
CK_RV
1543
NSSDBGC_FindObjectsInit(
1544
    CK_SESSION_HANDLE hSession,
1545
    CK_ATTRIBUTE_PTR pTemplate,
1546
    CK_ULONG ulCount)
1547
0
{
1548
0
    COMMON_DEFINITIONS;
1549
0
1550
0
    PR_LOG(modlog, 1, ("C_FindObjectsInit"));
1551
0
    log_handle(3, fmt_hSession, hSession);
1552
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
1553
0
    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
1554
0
    print_template(pTemplate, ulCount);
1555
0
    nssdbg_start_time(FUNC_C_FINDOBJECTSINIT, &start);
1556
0
    rv = module_functions->C_FindObjectsInit(hSession,
1557
0
                                             pTemplate,
1558
0
                                             ulCount);
1559
0
    nssdbg_finish_time(FUNC_C_FINDOBJECTSINIT, start);
1560
0
    log_rv(rv);
1561
0
    return rv;
1562
0
}
1563
1564
CK_RV
1565
NSSDBGC_FindObjects(
1566
    CK_SESSION_HANDLE hSession,
1567
    CK_OBJECT_HANDLE_PTR phObject,
1568
    CK_ULONG ulMaxObjectCount,
1569
    CK_ULONG_PTR pulObjectCount)
1570
0
{
1571
0
    COMMON_DEFINITIONS;
1572
0
    CK_ULONG i;
1573
0
1574
0
    PR_LOG(modlog, 1, ("C_FindObjects"));
1575
0
    log_handle(3, fmt_hSession, hSession);
1576
0
    PR_LOG(modlog, 3, (fmt_phObject, phObject));
1577
0
    PR_LOG(modlog, 3, ("  ulMaxObjectCount = %d", ulMaxObjectCount));
1578
0
    PR_LOG(modlog, 3, ("  pulObjectCount = 0x%p", pulObjectCount));
1579
0
    nssdbg_start_time(FUNC_C_FINDOBJECTS, &start);
1580
0
    rv = module_functions->C_FindObjects(hSession,
1581
0
                                         phObject,
1582
0
                                         ulMaxObjectCount,
1583
0
                                         pulObjectCount);
1584
0
    nssdbg_finish_time(FUNC_C_FINDOBJECTS, start);
1585
0
    PR_LOG(modlog, 4, ("  *pulObjectCount = 0x%x", *pulObjectCount));
1586
0
    for (i = 0; i < *pulObjectCount; i++) {
1587
0
        PR_LOG(modlog, 4, ("  phObject[%d] = 0x%x%s", i, phObject[i],
1588
0
                           phObject[i] ? "" : fmt_invalid_handle));
1589
0
    }
1590
0
    log_rv(rv);
1591
0
    return rv;
1592
0
}
1593
1594
CK_RV
1595
NSSDBGC_FindObjectsFinal(
1596
    CK_SESSION_HANDLE hSession)
1597
0
{
1598
0
    COMMON_DEFINITIONS;
1599
0
1600
0
    PR_LOG(modlog, 1, ("C_FindObjectsFinal"));
1601
0
    log_handle(3, fmt_hSession, hSession);
1602
0
    nssdbg_start_time(FUNC_C_FINDOBJECTSFINAL, &start);
1603
0
    rv = module_functions->C_FindObjectsFinal(hSession);
1604
0
    nssdbg_finish_time(FUNC_C_FINDOBJECTSFINAL, start);
1605
0
    log_rv(rv);
1606
0
    return rv;
1607
0
}
1608
1609
CK_RV
1610
NSSDBGC_EncryptInit(
1611
    CK_SESSION_HANDLE hSession,
1612
    CK_MECHANISM_PTR pMechanism,
1613
    CK_OBJECT_HANDLE hKey)
1614
0
{
1615
0
    COMMON_DEFINITIONS;
1616
0
1617
0
    PR_LOG(modlog, 1, ("C_EncryptInit"));
1618
0
    log_handle(3, fmt_hSession, hSession);
1619
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
1620
0
    log_handle(3, fmt_hKey, hKey);
1621
0
    print_mechanism(pMechanism);
1622
0
    nssdbg_start_time(FUNC_C_ENCRYPTINIT, &start);
1623
0
    rv = module_functions->C_EncryptInit(hSession,
1624
0
                                         pMechanism,
1625
0
                                         hKey);
1626
0
    nssdbg_finish_time(FUNC_C_ENCRYPTINIT, start);
1627
0
    log_rv(rv);
1628
0
    return rv;
1629
0
}
1630
1631
CK_RV
1632
NSSDBGC_Encrypt(
1633
    CK_SESSION_HANDLE hSession,
1634
    CK_BYTE_PTR pData,
1635
    CK_ULONG ulDataLen,
1636
    CK_BYTE_PTR pEncryptedData,
1637
    CK_ULONG_PTR pulEncryptedDataLen)
1638
0
{
1639
0
    COMMON_DEFINITIONS;
1640
0
1641
0
    PR_LOG(modlog, 1, ("C_Encrypt"));
1642
0
    log_handle(3, fmt_hSession, hSession);
1643
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
1644
0
    PR_LOG(modlog, 3, (fmt_ulDataLen, ulDataLen));
1645
0
    PR_LOG(modlog, 3, (fmt_pEncryptedData, pEncryptedData));
1646
0
    PR_LOG(modlog, 3, ("  pulEncryptedDataLen = 0x%p", pulEncryptedDataLen));
1647
0
    nssdbg_start_time(FUNC_C_ENCRYPT, &start);
1648
0
    rv = module_functions->C_Encrypt(hSession,
1649
0
                                     pData,
1650
0
                                     ulDataLen,
1651
0
                                     pEncryptedData,
1652
0
                                     pulEncryptedDataLen);
1653
0
    nssdbg_finish_time(FUNC_C_ENCRYPT, start);
1654
0
    PR_LOG(modlog, 4, ("  *pulEncryptedDataLen = 0x%x", *pulEncryptedDataLen));
1655
0
    log_rv(rv);
1656
0
    return rv;
1657
0
}
1658
1659
CK_RV
1660
NSSDBGC_EncryptUpdate(
1661
    CK_SESSION_HANDLE hSession,
1662
    CK_BYTE_PTR pPart,
1663
    CK_ULONG ulPartLen,
1664
    CK_BYTE_PTR pEncryptedPart,
1665
    CK_ULONG_PTR pulEncryptedPartLen)
1666
0
{
1667
0
    COMMON_DEFINITIONS;
1668
0
1669
0
    PR_LOG(modlog, 1, ("C_EncryptUpdate"));
1670
0
    log_handle(3, fmt_hSession, hSession);
1671
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
1672
0
    PR_LOG(modlog, 3, (fmt_ulPartLen, ulPartLen));
1673
0
    PR_LOG(modlog, 3, (fmt_pEncryptedPart, pEncryptedPart));
1674
0
    PR_LOG(modlog, 3, (fmt_pulEncryptedPartLen, pulEncryptedPartLen));
1675
0
    nssdbg_start_time(FUNC_C_ENCRYPTUPDATE, &start);
1676
0
    rv = module_functions->C_EncryptUpdate(hSession,
1677
0
                                           pPart,
1678
0
                                           ulPartLen,
1679
0
                                           pEncryptedPart,
1680
0
                                           pulEncryptedPartLen);
1681
0
    nssdbg_finish_time(FUNC_C_ENCRYPTUPDATE, start);
1682
0
    PR_LOG(modlog, 4, (fmt_spulEncryptedPartLen, *pulEncryptedPartLen));
1683
0
    log_rv(rv);
1684
0
    return rv;
1685
0
}
1686
1687
CK_RV
1688
NSSDBGC_EncryptFinal(
1689
    CK_SESSION_HANDLE hSession,
1690
    CK_BYTE_PTR pLastEncryptedPart,
1691
    CK_ULONG_PTR pulLastEncryptedPartLen)
1692
0
{
1693
0
    COMMON_DEFINITIONS;
1694
0
1695
0
    PR_LOG(modlog, 1, ("C_EncryptFinal"));
1696
0
    log_handle(3, fmt_hSession, hSession);
1697
0
    PR_LOG(modlog, 3, ("  pLastEncryptedPart = 0x%p", pLastEncryptedPart));
1698
0
    PR_LOG(modlog, 3, ("  pulLastEncryptedPartLen = 0x%p", pulLastEncryptedPartLen));
1699
0
    nssdbg_start_time(FUNC_C_ENCRYPTFINAL, &start);
1700
0
    rv = module_functions->C_EncryptFinal(hSession,
1701
0
                                          pLastEncryptedPart,
1702
0
                                          pulLastEncryptedPartLen);
1703
0
    nssdbg_finish_time(FUNC_C_ENCRYPTFINAL, start);
1704
0
    PR_LOG(modlog, 4, ("  *pulLastEncryptedPartLen = 0x%x", *pulLastEncryptedPartLen));
1705
0
    log_rv(rv);
1706
0
    return rv;
1707
0
}
1708
1709
CK_RV
1710
NSSDBGC_DecryptInit(
1711
    CK_SESSION_HANDLE hSession,
1712
    CK_MECHANISM_PTR pMechanism,
1713
    CK_OBJECT_HANDLE hKey)
1714
0
{
1715
0
    COMMON_DEFINITIONS;
1716
0
1717
0
    PR_LOG(modlog, 1, ("C_DecryptInit"));
1718
0
    log_handle(3, fmt_hSession, hSession);
1719
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
1720
0
    log_handle(3, fmt_hKey, hKey);
1721
0
    print_mechanism(pMechanism);
1722
0
    nssdbg_start_time(FUNC_C_DECRYPTINIT, &start);
1723
0
    rv = module_functions->C_DecryptInit(hSession,
1724
0
                                         pMechanism,
1725
0
                                         hKey);
1726
0
    nssdbg_finish_time(FUNC_C_DECRYPTINIT, start);
1727
0
    log_rv(rv);
1728
0
    return rv;
1729
0
}
1730
1731
CK_RV
1732
NSSDBGC_Decrypt(
1733
    CK_SESSION_HANDLE hSession,
1734
    CK_BYTE_PTR pEncryptedData,
1735
    CK_ULONG ulEncryptedDataLen,
1736
    CK_BYTE_PTR pData,
1737
    CK_ULONG_PTR pulDataLen)
1738
0
{
1739
0
    COMMON_DEFINITIONS;
1740
0
1741
0
    PR_LOG(modlog, 1, ("C_Decrypt"));
1742
0
    log_handle(3, fmt_hSession, hSession);
1743
0
    PR_LOG(modlog, 3, (fmt_pEncryptedData, pEncryptedData));
1744
0
    PR_LOG(modlog, 3, ("  ulEncryptedDataLen = %d", ulEncryptedDataLen));
1745
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
1746
0
    PR_LOG(modlog, 3, (fmt_pulDataLen, pulDataLen));
1747
0
    nssdbg_start_time(FUNC_C_DECRYPT, &start);
1748
0
    rv = module_functions->C_Decrypt(hSession,
1749
0
                                     pEncryptedData,
1750
0
                                     ulEncryptedDataLen,
1751
0
                                     pData,
1752
0
                                     pulDataLen);
1753
0
    nssdbg_finish_time(FUNC_C_DECRYPT, start);
1754
0
    PR_LOG(modlog, 4, (fmt_spulDataLen, *pulDataLen));
1755
0
    log_rv(rv);
1756
0
    return rv;
1757
0
}
1758
1759
CK_RV
1760
NSSDBGC_DecryptUpdate(
1761
    CK_SESSION_HANDLE hSession,
1762
    CK_BYTE_PTR pEncryptedPart,
1763
    CK_ULONG ulEncryptedPartLen,
1764
    CK_BYTE_PTR pPart,
1765
    CK_ULONG_PTR pulPartLen)
1766
0
{
1767
0
    COMMON_DEFINITIONS;
1768
0
1769
0
    PR_LOG(modlog, 1, ("C_DecryptUpdate"));
1770
0
    log_handle(3, fmt_hSession, hSession);
1771
0
    PR_LOG(modlog, 3, (fmt_pEncryptedPart, pEncryptedPart));
1772
0
    PR_LOG(modlog, 3, (fmt_ulEncryptedPartLen, ulEncryptedPartLen));
1773
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
1774
0
    PR_LOG(modlog, 3, (fmt_pulPartLen, pulPartLen));
1775
0
    nssdbg_start_time(FUNC_C_DECRYPTUPDATE, &start);
1776
0
    rv = module_functions->C_DecryptUpdate(hSession,
1777
0
                                           pEncryptedPart,
1778
0
                                           ulEncryptedPartLen,
1779
0
                                           pPart,
1780
0
                                           pulPartLen);
1781
0
    nssdbg_finish_time(FUNC_C_DECRYPTUPDATE, start);
1782
0
    PR_LOG(modlog, 4, (fmt_spulPartLen, *pulPartLen));
1783
0
    log_rv(rv);
1784
0
    return rv;
1785
0
}
1786
1787
CK_RV
1788
NSSDBGC_DecryptFinal(
1789
    CK_SESSION_HANDLE hSession,
1790
    CK_BYTE_PTR pLastPart,
1791
    CK_ULONG_PTR pulLastPartLen)
1792
0
{
1793
0
    COMMON_DEFINITIONS;
1794
0
1795
0
    PR_LOG(modlog, 1, ("C_DecryptFinal"));
1796
0
    log_handle(3, fmt_hSession, hSession);
1797
0
    PR_LOG(modlog, 3, ("  pLastPart = 0x%p", pLastPart));
1798
0
    PR_LOG(modlog, 3, ("  pulLastPartLen = 0x%p", pulLastPartLen));
1799
0
    nssdbg_start_time(FUNC_C_DECRYPTFINAL, &start);
1800
0
    rv = module_functions->C_DecryptFinal(hSession,
1801
0
                                          pLastPart,
1802
0
                                          pulLastPartLen);
1803
0
    nssdbg_finish_time(FUNC_C_DECRYPTFINAL, start);
1804
0
    PR_LOG(modlog, 4, ("  *pulLastPartLen = 0x%x", *pulLastPartLen));
1805
0
    log_rv(rv);
1806
0
    return rv;
1807
0
}
1808
1809
CK_RV
1810
NSSDBGC_DigestInit(
1811
    CK_SESSION_HANDLE hSession,
1812
    CK_MECHANISM_PTR pMechanism)
1813
0
{
1814
0
    COMMON_DEFINITIONS;
1815
0
1816
0
    PR_LOG(modlog, 1, ("C_DigestInit"));
1817
0
    log_handle(3, fmt_hSession, hSession);
1818
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
1819
0
    print_mechanism(pMechanism);
1820
0
    nssdbg_start_time(FUNC_C_DIGESTINIT, &start);
1821
0
    rv = module_functions->C_DigestInit(hSession,
1822
0
                                        pMechanism);
1823
0
    nssdbg_finish_time(FUNC_C_DIGESTINIT, start);
1824
0
    log_rv(rv);
1825
0
    return rv;
1826
0
}
1827
1828
CK_RV
1829
NSSDBGC_Digest(
1830
    CK_SESSION_HANDLE hSession,
1831
    CK_BYTE_PTR pData,
1832
    CK_ULONG ulDataLen,
1833
    CK_BYTE_PTR pDigest,
1834
    CK_ULONG_PTR pulDigestLen)
1835
0
{
1836
0
    COMMON_DEFINITIONS;
1837
0
1838
0
    PR_LOG(modlog, 1, ("C_Digest"));
1839
0
    log_handle(3, fmt_hSession, hSession);
1840
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
1841
0
    PR_LOG(modlog, 3, (fmt_ulDataLen, ulDataLen));
1842
0
    PR_LOG(modlog, 3, (fmt_pDigest, pDigest));
1843
0
    PR_LOG(modlog, 3, (fmt_pulDigestLen, pulDigestLen));
1844
0
    nssdbg_start_time(FUNC_C_DIGEST, &start);
1845
0
    rv = module_functions->C_Digest(hSession,
1846
0
                                    pData,
1847
0
                                    ulDataLen,
1848
0
                                    pDigest,
1849
0
                                    pulDigestLen);
1850
0
    nssdbg_finish_time(FUNC_C_DIGEST, start);
1851
0
    PR_LOG(modlog, 4, (fmt_spulDigestLen, *pulDigestLen));
1852
0
    log_rv(rv);
1853
0
    return rv;
1854
0
}
1855
1856
CK_RV
1857
NSSDBGC_DigestUpdate(
1858
    CK_SESSION_HANDLE hSession,
1859
    CK_BYTE_PTR pPart,
1860
    CK_ULONG ulPartLen)
1861
0
{
1862
0
    COMMON_DEFINITIONS;
1863
0
1864
0
    PR_LOG(modlog, 1, ("C_DigestUpdate"));
1865
0
    log_handle(3, fmt_hSession, hSession);
1866
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
1867
0
    PR_LOG(modlog, 3, (fmt_ulPartLen, ulPartLen));
1868
0
    nssdbg_start_time(FUNC_C_DIGESTUPDATE, &start);
1869
0
    rv = module_functions->C_DigestUpdate(hSession,
1870
0
                                          pPart,
1871
0
                                          ulPartLen);
1872
0
    nssdbg_finish_time(FUNC_C_DIGESTUPDATE, start);
1873
0
    log_rv(rv);
1874
0
    return rv;
1875
0
}
1876
1877
CK_RV
1878
NSSDBGC_DigestKey(
1879
    CK_SESSION_HANDLE hSession,
1880
    CK_OBJECT_HANDLE hKey)
1881
0
{
1882
0
    COMMON_DEFINITIONS;
1883
0
1884
0
    PR_LOG(modlog, 1, ("C_DigestKey"));
1885
0
    log_handle(3, fmt_hSession, hSession);
1886
0
    nssdbg_start_time(FUNC_C_DIGESTKEY, &start);
1887
0
    rv = module_functions->C_DigestKey(hSession,
1888
0
                                       hKey);
1889
0
    nssdbg_finish_time(FUNC_C_DIGESTKEY, start);
1890
0
    log_rv(rv);
1891
0
    return rv;
1892
0
}
1893
1894
CK_RV
1895
NSSDBGC_DigestFinal(
1896
    CK_SESSION_HANDLE hSession,
1897
    CK_BYTE_PTR pDigest,
1898
    CK_ULONG_PTR pulDigestLen)
1899
0
{
1900
0
    COMMON_DEFINITIONS;
1901
0
1902
0
    PR_LOG(modlog, 1, ("C_DigestFinal"));
1903
0
    log_handle(3, fmt_hSession, hSession);
1904
0
    PR_LOG(modlog, 3, (fmt_pDigest, pDigest));
1905
0
    PR_LOG(modlog, 3, (fmt_pulDigestLen, pulDigestLen));
1906
0
    nssdbg_start_time(FUNC_C_DIGESTFINAL, &start);
1907
0
    rv = module_functions->C_DigestFinal(hSession,
1908
0
                                         pDigest,
1909
0
                                         pulDigestLen);
1910
0
    nssdbg_finish_time(FUNC_C_DIGESTFINAL, start);
1911
0
    PR_LOG(modlog, 4, (fmt_spulDigestLen, *pulDigestLen));
1912
0
    log_rv(rv);
1913
0
    return rv;
1914
0
}
1915
1916
CK_RV
1917
NSSDBGC_SignInit(
1918
    CK_SESSION_HANDLE hSession,
1919
    CK_MECHANISM_PTR pMechanism,
1920
    CK_OBJECT_HANDLE hKey)
1921
0
{
1922
0
    COMMON_DEFINITIONS;
1923
0
1924
0
    PR_LOG(modlog, 1, ("C_SignInit"));
1925
0
    log_handle(3, fmt_hSession, hSession);
1926
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
1927
0
    log_handle(3, fmt_hKey, hKey);
1928
0
    print_mechanism(pMechanism);
1929
0
    nssdbg_start_time(FUNC_C_SIGNINIT, &start);
1930
0
    rv = module_functions->C_SignInit(hSession,
1931
0
                                      pMechanism,
1932
0
                                      hKey);
1933
0
    nssdbg_finish_time(FUNC_C_SIGNINIT, start);
1934
0
    log_rv(rv);
1935
0
    return rv;
1936
0
}
1937
1938
CK_RV
1939
NSSDBGC_Sign(
1940
    CK_SESSION_HANDLE hSession,
1941
    CK_BYTE_PTR pData,
1942
    CK_ULONG ulDataLen,
1943
    CK_BYTE_PTR pSignature,
1944
    CK_ULONG_PTR pulSignatureLen)
1945
0
{
1946
0
    COMMON_DEFINITIONS;
1947
0
1948
0
    PR_LOG(modlog, 1, ("C_Sign"));
1949
0
    log_handle(3, fmt_hSession, hSession);
1950
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
1951
0
    PR_LOG(modlog, 3, (fmt_ulDataLen, ulDataLen));
1952
0
    PR_LOG(modlog, 3, (fmt_pSignature, pSignature));
1953
0
    PR_LOG(modlog, 3, (fmt_pulSignatureLen, pulSignatureLen));
1954
0
    nssdbg_start_time(FUNC_C_SIGN, &start);
1955
0
    rv = module_functions->C_Sign(hSession,
1956
0
                                  pData,
1957
0
                                  ulDataLen,
1958
0
                                  pSignature,
1959
0
                                  pulSignatureLen);
1960
0
    nssdbg_finish_time(FUNC_C_SIGN, start);
1961
0
    PR_LOG(modlog, 4, (fmt_spulSignatureLen, *pulSignatureLen));
1962
0
    log_rv(rv);
1963
0
    return rv;
1964
0
}
1965
1966
CK_RV
1967
NSSDBGC_SignUpdate(
1968
    CK_SESSION_HANDLE hSession,
1969
    CK_BYTE_PTR pPart,
1970
    CK_ULONG ulPartLen)
1971
0
{
1972
0
    COMMON_DEFINITIONS;
1973
0
1974
0
    PR_LOG(modlog, 1, ("C_SignUpdate"));
1975
0
    log_handle(3, fmt_hSession, hSession);
1976
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
1977
0
    PR_LOG(modlog, 3, (fmt_ulPartLen, ulPartLen));
1978
0
    nssdbg_start_time(FUNC_C_SIGNUPDATE, &start);
1979
0
    rv = module_functions->C_SignUpdate(hSession,
1980
0
                                        pPart,
1981
0
                                        ulPartLen);
1982
0
    nssdbg_finish_time(FUNC_C_SIGNUPDATE, start);
1983
0
    log_rv(rv);
1984
0
    return rv;
1985
0
}
1986
1987
CK_RV
1988
NSSDBGC_SignFinal(
1989
    CK_SESSION_HANDLE hSession,
1990
    CK_BYTE_PTR pSignature,
1991
    CK_ULONG_PTR pulSignatureLen)
1992
0
{
1993
0
    COMMON_DEFINITIONS;
1994
0
1995
0
    PR_LOG(modlog, 1, ("C_SignFinal"));
1996
0
    log_handle(3, fmt_hSession, hSession);
1997
0
    PR_LOG(modlog, 3, (fmt_pSignature, pSignature));
1998
0
    PR_LOG(modlog, 3, (fmt_pulSignatureLen, pulSignatureLen));
1999
0
    nssdbg_start_time(FUNC_C_SIGNFINAL, &start);
2000
0
    rv = module_functions->C_SignFinal(hSession,
2001
0
                                       pSignature,
2002
0
                                       pulSignatureLen);
2003
0
    nssdbg_finish_time(FUNC_C_SIGNFINAL, start);
2004
0
    PR_LOG(modlog, 4, (fmt_spulSignatureLen, *pulSignatureLen));
2005
0
    log_rv(rv);
2006
0
    return rv;
2007
0
}
2008
2009
CK_RV
2010
NSSDBGC_SignRecoverInit(
2011
    CK_SESSION_HANDLE hSession,
2012
    CK_MECHANISM_PTR pMechanism,
2013
    CK_OBJECT_HANDLE hKey)
2014
0
{
2015
0
    COMMON_DEFINITIONS;
2016
0
2017
0
    PR_LOG(modlog, 1, ("C_SignRecoverInit"));
2018
0
    log_handle(3, fmt_hSession, hSession);
2019
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2020
0
    log_handle(3, fmt_hKey, hKey);
2021
0
    print_mechanism(pMechanism);
2022
0
    nssdbg_start_time(FUNC_C_SIGNRECOVERINIT, &start);
2023
0
    rv = module_functions->C_SignRecoverInit(hSession,
2024
0
                                             pMechanism,
2025
0
                                             hKey);
2026
0
    nssdbg_finish_time(FUNC_C_SIGNRECOVERINIT, start);
2027
0
    log_rv(rv);
2028
0
    return rv;
2029
0
}
2030
2031
CK_RV
2032
NSSDBGC_SignRecover(
2033
    CK_SESSION_HANDLE hSession,
2034
    CK_BYTE_PTR pData,
2035
    CK_ULONG ulDataLen,
2036
    CK_BYTE_PTR pSignature,
2037
    CK_ULONG_PTR pulSignatureLen)
2038
0
{
2039
0
    COMMON_DEFINITIONS;
2040
0
2041
0
    PR_LOG(modlog, 1, ("C_SignRecover"));
2042
0
    log_handle(3, fmt_hSession, hSession);
2043
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
2044
0
    PR_LOG(modlog, 3, (fmt_ulDataLen, ulDataLen));
2045
0
    PR_LOG(modlog, 3, (fmt_pSignature, pSignature));
2046
0
    PR_LOG(modlog, 3, (fmt_pulSignatureLen, pulSignatureLen));
2047
0
    nssdbg_start_time(FUNC_C_SIGNRECOVER, &start);
2048
0
    rv = module_functions->C_SignRecover(hSession,
2049
0
                                         pData,
2050
0
                                         ulDataLen,
2051
0
                                         pSignature,
2052
0
                                         pulSignatureLen);
2053
0
    nssdbg_finish_time(FUNC_C_SIGNRECOVER, start);
2054
0
    PR_LOG(modlog, 4, (fmt_spulSignatureLen, *pulSignatureLen));
2055
0
    log_rv(rv);
2056
0
    return rv;
2057
0
}
2058
2059
CK_RV
2060
NSSDBGC_VerifyInit(
2061
    CK_SESSION_HANDLE hSession,
2062
    CK_MECHANISM_PTR pMechanism,
2063
    CK_OBJECT_HANDLE hKey)
2064
0
{
2065
0
    COMMON_DEFINITIONS;
2066
0
2067
0
    PR_LOG(modlog, 1, ("C_VerifyInit"));
2068
0
    log_handle(3, fmt_hSession, hSession);
2069
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2070
0
    log_handle(3, fmt_hKey, hKey);
2071
0
    print_mechanism(pMechanism);
2072
0
    nssdbg_start_time(FUNC_C_VERIFYINIT, &start);
2073
0
    rv = module_functions->C_VerifyInit(hSession,
2074
0
                                        pMechanism,
2075
0
                                        hKey);
2076
0
    nssdbg_finish_time(FUNC_C_VERIFYINIT, start);
2077
0
    log_rv(rv);
2078
0
    return rv;
2079
0
}
2080
2081
CK_RV
2082
NSSDBGC_Verify(
2083
    CK_SESSION_HANDLE hSession,
2084
    CK_BYTE_PTR pData,
2085
    CK_ULONG ulDataLen,
2086
    CK_BYTE_PTR pSignature,
2087
    CK_ULONG ulSignatureLen)
2088
0
{
2089
0
    COMMON_DEFINITIONS;
2090
0
2091
0
    PR_LOG(modlog, 1, ("C_Verify"));
2092
0
    log_handle(3, fmt_hSession, hSession);
2093
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
2094
0
    PR_LOG(modlog, 3, (fmt_ulDataLen, ulDataLen));
2095
0
    PR_LOG(modlog, 3, (fmt_pSignature, pSignature));
2096
0
    PR_LOG(modlog, 3, (fmt_ulSignatureLen, ulSignatureLen));
2097
0
    nssdbg_start_time(FUNC_C_VERIFY, &start);
2098
0
    rv = module_functions->C_Verify(hSession,
2099
0
                                    pData,
2100
0
                                    ulDataLen,
2101
0
                                    pSignature,
2102
0
                                    ulSignatureLen);
2103
0
    nssdbg_finish_time(FUNC_C_VERIFY, start);
2104
0
    log_rv(rv);
2105
0
    return rv;
2106
0
}
2107
2108
CK_RV
2109
NSSDBGC_VerifyUpdate(
2110
    CK_SESSION_HANDLE hSession,
2111
    CK_BYTE_PTR pPart,
2112
    CK_ULONG ulPartLen)
2113
0
{
2114
0
    COMMON_DEFINITIONS;
2115
0
2116
0
    PR_LOG(modlog, 1, ("C_VerifyUpdate"));
2117
0
    log_handle(3, fmt_hSession, hSession);
2118
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
2119
0
    PR_LOG(modlog, 3, (fmt_ulPartLen, ulPartLen));
2120
0
    nssdbg_start_time(FUNC_C_VERIFYUPDATE, &start);
2121
0
    rv = module_functions->C_VerifyUpdate(hSession,
2122
0
                                          pPart,
2123
0
                                          ulPartLen);
2124
0
    nssdbg_finish_time(FUNC_C_VERIFYUPDATE, start);
2125
0
    log_rv(rv);
2126
0
    return rv;
2127
0
}
2128
2129
CK_RV
2130
NSSDBGC_VerifyFinal(
2131
    CK_SESSION_HANDLE hSession,
2132
    CK_BYTE_PTR pSignature,
2133
    CK_ULONG ulSignatureLen)
2134
0
{
2135
0
    COMMON_DEFINITIONS;
2136
0
2137
0
    PR_LOG(modlog, 1, ("C_VerifyFinal"));
2138
0
    log_handle(3, fmt_hSession, hSession);
2139
0
    PR_LOG(modlog, 3, (fmt_pSignature, pSignature));
2140
0
    PR_LOG(modlog, 3, (fmt_ulSignatureLen, ulSignatureLen));
2141
0
    nssdbg_start_time(FUNC_C_VERIFYFINAL, &start);
2142
0
    rv = module_functions->C_VerifyFinal(hSession,
2143
0
                                         pSignature,
2144
0
                                         ulSignatureLen);
2145
0
    nssdbg_finish_time(FUNC_C_VERIFYFINAL, start);
2146
0
    log_rv(rv);
2147
0
    return rv;
2148
0
}
2149
2150
CK_RV
2151
NSSDBGC_VerifyRecoverInit(
2152
    CK_SESSION_HANDLE hSession,
2153
    CK_MECHANISM_PTR pMechanism,
2154
    CK_OBJECT_HANDLE hKey)
2155
0
{
2156
0
    COMMON_DEFINITIONS;
2157
0
2158
0
    PR_LOG(modlog, 1, ("C_VerifyRecoverInit"));
2159
0
    log_handle(3, fmt_hSession, hSession);
2160
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2161
0
    log_handle(3, fmt_hKey, hKey);
2162
0
    print_mechanism(pMechanism);
2163
0
    nssdbg_start_time(FUNC_C_VERIFYRECOVERINIT, &start);
2164
0
    rv = module_functions->C_VerifyRecoverInit(hSession,
2165
0
                                               pMechanism,
2166
0
                                               hKey);
2167
0
    nssdbg_finish_time(FUNC_C_VERIFYRECOVERINIT, start);
2168
0
    log_rv(rv);
2169
0
    return rv;
2170
0
}
2171
2172
CK_RV
2173
NSSDBGC_VerifyRecover(
2174
    CK_SESSION_HANDLE hSession,
2175
    CK_BYTE_PTR pSignature,
2176
    CK_ULONG ulSignatureLen,
2177
    CK_BYTE_PTR pData,
2178
    CK_ULONG_PTR pulDataLen)
2179
0
{
2180
0
    COMMON_DEFINITIONS;
2181
0
2182
0
    PR_LOG(modlog, 1, ("C_VerifyRecover"));
2183
0
    log_handle(3, fmt_hSession, hSession);
2184
0
    PR_LOG(modlog, 3, (fmt_pSignature, pSignature));
2185
0
    PR_LOG(modlog, 3, (fmt_ulSignatureLen, ulSignatureLen));
2186
0
    PR_LOG(modlog, 3, (fmt_pData, pData));
2187
0
    PR_LOG(modlog, 3, (fmt_pulDataLen, pulDataLen));
2188
0
    nssdbg_start_time(FUNC_C_VERIFYRECOVER, &start);
2189
0
    rv = module_functions->C_VerifyRecover(hSession,
2190
0
                                           pSignature,
2191
0
                                           ulSignatureLen,
2192
0
                                           pData,
2193
0
                                           pulDataLen);
2194
0
    nssdbg_finish_time(FUNC_C_VERIFYRECOVER, start);
2195
0
    PR_LOG(modlog, 4, (fmt_spulDataLen, *pulDataLen));
2196
0
    log_rv(rv);
2197
0
    return rv;
2198
0
}
2199
2200
CK_RV
2201
NSSDBGC_DigestEncryptUpdate(
2202
    CK_SESSION_HANDLE hSession,
2203
    CK_BYTE_PTR pPart,
2204
    CK_ULONG ulPartLen,
2205
    CK_BYTE_PTR pEncryptedPart,
2206
    CK_ULONG_PTR pulEncryptedPartLen)
2207
0
{
2208
0
    COMMON_DEFINITIONS;
2209
0
2210
0
    PR_LOG(modlog, 1, ("C_DigestEncryptUpdate"));
2211
0
    log_handle(3, fmt_hSession, hSession);
2212
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
2213
0
    PR_LOG(modlog, 3, (fmt_ulPartLen, ulPartLen));
2214
0
    PR_LOG(modlog, 3, (fmt_pEncryptedPart, pEncryptedPart));
2215
0
    PR_LOG(modlog, 3, (fmt_pulEncryptedPartLen, pulEncryptedPartLen));
2216
0
    nssdbg_start_time(FUNC_C_DIGESTENCRYPTUPDATE, &start);
2217
0
    rv = module_functions->C_DigestEncryptUpdate(hSession,
2218
0
                                                 pPart,
2219
0
                                                 ulPartLen,
2220
0
                                                 pEncryptedPart,
2221
0
                                                 pulEncryptedPartLen);
2222
0
    nssdbg_finish_time(FUNC_C_DIGESTENCRYPTUPDATE, start);
2223
0
    PR_LOG(modlog, 4, (fmt_spulEncryptedPartLen, *pulEncryptedPartLen));
2224
0
    log_rv(rv);
2225
0
    return rv;
2226
0
}
2227
2228
CK_RV
2229
NSSDBGC_DecryptDigestUpdate(
2230
    CK_SESSION_HANDLE hSession,
2231
    CK_BYTE_PTR pEncryptedPart,
2232
    CK_ULONG ulEncryptedPartLen,
2233
    CK_BYTE_PTR pPart,
2234
    CK_ULONG_PTR pulPartLen)
2235
0
{
2236
0
    COMMON_DEFINITIONS;
2237
0
2238
0
    PR_LOG(modlog, 1, ("C_DecryptDigestUpdate"));
2239
0
    log_handle(3, fmt_hSession, hSession);
2240
0
    PR_LOG(modlog, 3, (fmt_pEncryptedPart, pEncryptedPart));
2241
0
    PR_LOG(modlog, 3, (fmt_ulEncryptedPartLen, ulEncryptedPartLen));
2242
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
2243
0
    PR_LOG(modlog, 3, (fmt_pulPartLen, pulPartLen));
2244
0
    nssdbg_start_time(FUNC_C_DECRYPTDIGESTUPDATE, &start);
2245
0
    rv = module_functions->C_DecryptDigestUpdate(hSession,
2246
0
                                                 pEncryptedPart,
2247
0
                                                 ulEncryptedPartLen,
2248
0
                                                 pPart,
2249
0
                                                 pulPartLen);
2250
0
    nssdbg_finish_time(FUNC_C_DECRYPTDIGESTUPDATE, start);
2251
0
    PR_LOG(modlog, 4, (fmt_spulPartLen, *pulPartLen));
2252
0
    log_rv(rv);
2253
0
    return rv;
2254
0
}
2255
2256
CK_RV
2257
NSSDBGC_SignEncryptUpdate(
2258
    CK_SESSION_HANDLE hSession,
2259
    CK_BYTE_PTR pPart,
2260
    CK_ULONG ulPartLen,
2261
    CK_BYTE_PTR pEncryptedPart,
2262
    CK_ULONG_PTR pulEncryptedPartLen)
2263
0
{
2264
0
    COMMON_DEFINITIONS;
2265
0
2266
0
    PR_LOG(modlog, 1, ("C_SignEncryptUpdate"));
2267
0
    log_handle(3, fmt_hSession, hSession);
2268
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
2269
0
    PR_LOG(modlog, 3, (fmt_ulPartLen, ulPartLen));
2270
0
    PR_LOG(modlog, 3, (fmt_pEncryptedPart, pEncryptedPart));
2271
0
    PR_LOG(modlog, 3, (fmt_pulEncryptedPartLen, pulEncryptedPartLen));
2272
0
    nssdbg_start_time(FUNC_C_SIGNENCRYPTUPDATE, &start);
2273
0
    rv = module_functions->C_SignEncryptUpdate(hSession,
2274
0
                                               pPart,
2275
0
                                               ulPartLen,
2276
0
                                               pEncryptedPart,
2277
0
                                               pulEncryptedPartLen);
2278
0
    nssdbg_finish_time(FUNC_C_SIGNENCRYPTUPDATE, start);
2279
0
    PR_LOG(modlog, 4, (fmt_spulEncryptedPartLen, *pulEncryptedPartLen));
2280
0
    log_rv(rv);
2281
0
    return rv;
2282
0
}
2283
2284
CK_RV
2285
NSSDBGC_DecryptVerifyUpdate(
2286
    CK_SESSION_HANDLE hSession,
2287
    CK_BYTE_PTR pEncryptedPart,
2288
    CK_ULONG ulEncryptedPartLen,
2289
    CK_BYTE_PTR pPart,
2290
    CK_ULONG_PTR pulPartLen)
2291
0
{
2292
0
    COMMON_DEFINITIONS;
2293
0
2294
0
    PR_LOG(modlog, 1, ("C_DecryptVerifyUpdate"));
2295
0
    log_handle(3, fmt_hSession, hSession);
2296
0
    PR_LOG(modlog, 3, (fmt_pEncryptedPart, pEncryptedPart));
2297
0
    PR_LOG(modlog, 3, (fmt_ulEncryptedPartLen, ulEncryptedPartLen));
2298
0
    PR_LOG(modlog, 3, (fmt_pPart, pPart));
2299
0
    PR_LOG(modlog, 3, (fmt_pulPartLen, pulPartLen));
2300
0
    nssdbg_start_time(FUNC_C_DECRYPTVERIFYUPDATE, &start);
2301
0
    rv = module_functions->C_DecryptVerifyUpdate(hSession,
2302
0
                                                 pEncryptedPart,
2303
0
                                                 ulEncryptedPartLen,
2304
0
                                                 pPart,
2305
0
                                                 pulPartLen);
2306
0
    nssdbg_finish_time(FUNC_C_DECRYPTVERIFYUPDATE, start);
2307
0
    PR_LOG(modlog, 4, (fmt_spulPartLen, *pulPartLen));
2308
0
    log_rv(rv);
2309
0
    return rv;
2310
0
}
2311
2312
CK_RV
2313
NSSDBGC_GenerateKey(
2314
    CK_SESSION_HANDLE hSession,
2315
    CK_MECHANISM_PTR pMechanism,
2316
    CK_ATTRIBUTE_PTR pTemplate,
2317
    CK_ULONG ulCount,
2318
    CK_OBJECT_HANDLE_PTR phKey)
2319
0
{
2320
0
    COMMON_DEFINITIONS;
2321
0
2322
0
    PR_LOG(modlog, 1, ("C_GenerateKey"));
2323
0
    log_handle(3, fmt_hSession, hSession);
2324
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2325
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
2326
0
    PR_LOG(modlog, 3, (fmt_ulCount, ulCount));
2327
0
    PR_LOG(modlog, 3, (fmt_phKey, phKey));
2328
0
    print_template(pTemplate, ulCount);
2329
0
    print_mechanism(pMechanism);
2330
0
    nssdbg_start_time(FUNC_C_GENERATEKEY, &start);
2331
0
    rv = module_functions->C_GenerateKey(hSession,
2332
0
                                         pMechanism,
2333
0
                                         pTemplate,
2334
0
                                         ulCount,
2335
0
                                         phKey);
2336
0
    nssdbg_finish_time(FUNC_C_GENERATEKEY, start);
2337
0
    log_handle(4, fmt_sphKey, *phKey);
2338
0
    log_rv(rv);
2339
0
    return rv;
2340
0
}
2341
2342
CK_RV
2343
NSSDBGC_GenerateKeyPair(
2344
    CK_SESSION_HANDLE hSession,
2345
    CK_MECHANISM_PTR pMechanism,
2346
    CK_ATTRIBUTE_PTR pPublicKeyTemplate,
2347
    CK_ULONG ulPublicKeyAttributeCount,
2348
    CK_ATTRIBUTE_PTR pPrivateKeyTemplate,
2349
    CK_ULONG ulPrivateKeyAttributeCount,
2350
    CK_OBJECT_HANDLE_PTR phPublicKey,
2351
    CK_OBJECT_HANDLE_PTR phPrivateKey)
2352
0
{
2353
0
    COMMON_DEFINITIONS;
2354
0
2355
0
    PR_LOG(modlog, 1, ("C_GenerateKeyPair"));
2356
0
    log_handle(3, fmt_hSession, hSession);
2357
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2358
0
    PR_LOG(modlog, 3, ("  pPublicKeyTemplate = 0x%p", pPublicKeyTemplate));
2359
0
    PR_LOG(modlog, 3, ("  ulPublicKeyAttributeCount = %d", ulPublicKeyAttributeCount));
2360
0
    PR_LOG(modlog, 3, ("  pPrivateKeyTemplate = 0x%p", pPrivateKeyTemplate));
2361
0
    PR_LOG(modlog, 3, ("  ulPrivateKeyAttributeCount = %d", ulPrivateKeyAttributeCount));
2362
0
    PR_LOG(modlog, 3, ("  phPublicKey = 0x%p", phPublicKey));
2363
0
    print_template(pPublicKeyTemplate, ulPublicKeyAttributeCount);
2364
0
    PR_LOG(modlog, 3, ("  phPrivateKey = 0x%p", phPrivateKey));
2365
0
    print_template(pPrivateKeyTemplate, ulPrivateKeyAttributeCount);
2366
0
    print_mechanism(pMechanism);
2367
0
    nssdbg_start_time(FUNC_C_GENERATEKEYPAIR, &start);
2368
0
    rv = module_functions->C_GenerateKeyPair(hSession,
2369
0
                                             pMechanism,
2370
0
                                             pPublicKeyTemplate,
2371
0
                                             ulPublicKeyAttributeCount,
2372
0
                                             pPrivateKeyTemplate,
2373
0
                                             ulPrivateKeyAttributeCount,
2374
0
                                             phPublicKey,
2375
0
                                             phPrivateKey);
2376
0
    nssdbg_finish_time(FUNC_C_GENERATEKEYPAIR, start);
2377
0
    log_handle(4, "  *phPublicKey = 0x%x", *phPublicKey);
2378
0
    log_handle(4, "  *phPrivateKey = 0x%x", *phPrivateKey);
2379
0
    log_rv(rv);
2380
0
    return rv;
2381
0
}
2382
2383
CK_RV
2384
NSSDBGC_WrapKey(
2385
    CK_SESSION_HANDLE hSession,
2386
    CK_MECHANISM_PTR pMechanism,
2387
    CK_OBJECT_HANDLE hWrappingKey,
2388
    CK_OBJECT_HANDLE hKey,
2389
    CK_BYTE_PTR pWrappedKey,
2390
    CK_ULONG_PTR pulWrappedKeyLen)
2391
0
{
2392
0
    COMMON_DEFINITIONS;
2393
0
2394
0
    PR_LOG(modlog, 1, ("C_WrapKey"));
2395
0
    log_handle(3, fmt_hSession, hSession);
2396
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2397
0
    log_handle(3, "  hWrappingKey = 0x%x", hWrappingKey);
2398
0
    log_handle(3, fmt_hKey, hKey);
2399
0
    PR_LOG(modlog, 3, (fmt_pWrappedKey, pWrappedKey));
2400
0
    PR_LOG(modlog, 3, ("  pulWrappedKeyLen = 0x%p", pulWrappedKeyLen));
2401
0
    print_mechanism(pMechanism);
2402
0
    nssdbg_start_time(FUNC_C_WRAPKEY, &start);
2403
0
    rv = module_functions->C_WrapKey(hSession,
2404
0
                                     pMechanism,
2405
0
                                     hWrappingKey,
2406
0
                                     hKey,
2407
0
                                     pWrappedKey,
2408
0
                                     pulWrappedKeyLen);
2409
0
    nssdbg_finish_time(FUNC_C_WRAPKEY, start);
2410
0
    PR_LOG(modlog, 4, ("  *pulWrappedKeyLen = 0x%x", *pulWrappedKeyLen));
2411
0
    log_rv(rv);
2412
0
    return rv;
2413
0
}
2414
2415
CK_RV
2416
NSSDBGC_UnwrapKey(
2417
    CK_SESSION_HANDLE hSession,
2418
    CK_MECHANISM_PTR pMechanism,
2419
    CK_OBJECT_HANDLE hUnwrappingKey,
2420
    CK_BYTE_PTR pWrappedKey,
2421
    CK_ULONG ulWrappedKeyLen,
2422
    CK_ATTRIBUTE_PTR pTemplate,
2423
    CK_ULONG ulAttributeCount,
2424
    CK_OBJECT_HANDLE_PTR phKey)
2425
0
{
2426
0
    COMMON_DEFINITIONS;
2427
0
2428
0
    PR_LOG(modlog, 1, ("C_UnwrapKey"));
2429
0
    log_handle(3, fmt_hSession, hSession);
2430
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2431
0
    log_handle(3, "  hUnwrappingKey = 0x%x", hUnwrappingKey);
2432
0
    PR_LOG(modlog, 3, (fmt_pWrappedKey, pWrappedKey));
2433
0
    PR_LOG(modlog, 3, ("  ulWrappedKeyLen = %d", ulWrappedKeyLen));
2434
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
2435
0
    PR_LOG(modlog, 3, (fmt_ulAttributeCount, ulAttributeCount));
2436
0
    PR_LOG(modlog, 3, (fmt_phKey, phKey));
2437
0
    print_template(pTemplate, ulAttributeCount);
2438
0
    print_mechanism(pMechanism);
2439
0
    nssdbg_start_time(FUNC_C_UNWRAPKEY, &start);
2440
0
    rv = module_functions->C_UnwrapKey(hSession,
2441
0
                                       pMechanism,
2442
0
                                       hUnwrappingKey,
2443
0
                                       pWrappedKey,
2444
0
                                       ulWrappedKeyLen,
2445
0
                                       pTemplate,
2446
0
                                       ulAttributeCount,
2447
0
                                       phKey);
2448
0
    nssdbg_finish_time(FUNC_C_UNWRAPKEY, start);
2449
0
    log_handle(4, fmt_sphKey, *phKey);
2450
0
    log_rv(rv);
2451
0
    return rv;
2452
0
}
2453
2454
CK_RV
2455
NSSDBGC_DeriveKey(
2456
    CK_SESSION_HANDLE hSession,
2457
    CK_MECHANISM_PTR pMechanism,
2458
    CK_OBJECT_HANDLE hBaseKey,
2459
    CK_ATTRIBUTE_PTR pTemplate,
2460
    CK_ULONG ulAttributeCount,
2461
    CK_OBJECT_HANDLE_PTR phKey)
2462
0
{
2463
0
    COMMON_DEFINITIONS;
2464
0
2465
0
    PR_LOG(modlog, 1, ("C_DeriveKey"));
2466
0
    log_handle(3, fmt_hSession, hSession);
2467
0
    PR_LOG(modlog, 3, (fmt_pMechanism, pMechanism));
2468
0
    log_handle(3, "  hBaseKey = 0x%x", hBaseKey);
2469
0
    PR_LOG(modlog, 3, (fmt_pTemplate, pTemplate));
2470
0
    PR_LOG(modlog, 3, (fmt_ulAttributeCount, ulAttributeCount));
2471
0
    PR_LOG(modlog, 3, (fmt_phKey, phKey));
2472
0
    print_template(pTemplate, ulAttributeCount);
2473
0
    print_mechanism(pMechanism);
2474
0
    nssdbg_start_time(FUNC_C_DERIVEKEY, &start);
2475
0
    rv = module_functions->C_DeriveKey(hSession,
2476
0
                                       pMechanism,
2477
0
                                       hBaseKey,
2478
0
                                       pTemplate,
2479
0
                                       ulAttributeCount,
2480
0
                                       phKey);
2481
0
    nssdbg_finish_time(FUNC_C_DERIVEKEY, start);
2482
0
    log_handle(4, fmt_sphKey, *phKey);
2483
0
    log_rv(rv);
2484
0
    return rv;
2485
0
}
2486
2487
CK_RV
2488
NSSDBGC_SeedRandom(
2489
    CK_SESSION_HANDLE hSession,
2490
    CK_BYTE_PTR pSeed,
2491
    CK_ULONG ulSeedLen)
2492
0
{
2493
0
    COMMON_DEFINITIONS;
2494
0
2495
0
    PR_LOG(modlog, 1, ("C_SeedRandom"));
2496
0
    log_handle(3, fmt_hSession, hSession);
2497
0
    PR_LOG(modlog, 3, ("  pSeed = 0x%p", pSeed));
2498
0
    PR_LOG(modlog, 3, ("  ulSeedLen = %d", ulSeedLen));
2499
0
    nssdbg_start_time(FUNC_C_SEEDRANDOM, &start);
2500
0
    rv = module_functions->C_SeedRandom(hSession,
2501
0
                                        pSeed,
2502
0
                                        ulSeedLen);
2503
0
    nssdbg_finish_time(FUNC_C_SEEDRANDOM, start);
2504
0
    log_rv(rv);
2505
0
    return rv;
2506
0
}
2507
2508
CK_RV
2509
NSSDBGC_GenerateRandom(
2510
    CK_SESSION_HANDLE hSession,
2511
    CK_BYTE_PTR RandomData,
2512
    CK_ULONG ulRandomLen)
2513
0
{
2514
0
    COMMON_DEFINITIONS;
2515
0
2516
0
    PR_LOG(modlog, 1, ("C_GenerateRandom"));
2517
0
    log_handle(3, fmt_hSession, hSession);
2518
0
    PR_LOG(modlog, 3, ("  RandomData = 0x%p", RandomData));
2519
0
    PR_LOG(modlog, 3, ("  ulRandomLen = %d", ulRandomLen));
2520
0
    nssdbg_start_time(FUNC_C_GENERATERANDOM, &start);
2521
0
    rv = module_functions->C_GenerateRandom(hSession,
2522
0
                                            RandomData,
2523
0
                                            ulRandomLen);
2524
0
    nssdbg_finish_time(FUNC_C_GENERATERANDOM, start);
2525
0
    log_rv(rv);
2526
0
    return rv;
2527
0
}
2528
2529
CK_RV
2530
NSSDBGC_GetFunctionStatus(
2531
    CK_SESSION_HANDLE hSession)
2532
0
{
2533
0
    COMMON_DEFINITIONS;
2534
0
2535
0
    PR_LOG(modlog, 1, ("C_GetFunctionStatus"));
2536
0
    log_handle(3, fmt_hSession, hSession);
2537
0
    nssdbg_start_time(FUNC_C_GETFUNCTIONSTATUS, &start);
2538
0
    rv = module_functions->C_GetFunctionStatus(hSession);
2539
0
    nssdbg_finish_time(FUNC_C_GETFUNCTIONSTATUS, start);
2540
0
    log_rv(rv);
2541
0
    return rv;
2542
0
}
2543
2544
CK_RV
2545
NSSDBGC_CancelFunction(
2546
    CK_SESSION_HANDLE hSession)
2547
0
{
2548
0
    COMMON_DEFINITIONS;
2549
0
2550
0
    PR_LOG(modlog, 1, ("C_CancelFunction"));
2551
0
    log_handle(3, fmt_hSession, hSession);
2552
0
    nssdbg_start_time(FUNC_C_CANCELFUNCTION, &start);
2553
0
    rv = module_functions->C_CancelFunction(hSession);
2554
0
    nssdbg_finish_time(FUNC_C_CANCELFUNCTION, start);
2555
0
    log_rv(rv);
2556
0
    return rv;
2557
0
}
2558
2559
CK_RV
2560
NSSDBGC_WaitForSlotEvent(
2561
    CK_FLAGS flags,
2562
    CK_SLOT_ID_PTR pSlot,
2563
    CK_VOID_PTR pRserved)
2564
0
{
2565
0
    COMMON_DEFINITIONS;
2566
0
2567
0
    PR_LOG(modlog, 1, ("C_WaitForSlotEvent"));
2568
0
    PR_LOG(modlog, 3, (fmt_flags, flags));
2569
0
    PR_LOG(modlog, 3, ("  pSlot = 0x%p", pSlot));
2570
0
    PR_LOG(modlog, 3, ("  pRserved = 0x%p", pRserved));
2571
0
    nssdbg_start_time(FUNC_C_WAITFORSLOTEVENT, &start);
2572
0
    rv = module_functions->C_WaitForSlotEvent(flags,
2573
0
                                              pSlot,
2574
0
                                              pRserved);
2575
0
    nssdbg_finish_time(FUNC_C_WAITFORSLOTEVENT, start);
2576
0
    log_rv(rv);
2577
0
    return rv;
2578
0
}
2579
2580
CK_FUNCTION_LIST_PTR
2581
nss_InsertDeviceLog(
2582
    CK_FUNCTION_LIST_PTR devEPV)
2583
0
{
2584
0
    module_functions = devEPV;
2585
0
    modlog = PR_NewLogModule("nss_mod_log");
2586
0
    debug_functions.C_Initialize = NSSDBGC_Initialize;
2587
0
    debug_functions.C_Finalize = NSSDBGC_Finalize;
2588
0
    debug_functions.C_GetInfo = NSSDBGC_GetInfo;
2589
0
    debug_functions.C_GetFunctionList = NSSDBGC_GetFunctionList;
2590
0
    debug_functions.C_GetSlotList = NSSDBGC_GetSlotList;
2591
0
    debug_functions.C_GetSlotInfo = NSSDBGC_GetSlotInfo;
2592
0
    debug_functions.C_GetTokenInfo = NSSDBGC_GetTokenInfo;
2593
0
    debug_functions.C_GetMechanismList = NSSDBGC_GetMechanismList;
2594
0
    debug_functions.C_GetMechanismInfo = NSSDBGC_GetMechanismInfo;
2595
0
    debug_functions.C_InitToken = NSSDBGC_InitToken;
2596
0
    debug_functions.C_InitPIN = NSSDBGC_InitPIN;
2597
0
    debug_functions.C_SetPIN = NSSDBGC_SetPIN;
2598
0
    debug_functions.C_OpenSession = NSSDBGC_OpenSession;
2599
0
    debug_functions.C_CloseSession = NSSDBGC_CloseSession;
2600
0
    debug_functions.C_CloseAllSessions = NSSDBGC_CloseAllSessions;
2601
0
    debug_functions.C_GetSessionInfo = NSSDBGC_GetSessionInfo;
2602
0
    debug_functions.C_GetOperationState = NSSDBGC_GetOperationState;
2603
0
    debug_functions.C_SetOperationState = NSSDBGC_SetOperationState;
2604
0
    debug_functions.C_Login = NSSDBGC_Login;
2605
0
    debug_functions.C_Logout = NSSDBGC_Logout;
2606
0
    debug_functions.C_CreateObject = NSSDBGC_CreateObject;
2607
0
    debug_functions.C_CopyObject = NSSDBGC_CopyObject;
2608
0
    debug_functions.C_DestroyObject = NSSDBGC_DestroyObject;
2609
0
    debug_functions.C_GetObjectSize = NSSDBGC_GetObjectSize;
2610
0
    debug_functions.C_GetAttributeValue = NSSDBGC_GetAttributeValue;
2611
0
    debug_functions.C_SetAttributeValue = NSSDBGC_SetAttributeValue;
2612
0
    debug_functions.C_FindObjectsInit = NSSDBGC_FindObjectsInit;
2613
0
    debug_functions.C_FindObjects = NSSDBGC_FindObjects;
2614
0
    debug_functions.C_FindObjectsFinal = NSSDBGC_FindObjectsFinal;
2615
0
    debug_functions.C_EncryptInit = NSSDBGC_EncryptInit;
2616
0
    debug_functions.C_Encrypt = NSSDBGC_Encrypt;
2617
0
    debug_functions.C_EncryptUpdate = NSSDBGC_EncryptUpdate;
2618
0
    debug_functions.C_EncryptFinal = NSSDBGC_EncryptFinal;
2619
0
    debug_functions.C_DecryptInit = NSSDBGC_DecryptInit;
2620
0
    debug_functions.C_Decrypt = NSSDBGC_Decrypt;
2621
0
    debug_functions.C_DecryptUpdate = NSSDBGC_DecryptUpdate;
2622
0
    debug_functions.C_DecryptFinal = NSSDBGC_DecryptFinal;
2623
0
    debug_functions.C_DigestInit = NSSDBGC_DigestInit;
2624
0
    debug_functions.C_Digest = NSSDBGC_Digest;
2625
0
    debug_functions.C_DigestUpdate = NSSDBGC_DigestUpdate;
2626
0
    debug_functions.C_DigestKey = NSSDBGC_DigestKey;
2627
0
    debug_functions.C_DigestFinal = NSSDBGC_DigestFinal;
2628
0
    debug_functions.C_SignInit = NSSDBGC_SignInit;
2629
0
    debug_functions.C_Sign = NSSDBGC_Sign;
2630
0
    debug_functions.C_SignUpdate = NSSDBGC_SignUpdate;
2631
0
    debug_functions.C_SignFinal = NSSDBGC_SignFinal;
2632
0
    debug_functions.C_SignRecoverInit = NSSDBGC_SignRecoverInit;
2633
0
    debug_functions.C_SignRecover = NSSDBGC_SignRecover;
2634
0
    debug_functions.C_VerifyInit = NSSDBGC_VerifyInit;
2635
0
    debug_functions.C_Verify = NSSDBGC_Verify;
2636
0
    debug_functions.C_VerifyUpdate = NSSDBGC_VerifyUpdate;
2637
0
    debug_functions.C_VerifyFinal = NSSDBGC_VerifyFinal;
2638
0
    debug_functions.C_VerifyRecoverInit = NSSDBGC_VerifyRecoverInit;
2639
0
    debug_functions.C_VerifyRecover = NSSDBGC_VerifyRecover;
2640
0
    debug_functions.C_DigestEncryptUpdate = NSSDBGC_DigestEncryptUpdate;
2641
0
    debug_functions.C_DecryptDigestUpdate = NSSDBGC_DecryptDigestUpdate;
2642
0
    debug_functions.C_SignEncryptUpdate = NSSDBGC_SignEncryptUpdate;
2643
0
    debug_functions.C_DecryptVerifyUpdate = NSSDBGC_DecryptVerifyUpdate;
2644
0
    debug_functions.C_GenerateKey = NSSDBGC_GenerateKey;
2645
0
    debug_functions.C_GenerateKeyPair = NSSDBGC_GenerateKeyPair;
2646
0
    debug_functions.C_WrapKey = NSSDBGC_WrapKey;
2647
0
    debug_functions.C_UnwrapKey = NSSDBGC_UnwrapKey;
2648
0
    debug_functions.C_DeriveKey = NSSDBGC_DeriveKey;
2649
0
    debug_functions.C_SeedRandom = NSSDBGC_SeedRandom;
2650
0
    debug_functions.C_GenerateRandom = NSSDBGC_GenerateRandom;
2651
0
    debug_functions.C_GetFunctionStatus = NSSDBGC_GetFunctionStatus;
2652
0
    debug_functions.C_CancelFunction = NSSDBGC_CancelFunction;
2653
0
    debug_functions.C_WaitForSlotEvent = NSSDBGC_WaitForSlotEvent;
2654
0
    return &debug_functions;
2655
0
}
2656
2657
/*
2658
 * scale the time factor up accordingly.
2659
 * This routine tries to keep at least 2 significant figures on output.
2660
 *    If the time is 0, then indicate that with a 'z' for units.
2661
 *    If the time is greater than 10 minutes, output the time in minutes.
2662
 *    If the time is less than 10 minutes but greater than 10 seconds output 
2663
 * the time in second.
2664
 *    If the time is less than 10 seconds but greater than 10 milliseconds 
2665
 * output * the time in millisecond.
2666
 *    If the time is less than 10 milliseconds but greater than 0 ticks output 
2667
 * the time in microsecond.
2668
 *
2669
 */
2670
static PRUint32
2671
getPrintTime(PRIntervalTime time, char **type)
2672
0
{
2673
0
    PRUint32 prTime;
2674
0
2675
0
    /* detect a programming error by outputting 'bu' to the output stream
2676
0
     * rather than crashing */
2677
0
    *type = "bug";
2678
0
    if (time == 0) {
2679
0
        *type = "z";
2680
0
        return 0;
2681
0
    }
2682
0
2683
0
    prTime = PR_IntervalToSeconds(time);
2684
0
2685
0
    if (prTime >= 600) {
2686
0
        *type = "m";
2687
0
        return prTime / 60;
2688
0
    }
2689
0
    if (prTime >= 10) {
2690
0
        *type = "s";
2691
0
        return prTime;
2692
0
    }
2693
0
    prTime = PR_IntervalToMilliseconds(time);
2694
0
    if (prTime >= 10) {
2695
0
        *type = "ms";
2696
0
        return prTime;
2697
0
    }
2698
0
    *type = "us";
2699
0
    return PR_IntervalToMicroseconds(time);
2700
0
}
2701
2702
static void
2703
print_final_statistics(void)
2704
0
{
2705
0
    int total_calls = 0;
2706
0
    PRIntervalTime total_time = 0;
2707
0
    PRUint32 pr_total_time;
2708
0
    char *type;
2709
0
    char *fname;
2710
0
    FILE *outfile = NULL;
2711
0
    int i;
2712
0
2713
0
    fname = PR_GetEnvSecure("NSS_OUTPUT_FILE");
2714
0
    if (fname) {
2715
0
        /* need to add an optional process id to the filename */
2716
0
        outfile = fopen(fname, "w+");
2717
0
    }
2718
0
    if (!outfile) {
2719
0
        outfile = stdout;
2720
0
    }
2721
0
2722
0
    fprintf(outfile, "%-25s %10s %12s %12s %10s\n", "Function", "# Calls",
2723
0
            "Time", "Avg.", "% Time");
2724
0
    fprintf(outfile, "\n");
2725
0
    for (i = 0; i < nssdbg_prof_size; i++) {
2726
0
        total_calls += nssdbg_prof_data[i].calls;
2727
0
        total_time += nssdbg_prof_data[i].time;
2728
0
    }
2729
0
    for (i = 0; i < nssdbg_prof_size; i++) {
2730
0
        PRIntervalTime time = nssdbg_prof_data[i].time;
2731
0
        PRUint32 usTime = PR_IntervalToMicroseconds(time);
2732
0
        PRUint32 prTime = 0;
2733
0
        PRUint32 calls = nssdbg_prof_data[i].calls;
2734
0
        /* don't print out functions that weren't even called */
2735
0
        if (calls == 0) {
2736
0
            continue;
2737
0
        }
2738
0
2739
0
        prTime = getPrintTime(time, &type);
2740
0
2741
0
        fprintf(outfile, "%-25s %10d %10d%2s ", nssdbg_prof_data[i].function,
2742
0
                calls, prTime, type);
2743
0
        /* for now always output the average in microseconds */
2744
0
        fprintf(outfile, "%10.2f%2s", (float)usTime / (float)calls, "us");
2745
0
        fprintf(outfile, "%10.2f%%", ((float)time / (float)total_time) * 100);
2746
0
        fprintf(outfile, "\n");
2747
0
    }
2748
0
    fprintf(outfile, "\n");
2749
0
2750
0
    pr_total_time = getPrintTime(total_time, &type);
2751
0
2752
0
    fprintf(outfile, "%25s %10d %10d%2s\n", "Totals", total_calls,
2753
0
            pr_total_time, type);
2754
0
    fprintf(outfile, "\n\nMaximum number of concurrent open sessions: %d\n\n",
2755
0
            maxOpenSessions);
2756
0
    fflush(outfile);
2757
0
    if (outfile != stdout) {
2758
0
        fclose(outfile);
2759
0
    }
2760
0
}