| 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 |
#include "Tpm.h" |
| 36 |
#include "Clear_fp.h" |
| 37 |
|
| 38 |
#if CC_Clear // Conditional expansion of this file |
| 39 |
|
| 40 |
/*(See part 3 specification) |
| 41 |
// Clear owner |
| 42 |
*/ |
| 43 |
// Return Type: TPM_RC |
| 44 |
// TPM_RC_DISABLED Clear command has been disabled |
| 45 |
TPM_RC |
| 46 |
TPM2_Clear( |
| 47 |
Clear_In *in // IN: input parameter list |
| 48 |
) |
| 49 |
{ |
| 50 |
// Input parameter is not reference in command action |
| 51 |
NOT_REFERENCED(in); |
| 52 |
|
| 53 |
// The command needs NV update. Check if NV is available. |
| 54 |
// A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at |
| 55 |
// this point |
| 56 |
RETURN_IF_NV_IS_NOT_AVAILABLE; |
| 57 |
|
| 58 |
// Input Validation |
| 59 |
|
| 60 |
// If Clear command is disabled, return an error |
| 61 |
if(gp.disableClear) |
| 62 |
return TPM_RC_DISABLED; |
| 63 |
|
| 64 |
// Internal Data Update |
| 65 |
|
| 66 |
// Reset storage hierarchy seed from RNG |
| 67 |
CryptRandomGenerate(sizeof(gp.SPSeed.t.buffer), gp.SPSeed.t.buffer); |
| 68 |
|
| 69 |
// Create new shProof and ehProof value from RNG |
| 70 |
CryptRandomGenerate(sizeof(gp.shProof.t.buffer), gp.shProof.t.buffer); |
| 71 |
CryptRandomGenerate(sizeof(gp.ehProof.t.buffer), gp.ehProof.t.buffer); |
| 72 |
|
| 73 |
// Enable storage and endorsement hierarchy |
| 74 |
gc.shEnable = gc.ehEnable = TRUE; |
| 75 |
|
| 76 |
// set the authValue buffers to zero |
| 77 |
MemorySet(&gp.ownerAuth, 0, sizeof(gp.ownerAuth)); |
| 78 |
MemorySet(&gp.endorsementAuth, 0, sizeof(gp.endorsementAuth)); |
| 79 |
MemorySet(&gp.lockoutAuth, 0, sizeof(gp.lockoutAuth)); |
| 80 |
|
| 81 |
// Set storage, endorsement, and lockout authPolicy to null |
| 82 |
gp.ownerAlg = gp.endorsementAlg = gp.lockoutAlg = TPM_ALG_NULL; |
| 83 |
MemorySet(&gp.ownerPolicy, 0, sizeof(gp.ownerPolicy)); |
| 84 |
MemorySet(&gp.endorsementPolicy, 0, sizeof(gp.endorsementPolicy)); |
| 85 |
MemorySet(&gp.lockoutPolicy, 0, sizeof(gp.lockoutPolicy)); |
| 86 |
|
| 87 |
// Flush loaded object in storage and endorsement hierarchy |
| 88 |
ObjectFlushHierarchy(TPM_RH_OWNER); |
| 89 |
ObjectFlushHierarchy(TPM_RH_ENDORSEMENT); |
| 90 |
|
| 91 |
// Flush owner and endorsement object and owner index in NV |
| 92 |
NvFlushHierarchy(TPM_RH_OWNER); |
| 93 |
NvFlushHierarchy(TPM_RH_ENDORSEMENT); |
| 94 |
|
| 95 |
// Initialize dictionary attack parameters |
| 96 |
DAPreInstall_Init(); |
| 97 |
|
| 98 |
// Reset clock |
| 99 |
go.clock = 0; |
| 100 |
go.clockSafe = YES; |
| 101 |
NvWrite(NV_ORDERLY_DATA, sizeof(ORDERLY_DATA), &go); |
| 102 |
|
| 103 |
// Reset counters |
| 104 |
gp.resetCount = gr.restartCount = gr.clearCount = 0; |
| 105 |
gp.auditCounter = 0; |
| 106 |
|
| 107 |
// Save persistent data changes to NV |
| 108 |
// Note: since there are so many changes to the persistent data structure, the |
| 109 |
// entire PERSISTENT_DATA structure is written as a unit |
| 110 |
NvWrite(NV_PERSISTENT_DATA, sizeof(PERSISTENT_DATA), &gp); |
| 111 |
|
| 112 |
// Reset the PCR authValues (this does not change the PCRs) |
| 113 |
PCR_ClearAuth(); |
| 114 |
|
| 115 |
// Bump the PCR counter |
| 116 |
PCRChanged(0); |
| 117 |
|
| 118 |
|
| 119 |
// orderly state should be cleared because of the update to state clear data |
| 120 |
g_clearOrderly = TRUE; |
| 121 |
|
| 122 |
return TPM_RC_SUCCESS; |
| 123 |
} |
| 124 |
|
| 125 |
#endif // CC_Clear |