blob: 276293c51588788bcb531ba0ee65c619a4484e47 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/**
2 * \file rsa.h
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00003 *
Rose Zadik21e29262018-04-17 14:08:56 +01004 * \brief This file provides an API for the RSA public-key cryptosystem.
Paul Bakker37ca75d2011-01-06 12:28:03 +00005 *
Rose Zadike8b5b992018-03-27 12:19:47 +01006 * The RSA public-key cryptosystem is defined in <em>Public-Key
7 * Cryptography Standards (PKCS) #1 v1.5: RSA Encryption</em>
Darryl Green11999bb2018-03-13 15:22:58 +00008 * and <em>Public-Key Cryptography Standards (PKCS) #1 v2.1:
Rose Zadike8b5b992018-03-27 12:19:47 +01009 * RSA Cryptography Specifications</em>.
Rose Zadik042e97f2018-01-26 16:35:10 +000010 *
Darryl Greena40a1012018-01-05 15:33:17 +000011 */
12/*
Rose Zadik042e97f2018-01-26 16:35:10 +000013 * Copyright (C) 2006-2018, Arm Limited (or its affiliates), All Rights Reserved
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +020014 * SPDX-License-Identifier: Apache-2.0
15 *
16 * Licensed under the Apache License, Version 2.0 (the "License"); you may
17 * not use this file except in compliance with the License.
18 * You may obtain a copy of the License at
19 *
20 * http://www.apache.org/licenses/LICENSE-2.0
21 *
22 * Unless required by applicable law or agreed to in writing, software
23 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25 * See the License for the specific language governing permissions and
26 * limitations under the License.
Paul Bakkerb96f1542010-07-18 20:36:00 +000027 *
Rose Zadik042e97f2018-01-26 16:35:10 +000028 * This file is part of Mbed TLS (https://tls.mbed.org)
Paul Bakker5121ce52009-01-03 21:22:43 +000029 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#ifndef MBEDTLS_RSA_H
31#define MBEDTLS_RSA_H
Paul Bakker5121ce52009-01-03 21:22:43 +000032
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020033#if !defined(MBEDTLS_CONFIG_FILE)
Paul Bakkered27a042013-04-18 22:46:23 +020034#include "config.h"
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020035#else
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020036#include MBEDTLS_CONFIG_FILE
Manuel Pégourié-Gonnardcef4ad22014-04-29 12:39:06 +020037#endif
Paul Bakkered27a042013-04-18 22:46:23 +020038
Paul Bakker314052f2011-08-15 09:07:52 +000039#include "bignum.h"
Paul Bakkerc70b9822013-04-07 22:00:46 +020040#include "md.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000041
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020042#if defined(MBEDTLS_THREADING_C)
Paul Bakkerc9965dc2013-09-29 14:58:17 +020043#include "threading.h"
44#endif
45
Paul Bakker13e2dfe2009-07-28 07:18:38 +000046/*
47 * RSA Error codes
48 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020049#define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
50#define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
51#define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
Rose Zadik042e97f2018-01-26 16:35:10 +000052#define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the validity check of the library. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020053#define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
54#define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
55#define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
56#define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */
57#define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030058
59/* MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION is deprecated and should not be used.
60 */
Rose Zadik042e97f2018-01-26 16:35:10 +000061#define MBEDTLS_ERR_RSA_UNSUPPORTED_OPERATION -0x4500 /**< The implementation does not offer the requested operation, for example, because of security violations or lack of functionality. */
Ron Eldor9924bdc2018-10-04 10:59:13 +030062
63/* MBEDTLS_ERR_RSA_HW_ACCEL_FAILED is deprecated and should not be used. */
Gilles Peskine7ecab3d2018-01-26 17:56:38 +010064#define MBEDTLS_ERR_RSA_HW_ACCEL_FAILED -0x4580 /**< RSA hardware accelerator failed. */
Paul Bakker5121ce52009-01-03 21:22:43 +000065
66/*
Paul Bakkerc70b9822013-04-07 22:00:46 +020067 * RSA constants
Paul Bakker5121ce52009-01-03 21:22:43 +000068 */
Rose Zadik042e97f2018-01-26 16:35:10 +000069#define MBEDTLS_RSA_PUBLIC 0 /**< Request private key operation. */
70#define MBEDTLS_RSA_PRIVATE 1 /**< Request public key operation. */
Paul Bakker5121ce52009-01-03 21:22:43 +000071
Rose Zadike8b5b992018-03-27 12:19:47 +010072#define MBEDTLS_RSA_PKCS_V15 0 /**< Use PKCS#1 v1.5 encoding. */
73#define MBEDTLS_RSA_PKCS_V21 1 /**< Use PKCS#1 v2.1 encoding. */
Paul Bakker5121ce52009-01-03 21:22:43 +000074
Rose Zadik042e97f2018-01-26 16:35:10 +000075#define MBEDTLS_RSA_SIGN 1 /**< Identifier for RSA signature operations. */
76#define MBEDTLS_RSA_CRYPT 2 /**< Identifier for RSA encryption and decryption operations. */
Paul Bakker5121ce52009-01-03 21:22:43 +000077
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020078#define MBEDTLS_RSA_SALT_LEN_ANY -1
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +020079
Manuel Pégourié-Gonnarde511ffc2013-08-22 17:33:21 +020080/*
81 * The above constants may be used even if the RSA module is compile out,
82 * eg for alternative (PKCS#11) RSA implemenations in the PK layers.
83 */
Hanno Beckerd22b78b2017-10-12 11:42:17 +010084
Paul Bakker407a0da2013-06-27 14:29:21 +020085#ifdef __cplusplus
86extern "C" {
87#endif
88
Ron Eldor4e6d55d2018-02-07 16:36:15 +020089#if !defined(MBEDTLS_RSA_ALT)
90// Regular implementation
91//
92
Paul Bakker5121ce52009-01-03 21:22:43 +000093/**
Rose Zadik042e97f2018-01-26 16:35:10 +000094 * \brief The RSA context structure.
Hanno Becker5063cd22017-09-29 11:49:12 +010095 *
96 * \note Direct manipulation of the members of this structure
Rose Zadik042e97f2018-01-26 16:35:10 +000097 * is deprecated. All manipulation should instead be done through
98 * the public interface functions.
Paul Bakker5121ce52009-01-03 21:22:43 +000099 */
Dawid Drozd428cc522018-07-24 10:02:47 +0200100typedef struct mbedtls_rsa_context
Paul Bakker5121ce52009-01-03 21:22:43 +0000101{
Rose Zadik042e97f2018-01-26 16:35:10 +0000102 int ver; /*!< Always 0.*/
103 size_t len; /*!< The size of \p N in Bytes. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000104
Rose Zadike8b5b992018-03-27 12:19:47 +0100105 mbedtls_mpi N; /*!< The public modulus. */
106 mbedtls_mpi E; /*!< The public exponent. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000107
Rose Zadike8b5b992018-03-27 12:19:47 +0100108 mbedtls_mpi D; /*!< The private exponent. */
109 mbedtls_mpi P; /*!< The first prime factor. */
110 mbedtls_mpi Q; /*!< The second prime factor. */
Hanno Becker1a59e792017-08-23 07:41:10 +0100111
Rose Zadikf2ec2882018-04-17 10:27:25 +0100112 mbedtls_mpi DP; /*!< <code>D % (P - 1)</code>. */
113 mbedtls_mpi DQ; /*!< <code>D % (Q - 1)</code>. */
114 mbedtls_mpi QP; /*!< <code>1 / (Q % P)</code>. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000115
Rose Zadikf2ec2882018-04-17 10:27:25 +0100116 mbedtls_mpi RN; /*!< cached <code>R^2 mod N</code>. */
Paul Bakker5121ce52009-01-03 21:22:43 +0000117
Rose Zadikf2ec2882018-04-17 10:27:25 +0100118 mbedtls_mpi RP; /*!< cached <code>R^2 mod P</code>. */
119 mbedtls_mpi RQ; /*!< cached <code>R^2 mod Q</code>. */
Manuel Pégourié-Gonnardea53a552013-09-10 13:29:30 +0200120
Rose Zadike8b5b992018-03-27 12:19:47 +0100121 mbedtls_mpi Vi; /*!< The cached blinding value. */
122 mbedtls_mpi Vf; /*!< The cached un-blinding value. */
Paul Bakker9dcc3222011-03-08 14:16:06 +0000123
Rose Zadik042e97f2018-01-26 16:35:10 +0000124 int padding; /*!< Selects padding mode:
125 #MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
126 #MBEDTLS_RSA_PKCS_V21 for OAEP or PSS. */
127 int hash_id; /*!< Hash identifier of mbedtls_md_type_t type,
128 as specified in md.h for use in the MGF
129 mask generating function used in the
130 EME-OAEP and EMSA-PSS encodings. */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200131#if defined(MBEDTLS_THREADING_C)
Rose Zadik042e97f2018-01-26 16:35:10 +0000132 mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex. */
Paul Bakkerc9965dc2013-09-29 14:58:17 +0200133#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000134}
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200135mbedtls_rsa_context;
Paul Bakker5121ce52009-01-03 21:22:43 +0000136
Ron Eldor4e6d55d2018-02-07 16:36:15 +0200137#else /* MBEDTLS_RSA_ALT */
138#include "rsa_alt.h"
139#endif /* MBEDTLS_RSA_ALT */
140
Paul Bakker5121ce52009-01-03 21:22:43 +0000141/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000142 * \brief This function initializes an RSA context.
Paul Bakker5121ce52009-01-03 21:22:43 +0000143 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000144 * \note Set padding to #MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
Paul Bakker9a736322012-11-14 12:39:52 +0000145 * encryption scheme and the RSASSA-PSS signature scheme.
146 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000147 * \note The \p hash_id parameter is ignored when using
148 * #MBEDTLS_RSA_PKCS_V15 padding.
Manuel Pégourié-Gonnarde6d1d822014-06-02 16:47:02 +0200149 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000150 * \note The choice of padding mode is strictly enforced for private key
Manuel Pégourié-Gonnarde6d1d822014-06-02 16:47:02 +0200151 * operations, since there might be security concerns in
Rose Zadik042e97f2018-01-26 16:35:10 +0000152 * mixing padding modes. For public key operations it is
Manuel Pégourié-Gonnarde6d1d822014-06-02 16:47:02 +0200153 * a default value, which can be overriden by calling specific
Rose Zadik042e97f2018-01-26 16:35:10 +0000154 * \c rsa_rsaes_xxx or \c rsa_rsassa_xxx functions.
Manuel Pégourié-Gonnarde6d1d822014-06-02 16:47:02 +0200155 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000156 * \note The hash selected in \p hash_id is always used for OEAP
157 * encryption. For PSS signatures, it is always used for
158 * making signatures, but can be overriden for verifying them.
159 * If set to #MBEDTLS_MD_NONE, it is always overriden.
Rose Zadike8b5b992018-03-27 12:19:47 +0100160 *
Hanno Becker9a467772018-12-13 09:54:59 +0000161 * \param ctx The RSA context to initialize. This must not be \c NULL.
162 * \param padding The padding mode to use. This must be either
163 * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
Hanno Becker385ce912018-12-13 18:33:12 +0000164 * \param hash_id The hash identifier of ::mbedtls_md_type_t type, if
Hanno Becker9a467772018-12-13 09:54:59 +0000165 * \p padding is #MBEDTLS_RSA_PKCS_V21. It is unused
166 * otherwise.
Paul Bakker5121ce52009-01-03 21:22:43 +0000167 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200168void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
Hanno Becker8fd55482017-08-23 14:07:48 +0100169 int padding,
Hanno Becker9a467772018-12-13 09:54:59 +0000170 int hash_id );
Paul Bakker5121ce52009-01-03 21:22:43 +0000171
172/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000173 * \brief This function imports a set of core parameters into an
174 * RSA context.
Manuel Pégourié-Gonnard844a4c02014-03-10 21:55:35 +0100175 *
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100176 * \note This function can be called multiple times for successive
Rose Zadik042e97f2018-01-26 16:35:10 +0000177 * imports, if the parameters are not simultaneously present.
178 *
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100179 * Any sequence of calls to this function should be followed
Rose Zadik042e97f2018-01-26 16:35:10 +0000180 * by a call to mbedtls_rsa_complete(), which checks and
181 * completes the provided information to a ready-for-use
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100182 * public or private RSA key.
183 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000184 * \note See mbedtls_rsa_complete() for more information on which
185 * parameters are necessary to set up a private or public
186 * RSA key.
Hanno Becker33195552017-10-25 17:04:10 +0100187 *
Hanno Becker5178dca2017-10-03 14:29:37 +0100188 * \note The imported parameters are copied and need not be preserved
189 * for the lifetime of the RSA context being set up.
190 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100191 * \param ctx The initialized RSA context to store the parameters in.
Hanno Becker9a467772018-12-13 09:54:59 +0000192 * \param N The RSA modulus. This may be \c NULL.
193 * \param P The first prime factor of \p N. This may be \c NULL.
194 * \param Q The second prime factor of \p N. This may be \c NULL.
195 * \param D The private exponent. This may be \c NULL.
196 * \param E The public exponent. This may be \c NULL.
Rose Zadike8b5b992018-03-27 12:19:47 +0100197 *
198 * \return \c 0 on success.
199 * \return A non-zero error code on failure.
Manuel Pégourié-Gonnard844a4c02014-03-10 21:55:35 +0100200 */
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100201int mbedtls_rsa_import( mbedtls_rsa_context *ctx,
202 const mbedtls_mpi *N,
203 const mbedtls_mpi *P, const mbedtls_mpi *Q,
204 const mbedtls_mpi *D, const mbedtls_mpi *E );
Manuel Pégourié-Gonnard844a4c02014-03-10 21:55:35 +0100205
206/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000207 * \brief This function imports core RSA parameters, in raw big-endian
208 * binary format, into an RSA context.
Paul Bakker5121ce52009-01-03 21:22:43 +0000209 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100210 * \note This function can be called multiple times for successive
211 * imports, if the parameters are not simultaneously present.
212 *
213 * Any sequence of calls to this function should be followed
214 * by a call to mbedtls_rsa_complete(), which checks and
215 * completes the provided information to a ready-for-use
216 * public or private RSA key.
217 *
218 * \note See mbedtls_rsa_complete() for more information on which
219 * parameters are necessary to set up a private or public
220 * RSA key.
221 *
222 * \note The imported parameters are copied and need not be preserved
223 * for the lifetime of the RSA context being set up.
224 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000225 * \param ctx The initialized RSA context to store the parameters in.
Hanno Becker9a467772018-12-13 09:54:59 +0000226 * \param N The RSA modulus. This may be \c NULL.
227 * \param N_len The Byte length of \p N; it is ignored if \p N == NULL.
228 * \param P The first prime factor of \p N. This may be \c NULL.
229 * \param P_len The Byte length of \p P; it ns ignored if \p P == NULL.
230 * \param Q The second prime factor of \p N. This may be \c NULL.
231 * \param Q_len The Byte length of \p Q; it is ignored if \p Q == NULL.
232 * \param D The private exponent. This may be \c NULL.
233 * \param D_len The Byte length of \p D; it is ignored if \p D == NULL.
234 * \param E The public exponent. This may be \c NULL.
235 * \param E_len The Byte length of \p E; it is ignored if \p E == NULL.
Paul Bakker5121ce52009-01-03 21:22:43 +0000236 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100237 * \return \c 0 on success.
238 * \return A non-zero error code on failure.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100239 */
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100240int mbedtls_rsa_import_raw( mbedtls_rsa_context *ctx,
Hanno Becker74716312017-10-02 10:00:37 +0100241 unsigned char const *N, size_t N_len,
242 unsigned char const *P, size_t P_len,
243 unsigned char const *Q, size_t Q_len,
244 unsigned char const *D, size_t D_len,
245 unsigned char const *E, size_t E_len );
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100246
247/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000248 * \brief This function completes an RSA context from
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100249 * a set of imported core parameters.
250 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000251 * To setup an RSA public key, precisely \p N and \p E
252 * must have been imported.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100253 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000254 * To setup an RSA private key, sufficient information must
255 * be present for the other parameters to be derivable.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100256 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000257 * The default implementation supports the following:
258 * <ul><li>Derive \p P, \p Q from \p N, \p D, \p E.</li>
259 * <li>Derive \p N, \p D from \p P, \p Q, \p E.</li></ul>
260 * Alternative implementations need not support these.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100261 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000262 * If this function runs successfully, it guarantees that
263 * the RSA context can be used for RSA operations without
264 * the risk of failure or crash.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100265 *
Hanno Becker1e801f52017-10-10 16:44:47 +0100266 * \warning This function need not perform consistency checks
Rose Zadik042e97f2018-01-26 16:35:10 +0000267 * for the imported parameters. In particular, parameters that
268 * are not needed by the implementation might be silently
269 * discarded and left unchecked. To check the consistency
270 * of the key material, see mbedtls_rsa_check_privkey().
Hanno Becker43a08d02017-10-02 13:16:35 +0100271 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100272 * \param ctx The initialized RSA context holding imported parameters.
273 *
274 * \return \c 0 on success.
275 * \return #MBEDTLS_ERR_RSA_BAD_INPUT_DATA if the attempted derivations
276 * failed.
277 *
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100278 */
Hanno Beckerf9e184b2017-10-10 16:49:26 +0100279int mbedtls_rsa_complete( mbedtls_rsa_context *ctx );
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100280
281/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000282 * \brief This function exports the core parameters of an RSA key.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100283 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000284 * If this function runs successfully, the non-NULL buffers
285 * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
286 * written, with additional unused space filled leading by
287 * zero Bytes.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100288 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000289 * Possible reasons for returning
Ron Eldor9924bdc2018-10-04 10:59:13 +0300290 * #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:<ul>
Rose Zadik042e97f2018-01-26 16:35:10 +0000291 * <li>An alternative RSA implementation is in use, which
292 * stores the key externally, and either cannot or should
293 * not export it into RAM.</li>
294 * <li>A SW or HW implementation might not support a certain
295 * deduction. For example, \p P, \p Q from \p N, \p D,
296 * and \p E if the former are not part of the
297 * implementation.</li></ul>
Hanno Becker91c194d2017-09-29 12:50:12 +0100298 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000299 * If the function fails due to an unsupported operation,
300 * the RSA context stays intact and remains usable.
301 *
302 * \param ctx The initialized RSA context.
Hanno Becker9a467772018-12-13 09:54:59 +0000303 * \param N The MPI to hold the RSA modulus.
304 * This may be \c NULL if this field need not be exported.
305 * \param P The MPI to hold the first prime factor of \p N.
306 * This may be \c NULL if this field need not be exported.
307 * \param Q The MPI to hold the second prime factor of \p N.
308 * This may be \c NULL if this field need not be exported.
309 * \param D The MPI to hold the private exponent.
310 * This may be \c NULL if this field need not be exported.
311 * \param E The MPI to hold the public exponent.
312 * This may be \c NULL if this field need not be exported.
Rose Zadik042e97f2018-01-26 16:35:10 +0000313 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100314 * \return \c 0 on success.
Ron Eldor9924bdc2018-10-04 10:59:13 +0300315 * \return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the
Rose Zadik042e97f2018-01-26 16:35:10 +0000316 * requested parameters cannot be done due to missing
Rose Zadike8b5b992018-03-27 12:19:47 +0100317 * functionality or because of security policies.
318 * \return A non-zero return code on any other failure.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100319 *
320 */
321int mbedtls_rsa_export( const mbedtls_rsa_context *ctx,
322 mbedtls_mpi *N, mbedtls_mpi *P, mbedtls_mpi *Q,
323 mbedtls_mpi *D, mbedtls_mpi *E );
324
325/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000326 * \brief This function exports core parameters of an RSA key
327 * in raw big-endian binary format.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100328 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000329 * If this function runs successfully, the non-NULL buffers
330 * pointed to by \p N, \p P, \p Q, \p D, and \p E are fully
331 * written, with additional unused space filled leading by
332 * zero Bytes.
333 *
334 * Possible reasons for returning
Ron Eldor9924bdc2018-10-04 10:59:13 +0300335 * #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED:<ul>
Rose Zadik042e97f2018-01-26 16:35:10 +0000336 * <li>An alternative RSA implementation is in use, which
337 * stores the key externally, and either cannot or should
338 * not export it into RAM.</li>
339 * <li>A SW or HW implementation might not support a certain
340 * deduction. For example, \p P, \p Q from \p N, \p D,
341 * and \p E if the former are not part of the
342 * implementation.</li></ul>
343 * If the function fails due to an unsupported operation,
344 * the RSA context stays intact and remains usable.
345 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100346 * \note The length parameters are ignored if the corresponding
Rose Zadike8b5b992018-03-27 12:19:47 +0100347 * buffer pointers are NULL.
348 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000349 * \param ctx The initialized RSA context.
Hanno Becker9a467772018-12-13 09:54:59 +0000350 * \param N The Byte array to store the RSA modulus,
351 * or \c NULL if this field need not be exported.
Rose Zadik042e97f2018-01-26 16:35:10 +0000352 * \param N_len The size of the buffer for the modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000353 * \param P The Byte array to hold the first prime factor of \p N,
354 * or \c NULL if this field need not be exported.
Rose Zadik042e97f2018-01-26 16:35:10 +0000355 * \param P_len The size of the buffer for the first prime factor.
Hanno Becker9a467772018-12-13 09:54:59 +0000356 * \param Q The Byte array to hold the second prime factor of \p N,
357 * or \c NULL if this field need not be exported.
Rose Zadik042e97f2018-01-26 16:35:10 +0000358 * \param Q_len The size of the buffer for the second prime factor.
Hanno Becker9a467772018-12-13 09:54:59 +0000359 * \param D The Byte array to hold the private exponent,
360 * or \c NULL if this field need not be exported.
Rose Zadik042e97f2018-01-26 16:35:10 +0000361 * \param D_len The size of the buffer for the private exponent.
Hanno Becker9a467772018-12-13 09:54:59 +0000362 * \param E The Byte array to hold the public exponent,
363 * or \c NULL if this field need not be exported.
Rose Zadik042e97f2018-01-26 16:35:10 +0000364 * \param E_len The size of the buffer for the public exponent.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100365 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100366 * \return \c 0 on success.
Ron Eldor9924bdc2018-10-04 10:59:13 +0300367 * \return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED if exporting the
Rose Zadik042e97f2018-01-26 16:35:10 +0000368 * requested parameters cannot be done due to missing
Rose Zadike8b5b992018-03-27 12:19:47 +0100369 * functionality or because of security policies.
370 * \return A non-zero return code on any other failure.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100371 */
372int mbedtls_rsa_export_raw( const mbedtls_rsa_context *ctx,
373 unsigned char *N, size_t N_len,
374 unsigned char *P, size_t P_len,
375 unsigned char *Q, size_t Q_len,
376 unsigned char *D, size_t D_len,
377 unsigned char *E, size_t E_len );
378
379/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000380 * \brief This function exports CRT parameters of a private RSA key.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100381 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100382 * \note Alternative RSA implementations not using CRT-parameters
383 * internally can implement this function based on
384 * mbedtls_rsa_deduce_opt().
385 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000386 * \param ctx The initialized RSA context.
Hanno Becker9a467772018-12-13 09:54:59 +0000387 * \param DP The MPI to hold \c D modulo `P-1`,
388 * or \c NULL if it need not be exported.
389 * \param DQ The MPI to hold \c D modulo `Q-1`,
390 * or \c NULL if it need not be exported.
391 * \param QP The MPI to hold modular inverse of \c Q modulo \c P,
392 * or \c NULL if it need not be exported.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100393 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100394 * \return \c 0 on success.
395 * \return A non-zero error code on failure.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100396 *
397 */
398int mbedtls_rsa_export_crt( const mbedtls_rsa_context *ctx,
399 mbedtls_mpi *DP, mbedtls_mpi *DQ, mbedtls_mpi *QP );
400
Paul Bakker5121ce52009-01-03 21:22:43 +0000401/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000402 * \brief This function sets padding for an already initialized RSA
403 * context. See mbedtls_rsa_init() for details.
Paul Bakker5121ce52009-01-03 21:22:43 +0000404 *
Hanno Becker9a467772018-12-13 09:54:59 +0000405 * \param ctx The initialized RSA context to be configured.
406 * \param padding The padding mode to use. This must be either
407 * #MBEDTLS_RSA_PKCS_V15 or #MBEDTLS_RSA_PKCS_V21.
Rose Zadik042e97f2018-01-26 16:35:10 +0000408 * \param hash_id The #MBEDTLS_RSA_PKCS_V21 hash identifier.
Paul Bakker40e46942009-01-03 21:51:57 +0000409 */
Hanno Becker8fd55482017-08-23 14:07:48 +0100410void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding,
Hanno Becker9a467772018-12-13 09:54:59 +0000411 int hash_id );
Paul Bakker21eb2802010-08-16 11:10:02 +0000412
Paul Bakkera3d195c2011-11-27 21:07:34 +0000413/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000414 * \brief This function retrieves the length of RSA modulus in Bytes.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100415 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000416 * \param ctx The initialized RSA context.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100417 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000418 * \return The length of the RSA modulus in Bytes.
Hanno Beckercbb59bc2017-08-23 14:11:08 +0100419 *
420 */
421size_t mbedtls_rsa_get_len( const mbedtls_rsa_context *ctx );
422
423/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000424 * \brief This function generates an RSA keypair.
Paul Bakker5121ce52009-01-03 21:22:43 +0000425 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000426 * \note mbedtls_rsa_init() must be called before this function,
427 * to set up the RSA context.
Paul Bakker5121ce52009-01-03 21:22:43 +0000428 *
Hanno Becker9a467772018-12-13 09:54:59 +0000429 * \param ctx The initialized RSA context used to hold the key.
430 * \param f_rng The RNG function to be used for key generation.
431 * This must not be \c NULL.
432 * \param p_rng The RNG context to be passed to \p f_rng.
433 * This may be \c NULL if \p f_rng doesn't need a context.
Rose Zadike8b5b992018-03-27 12:19:47 +0100434 * \param nbits The size of the public key in bits.
Hanno Becker9a467772018-12-13 09:54:59 +0000435 * \param exponent The public exponent to use. For example, \c 65537.
Rose Zadike8b5b992018-03-27 12:19:47 +0100436 *
437 * \return \c 0 on success.
438 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000439 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200440int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
Hanno Becker8fd55482017-08-23 14:07:48 +0100441 int (*f_rng)(void *, unsigned char *, size_t),
442 void *p_rng,
443 unsigned int nbits, int exponent );
Paul Bakker5121ce52009-01-03 21:22:43 +0000444
445/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000446 * \brief This function checks if a context contains at least an RSA
447 * public key.
Paul Bakker5121ce52009-01-03 21:22:43 +0000448 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000449 * If the function runs successfully, it is guaranteed that
450 * enough information is present to perform an RSA public key
451 * operation using mbedtls_rsa_public().
Paul Bakker5121ce52009-01-03 21:22:43 +0000452 *
Hanno Becker9a467772018-12-13 09:54:59 +0000453 * \param ctx The initialized RSA context to check.
Rose Zadik042e97f2018-01-26 16:35:10 +0000454 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100455 * \return \c 0 on success.
456 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Hanno Becker43a08d02017-10-02 13:16:35 +0100457 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000458 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200459int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000460
461/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000462 * \brief This function checks if a context contains an RSA private key
Hanno Becker1e801f52017-10-10 16:44:47 +0100463 * and perform basic consistency checks.
Paul Bakker5121ce52009-01-03 21:22:43 +0000464 *
Hanno Becker68767a62017-10-17 10:13:31 +0100465 * \note The consistency checks performed by this function not only
Rose Zadik042e97f2018-01-26 16:35:10 +0000466 * ensure that mbedtls_rsa_private() can be called successfully
Hanno Becker68767a62017-10-17 10:13:31 +0100467 * on the given context, but that the various parameters are
468 * mutually consistent with high probability, in the sense that
Rose Zadik042e97f2018-01-26 16:35:10 +0000469 * mbedtls_rsa_public() and mbedtls_rsa_private() are inverses.
Hanno Becker1e801f52017-10-10 16:44:47 +0100470 *
471 * \warning This function should catch accidental misconfigurations
472 * like swapping of parameters, but it cannot establish full
473 * trust in neither the quality nor the consistency of the key
474 * material that was used to setup the given RSA context:
Rose Zadik042e97f2018-01-26 16:35:10 +0000475 * <ul><li>Consistency: Imported parameters that are irrelevant
476 * for the implementation might be silently dropped. If dropped,
477 * the current function does not have access to them,
478 * and therefore cannot check them. See mbedtls_rsa_complete().
479 * If you want to check the consistency of the entire
480 * content of an PKCS1-encoded RSA private key, for example, you
481 * should use mbedtls_rsa_validate_params() before setting
482 * up the RSA context.
483 * Additionally, if the implementation performs empirical checks,
484 * these checks substantiate but do not guarantee consistency.</li>
485 * <li>Quality: This function is not expected to perform
486 * extended quality assessments like checking that the prime
487 * factors are safe. Additionally, it is the responsibility of the
488 * user to ensure the trustworthiness of the source of his RSA
489 * parameters, which goes beyond what is effectively checkable
490 * by the library.</li></ul>
Rose Zadike8b5b992018-03-27 12:19:47 +0100491 *
Hanno Becker9a467772018-12-13 09:54:59 +0000492 * \param ctx The initialized RSA context to check.
Rose Zadike8b5b992018-03-27 12:19:47 +0100493 *
494 * \return \c 0 on success.
495 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000496 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200497int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +0000498
499/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000500 * \brief This function checks a public-private RSA key pair.
Manuel Pégourié-Gonnard2f8d1f92014-11-06 14:02:51 +0100501 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000502 * It checks each of the contexts, and makes sure they match.
Manuel Pégourié-Gonnard2f8d1f92014-11-06 14:02:51 +0100503 *
Hanno Becker9a467772018-12-13 09:54:59 +0000504 * \param pub The initialized RSA context holding the public key.
505 * \param prv The initialized RSA context holding the private key.
Rose Zadik042e97f2018-01-26 16:35:10 +0000506 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100507 * \return \c 0 on success.
508 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Manuel Pégourié-Gonnard2f8d1f92014-11-06 14:02:51 +0100509 */
Hanno Becker98838b02017-10-02 13:16:10 +0100510int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub,
511 const mbedtls_rsa_context *prv );
Manuel Pégourié-Gonnard2f8d1f92014-11-06 14:02:51 +0100512
513/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000514 * \brief This function performs an RSA public key operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000515 *
Hanno Becker9a467772018-12-13 09:54:59 +0000516 * \param ctx The initialized RSA context to use.
517 * \param input The input buffer. This must be a readable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000518 * of length \c ctx->len Bytes. For example, \c 256 Bytes
519 * for an 2048-bit RSA modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000520 * \param output The output buffer. This must be a writable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000521 * of length \c ctx->len Bytes. For example, \c 256 Bytes
522 * for an 2048-bit RSA modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000523 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000524 * \note This function does not handle message padding.
525 *
526 * \note Make sure to set \p input[0] = 0 or ensure that
527 * input is smaller than \p N.
Paul Bakker5121ce52009-01-03 21:22:43 +0000528 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100529 * \return \c 0 on success.
530 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000531 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200532int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000533 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000534 unsigned char *output );
535
536/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000537 * \brief This function performs an RSA private key operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000538 *
Hanno Becker24120612017-10-26 11:53:35 +0100539 * \note Blinding is used if and only if a PRNG is provided.
Hanno Becker88ec2382017-05-03 13:51:16 +0100540 *
541 * \note If blinding is used, both the base of exponentation
Hanno Becker24120612017-10-26 11:53:35 +0100542 * and the exponent are blinded, providing protection
543 * against some side-channel attacks.
Hanno Becker88ec2382017-05-03 13:51:16 +0100544 *
Hanno Becker4e1be392017-10-02 15:56:48 +0100545 * \warning It is deprecated and a security risk to not provide
546 * a PRNG here and thereby prevent the use of blinding.
547 * Future versions of the library may enforce the presence
548 * of a PRNG.
Hanno Becker88ec2382017-05-03 13:51:16 +0100549 *
Hanno Becker9a467772018-12-13 09:54:59 +0000550 * \param ctx The initialized RSA context to use.
551 * \param f_rng The RNG function, used for blinding. It is discouraged
552 * and deprecated to pass \c NULL here, in which case
553 * blinding will be omitted.
554 * \param p_rng The RNG context to pass to \p f_rng. This may be \c NULL
555 * if \p f_rng is \c NULL or if \p f_rng doesn't need a context.
556 * \param input The input buffer. This must be a readable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000557 * of length \c ctx->len Bytes. For example, \c 256 Bytes
558 * for an 2048-bit RSA modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000559 * \param output The output buffer. This must be a writable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000560 * of length \c ctx->len Bytes. For example, \c 256 Bytes
561 * for an 2048-bit RSA modulus.
Rose Zadike8b5b992018-03-27 12:19:47 +0100562 *
563 * \return \c 0 on success.
564 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
565 *
Paul Bakker5121ce52009-01-03 21:22:43 +0000566 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200567int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +0200568 int (*f_rng)(void *, unsigned char *, size_t),
569 void *p_rng,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000570 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000571 unsigned char *output );
572
573/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000574 * \brief This function adds the message padding, then performs an RSA
575 * operation.
Paul Bakker5121ce52009-01-03 21:22:43 +0000576 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000577 * It is the generic wrapper for performing a PKCS#1 encryption
578 * operation using the \p mode from the context.
Paul Bakker5121ce52009-01-03 21:22:43 +0000579 *
Hanno Becker3cdc7112017-10-05 10:09:31 +0100580 * \deprecated It is deprecated and discouraged to call this function
Rose Zadik042e97f2018-01-26 16:35:10 +0000581 * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
582 * are likely to remove the \p mode argument and have it
583 * implicitly set to #MBEDTLS_RSA_PUBLIC.
Hanno Becker3cdc7112017-10-05 10:09:31 +0100584 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100585 * \note Alternative implementations of RSA need not support
586 * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300587 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100588 *
Hanno Becker9a467772018-12-13 09:54:59 +0000589 * \param ctx The initialized RSA context to use.
590 * \param f_rng This is the RNG function used to generate the
591 * PKCS#1 v2.1 padding encoding if \p mode is
592 * #MBEDTLS_RSA_PRIVATE.
593 * \param p_rng The RNG context to be passed to \p f_rng. May be
594 * \c NULL if \p f_rng is \c NULL or if \p f_rng doesn't
595 * need a context argument.
596 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000597 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
Hanno Becker9a467772018-12-13 09:54:59 +0000598 * \param ilen The length of the plaintext in Bytes.
599 * \param input The input data to encrypt. This must be a readable
600 * buffer of size \p ilen Bytes. It may be \c NULL if
601 * `ilen == 0`.
602 * \param output The output buffer. This must be a writable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000603 * of length \c ctx->len Bytes. For example, \c 256 Bytes
604 * for an 2048-bit RSA modulus.
Hanno Becker3cdc7112017-10-05 10:09:31 +0100605 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100606 * \return \c 0 on success.
607 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000608 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200609int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
Paul Bakkera3d195c2011-11-27 21:07:34 +0000610 int (*f_rng)(void *, unsigned char *, size_t),
Paul Bakker21eb2802010-08-16 11:10:02 +0000611 void *p_rng,
Paul Bakker23986e52011-04-24 08:57:21 +0000612 int mode, size_t ilen,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000613 const unsigned char *input,
Paul Bakker5121ce52009-01-03 21:22:43 +0000614 unsigned char *output );
615
616/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000617 * \brief This function performs a PKCS#1 v1.5 encryption operation
618 * (RSAES-PKCS1-v1_5-ENCRYPT).
Paul Bakkerb3869132013-02-28 17:21:01 +0100619 *
Hanno Becker3cdc7112017-10-05 10:09:31 +0100620 * \deprecated It is deprecated and discouraged to call this function
Rose Zadik042e97f2018-01-26 16:35:10 +0000621 * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
622 * are likely to remove the \p mode argument and have it
623 * implicitly set to #MBEDTLS_RSA_PUBLIC.
Hanno Becker3cdc7112017-10-05 10:09:31 +0100624 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100625 * \note Alternative implementations of RSA need not support
626 * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300627 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100628 *
Hanno Becker9a467772018-12-13 09:54:59 +0000629 * \param ctx The initialized RSA context to use.
630 * \param f_rng The RNG function, needed for padding generation if
631 * \p mode is #MBEDTLS_RSA_PRIVATE.
632 * \param p_rng The RNG context to be passed to \p f_rng. This may
633 * be \c NULL if \p f_rng is \c NULL or if \p f_rng
634 * doesn't need a context argument.
635 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000636 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
Hanno Becker9a467772018-12-13 09:54:59 +0000637 * \param ilen The length of the plaintext in Bytes.
638 * \param input The input data to encrypt. This must be a readable
639 * buffer of size \p ilen Bytes. It may be \c NULL if
640 * `ilen == 0`.
641 * \param output The output buffer. This must be a writable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000642 * of length \c ctx->len Bytes. For example, \c 256 Bytes
643 * for an 2048-bit RSA modulus.
Hanno Becker3cdc7112017-10-05 10:09:31 +0100644 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100645 * \return \c 0 on success.
646 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +0100647 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200648int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
Paul Bakkerb3869132013-02-28 17:21:01 +0100649 int (*f_rng)(void *, unsigned char *, size_t),
650 void *p_rng,
651 int mode, size_t ilen,
652 const unsigned char *input,
653 unsigned char *output );
654
655/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000656 * \brief This function performs a PKCS#1 v2.1 OAEP encryption
657 * operation (RSAES-OAEP-ENCRYPT).
Paul Bakkerb3869132013-02-28 17:21:01 +0100658 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100659 * \note The output buffer must be as large as the size
660 * of ctx->N. For example, 128 Bytes if RSA-1024 is used.
661 *
662 * \deprecated It is deprecated and discouraged to call this function
663 * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
664 * are likely to remove the \p mode argument and have it
665 * implicitly set to #MBEDTLS_RSA_PUBLIC.
666 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100667 * \note Alternative implementations of RSA need not support
668 * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300669 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100670 *
Hanno Becker9a467772018-12-13 09:54:59 +0000671 * \param ctx The initnialized RSA context to use.
672 * \param f_rng The RNG function, needed for padding and PKCS#1 v2.1
673 * encoding if \p mode is #MBEDTLS_RSA_PRIVATE.
674 * \param p_rng The RNG context to be passed to \p f_rng. This may
675 * be \c NULL if \p f_rng is \c NULL or if \p f_rng
676 * doesn't need a context argument.
677 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000678 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
Rose Zadik042e97f2018-01-26 16:35:10 +0000679 * \param label The buffer holding the custom label to use.
Hanno Becker9a467772018-12-13 09:54:59 +0000680 * This must be a readable buffer of length \p label_len
681 * Bytes. It may be \c NULL if \p label_len is \c 0.
682 * \param label_len The length of the label in Bytes.
683 * \param ilen The length of the plaintext buffer \p input in Bytes.
684 * \param input The input data to encrypt. This must be a readable
685 * buffer of size \p ilen Bytes. It may be \c NULL if
686 * `ilen == 0`.
687 * \param output The output buffer. This must be a writable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000688 * of length \c ctx->len Bytes. For example, \c 256 Bytes
689 * for an 2048-bit RSA modulus.
Paul Bakkerb3869132013-02-28 17:21:01 +0100690 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100691 * \return \c 0 on success.
692 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +0100693 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200694int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
Paul Bakkerb3869132013-02-28 17:21:01 +0100695 int (*f_rng)(void *, unsigned char *, size_t),
696 void *p_rng,
Paul Bakkera43231c2013-02-28 17:33:49 +0100697 int mode,
698 const unsigned char *label, size_t label_len,
699 size_t ilen,
Paul Bakkerb3869132013-02-28 17:21:01 +0100700 const unsigned char *input,
701 unsigned char *output );
702
703/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000704 * \brief This function performs an RSA operation, then removes the
705 * message padding.
Paul Bakker5121ce52009-01-03 21:22:43 +0000706 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000707 * It is the generic wrapper for performing a PKCS#1 decryption
708 * operation using the \p mode from the context.
Paul Bakker5121ce52009-01-03 21:22:43 +0000709 *
Hanno Becker248ae6d2017-05-04 11:27:39 +0100710 * \note The output buffer length \c output_max_len should be
Rose Zadik042e97f2018-01-26 16:35:10 +0000711 * as large as the size \p ctx->len of \p ctx->N (for example,
712 * 128 Bytes if RSA-1024 is used) to be able to hold an
713 * arbitrary decrypted message. If it is not large enough to
714 * hold the decryption of the particular ciphertext provided,
715 * the function returns \c MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
Hanno Becker248ae6d2017-05-04 11:27:39 +0100716 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100717 * \deprecated It is deprecated and discouraged to call this function
718 * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
719 * are likely to remove the \p mode argument and have it
720 * implicitly set to #MBEDTLS_RSA_PRIVATE.
721 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100722 * \note Alternative implementations of RSA need not support
723 * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300724 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100725 *
Hanno Becker9a467772018-12-13 09:54:59 +0000726 * \param ctx The initialized RSA context to use.
727 * \param f_rng The RNG function. This is needed for #MBEDTLS_RSA_PRIVATE.
728 * \param p_rng The RNG context to be passed to \p f_rng. This may be
729 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
730 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000731 * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
Hanno Becker9a467772018-12-13 09:54:59 +0000732 * \param olen The address at which to store the length of
733 * the plaintext. This must not be \c NULL.
734 * \param input The ciphertext buffer. This must be a readable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000735 * of length \c ctx->len Bytes. For example, \c 256 Bytes
736 * for an 2048-bit RSA modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000737 * \param output The buffer used to hold the plaintext. This must
738 * be a writable buffer of length \p output_max_len Bytes.
739 * \param output_max_len The maximum length of the output buffer.
Rose Zadike8b5b992018-03-27 12:19:47 +0100740 *
741 * \return \c 0 on success.
742 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000743 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200744int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +0200745 int (*f_rng)(void *, unsigned char *, size_t),
746 void *p_rng,
Paul Bakker23986e52011-04-24 08:57:21 +0000747 int mode, size_t *olen,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000748 const unsigned char *input,
Paul Bakker060c5682009-01-12 21:48:39 +0000749 unsigned char *output,
Paul Bakker23986e52011-04-24 08:57:21 +0000750 size_t output_max_len );
Paul Bakker5121ce52009-01-03 21:22:43 +0000751
752/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000753 * \brief This function performs a PKCS#1 v1.5 decryption
754 * operation (RSAES-PKCS1-v1_5-DECRYPT).
Paul Bakkerb3869132013-02-28 17:21:01 +0100755 *
Hanno Becker248ae6d2017-05-04 11:27:39 +0100756 * \note The output buffer length \c output_max_len should be
Rose Zadik042e97f2018-01-26 16:35:10 +0000757 * as large as the size \p ctx->len of \p ctx->N, for example,
758 * 128 Bytes if RSA-1024 is used, to be able to hold an
759 * arbitrary decrypted message. If it is not large enough to
760 * hold the decryption of the particular ciphertext provided,
761 * the function returns #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
Hanno Becker248ae6d2017-05-04 11:27:39 +0100762 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100763 * \deprecated It is deprecated and discouraged to call this function
764 * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
765 * are likely to remove the \p mode argument and have it
766 * implicitly set to #MBEDTLS_RSA_PRIVATE.
767 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100768 * \note Alternative implementations of RSA need not support
769 * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300770 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100771 *
Hanno Becker9a467772018-12-13 09:54:59 +0000772 * \param ctx The initialized RSA context to use.
773 * \param f_rng The RNG function. This is needed for #MBEDTLS_RSA_PRIVATE.
774 * \param p_rng The RNG context to be passed to \p f_rng. This may be
775 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
776 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000777 * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
Hanno Becker9a467772018-12-13 09:54:59 +0000778 * \param olen The address at which to store the length of
779 * the plaintext. This must not be \c NULL.
780 * \param input The ciphertext buffer. This must be a readable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000781 * of length \c ctx->len Bytes. For example, \c 256 Bytes
782 * for an 2048-bit RSA modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000783 * \param output The buffer used to hold the plaintext. This must
784 * be a writable buffer of length \p output_max_len Bytes.
785 * \param output_max_len The maximum length of the output buffer.
Rose Zadike8b5b992018-03-27 12:19:47 +0100786 *
787 * \return \c 0 on success.
788 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
789 *
Paul Bakkerb3869132013-02-28 17:21:01 +0100790 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200791int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +0200792 int (*f_rng)(void *, unsigned char *, size_t),
793 void *p_rng,
Paul Bakkerb3869132013-02-28 17:21:01 +0100794 int mode, size_t *olen,
795 const unsigned char *input,
796 unsigned char *output,
797 size_t output_max_len );
798
799/**
Rose Zadike8b5b992018-03-27 12:19:47 +0100800 * \brief This function performs a PKCS#1 v2.1 OAEP decryption
801 * operation (RSAES-OAEP-DECRYPT).
Paul Bakkerb3869132013-02-28 17:21:01 +0100802 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100803 * \note The output buffer length \c output_max_len should be
804 * as large as the size \p ctx->len of \p ctx->N, for
805 * example, 128 Bytes if RSA-1024 is used, to be able to
806 * hold an arbitrary decrypted message. If it is not
807 * large enough to hold the decryption of the particular
808 * ciphertext provided, the function returns
809 * #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE.
Paul Bakkerb3869132013-02-28 17:21:01 +0100810 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100811 * \deprecated It is deprecated and discouraged to call this function
812 * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
813 * are likely to remove the \p mode argument and have it
814 * implicitly set to #MBEDTLS_RSA_PRIVATE.
815 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100816 * \note Alternative implementations of RSA need not support
817 * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300818 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100819 *
Hanno Becker9a467772018-12-13 09:54:59 +0000820 * \param ctx The initialized RSA context to use.
821 * \param f_rng The RNG function. This is needed for #MBEDTLS_RSA_PRIVATE.
822 * \param p_rng The RNG context to be passed to \p f_rng. This may be
823 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
824 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000825 * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
Rose Zadike8b5b992018-03-27 12:19:47 +0100826 * \param label The buffer holding the custom label to use.
Hanno Becker9a467772018-12-13 09:54:59 +0000827 * This must be a readable buffer of length \p label_len
828 * Bytes. It may be \c NULL if \p label_len is \c 0.
829 * \param label_len The length of the label in Bytes.
830 * \param olen The address at which to store the length of
831 * the plaintext. This must not be \c NULL.
832 * \param input The ciphertext buffer. This must be a readable buffer
Hanno Becker385ce912018-12-13 18:33:12 +0000833 * of length \c ctx->len Bytes. For example, \c 256 Bytes
834 * for an 2048-bit RSA modulus.
Hanno Becker9a467772018-12-13 09:54:59 +0000835 * \param output The buffer used to hold the plaintext. This must
836 * be a writable buffer of length \p output_max_len Bytes.
837 * \param output_max_len The maximum length of the output buffer.
Rose Zadike8b5b992018-03-27 12:19:47 +0100838 *
839 * \return \c 0 on success.
840 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +0100841 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200842int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +0200843 int (*f_rng)(void *, unsigned char *, size_t),
844 void *p_rng,
Paul Bakkera43231c2013-02-28 17:33:49 +0100845 int mode,
846 const unsigned char *label, size_t label_len,
847 size_t *olen,
Paul Bakkerb3869132013-02-28 17:21:01 +0100848 const unsigned char *input,
849 unsigned char *output,
850 size_t output_max_len );
851
852/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000853 * \brief This function performs a private RSA operation to sign
854 * a message digest using PKCS#1.
Paul Bakker5121ce52009-01-03 21:22:43 +0000855 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000856 * It is the generic wrapper for performing a PKCS#1
857 * signature using the \p mode from the context.
Paul Bakker5121ce52009-01-03 21:22:43 +0000858 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000859 * \note The \p sig buffer must be as large as the size
860 * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
Paul Bakker9dcc3222011-03-08 14:16:06 +0000861 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000862 * \note For PKCS#1 v2.1 encoding, see comments on
863 * mbedtls_rsa_rsassa_pss_sign() for details on
864 * \p md_alg and \p hash_id.
Rose Zadike8b5b992018-03-27 12:19:47 +0100865 *
866 * \deprecated It is deprecated and discouraged to call this function
867 * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
868 * are likely to remove the \p mode argument and have it
869 * implicitly set to #MBEDTLS_RSA_PRIVATE.
870 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100871 * \note Alternative implementations of RSA need not support
872 * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300873 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100874 *
Hanno Becker9a467772018-12-13 09:54:59 +0000875 * \param ctx The initialized RSA context to use.
876 * \param f_rng The RNG function. It is needed for PKCS#1 v2.1 encoding
877 * and for \p mode set to #MBEDTLS_RSA_PRIVATE.
878 * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
879 * if \p f_rng is \c NULL or doesn't need a context argument.
880 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000881 * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
Rose Zadike8b5b992018-03-27 12:19:47 +0100882 * \param md_alg The message-digest algorithm used to hash the original data.
883 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +0000884 * \param hashlen The length of the message digest.
885 * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
886 * \param hash The buffer holding the message digest or raw data.
887 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
888 * buffer of length \p hashlen Bytes. If \p md_alg is not
889 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
890 * the size of the hash corresponding to \p md_alg.
891 * \param sig The buffer to hold the signature. This must be a writable
Hanno Becker385ce912018-12-13 18:33:12 +0000892 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
893 * for an 2048-bit RSA modulus.
Rose Zadike8b5b992018-03-27 12:19:47 +0100894 *
895 * \return \c 0 if the signing operation was successful.
896 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +0000897 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200898int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
Paul Bakkera3d195c2011-11-27 21:07:34 +0000899 int (*f_rng)(void *, unsigned char *, size_t),
Paul Bakker9dcc3222011-03-08 14:16:06 +0000900 void *p_rng,
Paul Bakker5121ce52009-01-03 21:22:43 +0000901 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200902 mbedtls_md_type_t md_alg,
Paul Bakker23986e52011-04-24 08:57:21 +0000903 unsigned int hashlen,
Paul Bakkerff60ee62010-03-16 21:09:09 +0000904 const unsigned char *hash,
Paul Bakker5121ce52009-01-03 21:22:43 +0000905 unsigned char *sig );
906
907/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000908 * \brief This function performs a PKCS#1 v1.5 signature
909 * operation (RSASSA-PKCS1-v1_5-SIGN).
Paul Bakkerb3869132013-02-28 17:21:01 +0100910 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100911 * \deprecated It is deprecated and discouraged to call this function
912 * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
913 * are likely to remove the \p mode argument and have it
914 * implicitly set to #MBEDTLS_RSA_PRIVATE.
915 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100916 * \note Alternative implementations of RSA need not support
917 * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300918 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100919 *
Hanno Becker9a467772018-12-13 09:54:59 +0000920 * \param ctx The initialized RSA context to use.
921 * \param f_rng The RNG function. It is needed for PKCS#1 v2.1 encoding
922 * and for \p mode set to #MBEDTLS_RSA_PRIVATE.
923 * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
924 * if \p f_rng is \c NULL or doesn't need a context argument.
925 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000926 * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
Rose Zadik042e97f2018-01-26 16:35:10 +0000927 * \param md_alg The message-digest algorithm used to hash the original data.
928 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +0000929 * \param hashlen The length of the message digest.
930 * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
931 * \param hash The buffer holding the message digest or raw data.
932 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
933 * buffer of length \p hashlen Bytes. If \p md_alg is not
934 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
935 * the size of the hash corresponding to \p md_alg.
936 * \param sig The buffer to hold the signature. This must be a writable
Hanno Becker385ce912018-12-13 18:33:12 +0000937 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
938 * for an 2048-bit RSA modulus.
Paul Bakkerb3869132013-02-28 17:21:01 +0100939 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100940 * \return \c 0 if the signing operation was successful.
941 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +0100942 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200943int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +0200944 int (*f_rng)(void *, unsigned char *, size_t),
945 void *p_rng,
Paul Bakkerb3869132013-02-28 17:21:01 +0100946 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200947 mbedtls_md_type_t md_alg,
Paul Bakkerb3869132013-02-28 17:21:01 +0100948 unsigned int hashlen,
949 const unsigned char *hash,
950 unsigned char *sig );
951
952/**
Rose Zadik042e97f2018-01-26 16:35:10 +0000953 * \brief This function performs a PKCS#1 v2.1 PSS signature
954 * operation (RSASSA-PSS-SIGN).
Paul Bakkerb3869132013-02-28 17:21:01 +0100955 *
Rose Zadik042e97f2018-01-26 16:35:10 +0000956 * \note The \p hash_id in the RSA context is the one used for the
957 * encoding. \p md_alg in the function call is the type of hash
958 * that is encoded. According to <em>RFC-3447: Public-Key
959 * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
960 * Specifications</em> it is advised to keep both hashes the
961 * same.
Rose Zadike8b5b992018-03-27 12:19:47 +0100962 *
Jaeden Amero3725bb22018-09-07 19:12:36 +0100963 * \note This function always uses the maximum possible salt size,
964 * up to the length of the payload hash. This choice of salt
965 * size complies with FIPS 186-4 §5.5 (e) and RFC 8017 (PKCS#1
966 * v2.2) §9.1.1 step 3. Furthermore this function enforces a
967 * minimum salt size which is the hash size minus 2 bytes. If
968 * this minimum size is too large given the key size (the salt
969 * size, plus the hash size, plus 2 bytes must be no more than
970 * the key size in bytes), this function returns
971 * #MBEDTLS_ERR_RSA_BAD_INPUT_DATA.
972 *
Rose Zadike8b5b992018-03-27 12:19:47 +0100973 * \deprecated It is deprecated and discouraged to call this function
974 * in #MBEDTLS_RSA_PUBLIC mode. Future versions of the library
975 * are likely to remove the \p mode argument and have it
976 * implicitly set to #MBEDTLS_RSA_PRIVATE.
977 *
Rose Zadikf2ec2882018-04-17 10:27:25 +0100978 * \note Alternative implementations of RSA need not support
979 * mode being set to #MBEDTLS_RSA_PUBLIC and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +0300980 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +0100981 *
Hanno Becker9a467772018-12-13 09:54:59 +0000982 * \param ctx The initialized RSA context to use.
983 * \param f_rng The RNG function. It must not be \c NULL.
984 * \param p_rng The RNG context to be passed to \p f_rng. This may be \c NULL
985 * if \p f_rng doesn't need a context argument.
986 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +0000987 * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated).
Rose Zadike8b5b992018-03-27 12:19:47 +0100988 * \param md_alg The message-digest algorithm used to hash the original data.
989 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +0000990 * \param hashlen The length of the message digest.
991 * Ths is only used if \p md_alg is #MBEDTLS_MD_NONE.
992 * \param hash The buffer holding the message digest or raw data.
993 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
994 * buffer of length \p hashlen Bytes. If \p md_alg is not
995 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
996 * the size of the hash corresponding to \p md_alg.
997 * \param sig The buffer to hold the signature. This must be a writable
Hanno Becker385ce912018-12-13 18:33:12 +0000998 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
999 * for an 2048-bit RSA modulus.
Rose Zadike8b5b992018-03-27 12:19:47 +01001000 *
1001 * \return \c 0 if the signing operation was successful.
1002 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +01001003 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001004int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
Paul Bakkerb3869132013-02-28 17:21:01 +01001005 int (*f_rng)(void *, unsigned char *, size_t),
1006 void *p_rng,
1007 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001008 mbedtls_md_type_t md_alg,
Paul Bakkerb3869132013-02-28 17:21:01 +01001009 unsigned int hashlen,
1010 const unsigned char *hash,
1011 unsigned char *sig );
1012
1013/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001014 * \brief This function performs a public RSA operation and checks
1015 * the message digest.
Paul Bakker5121ce52009-01-03 21:22:43 +00001016 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001017 * This is the generic wrapper for performing a PKCS#1
1018 * verification using the mode from the context.
Paul Bakker5121ce52009-01-03 21:22:43 +00001019 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001020 * \note For PKCS#1 v2.1 encoding, see comments on
1021 * mbedtls_rsa_rsassa_pss_verify() about \p md_alg and
1022 * \p hash_id.
Rose Zadike8b5b992018-03-27 12:19:47 +01001023 *
1024 * \deprecated It is deprecated and discouraged to call this function
1025 * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
1026 * are likely to remove the \p mode argument and have it
1027 * set to #MBEDTLS_RSA_PUBLIC.
1028 *
Rose Zadikf2ec2882018-04-17 10:27:25 +01001029 * \note Alternative implementations of RSA need not support
1030 * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +03001031 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +01001032 *
Hanno Becker9a467772018-12-13 09:54:59 +00001033 * \param ctx The initialized RSA public key context to use.
1034 * \param f_rng The RNG function to use. This is only needed if
1035 * \p mode is #MBEDTLS_RSA_PRIVATE.
1036 * \param p_rng The RNG context to be passed to \p f_rng. This may be
1037 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
1038 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +00001039 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
Rose Zadike8b5b992018-03-27 12:19:47 +01001040 * \param md_alg The message-digest algorithm used to hash the original data.
1041 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +00001042 * \param hashlen The length of the message digest.
1043 * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
1044 * \param hash The buffer holding the message digest or raw data.
1045 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
1046 * buffer of length \p hashlen Bytes. If \p md_alg is not
1047 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
1048 * the size of the hash corresponding to \p md_alg.
1049 * \param sig The buffer holding the signature. This must be a readable
Hanno Becker385ce912018-12-13 18:33:12 +00001050 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1051 * for an 2048-bit RSA modulus.
Rose Zadike8b5b992018-03-27 12:19:47 +01001052 *
1053 * \return \c 0 if the verify operation was successful.
1054 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +00001055 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001056int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +02001057 int (*f_rng)(void *, unsigned char *, size_t),
1058 void *p_rng,
Paul Bakker5121ce52009-01-03 21:22:43 +00001059 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001060 mbedtls_md_type_t md_alg,
Paul Bakker23986e52011-04-24 08:57:21 +00001061 unsigned int hashlen,
Paul Bakkerff60ee62010-03-16 21:09:09 +00001062 const unsigned char *hash,
Manuel Pégourié-Gonnardcc0a9d02013-08-12 11:34:35 +02001063 const unsigned char *sig );
Paul Bakker5121ce52009-01-03 21:22:43 +00001064
1065/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001066 * \brief This function performs a PKCS#1 v1.5 verification
1067 * operation (RSASSA-PKCS1-v1_5-VERIFY).
Paul Bakkerb3869132013-02-28 17:21:01 +01001068 *
Rose Zadike8b5b992018-03-27 12:19:47 +01001069 * \deprecated It is deprecated and discouraged to call this function
1070 * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
1071 * are likely to remove the \p mode argument and have it
1072 * set to #MBEDTLS_RSA_PUBLIC.
1073 *
Rose Zadikf2ec2882018-04-17 10:27:25 +01001074 * \note Alternative implementations of RSA need not support
1075 * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +03001076 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +01001077 *
Hanno Becker9a467772018-12-13 09:54:59 +00001078 * \param ctx The initialized RSA public key context to use.
1079 * \param f_rng The RNG function to use. This is only needed if
1080 * \p mode is #MBEDTLS_RSA_PRIVATE.
1081 * \param p_rng The RNG context to be passed to \p f_rng. This may be
1082 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
1083 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +00001084 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
Rose Zadik042e97f2018-01-26 16:35:10 +00001085 * \param md_alg The message-digest algorithm used to hash the original data.
1086 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +00001087 * \param hashlen The length of the message digest.
1088 * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
1089 * \param hash The buffer holding the message digest or raw data.
1090 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
1091 * buffer of length \p hashlen Bytes. If \p md_alg is not
1092 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
1093 * the size of the hash corresponding to \p md_alg.
1094 * \param sig The buffer holding the signature. This must be a readable
Hanno Becker385ce912018-12-13 18:33:12 +00001095 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1096 * for an 2048-bit RSA modulus.
Paul Bakkerb3869132013-02-28 17:21:01 +01001097 *
Rose Zadike8b5b992018-03-27 12:19:47 +01001098 * \return \c 0 if the verify operation was successful.
1099 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +01001100 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001101int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +02001102 int (*f_rng)(void *, unsigned char *, size_t),
1103 void *p_rng,
Paul Bakkerb3869132013-02-28 17:21:01 +01001104 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001105 mbedtls_md_type_t md_alg,
Paul Bakkerb3869132013-02-28 17:21:01 +01001106 unsigned int hashlen,
1107 const unsigned char *hash,
Manuel Pégourié-Gonnardcc0a9d02013-08-12 11:34:35 +02001108 const unsigned char *sig );
Paul Bakkerb3869132013-02-28 17:21:01 +01001109
1110/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001111 * \brief This function performs a PKCS#1 v2.1 PSS verification
1112 * operation (RSASSA-PSS-VERIFY).
Paul Bakkerb3869132013-02-28 17:21:01 +01001113 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001114 * The hash function for the MGF mask generating function
1115 * is that specified in the RSA context.
Paul Bakkerb3869132013-02-28 17:21:01 +01001116 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001117 * \note The \p hash_id in the RSA context is the one used for the
1118 * verification. \p md_alg in the function call is the type of
1119 * hash that is verified. According to <em>RFC-3447: Public-Key
1120 * Cryptography Standards (PKCS) #1 v2.1: RSA Cryptography
1121 * Specifications</em> it is advised to keep both hashes the
1122 * same. If \p hash_id in the RSA context is unset,
1123 * the \p md_alg from the function call is used.
Rose Zadike8b5b992018-03-27 12:19:47 +01001124 *
1125 * \deprecated It is deprecated and discouraged to call this function
1126 * in #MBEDTLS_RSA_PRIVATE mode. Future versions of the library
1127 * are likely to remove the \p mode argument and have it
1128 * implicitly set to #MBEDTLS_RSA_PUBLIC.
1129 *
Rose Zadikf2ec2882018-04-17 10:27:25 +01001130 * \note Alternative implementations of RSA need not support
1131 * mode being set to #MBEDTLS_RSA_PRIVATE and might instead
Ron Eldor9924bdc2018-10-04 10:59:13 +03001132 * return #MBEDTLS_ERR_PLATFORM_FEATURE_UNSUPPORTED.
Rose Zadikf2ec2882018-04-17 10:27:25 +01001133 *
Hanno Becker9a467772018-12-13 09:54:59 +00001134 * \param ctx The initialized RSA public key context to use.
1135 * \param f_rng The RNG function to use. This is only needed if
1136 * \p mode is #MBEDTLS_RSA_PRIVATE.
1137 * \param p_rng The RNG context to be passed to \p f_rng. This may be
1138 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
1139 * \param mode The mode of operation. This must be either
Hanno Becker385ce912018-12-13 18:33:12 +00001140 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE (deprecated).
Rose Zadike8b5b992018-03-27 12:19:47 +01001141 * \param md_alg The message-digest algorithm used to hash the original data.
1142 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +00001143 * \param hashlen The length of the message digest.
1144 * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
1145 * \param hash The buffer holding the message digest or raw data.
1146 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
1147 * buffer of length \p hashlen Bytes. If \p md_alg is not
1148 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
1149 * the size of the hash corresponding to \p md_alg.
1150 * \param sig The buffer holding the signature. This must be a readable
Hanno Becker385ce912018-12-13 18:33:12 +00001151 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1152 * for an 2048-bit RSA modulus.
Rose Zadike8b5b992018-03-27 12:19:47 +01001153 *
1154 * \return \c 0 if the verify operation was successful.
1155 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Paul Bakkerb3869132013-02-28 17:21:01 +01001156 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001157int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
Paul Bakker548957d2013-08-30 10:30:02 +02001158 int (*f_rng)(void *, unsigned char *, size_t),
1159 void *p_rng,
Paul Bakkerb3869132013-02-28 17:21:01 +01001160 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001161 mbedtls_md_type_t md_alg,
Paul Bakkerb3869132013-02-28 17:21:01 +01001162 unsigned int hashlen,
1163 const unsigned char *hash,
Manuel Pégourié-Gonnardcc0a9d02013-08-12 11:34:35 +02001164 const unsigned char *sig );
Paul Bakkerb3869132013-02-28 17:21:01 +01001165
1166/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001167 * \brief This function performs a PKCS#1 v2.1 PSS verification
1168 * operation (RSASSA-PSS-VERIFY).
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001169 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001170 * The hash function for the MGF mask generating function
1171 * is that specified in \p mgf1_hash_id.
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001172 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001173 * \note The \p sig buffer must be as large as the size
1174 * of \p ctx->N. For example, 128 Bytes if RSA-1024 is used.
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001175 *
Rose Zadik042e97f2018-01-26 16:35:10 +00001176 * \note The \p hash_id in the RSA context is ignored.
Rose Zadike8b5b992018-03-27 12:19:47 +01001177 *
Hanno Becker9a467772018-12-13 09:54:59 +00001178 * \param ctx The initialized RSA public key context to use.
1179 * \param f_rng The RNG function to use. This is only needed if
1180 * \p mode is #MBEDTLS_RSA_PRIVATE.
1181 * \param p_rng The RNG context to be passed to \p f_rng. This may be
1182 * \c NULL if \p f_rng is \c NULL or doesn't need a context.
1183 * \param mode The mode of operation. This must be either
1184 * #MBEDTLS_RSA_PUBLIC or #MBEDTLS_RSA_PRIVATE.
Rose Zadike8b5b992018-03-27 12:19:47 +01001185 * \param md_alg The message-digest algorithm used to hash the original data.
1186 * Use #MBEDTLS_MD_NONE for signing raw data.
Hanno Becker9a467772018-12-13 09:54:59 +00001187 * \param hashlen The length of the message digest.
1188 * This is only used if \p md_alg is #MBEDTLS_MD_NONE.
1189 * \param hash The buffer holding the message digest or raw data.
1190 * If \p md_alg is #MBEDTLS_MD_NONE, this must be a readable
1191 * buffer of length \p hashlen Bytes. If \p md_alg is not
1192 * #MBEDTLS_MD_NONE, it must be a readable buffer of length
1193 * the size of the hash corresponding to \p md_alg.
1194 * \param mgf1_hash_id The message digest used for mask generation.
1195 * \param expected_salt_len The length of the salt used in padding. Use
1196 * #MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length.
1197 * \param sig The buffer holding the signature. This must be a readable
Hanno Becker385ce912018-12-13 18:33:12 +00001198 * buffer of length \c ctx->len Bytes. For example, \c 256 Bytes
1199 * for an 2048-bit RSA modulus.
Rose Zadike8b5b992018-03-27 12:19:47 +01001200 *
1201 * \return \c 0 if the verify operation was successful.
1202 * \return An \c MBEDTLS_ERR_RSA_XXX error code on failure.
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001203 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001204int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001205 int (*f_rng)(void *, unsigned char *, size_t),
1206 void *p_rng,
1207 int mode,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001208 mbedtls_md_type_t md_alg,
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001209 unsigned int hashlen,
1210 const unsigned char *hash,
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001211 mbedtls_md_type_t mgf1_hash_id,
Manuel Pégourié-Gonnard5ec628a2014-06-03 11:44:06 +02001212 int expected_salt_len,
1213 const unsigned char *sig );
1214
1215/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001216 * \brief This function copies the components of an RSA context.
Manuel Pégourié-Gonnard3053f5b2013-08-14 13:39:57 +02001217 *
Hanno Becker9a467772018-12-13 09:54:59 +00001218 * \param dst The destination context. This must be initialized.
1219 * \param src The source context. This must be initialized.
Manuel Pégourié-Gonnard3053f5b2013-08-14 13:39:57 +02001220 *
Rose Zadike8b5b992018-03-27 12:19:47 +01001221 * \return \c 0 on success.
1222 * \return #MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure.
Manuel Pégourié-Gonnard3053f5b2013-08-14 13:39:57 +02001223 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001224int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src );
Manuel Pégourié-Gonnard3053f5b2013-08-14 13:39:57 +02001225
1226/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001227 * \brief This function frees the components of an RSA key.
Paul Bakker13e2dfe2009-07-28 07:18:38 +00001228 *
Hanno Becker9a467772018-12-13 09:54:59 +00001229 * \param ctx The RSA context to free. May be \c NULL, in which case
1230 * this function is a no-op. If it is not \c NULL, it must
Hanno Becker385ce912018-12-13 18:33:12 +00001231 * point to an initialized RSA context.
Paul Bakker5121ce52009-01-03 21:22:43 +00001232 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001233void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
Paul Bakker5121ce52009-01-03 21:22:43 +00001234
1235/**
Rose Zadik042e97f2018-01-26 16:35:10 +00001236 * \brief The RSA checkup routine.
Paul Bakker5121ce52009-01-03 21:22:43 +00001237 *
Rose Zadike8b5b992018-03-27 12:19:47 +01001238 * \return \c 0 on success.
1239 * \return \c 1 on failure.
Paul Bakker5121ce52009-01-03 21:22:43 +00001240 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +02001241int mbedtls_rsa_self_test( int verbose );
Paul Bakker5121ce52009-01-03 21:22:43 +00001242
1243#ifdef __cplusplus
1244}
1245#endif
1246
Paul Bakker5121ce52009-01-03 21:22:43 +00001247#endif /* rsa.h */