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 | 84f12b7 | 2010-07-18 10:13:04 +0000 | [diff] [blame] | 4 | * Copyright (C) 2006-2010, Brainspark B.V. |
| 5 | * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org> |
Paul Bakker | 77b385e | 2009-07-28 17:23:11 +0000 | [diff] [blame] | 6 | * All rights reserved. |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 7 | * |
Paul Bakker | e0ccd0a | 2009-01-04 16:27:10 +0000 | [diff] [blame] | 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 20 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 21 | */ |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 22 | #ifndef POLARSSL_RSA_H |
| 23 | #define POLARSSL_RSA_H |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 24 | |
Paul Bakker | 8e831ed | 2009-01-03 21:24:11 +0000 | [diff] [blame] | 25 | #include "polarssl/bignum.h" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 26 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 27 | /* |
| 28 | * RSA Error codes |
| 29 | */ |
Paul Bakker | 3391b12 | 2009-07-28 20:11:54 +0000 | [diff] [blame] | 30 | #define POLARSSL_ERR_RSA_BAD_INPUT_DATA -0x0400 |
| 31 | #define POLARSSL_ERR_RSA_INVALID_PADDING -0x0410 |
| 32 | #define POLARSSL_ERR_RSA_KEY_GEN_FAILED -0x0420 |
| 33 | #define POLARSSL_ERR_RSA_KEY_CHECK_FAILED -0x0430 |
| 34 | #define POLARSSL_ERR_RSA_PUBLIC_FAILED -0x0440 |
| 35 | #define POLARSSL_ERR_RSA_PRIVATE_FAILED -0x0450 |
| 36 | #define POLARSSL_ERR_RSA_VERIFY_FAILED -0x0460 |
| 37 | #define POLARSSL_ERR_RSA_OUTPUT_TOO_LARGE -0x0470 |
Paul Bakker | b572adf | 2010-07-18 08:29:32 +0000 | [diff] [blame] | 38 | #define POLARSSL_ERR_RSA_RNG_FAILED -0x0480 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 39 | |
| 40 | /* |
| 41 | * PKCS#1 constants |
| 42 | */ |
Paul Bakker | fc22c44 | 2009-07-19 20:36:27 +0000 | [diff] [blame] | 43 | #define SIG_RSA_RAW 0 |
| 44 | #define SIG_RSA_MD2 2 |
| 45 | #define SIG_RSA_MD4 3 |
| 46 | #define SIG_RSA_MD5 4 |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 47 | #define SIG_RSA_SHA1 5 |
| 48 | #define SIG_RSA_SHA224 14 |
| 49 | #define SIG_RSA_SHA256 11 |
| 50 | #define SIG_RSA_SHA384 12 |
| 51 | #define SIG_RSA_SHA512 13 |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 52 | |
| 53 | #define RSA_PUBLIC 0 |
| 54 | #define RSA_PRIVATE 1 |
| 55 | |
| 56 | #define RSA_PKCS_V15 0 |
| 57 | #define RSA_PKCS_V21 1 |
| 58 | |
| 59 | #define RSA_SIGN 1 |
| 60 | #define RSA_CRYPT 2 |
| 61 | |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 62 | #define ASN1_STR_CONSTRUCTED_SEQUENCE "\x30" |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 63 | #define ASN1_STR_NULL "\x05" |
| 64 | #define ASN1_STR_OID "\x06" |
| 65 | #define ASN1_STR_OCTET_STRING "\x04" |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 66 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 67 | #define OID_DIGEST_ALG_MDX "\x2A\x86\x48\x86\xF7\x0D\x02\x00" |
| 68 | #define OID_HASH_ALG_SHA1 "\x2b\x0e\x03\x02\x1a" |
| 69 | #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] | 70 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 71 | #define OID_ISO_MEMBER_BODIES "\x2a" |
| 72 | #define OID_ISO_IDENTIFIED_ORG "\x2b" |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 73 | |
| 74 | /* |
| 75 | * ISO Member bodies OID parts |
| 76 | */ |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 77 | #define OID_COUNTRY_US "\x86\x48" |
| 78 | #define OID_RSA_DATA_SECURITY "\x86\xf7\x0d" |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | * ISO Identified organization OID parts |
| 82 | */ |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 83 | #define OID_OIW_SECSIG_SHA1 "\x0e\x03\x02\x1a" |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 84 | |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 85 | /* |
| 86 | * DigestInfo ::= SEQUENCE { |
| 87 | * digestAlgorithm DigestAlgorithmIdentifier, |
| 88 | * digest Digest } |
| 89 | * |
| 90 | * DigestAlgorithmIdentifier ::= AlgorithmIdentifier |
| 91 | * |
| 92 | * Digest ::= OCTET STRING |
| 93 | */ |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 94 | #define ASN1_HASH_MDX \ |
| 95 | ( \ |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 96 | ASN1_STR_CONSTRUCTED_SEQUENCE "\x20" \ |
| 97 | ASN1_STR_CONSTRUCTED_SEQUENCE "\x0C" \ |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 98 | ASN1_STR_OID "\x08" \ |
| 99 | OID_DIGEST_ALG_MDX \ |
| 100 | ASN1_STR_NULL "\x00" \ |
| 101 | ASN1_STR_OCTET_STRING "\x10" \ |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 102 | ) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 103 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 104 | #define ASN1_HASH_SHA1 \ |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 105 | ASN1_STR_CONSTRUCTED_SEQUENCE "\x21" \ |
| 106 | ASN1_STR_CONSTRUCTED_SEQUENCE "\x09" \ |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 107 | ASN1_STR_OID "\x05" \ |
| 108 | OID_HASH_ALG_SHA1 \ |
| 109 | ASN1_STR_NULL "\x00" \ |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 110 | ASN1_STR_OCTET_STRING "\x14" |
| 111 | |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 112 | #define ASN1_HASH_SHA2X \ |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 113 | ASN1_STR_CONSTRUCTED_SEQUENCE "\x11" \ |
| 114 | ASN1_STR_CONSTRUCTED_SEQUENCE "\x0d" \ |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 115 | ASN1_STR_OID "\x09" \ |
| 116 | OID_HASH_ALG_SHA2X \ |
| 117 | ASN1_STR_NULL "\x00" \ |
Paul Bakker | 4593aea | 2009-02-09 22:32:35 +0000 | [diff] [blame] | 118 | ASN1_STR_OCTET_STRING "\x00" |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 119 | |
| 120 | /** |
| 121 | * \brief RSA context structure |
| 122 | */ |
| 123 | typedef struct |
| 124 | { |
| 125 | int ver; /*!< always 0 */ |
| 126 | int len; /*!< size(N) in chars */ |
| 127 | |
| 128 | mpi N; /*!< public modulus */ |
| 129 | mpi E; /*!< public exponent */ |
| 130 | |
| 131 | mpi D; /*!< private exponent */ |
| 132 | mpi P; /*!< 1st prime factor */ |
| 133 | mpi Q; /*!< 2nd prime factor */ |
| 134 | mpi DP; /*!< D % (P - 1) */ |
| 135 | mpi DQ; /*!< D % (Q - 1) */ |
| 136 | mpi QP; /*!< 1 / (Q % P) */ |
| 137 | |
| 138 | mpi RN; /*!< cached R^2 mod N */ |
| 139 | mpi RP; /*!< cached R^2 mod P */ |
| 140 | mpi RQ; /*!< cached R^2 mod Q */ |
| 141 | |
| 142 | int padding; /*!< 1.5 or OAEP/PSS */ |
| 143 | int hash_id; /*!< hash identifier */ |
| 144 | int (*f_rng)(void *); /*!< RNG function */ |
| 145 | void *p_rng; /*!< RNG parameter */ |
| 146 | } |
| 147 | rsa_context; |
| 148 | |
| 149 | #ifdef __cplusplus |
| 150 | extern "C" { |
| 151 | #endif |
| 152 | |
| 153 | /** |
| 154 | * \brief Initialize an RSA context |
| 155 | * |
| 156 | * \param ctx RSA context to be initialized |
| 157 | * \param padding RSA_PKCS_V15 or RSA_PKCS_V21 |
| 158 | * \param hash_id RSA_PKCS_V21 hash identifier |
| 159 | * \param f_rng RNG function |
| 160 | * \param p_rng RNG parameter |
| 161 | * |
| 162 | * \note The hash_id parameter is actually ignored |
| 163 | * when using RSA_PKCS_V15 padding. |
| 164 | * |
Paul Bakker | c38b2f5 | 2010-07-18 10:06:45 +0000 | [diff] [blame] | 165 | * \note Currently, RSA_PKCS_V21 padding |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 166 | * is not supported. |
| 167 | */ |
| 168 | void rsa_init( rsa_context *ctx, |
| 169 | int padding, |
| 170 | int hash_id, |
| 171 | int (*f_rng)(void *), |
| 172 | void *p_rng ); |
| 173 | |
| 174 | /** |
| 175 | * \brief Generate an RSA keypair |
| 176 | * |
| 177 | * \param ctx RSA context that will hold the key |
| 178 | * \param nbits size of the public key in bits |
| 179 | * \param exponent public exponent (e.g., 65537) |
| 180 | * |
| 181 | * \note rsa_init() must be called beforehand to setup |
| 182 | * the RSA context (especially f_rng and p_rng). |
| 183 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 184 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 185 | */ |
| 186 | int rsa_gen_key( rsa_context *ctx, int nbits, int exponent ); |
| 187 | |
| 188 | /** |
| 189 | * \brief Check a public RSA key |
| 190 | * |
| 191 | * \param ctx RSA context to be checked |
| 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 | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 195 | int rsa_check_pubkey( const rsa_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 196 | |
| 197 | /** |
| 198 | * \brief Check a private RSA key |
| 199 | * |
| 200 | * \param ctx RSA context to be checked |
| 201 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 202 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 203 | */ |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 204 | int rsa_check_privkey( const rsa_context *ctx ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 205 | |
| 206 | /** |
| 207 | * \brief Do an RSA public key operation |
| 208 | * |
| 209 | * \param ctx RSA context |
| 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 This function does NOT take care of message |
Paul Bakker | 619467a | 2009-03-28 23:26:51 +0000 | [diff] [blame] | 216 | * padding. Also, be sure to set input[0] = 0 or assure that |
| 217 | * input is smaller than N. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 218 | * |
| 219 | * \note The input and output buffers must be large |
| 220 | * enough (eg. 128 bytes if RSA-1024 is used). |
| 221 | */ |
| 222 | int rsa_public( rsa_context *ctx, |
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 | /** |
| 227 | * \brief Do an RSA private key operation |
| 228 | * |
| 229 | * \param ctx RSA context |
| 230 | * \param input input buffer |
| 231 | * \param output output buffer |
| 232 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 233 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 234 | * |
| 235 | * \note The input and output buffers must be large |
| 236 | * enough (eg. 128 bytes if RSA-1024 is used). |
| 237 | */ |
| 238 | int rsa_private( rsa_context *ctx, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 239 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 240 | unsigned char *output ); |
| 241 | |
| 242 | /** |
| 243 | * \brief Add the message padding, then do an RSA operation |
| 244 | * |
| 245 | * \param ctx RSA context |
| 246 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | 592457c | 2009-04-01 19:01:43 +0000 | [diff] [blame] | 247 | * \param ilen contains the plaintext length |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 248 | * \param input buffer holding the data to be encrypted |
| 249 | * \param output buffer that will hold the ciphertext |
| 250 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 251 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 252 | * |
| 253 | * \note The output buffer must be as large as the size |
| 254 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 255 | */ |
| 256 | int rsa_pkcs1_encrypt( rsa_context *ctx, |
| 257 | int mode, int ilen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 258 | const unsigned char *input, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 259 | unsigned char *output ); |
| 260 | |
| 261 | /** |
| 262 | * \brief Do an RSA operation, then remove the message padding |
| 263 | * |
| 264 | * \param ctx RSA context |
| 265 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
| 266 | * \param input buffer holding the encrypted data |
| 267 | * \param output buffer that will hold the plaintext |
| 268 | * \param olen will contain the plaintext length |
Paul Bakker | 060c568 | 2009-01-12 21:48:39 +0000 | [diff] [blame] | 269 | * \param output_max_len maximum length of the output buffer |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 270 | * |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 271 | * \return 0 if successful, or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 272 | * |
| 273 | * \note The output buffer must be as large as the size |
Paul Bakker | 060c568 | 2009-01-12 21:48:39 +0000 | [diff] [blame] | 274 | * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise |
| 275 | * an error is thrown. |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 276 | */ |
| 277 | int rsa_pkcs1_decrypt( rsa_context *ctx, |
| 278 | int mode, int *olen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 279 | const unsigned char *input, |
Paul Bakker | 060c568 | 2009-01-12 21:48:39 +0000 | [diff] [blame] | 280 | unsigned char *output, |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 281 | int output_max_len ); |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 282 | |
| 283 | /** |
| 284 | * \brief Do a private RSA to sign a message digest |
| 285 | * |
| 286 | * \param ctx RSA context |
| 287 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | fc22c44 | 2009-07-19 20:36:27 +0000 | [diff] [blame] | 288 | * \param hash_id SIG_RSA_RAW, SIG_RSA_MD{2,4,5} or SIG_RSA_SHA{1,224,256,384,512} |
| 289 | * \param hashlen message digest length (for SIG_RSA_RAW only) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 290 | * \param hash buffer holding the message digest |
| 291 | * \param sig buffer that will hold the ciphertext |
| 292 | * |
| 293 | * \return 0 if the signing operation was successful, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 294 | * or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 295 | * |
| 296 | * \note The "sig" buffer must be as large as the size |
| 297 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 298 | */ |
| 299 | int rsa_pkcs1_sign( rsa_context *ctx, |
| 300 | int mode, |
| 301 | int hash_id, |
| 302 | int hashlen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 303 | const unsigned char *hash, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 304 | unsigned char *sig ); |
| 305 | |
| 306 | /** |
| 307 | * \brief Do a public RSA and check the message digest |
| 308 | * |
| 309 | * \param ctx points to an RSA public key |
| 310 | * \param mode RSA_PUBLIC or RSA_PRIVATE |
Paul Bakker | b924f04 | 2010-07-18 08:49:19 +0000 | [diff] [blame] | 311 | * \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] | 312 | * \param hashlen message digest length (for SIG_RSA_RAW only) |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 313 | * \param hash buffer holding the message digest |
| 314 | * \param sig buffer holding the ciphertext |
| 315 | * |
| 316 | * \return 0 if the verify operation was successful, |
Paul Bakker | 40e4694 | 2009-01-03 21:51:57 +0000 | [diff] [blame] | 317 | * or an POLARSSL_ERR_RSA_XXX error code |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 318 | * |
| 319 | * \note The "sig" buffer must be as large as the size |
| 320 | * of ctx->N (eg. 128 bytes if RSA-1024 is used). |
| 321 | */ |
| 322 | int rsa_pkcs1_verify( rsa_context *ctx, |
| 323 | int mode, |
| 324 | int hash_id, |
| 325 | int hashlen, |
Paul Bakker | ff60ee6 | 2010-03-16 21:09:09 +0000 | [diff] [blame] | 326 | const unsigned char *hash, |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 327 | unsigned char *sig ); |
| 328 | |
| 329 | /** |
| 330 | * \brief Free the components of an RSA key |
Paul Bakker | 13e2dfe | 2009-07-28 07:18:38 +0000 | [diff] [blame] | 331 | * |
| 332 | * \param ctx RSA Context to free |
Paul Bakker | 5121ce5 | 2009-01-03 21:22:43 +0000 | [diff] [blame] | 333 | */ |
| 334 | void rsa_free( rsa_context *ctx ); |
| 335 | |
| 336 | /** |
| 337 | * \brief Checkup routine |
| 338 | * |
| 339 | * \return 0 if successful, or 1 if the test failed |
| 340 | */ |
| 341 | int rsa_self_test( int verbose ); |
| 342 | |
| 343 | #ifdef __cplusplus |
| 344 | } |
| 345 | #endif |
| 346 | |
| 347 | #endif /* rsa.h */ |