1 // This file was extracted from the TCG Published
2 // Trusted Platform Module Library
3 // Part 3: Commands
4 // Family "2.0"
5 // Level 00 Revision 01.16
6 // October 30, 2014
7 
8 #include "InternalRoutines.h"
9 #include "ChangeEPS_fp.h"
10 TPM_RC
TPM2_ChangeEPS(ChangeEPS_In * in)11 TPM2_ChangeEPS(
12    ChangeEPS_In     *in              // IN: input parameter list
13    )
14 {
15    TPM_RC           result;
16 
17    // The command needs NV update. Check if NV is available.
18    // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at
19    // this point
20    result = NvIsAvailable();
21    if(result != TPM_RC_SUCCESS) return result;
22 
23    // Input parameter is not reference in command action
24    in = NULL;
25 
26 // Internal Data Update
27 
28    // Reset endorsement hierarchy seed from RNG
29    CryptGenerateRandom(PRIMARY_SEED_SIZE, gp.EPSeed.t.buffer);
30 
31    // Create new ehProof value from RNG
32    CryptGenerateRandom(PROOF_SIZE, gp.ehProof.t.buffer);
33 
34    // Enable endorsement hierarchy
35    gc.ehEnable = TRUE;
36 
37    // set authValue buffer to zeros
38    MemorySet(gp.endorsementAuth.t.buffer, 0, gp.endorsementAuth.t.size);
39    // Set endorsement authValue to null
40    gp.endorsementAuth.t.size = 0;
41 
42    // Set endorsement authPolicy to null
43    gp.endorsementAlg = TPM_ALG_NULL;
44    gp.endorsementPolicy.t.size = 0;
45 
46    // Flush loaded object in endorsement hierarchy
47    ObjectFlushHierarchy(TPM_RH_ENDORSEMENT);
48 
49    // Flush evict object of endorsement hierarchy stored in NV
50    NvFlushHierarchy(TPM_RH_ENDORSEMENT);
51 
52    // Save hierarchy changes to NV
53    NvWriteReserved(NV_EP_SEED, &gp.EPSeed);
54    NvWriteReserved(NV_EH_PROOF, &gp.ehProof);
55    NvWriteReserved(NV_ENDORSEMENT_AUTH, &gp.endorsementAuth);
56    NvWriteReserved(NV_ENDORSEMENT_ALG, &gp.endorsementAlg);
57    NvWriteReserved(NV_ENDORSEMENT_POLICY, &gp.endorsementPolicy);
58 
59    // orderly state should be cleared because of the update to state clear data
60    g_clearOrderly = TRUE;
61 
62    return TPM_RC_SUCCESS;
63 }
64