mbed client on ethernet with LWIP

Dependencies:   mbed Socket lwip-eth lwip-sys lwip

Fork of mbed-client-classic-example-lwip by sandbox

Committer:
mbedAustin
Date:
Thu Jun 09 17:08:36 2016 +0000
Revision:
11:cada08fc8a70
Commit for public Consumption

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbedAustin 11:cada08fc8a70 1 /**
mbedAustin 11:cada08fc8a70 2 * \file rsa.h
mbedAustin 11:cada08fc8a70 3 *
mbedAustin 11:cada08fc8a70 4 * \brief The RSA public-key cryptosystem
mbedAustin 11:cada08fc8a70 5 *
mbedAustin 11:cada08fc8a70 6 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
mbedAustin 11:cada08fc8a70 7 * SPDX-License-Identifier: Apache-2.0
mbedAustin 11:cada08fc8a70 8 *
mbedAustin 11:cada08fc8a70 9 * Licensed under the Apache License, Version 2.0 (the "License"); you may
mbedAustin 11:cada08fc8a70 10 * not use this file except in compliance with the License.
mbedAustin 11:cada08fc8a70 11 * You may obtain a copy of the License at
mbedAustin 11:cada08fc8a70 12 *
mbedAustin 11:cada08fc8a70 13 * http://www.apache.org/licenses/LICENSE-2.0
mbedAustin 11:cada08fc8a70 14 *
mbedAustin 11:cada08fc8a70 15 * Unless required by applicable law or agreed to in writing, software
mbedAustin 11:cada08fc8a70 16 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
mbedAustin 11:cada08fc8a70 17 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
mbedAustin 11:cada08fc8a70 18 * See the License for the specific language governing permissions and
mbedAustin 11:cada08fc8a70 19 * limitations under the License.
mbedAustin 11:cada08fc8a70 20 *
mbedAustin 11:cada08fc8a70 21 * This file is part of mbed TLS (https://tls.mbed.org)
mbedAustin 11:cada08fc8a70 22 */
mbedAustin 11:cada08fc8a70 23 #ifndef MBEDTLS_RSA_H
mbedAustin 11:cada08fc8a70 24 #define MBEDTLS_RSA_H
mbedAustin 11:cada08fc8a70 25
mbedAustin 11:cada08fc8a70 26 #if !defined(MBEDTLS_CONFIG_FILE)
mbedAustin 11:cada08fc8a70 27 #include "config.h"
mbedAustin 11:cada08fc8a70 28 #else
mbedAustin 11:cada08fc8a70 29 #include MBEDTLS_CONFIG_FILE
mbedAustin 11:cada08fc8a70 30 #endif
mbedAustin 11:cada08fc8a70 31
mbedAustin 11:cada08fc8a70 32 #include "bignum.h"
mbedAustin 11:cada08fc8a70 33 #include "md.h"
mbedAustin 11:cada08fc8a70 34
mbedAustin 11:cada08fc8a70 35 #if defined(MBEDTLS_THREADING_C)
mbedAustin 11:cada08fc8a70 36 #include "threading.h"
mbedAustin 11:cada08fc8a70 37 #endif
mbedAustin 11:cada08fc8a70 38
mbedAustin 11:cada08fc8a70 39 /*
mbedAustin 11:cada08fc8a70 40 * RSA Error codes
mbedAustin 11:cada08fc8a70 41 */
mbedAustin 11:cada08fc8a70 42 #define MBEDTLS_ERR_RSA_BAD_INPUT_DATA -0x4080 /**< Bad input parameters to function. */
mbedAustin 11:cada08fc8a70 43 #define MBEDTLS_ERR_RSA_INVALID_PADDING -0x4100 /**< Input data contains invalid padding and is rejected. */
mbedAustin 11:cada08fc8a70 44 #define MBEDTLS_ERR_RSA_KEY_GEN_FAILED -0x4180 /**< Something failed during generation of a key. */
mbedAustin 11:cada08fc8a70 45 #define MBEDTLS_ERR_RSA_KEY_CHECK_FAILED -0x4200 /**< Key failed to pass the library's validity check. */
mbedAustin 11:cada08fc8a70 46 #define MBEDTLS_ERR_RSA_PUBLIC_FAILED -0x4280 /**< The public key operation failed. */
mbedAustin 11:cada08fc8a70 47 #define MBEDTLS_ERR_RSA_PRIVATE_FAILED -0x4300 /**< The private key operation failed. */
mbedAustin 11:cada08fc8a70 48 #define MBEDTLS_ERR_RSA_VERIFY_FAILED -0x4380 /**< The PKCS#1 verification failed. */
mbedAustin 11:cada08fc8a70 49 #define MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE -0x4400 /**< The output buffer for decryption is not large enough. */
mbedAustin 11:cada08fc8a70 50 #define MBEDTLS_ERR_RSA_RNG_FAILED -0x4480 /**< The random generator failed to generate non-zeros. */
mbedAustin 11:cada08fc8a70 51
mbedAustin 11:cada08fc8a70 52 /*
mbedAustin 11:cada08fc8a70 53 * RSA constants
mbedAustin 11:cada08fc8a70 54 */
mbedAustin 11:cada08fc8a70 55 #define MBEDTLS_RSA_PUBLIC 0
mbedAustin 11:cada08fc8a70 56 #define MBEDTLS_RSA_PRIVATE 1
mbedAustin 11:cada08fc8a70 57
mbedAustin 11:cada08fc8a70 58 #define MBEDTLS_RSA_PKCS_V15 0
mbedAustin 11:cada08fc8a70 59 #define MBEDTLS_RSA_PKCS_V21 1
mbedAustin 11:cada08fc8a70 60
mbedAustin 11:cada08fc8a70 61 #define MBEDTLS_RSA_SIGN 1
mbedAustin 11:cada08fc8a70 62 #define MBEDTLS_RSA_CRYPT 2
mbedAustin 11:cada08fc8a70 63
mbedAustin 11:cada08fc8a70 64 #define MBEDTLS_RSA_SALT_LEN_ANY -1
mbedAustin 11:cada08fc8a70 65
mbedAustin 11:cada08fc8a70 66 /*
mbedAustin 11:cada08fc8a70 67 * The above constants may be used even if the RSA module is compile out,
mbedAustin 11:cada08fc8a70 68 * eg for alternative (PKCS#11) RSA implemenations in the PK layers.
mbedAustin 11:cada08fc8a70 69 */
mbedAustin 11:cada08fc8a70 70 #if defined(MBEDTLS_RSA_C)
mbedAustin 11:cada08fc8a70 71
mbedAustin 11:cada08fc8a70 72 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 73 extern "C" {
mbedAustin 11:cada08fc8a70 74 #endif
mbedAustin 11:cada08fc8a70 75
mbedAustin 11:cada08fc8a70 76 /**
mbedAustin 11:cada08fc8a70 77 * \brief RSA context structure
mbedAustin 11:cada08fc8a70 78 */
mbedAustin 11:cada08fc8a70 79 typedef struct
mbedAustin 11:cada08fc8a70 80 {
mbedAustin 11:cada08fc8a70 81 int ver; /*!< always 0 */
mbedAustin 11:cada08fc8a70 82 size_t len; /*!< size(N) in chars */
mbedAustin 11:cada08fc8a70 83
mbedAustin 11:cada08fc8a70 84 mbedtls_mpi N; /*!< public modulus */
mbedAustin 11:cada08fc8a70 85 mbedtls_mpi E; /*!< public exponent */
mbedAustin 11:cada08fc8a70 86
mbedAustin 11:cada08fc8a70 87 mbedtls_mpi D; /*!< private exponent */
mbedAustin 11:cada08fc8a70 88 mbedtls_mpi P; /*!< 1st prime factor */
mbedAustin 11:cada08fc8a70 89 mbedtls_mpi Q; /*!< 2nd prime factor */
mbedAustin 11:cada08fc8a70 90 mbedtls_mpi DP; /*!< D % (P - 1) */
mbedAustin 11:cada08fc8a70 91 mbedtls_mpi DQ; /*!< D % (Q - 1) */
mbedAustin 11:cada08fc8a70 92 mbedtls_mpi QP; /*!< 1 / (Q % P) */
mbedAustin 11:cada08fc8a70 93
mbedAustin 11:cada08fc8a70 94 mbedtls_mpi RN; /*!< cached R^2 mod N */
mbedAustin 11:cada08fc8a70 95 mbedtls_mpi RP; /*!< cached R^2 mod P */
mbedAustin 11:cada08fc8a70 96 mbedtls_mpi RQ; /*!< cached R^2 mod Q */
mbedAustin 11:cada08fc8a70 97
mbedAustin 11:cada08fc8a70 98 mbedtls_mpi Vi; /*!< cached blinding value */
mbedAustin 11:cada08fc8a70 99 mbedtls_mpi Vf; /*!< cached un-blinding value */
mbedAustin 11:cada08fc8a70 100
mbedAustin 11:cada08fc8a70 101 int padding; /*!< MBEDTLS_RSA_PKCS_V15 for 1.5 padding and
mbedAustin 11:cada08fc8a70 102 RSA_PKCS_v21 for OAEP/PSS */
mbedAustin 11:cada08fc8a70 103 int hash_id; /*!< Hash identifier of mbedtls_md_type_t as
mbedAustin 11:cada08fc8a70 104 specified in the mbedtls_md.h header file
mbedAustin 11:cada08fc8a70 105 for the EME-OAEP and EMSA-PSS
mbedAustin 11:cada08fc8a70 106 encoding */
mbedAustin 11:cada08fc8a70 107 #if defined(MBEDTLS_THREADING_C)
mbedAustin 11:cada08fc8a70 108 mbedtls_threading_mutex_t mutex; /*!< Thread-safety mutex */
mbedAustin 11:cada08fc8a70 109 #endif
mbedAustin 11:cada08fc8a70 110 }
mbedAustin 11:cada08fc8a70 111 mbedtls_rsa_context;
mbedAustin 11:cada08fc8a70 112
mbedAustin 11:cada08fc8a70 113 /**
mbedAustin 11:cada08fc8a70 114 * \brief Initialize an RSA context
mbedAustin 11:cada08fc8a70 115 *
mbedAustin 11:cada08fc8a70 116 * Note: Set padding to MBEDTLS_RSA_PKCS_V21 for the RSAES-OAEP
mbedAustin 11:cada08fc8a70 117 * encryption scheme and the RSASSA-PSS signature scheme.
mbedAustin 11:cada08fc8a70 118 *
mbedAustin 11:cada08fc8a70 119 * \param ctx RSA context to be initialized
mbedAustin 11:cada08fc8a70 120 * \param padding MBEDTLS_RSA_PKCS_V15 or MBEDTLS_RSA_PKCS_V21
mbedAustin 11:cada08fc8a70 121 * \param hash_id MBEDTLS_RSA_PKCS_V21 hash identifier
mbedAustin 11:cada08fc8a70 122 *
mbedAustin 11:cada08fc8a70 123 * \note The hash_id parameter is actually ignored
mbedAustin 11:cada08fc8a70 124 * when using MBEDTLS_RSA_PKCS_V15 padding.
mbedAustin 11:cada08fc8a70 125 *
mbedAustin 11:cada08fc8a70 126 * \note Choice of padding mode is strictly enforced for private key
mbedAustin 11:cada08fc8a70 127 * operations, since there might be security concerns in
mbedAustin 11:cada08fc8a70 128 * mixing padding modes. For public key operations it's merely
mbedAustin 11:cada08fc8a70 129 * a default value, which can be overriden by calling specific
mbedAustin 11:cada08fc8a70 130 * rsa_rsaes_xxx or rsa_rsassa_xxx functions.
mbedAustin 11:cada08fc8a70 131 *
mbedAustin 11:cada08fc8a70 132 * \note The chosen hash is always used for OEAP encryption.
mbedAustin 11:cada08fc8a70 133 * For PSS signatures, it's always used for making signatures,
mbedAustin 11:cada08fc8a70 134 * but can be overriden (and always is, if set to
mbedAustin 11:cada08fc8a70 135 * MBEDTLS_MD_NONE) for verifying them.
mbedAustin 11:cada08fc8a70 136 */
mbedAustin 11:cada08fc8a70 137 void mbedtls_rsa_init( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 138 int padding,
mbedAustin 11:cada08fc8a70 139 int hash_id);
mbedAustin 11:cada08fc8a70 140
mbedAustin 11:cada08fc8a70 141 /**
mbedAustin 11:cada08fc8a70 142 * \brief Set padding for an already initialized RSA context
mbedAustin 11:cada08fc8a70 143 * See \c mbedtls_rsa_init() for details.
mbedAustin 11:cada08fc8a70 144 *
mbedAustin 11:cada08fc8a70 145 * \param ctx RSA context to be set
mbedAustin 11:cada08fc8a70 146 * \param padding MBEDTLS_RSA_PKCS_V15 or MBEDTLS_RSA_PKCS_V21
mbedAustin 11:cada08fc8a70 147 * \param hash_id MBEDTLS_RSA_PKCS_V21 hash identifier
mbedAustin 11:cada08fc8a70 148 */
mbedAustin 11:cada08fc8a70 149 void mbedtls_rsa_set_padding( mbedtls_rsa_context *ctx, int padding, int hash_id);
mbedAustin 11:cada08fc8a70 150
mbedAustin 11:cada08fc8a70 151 /**
mbedAustin 11:cada08fc8a70 152 * \brief Generate an RSA keypair
mbedAustin 11:cada08fc8a70 153 *
mbedAustin 11:cada08fc8a70 154 * \param ctx RSA context that will hold the key
mbedAustin 11:cada08fc8a70 155 * \param f_rng RNG function
mbedAustin 11:cada08fc8a70 156 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 157 * \param nbits size of the public key in bits
mbedAustin 11:cada08fc8a70 158 * \param exponent public exponent (e.g., 65537)
mbedAustin 11:cada08fc8a70 159 *
mbedAustin 11:cada08fc8a70 160 * \note mbedtls_rsa_init() must be called beforehand to setup
mbedAustin 11:cada08fc8a70 161 * the RSA context.
mbedAustin 11:cada08fc8a70 162 *
mbedAustin 11:cada08fc8a70 163 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 164 */
mbedAustin 11:cada08fc8a70 165 int mbedtls_rsa_gen_key( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 166 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 167 void *p_rng,
mbedAustin 11:cada08fc8a70 168 unsigned int nbits, int exponent );
mbedAustin 11:cada08fc8a70 169
mbedAustin 11:cada08fc8a70 170 /**
mbedAustin 11:cada08fc8a70 171 * \brief Check a public RSA key
mbedAustin 11:cada08fc8a70 172 *
mbedAustin 11:cada08fc8a70 173 * \param ctx RSA context to be checked
mbedAustin 11:cada08fc8a70 174 *
mbedAustin 11:cada08fc8a70 175 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 176 */
mbedAustin 11:cada08fc8a70 177 int mbedtls_rsa_check_pubkey( const mbedtls_rsa_context *ctx );
mbedAustin 11:cada08fc8a70 178
mbedAustin 11:cada08fc8a70 179 /**
mbedAustin 11:cada08fc8a70 180 * \brief Check a private RSA key
mbedAustin 11:cada08fc8a70 181 *
mbedAustin 11:cada08fc8a70 182 * \param ctx RSA context to be checked
mbedAustin 11:cada08fc8a70 183 *
mbedAustin 11:cada08fc8a70 184 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 185 */
mbedAustin 11:cada08fc8a70 186 int mbedtls_rsa_check_privkey( const mbedtls_rsa_context *ctx );
mbedAustin 11:cada08fc8a70 187
mbedAustin 11:cada08fc8a70 188 /**
mbedAustin 11:cada08fc8a70 189 * \brief Check a public-private RSA key pair.
mbedAustin 11:cada08fc8a70 190 * Check each of the contexts, and make sure they match.
mbedAustin 11:cada08fc8a70 191 *
mbedAustin 11:cada08fc8a70 192 * \param pub RSA context holding the public key
mbedAustin 11:cada08fc8a70 193 * \param prv RSA context holding the private key
mbedAustin 11:cada08fc8a70 194 *
mbedAustin 11:cada08fc8a70 195 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 196 */
mbedAustin 11:cada08fc8a70 197 int mbedtls_rsa_check_pub_priv( const mbedtls_rsa_context *pub, const mbedtls_rsa_context *prv );
mbedAustin 11:cada08fc8a70 198
mbedAustin 11:cada08fc8a70 199 /**
mbedAustin 11:cada08fc8a70 200 * \brief Do an RSA public key operation
mbedAustin 11:cada08fc8a70 201 *
mbedAustin 11:cada08fc8a70 202 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 203 * \param input input buffer
mbedAustin 11:cada08fc8a70 204 * \param output output buffer
mbedAustin 11:cada08fc8a70 205 *
mbedAustin 11:cada08fc8a70 206 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 207 *
mbedAustin 11:cada08fc8a70 208 * \note This function does NOT take care of message
mbedAustin 11:cada08fc8a70 209 * padding. Also, be sure to set input[0] = 0 or assure that
mbedAustin 11:cada08fc8a70 210 * input is smaller than N.
mbedAustin 11:cada08fc8a70 211 *
mbedAustin 11:cada08fc8a70 212 * \note The input and output buffers must be large
mbedAustin 11:cada08fc8a70 213 * enough (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 214 */
mbedAustin 11:cada08fc8a70 215 int mbedtls_rsa_public( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 216 const unsigned char *input,
mbedAustin 11:cada08fc8a70 217 unsigned char *output );
mbedAustin 11:cada08fc8a70 218
mbedAustin 11:cada08fc8a70 219 /**
mbedAustin 11:cada08fc8a70 220 * \brief Do an RSA private key operation
mbedAustin 11:cada08fc8a70 221 *
mbedAustin 11:cada08fc8a70 222 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 223 * \param f_rng RNG function (Needed for blinding)
mbedAustin 11:cada08fc8a70 224 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 225 * \param input input buffer
mbedAustin 11:cada08fc8a70 226 * \param output output buffer
mbedAustin 11:cada08fc8a70 227 *
mbedAustin 11:cada08fc8a70 228 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 229 *
mbedAustin 11:cada08fc8a70 230 * \note The input and output buffers must be large
mbedAustin 11:cada08fc8a70 231 * enough (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 232 */
mbedAustin 11:cada08fc8a70 233 int mbedtls_rsa_private( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 234 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 235 void *p_rng,
mbedAustin 11:cada08fc8a70 236 const unsigned char *input,
mbedAustin 11:cada08fc8a70 237 unsigned char *output );
mbedAustin 11:cada08fc8a70 238
mbedAustin 11:cada08fc8a70 239 /**
mbedAustin 11:cada08fc8a70 240 * \brief Generic wrapper to perform a PKCS#1 encryption using the
mbedAustin 11:cada08fc8a70 241 * mode from the context. Add the message padding, then do an
mbedAustin 11:cada08fc8a70 242 * RSA operation.
mbedAustin 11:cada08fc8a70 243 *
mbedAustin 11:cada08fc8a70 244 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 245 * \param f_rng RNG function (Needed for padding and PKCS#1 v2.1 encoding
mbedAustin 11:cada08fc8a70 246 * and MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 247 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 248 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 249 * \param ilen contains the plaintext length
mbedAustin 11:cada08fc8a70 250 * \param input buffer holding the data to be encrypted
mbedAustin 11:cada08fc8a70 251 * \param output buffer that will hold the ciphertext
mbedAustin 11:cada08fc8a70 252 *
mbedAustin 11:cada08fc8a70 253 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 254 *
mbedAustin 11:cada08fc8a70 255 * \note The output buffer must be as large as the size
mbedAustin 11:cada08fc8a70 256 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 257 */
mbedAustin 11:cada08fc8a70 258 int mbedtls_rsa_pkcs1_encrypt( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 259 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 260 void *p_rng,
mbedAustin 11:cada08fc8a70 261 int mode, size_t ilen,
mbedAustin 11:cada08fc8a70 262 const unsigned char *input,
mbedAustin 11:cada08fc8a70 263 unsigned char *output );
mbedAustin 11:cada08fc8a70 264
mbedAustin 11:cada08fc8a70 265 /**
mbedAustin 11:cada08fc8a70 266 * \brief Perform a PKCS#1 v1.5 encryption (RSAES-PKCS1-v1_5-ENCRYPT)
mbedAustin 11:cada08fc8a70 267 *
mbedAustin 11:cada08fc8a70 268 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 269 * \param f_rng RNG function (Needed for padding and MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 270 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 271 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 272 * \param ilen contains the plaintext length
mbedAustin 11:cada08fc8a70 273 * \param input buffer holding the data to be encrypted
mbedAustin 11:cada08fc8a70 274 * \param output buffer that will hold the ciphertext
mbedAustin 11:cada08fc8a70 275 *
mbedAustin 11:cada08fc8a70 276 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 277 *
mbedAustin 11:cada08fc8a70 278 * \note The output buffer must be as large as the size
mbedAustin 11:cada08fc8a70 279 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 280 */
mbedAustin 11:cada08fc8a70 281 int mbedtls_rsa_rsaes_pkcs1_v15_encrypt( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 282 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 283 void *p_rng,
mbedAustin 11:cada08fc8a70 284 int mode, size_t ilen,
mbedAustin 11:cada08fc8a70 285 const unsigned char *input,
mbedAustin 11:cada08fc8a70 286 unsigned char *output );
mbedAustin 11:cada08fc8a70 287
mbedAustin 11:cada08fc8a70 288 /**
mbedAustin 11:cada08fc8a70 289 * \brief Perform a PKCS#1 v2.1 OAEP encryption (RSAES-OAEP-ENCRYPT)
mbedAustin 11:cada08fc8a70 290 *
mbedAustin 11:cada08fc8a70 291 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 292 * \param f_rng RNG function (Needed for padding and PKCS#1 v2.1 encoding
mbedAustin 11:cada08fc8a70 293 * and MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 294 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 295 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 296 * \param label buffer holding the custom label to use
mbedAustin 11:cada08fc8a70 297 * \param label_len contains the label length
mbedAustin 11:cada08fc8a70 298 * \param ilen contains the plaintext length
mbedAustin 11:cada08fc8a70 299 * \param input buffer holding the data to be encrypted
mbedAustin 11:cada08fc8a70 300 * \param output buffer that will hold the ciphertext
mbedAustin 11:cada08fc8a70 301 *
mbedAustin 11:cada08fc8a70 302 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 303 *
mbedAustin 11:cada08fc8a70 304 * \note The output buffer must be as large as the size
mbedAustin 11:cada08fc8a70 305 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 306 */
mbedAustin 11:cada08fc8a70 307 int mbedtls_rsa_rsaes_oaep_encrypt( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 308 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 309 void *p_rng,
mbedAustin 11:cada08fc8a70 310 int mode,
mbedAustin 11:cada08fc8a70 311 const unsigned char *label, size_t label_len,
mbedAustin 11:cada08fc8a70 312 size_t ilen,
mbedAustin 11:cada08fc8a70 313 const unsigned char *input,
mbedAustin 11:cada08fc8a70 314 unsigned char *output );
mbedAustin 11:cada08fc8a70 315
mbedAustin 11:cada08fc8a70 316 /**
mbedAustin 11:cada08fc8a70 317 * \brief Generic wrapper to perform a PKCS#1 decryption using the
mbedAustin 11:cada08fc8a70 318 * mode from the context. Do an RSA operation, then remove
mbedAustin 11:cada08fc8a70 319 * the message padding
mbedAustin 11:cada08fc8a70 320 *
mbedAustin 11:cada08fc8a70 321 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 322 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 323 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 324 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 325 * \param olen will contain the plaintext length
mbedAustin 11:cada08fc8a70 326 * \param input buffer holding the encrypted data
mbedAustin 11:cada08fc8a70 327 * \param output buffer that will hold the plaintext
mbedAustin 11:cada08fc8a70 328 * \param output_max_len maximum length of the output buffer
mbedAustin 11:cada08fc8a70 329 *
mbedAustin 11:cada08fc8a70 330 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 331 *
mbedAustin 11:cada08fc8a70 332 * \note The output buffer must be as large as the size
mbedAustin 11:cada08fc8a70 333 * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
mbedAustin 11:cada08fc8a70 334 * an error is thrown.
mbedAustin 11:cada08fc8a70 335 */
mbedAustin 11:cada08fc8a70 336 int mbedtls_rsa_pkcs1_decrypt( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 337 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 338 void *p_rng,
mbedAustin 11:cada08fc8a70 339 int mode, size_t *olen,
mbedAustin 11:cada08fc8a70 340 const unsigned char *input,
mbedAustin 11:cada08fc8a70 341 unsigned char *output,
mbedAustin 11:cada08fc8a70 342 size_t output_max_len );
mbedAustin 11:cada08fc8a70 343
mbedAustin 11:cada08fc8a70 344 /**
mbedAustin 11:cada08fc8a70 345 * \brief Perform a PKCS#1 v1.5 decryption (RSAES-PKCS1-v1_5-DECRYPT)
mbedAustin 11:cada08fc8a70 346 *
mbedAustin 11:cada08fc8a70 347 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 348 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 349 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 350 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 351 * \param olen will contain the plaintext length
mbedAustin 11:cada08fc8a70 352 * \param input buffer holding the encrypted data
mbedAustin 11:cada08fc8a70 353 * \param output buffer that will hold the plaintext
mbedAustin 11:cada08fc8a70 354 * \param output_max_len maximum length of the output buffer
mbedAustin 11:cada08fc8a70 355 *
mbedAustin 11:cada08fc8a70 356 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 357 *
mbedAustin 11:cada08fc8a70 358 * \note The output buffer must be as large as the size
mbedAustin 11:cada08fc8a70 359 * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
mbedAustin 11:cada08fc8a70 360 * an error is thrown.
mbedAustin 11:cada08fc8a70 361 */
mbedAustin 11:cada08fc8a70 362 int mbedtls_rsa_rsaes_pkcs1_v15_decrypt( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 363 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 364 void *p_rng,
mbedAustin 11:cada08fc8a70 365 int mode, size_t *olen,
mbedAustin 11:cada08fc8a70 366 const unsigned char *input,
mbedAustin 11:cada08fc8a70 367 unsigned char *output,
mbedAustin 11:cada08fc8a70 368 size_t output_max_len );
mbedAustin 11:cada08fc8a70 369
mbedAustin 11:cada08fc8a70 370 /**
mbedAustin 11:cada08fc8a70 371 * \brief Perform a PKCS#1 v2.1 OAEP decryption (RSAES-OAEP-DECRYPT)
mbedAustin 11:cada08fc8a70 372 *
mbedAustin 11:cada08fc8a70 373 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 374 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 375 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 376 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 377 * \param label buffer holding the custom label to use
mbedAustin 11:cada08fc8a70 378 * \param label_len contains the label length
mbedAustin 11:cada08fc8a70 379 * \param olen will contain the plaintext length
mbedAustin 11:cada08fc8a70 380 * \param input buffer holding the encrypted data
mbedAustin 11:cada08fc8a70 381 * \param output buffer that will hold the plaintext
mbedAustin 11:cada08fc8a70 382 * \param output_max_len maximum length of the output buffer
mbedAustin 11:cada08fc8a70 383 *
mbedAustin 11:cada08fc8a70 384 * \return 0 if successful, or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 385 *
mbedAustin 11:cada08fc8a70 386 * \note The output buffer must be as large as the size
mbedAustin 11:cada08fc8a70 387 * of ctx->N (eg. 128 bytes if RSA-1024 is used) otherwise
mbedAustin 11:cada08fc8a70 388 * an error is thrown.
mbedAustin 11:cada08fc8a70 389 */
mbedAustin 11:cada08fc8a70 390 int mbedtls_rsa_rsaes_oaep_decrypt( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 391 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 392 void *p_rng,
mbedAustin 11:cada08fc8a70 393 int mode,
mbedAustin 11:cada08fc8a70 394 const unsigned char *label, size_t label_len,
mbedAustin 11:cada08fc8a70 395 size_t *olen,
mbedAustin 11:cada08fc8a70 396 const unsigned char *input,
mbedAustin 11:cada08fc8a70 397 unsigned char *output,
mbedAustin 11:cada08fc8a70 398 size_t output_max_len );
mbedAustin 11:cada08fc8a70 399
mbedAustin 11:cada08fc8a70 400 /**
mbedAustin 11:cada08fc8a70 401 * \brief Generic wrapper to perform a PKCS#1 signature using the
mbedAustin 11:cada08fc8a70 402 * mode from the context. Do a private RSA operation to sign
mbedAustin 11:cada08fc8a70 403 * a message digest
mbedAustin 11:cada08fc8a70 404 *
mbedAustin 11:cada08fc8a70 405 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 406 * \param f_rng RNG function (Needed for PKCS#1 v2.1 encoding and for
mbedAustin 11:cada08fc8a70 407 * MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 408 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 409 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 410 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 411 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 412 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 413 * \param sig buffer that will hold the ciphertext
mbedAustin 11:cada08fc8a70 414 *
mbedAustin 11:cada08fc8a70 415 * \return 0 if the signing operation was successful,
mbedAustin 11:cada08fc8a70 416 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 417 *
mbedAustin 11:cada08fc8a70 418 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 419 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 420 *
mbedAustin 11:cada08fc8a70 421 * \note In case of PKCS#1 v2.1 encoding, see comments on
mbedAustin 11:cada08fc8a70 422 * \note \c mbedtls_rsa_rsassa_pss_sign() for details on md_alg and hash_id.
mbedAustin 11:cada08fc8a70 423 */
mbedAustin 11:cada08fc8a70 424 int mbedtls_rsa_pkcs1_sign( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 425 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 426 void *p_rng,
mbedAustin 11:cada08fc8a70 427 int mode,
mbedAustin 11:cada08fc8a70 428 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 429 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 430 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 431 unsigned char *sig );
mbedAustin 11:cada08fc8a70 432
mbedAustin 11:cada08fc8a70 433 /**
mbedAustin 11:cada08fc8a70 434 * \brief Perform a PKCS#1 v1.5 signature (RSASSA-PKCS1-v1_5-SIGN)
mbedAustin 11:cada08fc8a70 435 *
mbedAustin 11:cada08fc8a70 436 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 437 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 438 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 439 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 440 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 441 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 442 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 443 * \param sig buffer that will hold the ciphertext
mbedAustin 11:cada08fc8a70 444 *
mbedAustin 11:cada08fc8a70 445 * \return 0 if the signing operation was successful,
mbedAustin 11:cada08fc8a70 446 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 447 *
mbedAustin 11:cada08fc8a70 448 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 449 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 450 */
mbedAustin 11:cada08fc8a70 451 int mbedtls_rsa_rsassa_pkcs1_v15_sign( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 452 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 453 void *p_rng,
mbedAustin 11:cada08fc8a70 454 int mode,
mbedAustin 11:cada08fc8a70 455 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 456 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 457 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 458 unsigned char *sig );
mbedAustin 11:cada08fc8a70 459
mbedAustin 11:cada08fc8a70 460 /**
mbedAustin 11:cada08fc8a70 461 * \brief Perform a PKCS#1 v2.1 PSS signature (RSASSA-PSS-SIGN)
mbedAustin 11:cada08fc8a70 462 *
mbedAustin 11:cada08fc8a70 463 * \param ctx RSA context
mbedAustin 11:cada08fc8a70 464 * \param f_rng RNG function (Needed for PKCS#1 v2.1 encoding and for
mbedAustin 11:cada08fc8a70 465 * MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 466 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 467 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 468 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 469 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 470 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 471 * \param sig buffer that will hold the ciphertext
mbedAustin 11:cada08fc8a70 472 *
mbedAustin 11:cada08fc8a70 473 * \return 0 if the signing operation was successful,
mbedAustin 11:cada08fc8a70 474 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 475 *
mbedAustin 11:cada08fc8a70 476 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 477 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 478 *
mbedAustin 11:cada08fc8a70 479 * \note The hash_id in the RSA context is the one used for the
mbedAustin 11:cada08fc8a70 480 * encoding. md_alg in the function call is the type of hash
mbedAustin 11:cada08fc8a70 481 * that is encoded. According to RFC 3447 it is advised to
mbedAustin 11:cada08fc8a70 482 * keep both hashes the same.
mbedAustin 11:cada08fc8a70 483 */
mbedAustin 11:cada08fc8a70 484 int mbedtls_rsa_rsassa_pss_sign( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 485 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 486 void *p_rng,
mbedAustin 11:cada08fc8a70 487 int mode,
mbedAustin 11:cada08fc8a70 488 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 489 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 490 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 491 unsigned char *sig );
mbedAustin 11:cada08fc8a70 492
mbedAustin 11:cada08fc8a70 493 /**
mbedAustin 11:cada08fc8a70 494 * \brief Generic wrapper to perform a PKCS#1 verification using the
mbedAustin 11:cada08fc8a70 495 * mode from the context. Do a public RSA operation and check
mbedAustin 11:cada08fc8a70 496 * the message digest
mbedAustin 11:cada08fc8a70 497 *
mbedAustin 11:cada08fc8a70 498 * \param ctx points to an RSA public key
mbedAustin 11:cada08fc8a70 499 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 500 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 501 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 502 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 503 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 504 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 505 * \param sig buffer holding the ciphertext
mbedAustin 11:cada08fc8a70 506 *
mbedAustin 11:cada08fc8a70 507 * \return 0 if the verify operation was successful,
mbedAustin 11:cada08fc8a70 508 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 509 *
mbedAustin 11:cada08fc8a70 510 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 511 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 512 *
mbedAustin 11:cada08fc8a70 513 * \note In case of PKCS#1 v2.1 encoding, see comments on
mbedAustin 11:cada08fc8a70 514 * \c mbedtls_rsa_rsassa_pss_verify() about md_alg and hash_id.
mbedAustin 11:cada08fc8a70 515 */
mbedAustin 11:cada08fc8a70 516 int mbedtls_rsa_pkcs1_verify( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 517 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 518 void *p_rng,
mbedAustin 11:cada08fc8a70 519 int mode,
mbedAustin 11:cada08fc8a70 520 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 521 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 522 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 523 const unsigned char *sig );
mbedAustin 11:cada08fc8a70 524
mbedAustin 11:cada08fc8a70 525 /**
mbedAustin 11:cada08fc8a70 526 * \brief Perform a PKCS#1 v1.5 verification (RSASSA-PKCS1-v1_5-VERIFY)
mbedAustin 11:cada08fc8a70 527 *
mbedAustin 11:cada08fc8a70 528 * \param ctx points to an RSA public key
mbedAustin 11:cada08fc8a70 529 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 530 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 531 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 532 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 533 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 534 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 535 * \param sig buffer holding the ciphertext
mbedAustin 11:cada08fc8a70 536 *
mbedAustin 11:cada08fc8a70 537 * \return 0 if the verify operation was successful,
mbedAustin 11:cada08fc8a70 538 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 539 *
mbedAustin 11:cada08fc8a70 540 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 541 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 542 */
mbedAustin 11:cada08fc8a70 543 int mbedtls_rsa_rsassa_pkcs1_v15_verify( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 544 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 545 void *p_rng,
mbedAustin 11:cada08fc8a70 546 int mode,
mbedAustin 11:cada08fc8a70 547 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 548 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 549 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 550 const unsigned char *sig );
mbedAustin 11:cada08fc8a70 551
mbedAustin 11:cada08fc8a70 552 /**
mbedAustin 11:cada08fc8a70 553 * \brief Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY)
mbedAustin 11:cada08fc8a70 554 * (This is the "simple" version.)
mbedAustin 11:cada08fc8a70 555 *
mbedAustin 11:cada08fc8a70 556 * \param ctx points to an RSA public key
mbedAustin 11:cada08fc8a70 557 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 558 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 559 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 560 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 561 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 562 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 563 * \param sig buffer holding the ciphertext
mbedAustin 11:cada08fc8a70 564 *
mbedAustin 11:cada08fc8a70 565 * \return 0 if the verify operation was successful,
mbedAustin 11:cada08fc8a70 566 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 567 *
mbedAustin 11:cada08fc8a70 568 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 569 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 570 *
mbedAustin 11:cada08fc8a70 571 * \note The hash_id in the RSA context is the one used for the
mbedAustin 11:cada08fc8a70 572 * verification. md_alg in the function call is the type of
mbedAustin 11:cada08fc8a70 573 * hash that is verified. According to RFC 3447 it is advised to
mbedAustin 11:cada08fc8a70 574 * keep both hashes the same. If hash_id in the RSA context is
mbedAustin 11:cada08fc8a70 575 * unset, the md_alg from the function call is used.
mbedAustin 11:cada08fc8a70 576 */
mbedAustin 11:cada08fc8a70 577 int mbedtls_rsa_rsassa_pss_verify( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 578 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 579 void *p_rng,
mbedAustin 11:cada08fc8a70 580 int mode,
mbedAustin 11:cada08fc8a70 581 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 582 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 583 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 584 const unsigned char *sig );
mbedAustin 11:cada08fc8a70 585
mbedAustin 11:cada08fc8a70 586 /**
mbedAustin 11:cada08fc8a70 587 * \brief Perform a PKCS#1 v2.1 PSS verification (RSASSA-PSS-VERIFY)
mbedAustin 11:cada08fc8a70 588 * (This is the version with "full" options.)
mbedAustin 11:cada08fc8a70 589 *
mbedAustin 11:cada08fc8a70 590 * \param ctx points to an RSA public key
mbedAustin 11:cada08fc8a70 591 * \param f_rng RNG function (Only needed for MBEDTLS_RSA_PRIVATE)
mbedAustin 11:cada08fc8a70 592 * \param p_rng RNG parameter
mbedAustin 11:cada08fc8a70 593 * \param mode MBEDTLS_RSA_PUBLIC or MBEDTLS_RSA_PRIVATE
mbedAustin 11:cada08fc8a70 594 * \param md_alg a MBEDTLS_MD_XXX (use MBEDTLS_MD_NONE for signing raw data)
mbedAustin 11:cada08fc8a70 595 * \param hashlen message digest length (for MBEDTLS_MD_NONE only)
mbedAustin 11:cada08fc8a70 596 * \param hash buffer holding the message digest
mbedAustin 11:cada08fc8a70 597 * \param mgf1_hash_id message digest used for mask generation
mbedAustin 11:cada08fc8a70 598 * \param expected_salt_len Length of the salt used in padding, use
mbedAustin 11:cada08fc8a70 599 * MBEDTLS_RSA_SALT_LEN_ANY to accept any salt length
mbedAustin 11:cada08fc8a70 600 * \param sig buffer holding the ciphertext
mbedAustin 11:cada08fc8a70 601 *
mbedAustin 11:cada08fc8a70 602 * \return 0 if the verify operation was successful,
mbedAustin 11:cada08fc8a70 603 * or an MBEDTLS_ERR_RSA_XXX error code
mbedAustin 11:cada08fc8a70 604 *
mbedAustin 11:cada08fc8a70 605 * \note The "sig" buffer must be as large as the size
mbedAustin 11:cada08fc8a70 606 * of ctx->N (eg. 128 bytes if RSA-1024 is used).
mbedAustin 11:cada08fc8a70 607 *
mbedAustin 11:cada08fc8a70 608 * \note The hash_id in the RSA context is ignored.
mbedAustin 11:cada08fc8a70 609 */
mbedAustin 11:cada08fc8a70 610 int mbedtls_rsa_rsassa_pss_verify_ext( mbedtls_rsa_context *ctx,
mbedAustin 11:cada08fc8a70 611 int (*f_rng)(void *, unsigned char *, size_t),
mbedAustin 11:cada08fc8a70 612 void *p_rng,
mbedAustin 11:cada08fc8a70 613 int mode,
mbedAustin 11:cada08fc8a70 614 mbedtls_md_type_t md_alg,
mbedAustin 11:cada08fc8a70 615 unsigned int hashlen,
mbedAustin 11:cada08fc8a70 616 const unsigned char *hash,
mbedAustin 11:cada08fc8a70 617 mbedtls_md_type_t mgf1_hash_id,
mbedAustin 11:cada08fc8a70 618 int expected_salt_len,
mbedAustin 11:cada08fc8a70 619 const unsigned char *sig );
mbedAustin 11:cada08fc8a70 620
mbedAustin 11:cada08fc8a70 621 /**
mbedAustin 11:cada08fc8a70 622 * \brief Copy the components of an RSA context
mbedAustin 11:cada08fc8a70 623 *
mbedAustin 11:cada08fc8a70 624 * \param dst Destination context
mbedAustin 11:cada08fc8a70 625 * \param src Source context
mbedAustin 11:cada08fc8a70 626 *
mbedAustin 11:cada08fc8a70 627 * \return 0 on success,
mbedAustin 11:cada08fc8a70 628 * MBEDTLS_ERR_MPI_ALLOC_FAILED on memory allocation failure
mbedAustin 11:cada08fc8a70 629 */
mbedAustin 11:cada08fc8a70 630 int mbedtls_rsa_copy( mbedtls_rsa_context *dst, const mbedtls_rsa_context *src );
mbedAustin 11:cada08fc8a70 631
mbedAustin 11:cada08fc8a70 632 /**
mbedAustin 11:cada08fc8a70 633 * \brief Free the components of an RSA key
mbedAustin 11:cada08fc8a70 634 *
mbedAustin 11:cada08fc8a70 635 * \param ctx RSA Context to free
mbedAustin 11:cada08fc8a70 636 */
mbedAustin 11:cada08fc8a70 637 void mbedtls_rsa_free( mbedtls_rsa_context *ctx );
mbedAustin 11:cada08fc8a70 638
mbedAustin 11:cada08fc8a70 639 /**
mbedAustin 11:cada08fc8a70 640 * \brief Checkup routine
mbedAustin 11:cada08fc8a70 641 *
mbedAustin 11:cada08fc8a70 642 * \return 0 if successful, or 1 if the test failed
mbedAustin 11:cada08fc8a70 643 */
mbedAustin 11:cada08fc8a70 644 int mbedtls_rsa_self_test( int verbose );
mbedAustin 11:cada08fc8a70 645
mbedAustin 11:cada08fc8a70 646 #ifdef __cplusplus
mbedAustin 11:cada08fc8a70 647 }
mbedAustin 11:cada08fc8a70 648 #endif
mbedAustin 11:cada08fc8a70 649
mbedAustin 11:cada08fc8a70 650 #endif /* MBEDTLS_RSA_C */
mbedAustin 11:cada08fc8a70 651
mbedAustin 11:cada08fc8a70 652 #endif /* rsa.h */