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