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 { 16 HASH_STATE hashState; 17 18 // Command Output 19 20 // Output hash 21 // Start hash stack 22 out->outHash.t.size = CryptStartHash(in->hashAlg, &hashState); 23 // Adding hash data 24 CryptUpdateDigest2B(&hashState, &in->data.b); 25 // Complete hash 26 CryptCompleteHash2B(&hashState, &out->outHash.b); 27 28 // Output ticket 29 out->validation.tag = TPM_ST_HASHCHECK; 30 out->validation.hierarchy = in->hierarchy; 31 32 if(in->hierarchy == TPM_RH_NULL) 33 { 34 // Ticket is not required 35 out->validation.hierarchy = TPM_RH_NULL; 36 out->validation.digest.t.size = 0; 37 } 38 else if( in->data.t.size >= sizeof(TPM_GENERATED) 39 && !TicketIsSafe(&in->data.b)) 40 { 41 // Ticket is not safe 42 out->validation.hierarchy = TPM_RH_NULL; 43 out->validation.digest.t.size = 0; 44 } 45 else 46 { 47 // Compute ticket 48 TicketComputeHashCheck(in->hierarchy, in->hashAlg, 49 &out->outHash, &out->validation); 50 } 51 52 return TPM_RC_SUCCESS; 53 } 54