blob: 85ca533da52f507c79fbbb0a7ec5ebb081b4d177 [file] [log] [blame]
Gabor Mezeic5328cf2022-07-18 23:13:13 +02001/**
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 Follath5005edb2022-07-19 12:45:13 +010020#ifndef MBEDTLS_BIGNUM_MOD_RAW_H
21#define MBEDTLS_BIGNUM_MOD_RAW_H
Gabor Mezeic5328cf2022-07-18 23:13:13 +020022
23#include "common.h"
24
25#if defined(MBEDTLS_BIGNUM_C)
26#include "mbedtls/bignum.h"
27#endif
28
Gabor Mezei37b06362022-08-02 17:22:18 +020029/** Import X from unsigned binary data.
30 *
Janos Follathdae11472022-08-08 11:50:02 +010031 * The MPI needs to have enough limbs to store the full value (in particular,
32 * this function does not skip 0s in the input).
Gabor Mezei37b06362022-08-02 17:22:18 +020033 *
Janos Follathdae11472022-08-08 11:50:02 +010034 * \param X The address of the MPI. The size is determined by \p m. (In
35 * particular, it must have at least as many limbs as the modulus
36 * \p m.)
37 * \param m The address of the modulus related to \p X.
Gabor Mezei37b06362022-08-02 17:22:18 +020038 * \param buf The input buffer to import from.
Janos Follath8ff07292022-08-08 08:39:52 +010039 * \param buflen The length in bytes of \p buf.
Gabor Mezei37b06362022-08-02 17:22:18 +020040 *
41 * \return \c 0 if successful.
42 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
43 * large enough to hold the value in \p buf.
Janos Follath8ff07292022-08-08 08:39:52 +010044 * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
Janos Follathdae11472022-08-08 11:50:02 +010045 * of \p m is invalid or \p X is not less than \p m.
Gabor Mezei37b06362022-08-02 17:22:18 +020046 */
Gabor Mezeic5328cf2022-07-18 23:13:13 +020047int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
48 mbedtls_mpi_mod_modulus *m,
49 unsigned char *buf,
50 size_t buflen );
51
Gabor Mezei37b06362022-08-02 17:22:18 +020052/** Export X into unsigned binary data.
53 *
Janos Follathdae11472022-08-08 11:50:02 +010054 * \param X The address of the MPI. The size is determined by \p m. (In
55 * particular, it must have at least as many limbs as the modulus
56 * \p m.)
57 * \param m The address of the modulus related to \p X.
58 * \param buf The output buffer to export to.
Janos Follath8ff07292022-08-08 08:39:52 +010059 * \param buflen The length in bytes of \p buf.
Gabor Mezei37b06362022-08-02 17:22:18 +020060 *
61 * \return \c 0 if successful.
62 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p buf isn't
63 * large enough to hold the value of \p X.
Janos Follath8ff07292022-08-08 08:39:52 +010064 * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
Gabor Mezei37b06362022-08-02 17:22:18 +020065 * of \p m is invalid.
66 */
Gabor Mezeic5328cf2022-07-18 23:13:13 +020067int mbedtls_mpi_mod_raw_write( mbedtls_mpi_uint *X,
68 mbedtls_mpi_mod_modulus *m,
69 unsigned char *buf,
70 size_t buflen );
71
Janos Follath5005edb2022-07-19 12:45:13 +010072#endif /* MBEDTLS_BIGNUM_MOD_RAW_H */