Coverage Report

Created: 2023-06-07 06:46

/src/tpm2/Manufacture.c
Line
Count
Source (jump to first uncovered line)
1
// This file was extracted from the TCG Published
2
// Trusted Platform Module Library
3
// Part 4: Supporting Routines
4
// Family "2.0"
5
// Level 00 Revision 01.16
6
// October 30, 2014
7
8
#define MANUFACTURE_C
9
#include "InternalRoutines.h"
10
#include "Global.h"
11
//
12
//
13
//          Functions
14
//
15
//         TPM_Manufacture()
16
//
17
//     This function initializes the TPM values in preparation for the TPM's first use. This function will fail if
18
//     previously called. The TPM can be re-manufactured by calling TPM_Teardown() first and then calling this
19
//     function again.
20
//
21
//     Return Value                      Meaning
22
//
23
//     0                                 success
24
//     1                                 manufacturing process previously performed
25
//
26
LIB_EXPORT int
27
TPM_Manufacture(
28
   BOOL                 firstTime           // IN: indicates if this is the first call from
29
                                            //     main()
30
   )
31
5.63k
{
32
5.63k
   TPM_SU              orderlyShutdown;
33
5.63k
   UINT64              totalResetCount = 0;
34
   // If TPM has been manufactured, return indication.
35
5.63k
   if(!firstTime && g_manufactured)
36
0
       return 1;
37
   // initialize crypto units
38
   //CryptInitUnits();
39
   //
40
5.63k
   s_selfHealTimer = 0;
41
5.63k
   s_lockoutTimer = 0;
42
5.63k
   s_DAPendingOnNV = FALSE;
43
   // initialize NV
44
5.63k
   NvInit();
45
5.63k
#ifdef _DRBG_STATE_SAVE
46
   // Initialize the drbg. This needs to come before the install
47
   // of the hierarchies
48
5.63k
   if(!_cpri__Startup())               // Have to start the crypto units first
49
0
       FAIL(FATAL_ERROR_INTERNAL);
50
5.63k
   _cpri__DrbgGetPutState(PUT_STATE, 0, NULL);
51
5.63k
#endif
52
   // default configuration for PCR
53
5.63k
   PCRSimStart();
54
   // initialize pre-installed hierarchy data
55
   // This should happen after NV is initialized because hierarchy data is
56
   // stored in NV.
57
5.63k
   HierarchyPreInstall_Init();
58
   // initialize dictionary attack parameters
59
5.63k
   DAPreInstall_Init();
60
   // initialize PP list
61
5.63k
   PhysicalPresencePreInstall_Init();
62
   // initialize command audit list
63
5.63k
   CommandAuditPreInstall_Init();
64
   // first start up is required to be Startup(CLEAR)
65
5.63k
   orderlyShutdown = TPM_SU_CLEAR;
66
5.63k
   NvWriteReserved(NV_ORDERLY, &orderlyShutdown);
67
   // initialize the firmware version
68
#ifdef EMBEDDED_MODE
69
   _plat__GetFwVersion(&gp.firmwareV1, &gp.firmwareV2);
70
#else
71
5.63k
   gp.firmwareV1 = FIRMWARE_V1;
72
5.63k
#ifdef FIRMWARE_V2
73
5.63k
   gp.firmwareV2 = FIRMWARE_V2;
74
#else
75
   gp.firmwareV2 = 0;
76
#endif
77
5.63k
   NvWriteReserved(NV_FIRMWARE_V1, &gp.firmwareV1);
78
5.63k
   NvWriteReserved(NV_FIRMWARE_V2, &gp.firmwareV2);
79
5.63k
#endif
80
    // initialize the total reset counter to 0
81
5.63k
    NvWriteReserved(NV_TOTAL_RESET_COUNT, &totalResetCount);
82
    // initialize the clock stuff
83
5.63k
    go.clock = 0;
84
5.63k
    go.clockSafe = YES;
85
5.63k
#ifdef _DRBG_STATE_SAVE
86
   // initialize the current DRBG state in NV
87
5.63k
   _cpri__DrbgGetPutState(GET_STATE, sizeof(go.drbgState), (BYTE *)&go.drbgState);
88
5.63k
#endif
89
5.63k
    NvWriteReserved(NV_ORDERLY_DATA, &go);
90
    // Commit NV writes. Manufacture process is an artificial process existing
91
    // only in simulator environment and it is not defined in the specification
92
    // that what should be the expected behavior if the NV write fails at this
93
    // point. Therefore, it is assumed the NV write here is always success and
94
    // no return code of this function is checked.
95
5.63k
    NvCommit();
96
5.63k
    g_manufactured = TRUE;
97
5.63k
    return 0;
98
5.63k
}
99
//
100
//
101
//          TPM_TearDown()
102
//
103
//      This function prepares the TPM for re-manufacture. It should not be implemented in anything other than a
104
//      simulated TPM.
105
//      In this implementation, all that is needs is to stop the cryptographic units and set a flag to indicate that the
106
//      TPM can be re-manufactured. This should be all that is necessary to start the manufacturing process
107
//      again.
108
//
109
//      Return Value                      Meaning
110
//
111
//      0                                 success
112
//      1                                 TPM not previously manufactured
113
//
114
LIB_EXPORT int
115
TPM_TearDown(
116
    void
117
    )
118
0
{
119
    // stop crypt units
120
0
    CryptStopUnits();
121
0
    g_manufactured = FALSE;
122
0
      return 0;
123
0
}