Coverage Report

Created: 2025-10-10 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tpm2/PolicyCommandCode.c
Line
Count
Source
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 "PolicyCommandCode_fp.h"
10
//
11
//
12
//     Error Returns                     Meaning
13
//
14
//     TPM_RC_VALUE                      commandCode of policySession previously set to a different value
15
//
16
TPM_RC
17
TPM2_PolicyCommandCode(
18
   PolicyCommandCode_In      *in                   // IN: input parameter list
19
   )
20
0
{
21
0
   SESSION      *session;
22
0
   TPM_CC       commandCode = TPM_CC_PolicyCommandCode;
23
0
   HASH_STATE   hashState;
24
25
// Input validation
26
27
   // Get pointer to the session structure
28
0
   session = SessionGet(in->policySession);
29
30
0
   if(session->commandCode != 0 && session->commandCode != in->code)
31
0
       return TPM_RC_VALUE + RC_PolicyCommandCode_code;
32
0
   if(!CommandIsImplemented(in->code))
33
0
       return TPM_RC_POLICY_CC + RC_PolicyCommandCode_code;
34
35
// Internal Data Update
36
   // Update policy hash
37
   // policyDigestnew = hash(policyDigestold || TPM_CC_PolicyCommandCode || code)
38
   // Start hash
39
0
   CryptStartHash(session->authHashAlg, &hashState);
40
41
   // add old digest
42
0
   CryptUpdateDigest2B(&hashState, &session->u2.policyDigest.b);
43
44
   // add commandCode
45
0
   CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &commandCode);
46
47
   // add input commandCode
48
0
   CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &in->code);
49
50
   // complete the hash and get the results
51
0
   CryptCompleteHash2B(&hashState, &session->u2.policyDigest.b);
52
53
   // update commandCode value in session context
54
0
   session->commandCode = in->code;
55
56
0
   return TPM_RC_SUCCESS;
57
0
}