gabor-mezei-arm | 944c107 | 2021-09-27 11:28:54 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Constant-time functions |
| 3 | * |
| 4 | * Copyright The Mbed TLS Contributors |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * |
| 7 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 8 | * not use this file except in compliance with the License. |
| 9 | * You may obtain a copy of the License at |
| 10 | * |
| 11 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | * |
| 13 | * Unless required by applicable law or agreed to in writing, software |
| 14 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 15 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | * See the License for the specific language governing permissions and |
| 17 | * limitations under the License. |
| 18 | */ |
| 19 | |
| 20 | #include "common.h" |
| 21 | |
gabor-mezei-arm | 097d4f5 | 2021-09-27 12:55:33 +0200 | [diff] [blame] | 22 | #if defined(MBEDTLS_BIGNUM_C) |
| 23 | #include "mbedtls/bignum.h" |
| 24 | #endif |
| 25 | |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 26 | #if defined(MBEDTLS_SSL_TLS_C) |
| 27 | #include "mbedtls/ssl_internal.h" |
| 28 | #endif |
| 29 | |
gabor-mezei-arm | 944c107 | 2021-09-27 11:28:54 +0200 | [diff] [blame] | 30 | #include <stddef.h> |
| 31 | |
gabor-mezei-arm | 944c107 | 2021-09-27 11:28:54 +0200 | [diff] [blame] | 32 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 33 | /** Constant-time buffer comparison without branches. |
| 34 | * |
| 35 | * This is equivalent to the standard memncmp function, but is likely to be |
| 36 | * compiled to code using bitwise operation rather than a branch. |
| 37 | * |
| 38 | * This function can be used to write constant-time code by replacing branches |
| 39 | * with bit operations using masks. |
| 40 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 41 | * \param a Pointer to the first buffer. |
| 42 | * \param b Pointer to the second buffer. |
| 43 | * \param n The number of bytes to compare in the buffer. |
| 44 | * |
| 45 | * \return Zero if the content of the two buffer is the same, |
| 46 | * otherwise non-zero. |
| 47 | */ |
gabor-mezei-arm | 378e7eb | 2021-07-19 15:19:19 +0200 | [diff] [blame] | 48 | int mbedtls_cf_memcmp( const void *a, |
| 49 | const void *b, |
| 50 | size_t n ); |
gabor-mezei-arm | c11cac9 | 2021-09-27 11:40:03 +0200 | [diff] [blame] | 51 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 52 | /** Turn a value into a mask: |
| 53 | * - if \p value == 0, return the all-bits 0 mask, aka 0 |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 54 | * - otherwise, return the all-bits 1 mask, aka (unsigned) -1 |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 55 | * |
| 56 | * This function can be used to write constant-time code by replacing branches |
| 57 | * with bit operations using masks. |
| 58 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 59 | * \param value The value to analyze. |
| 60 | * |
| 61 | * \return Zero if \p value is zero, otherwise all-bits-one. |
| 62 | */ |
gabor-mezei-arm | c11cac9 | 2021-09-27 11:40:03 +0200 | [diff] [blame] | 63 | unsigned mbedtls_cf_uint_mask( unsigned value ); |
gabor-mezei-arm | d361ccd | 2021-09-27 11:49:42 +0200 | [diff] [blame] | 64 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 65 | /** Turn a value into a mask: |
| 66 | * - if \p value == 0, return the all-bits 0 mask, aka 0 |
| 67 | * - otherwise, return the all-bits 1 mask, aka (size_t) -1 |
| 68 | * |
| 69 | * This function can be used to write constant-time code by replacing branches |
| 70 | * with bit operations using masks. |
| 71 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 72 | * \param value The value to analyze. |
| 73 | * |
| 74 | * \return Zero if \p value is zero, otherwise all-bits-one. |
| 75 | */ |
gabor-mezei-arm | 2f2c0be | 2021-08-10 20:56:21 +0200 | [diff] [blame] | 76 | size_t mbedtls_cf_size_mask( size_t value ); |
gabor-mezei-arm | 4d6b146 | 2021-09-27 11:53:54 +0200 | [diff] [blame] | 77 | |
gabor-mezei-arm | 60febd5 | 2021-08-11 15:07:02 +0200 | [diff] [blame] | 78 | #if defined(MBEDTLS_BIGNUM_C) |
| 79 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 80 | /** Turn a value into a mask: |
| 81 | * - if \p value == 0, return the all-bits 0 mask, aka 0 |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 82 | * - otherwise, return the all-bits 1 mask, aka (mbedtls_mpi_uint) -1 |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 83 | * |
| 84 | * This function can be used to write constant-time code by replacing branches |
| 85 | * with bit operations using masks. |
| 86 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 87 | * \param value The value to analyze. |
| 88 | * |
| 89 | * \return Zero if \p value is zero, otherwise all-bits-one. |
| 90 | */ |
gabor-mezei-arm | 60febd5 | 2021-08-11 15:07:02 +0200 | [diff] [blame] | 91 | mbedtls_mpi_uint mbedtls_cf_mpi_uint_mask( mbedtls_mpi_uint value ); |
| 92 | |
| 93 | #endif /* MBEDTLS_BIGNUM_C */ |
| 94 | |
Gabor Mezei | 2b35880 | 2021-10-18 17:05:06 +0200 | [diff] [blame^] | 95 | #if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) |
| 96 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 97 | /** Constant-flow mask generation for "greater or equal" comparison: |
| 98 | * - if \p x >= \p y, return all-bits 1, that is (size_t) -1 |
| 99 | * - otherwise, return all bits 0, that is 0 |
| 100 | * |
| 101 | * This function can be used to write constant-time code by replacing branches |
| 102 | * with bit operations using masks. |
| 103 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 104 | * \param x The first value to analyze. |
| 105 | * \param y The second value to analyze. |
| 106 | * |
| 107 | * \return All-bits-one if \p x is greater or equal than \p y, |
| 108 | * otherwise zero. |
| 109 | */ |
gabor-mezei-arm | 04087df | 2021-09-27 16:29:52 +0200 | [diff] [blame] | 110 | size_t mbedtls_cf_size_mask_ge( size_t x, |
| 111 | size_t y ); |
gabor-mezei-arm | 96584dd | 2021-09-27 12:15:19 +0200 | [diff] [blame] | 112 | |
Gabor Mezei | 2b35880 | 2021-10-18 17:05:06 +0200 | [diff] [blame^] | 113 | #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ |
| 114 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 115 | /** Constant-flow boolean "equal" comparison: |
| 116 | * return x == y |
| 117 | * |
| 118 | * This is equivalent to \p x == \p y, but is likely to be compiled |
| 119 | * to code using bitwise operation rather than a branch. |
| 120 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 121 | * \param x The first value to analyze. |
| 122 | * \param y The second value to analyze. |
| 123 | * |
| 124 | * \return 1 if \p x equals to \p y, otherwise 0. |
| 125 | */ |
gabor-mezei-arm | 1ffd0cc | 2021-08-11 17:28:49 +0200 | [diff] [blame] | 126 | unsigned mbedtls_cf_size_bool_eq( size_t x, |
| 127 | size_t y ); |
gabor-mezei-arm | 9d7bf09 | 2021-09-27 12:25:07 +0200 | [diff] [blame] | 128 | |
gabor-mezei-arm | 097d4f5 | 2021-09-27 12:55:33 +0200 | [diff] [blame] | 129 | #if defined(MBEDTLS_BIGNUM_C) |
| 130 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 131 | /** Decide if an integer is less than the other, without branches. |
| 132 | * |
| 133 | * This is equivalent to \p x < \p y, but is likely to be compiled |
| 134 | * to code using bitwise operation rather than a branch. |
| 135 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 136 | * \param x The first value to analyze. |
| 137 | * \param y The second value to analyze. |
| 138 | * |
| 139 | * \return 1 if \p x is less than \p y, otherwise 0. |
| 140 | */ |
gabor-mezei-arm | 097d4f5 | 2021-09-27 12:55:33 +0200 | [diff] [blame] | 141 | unsigned mbedtls_cf_mpi_uint_lt( const mbedtls_mpi_uint x, |
| 142 | const mbedtls_mpi_uint y ); |
| 143 | |
| 144 | #endif /* MBEDTLS_BIGNUM_C */ |
gabor-mezei-arm | 7533253 | 2021-09-27 12:59:30 +0200 | [diff] [blame] | 145 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 146 | /** Choose between two integer values without branches. |
| 147 | * |
| 148 | * This is equivalent to `condition ? if1 : if0`, but is likely to be compiled |
| 149 | * to code using bitwise operation rather than a branch. |
| 150 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 151 | * \param condition Condition to test. |
| 152 | * \param if1 Value to use if \p condition is nonzero. |
| 153 | * \param if0 Value to use if \p condition is zero. |
| 154 | * |
| 155 | * \return \c if1 if \p condition is nonzero, otherwise \c if0. |
| 156 | */ |
gabor-mezei-arm | 5e48824 | 2021-08-10 20:36:09 +0200 | [diff] [blame] | 157 | unsigned mbedtls_cf_uint_if( unsigned condition, |
gabor-mezei-arm | 04087df | 2021-09-27 16:29:52 +0200 | [diff] [blame] | 158 | unsigned if1, |
| 159 | unsigned if0 ); |
gabor-mezei-arm | 7533253 | 2021-09-27 12:59:30 +0200 | [diff] [blame] | 160 | |
gabor-mezei-arm | 043192d | 2021-09-27 13:17:15 +0200 | [diff] [blame] | 161 | #if defined(MBEDTLS_BIGNUM_C) |
| 162 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 163 | /** Conditionally assign a value without branches. |
| 164 | * |
| 165 | * This is equivalent to `if ( condition ) dest = src`, but is likely |
| 166 | * to be compiled to code using bitwise operation rather than a branch. |
| 167 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 168 | * \param n \p dest and \p src must be arrays of limbs of size n. |
| 169 | * \param dest The MPI to conditionally assign to. This must point |
| 170 | * to an initialized MPI. |
| 171 | * \param src The MPI to be assigned from. This must point to an |
| 172 | * initialized MPI. |
| 173 | * \param condition Condition to test, must be 0 or 1. |
| 174 | */ |
gabor-mezei-arm | 043192d | 2021-09-27 13:17:15 +0200 | [diff] [blame] | 175 | void mbedtls_cf_mpi_uint_cond_assign( size_t n, |
| 176 | mbedtls_mpi_uint *dest, |
| 177 | const mbedtls_mpi_uint *src, |
gabor-mezei-arm | 5e48824 | 2021-08-10 20:36:09 +0200 | [diff] [blame] | 178 | unsigned char condition ); |
gabor-mezei-arm | 043192d | 2021-09-27 13:17:15 +0200 | [diff] [blame] | 179 | |
| 180 | #endif /* MBEDTLS_BIGNUM_C */ |
gabor-mezei-arm | 7b23c0b | 2021-09-27 13:31:06 +0200 | [diff] [blame] | 181 | |
Gabor Mezei | 2b35880 | 2021-10-18 17:05:06 +0200 | [diff] [blame^] | 182 | #if defined(MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC) |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 183 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 184 | /** Conditional memcpy without branches. |
| 185 | * |
| 186 | * This is equivalent to `if ( c1 == c2 ) memcpy(dst, src, len)`, but is likely |
| 187 | * to be compiled to code using bitwise operation rather than a branch. |
| 188 | * |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 189 | * \param dest The pointer to conditionally copy to. |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 190 | * \param src The pointer to copy from. Shouldn't overlap with \p dest. |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 191 | * \param len The number of bytes to copy. |
| 192 | * \param c1 The first value to analyze in the condition. |
| 193 | * \param c2 The second value to analyze in the condition. |
| 194 | */ |
gabor-mezei-arm | 5e48824 | 2021-08-10 20:36:09 +0200 | [diff] [blame] | 195 | void mbedtls_cf_memcpy_if_eq( unsigned char *dest, |
gabor-mezei-arm | ee06feb | 2021-09-27 13:34:25 +0200 | [diff] [blame] | 196 | const unsigned char *src, |
| 197 | size_t len, |
| 198 | size_t c1, size_t c2 ); |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 199 | |
| 200 | /** Copy data from a secret position with constant flow. |
| 201 | * |
| 202 | * This function copies \p len bytes from \p src_base + \p offset_secret to \p |
| 203 | * dst, with a code flow and memory access pattern that does not depend on \p |
| 204 | * offset_secret, but only on \p offset_min, \p offset_max and \p len. |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 205 | * Functionally equivalent to `memcpy(dst, src + offset_secret, len)`. |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 206 | * |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 207 | * \param dest The destination buffer. This must point to a writable |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 208 | * buffer of at least \p len bytes. |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 209 | * \param src The base of the source buffer. This must point to a |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 210 | * readable buffer of at least \p offset_max + \p len |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 211 | * bytes. Shouldn't overlap with \p dest. |
| 212 | * \param offset The offset in the source buffer from which to copy. |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 213 | * This must be no less than \p offset_min and no greater |
| 214 | * than \p offset_max. |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 215 | * \param offset_min The minimal value of \p offset. |
| 216 | * \param offset_max The maximal value of \p offset. |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 217 | * \param len The number of bytes to copy. |
| 218 | */ |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 219 | void mbedtls_cf_memcpy_offset( unsigned char *dest, |
| 220 | const unsigned char *src, |
| 221 | size_t offset, |
gabor-mezei-arm | 04087df | 2021-09-27 16:29:52 +0200 | [diff] [blame] | 222 | size_t offset_min, |
| 223 | size_t offset_max, |
gabor-mezei-arm | 0f7b9e4 | 2021-09-27 13:57:45 +0200 | [diff] [blame] | 224 | size_t len ); |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 225 | |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 226 | /** Compute the HMAC of variable-length data with constant flow. |
| 227 | * |
| 228 | * This function computes the HMAC of the concatenation of \p add_data and \p |
| 229 | * data, and does with a code flow and memory access pattern that does not |
| 230 | * depend on \p data_len_secret, but only on \p min_data_len and \p |
| 231 | * max_data_len. In particular, this function always reads exactly \p |
| 232 | * max_data_len bytes from \p data. |
| 233 | * |
| 234 | * \param ctx The HMAC context. It must have keys configured |
| 235 | * with mbedtls_md_hmac_starts() and use one of the |
| 236 | * following hashes: SHA-384, SHA-256, SHA-1 or MD-5. |
| 237 | * It is reset using mbedtls_md_hmac_reset() after |
| 238 | * the computation is complete to prepare for the |
| 239 | * next computation. |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 240 | * \param add_data The first part of the message whose HMAC is being |
| 241 | * calculated. This must point to a readable buffer |
| 242 | * of \p add_data_len bytes. |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 243 | * \param add_data_len The length of \p add_data in bytes. |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 244 | * \param data The buffer containing the second part of the |
| 245 | * message. This must point to a readable buffer |
| 246 | * of \p max_data_len bytes. |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 247 | * \param data_len_secret The length of the data to process in \p data. |
| 248 | * This must be no less than \p min_data_len and no |
| 249 | * greater than \p max_data_len. |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 250 | * \param min_data_len The minimal length of the second part of the |
| 251 | * message, read from /p data. |
| 252 | * \param max_data_len The maximal length of the second part of the |
| 253 | * message, read from /p data. |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 254 | * \param output The HMAC will be written here. This must point to |
| 255 | * a writable buffer of sufficient size to hold the |
| 256 | * HMAC value. |
| 257 | * |
| 258 | * \retval 0 on success. |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 259 | * \retval #MBEDTLS_ERR_PLATFORM_HW_ACCEL_FAILED |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 260 | * The hardware accelerator failed. |
| 261 | */ |
gabor-mezei-arm | 04087df | 2021-09-27 16:29:52 +0200 | [diff] [blame] | 262 | int mbedtls_cf_hmac( mbedtls_md_context_t *ctx, |
| 263 | const unsigned char *add_data, |
| 264 | size_t add_data_len, |
| 265 | const unsigned char *data, |
| 266 | size_t data_len_secret, |
| 267 | size_t min_data_len, |
| 268 | size_t max_data_len, |
| 269 | unsigned char *output ); |
gabor-mezei-arm | cb4317b | 2021-09-27 14:28:31 +0200 | [diff] [blame] | 270 | |
| 271 | #endif /* MBEDTLS_SSL_SOME_SUITES_USE_TLS_CBC */ |
gabor-mezei-arm | f52941e | 2021-09-27 16:11:12 +0200 | [diff] [blame] | 272 | |
| 273 | #if defined(MBEDTLS_PKCS1_V15) && defined(MBEDTLS_RSA_C) && !defined(MBEDTLS_RSA_ALT) |
| 274 | |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 275 | /** This function performs the unpadding part of a PKCS#1 v1.5 decryption |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 276 | * operation (EME-PKCS1-v1_5 decoding). |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 277 | * |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 278 | * \note The return value from this function is a sensitive value |
| 279 | * (this is unusual). #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE shouldn't happen |
| 280 | * in a well-written application, but 0 vs #MBEDTLS_ERR_RSA_INVALID_PADDING |
| 281 | * is often a situation that an attacker can provoke and leaking which |
| 282 | * one is the result is precisely the information the attacker wants. |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 283 | * |
| 284 | * \param mode The mode of operation. This must be either |
| 285 | * #MBEDTLS_RSA_PRIVATE or #MBEDTLS_RSA_PUBLIC (deprecated). |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 286 | * \param input The input buffer which is the payload inside PKCS#1v1.5 |
| 287 | * encryption padding, called the "encoded message EM" |
| 288 | * by the terminology. |
| 289 | * \param ilen The length of the payload in the \p input buffer. |
| 290 | * \param output The buffer for the payload, called "message M" by the |
| 291 | * PKCS#1 terminology. This must be a writable buffer of |
| 292 | * length \p output_max_len bytes. |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 293 | * \param olen The address at which to store the length of |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 294 | * the payload. This must not be \c NULL. |
| 295 | * \param output_max_len The length in bytes of the output buffer \p output. |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 296 | * |
Gabor Mezei | 4b4e4d8 | 2021-10-18 16:28:27 +0200 | [diff] [blame] | 297 | * \return \c 0 on success. |
| 298 | * \return #MBEDTLS_ERR_RSA_OUTPUT_TOO_LARGE |
| 299 | * The output buffer is too small for the unpadded payload. |
| 300 | * \return #MBEDTLS_ERR_RSA_INVALID_PADDING |
| 301 | * The input doesn't contain properly formatted padding. |
gabor-mezei-arm | 7e6a1ea | 2021-08-11 16:40:35 +0200 | [diff] [blame] | 302 | */ |
gabor-mezei-arm | f52941e | 2021-09-27 16:11:12 +0200 | [diff] [blame] | 303 | int mbedtls_cf_rsaes_pkcs1_v15_unpadding( int mode, |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 304 | unsigned char *input, |
gabor-mezei-arm | f52941e | 2021-09-27 16:11:12 +0200 | [diff] [blame] | 305 | size_t ilen, |
gabor-mezei-arm | f52941e | 2021-09-27 16:11:12 +0200 | [diff] [blame] | 306 | unsigned char *output, |
| 307 | size_t output_max_len, |
Gabor Mezei | 91deea7 | 2021-10-18 16:17:57 +0200 | [diff] [blame] | 308 | size_t *olen ); |
gabor-mezei-arm | f52941e | 2021-09-27 16:11:12 +0200 | [diff] [blame] | 309 | |
| 310 | #endif /* MBEDTLS_PKCS1_V15 && MBEDTLS_RSA_C && ! MBEDTLS_RSA_ALT */ |