diff options
author | Vadim Bendebury <vbendeb@chromium.org> | 2015-05-20 10:32:25 -0700 |
---|---|---|
committer | Vadim Bendebury <vbendeb@chromium.org> | 2015-05-20 22:32:05 -0700 |
commit | 5679752bf24c21135884e987c4077e2f71848971 (patch) | |
tree | 3e680dd91a7af84c45ea1170ee88225bd4ad32c8 /PolicyCpHash.c | |
download | tpm2-5679752bf24c21135884e987c4077e2f71848971.tar.gz |
Initial commit to seed TPM2.0 source code directory
LICENSE file text copied from TCG library specification. README
describes the procedure used to extract source code from parts 3 and 4
of the specification.
The python scripts and part{34}.txt files will be removed in the
following commits.
Change-Id: Ie281e6e988481831f33483053455e8aff8f3f75f
Signed-off-by: Vadim Bendebury <vbendeb@chromium.org>
Diffstat (limited to 'PolicyCpHash.c')
-rw-r--r-- | PolicyCpHash.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/PolicyCpHash.c b/PolicyCpHash.c new file mode 100644 index 0000000..7dee3a3 --- /dev/null +++ b/PolicyCpHash.c @@ -0,0 +1,68 @@ +// This file was extracted from the TCG Published +// Trusted Platform Module Library +// Part 3: Commands +// Family "2.0" +// Level 00 Revision 01.16 +// October 30, 2014 + +#include "InternalRoutines.h" +#include "PolicyCpHash_fp.h" +// +// +// Error Returns Meaning +// +// TPM_RC_CPHASH cpHash of policySession has previously been set to a different value +// TPM_RC_SIZE cpHashA is not the size of a digest produced by the hash algorithm +// associated with policySession +// +TPM_RC +TPM2_PolicyCpHash( + PolicyCpHash_In *in // IN: input parameter list + ) +{ + SESSION *session; + TPM_CC commandCode = TPM_CC_PolicyCpHash; + HASH_STATE hashState; + +// Input Validation + + // Get pointer to the session structure + session = SessionGet(in->policySession); + + // A new cpHash is given in input parameter, but cpHash in session context + // is not empty, or is not the same as the new cpHash + if( in->cpHashA.t.size != 0 + && session->u1.cpHash.t.size != 0 + && !Memory2BEqual(&in->cpHashA.b, &session->u1.cpHash.b) + ) + return TPM_RC_CPHASH; + + // A valid cpHash must have the same size as session hash digest + if(in->cpHashA.t.size != CryptGetHashDigestSize(session->authHashAlg)) + return TPM_RC_SIZE + RC_PolicyCpHash_cpHashA; + +// Internal Data Update + + // Update policy hash + // policyDigestnew = hash(policyDigestold || TPM_CC_PolicyCpHash || cpHashA) + // Start hash + CryptStartHash(session->authHashAlg, &hashState); + + // add old digest + CryptUpdateDigest2B(&hashState, &session->u2.policyDigest.b); + + // add commandCode + CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &commandCode); + + // add cpHashA + CryptUpdateDigest2B(&hashState, &in->cpHashA.b); + + // complete the digest and get the results + CryptCompleteHash2B(&hashState, &session->u2.policyDigest.b); + + // update cpHash in session context + session->u1.cpHash = in->cpHashA; + session->attributes.iscpHashDefined = SET; + + return TPM_RC_SUCCESS; +} |