aboutsummaryrefslogtreecommitdiffstats
path: root/SoftHSMv2/src/lib/P11Objects.cpp
blob: 3e663b26b26bd98cbdb2a74bd314c71732f4b94c (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
/*
 * Copyright (c) 2011 .SE (The Internet Infrastructure Foundation)
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
 * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*****************************************************************************
 P11Objects.cpp

 This class respresent a PKCS#11 object
 *****************************************************************************/

#include "config.h"
#include "P11Objects.h"
#include <stdio.h>
#include <stdlib.h>

// Constructor
P11Object::P11Object()
{
	initialized = false;
	osobject = NULL;
}

// Destructor
P11Object::~P11Object()
{
	std::map<CK_ATTRIBUTE_TYPE, P11Attribute*> cleanUp = attributes;
	attributes.clear();

	for (std::map<CK_ATTRIBUTE_TYPE, P11Attribute*>::iterator i = cleanUp.begin(); i != cleanUp.end(); i++)
	{
		if (i->second == NULL)
		{
			continue;
		}

		delete i->second;
		i->second = NULL;
	}
}

// Add attributes
bool P11Object::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	osobject = inobject;

	// Create attributes
	P11Attribute* attrClass = new P11AttrClass(osobject);
	P11Attribute* attrToken = new P11AttrToken(osobject);
	P11Attribute* attrPrivate = new P11AttrPrivate(osobject);
	P11Attribute* attrModifiable = new P11AttrModifiable(osobject);
	P11Attribute* attrLabel = new P11AttrLabel(osobject);
	P11Attribute* attrCopyable = new P11AttrCopyable(osobject);
	P11Attribute* attrDestroyable = new P11AttrDestroyable(osobject);

	// Initialize the attributes
	if
	(
		!attrClass->init() ||
		!attrToken->init() ||
		!attrPrivate->init() ||
		!attrModifiable->init() ||
		!attrLabel->init() ||
		!attrCopyable->init() ||
		!attrDestroyable->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrClass;
		delete attrToken;
		delete attrPrivate;
		delete attrModifiable;
		delete attrLabel;
		delete attrCopyable;
		delete attrDestroyable;
		return false;
	}

	// Add them to the map
	attributes[attrClass->getType()] = attrClass;
	attributes[attrToken->getType()] = attrToken;
	attributes[attrPrivate->getType()] = attrPrivate;
	attributes[attrModifiable->getType()] = attrModifiable;
	attributes[attrLabel->getType()] = attrLabel;
	attributes[attrCopyable->getType()] = attrCopyable;
	attributes[attrDestroyable->getType()] = attrDestroyable;

	initialized = true;
	return true;
}

CK_RV P11Object::loadTemplate(Token *token, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount)
{
	bool isPrivate = this->isPrivate();

	// [PKCS#11 v2.40, C_GetAttributeValue]
	// 1. If the specified attribute (i.e., the attribute specified by the
	//    type field) for the object cannot be revealed because the object
	//    is sensitive or unextractable, then the ulValueLen field in that
	//    triple is modified to hold the value CK_UNAVAILABLE_INFORMATION.
	//
	// 2. Otherwise, if the specified value for the object is invalid (the
	//    object does not possess such an attribute), then the ulValueLen
	//    field in that triple is modified to hold the value
	//    CK_UNAVAILABLE_INFORMATION.
	//
	// 3. Otherwise, if the pValue field has the value NULL_PTR, then the
	//    ulValueLen field is modified to hold the exact length of the
	//    specified attribute for the object.
	//
	// 4. Otherwise, if the length specified in ulValueLen is large enough
	//    to hold the value of the specified attribute for the object,
	//    then that attribute is copied into the buffer located at pValue,
	//    and the ulValueLen field is modified to hold the exact length of
	//    the attribute.
	//
	// 5. Otherwise, the ulValueLen field is modified to hold the value
	//    CK_UNAVAILABLE_INFORMATION.

	bool invalid = false, sensitive = false, buffer_too_small = false;

	// If case 3 or 4 applies to all the requested attributes, then the call will return CKR_OK.
	for (CK_ULONG i = 0; i < ulAttributeCount; ++i)
	{
		P11Attribute* attr = attributes[pTemplate[i].type];

		// case 2 of the attribute checks
		if (attr == NULL) {
			pTemplate[i].ulValueLen = CK_UNAVAILABLE_INFORMATION;
			// If case 2 applies to any of the requested attributes, then the call should
			// return the value CKR_ATTRIBUTE_TYPE_INVALID.
			invalid = true;
			continue;
		}

		// case 1,3,4 and 5 of the attribute checks are done while retrieving the attribute itself.
		CK_RV retrieve_rv = attr->retrieve(token, isPrivate, pTemplate[i].pValue, &pTemplate[i].ulValueLen);
		if (retrieve_rv == CKR_ATTRIBUTE_SENSITIVE) {
			// If case 1 applies to any of the requested attributes, then the call should
			// return the value CKR_ATTRIBUTE_SENSITIVE.
			sensitive = true;
		} else if (retrieve_rv == CKR_BUFFER_TOO_SMALL) {
			// If case 5 applies to any of the requested attributes, then the call should
			// return the value CKR_BUFFER_TOO_SMALL.
			buffer_too_small = true;
		} else if (retrieve_rv != CKR_OK) {
		    return CKR_GENERAL_ERROR;
		}

	}

	// As usual if more than one of these error codes is applicable, Cryptoki may
	// return any of them. Only if none of them applies to any of the requested
	// attributes will CKR_OK be returned. We choose to return the errors in
	// the following priority, which is probably the most useful order.
	if (sensitive)
		return CKR_ATTRIBUTE_SENSITIVE;
	if (invalid)
		return CKR_ATTRIBUTE_TYPE_INVALID;
	if (buffer_too_small)
		return CKR_BUFFER_TOO_SMALL;
	return CKR_OK;
}

// Save template
CK_RV P11Object::saveTemplate(Token *token, bool isPrivate, CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulAttributeCount, int op)
{
	if (osobject == NULL)
		return CKR_GENERAL_ERROR;
	if (osobject->startTransaction() == false)
		return CKR_GENERAL_ERROR;

	if (op == OBJECT_OP_SET)
	{
		if (!isModifiable())
		{
			osobject->abortTransaction();
			return CKR_ACTION_PROHIBITED;
		}
	}

	// [PKCS#11 v2.40, 4.1.3 Copying objects] OBJECT_OP_COPY
	//    If the CKA_COPYABLE attribute of the object to be copied is set
	//    to CK_FALSE, C_CopyObject returns CKR_ACTION_PROHIBITED.
	if (op == OBJECT_OP_COPY)
	{
		if (!isCopyable())
		{
			osobject->abortTransaction();
			return CKR_ACTION_PROHIBITED;
		}
	}

	for (CK_ULONG i = 0; i < ulAttributeCount; i++)
	{
		// [PKCS#11 v2.40, 4.1.1 Creating objects] OBJECT_OP_CREATE | OBJECT_OP_SET | OBJECT_OP_COPY
		//    1. If the supplied template specifies a value for an invalid attribute, then the attempt
		//    should fail with the error code CKR_ATTRIBUTE_TYPE_INVALID. An attribute
		//    is valid if it is either one of the attributes described in the Cryptoki specification or an
		//    additional vendor-specific attribute supported by the library and token.
		P11Attribute* attr = attributes[pTemplate[i].type];

		if (attr == NULL)
		{
			osobject->abortTransaction();
			return CKR_ATTRIBUTE_TYPE_INVALID;
		}

		// Additonal checks are done while updating the attributes themselves.
		CK_RV rv = attr->update(token,isPrivate, pTemplate[i].pValue, pTemplate[i].ulValueLen, op);
		if (rv != CKR_OK)
		{
			osobject->abortTransaction();
			return rv;
		}
	}

	// [PKCS#11 v2.40, 4.1.1 Creating objects]
	//    4. If the attribute values in the supplied template, together with any default attribute
	//    values and any attribute values contributed to the object by the object-creation
	//    function itself, are insufficient to fully specify the object to create, then the attempt
	//    should fail with the error code CKR_TEMPLATE_INCOMPLETE.

	// All attributes that have to be specified are marked as such in the specification.
	// The following checks are relevant here:
	for (std::map<CK_ATTRIBUTE_TYPE, P11Attribute*>::iterator i = attributes.begin(); i != attributes.end(); i++)
	{
		CK_ULONG checks = i->second->getChecks();

		//  ck1  MUST be specified when object is created with C_CreateObject.
		//  ck3  MUST be specified when object is generated with C_GenerateKey or C_GenerateKeyPair.
		//  ck5  MUST be specified when object is unwrapped with C_UnwrapKey.
		if (((checks & P11Attribute::ck1) == P11Attribute::ck1 && op == OBJECT_OP_CREATE) ||
		    ((checks & P11Attribute::ck3) == P11Attribute::ck3 && op == OBJECT_OP_GENERATE) ||
		    ((checks & P11Attribute::ck5) == P11Attribute::ck5 && op == OBJECT_OP_UNWRAP))
		{
			bool isSpecified = false;

			for (CK_ULONG n = 0; n < ulAttributeCount; n++)
			{
				if (i->first == pTemplate[n].type)
				{
					isSpecified = true;
					break;
				}
			}

			if (!isSpecified)
			{
				ERROR_MSG("Mandatory attribute (0x%08X) was not specified in template", (unsigned int)i->first);

				return CKR_TEMPLATE_INCOMPLETE;
			}
		}
	}

	// [PKCS#11 v2.40, 4.1.1 Creating objects]
	//    5. If the attribute values in the supplied template, together with any default attribute
	//    values and any attribute values contributed to the object by the object-creation
	//    function itself, are inconsistent, then the attempt should fail with the error code
	//    CKR_TEMPLATE_INCONSISTENT. A set of attribute values is inconsistent if not
	//    all of its members can be satisfied simultaneously by the token, although each value
	//    individually is valid in Cryptoki. One example of an inconsistent template would be
	//    using a template which specifies two different values for the same attribute. Another
	//    example would be trying to create a secret key object with an attribute which is
	//    appropriate for various types of public keys or private keys, but not for secret keys.
	//    A final example would be a template with an attribute that violates some token
	//    specific requirement. Note that this final example of an inconsistent template is
	//    token-dependent—on a different token, such a template might not be inconsistent.

	if (osobject->commitTransaction() == false)
	{
		return CKR_GENERAL_ERROR;
	}

	return CKR_OK;
}

bool P11Object::isPrivate()
{
	// Get the CKA_PRIVATE attribute, when the attribute is
	// not present return the default value which we have
	// chosen to be CK_FALSE.
	if (!osobject->attributeExists(CKA_PRIVATE)) return false;

	return osobject->getBooleanValue(CKA_PRIVATE, false);
}

bool P11Object::isCopyable()
{
	// Get the CKA_COPYABLE attribute, when the attribute is not
	// present return the default value which is CK_TRUE.
	if (!osobject->attributeExists(CKA_COPYABLE)) return true;

	return osobject->getBooleanValue(CKA_COPYABLE, true);
}

bool P11Object::isModifiable()
{
	// Get the CKA_MODIFIABLE attribute, when the attribute is
	// not present return the default value which is CK_TRUE.
	if (!osobject->attributeExists(CKA_MODIFIABLE)) return true;

	return osobject->getBooleanValue(CKA_MODIFIABLE, true);
}

// Constructor
P11DataObj::P11DataObj()
{
	initialized = false;
}

// Add attributes
bool P11DataObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	// Set default values for attributes that will be introduced in the parent
	if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_DATA) {
		OSAttribute setClass((unsigned long)CKO_DATA);
		inobject->setAttribute(CKA_CLASS, setClass);
	}

	// Create parent
	if (!P11Object::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrApplication = new P11AttrApplication(osobject);
	P11Attribute* attrObjectID = new P11AttrObjectID(osobject);
	// NOTE: There is no mention in the PKCS#11 v2.40 spec that for a Data
	//  Object the CKA_VALUE attribute may be modified after creation!
	//  Therefore we assume it is not allowed to change the CKA_VALUE
	//  attribute of a Data Object.
	P11Attribute* attrValue = new P11AttrValue(osobject,0);

	// Initialize the attributes
	if
	(
		!attrApplication->init() ||
		!attrObjectID->init() ||
		!attrValue->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrApplication;
		delete attrObjectID;
		delete attrValue;
		return false;
	}

	// Add them to the map
	attributes[attrApplication->getType()] = attrApplication;
	attributes[attrObjectID->getType()] = attrObjectID;
	attributes[attrValue->getType()] = attrValue;

	initialized = true;
	return true;
}

// Constructor
P11CertificateObj::P11CertificateObj()
{
	initialized = false;
}

// Add attributes
bool P11CertificateObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	// Set default values for attributes that will be introduced in the parent
	if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_CERTIFICATE) {
		OSAttribute setClass((unsigned long)CKO_CERTIFICATE);
		inobject->setAttribute(CKA_CLASS, setClass);
	}
	// Make certificates public
	if (!inobject->attributeExists(CKA_PRIVATE)) {
		OSAttribute setPrivate(false);
		inobject->setAttribute(CKA_PRIVATE, setPrivate);
	}

	// Create parent
	if (!P11Object::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrCertificateType = new P11AttrCertificateType(osobject);
	P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
	P11Attribute* attrCertificateCategory = new P11AttrCertificateCategory(osobject);
	// NOTE: Because these attributes are used in a certificate object
	//  where the CKA_VALUE containing the certificate data is not
	//  modifiable, we assume that this attribute is also not modifiable.
	//  There is also no explicit mention of these attributes being modifiable.
	P11Attribute* attrCheckValue = new P11AttrCheckValue(osobject, 0);
	P11Attribute* attrStartDate = new P11AttrStartDate(osobject,0);
	P11Attribute* attrEndDate = new P11AttrEndDate(osobject,0);
	// TODO: CKA_PUBLIC_KEY_INFO is accepted, but we do not calculate it.
	P11Attribute* attrPublicKeyInfo = new P11AttrPublicKeyInfo(osobject,0);

	// Initialize the attributes
	if
	(
		!attrCertificateType->init() ||
		!attrTrusted->init() ||
		!attrCertificateCategory->init() ||
		!attrCheckValue->init() ||
		!attrStartDate->init() ||
		!attrEndDate->init() ||
		!attrPublicKeyInfo->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrCertificateType;
		delete attrTrusted;
		delete attrCertificateCategory;
		delete attrCheckValue;
		delete attrStartDate;
		delete attrEndDate;
		delete attrPublicKeyInfo;
		return false;
	}

	// Add them to the map
	attributes[attrCertificateType->getType()] = attrCertificateType;
	attributes[attrTrusted->getType()] = attrTrusted;
	attributes[attrCertificateCategory->getType()] = attrCertificateCategory;
	attributes[attrCheckValue->getType()] = attrCheckValue;
	attributes[attrStartDate->getType()] = attrStartDate;
	attributes[attrEndDate->getType()] = attrEndDate;
	attributes[attrPublicKeyInfo->getType()] = attrPublicKeyInfo;

	initialized = true;
	return true;
}

// Constructor
P11X509CertificateObj::P11X509CertificateObj()
{
	initialized = false;
}

// Add attributes
bool P11X509CertificateObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	// Set default values for attributes that will be introduced in the parent
	if (!inobject->attributeExists(CKA_CERTIFICATE_TYPE) || inobject->getUnsignedLongValue(CKA_CERTIFICATE_TYPE, CKC_VENDOR_DEFINED) != CKC_X_509) {
		OSAttribute setCertType((unsigned long)CKC_X_509);
		inobject->setAttribute(CKA_CERTIFICATE_TYPE, setCertType);
	}

	// Create parent
	if (!P11CertificateObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck1);
	P11Attribute* attrID = new P11AttrID(osobject);
	P11Attribute* attrIssuer = new P11AttrIssuer(osobject);
	P11Attribute* attrSerialNumber = new P11AttrSerialNumber(osobject);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck14);
	P11Attribute* attrURL = new P11AttrURL(osobject);
	P11Attribute* attrHashOfSubjectPublicKey = new P11AttrHashOfSubjectPublicKey(osobject);
	P11Attribute* attrHashOfIssuerPublicKey = new P11AttrHashOfIssuerPublicKey(osobject);
	P11Attribute* attrJavaMidpSecurityDomain = new P11AttrJavaMidpSecurityDomain(osobject);
	P11Attribute* attrNameHashAlgorithm = new P11AttrNameHashAlgorithm(osobject);

	// Initialize the attributes
	if
	(
		!attrSubject->init() ||
		!attrID->init() ||
		!attrIssuer->init() ||
		!attrSerialNumber->init() ||
		!attrValue->init() ||
		!attrURL->init() ||
		!attrHashOfSubjectPublicKey->init() ||
		!attrHashOfIssuerPublicKey->init() ||
		!attrJavaMidpSecurityDomain->init() ||
		!attrNameHashAlgorithm->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrSubject;
		delete attrID;
		delete attrIssuer;
		delete attrSerialNumber;
		delete attrValue;
		delete attrURL;
		delete attrHashOfSubjectPublicKey;
		delete attrHashOfIssuerPublicKey;
		delete attrJavaMidpSecurityDomain;
		delete attrNameHashAlgorithm;
		return false;
	}

	// Add them to the map
	attributes[attrSubject->getType()] = attrSubject;
	attributes[attrID->getType()] = attrID;
	attributes[attrIssuer->getType()] = attrIssuer;
	attributes[attrSerialNumber->getType()] = attrSerialNumber;
	attributes[attrValue->getType()] = attrValue;
	attributes[attrURL->getType()] = attrURL;
	attributes[attrHashOfSubjectPublicKey->getType()] = attrHashOfSubjectPublicKey;
	attributes[attrHashOfIssuerPublicKey->getType()] = attrHashOfIssuerPublicKey;
	attributes[attrJavaMidpSecurityDomain->getType()] = attrJavaMidpSecurityDomain;
	attributes[attrNameHashAlgorithm->getType()] = attrNameHashAlgorithm;

	return true;
}

// Constructor
P11OpenPGPPublicKeyObj::P11OpenPGPPublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11OpenPGPPublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	// Set default values for attributes that will be introduced in the parent
	if (!inobject->attributeExists(CKA_CERTIFICATE_TYPE) || inobject->getUnsignedLongValue(CKA_CERTIFICATE_TYPE, CKC_VENDOR_DEFINED) != CKC_OPENPGP) {
		OSAttribute setCertType((unsigned long)CKC_OPENPGP);
		inobject->setAttribute(CKA_CERTIFICATE_TYPE, setCertType);
	}

	// Create parent
	if (!P11CertificateObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck1);
	P11Attribute* attrID = new P11AttrID(osobject);
	P11Attribute* attrIssuer = new P11AttrIssuer(osobject);
	P11Attribute* attrSerialNumber = new P11AttrSerialNumber(osobject);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck14);
	P11Attribute* attrURL = new P11AttrURL(osobject);

	// Initialize the attributes
	if
	(
		!attrSubject->init() ||
		!attrID->init() ||
		!attrIssuer->init() ||
		!attrSerialNumber->init() ||
		!attrValue->init() ||
		!attrURL->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrSubject;
		delete attrID;
		delete attrIssuer;
		delete attrSerialNumber;
		delete attrValue;
		delete attrURL;
		return false;
	}

	// Add them to the map
	attributes[attrSubject->getType()] = attrSubject;
	attributes[attrID->getType()] = attrID;
	attributes[attrIssuer->getType()] = attrIssuer;
	attributes[attrSerialNumber->getType()] = attrSerialNumber;
	attributes[attrValue->getType()] = attrValue;
	attributes[attrURL->getType()] = attrURL;

	return true;
}

// Constructor
P11KeyObj::P11KeyObj()
{
	initialized = false;
}

// Add attributes
bool P11KeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	// Create parent
	if (!P11Object::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrKeyType = new P11AttrKeyType(osobject,P11Attribute::ck5);
	P11Attribute* attrID = new P11AttrID(osobject);
	P11Attribute* attrStartDate = new P11AttrStartDate(osobject,P11Attribute::ck8);
	P11Attribute* attrEndDate = new P11AttrEndDate(osobject,P11Attribute::ck8);
	P11Attribute* attrDerive = new P11AttrDerive(osobject);
	P11Attribute* attrLocal = new P11AttrLocal(osobject,P11Attribute::ck6);
	P11Attribute* attrKeyGenMechanism = new P11AttrKeyGenMechanism(osobject);
	P11Attribute* attrAllowedMechanisms = new P11AttrAllowedMechanisms(osobject);

	// Initialize the attributes
	if
	(
		!attrKeyType->init() ||
		!attrID->init() ||
		!attrStartDate->init() ||
		!attrEndDate->init() ||
		!attrDerive->init() ||
		!attrLocal->init() ||
		!attrKeyGenMechanism->init() ||
		!attrAllowedMechanisms->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrKeyType;
		delete attrID;
		delete attrStartDate;
		delete attrEndDate;
		delete attrDerive;
		delete attrLocal;
		delete attrKeyGenMechanism;
		delete attrAllowedMechanisms;
		return false;
	}

	// Add them to the map
	attributes[attrKeyType->getType()] = attrKeyType;
	attributes[attrID->getType()] = attrID;
	attributes[attrStartDate->getType()] = attrStartDate;
	attributes[attrEndDate->getType()] = attrEndDate;
	attributes[attrDerive->getType()] = attrDerive;
	attributes[attrLocal->getType()] = attrLocal;
	attributes[attrKeyGenMechanism->getType()] = attrKeyGenMechanism;
	attributes[attrAllowedMechanisms->getType()] = attrAllowedMechanisms;

	initialized = true;
	return true;
}

// Constructor
P11PublicKeyObj::P11PublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11PublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	// Set default values for attributes that will be introduced in the parent
	if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_PUBLIC_KEY) {
		OSAttribute setClass((unsigned long)CKO_PUBLIC_KEY);
		inobject->setAttribute(CKA_CLASS, setClass);
	}
	// Make public keys public
	if (!inobject->attributeExists(CKA_PRIVATE)) {
		OSAttribute setPrivate(false);
		inobject->setAttribute(CKA_PRIVATE, setPrivate);
	}

	// Create parent
	if (!P11KeyObj::init(inobject)) return false;

	if (initialized) return true;

	// Create attributes
	P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck8);
	P11Attribute* attrEncrypt = new P11AttrEncrypt(osobject);
	P11Attribute* attrVerify = new P11AttrVerify(osobject);
	P11Attribute* attrVerifyRecover = new P11AttrVerifyRecover(osobject);
	P11Attribute* attrWrap = new P11AttrWrap(osobject);
	P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
	P11Attribute* attrWrapTemplate = new P11AttrWrapTemplate(osobject);
	// TODO: CKA_PUBLIC_KEY_INFO is accepted, but we do not calculate it
	P11Attribute* attrPublicKeyInfo = new P11AttrPublicKeyInfo(osobject,0);

	// Initialize the attributes
	if
	(
		!attrSubject->init() ||
		!attrEncrypt->init() ||
		!attrVerify->init() ||
		!attrVerifyRecover->init() ||
		!attrWrap->init() ||
		!attrTrusted->init() ||
		!attrWrapTemplate->init() ||
		!attrPublicKeyInfo->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrSubject;
		delete attrEncrypt;
		delete attrVerify;
		delete attrVerifyRecover;
		delete attrWrap;
		delete attrTrusted;
		delete attrWrapTemplate;
		delete attrPublicKeyInfo;
		return false;
	}

	// Add them to the map
	attributes[attrSubject->getType()] = attrSubject;
	attributes[attrEncrypt->getType()] = attrEncrypt;
	attributes[attrVerify->getType()] = attrVerify;
	attributes[attrVerifyRecover->getType()] = attrVerifyRecover;
	attributes[attrWrap->getType()] = attrWrap;
	attributes[attrTrusted->getType()] = attrTrusted;
	attributes[attrWrapTemplate->getType()] = attrWrapTemplate;
	attributes[attrPublicKeyInfo->getType()] = attrPublicKeyInfo;

	initialized = true;
	return true;
}

// Constructor
P11RSAPublicKeyObj::P11RSAPublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11RSAPublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_RSA) {
		OSAttribute setKeyType((unsigned long)CKK_RSA);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PublicKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrModulus = new P11AttrModulus(osobject);
	P11Attribute* attrModulusBits = new P11AttrModulusBits(osobject);
	P11Attribute* attrPublicExponent = new P11AttrPublicExponent(osobject,P11Attribute::ck1);

	// Initialize the attributes
	if
	(
		!attrModulus->init() ||
		!attrModulusBits->init() ||
		!attrPublicExponent->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrModulus;
		delete attrModulusBits;
		delete attrPublicExponent;
		return false;
	}

	// Add them to the map
	attributes[attrModulus->getType()] = attrModulus;
	attributes[attrModulusBits->getType()] = attrModulusBits;
	attributes[attrPublicExponent->getType()] = attrPublicExponent;

	initialized = true;
	return true;
}

// Constructor
P11DSAPublicKeyObj::P11DSAPublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11DSAPublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DSA) {
		OSAttribute setKeyType((unsigned long)CKK_DSA);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PublicKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck3);
	P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck3);
	P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck3);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4);

	// Initialize the attributes
	if
	(
		!attrPrime->init() ||
		!attrSubPrime->init() ||
		!attrBase->init() ||
		!attrValue->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrPrime;
		delete attrSubPrime;
		delete attrBase;
		delete attrValue;
		return false;
	}

	// Add them to the map
	attributes[attrPrime->getType()] = attrPrime;
	attributes[attrSubPrime->getType()] = attrSubPrime;
	attributes[attrBase->getType()] = attrBase;
	attributes[attrValue->getType()] = attrValue;

	initialized = true;
	return true;
}

// Constructor
P11ECPublicKeyObj::P11ECPublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11ECPublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_EC) {
		OSAttribute setKeyType((unsigned long)CKK_EC);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PublicKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrEcParams = new P11AttrEcParams(osobject,P11Attribute::ck3);
	P11Attribute* attrEcPoint = new P11AttrEcPoint(osobject);

	// Initialize the attributes
	if
	(
		!attrEcParams->init() ||
		!attrEcPoint->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrEcParams;
		delete attrEcPoint;
		return false;
	}

	// Add them to the map
	attributes[attrEcParams->getType()] = attrEcParams;
	attributes[attrEcPoint->getType()] = attrEcPoint;

	initialized = true;
	return true;
}

// Constructor
P11DHPublicKeyObj::P11DHPublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11DHPublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DH) {
		OSAttribute setKeyType((unsigned long)CKK_DH);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PublicKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck3);
	P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck3);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4);

	// Initialize the attributes
	if
	(
		!attrPrime->init() ||
		!attrBase->init() ||
		!attrValue->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrPrime;
		delete attrBase;
		delete attrValue;
		return false;
	}

	// Add them to the map
	attributes[attrPrime->getType()] = attrPrime;
	attributes[attrBase->getType()] = attrBase;
	attributes[attrValue->getType()] = attrValue;

	initialized = true;
	return true;
}

// Constructor
P11GOSTPublicKeyObj::P11GOSTPublicKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11GOSTPublicKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_GOSTR3410) {
		OSAttribute setKeyType((unsigned long)CKK_GOSTR3410);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PublicKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4);
	P11Attribute* attrGostR3410Params = new P11AttrGostR3410Params(osobject,P11Attribute::ck3);
	P11Attribute* attrGostR3411Params = new P11AttrGostR3411Params(osobject,P11Attribute::ck3);
	P11Attribute* attrGost28147Params = new P11AttrGost28147Params(osobject,P11Attribute::ck8);

	// Initialize the attributes
	if
	(
		!attrValue->init() ||
		!attrGostR3410Params->init() ||
		!attrGostR3411Params->init() ||
		!attrGost28147Params->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrValue;
		delete attrGostR3410Params;
		delete attrGostR3411Params;
		delete attrGost28147Params;
		return false;
	}

	// Add them to the map
	attributes[attrValue->getType()] = attrValue;
	attributes[attrGostR3410Params->getType()] = attrGostR3410Params;
	attributes[attrGostR3411Params->getType()] = attrGostR3411Params;
	attributes[attrGost28147Params->getType()] = attrGost28147Params;

	initialized = true;
	return true;
}

//constructor
P11PrivateKeyObj::P11PrivateKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11PrivateKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_PRIVATE_KEY) {
		OSAttribute setClass((unsigned long)CKO_PRIVATE_KEY);
		inobject->setAttribute(CKA_CLASS, setClass);
	}

	// Create parent
	if (!P11KeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrSubject = new P11AttrSubject(osobject,P11Attribute::ck8);
	P11Attribute* attrSensitive = new P11AttrSensitive(osobject);
	P11Attribute* attrDecrypt = new P11AttrDecrypt(osobject);
	P11Attribute* attrSign = new P11AttrSign(osobject);
	P11Attribute* attrSignRecover = new P11AttrSignRecover(osobject);
	P11Attribute* attrUnwrap = new P11AttrUnwrap(osobject);
	P11Attribute* attrExtractable = new P11AttrExtractable(osobject);
	P11Attribute* attrAlwaysSensitive = new P11AttrAlwaysSensitive(osobject);
	P11Attribute* attrNeverExtractable = new P11AttrNeverExtractable(osobject);
	P11Attribute* attrWrapWithTrusted = new P11AttrWrapWithTrusted(osobject);
	P11Attribute* attrUnwrapTemplate = new P11AttrUnwrapTemplate(osobject);
	// TODO: CKA_ALWAYS_AUTHENTICATE is accepted, but we do not use it
	P11Attribute* attrAlwaysAuthenticate = new P11AttrAlwaysAuthenticate(osobject);
	// TODO: CKA_PUBLIC_KEY_INFO is accepted, but we do not calculate it
	P11Attribute* attrPublicKeyInfo = new P11AttrPublicKeyInfo(osobject,P11Attribute::ck8);

	// Initialize the attributes
	if
	(
		!attrSubject->init() ||
		!attrSensitive->init() ||
		!attrDecrypt->init() ||
		!attrSign->init() ||
		!attrSignRecover->init() ||
		!attrUnwrap->init() ||
		!attrExtractable->init() ||
		!attrAlwaysSensitive->init() ||
		!attrNeverExtractable->init() ||
		!attrWrapWithTrusted->init() ||
		!attrUnwrapTemplate->init() ||
		!attrAlwaysAuthenticate->init() ||
		!attrPublicKeyInfo->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrSubject;
		delete attrSensitive;
		delete attrDecrypt;
		delete attrSign;
		delete attrSignRecover;
		delete attrUnwrap;
		delete attrExtractable;
		delete attrAlwaysSensitive;
		delete attrNeverExtractable;
		delete attrWrapWithTrusted;
		delete attrUnwrapTemplate;
		delete attrAlwaysAuthenticate;
		delete attrPublicKeyInfo;
		return false;
	}

	// Add them to the map
	attributes[attrSubject->getType()] = attrSubject;
	attributes[attrSensitive->getType()] = attrSensitive;
	attributes[attrDecrypt->getType()] = attrDecrypt;
	attributes[attrSign->getType()] = attrSign;
	attributes[attrSignRecover->getType()] = attrSignRecover;
	attributes[attrUnwrap->getType()] = attrUnwrap;
	attributes[attrExtractable->getType()] = attrExtractable;
	attributes[attrAlwaysSensitive->getType()] = attrAlwaysSensitive;
	attributes[attrNeverExtractable->getType()] = attrNeverExtractable;
	attributes[attrWrapWithTrusted->getType()] = attrWrapWithTrusted;
	attributes[attrUnwrapTemplate->getType()] = attrUnwrapTemplate;
	attributes[attrAlwaysAuthenticate->getType()] = attrAlwaysAuthenticate;
	attributes[attrPublicKeyInfo->getType()] = attrPublicKeyInfo;

	initialized = true;
	return true;
}

// Constructor
P11RSAPrivateKeyObj::P11RSAPrivateKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11RSAPrivateKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_RSA) {
		OSAttribute setKeyType((unsigned long)CKK_RSA);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PrivateKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrModulus = new P11AttrModulus(osobject,P11Attribute::ck6);
	P11Attribute* attrPublicExponent = new P11AttrPublicExponent(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrPrivateExponent = new P11AttrPrivateExponent(osobject);
	P11Attribute* attrPrime1 = new P11AttrPrime1(osobject);
	P11Attribute* attrPrime2 = new P11AttrPrime2(osobject);
	P11Attribute* attrExponent1 = new P11AttrExponent1(osobject);
	P11Attribute* attrExponent2 = new P11AttrExponent2(osobject);
	P11Attribute* attrCoefficient = new P11AttrCoefficient(osobject);
        P11Attribute* attrPrivateHandle = new P11AttrPrivateHandle(osobject);

	// Initialize the attributes
	if
	(
		!attrModulus->init() ||
		!attrPublicExponent->init() ||
		!attrPrivateExponent->init() ||
		!attrPrime1->init() ||
		!attrPrime2->init() ||
		!attrExponent1->init() ||
		!attrExponent2->init() ||
                !attrPrivateHandle->init() ||
		!attrCoefficient->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrModulus;
		delete attrPublicExponent;
		delete attrPrivateExponent;
		delete attrPrime1;
		delete attrPrime2;
		delete attrExponent1;
		delete attrExponent2;
		delete attrCoefficient;
                delete attrPrivateHandle;
		return false;
	}

	// Add them to the map
	attributes[attrModulus->getType()] = attrModulus;
	attributes[attrPublicExponent->getType()] = attrPublicExponent;
	attributes[attrPrivateExponent->getType()] = attrPrivateExponent;
	attributes[attrPrime1->getType()] = attrPrime1;
	attributes[attrPrime2->getType()] = attrPrime2;
	attributes[attrExponent1->getType()] = attrExponent1;
	attributes[attrExponent2->getType()] = attrExponent2;
	attributes[attrCoefficient->getType()] = attrCoefficient;
        attributes[attrPrivateHandle->getType()] = attrPrivateHandle;

	initialized = true;
	return true;
}

// Constructor
P11DSAPrivateKeyObj::P11DSAPrivateKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11DSAPrivateKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DSA) {
		OSAttribute setKeyType((unsigned long)CKK_DSA);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PrivateKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);

	// Initialize the attributes
	if
	(
		!attrPrime->init() ||
		!attrSubPrime->init() ||
		!attrBase->init() ||
		!attrValue->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrPrime;
		delete attrSubPrime;
		delete attrBase;
		delete attrValue;
		return false;
	}

	// Add them to the map
	attributes[attrPrime->getType()] = attrPrime;
	attributes[attrSubPrime->getType()] = attrSubPrime;
	attributes[attrBase->getType()] = attrBase;
	attributes[attrValue->getType()] = attrValue;

	initialized = true;
	return true;
}

// Constructor
P11ECPrivateKeyObj::P11ECPrivateKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11ECPrivateKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_EC) {
		OSAttribute setKeyType((unsigned long)CKK_EC);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PrivateKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrEcParams = new P11AttrEcParams(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
        P11Attribute* attrPrivateHandle = new P11AttrPrivateHandle(osobject);

	// Initialize the attributes
	if
	(
		!attrEcParams->init() ||
                !attrPrivateHandle->init() ||
		!attrValue->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrEcParams;
		delete attrValue;
                delete attrPrivateHandle;
		return false;
	}

	// Add them to the map
	attributes[attrEcParams->getType()] = attrEcParams;
	attributes[attrValue->getType()] = attrValue;
        attributes[attrPrivateHandle->getType()] = attrPrivateHandle;

	initialized = true;
	return true;
}

// Constructor
P11DHPrivateKeyObj::P11DHPrivateKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11DHPrivateKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DH) {
		OSAttribute setKeyType((unsigned long)CKK_DH);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PrivateKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
	P11Attribute* attrValueBits = new P11AttrValueBits(osobject);

	// Initialize the attributes
	if
	(
		!attrPrime->init() ||
		!attrBase->init() ||
		!attrValue->init() ||
		!attrValueBits->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrPrime;
		delete attrBase;
		delete attrValue;
		delete attrValueBits;
		return false;
	}

	// Add them to the map
	attributes[attrPrime->getType()] = attrPrime;
	attributes[attrBase->getType()] = attrBase;
	attributes[attrValue->getType()] = attrValue;
	attributes[attrValueBits->getType()] = attrValueBits;

	initialized = true;
	return true;
}

// Constructor
P11GOSTPrivateKeyObj::P11GOSTPrivateKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11GOSTPrivateKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_GOSTR3410) {
		OSAttribute setKeyType((unsigned long)CKK_GOSTR3410);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11PrivateKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
	P11Attribute* attrGostR3410Params = new P11AttrGostR3410Params(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrGostR3411Params = new P11AttrGostR3411Params(osobject,P11Attribute::ck4|P11Attribute::ck6);
	P11Attribute* attrGost28147Params = new P11AttrGost28147Params(osobject,P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck8);

	// Initialize the attributes
	if
	(
		!attrValue->init() ||
		!attrGostR3410Params->init() ||
		!attrGostR3411Params->init() ||
		!attrGost28147Params->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrValue;
		delete attrGostR3410Params;
		delete attrGostR3411Params;
		delete attrGost28147Params;
		return false;
	}

	// Add them to the map
	attributes[attrValue->getType()] = attrValue;
	attributes[attrGostR3410Params->getType()] = attrGostR3410Params;
	attributes[attrGostR3411Params->getType()] = attrGostR3411Params;
	attributes[attrGost28147Params->getType()] = attrGost28147Params;

	initialized = true;
	return true;
}

// Constructor
P11SecretKeyObj::P11SecretKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11SecretKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_SECRET_KEY) {
		OSAttribute setClass((unsigned long)CKO_SECRET_KEY);
		inobject->setAttribute(CKA_CLASS, setClass);
	}

	// Create parent
	if (!P11KeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrSensitive = new P11AttrSensitive(osobject);
	P11Attribute* attrEncrypt = new P11AttrEncrypt(osobject);
	P11Attribute* attrDecrypt = new P11AttrDecrypt(osobject);
	P11Attribute* attrSign = new P11AttrSign(osobject);
	P11Attribute* attrVerify = new P11AttrVerify(osobject);
	P11Attribute* attrWrap = new P11AttrWrap(osobject);
	P11Attribute* attrUnwrap = new P11AttrUnwrap(osobject);
	P11Attribute* attrExtractable = new P11AttrExtractable(osobject);
	P11Attribute* attrAlwaysSensitive = new P11AttrAlwaysSensitive(osobject);
	P11Attribute* attrNeverExtractable = new P11AttrNeverExtractable(osobject);
	P11Attribute* attrCheckValue = new P11AttrCheckValue(osobject, P11Attribute::ck8);
	P11Attribute* attrWrapWithTrusted = new P11AttrWrapWithTrusted(osobject);
	P11Attribute* attrTrusted = new P11AttrTrusted(osobject);
	P11Attribute* attrWrapTemplate = new P11AttrWrapTemplate(osobject);
	P11Attribute* attrUnwrapTemplate = new P11AttrUnwrapTemplate(osobject);

	// Initialize the attributes
	if
	(
		!attrSensitive->init() ||
		!attrEncrypt->init() ||
		!attrDecrypt->init() ||
		!attrSign->init() ||
		!attrVerify->init() ||
		!attrWrap->init() ||
		!attrUnwrap->init() ||
		!attrExtractable->init() ||
		!attrAlwaysSensitive->init() ||
		!attrNeverExtractable->init() ||
		!attrCheckValue->init() ||
		!attrWrapWithTrusted->init() ||
		!attrTrusted->init() ||
		!attrWrapTemplate->init() ||
		!attrUnwrapTemplate->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrSensitive;
		delete attrEncrypt;
		delete attrDecrypt;
		delete attrSign;
		delete attrVerify;
		delete attrWrap;
		delete attrUnwrap;
		delete attrExtractable;
		delete attrAlwaysSensitive;
		delete attrNeverExtractable;
		delete attrCheckValue;
		delete attrWrapWithTrusted;
		delete attrTrusted;
		delete attrWrapTemplate;
		delete attrUnwrapTemplate;
		return false;
	}

	// Add them to the map
	attributes[attrSensitive->getType()] = attrSensitive;
	attributes[attrEncrypt->getType()] = attrEncrypt;
	attributes[attrDecrypt->getType()] = attrDecrypt;
	attributes[attrSign->getType()] = attrSign;
	attributes[attrVerify->getType()] = attrVerify;
	attributes[attrWrap->getType()] = attrWrap;
	attributes[attrUnwrap->getType()] = attrUnwrap;
	attributes[attrExtractable->getType()] = attrExtractable;
	attributes[attrAlwaysSensitive->getType()] = attrAlwaysSensitive;
	attributes[attrNeverExtractable->getType()] = attrNeverExtractable;
	attributes[attrCheckValue->getType()] = attrCheckValue;
	attributes[attrWrapWithTrusted->getType()] = attrWrapWithTrusted;
	attributes[attrTrusted->getType()] = attrTrusted;
	attributes[attrWrapTemplate->getType()] = attrWrapTemplate;
	attributes[attrUnwrapTemplate->getType()] = attrUnwrapTemplate;

	initialized = true;
	return true;
}

// Constructor
P11GenericSecretKeyObj::P11GenericSecretKeyObj()
{
	initialized = false;
	keytype = CKK_VENDOR_DEFINED;
}

// Add attributes
bool P11GenericSecretKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != keytype) {
		OSAttribute setKeyType(keytype);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11SecretKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
	P11Attribute* attrValueLen = new P11AttrValueLen(osobject);

	// Initialize the attributes
	if
	(
		!attrValue->init() ||
		!attrValueLen->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrValue;
		delete attrValueLen;
		return false;
	}

	// Add them to the map
	attributes[attrValue->getType()] = attrValue;
	attributes[attrValueLen->getType()] = attrValueLen;

	initialized = true;
	return true;
}

// Set Key Type
bool P11GenericSecretKeyObj::setKeyType(CK_KEY_TYPE inKeytype)
{
	if (!initialized)
	{
		keytype = inKeytype;
		return true;
	}
	else
		return false;
}

// Get Key Type
CK_KEY_TYPE P11GenericSecretKeyObj::getKeyType()
{
	return keytype;
}

// Constructor
P11AESSecretKeyObj::P11AESSecretKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11AESSecretKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_AES) {
		OSAttribute setKeyType((unsigned long)CKK_AES);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11SecretKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
	P11Attribute* attrValueLen = new P11AttrValueLen(osobject,P11Attribute::ck6);

	// Initialize the attributes
	if
	(
		!attrValue->init() ||
		!attrValueLen->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrValue;
		delete attrValueLen;
		return false;
	}

	// Add them to the map
	attributes[attrValue->getType()] = attrValue;
	attributes[attrValueLen->getType()] = attrValueLen;

	initialized = true;
	return true;
}

// Constructor
P11DESSecretKeyObj::P11DESSecretKeyObj()
{
	initialized = false;
	keytype = CKK_VENDOR_DEFINED;
}

// Add attributes
bool P11DESSecretKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != keytype) {
		OSAttribute setKeyType(keytype);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11SecretKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);

	// Initialize the attributes
	if (!attrValue->init())
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrValue;
		return false;
	}

	// Add them to the map
	attributes[attrValue->getType()] = attrValue;

	initialized = true;
	return true;
}

// Set Key Type
bool P11DESSecretKeyObj::setKeyType(CK_KEY_TYPE inKeytype)
{
	if (!initialized)
	{
		keytype = inKeytype;
		return true;
	}
	else
		return false;
}

// Get Key Type
CK_KEY_TYPE P11DESSecretKeyObj::getKeyType()
{
	return keytype;
}

// Constructor
P11GOSTSecretKeyObj::P11GOSTSecretKeyObj()
{
	initialized = false;
}

// Add attributes
bool P11GOSTSecretKeyObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_GOST28147) {
		OSAttribute setKeyType((unsigned long)CKK_GOST28147);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11SecretKeyObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrValue = new P11AttrValue(osobject,P11Attribute::ck1|P11Attribute::ck4|P11Attribute::ck6|P11Attribute::ck7);
	P11Attribute* attrGost28147Params = new P11AttrGost28147Params(osobject,P11Attribute::ck1|P11Attribute::ck3|P11Attribute::ck5);

	// Initialize the attributes
	if
	(
		!attrValue->init() ||
		!attrGost28147Params->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrValue;
		delete attrGost28147Params;
		return false;
	}

	// Add them to the map
	attributes[attrValue->getType()] = attrValue;
	attributes[attrGost28147Params->getType()] = attrGost28147Params;

	initialized = true;
	return true;
}

// Constructor
P11DomainObj::P11DomainObj()
{
	initialized = false;
}

// Add attributes
bool P11DomainObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_CLASS) || inobject->getUnsignedLongValue(CKA_CLASS, CKO_VENDOR_DEFINED) != CKO_DOMAIN_PARAMETERS) {
		OSAttribute setClass((unsigned long)CKO_DOMAIN_PARAMETERS);
		inobject->setAttribute(CKA_CLASS, setClass);
	}

	// Create parent
	if (!P11Object::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrKeyType = new P11AttrKeyType(osobject);
	P11Attribute* attrLocal = new P11AttrLocal(osobject);

	// Initialize the attributes
	if
	(
		!attrKeyType->init() ||
		!attrLocal->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrKeyType;
		delete attrLocal;
		return false;
	}

	// Add them to the map
	attributes[attrKeyType->getType()] = attrKeyType;
	attributes[attrLocal->getType()] = attrLocal;

	initialized = true;
	return true;
}

// Constructor
P11DSADomainObj::P11DSADomainObj()
{
	initialized = false;
}

// Add attributes
bool P11DSADomainObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DSA) {
		OSAttribute setKeyType((unsigned long)CKK_DSA);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11DomainObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4);
	P11Attribute* attrSubPrime = new P11AttrSubPrime(osobject,P11Attribute::ck4);
	P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4);
	P11Attribute* attrPrimeBits = new P11AttrPrimeBits(osobject);

	// Initialize the attributes
	if
	(
		!attrPrime->init() ||
		!attrSubPrime->init() ||
		!attrBase->init() ||
		!attrPrimeBits->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrPrime;
		delete attrSubPrime;
		delete attrBase;
		delete attrPrimeBits;
		return false;
	}

	// Add them to the map
	attributes[attrPrime->getType()] = attrPrime;
	attributes[attrSubPrime->getType()] = attrSubPrime;
	attributes[attrBase->getType()] = attrBase;
	attributes[attrPrimeBits->getType()] = attrPrimeBits;

	initialized = true;
	return true;
}

// Constructor
P11DHDomainObj::P11DHDomainObj()
{
	initialized = false;
}

// Add attributes
bool P11DHDomainObj::init(OSObject *inobject)
{
	if (initialized) return true;
	if (inobject == NULL) return false;

	if (!inobject->attributeExists(CKA_KEY_TYPE) || inobject->getUnsignedLongValue(CKA_KEY_TYPE, CKK_VENDOR_DEFINED) != CKK_DH) {
		OSAttribute setKeyType((unsigned long)CKK_DH);
		inobject->setAttribute(CKA_KEY_TYPE, setKeyType);
	}

	// Create parent
	if (!P11DomainObj::init(inobject)) return false;

	// Create attributes
	P11Attribute* attrPrime = new P11AttrPrime(osobject,P11Attribute::ck4);
	P11Attribute* attrBase = new P11AttrBase(osobject,P11Attribute::ck4);
	P11Attribute* attrPrimeBits = new P11AttrPrimeBits(osobject);

	// Initialize the attributes
	if
	(
		!attrPrime->init() ||
		!attrBase->init() ||
		!attrPrimeBits->init()
	)
	{
		ERROR_MSG("Could not initialize the attribute");
		delete attrPrime;
		delete attrBase;
		delete attrPrimeBits;
		return false;
	}

	// Add them to the map
	attributes[attrPrime->getType()] = attrPrime;
	attributes[attrBase->getType()] = attrBase;
	attributes[attrPrimeBits->getType()] = attrPrimeBits;

	initialized = true;
	return true;
}