• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 "PCR_SetAuthPolicy_fp.h"
10 //
11 //
12 //     Error Returns                     Meaning
13 //
14 //     TPM_RC_SIZE                       size of authPolicy is not the size of a digest produced by policyDigest
15 //     TPM_RC_VALUE                      PCR referenced by pcrNum is not a member of a PCR policy group
16 //
17 TPM_RC
TPM2_PCR_SetAuthPolicy(PCR_SetAuthPolicy_In * in)18 TPM2_PCR_SetAuthPolicy(
19    PCR_SetAuthPolicy_In       *in                   // IN: input parameter list
20    )
21 {
22    UINT32       groupIndex;
23 
24    TPM_RC       result;
25 
26    // The command needs NV update. Check if NV is available.
27    // A TPM_RC_NV_UNAVAILABLE or TPM_RC_NV_RATE error may be returned at
28    // this point
29    result = NvIsAvailable();
30    if(result != TPM_RC_SUCCESS) return result;
31 
32 // Input Validation:
33 
34    // Check the authPolicy consistent with hash algorithm
35    if(in->authPolicy.t.size != CryptGetHashDigestSize(in->hashAlg))
36        return TPM_RC_SIZE + RC_PCR_SetAuthPolicy_authPolicy;
37 
38    // If PCR does not belong to a policy group, return TPM_RC_VALUE
39    if(!PCRBelongsPolicyGroup(in->pcrNum, &groupIndex))
40        return TPM_RC_VALUE + RC_PCR_SetAuthPolicy_pcrNum;
41 
42 // Internal Data Update
43 
44    // Set PCR policy
45    gp.pcrPolicies.hashAlg[groupIndex] = in->hashAlg;
46    gp.pcrPolicies.policy[groupIndex] = in->authPolicy;
47 
48    // Save new policy to NV
49    NvWriteReserved(NV_PCR_POLICIES, &gp.pcrPolicies);
50 
51    return TPM_RC_SUCCESS;
52 }
53