2022-07-18 23:13:13 +02:00
|
|
|
/**
|
2022-08-19 13:09:17 +02:00
|
|
|
* Low-level modular bignum functions
|
2022-08-11 18:42:59 +02:00
|
|
|
*
|
2022-08-22 10:06:32 +02:00
|
|
|
* This interface should only be used by the higher-level modular bignum
|
2022-08-11 18:42:59 +02:00
|
|
|
* module (bignum_mod.c) and the ECP module (ecp.c, ecp_curves.c). All other
|
2022-08-22 10:06:32 +02:00
|
|
|
* modules should use the high-level modular bignum interface (bignum_mod.h)
|
2022-08-11 18:42:59 +02:00
|
|
|
* or the legacy bignum interface (bignum.h).
|
2022-07-18 23:13:13 +02:00
|
|
|
*
|
|
|
|
* Copyright The Mbed TLS Contributors
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
|
|
* not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2022-07-19 13:45:13 +02:00
|
|
|
#ifndef MBEDTLS_BIGNUM_MOD_RAW_H
|
|
|
|
#define MBEDTLS_BIGNUM_MOD_RAW_H
|
2022-07-18 23:13:13 +02:00
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
|
|
|
|
#if defined(MBEDTLS_BIGNUM_C)
|
|
|
|
#include "mbedtls/bignum.h"
|
|
|
|
#endif
|
|
|
|
|
2022-08-09 14:34:54 +02:00
|
|
|
#include "bignum_mod.h"
|
|
|
|
|
2022-08-02 17:22:18 +02:00
|
|
|
/** Import X from unsigned binary data.
|
|
|
|
*
|
2022-08-11 18:42:59 +02:00
|
|
|
* The MPI needs to have enough limbs to store the full value (including any
|
|
|
|
* most significant zero bytes in the input).
|
2022-08-02 17:22:18 +02:00
|
|
|
*
|
2022-08-19 13:24:40 +02:00
|
|
|
* \param[out] X The address of the MPI. The size is determined by \p m.
|
|
|
|
* (In particular, it must have at least as many limbs as
|
|
|
|
* the modulus \p m.)
|
|
|
|
* \param[in] m The address of the modulus related to \p X.
|
|
|
|
* \param[in] input The input buffer to import from.
|
|
|
|
* \param input_length The length in bytes of \p input.
|
2022-08-02 17:22:18 +02:00
|
|
|
*
|
|
|
|
* \return \c 0 if successful.
|
|
|
|
* \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
|
2022-08-19 13:24:40 +02:00
|
|
|
* large enough to hold the value in \p input.
|
2022-08-08 09:39:52 +02:00
|
|
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
|
2022-08-08 12:50:02 +02:00
|
|
|
* of \p m is invalid or \p X is not less than \p m.
|
2022-08-02 17:22:18 +02:00
|
|
|
*/
|
2022-07-18 23:13:13 +02:00
|
|
|
int mbedtls_mpi_mod_raw_read( mbedtls_mpi_uint *X,
|
2022-08-19 11:58:34 +02:00
|
|
|
const mbedtls_mpi_mod_modulus *m,
|
2022-08-19 13:24:40 +02:00
|
|
|
const unsigned char *input,
|
|
|
|
size_t input_length );
|
2022-07-18 23:13:13 +02:00
|
|
|
|
2022-08-19 13:24:40 +02:00
|
|
|
/** Export A into unsigned binary data.
|
2022-08-02 17:22:18 +02:00
|
|
|
*
|
2022-08-19 13:24:40 +02:00
|
|
|
* \param[in] A The address of the MPI. The size is determined by \p m.
|
|
|
|
* (In particular, it must have at least as many limbs as
|
|
|
|
* the modulus \p m.)
|
|
|
|
* \param[in] m The address of the modulus related to \p A.
|
|
|
|
* \param[out] output The output buffer to export to.
|
|
|
|
* \param output_length The length in bytes of \p output.
|
2022-08-02 17:22:18 +02:00
|
|
|
*
|
|
|
|
* \return \c 0 if successful.
|
2022-08-19 13:24:40 +02:00
|
|
|
* \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
|
|
|
|
* large enough to hold the value of \p A.
|
2022-08-08 09:39:52 +02:00
|
|
|
* \return #MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the external representation
|
2022-08-02 17:22:18 +02:00
|
|
|
* of \p m is invalid.
|
|
|
|
*/
|
2022-08-19 13:24:40 +02:00
|
|
|
int mbedtls_mpi_mod_raw_write( const mbedtls_mpi_uint *A,
|
2022-08-19 11:58:34 +02:00
|
|
|
const mbedtls_mpi_mod_modulus *m,
|
2022-08-19 13:24:40 +02:00
|
|
|
unsigned char *output,
|
|
|
|
size_t output_length );
|
2022-07-18 23:13:13 +02:00
|
|
|
|
2022-07-19 13:45:13 +02:00
|
|
|
#endif /* MBEDTLS_BIGNUM_MOD_RAW_H */
|