147e946eWyllys Ingersoll/*
247e946eWyllys Ingersoll *		Common Public License Version 0.5
347e946eWyllys Ingersoll *
447e946eWyllys Ingersoll *		THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF
547e946eWyllys Ingersoll *		THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE,
647e946eWyllys Ingersoll *		REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
747e946eWyllys Ingersoll *		RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
847e946eWyllys Ingersoll *
947e946eWyllys Ingersoll *		1. DEFINITIONS
1047e946eWyllys Ingersoll *
1147e946eWyllys Ingersoll *		"Contribution" means:
1247e946eWyllys Ingersoll *			a) in the case of the initial Contributor, the
1347e946eWyllys Ingersoll *			initial code and documentation distributed under
1447e946eWyllys Ingersoll *			this Agreement, and
1547e946eWyllys Ingersoll *
1647e946eWyllys Ingersoll *			b) in the case of each subsequent Contributor:
1747e946eWyllys Ingersoll *			i) changes to the Program, and
1847e946eWyllys Ingersoll *			ii) additions to the Program;
1947e946eWyllys Ingersoll *
2047e946eWyllys Ingersoll *			where such changes and/or additions to the Program
2147e946eWyllys Ingersoll *			originate from and are distributed by that
2247e946eWyllys Ingersoll *			particular Contributor. A Contribution 'originates'
2347e946eWyllys Ingersoll *			from a Contributor if it was added to the Program
2447e946eWyllys Ingersoll *			by such Contributor itself or anyone acting on such
2547e946eWyllys Ingersoll *			Contributor's behalf. Contributions do not include
2647e946eWyllys Ingersoll *			additions to the Program which: (i) are separate
2747e946eWyllys Ingersoll *			modules of software distributed in conjunction with
2847e946eWyllys Ingersoll *			the Program under their own license agreement, and
2947e946eWyllys Ingersoll *			(ii) are not derivative works of the Program.
3047e946eWyllys Ingersoll *
3147e946eWyllys Ingersoll *
3247e946eWyllys Ingersoll *		"Contributor" means any person or entity that distributes
3347e946eWyllys Ingersoll *		the Program.
3447e946eWyllys Ingersoll *
3547e946eWyllys Ingersoll *		"Licensed Patents " mean patent claims licensable by a
3647e946eWyllys Ingersoll *		Contributor which are necessarily infringed by the use or
3747e946eWyllys Ingersoll *		sale of its Contribution alone or when combined with the
3847e946eWyllys Ingersoll *		Program.
3947e946eWyllys Ingersoll *
4047e946eWyllys Ingersoll *		"Program" means the Contributions distributed in
4147e946eWyllys Ingersoll *		accordance with this Agreement.
4247e946eWyllys Ingersoll *
4347e946eWyllys Ingersoll *		"Recipient" means anyone who receives the Program under
4447e946eWyllys Ingersoll *		this Agreement, including all Contributors.
4547e946eWyllys Ingersoll *
4647e946eWyllys Ingersoll *		2. GRANT OF RIGHTS
4747e946eWyllys Ingersoll *
4847e946eWyllys Ingersoll *			a) Subject to the terms of this Agreement, each
4947e946eWyllys Ingersoll *			Contributor hereby grants Recipient a
5047e946eWyllys Ingersoll *			no - exclusive, worldwide, royalt - free copyright
5147e946eWyllys Ingersoll *			license to reproduce, prepare derivative works of,
5247e946eWyllys Ingersoll *			publicly display, publicly perform, distribute and
5347e946eWyllys Ingersoll *			sublicense the Contribution of such Contributor, if
5447e946eWyllys Ingersoll *			any, and such derivative works, in source code and
5547e946eWyllys Ingersoll *			object code form.
5647e946eWyllys Ingersoll *
5747e946eWyllys Ingersoll *			b) Subject to the terms of this Agreement, each
5847e946eWyllys Ingersoll *			Contributor hereby grants Recipient a
5947e946eWyllys Ingersoll *			no - exclusive, worldwide, royalt - free patent
6047e946eWyllys Ingersoll *			license under Licensed Patents to make, use, sell,
6147e946eWyllys Ingersoll *			offer to sell, import and otherwise transfer the
6247e946eWyllys Ingersoll *			Contribution of such Contributor, if any, in source
6347e946eWyllys Ingersoll *			code and object code form. This patent license
6447e946eWyllys Ingersoll *			shall apply to the combination of the Contribution
6547e946eWyllys Ingersoll *			and the Program if, at the time the Contribution is
6647e946eWyllys Ingersoll *			added by the Contributor, such addition of the
6747e946eWyllys Ingersoll *			Contribution causes such combination to be covered
6847e946eWyllys Ingersoll *			by the Licensed Patents. The patent license shall
6947e946eWyllys Ingersoll *			not apply to any other combinations which include
7047e946eWyllys Ingersoll *			the Contribution. No hardware per se is licensed
7147e946eWyllys Ingersoll *			hereunder.
7247e946eWyllys Ingersoll *
7347e946eWyllys Ingersoll *			c) Recipient understands that although each
7447e946eWyllys Ingersoll *			Contributor grants the licenses to its
7547e946eWyllys Ingersoll *			Contributions set forth herein, no assurances are
7647e946eWyllys Ingersoll *			provided by any Contributor that the Program does
7747e946eWyllys Ingersoll *			not infringe the patent or other intellectual
7847e946eWyllys Ingersoll *			property rights of any other entity. Each
7947e946eWyllys Ingersoll *			Contributor disclaims any liability to Recipient
8047e946eWyllys Ingersoll *			for claims brought by any other entity based on
8147e946eWyllys Ingersoll *			infringement of intellectual property rights or
8247e946eWyllys Ingersoll *			otherwise. As a condition to exercising the rights
8347e946eWyllys Ingersoll *			and licenses granted hereunder, each Recipient
8447e946eWyllys Ingersoll *			hereby assumes sole responsibility to secure any
8547e946eWyllys Ingersoll *			other intellectual property rights needed, if any.
8647e946eWyllys Ingersoll *
8747e946eWyllys Ingersoll *			For example, if a third party patent license is
8847e946eWyllys Ingersoll *			required to allow Recipient to distribute the
8947e946eWyllys Ingersoll *			Program, it is Recipient's responsibility to
9047e946eWyllys Ingersoll *			acquire that license before distributing the
9147e946eWyllys Ingersoll *			Program.
9247e946eWyllys Ingersoll *
9347e946eWyllys Ingersoll *			d) Each Contributor represents that to its
9447e946eWyllys Ingersoll *			knowledge it has sufficient copyright rights in its
9547e946eWyllys Ingersoll *			Contribution, if any, to grant the copyright
9647e946eWyllys Ingersoll *			license set forth in this Agreement.
9747e946eWyllys Ingersoll *
9847e946eWyllys Ingersoll *		3. REQUIREMENTS
9947e946eWyllys Ingersoll *
10047e946eWyllys Ingersoll *		A Contributor may choose to distribute the Program in
10147e946eWyllys Ingersoll *		object code form under its own license agreement, provided
10247e946eWyllys Ingersoll *		that:
10347e946eWyllys Ingersoll *			a) it complies with the terms and conditions of
10447e946eWyllys Ingersoll *			this Agreement; and
10547e946eWyllys Ingersoll *
10647e946eWyllys Ingersoll *			b) its license agreement:
10747e946eWyllys Ingersoll *			i) effectively disclaims on behalf of all
10847e946eWyllys Ingersoll *			Contributors all warranties and conditions, express
10947e946eWyllys Ingersoll *			and implied, including warranties or conditions of
11047e946eWyllys Ingersoll *			title and no - infringement, and implied warranties
11147e946eWyllys Ingersoll *			or conditions of merchantability and fitness for a
11247e946eWyllys Ingersoll *			particular purpose;
11347e946eWyllys Ingersoll *
11447e946eWyllys Ingersoll *			ii) effectively excludes on behalf of all
11547e946eWyllys Ingersoll *			Contributors all liability for damages, including
11647e946eWyllys Ingersoll *			direct, indirect, special, incidental and
11747e946eWyllys Ingersoll *			consequential damages, such as lost profits;
11847e946eWyllys Ingersoll *
11947e946eWyllys Ingersoll *			iii) states that any provisions which differ from
12047e946eWyllys Ingersoll *			this Agreement are offered by that Contributor
12147e946eWyllys Ingersoll *			alone and not by any other party; and
12247e946eWyllys Ingersoll *
12347e946eWyllys Ingersoll *			iv) states that source code for the Program is
12447e946eWyllys Ingersoll *			available from such Contributor, and informs
12547e946eWyllys Ingersoll *			licensees how to obtain it in a reasonable manner
12647e946eWyllys Ingersoll *			on or through a medium customarily used for
12747e946eWyllys Ingersoll *			software exchange.
12847e946eWyllys Ingersoll *
12947e946eWyllys Ingersoll *		When the Program is made available in source code form:
13047e946eWyllys Ingersoll *			a) it must be made available under this Agreement;
13147e946eWyllys Ingersoll *			and
13247e946eWyllys Ingersoll *			b) a copy of this Agreement must be included with
13347e946eWyllys Ingersoll *			each copy of the Program.
13447e946eWyllys Ingersoll *
13547e946eWyllys Ingersoll *		Contributors may not remove or alter any copyright notices
13647e946eWyllys Ingersoll *		contained within the Program.
13747e946eWyllys Ingersoll *
13847e946eWyllys Ingersoll *		Each Contributor must identify itself as the originator of
13947e946eWyllys Ingersoll *		its Contribution, if any, in a manner that reasonably
14047e946eWyllys Ingersoll *		allows subsequent Recipients to identify the originator of
14147e946eWyllys Ingersoll *		the Contribution.
14247e946eWyllys Ingersoll *
14347e946eWyllys Ingersoll *
14447e946eWyllys Ingersoll *		4. COMMERCIAL DISTRIBUTION
14547e946eWyllys Ingersoll *
14647e946eWyllys Ingersoll *		Commercial distributors of software may accept certain
14747e946eWyllys Ingersoll *		responsibilities with respect to end users, business
14847e946eWyllys Ingersoll *		partners and the like. While this license is intended to
14947e946eWyllys Ingersoll *		facilitate the commercial use of the Program, the
15047e946eWyllys Ingersoll *		Contributor who includes the Program in a commercial
15147e946eWyllys Ingersoll *		product offering should do so in a manner which does not
15247e946eWyllys Ingersoll *		create potential liability for other Contributors.
15347e946eWyllys Ingersoll *		Therefore, if a Contributor includes the Program in a
15447e946eWyllys Ingersoll *		commercial product offering, such Contributor ("Commercial
15547e946eWyllys Ingersoll *		Contributor") hereby agrees to defend and indemnify every
15647e946eWyllys Ingersoll *		other Contributor ("Indemnified Contributor") against any
15747e946eWyllys Ingersoll *		losses, damages and costs (collectively "Losses") arising
15847e946eWyllys Ingersoll *		from claims, lawsuits and other legal actions brought by a
15947e946eWyllys Ingersoll *		third party against the Indemnified Contributor to the
16047e946eWyllys Ingersoll *		extent caused by the acts or omissions of such Commercial
16147e946eWyllys Ingersoll *		Contributor in connection with its distribution of the
16247e946eWyllys Ingersoll *		Program in a commercial product offering. The obligations
16347e946eWyllys Ingersoll *		in this section do not apply to any claims or Losses
16447e946eWyllys Ingersoll *		relating to any actual or alleged intellectual property
16547e946eWyllys Ingersoll *		infringement. In order to qualify, an Indemnified
16647e946eWyllys Ingersoll *		Contributor must: a) promptly notify the Commercial
16747e946eWyllys Ingersoll *		Contributor in writing of such claim, and b) allow the
16847e946eWyllys Ingersoll *		Commercial Contributor to control, and cooperate with the
16947e946eWyllys Ingersoll *		Commercial Contributor in, the defense and any related
17047e946eWyllys Ingersoll *		settlement negotiations. The Indemnified Contributor may
17147e946eWyllys Ingersoll *		participate in any such claim at its own expense.
17247e946eWyllys Ingersoll *
17347e946eWyllys Ingersoll *
17447e946eWyllys Ingersoll *		For example, a Contributor might include the Program in a
17547e946eWyllys Ingersoll *		commercial product offering, Product X. That Contributor
17647e946eWyllys Ingersoll *		is then a Commercial Contributor. If that Commercial
17747e946eWyllys Ingersoll *		Contributor then makes performance claims, or offers
17847e946eWyllys Ingersoll *		warranties related to Product X, those performance claims
17947e946eWyllys Ingersoll *		and warranties are such Commercial Contributor's
18047e946eWyllys Ingersoll *		responsibility alone. Under this section, the Commercial
18147e946eWyllys Ingersoll *		Contributor would have to defend claims against the other
18247e946eWyllys Ingersoll *		Contributors related to those performance claims and
18347e946eWyllys Ingersoll *		warranties, and if a court requires any other Contributor
18447e946eWyllys Ingersoll *		to pay any damages as a result, the Commercial Contributor
18547e946eWyllys Ingersoll *		must pay those damages.
18647e946eWyllys Ingersoll *
18747e946eWyllys Ingersoll *
18847e946eWyllys Ingersoll *		5. NO WARRANTY
18947e946eWyllys Ingersoll *
19047e946eWyllys Ingersoll *		EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE
19147e946eWyllys Ingersoll *		PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
19247e946eWyllys Ingersoll *		WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
19347e946eWyllys Ingersoll *		IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
19447e946eWyllys Ingersoll *		CONDITIONS OF TITLE, NO - INFRINGEMENT, MERCHANTABILITY OR
19547e946eWyllys Ingersoll *		FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
19647e946eWyllys Ingersoll *		responsible for determining the appropriateness of using
19747e946eWyllys Ingersoll *		and distributing the Program and assumes all risks
19847e946eWyllys Ingersoll *		associated with its exercise of rights under this
19947e946eWyllys Ingersoll *		Agreement, including but not limited to the risks and
20047e946eWyllys Ingersoll *		costs of program errors, compliance with applicable laws,
20147e946eWyllys Ingersoll *		damage to or loss of data, programs or equipment, and
20247e946eWyllys Ingersoll *		unavailability or interruption of operations.
20347e946eWyllys Ingersoll *
20447e946eWyllys Ingersoll *		6. DISCLAIMER OF LIABILITY
20547e946eWyllys Ingersoll *		EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER
20647e946eWyllys Ingersoll *		RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY
20747e946eWyllys Ingersoll *		FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
20847e946eWyllys Ingersoll *		OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
20947e946eWyllys Ingersoll *		LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
21047e946eWyllys Ingersoll *		LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21147e946eWyllys Ingersoll *		(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
21247e946eWyllys Ingersoll *		OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE
21347e946eWyllys Ingersoll *		OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
21447e946eWyllys Ingersoll *		POSSIBILITY OF SUCH DAMAGES.
21547e946eWyllys Ingersoll *
21647e946eWyllys Ingersoll *		7. GENERAL
21747e946eWyllys Ingersoll *
21847e946eWyllys Ingersoll *		If any provision of this Agreement is invalid or
21947e946eWyllys Ingersoll *		unenforceable under applicable law, it shall not affect
22047e946eWyllys Ingersoll *		the validity or enforceability of the remainder of the
22147e946eWyllys Ingersoll *		terms of this Agreement, and without further action by the
22247e946eWyllys Ingersoll *		parties hereto, such provision shall be reformed to the
22347e946eWyllys Ingersoll *		minimum extent necessary to make such provision valid and
22447e946eWyllys Ingersoll *		enforceable.
22547e946eWyllys Ingersoll *
22647e946eWyllys Ingersoll *
22747e946eWyllys Ingersoll *		If Recipient institutes patent litigation against a
22847e946eWyllys Ingersoll *		Contributor with respect to a patent applicable to
22947e946eWyllys Ingersoll *		software (including a cros - claim or counterclaim in a
23047e946eWyllys Ingersoll *		lawsuit), then any patent licenses granted by that
23147e946eWyllys Ingersoll *		Contributor to such Recipient under this Agreement shall
23247e946eWyllys Ingersoll *		terminate as of the date such litigation is filed. In
23347e946eWyllys Ingersoll *		addition, If Recipient institutes patent litigation
23447e946eWyllys Ingersoll *		against any entity (including a cros - claim or
23547e946eWyllys Ingersoll *		counterclaim in a lawsuit) alleging that the Program
23647e946eWyllys Ingersoll *		itself (excluding combinations of the Program with other
23747e946eWyllys Ingersoll *		software or hardware) infringes such Recipient's
23847e946eWyllys Ingersoll *		patent(s), then such Recipient's rights granted under
23947e946eWyllys Ingersoll *		Section 2(b) shall terminate as of the date such
24047e946eWyllys Ingersoll *		litigation is filed.
24147e946eWyllys Ingersoll *
24247e946eWyllys Ingersoll *		All Recipient's rights under this Agreement shall
24347e946eWyllys Ingersoll *		terminate if it fails to comply with any of the material
24447e946eWyllys Ingersoll *		terms or conditions of this Agreement and does not cure
24547e946eWyllys Ingersoll *		such failure in a reasonable period of time after becoming
24647e946eWyllys Ingersoll *		aware of such noncompliance. If all Recipient's rights
24747e946eWyllys Ingersoll *		under this Agreement terminate, Recipient agrees to cease
24847e946eWyllys Ingersoll *		use and distribution of the Program as soon as reasonably
24947e946eWyllys Ingersoll *		practicable. However, Recipient's obligations under this
25047e946eWyllys Ingersoll *		Agreement and any licenses granted by Recipient relating
25147e946eWyllys Ingersoll *		to the Program shall continue and survive.
25247e946eWyllys Ingersoll *
25347e946eWyllys Ingersoll *		Everyone is permitted to copy and distribute copies of
25447e946eWyllys Ingersoll *		this Agreement, but in order to avoid inconsistency the
25547e946eWyllys Ingersoll *		Agreement is copyrighted and may only be modified in the
25647e946eWyllys Ingersoll *		following manner. The Agreement Steward reserves the right
25747e946eWyllys Ingersoll *		to publish new versions (including revisions) of this
25847e946eWyllys Ingersoll *		Agreement from time to time. No one other than the
25947e946eWyllys Ingersoll *		Agreement Steward has the right to modify this Agreement.
26047e946eWyllys Ingersoll *
26147e946eWyllys Ingersoll *		IBM is the initial Agreement Steward. IBM may assign the
26247e946eWyllys Ingersoll *		responsibility to serve as the Agreement Steward to a
26347e946eWyllys Ingersoll *		suitable separate entity. Each new version of the
26447e946eWyllys Ingersoll *		Agreement will be given a distinguishing version number.
26547e946eWyllys Ingersoll *		The Program (including Contributions) may always be
26647e946eWyllys Ingersoll *		distributed subject to the version of the Agreement under
26747e946eWyllys Ingersoll *		which it was received. In addition, after a new version of
26847e946eWyllys Ingersoll *		the Agreement is published, Contributor may elect to
26947e946eWyllys Ingersoll *		distribute the Program (including its Contributions) under
27047e946eWyllys Ingersoll *		the new version. Except as expressly stated in Sections
27147e946eWyllys Ingersoll *		2(a) and 2(b) above, Recipient receives no rights or
27247e946eWyllys Ingersoll *		licenses to the intellectual property of any Contributor
27347e946eWyllys Ingersoll *		under this Agreement, whether expressly, by implication,
27447e946eWyllys Ingersoll *		estoppel or otherwise. All rights in the Program not
27547e946eWyllys Ingersoll *		expressly granted under this Agreement are reserved.
27647e946eWyllys Ingersoll *
27747e946eWyllys Ingersoll *
27847e946eWyllys Ingersoll *		This Agreement is governed by the laws of the State of New
27947e946eWyllys Ingersoll *		York and the intellectual property laws of the United
28047e946eWyllys Ingersoll *		States of America. No party to this Agreement will bring a
28147e946eWyllys Ingersoll *		legal action under this Agreement more than one year after
28247e946eWyllys Ingersoll *		the cause of action arose. Each party waives its rights to
28347e946eWyllys Ingersoll *		a jury trial in any resulting litigation.
28447e946eWyllys Ingersoll *
28547e946eWyllys Ingersoll *
28647e946eWyllys Ingersoll *
28747e946eWyllys Ingersoll * (C) COPYRIGHT International Business Machines Corp. 2001, 2002
28847e946eWyllys Ingersoll */
28947e946eWyllys Ingersoll/*
29047e946eWyllys Ingersoll * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
29147e946eWyllys Ingersoll * Use is subject to license terms.
29247e946eWyllys Ingersoll */
29347e946eWyllys Ingersoll#include "tpmtok_int.h"
29447e946eWyllys Ingersoll
29547e946eWyllys IngersollCK_RV
29647e946eWyllys Ingersollhwf_object_check_required_attributes(TEMPLATE *tmpl, CK_ULONG mode)
29747e946eWyllys Ingersoll{
29847e946eWyllys Ingersoll	CK_ATTRIBUTE * attr = NULL;
29947e946eWyllys Ingersoll	CK_BBOOL    found;
30047e946eWyllys Ingersoll
30147e946eWyllys Ingersoll	found = template_attribute_find(tmpl, CKA_HW_FEATURE_TYPE, &attr);
30247e946eWyllys Ingersoll	if (! found) {
30347e946eWyllys Ingersoll		if (mode == MODE_CREATE) {
30447e946eWyllys Ingersoll			return (CKR_TEMPLATE_INCOMPLETE);
30547e946eWyllys Ingersoll		}
30647e946eWyllys Ingersoll	}
30747e946eWyllys Ingersoll
30847e946eWyllys Ingersoll	return (template_check_required_base_attributes(tmpl, mode));
30947e946eWyllys Ingersoll}
31047e946eWyllys Ingersoll
31147e946eWyllys IngersollCK_RV
31247e946eWyllys Ingersollclock_check_required_attributes(TEMPLATE *tmpl, CK_ULONG mode)
31347e946eWyllys Ingersoll{
31447e946eWyllys Ingersoll	CK_ATTRIBUTE *attr = NULL;
31547e946eWyllys Ingersoll	CK_BBOOL	found;
31647e946eWyllys Ingersoll
31747e946eWyllys Ingersoll	if (mode == MODE_CREATE) {
31847e946eWyllys Ingersoll		found = template_attribute_find(tmpl, CKA_VALUE, &attr);
31947e946eWyllys Ingersoll		if (! found) {
32047e946eWyllys Ingersoll			return (CKR_TEMPLATE_INCOMPLETE);
32147e946eWyllys Ingersoll		}
32247e946eWyllys Ingersoll	}
32347e946eWyllys Ingersoll
32447e946eWyllys Ingersoll	return (hwf_object_check_required_attributes(tmpl, mode));
32547e946eWyllys Ingersoll}
32647e946eWyllys Ingersoll
32747e946eWyllys IngersollCK_RV
32847e946eWyllys Ingersollcounter_check_required_attributes(TEMPLATE *tmpl, CK_ULONG mode)
32947e946eWyllys Ingersoll{
33047e946eWyllys Ingersoll	CK_ATTRIBUTE *attr = NULL;
33147e946eWyllys Ingersoll	CK_BBOOL	found;
33247e946eWyllys Ingersoll
33347e946eWyllys Ingersoll	if (mode == MODE_CREATE) {
33447e946eWyllys Ingersoll		found = template_attribute_find(tmpl, CKA_VALUE, &attr);
33547e946eWyllys Ingersoll		if (! found) {
33647e946eWyllys Ingersoll			return (CKR_TEMPLATE_INCOMPLETE);
33747e946eWyllys Ingersoll		}
33847e946eWyllys Ingersoll
33947e946eWyllys Ingersoll		found = template_attribute_find(tmpl, CKA_HAS_RESET, &attr);
34047e946eWyllys Ingersoll		if (! found) {
34147e946eWyllys Ingersoll			return (CKR_TEMPLATE_INCOMPLETE);
34247e946eWyllys Ingersoll		}
34347e946eWyllys Ingersoll
34447e946eWyllys Ingersoll		found = template_attribute_find(tmpl, CKA_RESET_ON_INIT, &attr);
34547e946eWyllys Ingersoll		if (! found) {
34647e946eWyllys Ingersoll			return (CKR_TEMPLATE_INCOMPLETE);
34747e946eWyllys Ingersoll		}
34847e946eWyllys Ingersoll	}
34947e946eWyllys Ingersoll
35047e946eWyllys Ingersoll	return (hwf_object_check_required_attributes(tmpl, mode));
35147e946eWyllys Ingersoll}
35247e946eWyllys Ingersoll
35347e946eWyllys Ingersoll
35447e946eWyllys Ingersoll// hwf_object_validate_attribute()
35547e946eWyllys Ingersoll//
35647e946eWyllys IngersollCK_RV
35747e946eWyllys Ingersollhwf_validate_attribute(TEMPLATE *tmpl, CK_ATTRIBUTE *attr, CK_ULONG mode)
35847e946eWyllys Ingersoll{
35947e946eWyllys Ingersoll	switch (attr->type) {
36047e946eWyllys Ingersoll		case CKA_HW_FEATURE_TYPE:
36147e946eWyllys Ingersoll		if (mode == MODE_CREATE)
36247e946eWyllys Ingersoll			return (CKR_OK);
36347e946eWyllys Ingersoll		else
36447e946eWyllys Ingersoll			return (CKR_ATTRIBUTE_READ_ONLY);
36547e946eWyllys Ingersoll
36647e946eWyllys Ingersoll		default:
36747e946eWyllys Ingersoll			return (template_validate_base_attribute(tmpl,
36847e946eWyllys Ingersoll			    attr, mode));
36947e946eWyllys Ingersoll	}
37047e946eWyllys Ingersoll}
37147e946eWyllys Ingersoll
37247e946eWyllys IngersollCK_RV
37347e946eWyllys Ingersollclock_validate_attribute(TEMPLATE *tmpl, CK_ATTRIBUTE *attr, CK_ULONG mode) {
37447e946eWyllys Ingersoll	switch (attr->type) {
37547e946eWyllys Ingersoll		case CKA_VALUE:
37647e946eWyllys Ingersoll		return (CKR_OK);
37747e946eWyllys Ingersoll
37847e946eWyllys Ingersoll		default:
37947e946eWyllys Ingersoll		return (hwf_validate_attribute(tmpl, attr, mode));
38047e946eWyllys Ingersoll	}
38147e946eWyllys Ingersoll}
38247e946eWyllys Ingersoll
38347e946eWyllys IngersollCK_RV
38447e946eWyllys Ingersollcounter_validate_attribute(TEMPLATE *tmpl, CK_ATTRIBUTE *attr, CK_ULONG mode)
38547e946eWyllys Ingersoll{
38647e946eWyllys Ingersoll	switch (attr->type) {
38747e946eWyllys Ingersoll		case CKA_VALUE:
38847e946eWyllys Ingersoll		/* Fall Through */
38947e946eWyllys Ingersoll		case CKA_HAS_RESET:
39047e946eWyllys Ingersoll		/* Fall Through */
39147e946eWyllys Ingersoll		case CKA_RESET_ON_INIT:
39247e946eWyllys Ingersoll		return (CKR_ATTRIBUTE_READ_ONLY);
39347e946eWyllys Ingersoll
39447e946eWyllys Ingersoll		default:
39547e946eWyllys Ingersoll		return (hwf_validate_attribute(tmpl, attr, mode));
39647e946eWyllys Ingersoll	}
39747e946eWyllys Ingersoll}
39847e946eWyllys Ingersoll
39947e946eWyllys Ingersoll
40047e946eWyllys IngersollCK_RV
40147e946eWyllys Ingersollclock_set_default_attributes(TEMPLATE *tmpl)
40247e946eWyllys Ingersoll{
40347e946eWyllys Ingersoll	CK_ATTRIBUTE		*value_attr;
40447e946eWyllys Ingersoll
40547e946eWyllys Ingersoll	value_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE));
40647e946eWyllys Ingersoll
40747e946eWyllys Ingersoll	if (! value_attr) {
40847e946eWyllys Ingersoll		return (CKR_HOST_MEMORY);
40947e946eWyllys Ingersoll	}
41047e946eWyllys Ingersoll
41147e946eWyllys Ingersoll	value_attr->type	= CKA_VALUE;
41247e946eWyllys Ingersoll	value_attr->ulValueLen = 0;
41347e946eWyllys Ingersoll	value_attr->pValue	= NULL;
41447e946eWyllys Ingersoll
41547e946eWyllys Ingersoll	(void) template_update_attribute(tmpl, value_attr);
41647e946eWyllys Ingersoll
41747e946eWyllys Ingersoll	return (CKR_OK);
41847e946eWyllys Ingersoll}
41947e946eWyllys Ingersoll
42047e946eWyllys IngersollCK_RV
42147e946eWyllys Ingersollcounter_set_default_attributes(TEMPLATE *tmpl)
42247e946eWyllys Ingersoll{
42347e946eWyllys Ingersoll	CK_ATTRIBUTE	 *value_attr;
42447e946eWyllys Ingersoll	CK_ATTRIBUTE	 *hasreset_attr;
42547e946eWyllys Ingersoll	CK_ATTRIBUTE	 *resetoninit_attr;
42647e946eWyllys Ingersoll
42747e946eWyllys Ingersoll	value_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE));
42847e946eWyllys Ingersoll	hasreset_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE) +
42947e946eWyllys Ingersoll	    sizeof (CK_BBOOL));
43047e946eWyllys Ingersoll	resetoninit_attr = (CK_ATTRIBUTE *)malloc(sizeof (CK_ATTRIBUTE) +
43147e946eWyllys Ingersoll	    sizeof (CK_BBOOL));
43247e946eWyllys Ingersoll
43347e946eWyllys Ingersoll	if (! value_attr || ! hasreset_attr || ! resetoninit_attr) {
43447e946eWyllys Ingersoll		if (value_attr) free(value_attr);
43547e946eWyllys Ingersoll		if (hasreset_attr) free(hasreset_attr);
43647e946eWyllys Ingersoll		if (resetoninit_attr) free(resetoninit_attr);
43747e946eWyllys Ingersoll		return (CKR_HOST_MEMORY);
43847e946eWyllys Ingersoll	}
43947e946eWyllys Ingersoll
44047e946eWyllys Ingersoll	value_attr->type	= CKA_VALUE;
44147e946eWyllys Ingersoll	value_attr->ulValueLen = 0;
44247e946eWyllys Ingersoll	value_attr->pValue	= NULL;
44347e946eWyllys Ingersoll
44447e946eWyllys Ingersoll	hasreset_attr->type	= CKA_HAS_RESET;
44547e946eWyllys Ingersoll	hasreset_attr->ulValueLen = sizeof (CK_BBOOL);
44647e946eWyllys Ingersoll	hasreset_attr->pValue	= (CK_BYTE *)hasreset_attr +
44747e946eWyllys Ingersoll	    sizeof (CK_ATTRIBUTE);
44847e946eWyllys Ingersoll	*(CK_BBOOL *)hasreset_attr->pValue = FALSE;
44947e946eWyllys Ingersoll
45047e946eWyllys Ingersoll	/* Hmm...  Not sure if we should be setting this here. */
45147e946eWyllys Ingersoll	resetoninit_attr->type	= CKA_RESET_ON_INIT;
45247e946eWyllys Ingersoll	resetoninit_attr->ulValueLen = sizeof (CK_BBOOL);
45347e946eWyllys Ingersoll	resetoninit_attr->pValue = (CK_BYTE *)resetoninit_attr +
45447e946eWyllys Ingersoll	    sizeof (CK_ATTRIBUTE);
45547e946eWyllys Ingersoll	*(CK_BBOOL *)resetoninit_attr->pValue = FALSE;
45647e946eWyllys Ingersoll
45747e946eWyllys Ingersoll	(void) template_update_attribute(tmpl, value_attr);
45847e946eWyllys Ingersoll	(void) template_update_attribute(tmpl, hasreset_attr);
45947e946eWyllys Ingersoll	(void) template_update_attribute(tmpl, resetoninit_attr);
46047e946eWyllys Ingersoll
46147e946eWyllys Ingersoll	return (CKR_OK);
46247e946eWyllys Ingersoll}
463