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