Coverage Report

Created: 2023-06-07 06:46

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