Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 1 | /** |
| 2 | * \file helpers.h |
| 3 | * |
| 4 | * \brief This file contains the prototypes of helper functions for the |
| 5 | * purpose of testing. |
| 6 | */ |
| 7 | |
Bence Szépkúti | 8697465 | 2020-06-15 11:59:37 +0200 | [diff] [blame] | 8 | /* |
Bence Szépkúti | 1e14827 | 2020-08-07 13:07:28 +0200 | [diff] [blame] | 9 | * Copyright The Mbed TLS Contributors |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: Apache-2.0 |
| 11 | * |
| 12 | * Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 13 | * not use this file except in compliance with the License. |
| 14 | * You may obtain a copy of the License at |
| 15 | * |
| 16 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 17 | * |
| 18 | * Unless required by applicable law or agreed to in writing, software |
| 19 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 20 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 21 | * See the License for the specific language governing permissions and |
| 22 | * limitations under the License. |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 23 | */ |
| 24 | |
| 25 | #ifndef TEST_HELPERS_H |
| 26 | #define TEST_HELPERS_H |
| 27 | |
| 28 | #if !defined(MBEDTLS_CONFIG_FILE) |
| 29 | #include "mbedtls/config.h" |
| 30 | #else |
| 31 | #include MBEDTLS_CONFIG_FILE |
| 32 | #endif |
| 33 | |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 34 | #if defined(MBEDTLS_THREADING_C) && defined(MBEDTLS_THREADING_PTHREAD) && \ |
| 35 | defined(MBEDTLS_TEST_HOOKS) |
| 36 | #define MBEDTLS_TEST_MUTEX_USAGE |
| 37 | #endif |
| 38 | |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 39 | #include "mbedtls/platform.h" |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 40 | |
| 41 | #include <stddef.h> |
| 42 | #include <stdint.h> |
| 43 | |
Gilles Peskine | db47971 | 2021-06-11 14:13:53 +0200 | [diff] [blame] | 44 | #if defined(MBEDTLS_BIGNUM_C) |
| 45 | #include "mbedtls/bignum.h" |
| 46 | #endif |
| 47 | |
Gilles Peskine | 34cb462 | 2022-09-20 21:37:56 +0200 | [diff] [blame] | 48 | /** The type of test case arguments that contain binary data. */ |
| 49 | typedef struct data_tag |
| 50 | { |
| 51 | uint8_t * x; |
| 52 | uint32_t len; |
| 53 | } data_t; |
| 54 | |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 55 | typedef enum |
| 56 | { |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 57 | MBEDTLS_TEST_RESULT_SUCCESS = 0, |
| 58 | MBEDTLS_TEST_RESULT_FAILED, |
| 59 | MBEDTLS_TEST_RESULT_SKIPPED |
| 60 | } mbedtls_test_result_t; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 61 | |
| 62 | typedef struct |
| 63 | { |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 64 | mbedtls_test_result_t result; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 65 | const char *test; |
| 66 | const char *filename; |
| 67 | int line_no; |
| 68 | unsigned long step; |
Gilles Peskine | b436649 | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 69 | char line1[76]; |
| 70 | char line2[76]; |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 71 | #if defined(MBEDTLS_TEST_MUTEX_USAGE) |
| 72 | const char *mutex_usage_error; |
| 73 | #endif |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 74 | } |
Chris Jones | e60e2ae | 2021-01-20 17:51:47 +0000 | [diff] [blame] | 75 | mbedtls_test_info_t; |
| 76 | extern mbedtls_test_info_t mbedtls_test_info; |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 77 | |
Ronald Cron | e9c09f1 | 2020-06-08 16:44:58 +0200 | [diff] [blame] | 78 | int mbedtls_test_platform_setup( void ); |
| 79 | void mbedtls_test_platform_teardown( void ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 80 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 81 | /** |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 82 | * \brief Record the current test case as a failure. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 83 | * |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 84 | * This function can be called directly however it is usually |
| 85 | * called via macros such as TEST_ASSERT, TEST_EQUAL, |
| 86 | * PSA_ASSERT, etc... |
| 87 | * |
| 88 | * \note If the test case was already marked as failed, calling |
| 89 | * `mbedtls_test_fail( )` again will not overwrite any |
| 90 | * previous information about the failure. |
| 91 | * |
| 92 | * \param test Description of the failure or assertion that failed. This |
| 93 | * MUST be a string literal. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 94 | * \param line_no Line number where the failure originated. |
| 95 | * \param filename Filename where the failure originated. |
| 96 | */ |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 97 | void mbedtls_test_fail( const char *test, int line_no, const char* filename ); |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 98 | |
| 99 | /** |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 100 | * \brief Record the current test case as skipped. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 101 | * |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 102 | * This function can be called directly however it is usually |
| 103 | * called via the TEST_ASSUME macro. |
| 104 | * |
| 105 | * \param test Description of the assumption that caused the test case to |
| 106 | * be skipped. This MUST be a string literal. |
| 107 | * \param line_no Line number where the test case was skipped. |
| 108 | * \param filename Filename where the test case was skipped. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 109 | */ |
Chris Jones | a5ab765 | 2021-02-02 16:20:45 +0000 | [diff] [blame] | 110 | void mbedtls_test_skip( const char *test, int line_no, const char* filename ); |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 111 | |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 112 | /** |
| 113 | * \brief Set the test step number for failure reports. |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 114 | * |
Chris Jones | 39ddb0a | 2021-02-03 16:15:00 +0000 | [diff] [blame] | 115 | * Call this function to display "step NNN" in addition to the |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 116 | * line number and file name if a test fails. Typically the "step |
| 117 | * number" is the index of a for loop but it can be whatever you |
| 118 | * want. |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 119 | * |
| 120 | * \param step The step number to report. |
| 121 | */ |
| 122 | void mbedtls_test_set_step( unsigned long step ); |
| 123 | |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 124 | /** |
| 125 | * \brief Reset mbedtls_test_info to a ready/starting state. |
Chris Jones | 567e0ad | 2021-02-03 12:07:01 +0000 | [diff] [blame] | 126 | */ |
Chris Jones | a5ab765 | 2021-02-02 16:20:45 +0000 | [diff] [blame] | 127 | void mbedtls_test_info_reset( void ); |
Chris Jones | 9634bb1 | 2021-01-20 15:56:42 +0000 | [diff] [blame] | 128 | |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 129 | /** |
Gilles Peskine | b436649 | 2021-04-29 20:28:54 +0200 | [diff] [blame] | 130 | * \brief Record the current test case as a failure if two integers |
| 131 | * have a different value. |
| 132 | * |
| 133 | * This function is usually called via the macro |
| 134 | * #TEST_EQUAL. |
| 135 | * |
| 136 | * \param test Description of the failure or assertion that failed. This |
| 137 | * MUST be a string literal. This normally has the form |
| 138 | * "EXPR1 == EXPR2" where EXPR1 has the value \p value1 |
| 139 | * and EXPR2 has the value \p value2. |
| 140 | * \param line_no Line number where the failure originated. |
| 141 | * \param filename Filename where the failure originated. |
| 142 | * \param value1 The first value to compare. |
| 143 | * \param value2 The second value to compare. |
| 144 | * |
| 145 | * \return \c 1 if the values are equal, otherwise \c 0. |
| 146 | */ |
| 147 | int mbedtls_test_equal( const char *test, int line_no, const char* filename, |
| 148 | unsigned long long value1, unsigned long long value2 ); |
| 149 | |
| 150 | /** |
Gilles Peskine | 063700d | 2022-04-13 23:59:52 +0200 | [diff] [blame] | 151 | * \brief Record the current test case as a failure based |
| 152 | * on comparing two unsigned integers. |
| 153 | * |
| 154 | * This function is usually called via the macro |
| 155 | * #TEST_LE_U. |
| 156 | * |
| 157 | * \param test Description of the failure or assertion that failed. This |
| 158 | * MUST be a string literal. This normally has the form |
| 159 | * "EXPR1 <= EXPR2" where EXPR1 has the value \p value1 |
| 160 | * and EXPR2 has the value \p value2. |
| 161 | * \param line_no Line number where the failure originated. |
| 162 | * \param filename Filename where the failure originated. |
| 163 | * \param value1 The first value to compare. |
| 164 | * \param value2 The second value to compare. |
| 165 | * |
| 166 | * \return \c 1 if \p value1 <= \p value2, otherwise \c 0. |
| 167 | */ |
| 168 | int mbedtls_test_le_u( const char *test, int line_no, const char* filename, |
| 169 | unsigned long long value1, unsigned long long value2 ); |
| 170 | |
| 171 | /** |
| 172 | * \brief Record the current test case as a failure based |
| 173 | * on comparing two signed integers. |
| 174 | * |
| 175 | * This function is usually called via the macro |
| 176 | * #TEST_LE_S. |
| 177 | * |
| 178 | * \param test Description of the failure or assertion that failed. This |
| 179 | * MUST be a string literal. This normally has the form |
| 180 | * "EXPR1 <= EXPR2" where EXPR1 has the value \p value1 |
| 181 | * and EXPR2 has the value \p value2. |
| 182 | * \param line_no Line number where the failure originated. |
| 183 | * \param filename Filename where the failure originated. |
| 184 | * \param value1 The first value to compare. |
| 185 | * \param value2 The second value to compare. |
| 186 | * |
| 187 | * \return \c 1 if \p value1 <= \p value2, otherwise \c 0. |
| 188 | */ |
| 189 | int mbedtls_test_le_s( const char *test, int line_no, const char* filename, |
| 190 | long long value1, long long value2 ); |
| 191 | |
| 192 | /** |
Ronald Cron | ab500cb | 2020-07-01 17:09:10 +0200 | [diff] [blame] | 193 | * \brief This function decodes the hexadecimal representation of |
| 194 | * data. |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 195 | * |
| 196 | * \note The output buffer can be the same as the input buffer. For |
| 197 | * any other overlapping of the input and output buffers, the |
| 198 | * behavior is undefined. |
| 199 | * |
| 200 | * \param obuf Output buffer. |
| 201 | * \param obufmax Size in number of bytes of \p obuf. |
| 202 | * \param ibuf Input buffer. |
| 203 | * \param len The number of unsigned char written in \p obuf. This must |
| 204 | * not be \c NULL. |
| 205 | * |
| 206 | * \return \c 0 on success. |
| 207 | * \return \c -1 if the output buffer is too small or the input string |
Ronald Cron | ab500cb | 2020-07-01 17:09:10 +0200 | [diff] [blame] | 208 | * is not a valid hexadecimal representation. |
Ronald Cron | a0c2539 | 2020-06-18 10:10:46 +0200 | [diff] [blame] | 209 | */ |
| 210 | int mbedtls_test_unhexify( unsigned char *obuf, size_t obufmax, |
| 211 | const char *ibuf, size_t *len ); |
| 212 | |
Ronald Cron | 72d628f | 2020-06-08 17:05:57 +0200 | [diff] [blame] | 213 | void mbedtls_test_hexify( unsigned char *obuf, |
| 214 | const unsigned char *ibuf, |
| 215 | int len ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * Allocate and zeroize a buffer. |
| 219 | * |
| 220 | * If the size if zero, a pointer to a zeroized 1-byte buffer is returned. |
| 221 | * |
| 222 | * For convenience, dies if allocation fails. |
| 223 | */ |
Ronald Cron | 690f3eb | 2020-06-10 10:42:18 +0200 | [diff] [blame] | 224 | unsigned char *mbedtls_test_zero_alloc( size_t len ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 225 | |
| 226 | /** |
| 227 | * Allocate and fill a buffer from hex data. |
| 228 | * |
| 229 | * The buffer is sized exactly as needed. This allows to detect buffer |
| 230 | * overruns (including overreads) when running the test suite under valgrind. |
| 231 | * |
| 232 | * If the size if zero, a pointer to a zeroized 1-byte buffer is returned. |
| 233 | * |
| 234 | * For convenience, dies if allocation fails. |
| 235 | */ |
Ronald Cron | a256c70 | 2020-06-10 10:53:11 +0200 | [diff] [blame] | 236 | unsigned char *mbedtls_test_unhexify_alloc( const char *ibuf, size_t *olen ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 237 | |
Ronald Cron | de70b16 | 2020-06-10 11:03:08 +0200 | [diff] [blame] | 238 | int mbedtls_test_hexcmp( uint8_t * a, uint8_t * b, |
| 239 | uint32_t a_len, uint32_t b_len ); |
Ronald Cron | f40529d | 2020-06-09 16:27:37 +0200 | [diff] [blame] | 240 | |
Ronald Cron | a123614 | 2020-07-01 16:01:21 +0200 | [diff] [blame] | 241 | #if defined(MBEDTLS_CHECK_PARAMS) |
| 242 | |
| 243 | typedef struct |
| 244 | { |
| 245 | const char *failure_condition; |
| 246 | const char *file; |
| 247 | int line; |
| 248 | } |
| 249 | mbedtls_test_param_failed_location_record_t; |
| 250 | |
| 251 | /** |
| 252 | * \brief Get the location record of the last call to |
| 253 | * mbedtls_test_param_failed(). |
| 254 | * |
| 255 | * \note The call expectation is set up and active until the next call to |
| 256 | * mbedtls_test_param_failed_check_expected_call() or |
| 257 | * mbedtls_param_failed() that cancels it. |
| 258 | */ |
| 259 | void mbedtls_test_param_failed_get_location_record( |
| 260 | mbedtls_test_param_failed_location_record_t *location_record ); |
| 261 | |
| 262 | /** |
| 263 | * \brief State that a call to mbedtls_param_failed() is expected. |
| 264 | * |
| 265 | * \note The call expectation is set up and active until the next call to |
| 266 | * mbedtls_test_param_failed_check_expected_call() or |
| 267 | * mbedtls_param_failed that cancel it. |
| 268 | */ |
| 269 | void mbedtls_test_param_failed_expect_call( void ); |
| 270 | |
| 271 | /** |
| 272 | * \brief Check whether mbedtls_param_failed() has been called as expected. |
| 273 | * |
| 274 | * \note Check whether mbedtls_param_failed() has been called between the |
| 275 | * last call to mbedtls_test_param_failed_expect_call() and the call |
| 276 | * to this function. |
| 277 | * |
| 278 | * \return \c 0 Since the last call to mbedtls_param_failed_expect_call(), |
| 279 | * mbedtls_param_failed() has been called. |
| 280 | * \c -1 Otherwise. |
| 281 | */ |
| 282 | int mbedtls_test_param_failed_check_expected_call( void ); |
| 283 | |
| 284 | /** |
Ronald Cron | bf4f408 | 2020-09-25 10:45:06 +0200 | [diff] [blame] | 285 | * \brief Get the address of the object of type jmp_buf holding the execution |
Ronald Cron | a123614 | 2020-07-01 16:01:21 +0200 | [diff] [blame] | 286 | * state information used by mbedtls_param_failed() to do a long jump. |
| 287 | * |
| 288 | * \note If a call to mbedtls_param_failed() is not expected in the sense |
| 289 | * that there is no call to mbedtls_test_param_failed_expect_call() |
| 290 | * preceding it, then mbedtls_param_failed() will try to restore the |
| 291 | * execution to the state stored in the jmp_buf object whose address |
| 292 | * is returned by the present function. |
| 293 | * |
Ronald Cron | bf4f408 | 2020-09-25 10:45:06 +0200 | [diff] [blame] | 294 | * \note This function is intended to provide the parameter of the |
| 295 | * setjmp() function to set-up where mbedtls_param_failed() should |
| 296 | * long-jump if it has to. It is foreseen to be used as: |
| 297 | * |
| 298 | * setjmp( mbedtls_test_param_failed_get_state_buf() ). |
| 299 | * |
| 300 | * \note The type of the returned value is not jmp_buf as jmp_buf is an |
| 301 | * an array type (C specification) and a function cannot return an |
| 302 | * array type. |
| 303 | * |
| 304 | * \note The type of the returned value is not jmp_buf* as then the return |
| 305 | * value couldn't be used by setjmp(), as its parameter's type is |
| 306 | * jmp_buf. |
Ronald Cron | a123614 | 2020-07-01 16:01:21 +0200 | [diff] [blame] | 307 | * |
| 308 | * \return Address of the object of type jmp_buf holding the execution state |
| 309 | * information used by mbedtls_param_failed() to do a long jump. |
| 310 | */ |
| 311 | void* mbedtls_test_param_failed_get_state_buf( void ); |
| 312 | |
| 313 | /** |
| 314 | * \brief Reset the execution state used by mbedtls_param_failed() to do a |
| 315 | * long jump. |
| 316 | * |
| 317 | * \note If a call to mbedtls_param_failed() is not expected in the sense |
| 318 | * that there is no call to mbedtls_test_param_failed_expect_call() |
| 319 | * preceding it, then mbedtls_param_failed() will try to restore the |
| 320 | * execution state that this function reset. |
| 321 | * |
| 322 | * \note It is recommended to reset the execution state when the state |
| 323 | * is not relevant anymore. That way an unexpected call to |
| 324 | * mbedtls_param_failed() will not trigger a long jump with |
| 325 | * undefined behavior but rather a long jump that will rather fault. |
| 326 | */ |
| 327 | void mbedtls_test_param_failed_reset_state( void ); |
| 328 | #endif /* MBEDTLS_CHECK_PARAMS */ |
| 329 | |
Gilles Peskine | 1dc19ff | 2021-02-08 20:59:39 +0100 | [diff] [blame] | 330 | #if defined(MBEDTLS_PSA_CRYPTO_C) && defined(MBEDTLS_PSA_CRYPTO_EXTERNAL_RNG) |
Gilles Peskine | 1af872d | 2021-01-20 20:02:01 +0100 | [diff] [blame] | 331 | #include "test/fake_external_rng_for_test.h" |
| 332 | #endif |
| 333 | |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 334 | #if defined(MBEDTLS_TEST_MUTEX_USAGE) |
Gilles Peskine | 1061ec6 | 2021-01-29 21:17:11 +0100 | [diff] [blame] | 335 | /** Permanently activate the mutex usage verification framework. See |
| 336 | * threading_helpers.c for information. */ |
| 337 | void mbedtls_test_mutex_usage_init( void ); |
Gilles Peskine | 2a4c598 | 2021-01-29 21:18:09 +0100 | [diff] [blame] | 338 | |
| 339 | /** Call this function after executing a test case to check for mutex usage |
| 340 | * errors. */ |
| 341 | void mbedtls_test_mutex_usage_check( void ); |
Gilles Peskine | 1061ec6 | 2021-01-29 21:17:11 +0100 | [diff] [blame] | 342 | #endif /* MBEDTLS_TEST_MUTEX_USAGE */ |
| 343 | |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 344 | #if defined(MBEDTLS_TEST_HOOKS) |
| 345 | /** |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 346 | * \brief Check that only a pure high-level error code is being combined with |
| 347 | * a pure low-level error code as otherwise the resultant error code |
Chris Jones | 5e8805a | 2021-01-12 15:21:57 +0000 | [diff] [blame] | 348 | * would be corrupted. |
Chris Jones | 3f613c1 | 2021-03-31 09:34:22 +0100 | [diff] [blame] | 349 | * |
| 350 | * \note Both high-level and low-level error codes cannot be greater than |
| 351 | * zero however can be zero. If one error code is zero then the |
| 352 | * other error code is returned even if both codes are zero. |
| 353 | * |
| 354 | * \note If the check fails, fail the test currently being run. |
Chris Jones | 96ae73b | 2021-01-08 17:04:59 +0000 | [diff] [blame] | 355 | */ |
| 356 | void mbedtls_test_err_add_check( int high, int low, |
| 357 | const char *file, int line); |
| 358 | #endif |
| 359 | |
Gilles Peskine | db47971 | 2021-06-11 14:13:53 +0200 | [diff] [blame] | 360 | #if defined(MBEDTLS_BIGNUM_C) |
Werner Lewis | 24b6078 | 2022-07-07 15:08:17 +0100 | [diff] [blame] | 361 | /** Read an MPI from a hexadecimal string. |
Gilles Peskine | db47971 | 2021-06-11 14:13:53 +0200 | [diff] [blame] | 362 | * |
| 363 | * Like mbedtls_mpi_read_string(), but size the resulting bignum based |
| 364 | * on the number of digits in the string. In particular, construct a |
| 365 | * bignum with 0 limbs for an empty string, and a bignum with leading 0 |
| 366 | * limbs if the string has sufficiently many leading 0 digits. |
| 367 | * |
| 368 | * This is important so that the "0 (null)" and "0 (1 limb)" and |
| 369 | * "leading zeros" test cases do what they claim. |
| 370 | * |
| 371 | * \param[out] X The MPI object to populate. It must be initialized. |
Werner Lewis | 24b6078 | 2022-07-07 15:08:17 +0100 | [diff] [blame] | 372 | * \param[in] s The null-terminated hexadecimal string to read from. |
Gilles Peskine | db47971 | 2021-06-11 14:13:53 +0200 | [diff] [blame] | 373 | * |
| 374 | * \return \c 0 on success, an \c MBEDTLS_ERR_MPI_xxx error code otherwise. |
| 375 | */ |
Werner Lewis | 24b6078 | 2022-07-07 15:08:17 +0100 | [diff] [blame] | 376 | int mbedtls_test_read_mpi( mbedtls_mpi *X, const char *s ); |
Gilles Peskine | db47971 | 2021-06-11 14:13:53 +0200 | [diff] [blame] | 377 | #endif /* MBEDTLS_BIGNUM_C */ |
| 378 | |
Ronald Cron | b6d6d4c | 2020-06-03 10:11:18 +0200 | [diff] [blame] | 379 | #endif /* TEST_HELPERS_H */ |