• 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: Apr  2, 2019  Time: 03:18:00PM
38  */
39 
40 #ifndef    _CRYPT_RSA_FP_H_
41 #define    _CRYPT_RSA_FP_H_
42 
43 #if ALG_RSA
44 
45 //*** CryptRsaInit()
46 // Function called at _TPM_Init().
47 BOOL
48 CryptRsaInit(
49     void
50 );
51 
52 //*** CryptRsaStartup()
53 // Function called at TPM2_Startup()
54 BOOL
55 CryptRsaStartup(
56     void
57 );
58 
59 //*** CryptRsaPssSaltSize()
60 // This function computes the salt size used in PSS. It is broken out so that
61 // the X509 code can get the same value that is used by the encoding function in this
62 // module.
63 INT16
64 CryptRsaPssSaltSize(
65     INT16              hashSize,
66     INT16               outSize
67 );
68 
69 //*** MakeDerTag()
70 // Construct the DER value that is used in RSASSA
71 //  Return Type: INT16
72 //   > 0        size of value
73 //   <= 0       no hash exists
74 INT16
75 MakeDerTag(
76     TPM_ALG_ID   hashAlg,
77     INT16        sizeOfBuffer,
78     BYTE        *buffer
79 );
80 
81 //*** CryptRsaSelectScheme()
82 // This function is used by TPM2_RSA_Decrypt and TPM2_RSA_Encrypt.  It sets up
83 // the rules to select a scheme between input and object default.
84 // This function assume the RSA object is loaded.
85 // If a default scheme is defined in object, the default scheme should be chosen,
86 // otherwise, the input scheme should be chosen.
87 // In the case that both the object and 'scheme' are not TPM_ALG_NULL, then
88 // if the schemes are the same, the input scheme will be chosen.
89 // if the scheme are not compatible, a NULL pointer will be returned.
90 //
91 // The return pointer may point to a TPM_ALG_NULL scheme.
92 TPMT_RSA_DECRYPT*
93 CryptRsaSelectScheme(
94     TPMI_DH_OBJECT       rsaHandle,     // IN: handle of an RSA key
95     TPMT_RSA_DECRYPT    *scheme         // IN: a sign or decrypt scheme
96 );
97 
98 //*** CryptRsaLoadPrivateExponent()
99 // This function is called to generate the private exponent of an RSA key.
100 //  Return Type: TPM_RC
101 //      TPM_RC_BINDING      public and private parts of 'rsaKey' are not matched
102 TPM_RC
103 CryptRsaLoadPrivateExponent(
104     TPMT_PUBLIC             *publicArea,
105     TPMT_SENSITIVE          *sensitive
106 );
107 
108 //*** CryptRsaEncrypt()
109 // This is the entry point for encryption using RSA. Encryption is
110 // use of the public exponent. The padding parameter determines what
111 // padding will be used.
112 //
113 // The 'cOutSize' parameter must be at least as large as the size of the key.
114 //
115 // If the padding is RSA_PAD_NONE, 'dIn' is treated as a number. It must be
116 // lower in value than the key modulus.
117 // NOTE: If dIn has fewer bytes than cOut, then we don't add low-order zeros to
118 //       dIn to make it the size of the RSA key for the call to RSAEP. This is
119 //       because the high order bytes of dIn might have a numeric value that is
120 //       greater than the value of the key modulus. If this had low-order zeros
121 //       added, it would have a numeric value larger than the modulus even though
122 //       it started out with a lower numeric value.
123 //
124 //  Return Type: TPM_RC
125 //      TPM_RC_VALUE     'cOutSize' is too small (must be the size
126 //                        of the modulus)
127 //      TPM_RC_SCHEME    'padType' is not a supported scheme
128 //
129 LIB_EXPORT TPM_RC
130 CryptRsaEncrypt(
131     TPM2B_PUBLIC_KEY_RSA        *cOut,          // OUT: the encrypted data
132     TPM2B                       *dIn,           // IN: the data to encrypt
133     OBJECT                      *key,           // IN: the key used for encryption
134     TPMT_RSA_DECRYPT            *scheme,        // IN: the type of padding and hash
135                                                 //     if needed
136     const TPM2B                 *label,         // IN: in case it is needed
137     RAND_STATE                  *rand           // IN: random number generator
138                                                 //     state (mostly for testing)
139 );
140 
141 //*** CryptRsaDecrypt()
142 // This is the entry point for decryption using RSA. Decryption is
143 // use of the private exponent. The 'padType' parameter determines what
144 // padding was used.
145 //
146 //  Return Type: TPM_RC
147 //      TPM_RC_SIZE        'cInSize' is not the same as the size of the public
148 //                          modulus of 'key'; or numeric value of the encrypted
149 //                          data is greater than the modulus
150 //      TPM_RC_VALUE       'dOutSize' is not large enough for the result
151 //      TPM_RC_SCHEME      'padType' is not supported
152 //
153 LIB_EXPORT TPM_RC
154 CryptRsaDecrypt(
155     TPM2B               *dOut,          // OUT: the decrypted data
156     TPM2B               *cIn,           // IN: the data to decrypt
157     OBJECT              *key,           // IN: the key to use for decryption
158     TPMT_RSA_DECRYPT    *scheme,        // IN: the padding scheme
159     const TPM2B         *label          // IN: in case it is needed for the scheme
160 );
161 
162 //*** CryptRsaSign()
163 // This function is used to generate an RSA signature of the type indicated in
164 // 'scheme'.
165 //
166 //  Return Type: TPM_RC
167 //      TPM_RC_SCHEME       'scheme' or 'hashAlg' are not supported
168 //      TPM_RC_VALUE        'hInSize' does not match 'hashAlg' (for RSASSA)
169 //
170 LIB_EXPORT TPM_RC
171 CryptRsaSign(
172     TPMT_SIGNATURE      *sigOut,
173     OBJECT              *key,           // IN: key to use
174     TPM2B_DIGEST        *hIn,           // IN: the digest to sign
175     RAND_STATE          *rand           // IN: the random number generator
176                                         //      to use (mostly for testing)
177 );
178 
179 //*** CryptRsaValidateSignature()
180 // This function is used to validate an RSA signature. If the signature is valid
181 // TPM_RC_SUCCESS is returned. If the signature is not valid, TPM_RC_SIGNATURE is
182 // returned. Other return codes indicate either parameter problems or fatal errors.
183 //
184 //  Return Type: TPM_RC
185 //      TPM_RC_SIGNATURE    the signature does not check
186 //      TPM_RC_SCHEME       unsupported scheme or hash algorithm
187 //
188 LIB_EXPORT TPM_RC
189 CryptRsaValidateSignature(
190     TPMT_SIGNATURE  *sig,           // IN: signature
191     OBJECT          *key,           // IN: public modulus
192     TPM2B_DIGEST    *digest         // IN: The digest being validated
193 );
194 
195 //*** CryptRsaGenerateKey()
196 // Generate an RSA key from a provided seed
197 //  Return Type: TPM_RC
198 //      TPM_RC_CANCELED     operation was canceled
199 //      TPM_RC_RANGE        public exponent is not supported
200 //      TPM_RC_VALUE        could not find a prime using the provided parameters
201 LIB_EXPORT TPM_RC
202 CryptRsaGenerateKey(
203     TPMT_PUBLIC         *publicArea,
204     TPMT_SENSITIVE      *sensitive,
205     RAND_STATE          *rand               // IN: if not NULL, the deterministic
206                                             //     RNG state
207 );
208 #endif // ALG_RSA
209 
210 #endif  // _CRYPT_RSA_FP_H_
211