Coverage Report

Created: 2025-10-10 06:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/tpm2/ECDH_ZGen.c
Line
Count
Source
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 "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
//
21
TPM_RC
22
TPM2_ECDH_ZGen(
23
   ECDH_ZGen_In      *in,                  // IN: input parameter list
24
   ECDH_ZGen_Out     *out                  // OUT: output parameter list
25
   )
26
0
{
27
0
   TPM_RC                     result;
28
0
   OBJECT                    *eccKey;
29
30
// Input Validation
31
32
0
   eccKey = ObjectGet(in->keyHandle);
33
34
   // Input key must be a non-restricted, decrypt ECC key
35
0
   if(   eccKey->publicArea.type != TPM_ALG_ECC)
36
0
       return TPM_RC_KEY + RC_ECDH_ZGen_keyHandle;
37
38
0
   if(     eccKey->publicArea.objectAttributes.restricted == SET
39
0
      ||   eccKey->publicArea.objectAttributes.decrypt != SET
40
0
     )
41
0
       return TPM_RC_ATTRIBUTES + RC_ECDH_ZGen_keyHandle;
42
43
   // Make sure the scheme allows this use
44
0
   if(     eccKey->publicArea.parameters.eccDetail.scheme.scheme != TPM_ALG_ECDH
45
0
       && eccKey->publicArea.parameters.eccDetail.scheme.scheme != TPM_ALG_NULL)
46
0
       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
0
   result = CryptEccPointMultiply(&out->outPoint.t.point,
52
0
                                  eccKey->publicArea.parameters.eccDetail.curveID,
53
0
                                  &eccKey->sensitive.sensitive.ecc,
54
0
                                  &in->inPoint.t.point);
55
0
   if(result != TPM_RC_SUCCESS)
56
0
       return RcSafeAddToResult(result, RC_ECDH_ZGen_inPoint);
57
58
0
   out->outPoint.t.size = TPMS_ECC_POINT_Marshal(&out->outPoint.t.point,
59
0
                                                 NULL, NULL);
60
61
0
   return TPM_RC_SUCCESS;
62
0
}
63
#endif