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