Gabor Mezei | c5328cf | 2022-07-18 23:13:13 +0200 | [diff] [blame] | 1 | /** |
| 2 | * Internal bignum 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 | |
Janos Follath | 5005edb | 2022-07-19 12:45:13 +0100 | [diff] [blame] | 20 | #ifndef MBEDTLS_BIGNUM_MOD_RAW_H |
| 21 | #define MBEDTLS_BIGNUM_MOD_RAW_H |
Gabor Mezei | c5328cf | 2022-07-18 23:13:13 +0200 | [diff] [blame] | 22 | |
| 23 | #include "common.h" |
| 24 | |
| 25 | #if defined(MBEDTLS_BIGNUM_C) |
| 26 | #include "mbedtls/bignum.h" |
| 27 | #endif |
| 28 | |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame^] | 29 | /** Import X from unsigned binary data. |
| 30 | * |
| 31 | * This function is guaranteed to return an MPI with exactly the necessary |
| 32 | * number of limbs (in particular, it does not skip 0s in the input). |
| 33 | * |
| 34 | * \param X The address of the MPI. The size is determined by \p m. |
| 35 | * \param m The address of a modulus related to \p X. |
| 36 | * \param buf The input buffer to import from. |
| 37 | * \param buflen Tne length in bytes of \p buf. |
| 38 | * |
| 39 | * \return \c 0 if successful. |
| 40 | * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't |
| 41 | * large enough to hold the value in \p buf. |
| 42 | * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external reprezentation |
| 43 | * of \p m is invalid or \p X is less then \p m. |
| 44 | */ |
Gabor Mezei | c5328cf | 2022-07-18 23:13:13 +0200 | [diff] [blame] | 45 | int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, |
| 46 | mbedtls_mpi_mod_modulus *m, |
| 47 | unsigned char *buf, |
| 48 | size_t buflen ); |
| 49 | |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame^] | 50 | /** Export X into unsigned binary data. |
| 51 | * |
| 52 | * \param X The address of the MPI. The size is determined by \p m. |
| 53 | * \param m The address of a modulus related to \p X. |
| 54 | * \param buf The output buffer to import. |
| 55 | * \param buflen Tne length in bytes of \p buf. |
| 56 | * |
| 57 | * \return \c 0 if successful. |
| 58 | * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't |
| 59 | * large enough to hold the value of \p X. |
| 60 | * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external reprezentation |
| 61 | * of \p m is invalid. |
| 62 | */ |
Gabor Mezei | c5328cf | 2022-07-18 23:13:13 +0200 | [diff] [blame] | 63 | int mbedtls_mpi_mod_raw_write( mbedtls_mpi_uint *X, |
| 64 | mbedtls_mpi_mod_modulus *m, |
| 65 | unsigned char *buf, |
| 66 | size_t buflen ); |
| 67 | |
Janos Follath | 5005edb | 2022-07-19 12:45:13 +0100 | [diff] [blame] | 68 | #endif /* MBEDTLS_BIGNUM_MOD_RAW_H */ |