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 | |
Janos Follath | 0ded631 | 2022-08-09 13:34:54 +0100 | [diff] [blame] | 29 | #include "bignum_mod.h" |
| 30 | |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 31 | /** Import X from unsigned binary data. |
| 32 | * |
Janos Follath | dae1147 | 2022-08-08 11:50:02 +0100 | [diff] [blame] | 33 | * The MPI needs to have enough limbs to store the full value (in particular, |
| 34 | * this function does not skip 0s in the input). |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 35 | * |
Janos Follath | dae1147 | 2022-08-08 11:50:02 +0100 | [diff] [blame] | 36 | * \param X The address of the MPI. The size is determined by \p m. (In |
| 37 | * particular, it must have at least as many limbs as the modulus |
| 38 | * \p m.) |
| 39 | * \param m The address of the modulus related to \p X. |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 40 | * \param buf The input buffer to import from. |
Janos Follath | 8ff0729 | 2022-08-08 08:39:52 +0100 | [diff] [blame] | 41 | * \param buflen The length in bytes of \p buf. |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 42 | * |
| 43 | * \return \c 0 if successful. |
| 44 | * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't |
| 45 | * large enough to hold the value in \p buf. |
Janos Follath | 8ff0729 | 2022-08-08 08:39:52 +0100 | [diff] [blame] | 46 | * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation |
Janos Follath | dae1147 | 2022-08-08 11:50:02 +0100 | [diff] [blame] | 47 | * of \p m is invalid or \p X is not less than \p m. |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 48 | */ |
Gabor Mezei | c5328cf | 2022-07-18 23:13:13 +0200 | [diff] [blame] | 49 | int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X, |
| 50 | mbedtls_mpi_mod_modulus *m, |
| 51 | unsigned char *buf, |
| 52 | size_t buflen ); |
| 53 | |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 54 | /** Export X into unsigned binary data. |
| 55 | * |
Janos Follath | dae1147 | 2022-08-08 11:50:02 +0100 | [diff] [blame] | 56 | * \param X The address of the MPI. The size is determined by \p m. (In |
| 57 | * particular, it must have at least as many limbs as the modulus |
| 58 | * \p m.) |
| 59 | * \param m The address of the modulus related to \p X. |
| 60 | * \param buf The output buffer to export to. |
Janos Follath | 8ff0729 | 2022-08-08 08:39:52 +0100 | [diff] [blame] | 61 | * \param buflen The length in bytes of \p buf. |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 62 | * |
| 63 | * \return \c 0 if successful. |
| 64 | * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't |
| 65 | * large enough to hold the value of \p X. |
Janos Follath | 8ff0729 | 2022-08-08 08:39:52 +0100 | [diff] [blame] | 66 | * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation |
Gabor Mezei | 37b0636 | 2022-08-02 17:22:18 +0200 | [diff] [blame] | 67 | * of \p m is invalid. |
| 68 | */ |
Gabor Mezei | c5328cf | 2022-07-18 23:13:13 +0200 | [diff] [blame] | 69 | int mbedtls_mpi_mod_raw_write( mbedtls_mpi_uint *X, |
| 70 | mbedtls_mpi_mod_modulus *m, |
| 71 | unsigned char *buf, |
| 72 | size_t buflen ); |
| 73 | |
Janos Follath | 5005edb | 2022-07-19 12:45:13 +0100 | [diff] [blame] | 74 | #endif /* MBEDTLS_BIGNUM_MOD_RAW_H */ |