xref: /onnv-gate/usr/src/lib/pkcs11/pkcs11_tpm/common/dig_mgr.c (revision 9453:f0534026bc38)
19126SWyllys.Ingersoll@Sun.COM /*
29126SWyllys.Ingersoll@Sun.COM  *		Common Public License Version 0.5
39126SWyllys.Ingersoll@Sun.COM  *
49126SWyllys.Ingersoll@Sun.COM  *		THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF
59126SWyllys.Ingersoll@Sun.COM  *		THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE,
69126SWyllys.Ingersoll@Sun.COM  *		REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
79126SWyllys.Ingersoll@Sun.COM  *		RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
89126SWyllys.Ingersoll@Sun.COM  *
99126SWyllys.Ingersoll@Sun.COM  *		1. DEFINITIONS
109126SWyllys.Ingersoll@Sun.COM  *
119126SWyllys.Ingersoll@Sun.COM  *		"Contribution" means:
129126SWyllys.Ingersoll@Sun.COM  *		      a) in the case of the initial Contributor, the
139126SWyllys.Ingersoll@Sun.COM  *		      initial code and documentation distributed under
149126SWyllys.Ingersoll@Sun.COM  *		      this Agreement, and
159126SWyllys.Ingersoll@Sun.COM  *
169126SWyllys.Ingersoll@Sun.COM  *		      b) in the case of each subsequent Contributor:
179126SWyllys.Ingersoll@Sun.COM  *		      i) changes to the Program, and
189126SWyllys.Ingersoll@Sun.COM  *		      ii) additions to the Program;
199126SWyllys.Ingersoll@Sun.COM  *
209126SWyllys.Ingersoll@Sun.COM  *		      where such changes and/or additions to the Program
219126SWyllys.Ingersoll@Sun.COM  *		      originate from and are distributed by that
229126SWyllys.Ingersoll@Sun.COM  *		      particular Contributor. A Contribution 'originates'
239126SWyllys.Ingersoll@Sun.COM  *		      from a Contributor if it was added to the Program
249126SWyllys.Ingersoll@Sun.COM  *		      by such Contributor itself or anyone acting on such
259126SWyllys.Ingersoll@Sun.COM  *		      Contributor's behalf. Contributions do not include
269126SWyllys.Ingersoll@Sun.COM  *		      additions to the Program which: (i) are separate
279126SWyllys.Ingersoll@Sun.COM  *		      modules of software distributed in conjunction with
289126SWyllys.Ingersoll@Sun.COM  *		      the Program under their own license agreement, and
299126SWyllys.Ingersoll@Sun.COM  *		      (ii) are not derivative works of the Program.
309126SWyllys.Ingersoll@Sun.COM  *
319126SWyllys.Ingersoll@Sun.COM  *
329126SWyllys.Ingersoll@Sun.COM  *		"Contributor" means any person or entity that distributes
339126SWyllys.Ingersoll@Sun.COM  *		the Program.
349126SWyllys.Ingersoll@Sun.COM  *
359126SWyllys.Ingersoll@Sun.COM  *		"Licensed Patents " mean patent claims licensable by a
369126SWyllys.Ingersoll@Sun.COM  *		Contributor which are necessarily infringed by the use or
379126SWyllys.Ingersoll@Sun.COM  *		sale of its Contribution alone or when combined with the
389126SWyllys.Ingersoll@Sun.COM  *		Program.
399126SWyllys.Ingersoll@Sun.COM  *
409126SWyllys.Ingersoll@Sun.COM  *		"Program" means the Contributions distributed in
419126SWyllys.Ingersoll@Sun.COM  *		accordance with this Agreement.
429126SWyllys.Ingersoll@Sun.COM  *
439126SWyllys.Ingersoll@Sun.COM  *		"Recipient" means anyone who receives the Program under
449126SWyllys.Ingersoll@Sun.COM  *		this Agreement, including all Contributors.
459126SWyllys.Ingersoll@Sun.COM  *
469126SWyllys.Ingersoll@Sun.COM  *		2. GRANT OF RIGHTS
479126SWyllys.Ingersoll@Sun.COM  *
489126SWyllys.Ingersoll@Sun.COM  *		      a) Subject to the terms of this Agreement, each
499126SWyllys.Ingersoll@Sun.COM  *		      Contributor hereby grants Recipient a
509126SWyllys.Ingersoll@Sun.COM  *		      no - exclusive, worldwide, royalt - free copyright
519126SWyllys.Ingersoll@Sun.COM  *		      license to reproduce, prepare derivative works of,
529126SWyllys.Ingersoll@Sun.COM  *		      publicly display, publicly perform, distribute and
539126SWyllys.Ingersoll@Sun.COM  *		      sublicense the Contribution of such Contributor, if
549126SWyllys.Ingersoll@Sun.COM  *		      any, and such derivative works, in source code and
559126SWyllys.Ingersoll@Sun.COM  *		      object code form.
569126SWyllys.Ingersoll@Sun.COM  *
579126SWyllys.Ingersoll@Sun.COM  *		      b) Subject to the terms of this Agreement, each
589126SWyllys.Ingersoll@Sun.COM  *		      Contributor hereby grants Recipient a
599126SWyllys.Ingersoll@Sun.COM  *		      no - exclusive, worldwide, royalt - free patent
609126SWyllys.Ingersoll@Sun.COM  *		      license under Licensed Patents to make, use, sell,
619126SWyllys.Ingersoll@Sun.COM  *		      offer to sell, import and otherwise transfer the
629126SWyllys.Ingersoll@Sun.COM  *		      Contribution of such Contributor, if any, in source
639126SWyllys.Ingersoll@Sun.COM  *		      code and object code form. This patent license
649126SWyllys.Ingersoll@Sun.COM  *		      shall apply to the combination of the Contribution
659126SWyllys.Ingersoll@Sun.COM  *		      and the Program if, at the time the Contribution is
669126SWyllys.Ingersoll@Sun.COM  *		      added by the Contributor, such addition of the
679126SWyllys.Ingersoll@Sun.COM  *		      Contribution causes such combination to be covered
689126SWyllys.Ingersoll@Sun.COM  *		      by the Licensed Patents. The patent license shall
699126SWyllys.Ingersoll@Sun.COM  *		      not apply to any other combinations which include
709126SWyllys.Ingersoll@Sun.COM  *		      the Contribution. No hardware per se is licensed
719126SWyllys.Ingersoll@Sun.COM  *		      hereunder.
729126SWyllys.Ingersoll@Sun.COM  *
739126SWyllys.Ingersoll@Sun.COM  *		      c) Recipient understands that although each
749126SWyllys.Ingersoll@Sun.COM  *		      Contributor grants the licenses to its
759126SWyllys.Ingersoll@Sun.COM  *		      Contributions set forth herein, no assurances are
769126SWyllys.Ingersoll@Sun.COM  *		      provided by any Contributor that the Program does
779126SWyllys.Ingersoll@Sun.COM  *		      not infringe the patent or other intellectual
789126SWyllys.Ingersoll@Sun.COM  *		      property rights of any other entity. Each
799126SWyllys.Ingersoll@Sun.COM  *		      Contributor disclaims any liability to Recipient
809126SWyllys.Ingersoll@Sun.COM  *		      for claims brought by any other entity based on
819126SWyllys.Ingersoll@Sun.COM  *		      infringement of intellectual property rights or
829126SWyllys.Ingersoll@Sun.COM  *		      otherwise. As a condition to exercising the rights
839126SWyllys.Ingersoll@Sun.COM  *		      and licenses granted hereunder, each Recipient
849126SWyllys.Ingersoll@Sun.COM  *		      hereby assumes sole responsibility to secure any
859126SWyllys.Ingersoll@Sun.COM  *		      other intellectual property rights needed, if any.
869126SWyllys.Ingersoll@Sun.COM  *
879126SWyllys.Ingersoll@Sun.COM  *		      For example, if a third party patent license is
889126SWyllys.Ingersoll@Sun.COM  *		      required to allow Recipient to distribute the
899126SWyllys.Ingersoll@Sun.COM  *		      Program, it is Recipient's responsibility to
909126SWyllys.Ingersoll@Sun.COM  *		      acquire that license before distributing the
919126SWyllys.Ingersoll@Sun.COM  *		      Program.
929126SWyllys.Ingersoll@Sun.COM  *
939126SWyllys.Ingersoll@Sun.COM  *		      d) Each Contributor represents that to its
949126SWyllys.Ingersoll@Sun.COM  *		      knowledge it has sufficient copyright rights in its
959126SWyllys.Ingersoll@Sun.COM  *		      Contribution, if any, to grant the copyright
969126SWyllys.Ingersoll@Sun.COM  *		      license set forth in this Agreement.
979126SWyllys.Ingersoll@Sun.COM  *
989126SWyllys.Ingersoll@Sun.COM  *		3. REQUIREMENTS
999126SWyllys.Ingersoll@Sun.COM  *
1009126SWyllys.Ingersoll@Sun.COM  *		A Contributor may choose to distribute the Program in
1019126SWyllys.Ingersoll@Sun.COM  *		object code form under its own license agreement, provided
1029126SWyllys.Ingersoll@Sun.COM  *		that:
1039126SWyllys.Ingersoll@Sun.COM  *		      a) it complies with the terms and conditions of
1049126SWyllys.Ingersoll@Sun.COM  *		      this Agreement; and
1059126SWyllys.Ingersoll@Sun.COM  *
1069126SWyllys.Ingersoll@Sun.COM  *		      b) its license agreement:
1079126SWyllys.Ingersoll@Sun.COM  *		      i) effectively disclaims on behalf of all
1089126SWyllys.Ingersoll@Sun.COM  *		      Contributors all warranties and conditions, express
1099126SWyllys.Ingersoll@Sun.COM  *		      and implied, including warranties or conditions of
1109126SWyllys.Ingersoll@Sun.COM  *		      title and no - infringement, and implied warranties
1119126SWyllys.Ingersoll@Sun.COM  *		      or conditions of merchantability and fitness for a
1129126SWyllys.Ingersoll@Sun.COM  *		      particular purpose;
1139126SWyllys.Ingersoll@Sun.COM  *
1149126SWyllys.Ingersoll@Sun.COM  *		      ii) effectively excludes on behalf of all
1159126SWyllys.Ingersoll@Sun.COM  *		      Contributors all liability for damages, including
1169126SWyllys.Ingersoll@Sun.COM  *		      direct, indirect, special, incidental and
1179126SWyllys.Ingersoll@Sun.COM  *		      consequential damages, such as lost profits;
1189126SWyllys.Ingersoll@Sun.COM  *
1199126SWyllys.Ingersoll@Sun.COM  *		      iii) states that any provisions which differ from
1209126SWyllys.Ingersoll@Sun.COM  *		      this Agreement are offered by that Contributor
1219126SWyllys.Ingersoll@Sun.COM  *		      alone and not by any other party; and
1229126SWyllys.Ingersoll@Sun.COM  *
1239126SWyllys.Ingersoll@Sun.COM  *		      iv) states that source code for the Program is
1249126SWyllys.Ingersoll@Sun.COM  *		      available from such Contributor, and informs
1259126SWyllys.Ingersoll@Sun.COM  *		      licensees how to obtain it in a reasonable manner
1269126SWyllys.Ingersoll@Sun.COM  *		      on or through a medium customarily used for
1279126SWyllys.Ingersoll@Sun.COM  *		      software exchange.
1289126SWyllys.Ingersoll@Sun.COM  *
1299126SWyllys.Ingersoll@Sun.COM  *		When the Program is made available in source code form:
1309126SWyllys.Ingersoll@Sun.COM  *		      a) it must be made available under this Agreement;
1319126SWyllys.Ingersoll@Sun.COM  *		      and
1329126SWyllys.Ingersoll@Sun.COM  *		      b) a copy of this Agreement must be included with
1339126SWyllys.Ingersoll@Sun.COM  *		      each copy of the Program.
1349126SWyllys.Ingersoll@Sun.COM  *
1359126SWyllys.Ingersoll@Sun.COM  *		Contributors may not remove or alter any copyright notices
1369126SWyllys.Ingersoll@Sun.COM  *		contained within the Program.
1379126SWyllys.Ingersoll@Sun.COM  *
1389126SWyllys.Ingersoll@Sun.COM  *		Each Contributor must identify itself as the originator of
1399126SWyllys.Ingersoll@Sun.COM  *		its Contribution, if any, in a manner that reasonably
1409126SWyllys.Ingersoll@Sun.COM  *		allows subsequent Recipients to identify the originator of
1419126SWyllys.Ingersoll@Sun.COM  *		the Contribution.
1429126SWyllys.Ingersoll@Sun.COM  *
1439126SWyllys.Ingersoll@Sun.COM  *
1449126SWyllys.Ingersoll@Sun.COM  *		4. COMMERCIAL DISTRIBUTION
1459126SWyllys.Ingersoll@Sun.COM  *
1469126SWyllys.Ingersoll@Sun.COM  *		Commercial distributors of software may accept certain
1479126SWyllys.Ingersoll@Sun.COM  *		responsibilities with respect to end users, business
1489126SWyllys.Ingersoll@Sun.COM  *		partners and the like. While this license is intended to
1499126SWyllys.Ingersoll@Sun.COM  *		facilitate the commercial use of the Program, the
1509126SWyllys.Ingersoll@Sun.COM  *		Contributor who includes the Program in a commercial
1519126SWyllys.Ingersoll@Sun.COM  *		product offering should do so in a manner which does not
1529126SWyllys.Ingersoll@Sun.COM  *		create potential liability for other Contributors.
1539126SWyllys.Ingersoll@Sun.COM  *		Therefore, if a Contributor includes the Program in a
1549126SWyllys.Ingersoll@Sun.COM  *		commercial product offering, such Contributor ("Commercial
1559126SWyllys.Ingersoll@Sun.COM  *		Contributor") hereby agrees to defend and indemnify every
1569126SWyllys.Ingersoll@Sun.COM  *		other Contributor ("Indemnified Contributor") against any
1579126SWyllys.Ingersoll@Sun.COM  *		losses, damages and costs (collectively "Losses") arising
1589126SWyllys.Ingersoll@Sun.COM  *		from claims, lawsuits and other legal actions brought by a
1599126SWyllys.Ingersoll@Sun.COM  *		third party against the Indemnified Contributor to the
1609126SWyllys.Ingersoll@Sun.COM  *		extent caused by the acts or omissions of such Commercial
1619126SWyllys.Ingersoll@Sun.COM  *		Contributor in connection with its distribution of the
1629126SWyllys.Ingersoll@Sun.COM  *		Program in a commercial product offering. The obligations
1639126SWyllys.Ingersoll@Sun.COM  *		in this section do not apply to any claims or Losses
1649126SWyllys.Ingersoll@Sun.COM  *		relating to any actual or alleged intellectual property
1659126SWyllys.Ingersoll@Sun.COM  *		infringement. In order to qualify, an Indemnified
1669126SWyllys.Ingersoll@Sun.COM  *		Contributor must: a) promptly notify the Commercial
1679126SWyllys.Ingersoll@Sun.COM  *		Contributor in writing of such claim, and b) allow the
1689126SWyllys.Ingersoll@Sun.COM  *		Commercial Contributor to control, and cooperate with the
1699126SWyllys.Ingersoll@Sun.COM  *		Commercial Contributor in, the defense and any related
1709126SWyllys.Ingersoll@Sun.COM  *		settlement negotiations. The Indemnified Contributor may
1719126SWyllys.Ingersoll@Sun.COM  *		participate in any such claim at its own expense.
1729126SWyllys.Ingersoll@Sun.COM  *
1739126SWyllys.Ingersoll@Sun.COM  *
1749126SWyllys.Ingersoll@Sun.COM  *		For example, a Contributor might include the Program in a
1759126SWyllys.Ingersoll@Sun.COM  *		commercial product offering, Product X. That Contributor
1769126SWyllys.Ingersoll@Sun.COM  *		is then a Commercial Contributor. If that Commercial
1779126SWyllys.Ingersoll@Sun.COM  *		Contributor then makes performance claims, or offers
1789126SWyllys.Ingersoll@Sun.COM  *		warranties related to Product X, those performance claims
1799126SWyllys.Ingersoll@Sun.COM  *		and warranties are such Commercial Contributor's
1809126SWyllys.Ingersoll@Sun.COM  *		responsibility alone. Under this section, the Commercial
1819126SWyllys.Ingersoll@Sun.COM  *		Contributor would have to defend claims against the other
1829126SWyllys.Ingersoll@Sun.COM  *		Contributors related to those performance claims and
1839126SWyllys.Ingersoll@Sun.COM  *		warranties, and if a court requires any other Contributor
1849126SWyllys.Ingersoll@Sun.COM  *		to pay any damages as a result, the Commercial Contributor
1859126SWyllys.Ingersoll@Sun.COM  *		must pay those damages.
1869126SWyllys.Ingersoll@Sun.COM  *
1879126SWyllys.Ingersoll@Sun.COM  *
1889126SWyllys.Ingersoll@Sun.COM  *		5. NO WARRANTY
1899126SWyllys.Ingersoll@Sun.COM  *
1909126SWyllys.Ingersoll@Sun.COM  *		EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE
1919126SWyllys.Ingersoll@Sun.COM  *		PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
1929126SWyllys.Ingersoll@Sun.COM  *		WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
1939126SWyllys.Ingersoll@Sun.COM  *		IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
1949126SWyllys.Ingersoll@Sun.COM  *		CONDITIONS OF TITLE, NO - INFRINGEMENT, MERCHANTABILITY OR
1959126SWyllys.Ingersoll@Sun.COM  *		FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
1969126SWyllys.Ingersoll@Sun.COM  *		responsible for determining the appropriateness of using
1979126SWyllys.Ingersoll@Sun.COM  *		and distributing the Program and assumes all risks
1989126SWyllys.Ingersoll@Sun.COM  *		associated with its exercise of rights under this
1999126SWyllys.Ingersoll@Sun.COM  *		Agreement, including but not limited to the risks and
2009126SWyllys.Ingersoll@Sun.COM  *		costs of program errors, compliance with applicable laws,
2019126SWyllys.Ingersoll@Sun.COM  *		damage to or loss of data, programs or equipment, and
2029126SWyllys.Ingersoll@Sun.COM  *		unavailability or interruption of operations.
2039126SWyllys.Ingersoll@Sun.COM  *
2049126SWyllys.Ingersoll@Sun.COM  *		6. DISCLAIMER OF LIABILITY
2059126SWyllys.Ingersoll@Sun.COM  *		EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER
2069126SWyllys.Ingersoll@Sun.COM  *		RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY
2079126SWyllys.Ingersoll@Sun.COM  *		FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
2089126SWyllys.Ingersoll@Sun.COM  *		OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
2099126SWyllys.Ingersoll@Sun.COM  *		LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
2109126SWyllys.Ingersoll@Sun.COM  *		LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2119126SWyllys.Ingersoll@Sun.COM  *		(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
2129126SWyllys.Ingersoll@Sun.COM  *		OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE
2139126SWyllys.Ingersoll@Sun.COM  *		OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
2149126SWyllys.Ingersoll@Sun.COM  *		POSSIBILITY OF SUCH DAMAGES.
2159126SWyllys.Ingersoll@Sun.COM  *
2169126SWyllys.Ingersoll@Sun.COM  *		7. GENERAL
2179126SWyllys.Ingersoll@Sun.COM  *
2189126SWyllys.Ingersoll@Sun.COM  *		If any provision of this Agreement is invalid or
2199126SWyllys.Ingersoll@Sun.COM  *		unenforceable under applicable law, it shall not affect
2209126SWyllys.Ingersoll@Sun.COM  *		the validity or enforceability of the remainder of the
2219126SWyllys.Ingersoll@Sun.COM  *		terms of this Agreement, and without further action by the
2229126SWyllys.Ingersoll@Sun.COM  *		parties hereto, such provision shall be reformed to the
2239126SWyllys.Ingersoll@Sun.COM  *		minimum extent necessary to make such provision valid and
2249126SWyllys.Ingersoll@Sun.COM  *		enforceable.
2259126SWyllys.Ingersoll@Sun.COM  *
2269126SWyllys.Ingersoll@Sun.COM  *
2279126SWyllys.Ingersoll@Sun.COM  *		If Recipient institutes patent litigation against a
2289126SWyllys.Ingersoll@Sun.COM  *		Contributor with respect to a patent applicable to
2299126SWyllys.Ingersoll@Sun.COM  *		software (including a cros - claim or counterclaim in a
2309126SWyllys.Ingersoll@Sun.COM  *		lawsuit), then any patent licenses granted by that
2319126SWyllys.Ingersoll@Sun.COM  *		Contributor to such Recipient under this Agreement shall
2329126SWyllys.Ingersoll@Sun.COM  *		terminate as of the date such litigation is filed. In
2339126SWyllys.Ingersoll@Sun.COM  *		addition, If Recipient institutes patent litigation
2349126SWyllys.Ingersoll@Sun.COM  *		against any entity (including a cros - claim or
2359126SWyllys.Ingersoll@Sun.COM  *		counterclaim in a lawsuit) alleging that the Program
2369126SWyllys.Ingersoll@Sun.COM  *		itself (excluding combinations of the Program with other
2379126SWyllys.Ingersoll@Sun.COM  *		software or hardware) infringes such Recipient's
2389126SWyllys.Ingersoll@Sun.COM  *		patent(s), then such Recipient's rights granted under
2399126SWyllys.Ingersoll@Sun.COM  *		Section 2(b) shall terminate as of the date such
2409126SWyllys.Ingersoll@Sun.COM  *		litigation is filed.
2419126SWyllys.Ingersoll@Sun.COM  *
2429126SWyllys.Ingersoll@Sun.COM  *		All Recipient's rights under this Agreement shall
2439126SWyllys.Ingersoll@Sun.COM  *		terminate if it fails to comply with any of the material
2449126SWyllys.Ingersoll@Sun.COM  *		terms or conditions of this Agreement and does not cure
2459126SWyllys.Ingersoll@Sun.COM  *		such failure in a reasonable period of time after becoming
2469126SWyllys.Ingersoll@Sun.COM  *		aware of such noncompliance. If all Recipient's rights
2479126SWyllys.Ingersoll@Sun.COM  *		under this Agreement terminate, Recipient agrees to cease
2489126SWyllys.Ingersoll@Sun.COM  *		use and distribution of the Program as soon as reasonably
2499126SWyllys.Ingersoll@Sun.COM  *		practicable. However, Recipient's obligations under this
2509126SWyllys.Ingersoll@Sun.COM  *		Agreement and any licenses granted by Recipient relating
2519126SWyllys.Ingersoll@Sun.COM  *		to the Program shall continue and survive.
2529126SWyllys.Ingersoll@Sun.COM  *
2539126SWyllys.Ingersoll@Sun.COM  *		Everyone is permitted to copy and distribute copies of
2549126SWyllys.Ingersoll@Sun.COM  *		this Agreement, but in order to avoid inconsistency the
2559126SWyllys.Ingersoll@Sun.COM  *		Agreement is copyrighted and may only be modified in the
2569126SWyllys.Ingersoll@Sun.COM  *		following manner. The Agreement Steward reserves the right
2579126SWyllys.Ingersoll@Sun.COM  *		to publish new versions (including revisions) of this
2589126SWyllys.Ingersoll@Sun.COM  *		Agreement from time to time. No one other than the
2599126SWyllys.Ingersoll@Sun.COM  *		Agreement Steward has the right to modify this Agreement.
2609126SWyllys.Ingersoll@Sun.COM  *
2619126SWyllys.Ingersoll@Sun.COM  *		IBM is the initial Agreement Steward. IBM may assign the
2629126SWyllys.Ingersoll@Sun.COM  *		responsibility to serve as the Agreement Steward to a
2639126SWyllys.Ingersoll@Sun.COM  *		suitable separate entity. Each new version of the
2649126SWyllys.Ingersoll@Sun.COM  *		Agreement will be given a distinguishing version number.
2659126SWyllys.Ingersoll@Sun.COM  *		The Program (including Contributions) may always be
2669126SWyllys.Ingersoll@Sun.COM  *		distributed subject to the version of the Agreement under
2679126SWyllys.Ingersoll@Sun.COM  *		which it was received. In addition, after a new version of
2689126SWyllys.Ingersoll@Sun.COM  *		the Agreement is published, Contributor may elect to
2699126SWyllys.Ingersoll@Sun.COM  *		distribute the Program (including its Contributions) under
2709126SWyllys.Ingersoll@Sun.COM  *		the new version. Except as expressly stated in Sections
2719126SWyllys.Ingersoll@Sun.COM  *		2(a) and 2(b) above, Recipient receives no rights or
2729126SWyllys.Ingersoll@Sun.COM  *		licenses to the intellectual property of any Contributor
2739126SWyllys.Ingersoll@Sun.COM  *		under this Agreement, whether expressly, by implication,
2749126SWyllys.Ingersoll@Sun.COM  *		estoppel or otherwise. All rights in the Program not
2759126SWyllys.Ingersoll@Sun.COM  *		expressly granted under this Agreement are reserved.
2769126SWyllys.Ingersoll@Sun.COM  *
2779126SWyllys.Ingersoll@Sun.COM  *
2789126SWyllys.Ingersoll@Sun.COM  *		This Agreement is governed by the laws of the State of New
2799126SWyllys.Ingersoll@Sun.COM  *		York and the intellectual property laws of the United
2809126SWyllys.Ingersoll@Sun.COM  *		States of America. No party to this Agreement will bring a
2819126SWyllys.Ingersoll@Sun.COM  *		legal action under this Agreement more than one year after
2829126SWyllys.Ingersoll@Sun.COM  *		the cause of action arose. Each party waives its rights to
2839126SWyllys.Ingersoll@Sun.COM  *		a jury trial in any resulting litigation.
2849126SWyllys.Ingersoll@Sun.COM  *
2859126SWyllys.Ingersoll@Sun.COM  *
2869126SWyllys.Ingersoll@Sun.COM  *
2879126SWyllys.Ingersoll@Sun.COM  * (C) COPYRIGHT International Business Machines Corp. 2001, 2002
2889126SWyllys.Ingersoll@Sun.COM  */
2899126SWyllys.Ingersoll@Sun.COM /*
2909126SWyllys.Ingersoll@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2919126SWyllys.Ingersoll@Sun.COM  * Use is subject to license terms.
2929126SWyllys.Ingersoll@Sun.COM  */
2939126SWyllys.Ingersoll@Sun.COM 
2949126SWyllys.Ingersoll@Sun.COM /*
2959126SWyllys.Ingersoll@Sun.COM  * Digest manager routines
2969126SWyllys.Ingersoll@Sun.COM  */
2979126SWyllys.Ingersoll@Sun.COM #include "tpmtok_int.h"
2989126SWyllys.Ingersoll@Sun.COM 
2999126SWyllys.Ingersoll@Sun.COM CK_RV
digest_mgr_init(SESSION * sess,DIGEST_CONTEXT * ctx,CK_MECHANISM * mech)3009126SWyllys.Ingersoll@Sun.COM digest_mgr_init(SESSION	*sess,
3019126SWyllys.Ingersoll@Sun.COM 	DIGEST_CONTEXT	*ctx,
3029126SWyllys.Ingersoll@Sun.COM 	CK_MECHANISM	*mech)
3039126SWyllys.Ingersoll@Sun.COM {
3049126SWyllys.Ingersoll@Sun.COM 	if (! sess || ! ctx) {
3059126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
3069126SWyllys.Ingersoll@Sun.COM 	}
3079126SWyllys.Ingersoll@Sun.COM 	if (ctx->active != FALSE) {
3089126SWyllys.Ingersoll@Sun.COM 		return (CKR_OPERATION_ACTIVE);
3099126SWyllys.Ingersoll@Sun.COM 	}
3109126SWyllys.Ingersoll@Sun.COM 
3119126SWyllys.Ingersoll@Sun.COM 	switch (mech->mechanism) {
3129126SWyllys.Ingersoll@Sun.COM 		case CKM_SHA_1:
3139126SWyllys.Ingersoll@Sun.COM 		{
3149126SWyllys.Ingersoll@Sun.COM 			ctx->context_len = sizeof (SHA1_CTX);
3159126SWyllys.Ingersoll@Sun.COM 			ctx->context.sha1ctx = (SHA1_CTX *)
3169126SWyllys.Ingersoll@Sun.COM 			    malloc(ctx->context_len);
3179126SWyllys.Ingersoll@Sun.COM 			if (!ctx->context.sha1ctx)
3189126SWyllys.Ingersoll@Sun.COM 				return (CKR_HOST_MEMORY);
3199126SWyllys.Ingersoll@Sun.COM 			SHA1Init(ctx->context.sha1ctx);
3209126SWyllys.Ingersoll@Sun.COM 		}
3219126SWyllys.Ingersoll@Sun.COM 		break;
3229126SWyllys.Ingersoll@Sun.COM 
3239126SWyllys.Ingersoll@Sun.COM 		case CKM_MD5:
3249126SWyllys.Ingersoll@Sun.COM 		{
3259126SWyllys.Ingersoll@Sun.COM 			ctx->context_len = sizeof (MD5_CTX);
3269126SWyllys.Ingersoll@Sun.COM 			ctx->context.md5ctx = (MD5_CTX *)
3279126SWyllys.Ingersoll@Sun.COM 			    malloc(ctx->context_len);
3289126SWyllys.Ingersoll@Sun.COM 			if (! ctx->context.md5ctx) {
3299126SWyllys.Ingersoll@Sun.COM 				return (CKR_HOST_MEMORY);
3309126SWyllys.Ingersoll@Sun.COM 			}
3319126SWyllys.Ingersoll@Sun.COM 			MD5Init(ctx->context.md5ctx);
3329126SWyllys.Ingersoll@Sun.COM 		}
3339126SWyllys.Ingersoll@Sun.COM 		break;
3349126SWyllys.Ingersoll@Sun.COM 
3359126SWyllys.Ingersoll@Sun.COM 		default:
3369126SWyllys.Ingersoll@Sun.COM 			return (CKR_MECHANISM_INVALID);
3379126SWyllys.Ingersoll@Sun.COM 	}
3389126SWyllys.Ingersoll@Sun.COM 
3399126SWyllys.Ingersoll@Sun.COM 	ctx->mech.ulParameterLen = mech->ulParameterLen;
3409126SWyllys.Ingersoll@Sun.COM 	ctx->mech.mechanism = mech->mechanism;
341*9453SWyllys.Ingersoll@Sun.COM 	ctx->mech.pParameter = mech->pParameter;
3429126SWyllys.Ingersoll@Sun.COM 	ctx->multi = FALSE;
3439126SWyllys.Ingersoll@Sun.COM 	ctx->active = TRUE;
3449126SWyllys.Ingersoll@Sun.COM 
3459126SWyllys.Ingersoll@Sun.COM 	return (CKR_OK);
3469126SWyllys.Ingersoll@Sun.COM }
3479126SWyllys.Ingersoll@Sun.COM 
3489126SWyllys.Ingersoll@Sun.COM CK_RV
digest_mgr_cleanup(DIGEST_CONTEXT * ctx)3499126SWyllys.Ingersoll@Sun.COM digest_mgr_cleanup(DIGEST_CONTEXT *ctx)
3509126SWyllys.Ingersoll@Sun.COM {
3519126SWyllys.Ingersoll@Sun.COM 	if (!ctx) {
3529126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
3539126SWyllys.Ingersoll@Sun.COM 	}
3549126SWyllys.Ingersoll@Sun.COM 	if (ctx->mech.mechanism == CKM_MD5) {
3559126SWyllys.Ingersoll@Sun.COM 		free(ctx->context.md5ctx);
3569126SWyllys.Ingersoll@Sun.COM 		ctx->context.md5ctx = NULL;
3579126SWyllys.Ingersoll@Sun.COM 	} else if (ctx->mech.mechanism == CKM_SHA_1) {
3589126SWyllys.Ingersoll@Sun.COM 		free(ctx->context.sha1ctx);
3599126SWyllys.Ingersoll@Sun.COM 		ctx->context.sha1ctx = NULL;
3609126SWyllys.Ingersoll@Sun.COM 	}
3619126SWyllys.Ingersoll@Sun.COM 	ctx->mech.ulParameterLen = 0;
362*9453SWyllys.Ingersoll@Sun.COM 	ctx->mech.pParameter = NULL;
3639126SWyllys.Ingersoll@Sun.COM 	ctx->mech.mechanism = 0;
3649126SWyllys.Ingersoll@Sun.COM 	ctx->multi = FALSE;
3659126SWyllys.Ingersoll@Sun.COM 	ctx->active = FALSE;
3669126SWyllys.Ingersoll@Sun.COM 	ctx->context_len = 0;
3679126SWyllys.Ingersoll@Sun.COM 
3689126SWyllys.Ingersoll@Sun.COM 	return (CKR_OK);
3699126SWyllys.Ingersoll@Sun.COM }
3709126SWyllys.Ingersoll@Sun.COM 
3719126SWyllys.Ingersoll@Sun.COM CK_RV
digest_mgr_digest(SESSION * sess,CK_BBOOL length_only,DIGEST_CONTEXT * ctx,CK_BYTE * in_data,CK_ULONG in_data_len,CK_BYTE * out_data,CK_ULONG * out_data_len)3729126SWyllys.Ingersoll@Sun.COM digest_mgr_digest(SESSION *sess,
3739126SWyllys.Ingersoll@Sun.COM 	CK_BBOOL length_only,
3749126SWyllys.Ingersoll@Sun.COM 	DIGEST_CONTEXT  *ctx,
3759126SWyllys.Ingersoll@Sun.COM 	CK_BYTE *in_data,
3769126SWyllys.Ingersoll@Sun.COM 	CK_ULONG in_data_len,
3779126SWyllys.Ingersoll@Sun.COM 	CK_BYTE *out_data,
3789126SWyllys.Ingersoll@Sun.COM 	CK_ULONG *out_data_len)
3799126SWyllys.Ingersoll@Sun.COM {
3809126SWyllys.Ingersoll@Sun.COM 
3819126SWyllys.Ingersoll@Sun.COM 	if (! sess || ! ctx) {
3829126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
3839126SWyllys.Ingersoll@Sun.COM 	}
3849126SWyllys.Ingersoll@Sun.COM 	if (ctx->active == FALSE) {
3859126SWyllys.Ingersoll@Sun.COM 		return (CKR_OPERATION_NOT_INITIALIZED);
3869126SWyllys.Ingersoll@Sun.COM 	}
3879126SWyllys.Ingersoll@Sun.COM 
3889126SWyllys.Ingersoll@Sun.COM 	if ((length_only == FALSE) && (! in_data || ! out_data)) {
3899126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
3909126SWyllys.Ingersoll@Sun.COM 	}
3919126SWyllys.Ingersoll@Sun.COM 
3929126SWyllys.Ingersoll@Sun.COM 	if (ctx->multi == TRUE) {
3939126SWyllys.Ingersoll@Sun.COM 		return (CKR_OPERATION_ACTIVE);
3949126SWyllys.Ingersoll@Sun.COM 	}
3959126SWyllys.Ingersoll@Sun.COM 	switch (ctx->mech.mechanism) {
3969126SWyllys.Ingersoll@Sun.COM 		case CKM_SHA_1:
397*9453SWyllys.Ingersoll@Sun.COM 		if (!length_only && *out_data_len < SHA1_DIGEST_LENGTH)
398*9453SWyllys.Ingersoll@Sun.COM 			return (CKR_BUFFER_TOO_SMALL);
3999126SWyllys.Ingersoll@Sun.COM 		return (sha1_hash(sess, length_only, ctx,
4009126SWyllys.Ingersoll@Sun.COM 		    in_data, in_data_len, out_data,  out_data_len));
4019126SWyllys.Ingersoll@Sun.COM 
4029126SWyllys.Ingersoll@Sun.COM 		case CKM_MD5:
403*9453SWyllys.Ingersoll@Sun.COM 		if (!length_only && *out_data_len < MD5_DIGEST_LENGTH)
404*9453SWyllys.Ingersoll@Sun.COM 			return (CKR_BUFFER_TOO_SMALL);
4059126SWyllys.Ingersoll@Sun.COM 		return (md5_hash(sess, length_only, ctx,
4069126SWyllys.Ingersoll@Sun.COM 		    in_data,  in_data_len, out_data, out_data_len));
4079126SWyllys.Ingersoll@Sun.COM 
4089126SWyllys.Ingersoll@Sun.COM 		default:
4099126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
4109126SWyllys.Ingersoll@Sun.COM 	}
4119126SWyllys.Ingersoll@Sun.COM }
4129126SWyllys.Ingersoll@Sun.COM 
4139126SWyllys.Ingersoll@Sun.COM CK_RV
digest_mgr_digest_update(SESSION * sess,DIGEST_CONTEXT * ctx,CK_BYTE * data,CK_ULONG data_len)4149126SWyllys.Ingersoll@Sun.COM digest_mgr_digest_update(SESSION *sess,
4159126SWyllys.Ingersoll@Sun.COM 	DIGEST_CONTEXT  *ctx,
4169126SWyllys.Ingersoll@Sun.COM 	CK_BYTE *data,
4179126SWyllys.Ingersoll@Sun.COM 	CK_ULONG data_len)
4189126SWyllys.Ingersoll@Sun.COM {
4199126SWyllys.Ingersoll@Sun.COM 	if (! sess || ! ctx) {
4209126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
4219126SWyllys.Ingersoll@Sun.COM 	}
4229126SWyllys.Ingersoll@Sun.COM 	if (ctx->active == FALSE) {
4239126SWyllys.Ingersoll@Sun.COM 		return (CKR_OPERATION_NOT_INITIALIZED);
4249126SWyllys.Ingersoll@Sun.COM 	}
4259126SWyllys.Ingersoll@Sun.COM 
4269126SWyllys.Ingersoll@Sun.COM 	ctx->multi = TRUE;
4279126SWyllys.Ingersoll@Sun.COM 
4289126SWyllys.Ingersoll@Sun.COM 	switch (ctx->mech.mechanism) {
4299126SWyllys.Ingersoll@Sun.COM 		case CKM_SHA_1:
4309126SWyllys.Ingersoll@Sun.COM 			SHA1Update(ctx->context.sha1ctx, data, data_len);
4319126SWyllys.Ingersoll@Sun.COM 			return (CKR_OK);
4329126SWyllys.Ingersoll@Sun.COM 
4339126SWyllys.Ingersoll@Sun.COM 		case CKM_MD5:
4349126SWyllys.Ingersoll@Sun.COM 			MD5Update(ctx->context.md5ctx, data, data_len);
4359126SWyllys.Ingersoll@Sun.COM 			return (CKR_OK);
4369126SWyllys.Ingersoll@Sun.COM 		default:
4379126SWyllys.Ingersoll@Sun.COM 			return (CKR_MECHANISM_INVALID);
4389126SWyllys.Ingersoll@Sun.COM 	}
4399126SWyllys.Ingersoll@Sun.COM }
4409126SWyllys.Ingersoll@Sun.COM 
4419126SWyllys.Ingersoll@Sun.COM CK_RV
digest_mgr_digest_key(SESSION * sess,DIGEST_CONTEXT * ctx,CK_OBJECT_HANDLE key_handle)4429126SWyllys.Ingersoll@Sun.COM digest_mgr_digest_key(SESSION * sess,
4439126SWyllys.Ingersoll@Sun.COM 	DIGEST_CONTEXT *ctx,
4449126SWyllys.Ingersoll@Sun.COM 	CK_OBJECT_HANDLE key_handle)
4459126SWyllys.Ingersoll@Sun.COM {
4469126SWyllys.Ingersoll@Sun.COM 	CK_ATTRIBUTE *attr = NULL;
4479126SWyllys.Ingersoll@Sun.COM 	OBJECT * key_obj  = NULL;
4489126SWyllys.Ingersoll@Sun.COM 	CK_OBJECT_CLASS   class;
4499126SWyllys.Ingersoll@Sun.COM 	CK_RV rc;
4509126SWyllys.Ingersoll@Sun.COM 
4519126SWyllys.Ingersoll@Sun.COM 	if (!sess || !ctx) {
4529126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
4539126SWyllys.Ingersoll@Sun.COM 	}
4549126SWyllys.Ingersoll@Sun.COM 
4559126SWyllys.Ingersoll@Sun.COM 	rc = object_mgr_find_in_map1(sess->hContext, key_handle, &key_obj);
4569126SWyllys.Ingersoll@Sun.COM 	if (rc != CKR_OK) {
4579126SWyllys.Ingersoll@Sun.COM 		return (CKR_KEY_HANDLE_INVALID);
4589126SWyllys.Ingersoll@Sun.COM 	}
4599126SWyllys.Ingersoll@Sun.COM 	rc = template_attribute_find(key_obj->template, CKA_CLASS, &attr);
4609126SWyllys.Ingersoll@Sun.COM 	if (rc == FALSE)
4619126SWyllys.Ingersoll@Sun.COM 		return (CKR_KEY_INDIGESTIBLE);
4629126SWyllys.Ingersoll@Sun.COM 	else
4639126SWyllys.Ingersoll@Sun.COM 		class = *(CK_OBJECT_CLASS *)attr->pValue;
4649126SWyllys.Ingersoll@Sun.COM 
4659126SWyllys.Ingersoll@Sun.COM 	if (class != CKO_SECRET_KEY)
4669126SWyllys.Ingersoll@Sun.COM 		return (CKR_KEY_INDIGESTIBLE);
4679126SWyllys.Ingersoll@Sun.COM 
4689126SWyllys.Ingersoll@Sun.COM 	rc = template_attribute_find(key_obj->template, CKA_VALUE, &attr);
4699126SWyllys.Ingersoll@Sun.COM 	if (! rc)
4709126SWyllys.Ingersoll@Sun.COM 		return (CKR_KEY_INDIGESTIBLE);
4719126SWyllys.Ingersoll@Sun.COM 
4729126SWyllys.Ingersoll@Sun.COM 	rc = digest_mgr_digest_update(sess,
4739126SWyllys.Ingersoll@Sun.COM 	    ctx, attr->pValue, attr->ulValueLen);
4749126SWyllys.Ingersoll@Sun.COM 	return (rc);
4759126SWyllys.Ingersoll@Sun.COM }
4769126SWyllys.Ingersoll@Sun.COM 
4779126SWyllys.Ingersoll@Sun.COM CK_RV
digest_mgr_digest_final(SESSION * sess,DIGEST_CONTEXT * ctx,CK_BYTE * hash,CK_ULONG * hash_len)4789126SWyllys.Ingersoll@Sun.COM digest_mgr_digest_final(SESSION *sess,
4799126SWyllys.Ingersoll@Sun.COM 	DIGEST_CONTEXT  *ctx,
4809126SWyllys.Ingersoll@Sun.COM 	CK_BYTE *hash,
4819126SWyllys.Ingersoll@Sun.COM 	CK_ULONG *hash_len)
4829126SWyllys.Ingersoll@Sun.COM {
4839126SWyllys.Ingersoll@Sun.COM 	if (! sess || ! ctx) {
4849126SWyllys.Ingersoll@Sun.COM 		return (CKR_FUNCTION_FAILED);
4859126SWyllys.Ingersoll@Sun.COM 	}
4869126SWyllys.Ingersoll@Sun.COM 	if (ctx->active == FALSE) {
4879126SWyllys.Ingersoll@Sun.COM 		return (CKR_OPERATION_NOT_INITIALIZED);
4889126SWyllys.Ingersoll@Sun.COM 	}
4899126SWyllys.Ingersoll@Sun.COM 
4909126SWyllys.Ingersoll@Sun.COM 	ctx->multi = FALSE;
491*9453SWyllys.Ingersoll@Sun.COM 	if (hash == NULL && hash_len == NULL)
492*9453SWyllys.Ingersoll@Sun.COM 		return (CKR_ARGUMENTS_BAD);
4939126SWyllys.Ingersoll@Sun.COM 
4949126SWyllys.Ingersoll@Sun.COM 	switch (ctx->mech.mechanism) {
4959126SWyllys.Ingersoll@Sun.COM 		case CKM_SHA_1:
496*9453SWyllys.Ingersoll@Sun.COM 			if (hash == NULL) {
497*9453SWyllys.Ingersoll@Sun.COM 				*hash_len = SHA1_DIGEST_LENGTH;
498*9453SWyllys.Ingersoll@Sun.COM 				return (CKR_OK);
499*9453SWyllys.Ingersoll@Sun.COM 			}
500*9453SWyllys.Ingersoll@Sun.COM 			if (*hash_len < SHA1_DIGEST_LENGTH)
501*9453SWyllys.Ingersoll@Sun.COM 				return (CKR_BUFFER_TOO_SMALL);
5029126SWyllys.Ingersoll@Sun.COM 			SHA1Final(hash, ctx->context.sha1ctx);
5039126SWyllys.Ingersoll@Sun.COM 			if (hash_len)
5049126SWyllys.Ingersoll@Sun.COM 				*hash_len = SHA1_DIGEST_LENGTH;
5059126SWyllys.Ingersoll@Sun.COM 			return (CKR_OK);
5069126SWyllys.Ingersoll@Sun.COM 
5079126SWyllys.Ingersoll@Sun.COM 		case CKM_MD5:
508*9453SWyllys.Ingersoll@Sun.COM 			if (hash == NULL) {
509*9453SWyllys.Ingersoll@Sun.COM 				*hash_len = MD5_DIGEST_LENGTH;
510*9453SWyllys.Ingersoll@Sun.COM 				return (CKR_OK);
511*9453SWyllys.Ingersoll@Sun.COM 			}
512*9453SWyllys.Ingersoll@Sun.COM 			if (*hash_len < MD5_DIGEST_LENGTH)
513*9453SWyllys.Ingersoll@Sun.COM 				return (CKR_BUFFER_TOO_SMALL);
5149126SWyllys.Ingersoll@Sun.COM 			MD5Final(hash, ctx->context.md5ctx);
5159126SWyllys.Ingersoll@Sun.COM 			if (hash_len)
5169126SWyllys.Ingersoll@Sun.COM 				*hash_len = MD5_DIGEST_LENGTH;
5179126SWyllys.Ingersoll@Sun.COM 			return (CKR_OK);
5189126SWyllys.Ingersoll@Sun.COM 
5199126SWyllys.Ingersoll@Sun.COM 		default:
5209126SWyllys.Ingersoll@Sun.COM 			return (CKR_MECHANISM_INVALID);
5219126SWyllys.Ingersoll@Sun.COM 	}
5229126SWyllys.Ingersoll@Sun.COM }
523