blob: 5a11067ad6015eafcc29f5c5d9de30688a9c215e [file] [log] [blame]
Vadim Bendebury56797522015-05-20 10:32:25 -07001// 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 "ECDH_ZGen_fp.h"
10#ifdef TPM_ALG_ECC
11//
12//
13// Error Returns Meaning
14//
15// TPM_RC_ATTRIBUTES key referenced by keyA is restricted or not a decrypt key
16// TPM_RC_KEY key referenced by keyA is not an ECC key
17// TPM_RC_NO_RESULT multiplying inPoint resulted in a point at infinity
18// TPM_RC_SCHEME the scheme of the key referenced by keyA is not TPM_ALG_NULL,
19// TPM_ALG_ECDH,
20//
21TPM_RC
22TPM2_ECDH_ZGen(
23 ECDH_ZGen_In *in, // IN: input parameter list
24 ECDH_ZGen_Out *out // OUT: output parameter list
25 )
26{
27 TPM_RC result;
28 OBJECT *eccKey;
29
30// Input Validation
31
32 eccKey = ObjectGet(in->keyHandle);
33
34 // Input key must be a non-restricted, decrypt ECC key
35 if( eccKey->publicArea.type != TPM_ALG_ECC)
Vadim Bendebury065e0d72015-10-16 09:35:42 -070036 return TPM_RC_KEY + RC_ECDH_ZGen_keyHandle;
Vadim Bendebury56797522015-05-20 10:32:25 -070037
38 if( eccKey->publicArea.objectAttributes.restricted == SET
39 || eccKey->publicArea.objectAttributes.decrypt != SET
40 )
41 return TPM_RC_KEY + RC_ECDH_ZGen_keyHandle;
42
43 // Make sure the scheme allows this use
44 if( eccKey->publicArea.parameters.eccDetail.scheme.scheme != TPM_ALG_ECDH
45 && eccKey->publicArea.parameters.eccDetail.scheme.scheme != TPM_ALG_NULL)
46 return TPM_RC_SCHEME + RC_ECDH_ZGen_keyHandle;
47
48// Command Output
49
50 // Compute Z. TPM_RC_ECC_POINT or TPM_RC_NO_RESULT may be returned here.
51 result = CryptEccPointMultiply(&out->outPoint.t.point,
52 eccKey->publicArea.parameters.eccDetail.curveID,
53 &eccKey->sensitive.sensitive.ecc,
54 &in->inPoint.t.point);
55 if(result != TPM_RC_SUCCESS)
56 return RcSafeAddToResult(result, RC_ECDH_ZGen_inPoint);
57
58 out->outPoint.t.size = TPMS_ECC_POINT_Marshal(&out->outPoint.t.point,
59 NULL, NULL);
60
61 return TPM_RC_SUCCESS;
62}
63#endif