aboutsummaryrefslogtreecommitdiff
path: root/ECDH_ZGen.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 /ECDH_ZGen.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 'ECDH_ZGen.c')
-rw-r--r--ECDH_ZGen.c63
1 files changed, 63 insertions, 0 deletions
diff --git a/ECDH_ZGen.c b/ECDH_ZGen.c
new file mode 100644
index 0000000..37d95fa
--- /dev/null
+++ b/ECDH_ZGen.c
@@ -0,0 +1,63 @@
+// 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 "ECDH_ZGen_fp.h"
+#ifdef TPM_ALG_ECC
+//
+//
+// Error Returns Meaning
+//
+// TPM_RC_ATTRIBUTES key referenced by keyA is restricted or not a decrypt key
+// TPM_RC_KEY key referenced by keyA is not an ECC key
+// TPM_RC_NO_RESULT multiplying inPoint resulted in a point at infinity
+// TPM_RC_SCHEME the scheme of the key referenced by keyA is not TPM_ALG_NULL,
+// TPM_ALG_ECDH,
+//
+TPM_RC
+TPM2_ECDH_ZGen(
+ ECDH_ZGen_In *in, // IN: input parameter list
+ ECDH_ZGen_Out *out // OUT: output parameter list
+ )
+{
+ TPM_RC result;
+ OBJECT *eccKey;
+
+// Input Validation
+
+ eccKey = ObjectGet(in->keyHandle);
+
+ // Input key must be a non-restricted, decrypt ECC key
+ if( eccKey->publicArea.type != TPM_ALG_ECC)
+ return TPM_RCS_KEY + RC_ECDH_ZGen_keyHandle;
+
+ if( eccKey->publicArea.objectAttributes.restricted == SET
+ || eccKey->publicArea.objectAttributes.decrypt != SET
+ )
+ return TPM_RC_KEY + RC_ECDH_ZGen_keyHandle;
+
+ // Make sure the scheme allows this use
+ if( eccKey->publicArea.parameters.eccDetail.scheme.scheme != TPM_ALG_ECDH
+ && eccKey->publicArea.parameters.eccDetail.scheme.scheme != TPM_ALG_NULL)
+ return TPM_RC_SCHEME + RC_ECDH_ZGen_keyHandle;
+
+// Command Output
+
+ // Compute Z. TPM_RC_ECC_POINT or TPM_RC_NO_RESULT may be returned here.
+ result = CryptEccPointMultiply(&out->outPoint.t.point,
+ eccKey->publicArea.parameters.eccDetail.curveID,
+ &eccKey->sensitive.sensitive.ecc,
+ &in->inPoint.t.point);
+ if(result != TPM_RC_SUCCESS)
+ return RcSafeAddToResult(result, RC_ECDH_ZGen_inPoint);
+
+ out->outPoint.t.size = TPMS_ECC_POINT_Marshal(&out->outPoint.t.point,
+ NULL, NULL);
+
+ return TPM_RC_SUCCESS;
+}
+#endif