• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Microsoft Reference Implementation for TPM 2.0
2  *
3  *  The copyright in this software is being made available under the BSD License,
4  *  included below. This software may be subject to other third party and
5  *  contributor rights, including patent rights, and no such rights are granted
6  *  under this license.
7  *
8  *  Copyright (c) Microsoft Corporation
9  *
10  *  All rights reserved.
11  *
12  *  BSD License
13  *
14  *  Redistribution and use in source and binary forms, with or without modification,
15  *  are permitted provided that the following conditions are met:
16  *
17  *  Redistributions of source code must retain the above copyright notice, this list
18  *  of conditions and the following disclaimer.
19  *
20  *  Redistributions in binary form must reproduce the above copyright notice, this
21  *  list of conditions and the following disclaimer in the documentation and/or
22  *  other materials provided with the distribution.
23  *
24  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ""AS IS""
25  *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
28  *  ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29  *  (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
31  *  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33  *  SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  */
35 /*(Auto-generated)
36  *  Created by TpmPrototypes; Version 3.0 July 18, 2017
37  *  Date: Mar 28, 2019  Time: 08:25:18PM
38  */
39 
40 #ifndef    _CRYPT_ECC_SIGNATURE_FP_H_
41 #define    _CRYPT_ECC_SIGNATURE_FP_H_
42 
43 #if ALG_ECC
44 
45 //*** BnSignEcdsa()
46 // This function implements the ECDSA signing algorithm. The method is described
47 // in the comments below.
48 TPM_RC
49 BnSignEcdsa(
50     bigNum                   bnR,           // OUT: 'r' component of the signature
51     bigNum                   bnS,           // OUT: 's' component of the signature
52     bigCurve                 E,             // IN: the curve used in the signature
53                                             //     process
54     bigNum                   bnD,           // IN: private signing key
55     const TPM2B_DIGEST      *digest,        // IN: the digest to sign
56     RAND_STATE              *rand           // IN: used in debug of signing
57 );
58 
59 //*** CryptEccSign()
60 // This function is the dispatch function for the various ECC-based
61 // signing schemes.
62 // There is a bit of ugliness to the parameter passing. In order to test this,
63 // we sometime would like to use a deterministic RNG so that we can get the same
64 // signatures during testing. The easiest way to do this for most schemes is to
65 // pass in a deterministic RNG and let it return canned values during testing.
66 // There is a competing need for a canned parameter to use in ECDAA. To accommodate
67 // both needs with minimal fuss, a special type of RAND_STATE is defined to carry
68 // the address of the commit value. The setup and handling of this is not very
69 // different for the caller than what was in previous versions of the code.
70 //  Return Type: TPM_RC
71 //      TPM_RC_SCHEME            'scheme' is not supported
72 LIB_EXPORT TPM_RC
73 CryptEccSign(
74     TPMT_SIGNATURE          *signature,     // OUT: signature
75     OBJECT                  *signKey,       // IN: ECC key to sign the hash
76     const TPM2B_DIGEST      *digest,        // IN: digest to sign
77     TPMT_ECC_SCHEME         *scheme,        // IN: signing scheme
78     RAND_STATE              *rand
79 );
80 #if ALG_ECDSA
81 
82 //*** BnValidateSignatureEcdsa()
83 // This function validates an ECDSA signature. rIn and sIn should have been checked
84 // to make sure that they are in the range 0 < 'v' < 'n'
85 //  Return Type: TPM_RC
86 //      TPM_RC_SIGNATURE           signature not valid
87 TPM_RC
88 BnValidateSignatureEcdsa(
89     bigNum                   bnR,           // IN: 'r' component of the signature
90     bigNum                   bnS,           // IN: 's' component of the signature
91     bigCurve                 E,             // IN: the curve used in the signature
92                                             //     process
93     bn_point_t              *ecQ,           // IN: the public point of the key
94     const TPM2B_DIGEST      *digest         // IN: the digest that was signed
95 );
96 #endif      // ALG_ECDSA
97 
98 //*** CryptEccValidateSignature()
99 // This function validates an EcDsa or EcSchnorr signature.
100 // The point 'Qin' needs to have been validated to be on the curve of 'curveId'.
101 //  Return Type: TPM_RC
102 //      TPM_RC_SIGNATURE            not a valid signature
103 LIB_EXPORT TPM_RC
104 CryptEccValidateSignature(
105     TPMT_SIGNATURE          *signature,     // IN: signature to be verified
106     OBJECT                  *signKey,       // IN: ECC key signed the hash
107     const TPM2B_DIGEST      *digest         // IN: digest that was signed
108 );
109 
110 //***CryptEccCommitCompute()
111 // This function performs the point multiply operations required by TPM2_Commit.
112 //
113 // If 'B' or 'M' is provided, they must be on the curve defined by 'curveId'. This
114 // routine does not check that they are on the curve and results are unpredictable
115 // if they are not.
116 //
117 // It is a fatal error if 'r' is NULL. If 'B' is not NULL, then it is a
118 // fatal error if 'd' is NULL or if 'K' and 'L' are both NULL.
119 // If 'M' is not NULL, then it is a fatal error if 'E' is NULL.
120 //
121 //  Return Type: TPM_RC
122 //      TPM_RC_NO_RESULT        if 'K', 'L' or 'E' was computed to be the point
123 //                              at infinity
124 //      TPM_RC_CANCELED         a cancel indication was asserted during this
125 //                              function
126 LIB_EXPORT TPM_RC
127 CryptEccCommitCompute(
128     TPMS_ECC_POINT          *K,             // OUT: [d]B or [r]Q
129     TPMS_ECC_POINT          *L,             // OUT: [r]B
130     TPMS_ECC_POINT          *E,             // OUT: [r]M
131     TPM_ECC_CURVE            curveId,       // IN: the curve for the computations
132     TPMS_ECC_POINT          *M,             // IN: M (optional)
133     TPMS_ECC_POINT          *B,             // IN: B (optional)
134     TPM2B_ECC_PARAMETER     *d,             // IN: d (optional)
135     TPM2B_ECC_PARAMETER     *r              // IN: the computed r value (required)
136 );
137 #endif  // ALG_ECC
138 
139 #endif  // _CRYPT_ECC_SIGNATURE_FP_H_
140