Coverage Report

Created: 2025-07-11 06:15

/src/tpm2/Hash.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 "Hash_fp.h"
10
TPM_RC
11
TPM2_Hash(
12
   Hash_In         *in,            // IN: input parameter list
13
   Hash_Out        *out            // OUT: output parameter list
14
   )
15
0
{
16
0
   HASH_STATE         hashState;
17
18
// Command Output
19
20
   // Output hash
21
       // Start hash stack
22
0
   out->outHash.t.size = CryptStartHash(in->hashAlg, &hashState);
23
       // Adding hash data
24
0
   CryptUpdateDigest2B(&hashState, &in->data.b);
25
       // Complete hash
26
0
   CryptCompleteHash2B(&hashState, &out->outHash.b);
27
28
   // Output ticket
29
0
   out->validation.tag = TPM_ST_HASHCHECK;
30
0
   out->validation.hierarchy = in->hierarchy;
31
32
0
   if(in->hierarchy == TPM_RH_NULL)
33
0
   {
34
       // Ticket is not required
35
0
       out->validation.hierarchy = TPM_RH_NULL;
36
0
       out->validation.digest.t.size = 0;
37
0
   }
38
0
   else if( in->data.t.size >= sizeof(TPM_GENERATED)
39
0
           && !TicketIsSafe(&in->data.b))
40
0
   {
41
       // Ticket is not safe
42
0
       out->validation.hierarchy = TPM_RH_NULL;
43
0
       out->validation.digest.t.size = 0;
44
0
   }
45
0
   else
46
0
   {
47
       // Compute ticket
48
0
       TicketComputeHashCheck(in->hierarchy, in->hashAlg,
49
0
                              &out->outHash, &out->validation);
50
0
   }
51
52
0
   return TPM_RC_SUCCESS;
53
0
}