47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll/*
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Common Public License Version 0.5
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * THIS COMMON PUBLIC LICENSE ("AGREEMENT"). ANY USE,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * REPRODUCTION OR DISTRIBUTION OF THE PROGRAM CONSTITUTES
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * RECIPIENT'S ACCEPTANCE OF THIS AGREEMENT.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 1. DEFINITIONS
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * "Contribution" means:
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * a) in the case of the initial Contributor, the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * initial code and documentation distributed under
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * this Agreement, and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * b) in the case of each subsequent Contributor:
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * i) changes to the Program, and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * ii) additions to the Program;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * where such changes and/or additions to the Program
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * originate from and are distributed by that
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * particular Contributor. A Contribution 'originates'
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * from a Contributor if it was added to the Program
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * by such Contributor itself or anyone acting on such
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor's behalf. Contributions do not include
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * additions to the Program which: (i) are separate
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * modules of software distributed in conjunction with
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the Program under their own license agreement, and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * (ii) are not derivative works of the Program.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * "Contributor" means any person or entity that distributes
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the Program.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * "Licensed Patents " mean patent claims licensable by a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor which are necessarily infringed by the use or
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * sale of its Contribution alone or when combined with the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Program.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * "Program" means the Contributions distributed in
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * accordance with this Agreement.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * "Recipient" means anyone who receives the Program under
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * this Agreement, including all Contributors.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 2. GRANT OF RIGHTS
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * a) Subject to the terms of this Agreement, each
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor hereby grants Recipient a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * non-exclusive, worldwide, royalty-free copyright
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * license to reproduce, prepare derivative works of,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * publicly display, publicly perform, distribute and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * sublicense the Contribution of such Contributor, if
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * any, and such derivative works, in source code and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * object code form.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * b) Subject to the terms of this Agreement, each
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor hereby grants Recipient a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * non-exclusive, worldwide, royalty-free patent
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * license under Licensed Patents to make, use, sell,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * offer to sell, import and otherwise transfer the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contribution of such Contributor, if any, in source
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * code and object code form. This patent license
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * shall apply to the combination of the Contribution
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and the Program if, at the time the Contribution is
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * added by the Contributor, such addition of the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contribution causes such combination to be covered
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * by the Licensed Patents. The patent license shall
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * not apply to any other combinations which include
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the Contribution. No hardware per se is licensed
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * hereunder.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * c) Recipient understands that although each
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor grants the licenses to its
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributions set forth herein, no assurances are
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * provided by any Contributor that the Program does
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * not infringe the patent or other intellectual
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * property rights of any other entity. Each
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor disclaims any liability to Recipient
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * for claims brought by any other entity based on
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * infringement of intellectual property rights or
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * otherwise. As a condition to exercising the rights
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and licenses granted hereunder, each Recipient
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * hereby assumes sole responsibility to secure any
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * other intellectual property rights needed, if any.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * For example, if a third party patent license is
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * required to allow Recipient to distribute the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Program, it is Recipient's responsibility to
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * acquire that license before distributing the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Program.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * d) Each Contributor represents that to its
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * knowledge it has sufficient copyright rights in its
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contribution, if any, to grant the copyright
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * license set forth in this Agreement.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 3. REQUIREMENTS
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * A Contributor may choose to distribute the Program in
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * object code form under its own license agreement, provided
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * that:
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * a) it complies with the terms and conditions of
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * this Agreement; and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * b) its license agreement:
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * i) effectively disclaims on behalf of all
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributors all warranties and conditions, express
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and implied, including warranties or conditions of
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * title and non-infringement, and implied warranties
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * or conditions of merchantability and fitness for a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * particular purpose;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * ii) effectively excludes on behalf of all
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributors all liability for damages, including
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * direct, indirect, special, incidental and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * consequential damages, such as lost profits;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * iii) states that any provisions which differ from
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * this Agreement are offered by that Contributor
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * alone and not by any other party; and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * iv) states that source code for the Program is
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * available from such Contributor, and informs
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * licensees how to obtain it in a reasonable manner
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * on or through a medium customarily used for
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * software exchange.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * When the Program is made available in source code form:
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * a) it must be made available under this Agreement;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * b) a copy of this Agreement must be included with
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * each copy of the Program.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributors may not remove or alter any copyright notices
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * contained within the Program.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Each Contributor must identify itself as the originator of
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * its Contribution, if any, in a manner that reasonably
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * allows subsequent Recipients to identify the originator of
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the Contribution.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 4. COMMERCIAL DISTRIBUTION
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Commercial distributors of software may accept certain
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * responsibilities with respect to end users, business
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * partners and the like. While this license is intended to
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * facilitate the commercial use of the Program, the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor who includes the Program in a commercial
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * product offering should do so in a manner which does not
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * create potential liability for other Contributors.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Therefore, if a Contributor includes the Program in a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * commercial product offering, such Contributor ("Commercial
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor") hereby agrees to defend and indemnify every
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * other Contributor ("Indemnified Contributor") against any
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * losses, damages and costs (collectively "Losses") arising
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * from claims, lawsuits and other legal actions brought by a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * third party against the Indemnified Contributor to the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * extent caused by the acts or omissions of such Commercial
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor in connection with its distribution of the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Program in a commercial product offering. The obligations
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * in this section do not apply to any claims or Losses
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * relating to any actual or alleged intellectual property
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * infringement. In order to qualify, an Indemnified
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor must: a) promptly notify the Commercial
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor in writing of such claim, and b) allow the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Commercial Contributor to control, and cooperate with the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Commercial Contributor in, the defense and any related
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * settlement negotiations. The Indemnified Contributor may
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * participate in any such claim at its own expense.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * For example, a Contributor might include the Program in a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * commercial product offering, Product X. That Contributor
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * is then a Commercial Contributor. If that Commercial
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor then makes performance claims, or offers
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * warranties related to Product X, those performance claims
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and warranties are such Commercial Contributor's
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * responsibility alone. Under this section, the Commercial
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor would have to defend claims against the other
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributors related to those performance claims and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * warranties, and if a court requires any other Contributor
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * to pay any damages as a result, the Commercial Contributor
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * must pay those damages.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 5. NO WARRANTY
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * IMPLIED INCLUDING, WITHOUT LIMITATION, ANY WARRANTIES OR
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * responsible for determining the appropriateness of using
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * and distributing the Program and assumes all risks
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * associated with its exercise of rights under this
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Agreement, including but not limited to the risks and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * costs of program errors, compliance with applicable laws,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * damage to or loss of data, programs or equipment, and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * unavailability or interruption of operations.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 6. DISCLAIMER OF LIABILITY
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * OR CONSEQUENTIAL DAMAGES (INCLUDING WITHOUT LIMITATION
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * OF THE USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * OF ANY RIGHTS GRANTED HEREUNDER, EVEN IF ADVISED OF THE
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * POSSIBILITY OF SUCH DAMAGES.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 7. GENERAL
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * If any provision of this Agreement is invalid or
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * unenforceable under applicable law, it shall not affect
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the validity or enforceability of the remainder of the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * terms of this Agreement, and without further action by the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * parties hereto, such provision shall be reformed to the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * minimum extent necessary to make such provision valid and
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * enforceable.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * If Recipient institutes patent litigation against a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor with respect to a patent applicable to
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * software (including a cross-claim or counterclaim in a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * lawsuit), then any patent licenses granted by that
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Contributor to such Recipient under this Agreement shall
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * terminate as of the date such litigation is filed. In
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * addition, If Recipient institutes patent litigation
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * against any entity (including a cross-claim or
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * counterclaim in a lawsuit) alleging that the Program
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * itself (excluding combinations of the Program with other
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * software or hardware) infringes such Recipient's
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * patent(s), then such Recipient's rights granted under
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Section 2(b) shall terminate as of the date such
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * litigation is filed.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * All Recipient's rights under this Agreement shall
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * terminate if it fails to comply with any of the material
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * terms or conditions of this Agreement and does not cure
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * such failure in a reasonable period of time after becoming
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * aware of such noncompliance. If all Recipient's rights
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * under this Agreement terminate, Recipient agrees to cease
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * use and distribution of the Program as soon as reasonably
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * practicable. However, Recipient's obligations under this
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Agreement and any licenses granted by Recipient relating
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * to the Program shall continue and survive.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Everyone is permitted to copy and distribute copies of
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * this Agreement, but in order to avoid inconsistency the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Agreement is copyrighted and may only be modified in the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * following manner. The Agreement Steward reserves the right
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * to publish new versions (including revisions) of this
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Agreement from time to time. No one other than the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Agreement Steward has the right to modify this Agreement.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * IBM is the initial Agreement Steward. IBM may assign the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * responsibility to serve as the Agreement Steward to a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * suitable separate entity. Each new version of the
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Agreement will be given a distinguishing version number.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * The Program (including Contributions) may always be
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * distributed subject to the version of the Agreement under
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * which it was received. In addition, after a new version of
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the Agreement is published, Contributor may elect to
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * distribute the Program (including its Contributions) under
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the new version. Except as expressly stated in Sections
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * 2(a) and 2(b) above, Recipient receives no rights or
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * licenses to the intellectual property of any Contributor
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * under this Agreement, whether expressly, by implication,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * estoppel or otherwise. All rights in the Program not
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * expressly granted under this Agreement are reserved.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * This Agreement is governed by the laws of the State of New
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * York and the intellectual property laws of the United
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * States of America. No party to this Agreement will bring a
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * legal action under this Agreement more than one year after
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * the cause of action arose. Each party waives its rights to
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * a jury trial in any resulting litigation.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * (C) COPYRIGHT International Business Machines Corp. 2001,2002
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll */
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll/*
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll * Use is subject to license terms.
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll */
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll#include "tpmtok_int.h"
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys IngersollCK_RV
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersollmd5_hash(SESSION *sess,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BBOOL length_only,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll DIGEST_CONTEXT *ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE *in_data,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG in_data_len,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE *out_data,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG *out_data_len)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll{
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (! sess || ! ctx || ! out_data_len) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_FUNCTION_FAILED);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *out_data_len = MD5_DIGEST_LENGTH;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (length_only == TRUE) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_OK);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll MD5Update(ctx->context.md5ctx, in_data, in_data_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll MD5Final(out_data, ctx->context.md5ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_OK);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll}
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys IngersollCK_RV
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersollmd5_hmac_sign(SESSION * sess,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BBOOL length_only,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll SIGN_VERIFY_CONTEXT * ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE * in_data,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG in_data_len,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE * out_data,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG * out_data_len)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll{
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll OBJECT * key_obj = NULL;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ATTRIBUTE * attr = NULL;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE hash[MD5_DIGEST_LENGTH];
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll DIGEST_CONTEXT digest_ctx;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_MECHANISM digest_mech;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE k_ipad[MD5_BLOCK_SIZE];
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE k_opad[MD5_BLOCK_SIZE];
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG key_bytes, hash_len, hmac_len;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG i;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_RV rc;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (! sess || ! ctx || ! out_data_len) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_FUNCTION_FAILED);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (ctx->mech.mechanism == CKM_MD5_HMAC_GENERAL) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hmac_len = *(CK_ULONG *)ctx->mech.pParameter;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (hmac_len == 0) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *out_data_len = 0;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_OK);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll else
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hmac_len = MD5_DIGEST_LENGTH;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *out_data_len = hmac_len;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (length_only == TRUE) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_OK);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&digest_ctx, 0x0, sizeof (DIGEST_CONTEXT));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = object_mgr_find_in_map1(sess->hContext, ctx->key, &key_obj);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = template_attribute_find(key_obj->template, CKA_VALUE, &attr);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc == FALSE) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_FUNCTION_FAILED);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll else
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll key_bytes = attr->ulValueLen;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll // build (K XOR ipad), (K XOR opad)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll //
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (key_bytes > MD5_BLOCK_SIZE) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll digest_mech.mechanism = CKM_MD5;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll digest_mech.ulParameterLen = 0;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll digest_mech.pParameter = NULL;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_init(sess, &digest_ctx, &digest_mech);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hash_len = *out_data_len;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest(sess, FALSE, &digest_ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll attr->pValue, attr->ulValueLen,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hash, &hash_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&digest_ctx, 0x0, sizeof (DIGEST_CONTEXT));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll for (i = 0; i < hash_len; i++) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll k_ipad[i] = hash[i] ^ 0x36;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll k_opad[i] = hash[i] ^ 0x5C;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&k_ipad[i], 0x36, MD5_BLOCK_SIZE - i);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&k_opad[i], 0x5C, MD5_BLOCK_SIZE - i);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll } else {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE *key = attr->pValue;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll for (i = 0; i < key_bytes; i++) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll k_ipad[i] = key[i] ^ 0x36;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll k_opad[i] = key[i] ^ 0x5C;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&k_ipad[i], 0x36, MD5_BLOCK_SIZE - key_bytes);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&k_opad[i], 0x5C, MD5_BLOCK_SIZE - key_bytes);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll digest_mech.mechanism = CKM_MD5;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll digest_mech.ulParameterLen = 0;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll digest_mech.pParameter = NULL;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_init(sess, &digest_ctx, &digest_mech);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest_update(sess, &digest_ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll k_ipad, MD5_BLOCK_SIZE);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest_update(sess, &digest_ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll in_data, in_data_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hash_len = sizeof (hash);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest_final(sess, &digest_ctx, hash, &hash_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&digest_ctx, 0x0, sizeof (DIGEST_CONTEXT));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_init(sess, &digest_ctx, &digest_mech);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest_update(sess, &digest_ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll k_opad, MD5_BLOCK_SIZE);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest_update(sess, &digest_ctx, hash, hash_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hash_len = sizeof (hash);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = digest_mgr_digest_final(sess, &digest_ctx, hash, &hash_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memcpy(out_data, hash, hmac_len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll *out_data_len = hmac_len;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) digest_mgr_cleanup(&digest_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_OK);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll}
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys IngersollCK_RV
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersollmd5_hmac_verify(SESSION * sess,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll SIGN_VERIFY_CONTEXT * ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE * in_data,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG in_data_len,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE * signature,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG sig_len)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll{
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_BYTE hmac[MD5_DIGEST_LENGTH];
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll SIGN_VERIFY_CONTEXT hmac_ctx;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_ULONG hmac_len, len;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll CK_RV rc;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (! sess || ! ctx || ! in_data || ! signature) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_FUNCTION_FAILED);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (ctx->mech.mechanism == CKM_MD5_HMAC_GENERAL)
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hmac_len = *(CK_ULONG *)ctx->mech.pParameter;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll else
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll hmac_len = MD5_DIGEST_LENGTH;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) memset(&hmac_ctx, 0, sizeof (SIGN_VERIFY_CONTEXT));
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = sign_mgr_init(sess, &hmac_ctx, &ctx->mech, FALSE, ctx->key);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) sign_mgr_cleanup(&hmac_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll len = sizeof (hmac);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = sign_mgr_sign(sess, FALSE, &hmac_ctx,
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll in_data, in_data_len, hmac, &len);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (rc != CKR_OK) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) sign_mgr_cleanup(&hmac_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if ((len != hmac_len) || (len != sig_len)) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (CKR_SIGNATURE_LEN_RANGE);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll if (memcmp(hmac, signature, hmac_len) != 0) {
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll rc = CKR_SIGNATURE_INVALID;
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll }
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll (void) sign_mgr_cleanup(&hmac_ctx);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll return (rc);
47e946e784719ae402ace34695f67b0e6e76ae5cWyllys Ingersoll}