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