Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 1 | /** |
| 2 | * \file rsa.h |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 3 | * |
Paul Bakker | 37ca75d | 2011-01-06 12:28:03 +0000 | [diff] [blame] | 4 | * \brief The RSA public-key cryptosystem |
| 5 | * |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 6 | * Copyright (C) 2006-2013, Brainspark B.V. |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 7 | * |
| 8 | * This file is part of PolarSSL (http://www.polarssl.org) |
Paul Bakker | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 9 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | b96f154 | 2010-07-18 20:36:00 +0000 | [diff] [blame] | 10 | * |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 11 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 12 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License along |
| 24 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 25 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 27 | #ifndef POLARSSL_RSA_H |
| 28 | #define POLARSSL_RSA_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 29 | |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 30 | #include "config.h" |
| 31 | |
Paul Bakker | 314052f | 2011-08-15 09:07:52 +0000 | [diff] [blame] | 32 | #include "bignum.h" |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 33 | #include "md.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 34 | |
Paul Bakker | c9965dc | 2013-09-29 14:58:17 +0200 | [diff] [blame] | 35 | #if defined(POLARSSL_THREADING_C) |
| 36 | #include "threading.h" |
| 37 | #endif |
| 38 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 39 | /* |
| 40 | * RSA Error codes |
| 41 | */ |
Paul Bakker | 9d78140 | 2011-05-09 16:17:09 +0000 | [diff] [blame] | 42 | #define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */ |
| 43 | #define POLARSSL_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */ |
| 44 | #define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */ |
| 45 | #define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the libraries validity check. */ |
| 46 | #define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */ |
| 47 | #define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */ |
| 48 | #define POLARSSL_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */ |
| 49 | #define POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */ |
| 50 | #define POLARSSL_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 51 | |
| 52 | /* |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 53 | * RSA constants |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 54 | */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 55 | #define RSA_PUBLIC 0 |
| 56 | #define RSA_PRIVATE 1 |
| 57 | |
| 58 | #define RSA_PKCS_V15 0 |
| 59 | #define RSA_PKCS_V21 1 |
| 60 | |
| 61 | #define RSA_SIGN 1 |
| 62 | #define RSA_CRYPT 2 |
| 63 | |
Manuel Pégourié-Gonnard | e511ffc | 2013-08-22 17:33:21 +0200 | [diff] [blame] | 64 | /* |
| 65 | * The above constants may be used even if the RSA module is compile out, |
| 66 | * eg for alternative (PKCS#11) RSA implemenations in the PK layers. |
| 67 | */ |
| 68 | #if defined(POLARSSL_RSA_C) |
| 69 | |
Paul Bakker | 407a0da | 2013-06-27 14:29:21 +0200 | [diff] [blame] | 70 | #ifdef __cplusplus |
| 71 | extern "C" { |
| 72 | #endif |
| 73 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 74 | /** |
| 75 | * \brief RSA context structure |
| 76 | */ |
| 77 | typedef struct |
| 78 | { |
| 79 | int ver; /*!< always 0 */ |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 80 | size_t len; /*!< size(N) in chars */ |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 81 | |
| 82 | mpi N; /*!< public modulus */ |
| 83 | mpi E; /*!< public exponent */ |
| 84 | |
| 85 | mpi D; /*!< private exponent */ |
| 86 | mpi P; /*!< 1st prime factor */ |
| 87 | mpi Q; /*!< 2nd prime factor */ |
| 88 | mpi DP; /*!< D % (P - 1) */ |
| 89 | mpi DQ; /*!< D % (Q - 1) */ |
| 90 | mpi QP; /*!< 1 / (Q % P) */ |
| 91 | |
| 92 | mpi RN; /*!< cached R^2 mod N */ |
| 93 | mpi RP; /*!< cached R^2 mod P */ |
| 94 | mpi RQ; /*!< cached R^2 mod Q */ |
| 95 | |
Manuel Pégourié-Gonnard | ea53a55 | 2013-09-10 13:29:30 +0200 | [diff] [blame] | 96 | #if !defined(POLARSSL_RSA_NO_CRT) |
| 97 | mpi Vi; /*!< cached blinding value */ |
| 98 | mpi Vf; /*!< cached un-blinding value */ |
| 99 | #endif |
| 100 | |
Paul Bakker | 9dcc322 | 2011-03-08 14:16:06 +0000 | [diff] [blame] | 101 | int padding; /*!< RSA_PKCS_V15 for 1.5 padding and |
| 102 | RSA_PKCS_v21 for OAEP/PSS */ |
| 103 | int hash_id; /*!< Hash identifier of md_type_t as |
| 104 | specified in the md.h header file |
| 105 | for the EME-OAEP and EMSA-PSS |
| 106 | encoding */ |
Paul Bakker | c9965dc | 2013-09-29 14:58:17 +0200 | [diff] [blame] | 107 | #if defined(POLARSSL_THREADING_C) |
| 108 | threading_mutex_t mutex; /*!< Thread-safety mutex */ |
| 109 | #endif |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 110 | } |
| 111 | rsa_context; |
| 112 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 113 | /** |
| 114 | * \brief Initialize an RSA context |
| 115 | * |
Paul Bakker | 9a73632 | 2012-11-14 12:39:52 +0000 | [diff] [blame] | 116 | * Note: Set padding to RSA_PKCS_V21 for the RSAES-OAEP |
| 117 | * encryption scheme and the RSASSA-PSS signature scheme. |
| 118 | * |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | * \param ctx RSA context to be initialized |
| 120 | * \param padding RSA_PKCS_V15 or RSA_PKCS_V21 |
| 121 | * \param hash_id RSA_PKCS_V21 hash identifier |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 122 | * |
| 123 | * \note The hash_id parameter is actually ignored |
| 124 | * when using RSA_PKCS_V15 padding. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 125 | */ |
| 126 | void rsa_init( rsa_context *ctx, |
| 127 | int padding, |
Manuel Pégourié-Gonnard | b4fae57 | 2014-01-20 11:22:25 +0100 | [diff] [blame] | 128 | int hash_id ); |
| 129 | |
| 130 | /** |
| 131 | * \brief Set the padding method on an initilized RSA context. |
| 132 | * |
| 133 | * Note: Set padding to RSA_PKCS_V21 for the RSAES-OAEP |
| 134 | * encryption scheme and the RSASSA-PSS signature scheme. |
| 135 | * |
| 136 | * \param ctx RSA context to be set |
| 137 | * \param padding RSA_PKCS_V15 or RSA_PKCS_V21 |
| 138 | * \param hash_id RSA_PKCS_V21 hash identifier |
| 139 | * |
| 140 | * \note The hash_id parameter is actually ignored |
| 141 | * when using RSA_PKCS_V15 padding. |
| 142 | */ |
| 143 | void rsa_set_padding( rsa_context *ctx, |
| 144 | int padding, |
| 145 | int hash_id ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * \brief Generate an RSA keypair |
| 149 | * |
| 150 | * \param ctx RSA context that will hold the key |
Paul Bakker | 21eb280 | 2010-08-16 11:10:02 +0000 | [diff] [blame] | 151 | * \param f_rng RNG function |
| 152 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 153 | * \param nbits size of the public key in bits |
| 154 | * \param exponent public exponent (e.g., 65537) |
| 155 | * |
| 156 | * \note rsa_init() must be called beforehand to setup |
Paul Bakker | 21eb280 | 2010-08-16 11:10:02 +0000 | [diff] [blame] | 157 | * the RSA context. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 158 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 159 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 160 | */ |
Paul Bakker | 21eb280 | 2010-08-16 11:10:02 +0000 | [diff] [blame] | 161 | int rsa_gen_key( rsa_context *ctx, |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 162 | int (*f_rng)(void *, unsigned char *, size_t), |
Paul Bakker | 21eb280 | 2010-08-16 11:10:02 +0000 | [diff] [blame] | 163 | void *p_rng, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 164 | unsigned int nbits, int exponent ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 165 | |
| 166 | /** |
| 167 | * \brief Check a public RSA key |
| 168 | * |
| 169 | * \param ctx RSA context to be checked |
| 170 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 171 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 172 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 173 | int rsa_check_pubkey( const rsa_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 174 | |
| 175 | /** |
| 176 | * \brief Check a private RSA key |
| 177 | * |
| 178 | * \param ctx RSA context to be checked |
| 179 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 180 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 181 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 182 | int rsa_check_privkey( const rsa_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 183 | |
| 184 | /** |
| 185 | * \brief Do an RSA public key operation |
| 186 | * |
| 187 | * \param ctx RSA context |
| 188 | * \param input input buffer |
| 189 | * \param output output buffer |
| 190 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 191 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 192 | * |
| 193 | * \note This function does NOT take care of message |
Paul Bakker | 619467a | 2009-03-28 23:26:51 +0000 | [diff] [blame] | 194 | * padding. Also, be sure to set input[0] = 0 or assure that |
| 195 | * input is smaller than N. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 196 | * |
| 197 | * \note The input and output buffers must be large |
| 198 | * enough (eg. 128 bytes if RSA-1024 is used). |
| 199 | */ |
| 200 | int rsa_public( rsa_context *ctx, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 201 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 202 | unsigned char *output ); |
| 203 | |
| 204 | /** |
| 205 | * \brief Do an RSA private key operation |
| 206 | * |
| 207 | * \param ctx RSA context |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 208 | * \param f_rng RNG function (Needed for blinding) |
| 209 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 210 | * \param input input buffer |
| 211 | * \param output output buffer |
| 212 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 213 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 214 | * |
| 215 | * \note The input and output buffers must be large |
| 216 | * enough (eg. 128 bytes if RSA-1024 is used). |
| 217 | */ |
| 218 | int rsa_private( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 219 | int (*f_rng)(void *, unsigned char *, size_t), |
| 220 | void *p_rng, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 221 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 222 | unsigned char *output ); |
| 223 | |
| 224 | /** |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 225 | * \brief Generic wrapper to perform a PKCS#1 encryption using the |
| 226 | * mode from the context. Add the message padding, then do an |
| 227 | * RSA operation. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 228 | * |
| 229 | * \param ctx RSA context |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 230 | * \param f_rng RNG function (Needed for padding and PKCS#1 v2.1 encoding |
| 231 | * and RSA_PRIVATE) |
Paul Bakker | 21eb280 | 2010-08-16 11:10:02 +0000 | [diff] [blame] | 232 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 233 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | 592457c | 2009-04-01 19:01:43 +0000 | [diff] [blame] | 234 | * \param ilen contains the plaintext length |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 235 | * \param input buffer holding the data to be encrypted |
| 236 | * \param output buffer that will hold the ciphertext |
| 237 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 238 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 239 | * |
| 240 | * \note The output buffer must be as large as the size |
| 241 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 242 | */ |
| 243 | int rsa_pkcs1_encrypt( rsa_context *ctx, |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 244 | int (*f_rng)(void *, unsigned char *, size_t), |
Paul Bakker | 21eb280 | 2010-08-16 11:10:02 +0000 | [diff] [blame] | 245 | void *p_rng, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 246 | int mode, size_t ilen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 247 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 248 | unsigned char *output ); |
| 249 | |
| 250 | /** |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 251 | * \brief Perform a PKCS#1 v1.5 encryption (RSAES-PKCS1-v1_5-ENCRYPT) |
| 252 | * |
| 253 | * \param ctx RSA context |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 254 | * \param f_rng RNG function (Needed for padding and RSA_PRIVATE) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 255 | * \param p_rng RNG parameter |
| 256 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
| 257 | * \param ilen contains the plaintext length |
| 258 | * \param input buffer holding the data to be encrypted |
| 259 | * \param output buffer that will hold the ciphertext |
| 260 | * |
| 261 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
| 262 | * |
| 263 | * \note The output buffer must be as large as the size |
| 264 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 265 | */ |
| 266 | int rsa_rsaes_pkcs1_v15_encrypt( rsa_context *ctx, |
| 267 | int (*f_rng)(void *, unsigned char *, size_t), |
| 268 | void *p_rng, |
| 269 | int mode, size_t ilen, |
| 270 | const unsigned char *input, |
| 271 | unsigned char *output ); |
| 272 | |
| 273 | /** |
| 274 | * \brief Perform a PKCS#1 v2.1 OAEP encryption (RSAES-OAEP-ENCRYPT) |
| 275 | * |
| 276 | * \param ctx RSA context |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 277 | * \param f_rng RNG function (Needed for padding and PKCS#1 v2.1 encoding |
| 278 | * and RSA_PRIVATE) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 279 | * \param p_rng RNG parameter |
| 280 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | a43231c | 2013-02-28 17:33:49 +0100 | [diff] [blame] | 281 | * \param label buffer holding the custom label to use |
| 282 | * \param label_len contains the label length |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 283 | * \param ilen contains the plaintext length |
| 284 | * \param input buffer holding the data to be encrypted |
| 285 | * \param output buffer that will hold the ciphertext |
| 286 | * |
| 287 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
| 288 | * |
| 289 | * \note The output buffer must be as large as the size |
| 290 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 291 | */ |
| 292 | int rsa_rsaes_oaep_encrypt( rsa_context *ctx, |
| 293 | int (*f_rng)(void *, unsigned char *, size_t), |
| 294 | void *p_rng, |
Paul Bakker | a43231c | 2013-02-28 17:33:49 +0100 | [diff] [blame] | 295 | int mode, |
| 296 | const unsigned char *label, size_t label_len, |
| 297 | size_t ilen, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 298 | const unsigned char *input, |
| 299 | unsigned char *output ); |
| 300 | |
| 301 | /** |
| 302 | * \brief Generic wrapper to perform a PKCS#1 decryption using the |
| 303 | * mode from the context. Do an RSA operation, then remove |
| 304 | * the message padding |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 305 | * |
| 306 | * \param ctx RSA context |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 307 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 308 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 309 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | 4d8ca70 | 2011-08-09 10:31:05 +0000 | [diff] [blame] | 310 | * \param olen will contain the plaintext length |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 311 | * \param input buffer holding the encrypted data |
| 312 | * \param output buffer that will hold the plaintext |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 313 | * \param output_max_len maximum length of the output buffer |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 314 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 315 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 316 | * |
| 317 | * \note The output buffer must be as large as the size |
Paul Bakker | 060c568 | 2009-01-12 21:48:39 +0000 | [diff] [blame] | 318 | * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise |
| 319 | * an error is thrown. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 320 | */ |
| 321 | int rsa_pkcs1_decrypt( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 322 | int (*f_rng)(void *, unsigned char *, size_t), |
| 323 | void *p_rng, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 324 | int mode, size_t *olen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 325 | const unsigned char *input, |
Paul Bakker | 060c568 | 2009-01-12 21:48:39 +0000 | [diff] [blame] | 326 | unsigned char *output, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 327 | size_t output_max_len ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 328 | |
| 329 | /** |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 330 | * \brief Perform a PKCS#1 v1.5 decryption (RSAES-PKCS1-v1_5-DECRYPT) |
| 331 | * |
| 332 | * \param ctx RSA context |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 333 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 334 | * \param p_rng RNG parameter |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 335 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
| 336 | * \param olen will contain the plaintext length |
| 337 | * \param input buffer holding the encrypted data |
| 338 | * \param output buffer that will hold the plaintext |
| 339 | * \param output_max_len maximum length of the output buffer |
| 340 | * |
| 341 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
| 342 | * |
| 343 | * \note The output buffer must be as large as the size |
| 344 | * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise |
| 345 | * an error is thrown. |
| 346 | */ |
| 347 | int rsa_rsaes_pkcs1_v15_decrypt( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 348 | int (*f_rng)(void *, unsigned char *, size_t), |
| 349 | void *p_rng, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 350 | int mode, size_t *olen, |
| 351 | const unsigned char *input, |
| 352 | unsigned char *output, |
| 353 | size_t output_max_len ); |
| 354 | |
| 355 | /** |
| 356 | * \brief Perform a PKCS#1 v2.1 OAEP decryption (RSAES-OAEP-DECRYPT) |
| 357 | * |
| 358 | * \param ctx RSA context |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 359 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 360 | * \param p_rng RNG parameter |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 361 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | a43231c | 2013-02-28 17:33:49 +0100 | [diff] [blame] | 362 | * \param label buffer holding the custom label to use |
| 363 | * \param label_len contains the label length |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 364 | * \param olen will contain the plaintext length |
| 365 | * \param input buffer holding the encrypted data |
| 366 | * \param output buffer that will hold the plaintext |
| 367 | * \param output_max_len maximum length of the output buffer |
| 368 | * |
| 369 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
| 370 | * |
| 371 | * \note The output buffer must be as large as the size |
| 372 | * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise |
| 373 | * an error is thrown. |
| 374 | */ |
| 375 | int rsa_rsaes_oaep_decrypt( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 376 | int (*f_rng)(void *, unsigned char *, size_t), |
| 377 | void *p_rng, |
Paul Bakker | a43231c | 2013-02-28 17:33:49 +0100 | [diff] [blame] | 378 | int mode, |
| 379 | const unsigned char *label, size_t label_len, |
| 380 | size_t *olen, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 381 | const unsigned char *input, |
| 382 | unsigned char *output, |
| 383 | size_t output_max_len ); |
| 384 | |
| 385 | /** |
| 386 | * \brief Generic wrapper to perform a PKCS#1 signature using the |
| 387 | * mode from the context. Do a private RSA operation to sign |
| 388 | * a message digest |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 389 | * |
| 390 | * \param ctx RSA context |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 391 | * \param f_rng RNG function (Needed for PKCS#1 v2.1 encoding and for |
| 392 | * RSA_PRIVATE) |
Paul Bakker | 9dcc322 | 2011-03-08 14:16:06 +0000 | [diff] [blame] | 393 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 394 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 395 | * \param md_alg a POLARSSL_MD_* (use POLARSSL_MD_NONE for signing raw data) |
| 396 | * \param hashlen message digest length (for POLARSSL_MD_NONE only) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 397 | * \param hash buffer holding the message digest |
| 398 | * \param sig buffer that will hold the ciphertext |
| 399 | * |
| 400 | * \return 0 if the signing operation was successful, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 401 | * or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 402 | * |
| 403 | * \note The "sig" buffer must be as large as the size |
| 404 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
Paul Bakker | 9dcc322 | 2011-03-08 14:16:06 +0000 | [diff] [blame] | 405 | * |
| 406 | * \note In case of PKCS#1 v2.1 encoding keep in mind that |
| 407 | * the hash_id in the RSA context is the one used for the |
| 408 | * encoding. hash_id in the function call is the type of hash |
| 409 | * that is encoded. According to RFC 3447 it is advised to |
| 410 | * keep both hashes the same. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 411 | */ |
| 412 | int rsa_pkcs1_sign( rsa_context *ctx, |
Paul Bakker | a3d195c | 2011-11-27 21:07:34 +0000 | [diff] [blame] | 413 | int (*f_rng)(void *, unsigned char *, size_t), |
Paul Bakker | 9dcc322 | 2011-03-08 14:16:06 +0000 | [diff] [blame] | 414 | void *p_rng, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 415 | int mode, |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 416 | md_type_t md_alg, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 417 | unsigned int hashlen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 418 | const unsigned char *hash, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 419 | unsigned char *sig ); |
| 420 | |
| 421 | /** |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 422 | * \brief Perform a PKCS#1 v1.5 signature (RSASSA-PKCS1-v1_5-SIGN) |
| 423 | * |
| 424 | * \param ctx RSA context |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 425 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 426 | * \param p_rng RNG parameter |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 427 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 428 | * \param md_alg a POLARSSL_MD_* (use POLARSSL_MD_NONE for signing raw data) |
| 429 | * \param hashlen message digest length (for POLARSSL_MD_NONE only) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 430 | * \param hash buffer holding the message digest |
| 431 | * \param sig buffer that will hold the ciphertext |
| 432 | * |
| 433 | * \return 0 if the signing operation was successful, |
| 434 | * or an POLARSSL_ERR_RSA_XXX error code |
| 435 | * |
| 436 | * \note The "sig" buffer must be as large as the size |
| 437 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 438 | */ |
| 439 | int rsa_rsassa_pkcs1_v15_sign( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 440 | int (*f_rng)(void *, unsigned char *, size_t), |
| 441 | void *p_rng, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 442 | int mode, |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 443 | md_type_t md_alg, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 444 | unsigned int hashlen, |
| 445 | const unsigned char *hash, |
| 446 | unsigned char *sig ); |
| 447 | |
| 448 | /** |
| 449 | * \brief Perform a PKCS#1 v2.1 PSS signature (RSASSA-PSS-SIGN) |
| 450 | * |
| 451 | * \param ctx RSA context |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 452 | * \param f_rng RNG function (Needed for PKCS#1 v2.1 encoding and for |
| 453 | * RSA_PRIVATE) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 454 | * \param p_rng RNG parameter |
| 455 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 456 | * \param md_alg a POLARSSL_MD_* (use POLARSSL_MD_NONE for signing raw data) |
| 457 | * \param hashlen message digest length (for POLARSSL_MD_NONE only) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 458 | * \param hash buffer holding the message digest |
| 459 | * \param sig buffer that will hold the ciphertext |
| 460 | * |
| 461 | * \return 0 if the signing operation was successful, |
| 462 | * or an POLARSSL_ERR_RSA_XXX error code |
| 463 | * |
| 464 | * \note The "sig" buffer must be as large as the size |
| 465 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 466 | * |
| 467 | * \note In case of PKCS#1 v2.1 encoding keep in mind that |
| 468 | * the hash_id in the RSA context is the one used for the |
| 469 | * encoding. hash_id in the function call is the type of hash |
| 470 | * that is encoded. According to RFC 3447 it is advised to |
| 471 | * keep both hashes the same. |
| 472 | */ |
| 473 | int rsa_rsassa_pss_sign( rsa_context *ctx, |
| 474 | int (*f_rng)(void *, unsigned char *, size_t), |
| 475 | void *p_rng, |
| 476 | int mode, |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 477 | md_type_t md_alg, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 478 | unsigned int hashlen, |
| 479 | const unsigned char *hash, |
| 480 | unsigned char *sig ); |
| 481 | |
| 482 | /** |
| 483 | * \brief Generic wrapper to perform a PKCS#1 verification using the |
| 484 | * mode from the context. Do a public RSA operation and check |
| 485 | * the message digest |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 486 | * |
| 487 | * \param ctx points to an RSA public key |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 488 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 489 | * \param p_rng RNG parameter |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 490 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 491 | * \param md_alg a POLARSSL_MD_* (use POLARSSL_MD_NONE for signing raw data) |
| 492 | * \param hashlen message digest length (for POLARSSL_MD_NONE only) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 493 | * \param hash buffer holding the message digest |
| 494 | * \param sig buffer holding the ciphertext |
| 495 | * |
| 496 | * \return 0 if the verify operation was successful, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 497 | * or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 498 | * |
| 499 | * \note The "sig" buffer must be as large as the size |
| 500 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
Paul Bakker | 9dcc322 | 2011-03-08 14:16:06 +0000 | [diff] [blame] | 501 | * |
| 502 | * \note In case of PKCS#1 v2.1 encoding keep in mind that |
| 503 | * the hash_id in the RSA context is the one used for the |
| 504 | * verification. hash_id in the function call is the type of hash |
| 505 | * that is verified. According to RFC 3447 it is advised to |
| 506 | * keep both hashes the same. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 507 | */ |
| 508 | int rsa_pkcs1_verify( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 509 | int (*f_rng)(void *, unsigned char *, size_t), |
| 510 | void *p_rng, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 511 | int mode, |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 512 | md_type_t md_alg, |
Paul Bakker | 23986e5 | 2011-04-24 08:57:21 +0000 | [diff] [blame] | 513 | unsigned int hashlen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 514 | const unsigned char *hash, |
Manuel Pégourié-Gonnard | cc0a9d0 | 2013-08-12 11:34:35 +0200 | [diff] [blame] | 515 | const unsigned char *sig ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 516 | |
| 517 | /** |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 518 | * \brief Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY) |
| 519 | * |
| 520 | * \param ctx points to an RSA public key |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 521 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 522 | * \param p_rng RNG parameter |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 523 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 524 | * \param md_alg a POLARSSL_MD_* (use POLARSSL_MD_NONE for signing raw data) |
| 525 | * \param hashlen message digest length (for POLARSSL_MD_NONE only) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 526 | * \param hash buffer holding the message digest |
| 527 | * \param sig buffer holding the ciphertext |
| 528 | * |
| 529 | * \return 0 if the verify operation was successful, |
| 530 | * or an POLARSSL_ERR_RSA_XXX error code |
| 531 | * |
| 532 | * \note The "sig" buffer must be as large as the size |
| 533 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 534 | */ |
| 535 | int rsa_rsassa_pkcs1_v15_verify( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 536 | int (*f_rng)(void *, unsigned char *, size_t), |
| 537 | void *p_rng, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 538 | int mode, |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 539 | md_type_t md_alg, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 540 | unsigned int hashlen, |
| 541 | const unsigned char *hash, |
Manuel Pégourié-Gonnard | cc0a9d0 | 2013-08-12 11:34:35 +0200 | [diff] [blame] | 542 | const unsigned char *sig ); |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 543 | |
| 544 | /** |
| 545 | * \brief Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 546 | * |
| 547 | * \param ctx points to an RSA public key |
Paul Bakker | f451bac | 2013-08-30 15:37:02 +0200 | [diff] [blame] | 548 | * \param f_rng RNG function (Only needed for RSA_PRIVATE) |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 549 | * \param p_rng RNG parameter |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 550 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 551 | * \param md_alg a POLARSSL_MD_* (use POLARSSL_MD_NONE for signing raw data) |
| 552 | * \param hashlen message digest length (for POLARSSL_MD_NONE only) |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 553 | * \param hash buffer holding the message digest |
| 554 | * \param sig buffer holding the ciphertext |
| 555 | * |
| 556 | * \return 0 if the verify operation was successful, |
| 557 | * or an POLARSSL_ERR_RSA_XXX error code |
| 558 | * |
| 559 | * \note The "sig" buffer must be as large as the size |
| 560 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 561 | * |
| 562 | * \note In case of PKCS#1 v2.1 encoding keep in mind that |
| 563 | * the hash_id in the RSA context is the one used for the |
| 564 | * verification. hash_id in the function call is the type of hash |
| 565 | * that is verified. According to RFC 3447 it is advised to |
| 566 | * keep both hashes the same. |
| 567 | */ |
| 568 | int rsa_rsassa_pss_verify( rsa_context *ctx, |
Paul Bakker | 548957d | 2013-08-30 10:30:02 +0200 | [diff] [blame] | 569 | int (*f_rng)(void *, unsigned char *, size_t), |
| 570 | void *p_rng, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 571 | int mode, |
Paul Bakker | c70b982 | 2013-04-07 22:00:46 +0200 | [diff] [blame] | 572 | md_type_t md_alg, |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 573 | unsigned int hashlen, |
| 574 | const unsigned char *hash, |
Manuel Pégourié-Gonnard | cc0a9d0 | 2013-08-12 11:34:35 +0200 | [diff] [blame] | 575 | const unsigned char *sig ); |
Paul Bakker | b386913 | 2013-02-28 17:21:01 +0100 | [diff] [blame] | 576 | |
| 577 | /** |
Manuel Pégourié-Gonnard | 3053f5b | 2013-08-14 13:39:57 +0200 | [diff] [blame] | 578 | * \brief Copy the components of an RSA context |
| 579 | * |
| 580 | * \param dst Destination context |
| 581 | * \param src Source context |
| 582 | * |
| 583 | * \return O on success, |
| 584 | * POLARSSL_ERR_MPI_MALLOC_FAILED on memory allocation failure |
| 585 | */ |
| 586 | int rsa_copy( rsa_context *dst, const rsa_context *src ); |
| 587 | |
| 588 | /** |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 589 | * \brief Free the components of an RSA key |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 590 | * |
| 591 | * \param ctx RSA Context to free |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 592 | */ |
| 593 | void rsa_free( rsa_context *ctx ); |
| 594 | |
| 595 | /** |
| 596 | * \brief Checkup routine |
| 597 | * |
| 598 | * \return 0 if successful, or 1 if the test failed |
| 599 | */ |
| 600 | int rsa_self_test( int verbose ); |
| 601 | |
| 602 | #ifdef __cplusplus |
| 603 | } |
| 604 | #endif |
| 605 | |
Paul Bakker | ed27a04 | 2013-04-18 22:46:23 +0200 | [diff] [blame] | 606 | #endif /* POLARSSL_RSA_C */ |
| 607 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 608 | #endif /* rsa.h */ |