xref: /aosp_15_r20/external/mbedtls/library/psa_crypto_rsa.h (revision 62c56f9862f102b96d72393aff6076c951fb8148)
1*62c56f98SSadaf Ebrahimi /*
2*62c56f98SSadaf Ebrahimi  *  PSA RSA layer on top of Mbed TLS crypto
3*62c56f98SSadaf Ebrahimi  */
4*62c56f98SSadaf Ebrahimi /*
5*62c56f98SSadaf Ebrahimi  *  Copyright The Mbed TLS Contributors
6*62c56f98SSadaf Ebrahimi  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
7*62c56f98SSadaf Ebrahimi  */
8*62c56f98SSadaf Ebrahimi 
9*62c56f98SSadaf Ebrahimi #ifndef PSA_CRYPTO_RSA_H
10*62c56f98SSadaf Ebrahimi #define PSA_CRYPTO_RSA_H
11*62c56f98SSadaf Ebrahimi 
12*62c56f98SSadaf Ebrahimi #include <psa/crypto.h>
13*62c56f98SSadaf Ebrahimi #include <mbedtls/rsa.h>
14*62c56f98SSadaf Ebrahimi 
15*62c56f98SSadaf Ebrahimi /** Load the contents of a key buffer into an internal RSA representation
16*62c56f98SSadaf Ebrahimi  *
17*62c56f98SSadaf Ebrahimi  * \param[in] type          The type of key contained in \p data.
18*62c56f98SSadaf Ebrahimi  * \param[in] data          The buffer from which to load the representation.
19*62c56f98SSadaf Ebrahimi  * \param[in] data_length   The size in bytes of \p data.
20*62c56f98SSadaf Ebrahimi  * \param[out] p_rsa        Returns a pointer to an RSA context on success.
21*62c56f98SSadaf Ebrahimi  *                          The caller is responsible for freeing both the
22*62c56f98SSadaf Ebrahimi  *                          contents of the context and the context itself
23*62c56f98SSadaf Ebrahimi  *                          when done.
24*62c56f98SSadaf Ebrahimi  */
25*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_load_representation(psa_key_type_t type,
26*62c56f98SSadaf Ebrahimi                                                  const uint8_t *data,
27*62c56f98SSadaf Ebrahimi                                                  size_t data_length,
28*62c56f98SSadaf Ebrahimi                                                  mbedtls_rsa_context **p_rsa);
29*62c56f98SSadaf Ebrahimi 
30*62c56f98SSadaf Ebrahimi /** Import an RSA key in binary format.
31*62c56f98SSadaf Ebrahimi  *
32*62c56f98SSadaf Ebrahimi  * \note The signature of this function is that of a PSA driver
33*62c56f98SSadaf Ebrahimi  *       import_key entry point. This function behaves as an import_key
34*62c56f98SSadaf Ebrahimi  *       entry point as defined in the PSA driver interface specification for
35*62c56f98SSadaf Ebrahimi  *       transparent drivers.
36*62c56f98SSadaf Ebrahimi  *
37*62c56f98SSadaf Ebrahimi  * \param[in]  attributes       The attributes for the key to import.
38*62c56f98SSadaf Ebrahimi  * \param[in]  data             The buffer containing the key data in import
39*62c56f98SSadaf Ebrahimi  *                              format.
40*62c56f98SSadaf Ebrahimi  * \param[in]  data_length      Size of the \p data buffer in bytes.
41*62c56f98SSadaf Ebrahimi  * \param[out] key_buffer       The buffer containing the key data in output
42*62c56f98SSadaf Ebrahimi  *                              format.
43*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer_size  Size of the \p key_buffer buffer in bytes. This
44*62c56f98SSadaf Ebrahimi  *                              size is greater or equal to \p data_length.
45*62c56f98SSadaf Ebrahimi  * \param[out] key_buffer_length  The length of the data written in \p
46*62c56f98SSadaf Ebrahimi  *                                key_buffer in bytes.
47*62c56f98SSadaf Ebrahimi  * \param[out] bits             The key size in number of bits.
48*62c56f98SSadaf Ebrahimi  *
49*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS  The RSA key was imported successfully.
50*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_ARGUMENT
51*62c56f98SSadaf Ebrahimi  *         The key data is not correctly formatted.
52*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
53*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
54*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
55*62c56f98SSadaf Ebrahimi  */
56*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_import_key(
57*62c56f98SSadaf Ebrahimi     const psa_key_attributes_t *attributes,
58*62c56f98SSadaf Ebrahimi     const uint8_t *data, size_t data_length,
59*62c56f98SSadaf Ebrahimi     uint8_t *key_buffer, size_t key_buffer_size,
60*62c56f98SSadaf Ebrahimi     size_t *key_buffer_length, size_t *bits);
61*62c56f98SSadaf Ebrahimi 
62*62c56f98SSadaf Ebrahimi /** Export an RSA key to export representation
63*62c56f98SSadaf Ebrahimi  *
64*62c56f98SSadaf Ebrahimi  * \param[in] type          The type of key (public/private) to export
65*62c56f98SSadaf Ebrahimi  * \param[in] rsa           The internal RSA representation from which to export
66*62c56f98SSadaf Ebrahimi  * \param[out] data         The buffer to export to
67*62c56f98SSadaf Ebrahimi  * \param[in] data_size     The length of the buffer to export to
68*62c56f98SSadaf Ebrahimi  * \param[out] data_length  The amount of bytes written to \p data
69*62c56f98SSadaf Ebrahimi  */
70*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_export_key(psa_key_type_t type,
71*62c56f98SSadaf Ebrahimi                                         mbedtls_rsa_context *rsa,
72*62c56f98SSadaf Ebrahimi                                         uint8_t *data,
73*62c56f98SSadaf Ebrahimi                                         size_t data_size,
74*62c56f98SSadaf Ebrahimi                                         size_t *data_length);
75*62c56f98SSadaf Ebrahimi 
76*62c56f98SSadaf Ebrahimi /** Export a public RSA key or the public part of an RSA key pair in binary
77*62c56f98SSadaf Ebrahimi  *  format.
78*62c56f98SSadaf Ebrahimi  *
79*62c56f98SSadaf Ebrahimi  * \note The signature of this function is that of a PSA driver
80*62c56f98SSadaf Ebrahimi  *       export_public_key entry point. This function behaves as an
81*62c56f98SSadaf Ebrahimi  *       export_public_key entry point as defined in the PSA driver interface
82*62c56f98SSadaf Ebrahimi  *       specification.
83*62c56f98SSadaf Ebrahimi  *
84*62c56f98SSadaf Ebrahimi  * \param[in]  attributes       The attributes for the key to export.
85*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer       Material or context of the key to export.
86*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer_size  Size of the \p key_buffer buffer in bytes.
87*62c56f98SSadaf Ebrahimi  * \param[out] data             Buffer where the key data is to be written.
88*62c56f98SSadaf Ebrahimi  * \param[in]  data_size        Size of the \p data buffer in bytes.
89*62c56f98SSadaf Ebrahimi  * \param[out] data_length      On success, the number of bytes written in
90*62c56f98SSadaf Ebrahimi  *                              \p data.
91*62c56f98SSadaf Ebrahimi  *
92*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS  The RSA public key was exported successfully.
93*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
94*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
95*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription
96*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
97*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_STORAGE_FAILURE \emptydescription
98*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
99*62c56f98SSadaf Ebrahimi  */
100*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_export_public_key(
101*62c56f98SSadaf Ebrahimi     const psa_key_attributes_t *attributes,
102*62c56f98SSadaf Ebrahimi     const uint8_t *key_buffer, size_t key_buffer_size,
103*62c56f98SSadaf Ebrahimi     uint8_t *data, size_t data_size, size_t *data_length);
104*62c56f98SSadaf Ebrahimi 
105*62c56f98SSadaf Ebrahimi /**
106*62c56f98SSadaf Ebrahimi  * \brief Generate an RSA key.
107*62c56f98SSadaf Ebrahimi  *
108*62c56f98SSadaf Ebrahimi  * \note The signature of the function is that of a PSA driver generate_key
109*62c56f98SSadaf Ebrahimi  *       entry point.
110*62c56f98SSadaf Ebrahimi  *
111*62c56f98SSadaf Ebrahimi  * \param[in]  attributes         The attributes for the RSA key to generate.
112*62c56f98SSadaf Ebrahimi  * \param[out] key_buffer         Buffer where the key data is to be written.
113*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer_size    Size of \p key_buffer in bytes.
114*62c56f98SSadaf Ebrahimi  * \param[out] key_buffer_length  On success, the number of bytes written in
115*62c56f98SSadaf Ebrahimi  *                                \p key_buffer.
116*62c56f98SSadaf Ebrahimi  *
117*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS
118*62c56f98SSadaf Ebrahimi  *         The key was successfully generated.
119*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED
120*62c56f98SSadaf Ebrahimi  *         Key length or type not supported.
121*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_BUFFER_TOO_SMALL
122*62c56f98SSadaf Ebrahimi  *         The size of \p key_buffer is too small.
123*62c56f98SSadaf Ebrahimi  */
124*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_generate_key(
125*62c56f98SSadaf Ebrahimi     const psa_key_attributes_t *attributes,
126*62c56f98SSadaf Ebrahimi     uint8_t *key_buffer, size_t key_buffer_size, size_t *key_buffer_length);
127*62c56f98SSadaf Ebrahimi 
128*62c56f98SSadaf Ebrahimi /** Sign an already-calculated hash with an RSA private key.
129*62c56f98SSadaf Ebrahimi  *
130*62c56f98SSadaf Ebrahimi  * \note The signature of this function is that of a PSA driver
131*62c56f98SSadaf Ebrahimi  *       sign_hash entry point. This function behaves as a sign_hash
132*62c56f98SSadaf Ebrahimi  *       entry point as defined in the PSA driver interface specification for
133*62c56f98SSadaf Ebrahimi  *       transparent drivers.
134*62c56f98SSadaf Ebrahimi  *
135*62c56f98SSadaf Ebrahimi  * \param[in]  attributes       The attributes of the RSA key to use for the
136*62c56f98SSadaf Ebrahimi  *                              operation.
137*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer       The buffer containing the RSA key context.
138*62c56f98SSadaf Ebrahimi  *                              format.
139*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer_size  Size of the \p key_buffer buffer in bytes.
140*62c56f98SSadaf Ebrahimi  * \param[in]  alg              A signature algorithm that is compatible with
141*62c56f98SSadaf Ebrahimi  *                              an RSA key.
142*62c56f98SSadaf Ebrahimi  * \param[in]  hash             The hash or message to sign.
143*62c56f98SSadaf Ebrahimi  * \param[in]  hash_length      Size of the \p hash buffer in bytes.
144*62c56f98SSadaf Ebrahimi  * \param[out] signature        Buffer where the signature is to be written.
145*62c56f98SSadaf Ebrahimi  * \param[in]  signature_size   Size of the \p signature buffer in bytes.
146*62c56f98SSadaf Ebrahimi  * \param[out] signature_length On success, the number of bytes
147*62c56f98SSadaf Ebrahimi  *                              that make up the returned signature value.
148*62c56f98SSadaf Ebrahimi  *
149*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS \emptydescription
150*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_BUFFER_TOO_SMALL
151*62c56f98SSadaf Ebrahimi  *         The size of the \p signature buffer is too small. You can
152*62c56f98SSadaf Ebrahimi  *         determine a sufficient buffer size by calling
153*62c56f98SSadaf Ebrahimi  *         #PSA_SIGN_OUTPUT_SIZE(\c PSA_KEY_TYPE_RSA_KEY_PAIR, \c key_bits,
154*62c56f98SSadaf Ebrahimi  *         \p alg) where \c key_bits is the bit-size of the RSA key.
155*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
156*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
157*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
158*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
159*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
160*62c56f98SSadaf Ebrahimi  */
161*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_sign_hash(
162*62c56f98SSadaf Ebrahimi     const psa_key_attributes_t *attributes,
163*62c56f98SSadaf Ebrahimi     const uint8_t *key_buffer, size_t key_buffer_size,
164*62c56f98SSadaf Ebrahimi     psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
165*62c56f98SSadaf Ebrahimi     uint8_t *signature, size_t signature_size, size_t *signature_length);
166*62c56f98SSadaf Ebrahimi 
167*62c56f98SSadaf Ebrahimi /**
168*62c56f98SSadaf Ebrahimi  * \brief Verify the signature a hash or short message using a public RSA key.
169*62c56f98SSadaf Ebrahimi  *
170*62c56f98SSadaf Ebrahimi  * \note The signature of this function is that of a PSA driver
171*62c56f98SSadaf Ebrahimi  *       verify_hash entry point. This function behaves as a verify_hash
172*62c56f98SSadaf Ebrahimi  *       entry point as defined in the PSA driver interface specification for
173*62c56f98SSadaf Ebrahimi  *       transparent drivers.
174*62c56f98SSadaf Ebrahimi  *
175*62c56f98SSadaf Ebrahimi  * \param[in]  attributes       The attributes of the RSA key to use for the
176*62c56f98SSadaf Ebrahimi  *                              operation.
177*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer       The buffer containing the RSA key context.
178*62c56f98SSadaf Ebrahimi  *                              format.
179*62c56f98SSadaf Ebrahimi  * \param[in]  key_buffer_size  Size of the \p key_buffer buffer in bytes.
180*62c56f98SSadaf Ebrahimi  * \param[in]  alg              A signature algorithm that is compatible with
181*62c56f98SSadaf Ebrahimi  *                              an RSA key.
182*62c56f98SSadaf Ebrahimi  * \param[in]  hash             The hash or message whose signature is to be
183*62c56f98SSadaf Ebrahimi  *                              verified.
184*62c56f98SSadaf Ebrahimi  * \param[in]  hash_length      Size of the \p hash buffer in bytes.
185*62c56f98SSadaf Ebrahimi  * \param[in]  signature        Buffer containing the signature to verify.
186*62c56f98SSadaf Ebrahimi  * \param[in]  signature_length Size of the \p signature buffer in bytes.
187*62c56f98SSadaf Ebrahimi  *
188*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS
189*62c56f98SSadaf Ebrahimi  *         The signature is valid.
190*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_SIGNATURE
191*62c56f98SSadaf Ebrahimi  *         The calculation was performed successfully, but the passed
192*62c56f98SSadaf Ebrahimi  *         signature is not a valid signature.
193*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
194*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
195*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
196*62c56f98SSadaf Ebrahimi  */
197*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_rsa_verify_hash(
198*62c56f98SSadaf Ebrahimi     const psa_key_attributes_t *attributes,
199*62c56f98SSadaf Ebrahimi     const uint8_t *key_buffer, size_t key_buffer_size,
200*62c56f98SSadaf Ebrahimi     psa_algorithm_t alg, const uint8_t *hash, size_t hash_length,
201*62c56f98SSadaf Ebrahimi     const uint8_t *signature, size_t signature_length);
202*62c56f98SSadaf Ebrahimi 
203*62c56f98SSadaf Ebrahimi /**
204*62c56f98SSadaf Ebrahimi  * \brief Encrypt a short message with a public key.
205*62c56f98SSadaf Ebrahimi  *
206*62c56f98SSadaf Ebrahimi  * \param attributes            The attributes for the key to import.
207*62c56f98SSadaf Ebrahimi  * \param key_buffer            Buffer where the key data is to be written.
208*62c56f98SSadaf Ebrahimi  * \param key_buffer_size       Size of the \p key_buffer buffer in bytes.
209*62c56f98SSadaf Ebrahimi  * \param input_length          Size of the \p input buffer in bytes.
210*62c56f98SSadaf Ebrahimi  * \param[in] salt              A salt or label, if supported by the
211*62c56f98SSadaf Ebrahimi  *                              encryption algorithm.
212*62c56f98SSadaf Ebrahimi  *                              If the algorithm does not support a
213*62c56f98SSadaf Ebrahimi  *                              salt, pass \c NULL.
214*62c56f98SSadaf Ebrahimi  *                              If the algorithm supports an optional
215*62c56f98SSadaf Ebrahimi  *                              salt and you do not want to pass a salt,
216*62c56f98SSadaf Ebrahimi  *                              pass \c NULL.
217*62c56f98SSadaf Ebrahimi  *
218*62c56f98SSadaf Ebrahimi  *                              - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
219*62c56f98SSadaf Ebrahimi  *                                supported.
220*62c56f98SSadaf Ebrahimi  * \param salt_length           Size of the \p salt buffer in bytes.
221*62c56f98SSadaf Ebrahimi  *                              If \p salt is \c NULL, pass 0.
222*62c56f98SSadaf Ebrahimi  * \param[out] output           Buffer where the encrypted message is to
223*62c56f98SSadaf Ebrahimi  *                              be written.
224*62c56f98SSadaf Ebrahimi  * \param output_size           Size of the \p output buffer in bytes.
225*62c56f98SSadaf Ebrahimi  * \param[out] output_length    On success, the number of bytes
226*62c56f98SSadaf Ebrahimi  *                              that make up the returned output.
227*62c56f98SSadaf Ebrahimi  *
228*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS \emptydescription
229*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_BUFFER_TOO_SMALL
230*62c56f98SSadaf Ebrahimi  *         The size of the \p output buffer is too small. You can
231*62c56f98SSadaf Ebrahimi  *         determine a sufficient buffer size by calling
232*62c56f98SSadaf Ebrahimi  *         #PSA_ASYMMETRIC_ENCRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
233*62c56f98SSadaf Ebrahimi  *         where \c key_type and \c key_bits are the type and bit-size
234*62c56f98SSadaf Ebrahimi  *         respectively of \p key.
235*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
236*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
237*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
238*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
239*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription
240*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
241*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
242*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_BAD_STATE
243*62c56f98SSadaf Ebrahimi  *         The library has not been previously initialized by psa_crypto_init().
244*62c56f98SSadaf Ebrahimi  *         It is implementation-dependent whether a failure to initialize
245*62c56f98SSadaf Ebrahimi  *         results in this error code.
246*62c56f98SSadaf Ebrahimi  */
247*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_asymmetric_encrypt(const psa_key_attributes_t *attributes,
248*62c56f98SSadaf Ebrahimi                                             const uint8_t *key_buffer,
249*62c56f98SSadaf Ebrahimi                                             size_t key_buffer_size,
250*62c56f98SSadaf Ebrahimi                                             psa_algorithm_t alg,
251*62c56f98SSadaf Ebrahimi                                             const uint8_t *input,
252*62c56f98SSadaf Ebrahimi                                             size_t input_length,
253*62c56f98SSadaf Ebrahimi                                             const uint8_t *salt,
254*62c56f98SSadaf Ebrahimi                                             size_t salt_length,
255*62c56f98SSadaf Ebrahimi                                             uint8_t *output,
256*62c56f98SSadaf Ebrahimi                                             size_t output_size,
257*62c56f98SSadaf Ebrahimi                                             size_t *output_length);
258*62c56f98SSadaf Ebrahimi 
259*62c56f98SSadaf Ebrahimi /**
260*62c56f98SSadaf Ebrahimi  * \brief Decrypt a short message with a private key.
261*62c56f98SSadaf Ebrahimi  *
262*62c56f98SSadaf Ebrahimi  * \param attributes            The attributes for the key to import.
263*62c56f98SSadaf Ebrahimi  * \param key_buffer            Buffer where the key data is to be written.
264*62c56f98SSadaf Ebrahimi  * \param key_buffer_size       Size of the \p key_buffer buffer in bytes.
265*62c56f98SSadaf Ebrahimi  * \param[in] input             The message to decrypt.
266*62c56f98SSadaf Ebrahimi  * \param input_length          Size of the \p input buffer in bytes.
267*62c56f98SSadaf Ebrahimi  * \param[in] salt              A salt or label, if supported by the
268*62c56f98SSadaf Ebrahimi  *                              encryption algorithm.
269*62c56f98SSadaf Ebrahimi  *                              If the algorithm does not support a
270*62c56f98SSadaf Ebrahimi  *                              salt, pass \c NULL.
271*62c56f98SSadaf Ebrahimi  *                              If the algorithm supports an optional
272*62c56f98SSadaf Ebrahimi  *                              salt and you do not want to pass a salt,
273*62c56f98SSadaf Ebrahimi  *                              pass \c NULL.
274*62c56f98SSadaf Ebrahimi  *
275*62c56f98SSadaf Ebrahimi  *                              - For #PSA_ALG_RSA_PKCS1V15_CRYPT, no salt is
276*62c56f98SSadaf Ebrahimi  *                                supported.
277*62c56f98SSadaf Ebrahimi  * \param salt_length           Size of the \p salt buffer in bytes.
278*62c56f98SSadaf Ebrahimi  *                              If \p salt is \c NULL, pass 0.
279*62c56f98SSadaf Ebrahimi  * \param[out] output           Buffer where the decrypted message is to
280*62c56f98SSadaf Ebrahimi  *                              be written.
281*62c56f98SSadaf Ebrahimi  * \param output_size           Size of the \c output buffer in bytes.
282*62c56f98SSadaf Ebrahimi  * \param[out] output_length    On success, the number of bytes
283*62c56f98SSadaf Ebrahimi  *                              that make up the returned output.
284*62c56f98SSadaf Ebrahimi  *
285*62c56f98SSadaf Ebrahimi  * \retval #PSA_SUCCESS \emptydescription
286*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_BUFFER_TOO_SMALL
287*62c56f98SSadaf Ebrahimi  *         The size of the \p output buffer is too small. You can
288*62c56f98SSadaf Ebrahimi  *         determine a sufficient buffer size by calling
289*62c56f98SSadaf Ebrahimi  *         #PSA_ASYMMETRIC_DECRYPT_OUTPUT_SIZE(\c key_type, \c key_bits, \p alg)
290*62c56f98SSadaf Ebrahimi  *         where \c key_type and \c key_bits are the type and bit-size
291*62c56f98SSadaf Ebrahimi  *         respectively of \p key.
292*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_NOT_SUPPORTED \emptydescription
293*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_ARGUMENT \emptydescription
294*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_MEMORY \emptydescription
295*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_COMMUNICATION_FAILURE \emptydescription
296*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_HARDWARE_FAILURE \emptydescription
297*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_CORRUPTION_DETECTED \emptydescription
298*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INSUFFICIENT_ENTROPY \emptydescription
299*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_INVALID_PADDING \emptydescription
300*62c56f98SSadaf Ebrahimi  * \retval #PSA_ERROR_BAD_STATE
301*62c56f98SSadaf Ebrahimi  *         The library has not been previously initialized by psa_crypto_init().
302*62c56f98SSadaf Ebrahimi  *         It is implementation-dependent whether a failure to initialize
303*62c56f98SSadaf Ebrahimi  *         results in this error code.
304*62c56f98SSadaf Ebrahimi  */
305*62c56f98SSadaf Ebrahimi psa_status_t mbedtls_psa_asymmetric_decrypt(const psa_key_attributes_t *attributes,
306*62c56f98SSadaf Ebrahimi                                             const uint8_t *key_buffer,
307*62c56f98SSadaf Ebrahimi                                             size_t key_buffer_size,
308*62c56f98SSadaf Ebrahimi                                             psa_algorithm_t alg,
309*62c56f98SSadaf Ebrahimi                                             const uint8_t *input,
310*62c56f98SSadaf Ebrahimi                                             size_t input_length,
311*62c56f98SSadaf Ebrahimi                                             const uint8_t *salt,
312*62c56f98SSadaf Ebrahimi                                             size_t salt_length,
313*62c56f98SSadaf Ebrahimi                                             uint8_t *output,
314*62c56f98SSadaf Ebrahimi                                             size_t output_size,
315*62c56f98SSadaf Ebrahimi                                             size_t *output_length);
316*62c56f98SSadaf Ebrahimi 
317*62c56f98SSadaf Ebrahimi #endif /* PSA_CRYPTO_RSA_H */
318