blob: aba5d0699db101c7ed378240501e5e3779c31ebd [file] [log] [blame]
Gabor Mezeic5328cf2022-07-18 23:13:13 +02001/**
Janos Follatha95f2042022-08-19 12:09:17 +01002 * Low-level modular bignum functions
Janos Follath63184682022-08-11 17:42:59 +01003 *
Janos Follathaf3f39c2022-08-22 09:06:32 +01004 * This interface should only be used by the higher-level modular bignum
Janos Follath63184682022-08-11 17:42:59 +01005 * module (bignum_mod.c) and the ECP module (ecp.c, ecp_curves.c). All other
Janos Follathaf3f39c2022-08-22 09:06:32 +01006 * modules should use the high-level modular bignum interface (bignum_mod.h)
Janos Follath63184682022-08-11 17:42:59 +01007 * or the legacy bignum interface (bignum.h).
Gilles Peskine7f887bd2022-09-27 13:12:30 +02008 */
9
10/*
Gabor Mezeic5328cf2022-07-18 23:13:13 +020011 * Copyright The Mbed TLS Contributors
12 * SPDX-License-Identifier: Apache-2.0
13 *
14 * Licensed under the Apache License, Version 2.0 (the "License"); you may
15 * not use this file except in compliance with the License.
16 * You may obtain a copy of the License at
17 *
18 * http://www.apache.org/licenses/LICENSE-2.0
19 *
20 * Unless required by applicable law or agreed to in writing, software
21 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
22 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23 * See the License for the specific language governing permissions and
24 * limitations under the License.
25 */
26
Janos Follath5005edb2022-07-19 12:45:13 +010027#ifndef MBEDTLS_BIGNUM_MOD_RAW_H
28#define MBEDTLS_BIGNUM_MOD_RAW_H
Gabor Mezeic5328cf2022-07-18 23:13:13 +020029
30#include "common.h"
31
32#if defined(MBEDTLS_BIGNUM_C)
33#include "mbedtls/bignum.h"
34#endif
35
Janos Follath0ded6312022-08-09 13:34:54 +010036#include "bignum_mod.h"
37
Gabor Mezei37b06362022-08-02 17:22:18 +020038/** Import X from unsigned binary data.
39 *
Janos Follath63184682022-08-11 17:42:59 +010040 * The MPI needs to have enough limbs to store the full value (including any
41 * most significant zero bytes in the input).
Gabor Mezei37b06362022-08-02 17:22:18 +020042 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010043 * \param[out] X The address of the MPI. The size is determined by \p m.
44 * (In particular, it must have at least as many limbs as
45 * the modulus \p m.)
46 * \param[in] m The address of the modulus related to \p X.
47 * \param[in] input The input buffer to import from.
48 * \param input_length The length in bytes of \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +020049 *
50 * \return \c 0 if successful.
51 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
Janos Follathb7a88ec2022-08-19 12:24:40 +010052 * large enough to hold the value in \p input.
Janos Follath8ff07292022-08-08 08:39:52 +010053 * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
Janos Follathdae11472022-08-08 11:50:02 +010054 * of \p m is invalid or \p X is not less than \p m.
Gabor Mezei37b06362022-08-02 17:22:18 +020055 */
Gabor Mezeic5328cf2022-07-18 23:13:13 +020056int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
Janos Follath6b8a4ad2022-08-19 10:58:34 +010057 const mbedtls_mpi_mod_modulus *m,
Janos Follathb7a88ec2022-08-19 12:24:40 +010058 const unsigned char *input,
59 size_t input_length );
Gabor Mezeic5328cf2022-07-18 23:13:13 +020060
Janos Follathb7a88ec2022-08-19 12:24:40 +010061/** Export A into unsigned binary data.
Gabor Mezei37b06362022-08-02 17:22:18 +020062 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010063 * \param[in] A The address of the MPI. The size is determined by \p m.
64 * (In particular, it must have at least as many limbs as
65 * the modulus \p m.)
66 * \param[in] m The address of the modulus related to \p A.
67 * \param[out] output The output buffer to export to.
68 * \param output_length The length in bytes of \p output.
Gabor Mezei37b06362022-08-02 17:22:18 +020069 *
70 * \return \c 0 if successful.
Janos Follathb7a88ec2022-08-19 12:24:40 +010071 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
72 * large enough to hold the value of \p A.
Janos Follath8ff07292022-08-08 08:39:52 +010073 * \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
Gabor Mezei37b06362022-08-02 17:22:18 +020074 * of \p m is invalid.
75 */
Janos Follathb7a88ec2022-08-19 12:24:40 +010076int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A,
Janos Follath6b8a4ad2022-08-19 10:58:34 +010077 const mbedtls_mpi_mod_modulus *m,
Janos Follathb7a88ec2022-08-19 12:24:40 +010078 unsigned char *output,
79 size_t output_length );
Gabor Mezeic5328cf2022-07-18 23:13:13 +020080
Janos Follath5005edb2022-07-19 12:45:13 +010081#endif /* MBEDTLS_BIGNUM_MOD_RAW_H */