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 "PolicyOR_fp.h"
10 #include "Policy_spt_fp.h"
11 //
12 //
13 //     Error Returns                 Meaning
14 //
15 //     TPM_RC_VALUE                  no digest in pHashList matched the current value of policyDigest for
16 //                                   policySession
17 //
18 TPM_RC
TPM2_PolicyOR(PolicyOR_In * in)19 TPM2_PolicyOR(
20    PolicyOR_In      *in               // IN: input parameter list
21    )
22 {
23    SESSION       *session;
24    UINT32         i;
25 
26 // Input Validation and Update
27 
28    // Get pointer to the session structure
29    session = SessionGet(in->policySession);
30 
31    // Compare and Update Internal Session policy if match
32    for(i = 0; i < in->pHashList.count; i++)
33    {
34        if(   session->attributes.isTrialPolicy == SET
35           || (Memory2BEqual(&session->u2.policyDigest.b,
36                             &in->pHashList.digests[i].b))
37          )
38        {
39            // Found a match
40            HASH_STATE      hashState;
41            TPM_CC          commandCode = TPM_CC_PolicyOR;
42 
43              // Start hash
44              session->u2.policyDigest.t.size = CryptStartHash(session->authHashAlg,
45                                                             &hashState);
46              // Set policyDigest to 0 string and add it to hash
47              MemorySet(session->u2.policyDigest.t.buffer, 0,
48                        session->u2.policyDigest.t.size);
49              CryptUpdateDigest2B(&hashState, &session->u2.policyDigest.b);
50 
51              // add command code
52              CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &commandCode);
53 
54              // Add each of the hashes in the list
55              for(i = 0; i < in->pHashList.count; i++)
56              {
57                  // Extend policyDigest
58                  CryptUpdateDigest2B(&hashState, &in->pHashList.digests[i].b);
59              }
60              // Complete digest
61              CryptCompleteHash2B(&hashState, &session->u2.policyDigest.b);
62 
63              return TPM_RC_SUCCESS;
64        }
65    }
66    // None of the values in the list matched the current policyDigest
67    return TPM_RC_VALUE + RC_PolicyOR_pHashList;
68 }
69