summaryrefslogtreecommitdiff
path: root/security/nss/lib/pk11wrap/debug_module.c
blob: e2b204f65fb866cd8f644786737770f8c84db2a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
/*
 * The contents of this file are subject to the Mozilla Public
 * License Version 1.1 (the "License"); you may not use this file
 * except in compliance with the License. You may obtain a copy of
 * the License at http://www.mozilla.org/MPL/
 * 
 * Software distributed under the License is distributed on an "AS
 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
 * implied. See the License for the specific language governing
 * rights and limitations under the License.
 * 
 * The Original Code is the Netscape security libraries.
 * 
 * The Initial Developer of the Original Code is Netscape
 * Communications Corporation.  Portions created by Netscape are 
 * Copyright (C) 1994-2000 Netscape Communications Corporation.  All
 * Rights Reserved.
 * 
 * Contributor(s):
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL"), in which case the provisions of the GPL are applicable 
 * instead of those above.  If you wish to allow use of your 
 * version of this file only under the terms of the GPL and not to
 * allow others to use your version of this file under the MPL,
 * indicate your decision by deleting the provisions above and
 * replace them with the notice and other provisions required by
 * the GPL.  If you do not delete the provisions above, a recipient
 * may use your version of this file under either the MPL or the
 * GPL.
 */
#include "prlog.h"
#include <stdio.h>

static PRLogModuleInfo *modlog = NULL;

static CK_FUNCTION_LIST_PTR module_functions;

static CK_FUNCTION_LIST debug_functions;

static void print_final_statistics(void);

/* The AIX 64-bit compiler chokes on large switch statements (see
 * bug #63815).  I tried the trick recommended there, using -O2 in
 * debug builds, and it didn't work.  Instead, I'll suppress some of
 * the verbose output and just dump values.
 */

static void get_attr_type_str(CK_ATTRIBUTE_TYPE atype, char *str, int len)
{
#define SETA(attr) \
    PR_snprintf(str, len, "%s", attr); break;
    switch (atype) {
#ifndef AIX_64BIT
    case CKA_CLASS: SETA("CKA_CLASS");
    case CKA_TOKEN: SETA("CKA_TOKEN");
    case CKA_PRIVATE: SETA("CKA_PRIVATE");
    case CKA_LABEL: SETA("CKA_LABEL");
    case CKA_APPLICATION: SETA("CKA_APPLICATION");
    case CKA_VALUE: SETA("CKA_VALUE");
    case CKA_OBJECT_ID: SETA("CKA_OBJECT_ID");
    case CKA_CERTIFICATE_TYPE: SETA("CKA_CERTIFICATE_TYPE");
    case CKA_ISSUER: SETA("CKA_ISSUER");
    case CKA_SERIAL_NUMBER: SETA("CKA_SERIAL_NUMBER");
    case CKA_AC_ISSUER: SETA("CKA_AC_ISSUER");
    case CKA_OWNER: SETA("CKA_OWNER");
    case CKA_ATTR_TYPES: SETA("CKA_ATTR_TYPES");
    case CKA_TRUSTED: SETA("CKA_TRUSTED");
    case CKA_KEY_TYPE: SETA("CKA_KEY_TYPE");
    case CKA_SUBJECT: SETA("CKA_SUBJECT");
    case CKA_ID: SETA("CKA_ID");
    case CKA_SENSITIVE: SETA("CKA_SENSITIVE");
    case CKA_ENCRYPT: SETA("CKA_ENCRYPT");
    case CKA_DECRYPT: SETA("CKA_DECRYPT");
    case CKA_WRAP: SETA("CKA_WRAP");
    case CKA_UNWRAP: SETA("CKA_UNWRAP");
    case CKA_SIGN: SETA("CKA_SIGN");
    case CKA_SIGN_RECOVER: SETA("CKA_SIGN_RECOVER");
    case CKA_VERIFY: SETA("CKA_VERIFY");
    case CKA_VERIFY_RECOVER: SETA("CKA_VERIFY_RECOVER");
    case CKA_DERIVE: SETA("CKA_DERIVE");
    case CKA_START_DATE: SETA("CKA_START_DATE");
    case CKA_END_DATE: SETA("CKA_END_DATE");
    case CKA_MODULUS: SETA("CKA_MODULUS");
    case CKA_MODULUS_BITS: SETA("CKA_MODULUS_BITS");
    case CKA_PUBLIC_EXPONENT: SETA("CKA_PUBLIC_EXPONENT");
    case CKA_PRIVATE_EXPONENT: SETA("CKA_PRIVATE_EXPONENT");
    case CKA_PRIME_1: SETA("CKA_PRIME_1");
    case CKA_PRIME_2: SETA("CKA_PRIME_2");
    case CKA_EXPONENT_1: SETA("CKA_EXPONENT_1");
    case CKA_EXPONENT_2: SETA("CKA_EXPONENT_2");
    case CKA_COEFFICIENT: SETA("CKA_COEFFICIENT");
    case CKA_PRIME: SETA("CKA_PRIME");
    case CKA_SUBPRIME: SETA("CKA_SUBPRIME");
    case CKA_BASE: SETA("CKA_BASE");
    case CKA_PRIME_BITS: SETA("CKA_PRIME_BITS");
    case CKA_SUB_PRIME_BITS: SETA("CKA_SUB_PRIME_BITS");
    case CKA_VALUE_BITS: SETA("CKA_VALUE_BITS");
    case CKA_VALUE_LEN: SETA("CKA_VALUE_LEN");
    case CKA_EXTRACTABLE: SETA("CKA_EXTRACTABLE");
    case CKA_LOCAL: SETA("CKA_LOCAL");
    case CKA_NEVER_EXTRACTABLE: SETA("CKA_NEVER_EXTRACTABLE");
    case CKA_ALWAYS_SENSITIVE: SETA("CKA_ALWAYS_SENSITIVE");
    case CKA_KEY_GEN_MECHANISM: SETA("CKA_KEY_GEN_MECHANISM");
    case CKA_MODIFIABLE: SETA("CKA_MODIFIABLE");
    case CKA_ECDSA_PARAMS: SETA("CKA_ECDSA_PARAMS");
    case CKA_EC_POINT: SETA("CKA_EC_POINT");
    case CKA_SECONDARY_AUTH: SETA("CKA_SECONDARY_AUTH");
    case CKA_AUTH_PIN_FLAGS: SETA("CKA_AUTH_PIN_FLAGS");
    case CKA_HW_FEATURE_TYPE: SETA("CKA_HW_FEATURE_TYPE");
    case CKA_RESET_ON_INIT: SETA("CKA_RESET_ON_INIT");
    case CKA_HAS_RESET: SETA("CKA_HAS_RESET");
    case CKA_VENDOR_DEFINED: SETA("CKA_VENDOR_DEFINED");
    case CKA_NETSCAPE_URL: SETA("CKA_NETSCAPE_URL");
    case CKA_NETSCAPE_EMAIL: SETA("CKA_NETSCAPE_EMAIL");
    case CKA_NETSCAPE_SMIME_INFO: SETA("CKA_NETSCAPE_SMIME_INFO");
    case CKA_NETSCAPE_SMIME_TIMESTAMP: SETA("CKA_NETSCAPE_SMIME_TIMESTAMP");
    case CKA_NETSCAPE_PKCS8_SALT: SETA("CKA_NETSCAPE_PKCS8_SALT");
    case CKA_NETSCAPE_PASSWORD_CHECK: SETA("CKA_NETSCAPE_PASSWORD_CHECK");
    case CKA_NETSCAPE_EXPIRES: SETA("CKA_NETSCAPE_EXPIRES");
    case CKA_NETSCAPE_KRL: SETA("CKA_NETSCAPE_KRL");
    case CKA_NETSCAPE_PQG_COUNTER: SETA("CKA_NETSCAPE_PQG_COUNTER");
    case CKA_NETSCAPE_PQG_SEED: SETA("CKA_NETSCAPE_PQG_SEED");
    case CKA_NETSCAPE_PQG_H: SETA("CKA_NETSCAPE_PQG_H");
    case CKA_NETSCAPE_PQG_SEED_BITS: SETA("CKA_NETSCAPE_PQG_SEED_BITS");
    case CKA_TRUST: SETA("CKA_TRUST");
    case CKA_TRUST_DIGITAL_SIGNATURE: SETA("CKA_TRUST_DIGITAL_SIGNATURE");
    case CKA_TRUST_NON_REPUDIATION: SETA("CKA_TRUST_NON_REPUDIATION");
    case CKA_TRUST_KEY_ENCIPHERMENT: SETA("CKA_TRUST_KEY_ENCIPHERMENT");
    case CKA_TRUST_DATA_ENCIPHERMENT: SETA("CKA_TRUST_DATA_ENCIPHERMENT");
    case CKA_TRUST_KEY_AGREEMENT: SETA("CKA_TRUST_KEY_AGREEMENT");
    case CKA_TRUST_KEY_CERT_SIGN: SETA("CKA_TRUST_KEY_CERT_SIGN");
    case CKA_TRUST_CRL_SIGN: SETA("CKA_TRUST_CRL_SIGN");
    case CKA_TRUST_SERVER_AUTH: SETA("CKA_TRUST_SERVER_AUTH");
    case CKA_TRUST_CLIENT_AUTH: SETA("CKA_TRUST_CLIENT_AUTH");
    case CKA_TRUST_CODE_SIGNING: SETA("CKA_TRUST_CODE_SIGNING");
    case CKA_TRUST_EMAIL_PROTECTION: SETA("CKA_TRUST_EMAIL_PROTECTION");
    case CKA_TRUST_IPSEC_END_SYSTEM: SETA("CKA_TRUST_IPSEC_END_SYSTEM");
    case CKA_TRUST_IPSEC_TUNNEL: SETA("CKA_TRUST_IPSEC_TUNNEL");
    case CKA_TRUST_IPSEC_USER: SETA("CKA_TRUST_IPSEC_USER");
    case CKA_TRUST_TIME_STAMPING: SETA("CKA_TRUST_TIME_STAMPING");
    case CKA_CERT_SHA1_HASH: SETA("CKA_CERT_SHA1_HASH");
    case CKA_CERT_MD5_HASH: SETA("CKA_CERT_MD5_HASH");
    case CKA_NETSCAPE_DB: SETA("CKA_NETSCAPE_DB");
    case CKA_NETSCAPE_TRUST: SETA("CKA_NETSCAPE_TRUST");
#endif
    default: PR_snprintf(str, len, "0x%p", atype); break;
    }
}

static void get_obj_class(CK_OBJECT_CLASS class, char *str, int len)
{
#define SETO(objc) \
    PR_snprintf(str, len, "%s", objc); break;
    switch (class) {
#ifndef AIX_64BIT
    case CKO_DATA: SETO("CKO_DATA");
    case CKO_CERTIFICATE: SETO("CKO_CERTIFICATE");
    case CKO_PUBLIC_KEY: SETO("CKO_PUBLIC_KEY");
    case CKO_PRIVATE_KEY: SETO("CKO_PRIVATE_KEY");
    case CKO_SECRET_KEY: SETO("CKO_SECRET_KEY");
    case CKO_HW_FEATURE: SETO("CKO_HW_FEATURE");
    case CKO_DOMAIN_PARAMETERS: SETO("CKO_DOMAIN_PARAMETERS");
    case CKO_NETSCAPE_CRL: SETO("CKO_NETSCAPE_CRL");
    case CKO_NETSCAPE_SMIME: SETO("CKO_NETSCAPE_SMIME");
    case CKO_NETSCAPE_TRUST: SETO("CKO_NETSCAPE_TRUST");
    case CKO_NETSCAPE_BUILTIN_ROOT_LIST: SETO("CKO_NETSCAPE_BUILTIN_ROOT_LIST");
#endif
    default: PR_snprintf(str, len, "0x%p", class); break;
    }
}

static void get_trust_val(CK_TRUST trust, char *str, int len)
{
#define SETT(objc) \
    PR_snprintf(str, len, "%s", objc); break;
    switch (trust) {
#ifndef AIX_64BIT
    case CKT_NETSCAPE_TRUSTED: SETT("CKT_NETSCAPE_TRUSTED");
    case CKT_NETSCAPE_TRUSTED_DELEGATOR: SETT("CKT_NETSCAPE_TRUSTED_DELEGATOR");
    case CKT_NETSCAPE_UNTRUSTED: SETT("CKT_NETSCAPE_UNTRUSTED");
    case CKT_NETSCAPE_MUST_VERIFY: SETT("CKT_NETSCAPE_MUST_VERIFY");
    case CKT_NETSCAPE_TRUST_UNKNOWN: SETT("CKT_NETSCAPE_TRUST_UNKNOWN");
    case CKT_NETSCAPE_VALID: SETT("CKT_NETSCAPE_VALID");
    case CKT_NETSCAPE_VALID_DELEGATOR: SETT("CKT_NETSCAPE_VALID_DELEGATOR");
#endif
    default: PR_snprintf(str, len, "0x%p", trust); break;
    }
}

static void print_attr_value(CK_ATTRIBUTE_PTR attr)
{
    char atype[48];
    char valstr[48];
    int len;
    get_attr_type_str(attr->type, atype, sizeof atype);
    switch (attr->type) {
    case CKA_TOKEN:
    case CKA_PRIVATE:
    case CKA_SENSITIVE:
    case CKA_ENCRYPT:
    case CKA_DECRYPT:
    case CKA_WRAP:
    case CKA_UNWRAP:
    case CKA_SIGN:
    case CKA_SIGN_RECOVER:
    case CKA_VERIFY:
    case CKA_VERIFY_RECOVER:
    case CKA_DERIVE:
    case CKA_EXTRACTABLE:
    case CKA_LOCAL:
    case CKA_NEVER_EXTRACTABLE:
    case CKA_ALWAYS_SENSITIVE:
    case CKA_MODIFIABLE:
	if (attr->ulValueLen > 0 && attr->pValue) {
	    CK_BBOOL tf = *((CK_BBOOL *)attr->pValue);
	    len = sizeof(valstr);
	    PR_snprintf(valstr, len, "%s", tf ? "CK_TRUE" : "CK_FALSE");
	    PR_LOG(modlog, 4, ("    %s = %s [%d]", 
	           atype, valstr, attr->ulValueLen));
	    break;
	}
    case CKA_CLASS:
	if (attr->ulValueLen > 0 && attr->pValue) {
	    CK_OBJECT_CLASS class = *((CK_OBJECT_CLASS *)attr->pValue);
	    get_obj_class(class, valstr, sizeof valstr);
	    PR_LOG(modlog, 4, ("    %s = %s [%d]", 
	           atype, valstr, attr->ulValueLen));
	    break;
	}
    case CKA_TRUST_SERVER_AUTH:
    case CKA_TRUST_CLIENT_AUTH:
    case CKA_TRUST_CODE_SIGNING:
    case CKA_TRUST_EMAIL_PROTECTION:
	if (attr->ulValueLen > 0 && attr->pValue) {
	    CK_TRUST trust = *((CK_TRUST *)attr->pValue);
	    get_trust_val(trust, valstr, sizeof valstr);
	    PR_LOG(modlog, 4, ("    %s = %s [%d]", 
	           atype, valstr, attr->ulValueLen));
	    break;
	}
    case CKA_LABEL:
    case CKA_NETSCAPE_EMAIL:
    case CKA_NETSCAPE_URL:
	if (attr->ulValueLen > 0 && attr->pValue) {
	    len = PR_MIN(attr->ulValueLen + 1, sizeof valstr);
	    PR_snprintf(valstr, len, "%s", attr->pValue);
	    PR_LOG(modlog, 4, ("    %s = %s [%d]", 
	           atype, valstr, attr->ulValueLen));
	    break;
	}
    default:
	PR_LOG(modlog, 4, ("    %s = 0x%p [%d]", 
	       atype, attr->pValue, attr->ulValueLen));
	break;
    }
}

static void print_template(CK_ATTRIBUTE_PTR templ, CK_ULONG tlen)
{
    CK_ULONG i;
    for (i=0; i<tlen; i++) {
	print_attr_value(&templ[i]);
    }
}

static void print_mechanism(CK_MECHANISM_PTR m)
{
    PR_LOG(modlog, 4, ("      mechanism = 0x%p", m->mechanism));
}

#define MAX_UINT32 0xffffffff

static void nssdbg_finish_time(PRInt32 *counter, PRIntervalTime start)
{
    PRIntervalTime ival;
    PRIntervalTime end = PR_IntervalNow();

    if (end >= start) {
	ival = PR_IntervalToMilliseconds(end-start);
    } else {
	/* the interval timer rolled over. presume it only tripped once */
	ival = PR_IntervalToMilliseconds(MAX_UINT32-start) +
			PR_IntervalToMilliseconds(end);
    }
    PR_AtomicAdd(counter, ival);
}

static PRInt32 counter_C_Initialize = 0;
static PRInt32 calls_C_Initialize = 0;
CK_RV NSSDBGC_Initialize(
  CK_VOID_PTR pInitArgs
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Initialize);
    PR_LOG(modlog, 1, ("C_Initialize"));
    PR_LOG(modlog, 3, ("  pInitArgs = 0x%p", pInitArgs));
    start = PR_IntervalNow();
    rv = module_functions->C_Initialize(pInitArgs);
    nssdbg_finish_time(&counter_C_Initialize,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Finalize = 0;
static PRInt32 calls_C_Finalize = 0;
CK_RV NSSDBGC_Finalize(
  CK_VOID_PTR pReserved
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Finalize);
    PR_LOG(modlog, 1, ("C_Finalize"));
    PR_LOG(modlog, 3, ("  pReserved = 0x%p", pReserved));
    start = PR_IntervalNow();
    rv = module_functions->C_Finalize(pReserved);
    nssdbg_finish_time(&counter_C_Finalize,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetInfo = 0;
static PRInt32 calls_C_GetInfo = 0;
CK_RV NSSDBGC_GetInfo(
  CK_INFO_PTR pInfo
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetInfo);
    PR_LOG(modlog, 1, ("C_GetInfo"));
    PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
    start = PR_IntervalNow();
    rv = module_functions->C_GetInfo(pInfo);
    nssdbg_finish_time(&counter_C_GetInfo,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetFunctionList = 0;
static PRInt32 calls_C_GetFunctionList = 0;
CK_RV NSSDBGC_GetFunctionList(
  CK_FUNCTION_LIST_PTR_PTR ppFunctionList
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetFunctionList);
    PR_LOG(modlog, 1, ("C_GetFunctionList"));
    PR_LOG(modlog, 3, ("  ppFunctionList = 0x%p", ppFunctionList));
    start = PR_IntervalNow();
    rv = module_functions->C_GetFunctionList(ppFunctionList);
    nssdbg_finish_time(&counter_C_GetFunctionList,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetSlotList = 0;
static PRInt32 calls_C_GetSlotList = 0;
CK_RV NSSDBGC_GetSlotList(
  CK_BBOOL       tokenPresent,
  CK_SLOT_ID_PTR pSlotList,
  CK_ULONG_PTR   pulCount
)
{
    CK_RV rv;
    PRIntervalTime start;
    CK_ULONG i;
    PR_AtomicIncrement(&calls_C_GetSlotList);
    PR_LOG(modlog, 1, ("C_GetSlotList"));
    PR_LOG(modlog, 3, ("  tokenPresent = 0x%x", tokenPresent));
    PR_LOG(modlog, 3, ("  pSlotList = 0x%p", pSlotList));
    PR_LOG(modlog, 3, ("  pulCount = 0x%p", pulCount));
    start = PR_IntervalNow();
    rv = module_functions->C_GetSlotList(tokenPresent,
                                 pSlotList,
                                 pulCount);
    nssdbg_finish_time(&counter_C_GetSlotList,start);
    PR_LOG(modlog, 4, ("  *pulCount = 0x%x", *pulCount));
    if (pSlotList) {
	for (i=0; i<*pulCount; i++) {
	    PR_LOG(modlog, 4, ("  slotID[%d] = %x", i, pSlotList[i]));
	}
    }
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetSlotInfo = 0;
static PRInt32 calls_C_GetSlotInfo = 0;
CK_RV NSSDBGC_GetSlotInfo(
  CK_SLOT_ID       slotID,
  CK_SLOT_INFO_PTR pInfo
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetSlotInfo);
    PR_LOG(modlog, 1, ("C_GetSlotInfo"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
    start = PR_IntervalNow();
    rv = module_functions->C_GetSlotInfo(slotID,
                                 pInfo);
    nssdbg_finish_time(&counter_C_GetSlotInfo,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetTokenInfo = 0;
static PRInt32 calls_C_GetTokenInfo = 0;
CK_RV NSSDBGC_GetTokenInfo(
  CK_SLOT_ID        slotID,
  CK_TOKEN_INFO_PTR pInfo
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetTokenInfo);
    PR_LOG(modlog, 1, ("C_GetTokenInfo"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
    start = PR_IntervalNow();
    rv = module_functions->C_GetTokenInfo(slotID,
                                 pInfo);
    nssdbg_finish_time(&counter_C_GetTokenInfo,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetMechanismList = 0;
static PRInt32 calls_C_GetMechanismList = 0;
CK_RV NSSDBGC_GetMechanismList(
  CK_SLOT_ID            slotID,
  CK_MECHANISM_TYPE_PTR pMechanismList,
  CK_ULONG_PTR          pulCount
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetMechanismList);
    PR_LOG(modlog, 1, ("C_GetMechanismList"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    PR_LOG(modlog, 3, ("  pMechanismList = 0x%p", pMechanismList));
    PR_LOG(modlog, 3, ("  pulCount = 0x%p", pulCount));
    start = PR_IntervalNow();
    rv = module_functions->C_GetMechanismList(slotID,
                                 pMechanismList,
                                 pulCount);
    nssdbg_finish_time(&counter_C_GetMechanismList,start);
    PR_LOG(modlog, 4, ("  *pulCount = 0x%x", *pulCount));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetMechanismInfo = 0;
static PRInt32 calls_C_GetMechanismInfo = 0;
CK_RV NSSDBGC_GetMechanismInfo(
  CK_SLOT_ID            slotID,
  CK_MECHANISM_TYPE     type,
  CK_MECHANISM_INFO_PTR pInfo
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetMechanismInfo);
    PR_LOG(modlog, 1, ("C_GetMechanismInfo"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    PR_LOG(modlog, 3, ("  type = 0x%x", type));
    PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
    start = PR_IntervalNow();
    rv = module_functions->C_GetMechanismInfo(slotID,
                                 type,
                                 pInfo);
    nssdbg_finish_time(&counter_C_GetMechanismInfo,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_InitToken = 0;
static PRInt32 calls_C_InitToken = 0;
CK_RV NSSDBGC_InitToken(
  CK_SLOT_ID  slotID,
  CK_CHAR_PTR pPin,
  CK_ULONG    ulPinLen,
  CK_CHAR_PTR pLabel
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_InitToken);
    PR_LOG(modlog, 1, ("C_InitToken"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    PR_LOG(modlog, 3, ("  pPin = 0x%p", pPin));
    PR_LOG(modlog, 3, ("  ulPinLen = %d", ulPinLen));
    PR_LOG(modlog, 3, ("  pLabel = 0x%p", pLabel));
    start = PR_IntervalNow();
    rv = module_functions->C_InitToken(slotID,
                                 pPin,
                                 ulPinLen,
                                 pLabel);
    nssdbg_finish_time(&counter_C_InitToken,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_InitPIN = 0;
static PRInt32 calls_C_InitPIN = 0;
CK_RV NSSDBGC_InitPIN(
  CK_SESSION_HANDLE hSession,
  CK_CHAR_PTR       pPin,
  CK_ULONG          ulPinLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_InitPIN);
    PR_LOG(modlog, 1, ("C_InitPIN"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPin = 0x%p", pPin));
    PR_LOG(modlog, 3, ("  ulPinLen = %d", ulPinLen));
    start = PR_IntervalNow();
    rv = module_functions->C_InitPIN(hSession,
                                 pPin,
                                 ulPinLen);
    nssdbg_finish_time(&counter_C_InitPIN,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SetPIN = 0;
static PRInt32 calls_C_SetPIN = 0;
CK_RV NSSDBGC_SetPIN(
  CK_SESSION_HANDLE hSession,
  CK_CHAR_PTR       pOldPin,
  CK_ULONG          ulOldLen,
  CK_CHAR_PTR       pNewPin,
  CK_ULONG          ulNewLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SetPIN);
    PR_LOG(modlog, 1, ("C_SetPIN"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pOldPin = 0x%p", pOldPin));
    PR_LOG(modlog, 3, ("  ulOldLen = %d", ulOldLen));
    PR_LOG(modlog, 3, ("  pNewPin = 0x%p", pNewPin));
    PR_LOG(modlog, 3, ("  ulNewLen = %d", ulNewLen));
    start = PR_IntervalNow();
    rv = module_functions->C_SetPIN(hSession,
                                 pOldPin,
                                 ulOldLen,
                                 pNewPin,
                                 ulNewLen);
    nssdbg_finish_time(&counter_C_SetPIN,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_OpenSession = 0;
static PRInt32 calls_C_OpenSession = 0;
static PRInt32 numOpenSessions = 0;
static PRInt32 maxOpenSessions = 0;
CK_RV NSSDBGC_OpenSession(
  CK_SLOT_ID            slotID,
  CK_FLAGS              flags,
  CK_VOID_PTR           pApplication,
  CK_NOTIFY             Notify,
  CK_SESSION_HANDLE_PTR phSession
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_OpenSession);
    PR_AtomicIncrement(&numOpenSessions);
    maxOpenSessions = PR_MAX(numOpenSessions, maxOpenSessions);
    PR_LOG(modlog, 1, ("C_OpenSession"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    PR_LOG(modlog, 3, ("  flags = 0x%x", flags));
    PR_LOG(modlog, 3, ("  pApplication = 0x%p", pApplication));
    PR_LOG(modlog, 3, ("  Notify = 0x%x", Notify));
    PR_LOG(modlog, 3, ("  phSession = 0x%p", phSession));
    start = PR_IntervalNow();
    rv = module_functions->C_OpenSession(slotID,
                                 flags,
                                 pApplication,
                                 Notify,
                                 phSession);
    nssdbg_finish_time(&counter_C_OpenSession,start);
    PR_LOG(modlog, 4, ("  *phSession = 0x%x", *phSession));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_CloseSession = 0;
static PRInt32 calls_C_CloseSession = 0;
CK_RV NSSDBGC_CloseSession(
  CK_SESSION_HANDLE hSession
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_CloseSession);
    PR_AtomicDecrement(&numOpenSessions);
    PR_LOG(modlog, 1, ("C_CloseSession"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    start = PR_IntervalNow();
    rv = module_functions->C_CloseSession(hSession);
    nssdbg_finish_time(&counter_C_CloseSession,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_CloseAllSessions = 0;
static PRInt32 calls_C_CloseAllSessions = 0;
CK_RV NSSDBGC_CloseAllSessions(
  CK_SLOT_ID slotID
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_CloseAllSessions);
    PR_LOG(modlog, 1, ("C_CloseAllSessions"));
    PR_LOG(modlog, 3, ("  slotID = 0x%x", slotID));
    start = PR_IntervalNow();
    rv = module_functions->C_CloseAllSessions(slotID);
    nssdbg_finish_time(&counter_C_CloseAllSessions,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetSessionInfo = 0;
static PRInt32 calls_C_GetSessionInfo = 0;
CK_RV NSSDBGC_GetSessionInfo(
  CK_SESSION_HANDLE   hSession,
  CK_SESSION_INFO_PTR pInfo
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetSessionInfo);
    PR_LOG(modlog, 1, ("C_GetSessionInfo"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pInfo = 0x%p", pInfo));
    start = PR_IntervalNow();
    rv = module_functions->C_GetSessionInfo(hSession,
                                 pInfo);
    nssdbg_finish_time(&counter_C_GetSessionInfo,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetOperationState = 0;
static PRInt32 calls_C_GetOperationState = 0;
CK_RV NSSDBGC_GetOperationState(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pOperationState,
  CK_ULONG_PTR      pulOperationStateLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetOperationState);
    PR_LOG(modlog, 1, ("C_GetOperationState"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pOperationState = 0x%p", pOperationState));
    PR_LOG(modlog, 3, ("  pulOperationStateLen = 0x%p", pulOperationStateLen));
    start = PR_IntervalNow();
    rv = module_functions->C_GetOperationState(hSession,
                                 pOperationState,
                                 pulOperationStateLen);
    nssdbg_finish_time(&counter_C_GetOperationState,start);
    PR_LOG(modlog, 4, ("  *pulOperationStateLen = 0x%x", *pulOperationStateLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SetOperationState = 0;
static PRInt32 calls_C_SetOperationState = 0;
CK_RV NSSDBGC_SetOperationState(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR      pOperationState,
  CK_ULONG         ulOperationStateLen,
  CK_OBJECT_HANDLE hEncryptionKey,
  CK_OBJECT_HANDLE hAuthenticationKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SetOperationState);
    PR_LOG(modlog, 1, ("C_SetOperationState"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pOperationState = 0x%p", pOperationState));
    PR_LOG(modlog, 3, ("  ulOperationStateLen = %d", ulOperationStateLen));
    PR_LOG(modlog, 3, ("  hEncryptionKey = 0x%x", hEncryptionKey));
    PR_LOG(modlog, 3, ("  hAuthenticationKey = 0x%x", hAuthenticationKey));
    start = PR_IntervalNow();
    rv = module_functions->C_SetOperationState(hSession,
                                 pOperationState,
                                 ulOperationStateLen,
                                 hEncryptionKey,
                                 hAuthenticationKey);
    nssdbg_finish_time(&counter_C_SetOperationState,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Login = 0;
static PRInt32 calls_C_Login = 0;
CK_RV NSSDBGC_Login(
  CK_SESSION_HANDLE hSession,
  CK_USER_TYPE      userType,
  CK_CHAR_PTR       pPin,
  CK_ULONG          ulPinLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Login);
    PR_LOG(modlog, 1, ("C_Login"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  userType = 0x%x", userType));
    PR_LOG(modlog, 3, ("  pPin = 0x%p", pPin));
    PR_LOG(modlog, 3, ("  ulPinLen = %d", ulPinLen));
    start = PR_IntervalNow();
    rv = module_functions->C_Login(hSession,
                                 userType,
                                 pPin,
                                 ulPinLen);
    nssdbg_finish_time(&counter_C_Login,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Logout = 0;
static PRInt32 calls_C_Logout = 0;
CK_RV NSSDBGC_Logout(
  CK_SESSION_HANDLE hSession
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Logout);
    PR_LOG(modlog, 1, ("C_Logout"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    start = PR_IntervalNow();
    rv = module_functions->C_Logout(hSession);
    nssdbg_finish_time(&counter_C_Logout,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_CreateObject = 0;
static PRInt32 calls_C_CreateObject = 0;
CK_RV NSSDBGC_CreateObject(
  CK_SESSION_HANDLE    hSession,
  CK_ATTRIBUTE_PTR     pTemplate,
  CK_ULONG             ulCount,
  CK_OBJECT_HANDLE_PTR phObject
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_CreateObject);
    PR_LOG(modlog, 1, ("C_CreateObject"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
    PR_LOG(modlog, 3, ("  phObject = 0x%p", phObject));
    print_template(pTemplate, ulCount);
    start = PR_IntervalNow();
    rv = module_functions->C_CreateObject(hSession,
                                 pTemplate,
                                 ulCount,
                                 phObject);
    nssdbg_finish_time(&counter_C_CreateObject,start);
    PR_LOG(modlog, 4, ("  *phObject = 0x%x", *phObject));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_CopyObject = 0;
static PRInt32 calls_C_CopyObject = 0;
CK_RV NSSDBGC_CopyObject(
  CK_SESSION_HANDLE    hSession,
  CK_OBJECT_HANDLE     hObject,
  CK_ATTRIBUTE_PTR     pTemplate,
  CK_ULONG             ulCount,
  CK_OBJECT_HANDLE_PTR phNewObject
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_CopyObject);
    PR_LOG(modlog, 1, ("C_CopyObject"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
    PR_LOG(modlog, 3, ("  phNewObject = 0x%p", phNewObject));
    print_template(pTemplate, ulCount);
    start = PR_IntervalNow();
    rv = module_functions->C_CopyObject(hSession,
                                 hObject,
                                 pTemplate,
                                 ulCount,
                                 phNewObject);
    nssdbg_finish_time(&counter_C_CopyObject,start);
    PR_LOG(modlog, 4, ("  *phNewObject = 0x%x", *phNewObject));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DestroyObject = 0;
static PRInt32 calls_C_DestroyObject = 0;
CK_RV NSSDBGC_DestroyObject(
  CK_SESSION_HANDLE hSession,
  CK_OBJECT_HANDLE  hObject
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DestroyObject);
    PR_LOG(modlog, 1, ("C_DestroyObject"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
    start = PR_IntervalNow();
    rv = module_functions->C_DestroyObject(hSession,
                                 hObject);
    nssdbg_finish_time(&counter_C_DestroyObject,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetObjectSize = 0;
static PRInt32 calls_C_GetObjectSize = 0;
CK_RV NSSDBGC_GetObjectSize(
  CK_SESSION_HANDLE hSession,
  CK_OBJECT_HANDLE  hObject,
  CK_ULONG_PTR      pulSize
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetObjectSize);
    PR_LOG(modlog, 1, ("C_GetObjectSize"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
    PR_LOG(modlog, 3, ("  pulSize = 0x%p", pulSize));
    start = PR_IntervalNow();
    rv = module_functions->C_GetObjectSize(hSession,
                                 hObject,
                                 pulSize);
    nssdbg_finish_time(&counter_C_GetObjectSize,start);
    PR_LOG(modlog, 4, ("  *pulSize = 0x%x", *pulSize));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetAttributeValue = 0;
static PRInt32 calls_C_GetAttributeValue = 0;
CK_RV NSSDBGC_GetAttributeValue(
  CK_SESSION_HANDLE hSession,
  CK_OBJECT_HANDLE  hObject,
  CK_ATTRIBUTE_PTR  pTemplate,
  CK_ULONG          ulCount
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetAttributeValue);
    PR_LOG(modlog, 1, ("C_GetAttributeValue"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
    start = PR_IntervalNow();
    rv = module_functions->C_GetAttributeValue(hSession,
                                 hObject,
                                 pTemplate,
                                 ulCount);
    nssdbg_finish_time(&counter_C_GetAttributeValue,start);
    print_template(pTemplate, ulCount);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SetAttributeValue = 0;
static PRInt32 calls_C_SetAttributeValue = 0;
CK_RV NSSDBGC_SetAttributeValue(
  CK_SESSION_HANDLE hSession,
  CK_OBJECT_HANDLE  hObject,
  CK_ATTRIBUTE_PTR  pTemplate,
  CK_ULONG          ulCount
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SetAttributeValue);
    PR_LOG(modlog, 1, ("C_SetAttributeValue"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  hObject = 0x%x", hObject));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
    print_template(pTemplate, ulCount);
    start = PR_IntervalNow();
    rv = module_functions->C_SetAttributeValue(hSession,
                                 hObject,
                                 pTemplate,
                                 ulCount);
    nssdbg_finish_time(&counter_C_SetAttributeValue,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_FindObjectsInit = 0;
static PRInt32 calls_C_FindObjectsInit = 0;
CK_RV NSSDBGC_FindObjectsInit(
  CK_SESSION_HANDLE hSession,
  CK_ATTRIBUTE_PTR  pTemplate,
  CK_ULONG          ulCount
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_FindObjectsInit);
    PR_LOG(modlog, 1, ("C_FindObjectsInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
    print_template(pTemplate, ulCount);
    start = PR_IntervalNow();
    rv = module_functions->C_FindObjectsInit(hSession,
                                 pTemplate,
                                 ulCount);
    nssdbg_finish_time(&counter_C_FindObjectsInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_FindObjects = 0;
static PRInt32 calls_C_FindObjects = 0;
CK_RV NSSDBGC_FindObjects(
  CK_SESSION_HANDLE    hSession,
  CK_OBJECT_HANDLE_PTR phObject,
  CK_ULONG             ulMaxObjectCount,
  CK_ULONG_PTR         pulObjectCount
)
{
    CK_RV rv;
    CK_ULONG i;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_FindObjects);
    PR_LOG(modlog, 1, ("C_FindObjects"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  phObject = 0x%p", phObject));
    PR_LOG(modlog, 3, ("  ulMaxObjectCount = %d", ulMaxObjectCount));
    PR_LOG(modlog, 3, ("  pulObjectCount = 0x%p", pulObjectCount));
    start = PR_IntervalNow();
    rv = module_functions->C_FindObjects(hSession,
                                 phObject,
                                 ulMaxObjectCount,
                                 pulObjectCount);
    nssdbg_finish_time(&counter_C_FindObjects,start);
    PR_LOG(modlog, 4, ("  *pulObjectCount = 0x%x", *pulObjectCount));
    for (i=0; i<*pulObjectCount; i++) {
	PR_LOG(modlog, 4, ("  phObject[%d] = 0x%x", i, phObject[i]));
    }
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_FindObjectsFinal = 0;
static PRInt32 calls_C_FindObjectsFinal = 0;
CK_RV NSSDBGC_FindObjectsFinal(
  CK_SESSION_HANDLE hSession
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_FindObjectsFinal);
    PR_LOG(modlog, 1, ("C_FindObjectsFinal"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    start = PR_IntervalNow();
    rv = module_functions->C_FindObjectsFinal(hSession);
    nssdbg_finish_time(&counter_C_FindObjectsFinal,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_EncryptInit = 0;
static PRInt32 calls_C_EncryptInit = 0;
CK_RV NSSDBGC_EncryptInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_EncryptInit);
    PR_LOG(modlog, 1, ("C_EncryptInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_EncryptInit(hSession,
                                 pMechanism,
                                 hKey);
    nssdbg_finish_time(&counter_C_EncryptInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Encrypt = 0;
static PRInt32 calls_C_Encrypt = 0;
CK_RV NSSDBGC_Encrypt(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pData,
  CK_ULONG          ulDataLen,
  CK_BYTE_PTR       pEncryptedData,
  CK_ULONG_PTR      pulEncryptedDataLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Encrypt);
    PR_LOG(modlog, 1, ("C_Encrypt"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
    PR_LOG(modlog, 3, ("  pEncryptedData = 0x%p", pEncryptedData));
    PR_LOG(modlog, 3, ("  pulEncryptedDataLen = 0x%p", pulEncryptedDataLen));
    start = PR_IntervalNow();
    rv = module_functions->C_Encrypt(hSession,
                                 pData,
                                 ulDataLen,
                                 pEncryptedData,
                                 pulEncryptedDataLen);
    nssdbg_finish_time(&counter_C_Encrypt,start);
    PR_LOG(modlog, 4, ("  *pulEncryptedDataLen = 0x%x", *pulEncryptedDataLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_EncryptUpdate = 0;
static PRInt32 calls_C_EncryptUpdate = 0;
CK_RV NSSDBGC_EncryptUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pPart,
  CK_ULONG          ulPartLen,
  CK_BYTE_PTR       pEncryptedPart,
  CK_ULONG_PTR      pulEncryptedPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_EncryptUpdate);
    PR_LOG(modlog, 1, ("C_EncryptUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
    PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
    PR_LOG(modlog, 3, ("  pulEncryptedPartLen = 0x%p", pulEncryptedPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_EncryptUpdate(hSession,
                                 pPart,
                                 ulPartLen,
                                 pEncryptedPart,
                                 pulEncryptedPartLen);
    nssdbg_finish_time(&counter_C_EncryptUpdate,start);
    PR_LOG(modlog, 4, ("  *pulEncryptedPartLen = 0x%x", *pulEncryptedPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_EncryptFinal = 0;
static PRInt32 calls_C_EncryptFinal = 0;
CK_RV NSSDBGC_EncryptFinal(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pLastEncryptedPart,
  CK_ULONG_PTR      pulLastEncryptedPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_EncryptFinal);
    PR_LOG(modlog, 1, ("C_EncryptFinal"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pLastEncryptedPart = 0x%p", pLastEncryptedPart));
    PR_LOG(modlog, 3, ("  pulLastEncryptedPartLen = 0x%p", pulLastEncryptedPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_EncryptFinal(hSession,
                                 pLastEncryptedPart,
                                 pulLastEncryptedPartLen);
    nssdbg_finish_time(&counter_C_EncryptFinal,start);
    PR_LOG(modlog, 4, ("  *pulLastEncryptedPartLen = 0x%x", *pulLastEncryptedPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DecryptInit = 0;
static PRInt32 calls_C_DecryptInit = 0;
CK_RV NSSDBGC_DecryptInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DecryptInit);
    PR_LOG(modlog, 1, ("C_DecryptInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_DecryptInit(hSession,
                                 pMechanism,
                                 hKey);
    nssdbg_finish_time(&counter_C_DecryptInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Decrypt = 0;
static PRInt32 calls_C_Decrypt = 0;
CK_RV NSSDBGC_Decrypt(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pEncryptedData,
  CK_ULONG          ulEncryptedDataLen,
  CK_BYTE_PTR       pData,
  CK_ULONG_PTR      pulDataLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Decrypt);
    PR_LOG(modlog, 1, ("C_Decrypt"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pEncryptedData = 0x%p", pEncryptedData));
    PR_LOG(modlog, 3, ("  ulEncryptedDataLen = %d", ulEncryptedDataLen));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  pulDataLen = 0x%p", pulDataLen));
    start = PR_IntervalNow();
    rv = module_functions->C_Decrypt(hSession,
                                 pEncryptedData,
                                 ulEncryptedDataLen,
                                 pData,
                                 pulDataLen);
    nssdbg_finish_time(&counter_C_Decrypt,start);
    PR_LOG(modlog, 4, ("  *pulDataLen = 0x%x", *pulDataLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DecryptUpdate = 0;
static PRInt32 calls_C_DecryptUpdate = 0;
CK_RV NSSDBGC_DecryptUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pEncryptedPart,
  CK_ULONG          ulEncryptedPartLen,
  CK_BYTE_PTR       pPart,
  CK_ULONG_PTR      pulPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DecryptUpdate);
    PR_LOG(modlog, 1, ("C_DecryptUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
    PR_LOG(modlog, 3, ("  ulEncryptedPartLen = %d", ulEncryptedPartLen));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  pulPartLen = 0x%p", pulPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DecryptUpdate(hSession,
                                 pEncryptedPart,
                                 ulEncryptedPartLen,
                                 pPart,
                                 pulPartLen);
    nssdbg_finish_time(&counter_C_DecryptUpdate,start);
    PR_LOG(modlog, 4, ("  *pulPartLen = 0x%x", *pulPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DecryptFinal = 0;
static PRInt32 calls_C_DecryptFinal = 0;
CK_RV NSSDBGC_DecryptFinal(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pLastPart,
  CK_ULONG_PTR      pulLastPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DecryptFinal);
    PR_LOG(modlog, 1, ("C_DecryptFinal"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pLastPart = 0x%p", pLastPart));
    PR_LOG(modlog, 3, ("  pulLastPartLen = 0x%p", pulLastPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DecryptFinal(hSession,
                                 pLastPart,
                                 pulLastPartLen);
    nssdbg_finish_time(&counter_C_DecryptFinal,start);
    PR_LOG(modlog, 4, ("  *pulLastPartLen = 0x%x", *pulLastPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DigestInit = 0;
static PRInt32 calls_C_DigestInit = 0;
CK_RV NSSDBGC_DigestInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DigestInit);
    PR_LOG(modlog, 1, ("C_DigestInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_DigestInit(hSession,
                                 pMechanism);
    nssdbg_finish_time(&counter_C_DigestInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Digest = 0;
static PRInt32 calls_C_Digest = 0;
CK_RV NSSDBGC_Digest(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pData,
  CK_ULONG          ulDataLen,
  CK_BYTE_PTR       pDigest,
  CK_ULONG_PTR      pulDigestLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Digest);
    PR_LOG(modlog, 1, ("C_Digest"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
    PR_LOG(modlog, 3, ("  pDigest = 0x%p", pDigest));
    PR_LOG(modlog, 3, ("  pulDigestLen = 0x%p", pulDigestLen));
    start = PR_IntervalNow();
    rv = module_functions->C_Digest(hSession,
                                 pData,
                                 ulDataLen,
                                 pDigest,
                                 pulDigestLen);
    nssdbg_finish_time(&counter_C_Digest,start);
    PR_LOG(modlog, 4, ("  *pulDigestLen = 0x%x", *pulDigestLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DigestUpdate = 0;
static PRInt32 calls_C_DigestUpdate = 0;
CK_RV NSSDBGC_DigestUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pPart,
  CK_ULONG          ulPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DigestUpdate);
    PR_LOG(modlog, 1, ("C_DigestUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DigestUpdate(hSession,
                                 pPart,
                                 ulPartLen);
    nssdbg_finish_time(&counter_C_DigestUpdate,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DigestKey = 0;
static PRInt32 calls_C_DigestKey = 0;
CK_RV NSSDBGC_DigestKey(
  CK_SESSION_HANDLE hSession,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DigestKey);
    PR_LOG(modlog, 1, ("C_DigestKey"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    start = PR_IntervalNow();
    rv = module_functions->C_DigestKey(hSession,
                                 hKey);
    nssdbg_finish_time(&counter_C_DigestKey,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DigestFinal = 0;
static PRInt32 calls_C_DigestFinal = 0;
CK_RV NSSDBGC_DigestFinal(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pDigest,
  CK_ULONG_PTR      pulDigestLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DigestFinal);
    PR_LOG(modlog, 1, ("C_DigestFinal"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pDigest = 0x%p", pDigest));
    PR_LOG(modlog, 3, ("  pulDigestLen = 0x%p", pulDigestLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DigestFinal(hSession,
                                 pDigest,
                                 pulDigestLen);
    nssdbg_finish_time(&counter_C_DigestFinal,start);
    PR_LOG(modlog, 4, ("  *pulDigestLen = 0x%x", *pulDigestLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SignInit = 0;
static PRInt32 calls_C_SignInit = 0;
CK_RV NSSDBGC_SignInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SignInit);
    PR_LOG(modlog, 1, ("C_SignInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_SignInit(hSession,
                                 pMechanism,
                                 hKey);
    nssdbg_finish_time(&counter_C_SignInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Sign = 0;
static PRInt32 calls_C_Sign = 0;
CK_RV NSSDBGC_Sign(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pData,
  CK_ULONG          ulDataLen,
  CK_BYTE_PTR       pSignature,
  CK_ULONG_PTR      pulSignatureLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Sign);
    PR_LOG(modlog, 1, ("C_Sign"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
    PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
    PR_LOG(modlog, 3, ("  pulSignatureLen = 0x%p", pulSignatureLen));
    start = PR_IntervalNow();
    rv = module_functions->C_Sign(hSession,
                                 pData,
                                 ulDataLen,
                                 pSignature,
                                 pulSignatureLen);
    nssdbg_finish_time(&counter_C_Sign,start);
    PR_LOG(modlog, 4, ("  *pulSignatureLen = 0x%x", *pulSignatureLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SignUpdate = 0;
static PRInt32 calls_C_SignUpdate = 0;
CK_RV NSSDBGC_SignUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pPart,
  CK_ULONG          ulPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SignUpdate);
    PR_LOG(modlog, 1, ("C_SignUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_SignUpdate(hSession,
                                 pPart,
                                 ulPartLen);
    nssdbg_finish_time(&counter_C_SignUpdate,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SignFinal = 0;
static PRInt32 calls_C_SignFinal = 0;
CK_RV NSSDBGC_SignFinal(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pSignature,
  CK_ULONG_PTR      pulSignatureLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SignFinal);
    PR_LOG(modlog, 1, ("C_SignFinal"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
    PR_LOG(modlog, 3, ("  pulSignatureLen = 0x%p", pulSignatureLen));
    start = PR_IntervalNow();
    rv = module_functions->C_SignFinal(hSession,
                                 pSignature,
                                 pulSignatureLen);
    nssdbg_finish_time(&counter_C_SignFinal,start);
    PR_LOG(modlog, 4, ("  *pulSignatureLen = 0x%x", *pulSignatureLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SignRecoverInit = 0;
static PRInt32 calls_C_SignRecoverInit = 0;
CK_RV NSSDBGC_SignRecoverInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SignRecoverInit);
    PR_LOG(modlog, 1, ("C_SignRecoverInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_SignRecoverInit(hSession,
                                 pMechanism,
                                 hKey);
    nssdbg_finish_time(&counter_C_SignRecoverInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SignRecover = 0;
static PRInt32 calls_C_SignRecover = 0;
CK_RV NSSDBGC_SignRecover(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pData,
  CK_ULONG          ulDataLen,
  CK_BYTE_PTR       pSignature,
  CK_ULONG_PTR      pulSignatureLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SignRecover);
    PR_LOG(modlog, 1, ("C_SignRecover"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
    PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
    PR_LOG(modlog, 3, ("  pulSignatureLen = 0x%p", pulSignatureLen));
    start = PR_IntervalNow();
    rv = module_functions->C_SignRecover(hSession,
                                 pData,
                                 ulDataLen,
                                 pSignature,
                                 pulSignatureLen);
    nssdbg_finish_time(&counter_C_SignRecover,start);
    PR_LOG(modlog, 4, ("  *pulSignatureLen = 0x%x", *pulSignatureLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_VerifyInit = 0;
static PRInt32 calls_C_VerifyInit = 0;
CK_RV NSSDBGC_VerifyInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_VerifyInit);
    PR_LOG(modlog, 1, ("C_VerifyInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_VerifyInit(hSession,
                                 pMechanism,
                                 hKey);
    nssdbg_finish_time(&counter_C_VerifyInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_Verify = 0;
static PRInt32 calls_C_Verify = 0;
CK_RV NSSDBGC_Verify(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pData,
  CK_ULONG          ulDataLen,
  CK_BYTE_PTR       pSignature,
  CK_ULONG          ulSignatureLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_Verify);
    PR_LOG(modlog, 1, ("C_Verify"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  ulDataLen = %d", ulDataLen));
    PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
    PR_LOG(modlog, 3, ("  ulSignatureLen = %d", ulSignatureLen));
    start = PR_IntervalNow();
    rv = module_functions->C_Verify(hSession,
                                 pData,
                                 ulDataLen,
                                 pSignature,
                                 ulSignatureLen);
    nssdbg_finish_time(&counter_C_Verify,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_VerifyUpdate = 0;
static PRInt32 calls_C_VerifyUpdate = 0;
CK_RV NSSDBGC_VerifyUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pPart,
  CK_ULONG          ulPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_VerifyUpdate);
    PR_LOG(modlog, 1, ("C_VerifyUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_VerifyUpdate(hSession,
                                 pPart,
                                 ulPartLen);
    nssdbg_finish_time(&counter_C_VerifyUpdate,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_VerifyFinal = 0;
static PRInt32 calls_C_VerifyFinal = 0;
CK_RV NSSDBGC_VerifyFinal(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pSignature,
  CK_ULONG          ulSignatureLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_VerifyFinal);
    PR_LOG(modlog, 1, ("C_VerifyFinal"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
    PR_LOG(modlog, 3, ("  ulSignatureLen = %d", ulSignatureLen));
    start = PR_IntervalNow();
    rv = module_functions->C_VerifyFinal(hSession,
                                 pSignature,
                                 ulSignatureLen);
    nssdbg_finish_time(&counter_C_VerifyFinal,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_VerifyRecoverInit = 0;
static PRInt32 calls_C_VerifyRecoverInit = 0;
CK_RV NSSDBGC_VerifyRecoverInit(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_VerifyRecoverInit);
    PR_LOG(modlog, 1, ("C_VerifyRecoverInit"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_VerifyRecoverInit(hSession,
                                 pMechanism,
                                 hKey);
    nssdbg_finish_time(&counter_C_VerifyRecoverInit,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_VerifyRecover = 0;
static PRInt32 calls_C_VerifyRecover = 0;
CK_RV NSSDBGC_VerifyRecover(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pSignature,
  CK_ULONG          ulSignatureLen,
  CK_BYTE_PTR       pData,
  CK_ULONG_PTR      pulDataLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_VerifyRecover);
    PR_LOG(modlog, 1, ("C_VerifyRecover"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pSignature = 0x%p", pSignature));
    PR_LOG(modlog, 3, ("  ulSignatureLen = %d", ulSignatureLen));
    PR_LOG(modlog, 3, ("  pData = 0x%p", pData));
    PR_LOG(modlog, 3, ("  pulDataLen = 0x%p", pulDataLen));
    start = PR_IntervalNow();
    rv = module_functions->C_VerifyRecover(hSession,
                                 pSignature,
                                 ulSignatureLen,
                                 pData,
                                 pulDataLen);
    nssdbg_finish_time(&counter_C_VerifyRecover,start);
    PR_LOG(modlog, 4, ("  *pulDataLen = 0x%x", *pulDataLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DigestEncryptUpdate = 0;
static PRInt32 calls_C_DigestEncryptUpdate = 0;
CK_RV NSSDBGC_DigestEncryptUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pPart,
  CK_ULONG          ulPartLen,
  CK_BYTE_PTR       pEncryptedPart,
  CK_ULONG_PTR      pulEncryptedPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DigestEncryptUpdate);
    PR_LOG(modlog, 1, ("C_DigestEncryptUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
    PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
    PR_LOG(modlog, 3, ("  pulEncryptedPartLen = 0x%p", pulEncryptedPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DigestEncryptUpdate(hSession,
                                 pPart,
                                 ulPartLen,
                                 pEncryptedPart,
                                 pulEncryptedPartLen);
    nssdbg_finish_time(&counter_C_DigestEncryptUpdate,start);
    PR_LOG(modlog, 4, ("  *pulEncryptedPartLen = 0x%x", *pulEncryptedPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DecryptDigestUpdate = 0;
static PRInt32 calls_C_DecryptDigestUpdate = 0;
CK_RV NSSDBGC_DecryptDigestUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pEncryptedPart,
  CK_ULONG          ulEncryptedPartLen,
  CK_BYTE_PTR       pPart,
  CK_ULONG_PTR      pulPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DecryptDigestUpdate);
    PR_LOG(modlog, 1, ("C_DecryptDigestUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
    PR_LOG(modlog, 3, ("  ulEncryptedPartLen = %d", ulEncryptedPartLen));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  pulPartLen = 0x%p", pulPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DecryptDigestUpdate(hSession,
                                 pEncryptedPart,
                                 ulEncryptedPartLen,
                                 pPart,
                                 pulPartLen);
    nssdbg_finish_time(&counter_C_DecryptDigestUpdate,start);
    PR_LOG(modlog, 4, ("  *pulPartLen = 0x%x", *pulPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SignEncryptUpdate = 0;
static PRInt32 calls_C_SignEncryptUpdate = 0;
CK_RV NSSDBGC_SignEncryptUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pPart,
  CK_ULONG          ulPartLen,
  CK_BYTE_PTR       pEncryptedPart,
  CK_ULONG_PTR      pulEncryptedPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SignEncryptUpdate);
    PR_LOG(modlog, 1, ("C_SignEncryptUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  ulPartLen = %d", ulPartLen));
    PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
    PR_LOG(modlog, 3, ("  pulEncryptedPartLen = 0x%p", pulEncryptedPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_SignEncryptUpdate(hSession,
                                 pPart,
                                 ulPartLen,
                                 pEncryptedPart,
                                 pulEncryptedPartLen);
    nssdbg_finish_time(&counter_C_SignEncryptUpdate,start);
    PR_LOG(modlog, 4, ("  *pulEncryptedPartLen = 0x%x", *pulEncryptedPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DecryptVerifyUpdate = 0;
static PRInt32 calls_C_DecryptVerifyUpdate = 0;
CK_RV NSSDBGC_DecryptVerifyUpdate(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pEncryptedPart,
  CK_ULONG          ulEncryptedPartLen,
  CK_BYTE_PTR       pPart,
  CK_ULONG_PTR      pulPartLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DecryptVerifyUpdate);
    PR_LOG(modlog, 1, ("C_DecryptVerifyUpdate"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pEncryptedPart = 0x%p", pEncryptedPart));
    PR_LOG(modlog, 3, ("  ulEncryptedPartLen = %d", ulEncryptedPartLen));
    PR_LOG(modlog, 3, ("  pPart = 0x%p", pPart));
    PR_LOG(modlog, 3, ("  pulPartLen = 0x%p", pulPartLen));
    start = PR_IntervalNow();
    rv = module_functions->C_DecryptVerifyUpdate(hSession,
                                 pEncryptedPart,
                                 ulEncryptedPartLen,
                                 pPart,
                                 pulPartLen);
    nssdbg_finish_time(&counter_C_DecryptVerifyUpdate,start);
    PR_LOG(modlog, 4, ("  *pulPartLen = 0x%x", *pulPartLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GenerateKey = 0;
static PRInt32 calls_C_GenerateKey = 0;
CK_RV NSSDBGC_GenerateKey(
  CK_SESSION_HANDLE    hSession,
  CK_MECHANISM_PTR     pMechanism,
  CK_ATTRIBUTE_PTR     pTemplate,
  CK_ULONG             ulCount,
  CK_OBJECT_HANDLE_PTR phKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GenerateKey);
    PR_LOG(modlog, 1, ("C_GenerateKey"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulCount = %d", ulCount));
    PR_LOG(modlog, 3, ("  phKey = 0x%p", phKey));
    print_template(pTemplate, ulCount);
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_GenerateKey(hSession,
                                 pMechanism,
                                 pTemplate,
                                 ulCount,
                                 phKey);
    nssdbg_finish_time(&counter_C_GenerateKey,start);
    PR_LOG(modlog, 4, ("  *phKey = 0x%x", *phKey));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GenerateKeyPair = 0;
static PRInt32 calls_C_GenerateKeyPair = 0;
CK_RV NSSDBGC_GenerateKeyPair(
  CK_SESSION_HANDLE    hSession,
  CK_MECHANISM_PTR     pMechanism,
  CK_ATTRIBUTE_PTR     pPublicKeyTemplate,
  CK_ULONG             ulPublicKeyAttributeCount,
  CK_ATTRIBUTE_PTR     pPrivateKeyTemplate,
  CK_ULONG             ulPrivateKeyAttributeCount,
  CK_OBJECT_HANDLE_PTR phPublicKey,
  CK_OBJECT_HANDLE_PTR phPrivateKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GenerateKeyPair);
    PR_LOG(modlog, 1, ("C_GenerateKeyPair"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  pPublicKeyTemplate = 0x%p", pPublicKeyTemplate));
    PR_LOG(modlog, 3, ("  ulPublicKeyAttributeCount = %d", ulPublicKeyAttributeCount));
    PR_LOG(modlog, 3, ("  pPrivateKeyTemplate = 0x%p", pPrivateKeyTemplate));
    PR_LOG(modlog, 3, ("  ulPrivateKeyAttributeCount = %d", ulPrivateKeyAttributeCount));
    PR_LOG(modlog, 3, ("  phPublicKey = 0x%p", phPublicKey));
    PR_LOG(modlog, 3, ("  phPrivateKey = 0x%p", phPrivateKey));
    print_template(pPublicKeyTemplate, ulPublicKeyAttributeCount);
    print_template(pPrivateKeyTemplate, ulPrivateKeyAttributeCount);
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_GenerateKeyPair(hSession,
                                 pMechanism,
                                 pPublicKeyTemplate,
                                 ulPublicKeyAttributeCount,
                                 pPrivateKeyTemplate,
                                 ulPrivateKeyAttributeCount,
                                 phPublicKey,
                                 phPrivateKey);
    nssdbg_finish_time(&counter_C_GenerateKeyPair,start);
    PR_LOG(modlog, 4, ("  *phPublicKey = 0x%x", *phPublicKey));
    PR_LOG(modlog, 4, ("  *phPrivateKey = 0x%x", *phPrivateKey));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_WrapKey = 0;
static PRInt32 calls_C_WrapKey = 0;
CK_RV NSSDBGC_WrapKey(
  CK_SESSION_HANDLE hSession,
  CK_MECHANISM_PTR  pMechanism,
  CK_OBJECT_HANDLE  hWrappingKey,
  CK_OBJECT_HANDLE  hKey,
  CK_BYTE_PTR       pWrappedKey,
  CK_ULONG_PTR      pulWrappedKeyLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_WrapKey);
    PR_LOG(modlog, 1, ("C_WrapKey"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hWrappingKey = 0x%x", hWrappingKey));
    PR_LOG(modlog, 3, ("  hKey = 0x%x", hKey));
    PR_LOG(modlog, 3, ("  pWrappedKey = 0x%p", pWrappedKey));
    PR_LOG(modlog, 3, ("  pulWrappedKeyLen = 0x%p", pulWrappedKeyLen));
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_WrapKey(hSession,
                                 pMechanism,
                                 hWrappingKey,
                                 hKey,
                                 pWrappedKey,
                                 pulWrappedKeyLen);
    nssdbg_finish_time(&counter_C_WrapKey,start);
    PR_LOG(modlog, 4, ("  *pulWrappedKeyLen = 0x%x", *pulWrappedKeyLen));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_UnwrapKey = 0;
static PRInt32 calls_C_UnwrapKey = 0;
CK_RV NSSDBGC_UnwrapKey(
  CK_SESSION_HANDLE    hSession,
  CK_MECHANISM_PTR     pMechanism,
  CK_OBJECT_HANDLE     hUnwrappingKey,
  CK_BYTE_PTR          pWrappedKey,
  CK_ULONG             ulWrappedKeyLen,
  CK_ATTRIBUTE_PTR     pTemplate,
  CK_ULONG             ulAttributeCount,
  CK_OBJECT_HANDLE_PTR phKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_UnwrapKey);
    PR_LOG(modlog, 1, ("C_UnwrapKey"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hUnwrappingKey = 0x%x", hUnwrappingKey));
    PR_LOG(modlog, 3, ("  pWrappedKey = 0x%p", pWrappedKey));
    PR_LOG(modlog, 3, ("  ulWrappedKeyLen = %d", ulWrappedKeyLen));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulAttributeCount = %d", ulAttributeCount));
    PR_LOG(modlog, 3, ("  phKey = 0x%p", phKey));
    print_template(pTemplate, ulAttributeCount);
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_UnwrapKey(hSession,
                                 pMechanism,
                                 hUnwrappingKey,
                                 pWrappedKey,
                                 ulWrappedKeyLen,
                                 pTemplate,
                                 ulAttributeCount,
                                 phKey);
    nssdbg_finish_time(&counter_C_UnwrapKey,start);
    PR_LOG(modlog, 4, ("  *phKey = 0x%x", *phKey));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_DeriveKey = 0;
static PRInt32 calls_C_DeriveKey = 0;
CK_RV NSSDBGC_DeriveKey(
  CK_SESSION_HANDLE    hSession,
  CK_MECHANISM_PTR     pMechanism,
  CK_OBJECT_HANDLE     hBaseKey,
  CK_ATTRIBUTE_PTR     pTemplate,
  CK_ULONG             ulAttributeCount,
  CK_OBJECT_HANDLE_PTR phKey
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_DeriveKey);
    PR_LOG(modlog, 1, ("C_DeriveKey"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pMechanism = 0x%p", pMechanism));
    PR_LOG(modlog, 3, ("  hBaseKey = 0x%x", hBaseKey));
    PR_LOG(modlog, 3, ("  pTemplate = 0x%p", pTemplate));
    PR_LOG(modlog, 3, ("  ulAttributeCount = %d", ulAttributeCount));
    PR_LOG(modlog, 3, ("  phKey = 0x%p", phKey));
    print_template(pTemplate, ulAttributeCount);
    print_mechanism(pMechanism);
    start = PR_IntervalNow();
    rv = module_functions->C_DeriveKey(hSession,
                                 pMechanism,
                                 hBaseKey,
                                 pTemplate,
                                 ulAttributeCount,
                                 phKey);
    nssdbg_finish_time(&counter_C_DeriveKey,start);
    PR_LOG(modlog, 4, ("  *phKey = 0x%x", *phKey));
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_SeedRandom = 0;
static PRInt32 calls_C_SeedRandom = 0;
CK_RV NSSDBGC_SeedRandom(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       pSeed,
  CK_ULONG          ulSeedLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_SeedRandom);
    PR_LOG(modlog, 1, ("C_SeedRandom"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  pSeed = 0x%p", pSeed));
    PR_LOG(modlog, 3, ("  ulSeedLen = %d", ulSeedLen));
    start = PR_IntervalNow();
    rv = module_functions->C_SeedRandom(hSession,
                                 pSeed,
                                 ulSeedLen);
    nssdbg_finish_time(&counter_C_SeedRandom,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GenerateRandom = 0;
static PRInt32 calls_C_GenerateRandom = 0;
CK_RV NSSDBGC_GenerateRandom(
  CK_SESSION_HANDLE hSession,
  CK_BYTE_PTR       RandomData,
  CK_ULONG          ulRandomLen
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GenerateRandom);
    PR_LOG(modlog, 1, ("C_GenerateRandom"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    PR_LOG(modlog, 3, ("  RandomData = 0x%p", RandomData));
    PR_LOG(modlog, 3, ("  ulRandomLen = %d", ulRandomLen));
    start = PR_IntervalNow();
    rv = module_functions->C_GenerateRandom(hSession,
                                 RandomData,
                                 ulRandomLen);
    nssdbg_finish_time(&counter_C_GenerateRandom,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_GetFunctionStatus = 0;
static PRInt32 calls_C_GetFunctionStatus = 0;
CK_RV NSSDBGC_GetFunctionStatus(
  CK_SESSION_HANDLE hSession
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_GetFunctionStatus);
    PR_LOG(modlog, 1, ("C_GetFunctionStatus"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    start = PR_IntervalNow();
    rv = module_functions->C_GetFunctionStatus(hSession);
    nssdbg_finish_time(&counter_C_GetFunctionStatus,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_CancelFunction = 0;
static PRInt32 calls_C_CancelFunction = 0;
CK_RV NSSDBGC_CancelFunction(
  CK_SESSION_HANDLE hSession
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_CancelFunction);
    PR_LOG(modlog, 1, ("C_CancelFunction"));
    PR_LOG(modlog, 3, ("  hSession = 0x%x", hSession));
    start = PR_IntervalNow();
    rv = module_functions->C_CancelFunction(hSession);
    nssdbg_finish_time(&counter_C_CancelFunction,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

static PRInt32 counter_C_WaitForSlotEvent = 0;
static PRInt32 calls_C_WaitForSlotEvent = 0;
CK_RV NSSDBGC_WaitForSlotEvent(
  CK_FLAGS       flags,
  CK_SLOT_ID_PTR pSlot,
  CK_VOID_PTR    pRserved
)
{
    CK_RV rv;
    PRIntervalTime start;
    PR_AtomicIncrement(&calls_C_WaitForSlotEvent);
    PR_LOG(modlog, 1, ("C_WaitForSlotEvent"));
    PR_LOG(modlog, 3, ("  flags = 0x%x", flags));
    PR_LOG(modlog, 3, ("  pSlot = 0x%p", pSlot));
    PR_LOG(modlog, 3, ("  pRserved = 0x%p", pRserved));
    start = PR_IntervalNow();
    rv = module_functions->C_WaitForSlotEvent(flags,
                                 pSlot,
                                 pRserved);
    nssdbg_finish_time(&counter_C_WaitForSlotEvent,start);
    PR_LOG(modlog, 1, ("  rv = 0x%x\n", rv));
    return rv;
}

CK_FUNCTION_LIST_PTR nss_InsertDeviceLog(
  CK_FUNCTION_LIST_PTR devEPV
)
{
    module_functions = devEPV;
    modlog = PR_NewLogModule("nss_mod_log");
    debug_functions.C_Initialize = NSSDBGC_Initialize;
    debug_functions.C_Finalize = NSSDBGC_Finalize;
    debug_functions.C_GetInfo = NSSDBGC_GetInfo;
    debug_functions.C_GetFunctionList = NSSDBGC_GetFunctionList;
    debug_functions.C_GetSlotList = NSSDBGC_GetSlotList;
    debug_functions.C_GetSlotInfo = NSSDBGC_GetSlotInfo;
    debug_functions.C_GetTokenInfo = NSSDBGC_GetTokenInfo;
    debug_functions.C_GetMechanismList = NSSDBGC_GetMechanismList;
    debug_functions.C_GetMechanismInfo = NSSDBGC_GetMechanismInfo;
    debug_functions.C_InitToken = NSSDBGC_InitToken;
    debug_functions.C_InitPIN = NSSDBGC_InitPIN;
    debug_functions.C_SetPIN = NSSDBGC_SetPIN;
    debug_functions.C_OpenSession = NSSDBGC_OpenSession;
    debug_functions.C_CloseSession = NSSDBGC_CloseSession;
    debug_functions.C_CloseAllSessions = NSSDBGC_CloseAllSessions;
    debug_functions.C_GetSessionInfo = NSSDBGC_GetSessionInfo;
    debug_functions.C_GetOperationState = NSSDBGC_GetOperationState;
    debug_functions.C_SetOperationState = NSSDBGC_SetOperationState;
    debug_functions.C_Login = NSSDBGC_Login;
    debug_functions.C_Logout = NSSDBGC_Logout;
    debug_functions.C_CreateObject = NSSDBGC_CreateObject;
    debug_functions.C_CopyObject = NSSDBGC_CopyObject;
    debug_functions.C_DestroyObject = NSSDBGC_DestroyObject;
    debug_functions.C_GetObjectSize = NSSDBGC_GetObjectSize;
    debug_functions.C_GetAttributeValue = NSSDBGC_GetAttributeValue;
    debug_functions.C_SetAttributeValue = NSSDBGC_SetAttributeValue;
    debug_functions.C_FindObjectsInit = NSSDBGC_FindObjectsInit;
    debug_functions.C_FindObjects = NSSDBGC_FindObjects;
    debug_functions.C_FindObjectsFinal = NSSDBGC_FindObjectsFinal;
    debug_functions.C_EncryptInit = NSSDBGC_EncryptInit;
    debug_functions.C_Encrypt = NSSDBGC_Encrypt;
    debug_functions.C_EncryptUpdate = NSSDBGC_EncryptUpdate;
    debug_functions.C_EncryptFinal = NSSDBGC_EncryptFinal;
    debug_functions.C_DecryptInit = NSSDBGC_DecryptInit;
    debug_functions.C_Decrypt = NSSDBGC_Decrypt;
    debug_functions.C_DecryptUpdate = NSSDBGC_DecryptUpdate;
    debug_functions.C_DecryptFinal = NSSDBGC_DecryptFinal;
    debug_functions.C_DigestInit = NSSDBGC_DigestInit;
    debug_functions.C_Digest = NSSDBGC_Digest;
    debug_functions.C_DigestUpdate = NSSDBGC_DigestUpdate;
    debug_functions.C_DigestKey = NSSDBGC_DigestKey;
    debug_functions.C_DigestFinal = NSSDBGC_DigestFinal;
    debug_functions.C_SignInit = NSSDBGC_SignInit;
    debug_functions.C_Sign = NSSDBGC_Sign;
    debug_functions.C_SignUpdate = NSSDBGC_SignUpdate;
    debug_functions.C_SignFinal = NSSDBGC_SignFinal;
    debug_functions.C_SignRecoverInit = NSSDBGC_SignRecoverInit;
    debug_functions.C_SignRecover = NSSDBGC_SignRecover;
    debug_functions.C_VerifyInit = NSSDBGC_VerifyInit;
    debug_functions.C_Verify = NSSDBGC_Verify;
    debug_functions.C_VerifyUpdate = NSSDBGC_VerifyUpdate;
    debug_functions.C_VerifyFinal = NSSDBGC_VerifyFinal;
    debug_functions.C_VerifyRecoverInit = NSSDBGC_VerifyRecoverInit;
    debug_functions.C_VerifyRecover = NSSDBGC_VerifyRecover;
    debug_functions.C_DigestEncryptUpdate = NSSDBGC_DigestEncryptUpdate;
    debug_functions.C_DecryptDigestUpdate = NSSDBGC_DecryptDigestUpdate;
    debug_functions.C_SignEncryptUpdate = NSSDBGC_SignEncryptUpdate;
    debug_functions.C_DecryptVerifyUpdate = NSSDBGC_DecryptVerifyUpdate;
    debug_functions.C_GenerateKey = NSSDBGC_GenerateKey;
    debug_functions.C_GenerateKeyPair = NSSDBGC_GenerateKeyPair;
    debug_functions.C_WrapKey = NSSDBGC_WrapKey;
    debug_functions.C_UnwrapKey = NSSDBGC_UnwrapKey;
    debug_functions.C_DeriveKey = NSSDBGC_DeriveKey;
    debug_functions.C_SeedRandom = NSSDBGC_SeedRandom;
    debug_functions.C_GenerateRandom = NSSDBGC_GenerateRandom;
    debug_functions.C_GetFunctionStatus = NSSDBGC_GetFunctionStatus;
    debug_functions.C_CancelFunction = NSSDBGC_CancelFunction;
    debug_functions.C_WaitForSlotEvent = NSSDBGC_WaitForSlotEvent;
    return &debug_functions;
}

static void print_final_statistics(void)
{
    int total_calls = 0;
    PRInt32 total_time = 0;
    char *fname;
    FILE *outfile = NULL;

    fname = PR_GetEnv("NSS_OUTPUT_FILE");
    if (fname) {
	outfile = fopen(fname,"w+");
    }
    if (!outfile) {
	outfile = stdout;
    }
	

    fprintf(outfile,"%-25s %10s %11s %10s %10s\n", "Function", "# Calls", "Time (ms)", "Avg. (ms)", "% Time");
    fprintf(outfile,"\n");
    total_calls += calls_C_CancelFunction;
    total_time += counter_C_CancelFunction;
    total_calls += calls_C_CloseAllSessions;
    total_time += counter_C_CloseAllSessions;
    total_calls += calls_C_CloseSession;
    total_time += counter_C_CloseSession;
    total_calls += calls_C_CopyObject;
    total_time += counter_C_CopyObject;
    total_calls += calls_C_CreateObject;
    total_time += counter_C_CreateObject;
    total_calls += calls_C_Decrypt;
    total_time += counter_C_Decrypt;
    total_calls += calls_C_DecryptDigestUpdate;
    total_time += counter_C_DecryptDigestUpdate;
    total_calls += calls_C_DecryptFinal;
    total_time += counter_C_DecryptFinal;
    total_calls += calls_C_DecryptInit;
    total_time += counter_C_DecryptInit;
    total_calls += calls_C_DecryptUpdate;
    total_time += counter_C_DecryptUpdate;
    total_calls += calls_C_DecryptVerifyUpdate;
    total_time += counter_C_DecryptVerifyUpdate;
    total_calls += calls_C_DeriveKey;
    total_time += counter_C_DeriveKey;
    total_calls += calls_C_DestroyObject;
    total_time += counter_C_DestroyObject;
    total_calls += calls_C_Digest;
    total_time += counter_C_Digest;
    total_calls += calls_C_DigestEncryptUpdate;
    total_time += counter_C_DigestEncryptUpdate;
    total_calls += calls_C_DigestFinal;
    total_time += counter_C_DigestFinal;
    total_calls += calls_C_DigestInit;
    total_time += counter_C_DigestInit;
    total_calls += calls_C_DigestKey;
    total_time += counter_C_DigestKey;
    total_calls += calls_C_DigestUpdate;
    total_time += counter_C_DigestUpdate;
    total_calls += calls_C_Encrypt;
    total_time += counter_C_Encrypt;
    total_calls += calls_C_EncryptFinal;
    total_time += counter_C_EncryptFinal;
    total_calls += calls_C_EncryptInit;
    total_time += counter_C_EncryptInit;
    total_calls += calls_C_EncryptUpdate;
    total_time += counter_C_EncryptUpdate;
    total_calls += calls_C_Finalize;
    total_time += counter_C_Finalize;
    total_calls += calls_C_FindObjects;
    total_time += counter_C_FindObjects;
    total_calls += calls_C_FindObjectsFinal;
    total_time += counter_C_FindObjectsFinal;
    total_calls += calls_C_FindObjectsInit;
    total_time += counter_C_FindObjectsInit;
    total_calls += calls_C_GenerateKey;
    total_time += counter_C_GenerateKey;
    total_calls += calls_C_GenerateKeyPair;
    total_time += counter_C_GenerateKeyPair;
    total_calls += calls_C_GenerateRandom;
    total_time += counter_C_GenerateRandom;
    total_calls += calls_C_GetAttributeValue;
    total_time += counter_C_GetAttributeValue;
    total_calls += calls_C_GetFunctionList;
    total_time += counter_C_GetFunctionList;
    total_calls += calls_C_GetFunctionStatus;
    total_time += counter_C_GetFunctionStatus;
    total_calls += calls_C_GetInfo;
    total_time += counter_C_GetInfo;
    total_calls += calls_C_GetMechanismInfo;
    total_time += counter_C_GetMechanismInfo;
    total_calls += calls_C_GetMechanismList;
    total_time += counter_C_GetMechanismList;
    total_calls += calls_C_GetObjectSize;
    total_time += counter_C_GetObjectSize;
    total_calls += calls_C_GetOperationState;
    total_time += counter_C_GetOperationState;
    total_calls += calls_C_GetSessionInfo;
    total_time += counter_C_GetSessionInfo;
    total_calls += calls_C_GetSlotInfo;
    total_time += counter_C_GetSlotInfo;
    total_calls += calls_C_GetSlotList;
    total_time += counter_C_GetSlotList;
    total_calls += calls_C_GetTokenInfo;
    total_time += counter_C_GetTokenInfo;
    total_calls += calls_C_InitPIN;
    total_time += counter_C_InitPIN;
    total_calls += calls_C_InitToken;
    total_time += counter_C_InitToken;
    total_calls += calls_C_Initialize;
    total_time += counter_C_Initialize;
    total_calls += calls_C_Login;
    total_time += counter_C_Login;
    total_calls += calls_C_Logout;
    total_time += counter_C_Logout;
    total_calls += calls_C_OpenSession;
    total_time += counter_C_OpenSession;
    total_calls += calls_C_SeedRandom;
    total_time += counter_C_SeedRandom;
    total_calls += calls_C_SetAttributeValue;
    total_time += counter_C_SetAttributeValue;
    total_calls += calls_C_SetOperationState;
    total_time += counter_C_SetOperationState;
    total_calls += calls_C_SetPIN;
    total_time += counter_C_SetPIN;
    total_calls += calls_C_Sign;
    total_time += counter_C_Sign;
    total_calls += calls_C_SignEncryptUpdate;
    total_time += counter_C_SignEncryptUpdate;
    total_calls += calls_C_SignFinal;
    total_time += counter_C_SignFinal;
    total_calls += calls_C_SignInit;
    total_time += counter_C_SignInit;
    total_calls += calls_C_SignRecover;
    total_time += counter_C_SignRecover;
    total_calls += calls_C_SignRecoverInit;
    total_time += counter_C_SignRecoverInit;
    total_calls += calls_C_SignUpdate;
    total_time += counter_C_SignUpdate;
    total_calls += calls_C_UnwrapKey;
    total_time += counter_C_UnwrapKey;
    total_calls += calls_C_Verify;
    total_time += counter_C_Verify;
    total_calls += calls_C_VerifyFinal;
    total_time += counter_C_VerifyFinal;
    total_calls += calls_C_VerifyInit;
    total_time += counter_C_VerifyInit;
    total_calls += calls_C_VerifyRecover;
    total_time += counter_C_VerifyRecover;
    total_calls += calls_C_VerifyRecoverInit;
    total_time += counter_C_VerifyRecoverInit;
    total_calls += calls_C_VerifyUpdate;
    total_time += counter_C_VerifyUpdate;
    total_calls += calls_C_WaitForSlotEvent;
    total_time += counter_C_WaitForSlotEvent;
    total_calls += calls_C_WrapKey;
    total_time += counter_C_WrapKey;
    fprintf(outfile,"%-25s %10d %10d ", "C_CancelFunction", calls_C_CancelFunction, counter_C_CancelFunction);
    if (calls_C_CancelFunction > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_CancelFunction / (float)calls_C_CancelFunction);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_CancelFunction / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_CloseAllSessions", calls_C_CloseAllSessions, counter_C_CloseAllSessions);
    if (calls_C_CloseAllSessions > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_CloseAllSessions / (float)calls_C_CloseAllSessions);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_CloseAllSessions / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_CloseSession", calls_C_CloseSession, counter_C_CloseSession);
    if (calls_C_CloseSession > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_CloseSession / (float)calls_C_CloseSession);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_CloseSession / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_CopyObject", calls_C_CopyObject, counter_C_CopyObject);
    if (calls_C_CopyObject > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_CopyObject / (float)calls_C_CopyObject);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_CopyObject / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_CreateObject", calls_C_CreateObject, counter_C_CreateObject);
    if (calls_C_CreateObject > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_CreateObject / (float)calls_C_CreateObject);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_CreateObject / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Decrypt", calls_C_Decrypt, counter_C_Decrypt);
    if (calls_C_Decrypt > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Decrypt / (float)calls_C_Decrypt);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Decrypt / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DecryptDigestUpdate", calls_C_DecryptDigestUpdate, counter_C_DecryptDigestUpdate);
    if (calls_C_DecryptDigestUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DecryptDigestUpdate / (float)calls_C_DecryptDigestUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DecryptDigestUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DecryptFinal", calls_C_DecryptFinal, counter_C_DecryptFinal);
    if (calls_C_DecryptFinal > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DecryptFinal / (float)calls_C_DecryptFinal);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DecryptFinal / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DecryptInit", calls_C_DecryptInit, counter_C_DecryptInit);
    if (calls_C_DecryptInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DecryptInit / (float)calls_C_DecryptInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DecryptInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DecryptUpdate", calls_C_DecryptUpdate, counter_C_DecryptUpdate);
    if (calls_C_DecryptUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DecryptUpdate / (float)calls_C_DecryptUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DecryptUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DecryptVerifyUpdate", calls_C_DecryptVerifyUpdate, counter_C_DecryptVerifyUpdate);
    if (calls_C_DecryptVerifyUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DecryptVerifyUpdate / (float)calls_C_DecryptVerifyUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DecryptVerifyUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DeriveKey", calls_C_DeriveKey, counter_C_DeriveKey);
    if (calls_C_DeriveKey > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DeriveKey / (float)calls_C_DeriveKey);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DeriveKey / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DestroyObject", calls_C_DestroyObject, counter_C_DestroyObject);
    if (calls_C_DestroyObject > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DestroyObject / (float)calls_C_DestroyObject);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DestroyObject / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Digest", calls_C_Digest, counter_C_Digest);
    if (calls_C_Digest > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Digest / (float)calls_C_Digest);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Digest / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DigestEncryptUpdate", calls_C_DigestEncryptUpdate, counter_C_DigestEncryptUpdate);
    if (calls_C_DigestEncryptUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DigestEncryptUpdate / (float)calls_C_DigestEncryptUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DigestEncryptUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DigestFinal", calls_C_DigestFinal, counter_C_DigestFinal);
    if (calls_C_DigestFinal > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DigestFinal / (float)calls_C_DigestFinal);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DigestFinal / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DigestInit", calls_C_DigestInit, counter_C_DigestInit);
    if (calls_C_DigestInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DigestInit / (float)calls_C_DigestInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DigestInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DigestKey", calls_C_DigestKey, counter_C_DigestKey);
    if (calls_C_DigestKey > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DigestKey / (float)calls_C_DigestKey);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DigestKey / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_DigestUpdate", calls_C_DigestUpdate, counter_C_DigestUpdate);
    if (calls_C_DigestUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_DigestUpdate / (float)calls_C_DigestUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_DigestUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Encrypt", calls_C_Encrypt, counter_C_Encrypt);
    if (calls_C_Encrypt > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Encrypt / (float)calls_C_Encrypt);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Encrypt / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_EncryptFinal", calls_C_EncryptFinal, counter_C_EncryptFinal);
    if (calls_C_EncryptFinal > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_EncryptFinal / (float)calls_C_EncryptFinal);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_EncryptFinal / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_EncryptInit", calls_C_EncryptInit, counter_C_EncryptInit);
    if (calls_C_EncryptInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_EncryptInit / (float)calls_C_EncryptInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_EncryptInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_EncryptUpdate", calls_C_EncryptUpdate, counter_C_EncryptUpdate);
    if (calls_C_EncryptUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_EncryptUpdate / (float)calls_C_EncryptUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_EncryptUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Finalize", calls_C_Finalize, counter_C_Finalize);
    if (calls_C_Finalize > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Finalize / (float)calls_C_Finalize);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Finalize / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_FindObjects", calls_C_FindObjects, counter_C_FindObjects);
    if (calls_C_FindObjects > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_FindObjects / (float)calls_C_FindObjects);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_FindObjects / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_FindObjectsFinal", calls_C_FindObjectsFinal, counter_C_FindObjectsFinal);
    if (calls_C_FindObjectsFinal > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_FindObjectsFinal / (float)calls_C_FindObjectsFinal);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_FindObjectsFinal / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_FindObjectsInit", calls_C_FindObjectsInit, counter_C_FindObjectsInit);
    if (calls_C_FindObjectsInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_FindObjectsInit / (float)calls_C_FindObjectsInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_FindObjectsInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GenerateKey", calls_C_GenerateKey, counter_C_GenerateKey);
    if (calls_C_GenerateKey > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GenerateKey / (float)calls_C_GenerateKey);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GenerateKey / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GenerateKeyPair", calls_C_GenerateKeyPair, counter_C_GenerateKeyPair);
    if (calls_C_GenerateKeyPair > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GenerateKeyPair / (float)calls_C_GenerateKeyPair);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GenerateKeyPair / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GenerateRandom", calls_C_GenerateRandom, counter_C_GenerateRandom);
    if (calls_C_GenerateRandom > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GenerateRandom / (float)calls_C_GenerateRandom);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GenerateRandom / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetAttributeValue", calls_C_GetAttributeValue, counter_C_GetAttributeValue);
    if (calls_C_GetAttributeValue > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetAttributeValue / (float)calls_C_GetAttributeValue);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetAttributeValue / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetFunctionList", calls_C_GetFunctionList, counter_C_GetFunctionList);
    if (calls_C_GetFunctionList > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetFunctionList / (float)calls_C_GetFunctionList);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetFunctionList / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetFunctionStatus", calls_C_GetFunctionStatus, counter_C_GetFunctionStatus);
    if (calls_C_GetFunctionStatus > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetFunctionStatus / (float)calls_C_GetFunctionStatus);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetFunctionStatus / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetInfo", calls_C_GetInfo, counter_C_GetInfo);
    if (calls_C_GetInfo > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetInfo / (float)calls_C_GetInfo);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetInfo / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetMechanismInfo", calls_C_GetMechanismInfo, counter_C_GetMechanismInfo);
    if (calls_C_GetMechanismInfo > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetMechanismInfo / (float)calls_C_GetMechanismInfo);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetMechanismInfo / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetMechanismList", calls_C_GetMechanismList, counter_C_GetMechanismList);
    if (calls_C_GetMechanismList > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetMechanismList / (float)calls_C_GetMechanismList);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetMechanismList / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetObjectSize", calls_C_GetObjectSize, counter_C_GetObjectSize);
    if (calls_C_GetObjectSize > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetObjectSize / (float)calls_C_GetObjectSize);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetObjectSize / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetOperationState", calls_C_GetOperationState, counter_C_GetOperationState);
    if (calls_C_GetOperationState > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetOperationState / (float)calls_C_GetOperationState);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetOperationState / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetSessionInfo", calls_C_GetSessionInfo, counter_C_GetSessionInfo);
    if (calls_C_GetSessionInfo > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetSessionInfo / (float)calls_C_GetSessionInfo);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetSessionInfo / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetSlotInfo", calls_C_GetSlotInfo, counter_C_GetSlotInfo);
    if (calls_C_GetSlotInfo > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetSlotInfo / (float)calls_C_GetSlotInfo);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetSlotInfo / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetSlotList", calls_C_GetSlotList, counter_C_GetSlotList);
    if (calls_C_GetSlotList > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetSlotList / (float)calls_C_GetSlotList);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetSlotList / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_GetTokenInfo", calls_C_GetTokenInfo, counter_C_GetTokenInfo);
    if (calls_C_GetTokenInfo > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_GetTokenInfo / (float)calls_C_GetTokenInfo);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_GetTokenInfo / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_InitPIN", calls_C_InitPIN, counter_C_InitPIN);
    if (calls_C_InitPIN > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_InitPIN / (float)calls_C_InitPIN);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_InitPIN / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_InitToken", calls_C_InitToken, counter_C_InitToken);
    if (calls_C_InitToken > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_InitToken / (float)calls_C_InitToken);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_InitToken / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Initialize", calls_C_Initialize, counter_C_Initialize);
    if (calls_C_Initialize > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Initialize / (float)calls_C_Initialize);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Initialize / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Login", calls_C_Login, counter_C_Login);
    if (calls_C_Login > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Login / (float)calls_C_Login);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Login / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Logout", calls_C_Logout, counter_C_Logout);
    if (calls_C_Logout > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Logout / (float)calls_C_Logout);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Logout / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_OpenSession", calls_C_OpenSession, counter_C_OpenSession);
    if (calls_C_OpenSession > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_OpenSession / (float)calls_C_OpenSession);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_OpenSession / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SeedRandom", calls_C_SeedRandom, counter_C_SeedRandom);
    if (calls_C_SeedRandom > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SeedRandom / (float)calls_C_SeedRandom);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SeedRandom / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SetAttributeValue", calls_C_SetAttributeValue, counter_C_SetAttributeValue);
    if (calls_C_SetAttributeValue > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SetAttributeValue / (float)calls_C_SetAttributeValue);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SetAttributeValue / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SetOperationState", calls_C_SetOperationState, counter_C_SetOperationState);
    if (calls_C_SetOperationState > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SetOperationState / (float)calls_C_SetOperationState);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SetOperationState / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SetPIN", calls_C_SetPIN, counter_C_SetPIN);
    if (calls_C_SetPIN > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SetPIN / (float)calls_C_SetPIN);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SetPIN / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Sign", calls_C_Sign, counter_C_Sign);
    if (calls_C_Sign > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Sign / (float)calls_C_Sign);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Sign / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SignEncryptUpdate", calls_C_SignEncryptUpdate, counter_C_SignEncryptUpdate);
    if (calls_C_SignEncryptUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SignEncryptUpdate / (float)calls_C_SignEncryptUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SignEncryptUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SignFinal", calls_C_SignFinal, counter_C_SignFinal);
    if (calls_C_SignFinal > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SignFinal / (float)calls_C_SignFinal);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SignFinal / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SignInit", calls_C_SignInit, counter_C_SignInit);
    if (calls_C_SignInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SignInit / (float)calls_C_SignInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SignInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SignRecover", calls_C_SignRecover, counter_C_SignRecover);
    if (calls_C_SignRecover > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SignRecover / (float)calls_C_SignRecover);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SignRecover / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SignRecoverInit", calls_C_SignRecoverInit, counter_C_SignRecoverInit);
    if (calls_C_SignRecoverInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SignRecoverInit / (float)calls_C_SignRecoverInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SignRecoverInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_SignUpdate", calls_C_SignUpdate, counter_C_SignUpdate);
    if (calls_C_SignUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_SignUpdate / (float)calls_C_SignUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_SignUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_UnwrapKey", calls_C_UnwrapKey, counter_C_UnwrapKey);
    if (calls_C_UnwrapKey > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_UnwrapKey / (float)calls_C_UnwrapKey);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_UnwrapKey / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_Verify", calls_C_Verify, counter_C_Verify);
    if (calls_C_Verify > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_Verify / (float)calls_C_Verify);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_Verify / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_VerifyFinal", calls_C_VerifyFinal, counter_C_VerifyFinal);
    if (calls_C_VerifyFinal > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_VerifyFinal / (float)calls_C_VerifyFinal);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_VerifyFinal / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_VerifyInit", calls_C_VerifyInit, counter_C_VerifyInit);
    if (calls_C_VerifyInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_VerifyInit / (float)calls_C_VerifyInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_VerifyInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_VerifyRecover", calls_C_VerifyRecover, counter_C_VerifyRecover);
    if (calls_C_VerifyRecover > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_VerifyRecover / (float)calls_C_VerifyRecover);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_VerifyRecover / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_VerifyRecoverInit", calls_C_VerifyRecoverInit, counter_C_VerifyRecoverInit);
    if (calls_C_VerifyRecoverInit > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_VerifyRecoverInit / (float)calls_C_VerifyRecoverInit);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_VerifyRecoverInit / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_VerifyUpdate", calls_C_VerifyUpdate, counter_C_VerifyUpdate);
    if (calls_C_VerifyUpdate > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_VerifyUpdate / (float)calls_C_VerifyUpdate);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_VerifyUpdate / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_WaitForSlotEvent", calls_C_WaitForSlotEvent, counter_C_WaitForSlotEvent);
    if (calls_C_WaitForSlotEvent > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_WaitForSlotEvent / (float)calls_C_WaitForSlotEvent);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_WaitForSlotEvent / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"%-25s %10d %10d ", "C_WrapKey", calls_C_WrapKey, counter_C_WrapKey);
    if (calls_C_WrapKey > 0) {
        fprintf(outfile,"%10.2f", (float)counter_C_WrapKey / (float)calls_C_WrapKey);
    } else {
        fprintf(outfile,"%10.2f", 0.0);
    }
    fprintf(outfile,"%10.2f", (float)counter_C_WrapKey / (float)total_time * 100);
    fprintf(outfile,"\n");
    fprintf(outfile,"\n");

    fprintf(outfile,"%25s %10d %10d\n", "Totals", total_calls, total_time);
    fprintf(outfile,"\n\nMaximum number of concurrent open sessions: %d\n\n", maxOpenSessions);
    fflush (outfile);
    if (outfile != stdout) {
	fclose(outfile);
    }
}