| 1 |
/* Microsoft Reference Implementation for TPM 2.0 |
| 2 |
* |
| 3 |
* The copyright in this software is being made available under the BSD License, |
| 4 |
* included below. This software may be subject to other third party and |
| 5 |
* contributor rights, including patent rights, and no such rights are granted |
| 6 |
* under this license. |
| 7 |
* |
| 8 |
* Copyright (c) Microsoft Corporation |
| 9 |
* |
| 10 |
* All rights reserved. |
| 11 |
* |
| 12 |
* BSD License |
| 13 |
* |
| 14 |
* Redistribution and use in source and binary forms, with or without modification, |
| 15 |
* are permitted provided that the following conditions are met: |
| 16 |
* |
| 17 |
* Redistributions of source code must retain the above copyright notice, this list |
| 18 |
* of conditions and the following disclaimer. |
| 19 |
* |
| 20 |
* Redistributions in binary form must reproduce the above copyright notice, this |
| 21 |
* list of conditions and the following disclaimer in the documentation and/or |
| 22 |
* other materials provided with the distribution. |
| 23 |
* |
| 24 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS"" |
| 25 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 26 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 27 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR |
| 28 |
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 29 |
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 30 |
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON |
| 31 |
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 32 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 33 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 34 |
*/ |
| 35 |
//** Description |
| 36 |
// This file contains the function that performs the "manufacturing" of the TPM |
| 37 |
// in a simulated environment. These functions should not be used outside of |
| 38 |
// a manufacturing or simulation environment. |
| 39 |
|
| 40 |
//** Includes and Data Definitions |
| 41 |
#define MANUFACTURE_C |
| 42 |
#include "Tpm.h" |
| 43 |
#include "TpmSizeChecks_fp.h" |
| 44 |
|
| 45 |
//** Functions |
| 46 |
|
| 47 |
//*** TPM_Manufacture() |
| 48 |
// This function initializes the TPM values in preparation for the TPM's first |
| 49 |
// use. This function will fail if previously called. The TPM can be re-manufactured |
| 50 |
// by calling TPM_Teardown() first and then calling this function again. |
| 51 |
// Return Type: int |
| 52 |
// 0 success |
| 53 |
// 1 manufacturing process previously performed |
| 54 |
LIB_EXPORT int |
| 55 |
TPM_Manufacture( |
| 56 |
int firstTime // IN: indicates if this is the first call from |
| 57 |
// main() |
| 58 |
) |
| 59 |
{ |
| 60 |
TPM_SU orderlyShutdown; |
| 61 |
|
| 62 |
#if RUNTIME_SIZE_CHECKS |
| 63 |
// Call the function to verify the sizes of values that result from different |
| 64 |
// compile options. |
| 65 |
TpmSizeChecks(); |
| 66 |
#endif |
| 67 |
|
| 68 |
// If TPM has been manufactured, return indication. |
| 69 |
if(!firstTime && g_manufactured) |
| 70 |
return 1; |
| 71 |
|
| 72 |
// Do power on initializations of the cryptographic libraries. |
| 73 |
CryptInit(); |
| 74 |
|
| 75 |
s_DAPendingOnNV = FALSE; |
| 76 |
|
| 77 |
// initialize NV |
| 78 |
NvManufacture(); |
| 79 |
|
| 80 |
// Clear the magic value in the DRBG state |
| 81 |
go.drbgState.magic = 0; |
| 82 |
|
| 83 |
CryptStartup(SU_RESET); |
| 84 |
|
| 85 |
// default configuration for PCR |
| 86 |
PCRSimStart(); |
| 87 |
|
| 88 |
// initialize pre-installed hierarchy data |
| 89 |
// This should happen after NV is initialized because hierarchy data is |
| 90 |
// stored in NV. |
| 91 |
HierarchyPreInstall_Init(); |
| 92 |
|
| 93 |
// initialize dictionary attack parameters |
| 94 |
DAPreInstall_Init(); |
| 95 |
|
| 96 |
// initialize PP list |
| 97 |
PhysicalPresencePreInstall_Init(); |
| 98 |
|
| 99 |
// initialize command audit list |
| 100 |
CommandAuditPreInstall_Init(); |
| 101 |
|
| 102 |
// first start up is required to be Startup(CLEAR) |
| 103 |
orderlyShutdown = TPM_SU_CLEAR; |
| 104 |
NV_WRITE_PERSISTENT(orderlyState, orderlyShutdown); |
| 105 |
|
| 106 |
// initialize the firmware version |
| 107 |
gp.firmwareV1 = FIRMWARE_V1; |
| 108 |
#ifdef FIRMWARE_V2 |
| 109 |
gp.firmwareV2 = FIRMWARE_V2; |
| 110 |
#else |
| 111 |
gp.firmwareV2 = 0; |
| 112 |
#endif |
| 113 |
NV_SYNC_PERSISTENT(firmwareV1); |
| 114 |
NV_SYNC_PERSISTENT(firmwareV2); |
| 115 |
|
| 116 |
// initialize the total reset counter to 0 |
| 117 |
gp.totalResetCount = 0; |
| 118 |
NV_SYNC_PERSISTENT(totalResetCount); |
| 119 |
|
| 120 |
// initialize the clock stuff |
| 121 |
go.clock = 0; |
| 122 |
go.clockSafe = YES; |
| 123 |
|
| 124 |
NvWrite(NV_ORDERLY_DATA, sizeof(ORDERLY_DATA), &go); |
| 125 |
|
| 126 |
// Commit NV writes. Manufacture process is an artificial process existing |
| 127 |
// only in simulator environment and it is not defined in the specification |
| 128 |
// that what should be the expected behavior if the NV write fails at this |
| 129 |
// point. Therefore, it is assumed the NV write here is always success and |
| 130 |
// no return code of this function is checked. |
| 131 |
NvCommit(); |
| 132 |
|
| 133 |
g_manufactured = TRUE; |
| 134 |
|
| 135 |
return 0; |
| 136 |
} |
| 137 |
|
| 138 |
//*** TPM_TearDown() |
| 139 |
// This function prepares the TPM for re-manufacture. It should not be implemented |
| 140 |
// in anything other than a simulated TPM. |
| 141 |
// |
| 142 |
// In this implementation, all that is needs is to stop the cryptographic units |
| 143 |
// and set a flag to indicate that the TPM can be re-manufactured. This should |
| 144 |
// be all that is necessary to start the manufacturing process again. |
| 145 |
// Return Type: int |
| 146 |
// 0 success |
| 147 |
// 1 TPM not previously manufactured |
| 148 |
LIB_EXPORT int |
| 149 |
TPM_TearDown( |
| 150 |
void |
| 151 |
) |
| 152 |
{ |
| 153 |
g_manufactured = FALSE; |
| 154 |
return 0; |
| 155 |
} |
| 156 |
|
| 157 |
|
| 158 |
//*** TpmEndSimulation() |
| 159 |
// This function is called at the end of the simulation run. It is used to provoke |
| 160 |
// printing of any statistics that might be needed. |
| 161 |
LIB_EXPORT void |
| 162 |
TpmEndSimulation( |
| 163 |
void |
| 164 |
) |
| 165 |
{ |
| 166 |
#if SIMULATION |
| 167 |
HashLibSimulationEnd(); |
| 168 |
SymLibSimulationEnd(); |
| 169 |
MathLibSimulationEnd(); |
| 170 |
#if ALG_RSA |
| 171 |
RsaSimulationEnd(); |
| 172 |
#endif |
| 173 |
#if ALG_ECC |
| 174 |
EccSimulationEnd(); |
| 175 |
#endif |
| 176 |
#endif // SIMULATION |
| 177 |
} |