Coverage Report

Created: 2026-08-31 07:17

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/ibmswtpm2/src/Manufacture.c
Line
Count
Source
1
/********************************************************************************/
2
/*                    */
3
/*      Performs the manufacturing of the TPM       */
4
/*           Written by Ken Goldman       */
5
/*           IBM Thomas J. Watson Research Center     */
6
/*            $Id: Manufacture.c 1262 2018-07-11 21:03:43Z kgoldman $   */
7
/*                    */
8
/*  Licenses and Notices              */
9
/*                    */
10
/*  1. Copyright Licenses:              */
11
/*                    */
12
/*  - Trusted Computing Group (TCG) grants to the user of the source code in  */
13
/*    this specification (the "Source Code") a worldwide, irrevocable,    */
14
/*    nonexclusive, royalty free, copyright license to reproduce, create  */
15
/*    derivative works, distribute, display and perform the Source Code and */
16
/*    derivative works thereof, and to grant others the rights granted herein.  */
17
/*                    */
18
/*  - The TCG grants to the user of the other parts of the specification  */
19
/*    (other than the Source Code) the rights to reproduce, distribute,   */
20
/*    display, and perform the specification solely for the purpose of    */
21
/*    developing products based on such documents.        */
22
/*                    */
23
/*  2. Source Code Distribution Conditions:         */
24
/*                    */
25
/*  - Redistributions of Source Code must retain the above copyright licenses,  */
26
/*    this list of conditions and the following disclaimers.      */
27
/*                    */
28
/*  - Redistributions in binary form must reproduce the above copyright   */
29
/*    licenses, this list of conditions and the following disclaimers in the  */
30
/*    documentation and/or other materials provided with the distribution.  */
31
/*                    */
32
/*  3. Disclaimers:               */
33
/*                    */
34
/*  - THE COPYRIGHT LICENSES SET FORTH ABOVE DO NOT REPRESENT ANY FORM OF */
35
/*  LICENSE OR WAIVER, EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, WITH */
36
/*  RESPECT TO PATENT RIGHTS HELD BY TCG MEMBERS (OR OTHER THIRD PARTIES) */
37
/*  THAT MAY BE NECESSARY TO IMPLEMENT THIS SPECIFICATION OR OTHERWISE.   */
38
/*  Contact TCG Administration (admin@trustedcomputinggroup.org) for    */
39
/*  information on specification licensing rights available through TCG   */
40
/*  membership agreements.              */
41
/*                    */
42
/*  - THIS SPECIFICATION IS PROVIDED "AS IS" WITH NO EXPRESS OR IMPLIED   */
43
/*    WARRANTIES WHATSOEVER, INCLUDING ANY WARRANTY OF MERCHANTABILITY OR   */
44
/*    FITNESS FOR A PARTICULAR PURPOSE, ACCURACY, COMPLETENESS, OR    */
45
/*    NONINFRINGEMENT OF INTELLECTUAL PROPERTY RIGHTS, OR ANY WARRANTY    */
46
/*    OTHERWISE ARISING OUT OF ANY PROPOSAL, SPECIFICATION OR SAMPLE.   */
47
/*                    */
48
/*  - Without limitation, TCG and its members and licensors disclaim all  */
49
/*    liability, including liability for infringement of any proprietary  */
50
/*    rights, relating to use of information in this specification and to the */
51
/*    implementation of this specification, and TCG disclaims all liability for */
52
/*    cost of procurement of substitute goods or services, lost profits, loss   */
53
/*    of use, loss of data or any incidental, consequential, direct, indirect,  */
54
/*    or special damages, whether under contract, tort, warranty or otherwise,  */
55
/*    arising in any way out of use or reliance upon this specification or any  */
56
/*    information herein.             */
57
/*                    */
58
/*  (c) Copyright IBM Corp. and others, 2016 - 2018       */
59
/*                    */
60
/********************************************************************************/
61
62
/* 9.9 Manufacture.c */
63
/* 9.9.1 Description */
64
/* This file contains the function that performs the manufacturing of the TPM in a simulated
65
   environment. These functions should not be used outside of a manufacturing or simulation
66
   environment. */
67
/* 9.9.2 Includes and Data Definitions */
68
#define MANUFACTURE_C
69
#include "Tpm.h"
70
#include "TpmSizeChecks_fp.h"
71
/* 9.9.3 Functions */
72
/* 9.9.3.1 TPM_Manufacture() */
73
/* This function initializes the TPM values in preparation for the TPMs first use. This function
74
   will fail if previously called. The TPM can be re-manufactured by calling TPM_Teardown() first
75
   and then calling this function again. */
76
/* Return Values Meaning */
77
/* 0 success */
78
/* 1 manufacturing process previously performed */
79
LIB_EXPORT int
80
TPM_Manufacture(
81
    int             firstTime       // IN: indicates if this is the first call from
82
            // main()
83
    )
84
759
{
85
759
    TPM_SU          orderlyShutdown;
86
#if RUNTIME_SIZE_CHECKS
87
    // Call the function to verify the sizes of values that result from different
88
    // compile options.
89
    TpmSizeChecks();
90
#endif
91
    // If TPM has been manufactured, return indication.
92
759
    if(!firstTime && g_manufactured)
93
253
  return 1;
94
    // Do power on initializations of the cryptographic libraries.
95
506
    CryptInit();
96
506
    s_DAPendingOnNV = FALSE;
97
    // initialize NV
98
506
    NvManufacture();
99
    // Clear the magic value in the DRBG state
100
506
    go.drbgState.magic = 0;
101
506
    CryptStartup(SU_RESET);
102
    // default configuration for PCR
103
506
    PCRSimStart();
104
    // initialize pre-installed hierarchy data
105
    // This should happen after NV is initialized because hierarchy data is
106
    // stored in NV.
107
506
    HierarchyPreInstall_Init();
108
    // initialize dictionary attack parameters
109
506
    DAPreInstall_Init();
110
    // initialize PP list
111
506
    PhysicalPresencePreInstall_Init();
112
    // initialize command audit list
113
506
    CommandAuditPreInstall_Init();
114
    // first start up is required to be Startup(CLEAR)
115
506
    orderlyShutdown = TPM_SU_CLEAR;
116
506
    NV_WRITE_PERSISTENT(orderlyState, orderlyShutdown);
117
    // initialize the firmware version
118
506
    gp.firmwareV1 = FIRMWARE_V1;
119
506
#ifdef FIRMWARE_V2
120
506
    gp.firmwareV2 = FIRMWARE_V2;
121
#else
122
    gp.firmwareV2 = 0;
123
#endif
124
506
    NV_SYNC_PERSISTENT(firmwareV1);
125
506
    NV_SYNC_PERSISTENT(firmwareV2);
126
    // initialize the total reset counter to 0
127
506
    gp.totalResetCount = 0;
128
506
    NV_SYNC_PERSISTENT(totalResetCount);
129
    // initialize the clock stuff
130
506
    go.clock = 0;
131
506
    go.clockSafe = YES;
132
506
    NvWrite(NV_ORDERLY_DATA, sizeof(ORDERLY_DATA), &go);
133
    // Commit NV writes.  Manufacture process is an artificial process existing
134
    // only in simulator environment and it is not defined in the specification
135
    // that what should be the expected behavior if the NV write fails at this
136
    // point.  Therefore, it is assumed the NV write here is always success and
137
    // no return code of this function is checked.
138
506
    NvCommit();
139
506
    g_manufactured = TRUE;
140
506
    return 0;
141
759
}
142
/* 9.9.3.2 TPM_TearDown() */
143
/* This function prepares the TPM for re-manufacture. It should not be implemented in anything other
144
   than a simulated TPM. */
145
/* In this implementation, all that is needs is to stop the cryptographic units and set a flag to
146
   indicate that the TPM can be re-manufactured. This should be all that is necessary to start the
147
   manufacturing process again. */
148
/* Return Values Meaning */
149
/* 0 success */
150
/* 1 TPM not previously manufactured */
151
LIB_EXPORT int
152
TPM_TearDown(
153
       void
154
       )
155
253
{
156
253
    g_manufactured = FALSE;
157
253
    return 0;
158
253
}
159
/* 9.9.3.3 TpmEndSimulation() */
160
/* This function is called at the end of the simulation run. It is used to provoke printing of any
161
   statistics that might be needed. */
162
LIB_EXPORT void
163
TpmEndSimulation(
164
     void
165
     )
166
0
{
167
#if SIMULATION
168
    HashLibSimulationEnd();
169
    SymLibSimulationEnd();
170
    MathLibSimulationEnd();
171
#if ALG_RSA
172
    RsaSimulationEnd();
173
#endif
174
#if ALG_ECC
175
    EccSimulationEnd();
176
#endif
177
#endif // SIMULATION
178
0
}