aboutsummaryrefslogtreecommitdiff
path: root/PolicyDuplicationSelect.c
diff options
context:
space:
mode:
authorVadim Bendebury <vbendeb@chromium.org>2015-05-20 10:32:25 -0700
committerVadim Bendebury <vbendeb@chromium.org>2015-05-20 22:32:05 -0700
commit5679752bf24c21135884e987c4077e2f71848971 (patch)
tree3e680dd91a7af84c45ea1170ee88225bd4ad32c8 /PolicyDuplicationSelect.c
downloadtpm2-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 'PolicyDuplicationSelect.c')
-rw-r--r--PolicyDuplicationSelect.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/PolicyDuplicationSelect.c b/PolicyDuplicationSelect.c
new file mode 100644
index 0000000..eaa323c
--- /dev/null
+++ b/PolicyDuplicationSelect.c
@@ -0,0 +1,85 @@
+// 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 "PolicyDuplicationSelect_fp.h"
+//
+//
+// Error Returns Meaning
+//
+// TPM_RC_COMMAND_CODE commandCode of 'policySession; is not empty
+// TPM_RC_CPHASH cpHash of policySession is not empty
+//
+TPM_RC
+TPM2_PolicyDuplicationSelect(
+ PolicyDuplicationSelect_In *in // IN: input parameter list
+ )
+{
+ SESSION *session;
+ HASH_STATE hashState;
+ TPM_CC commandCode = TPM_CC_PolicyDuplicationSelect;
+
+// Input Validation
+
+ // Get pointer to the session structure
+ session = SessionGet(in->policySession);
+
+ // cpHash in session context must be empty
+ if(session->u1.cpHash.t.size != 0)
+ return TPM_RC_CPHASH;
+
+ // commandCode in session context must be empty
+ if(session->commandCode != 0)
+ return TPM_RC_COMMAND_CODE;
+
+// Internal Data Update
+
+ // Update name hash
+ session->u1.cpHash.t.size = CryptStartHash(session->authHashAlg, &hashState);
+
+ // add objectName
+ CryptUpdateDigest2B(&hashState, &in->objectName.b);
+
+ // add new parent name
+ CryptUpdateDigest2B(&hashState, &in->newParentName.b);
+
+ // complete hash
+ CryptCompleteHash2B(&hashState, &session->u1.cpHash.b);
+
+ // update policy hash
+ // Old policyDigest size should be the same as the new policyDigest size since
+ // they are using the same hash algorithm
+ session->u2.policyDigest.t.size
+ = CryptStartHash(session->authHashAlg, &hashState);
+
+ // add old policy
+ CryptUpdateDigest2B(&hashState, &session->u2.policyDigest.b);
+
+ // add command code
+ CryptUpdateDigestInt(&hashState, sizeof(TPM_CC), &commandCode);
+
+ // add objectName
+ if(in->includeObject == YES)
+ CryptUpdateDigest2B(&hashState, &in->objectName.b);
+
+ // add new parent name
+ CryptUpdateDigest2B(&hashState, &in->newParentName.b);
+
+ // add includeObject
+ CryptUpdateDigestInt(&hashState, sizeof(TPMI_YES_NO), &in->includeObject);
+
+ // complete digest
+ CryptCompleteHash2B(&hashState, &session->u2.policyDigest.b);
+
+ // clear iscpHashDefined bit to indicate now this field contains a nameHash
+ session->attributes.iscpHashDefined = CLEAR;
+
+ // set commandCode in session context
+ session->commandCode = TPM_CC_Duplicate;
+
+ return TPM_RC_SUCCESS;
+}