blob: bd246d5e369974290ef2b1d020849cf97eacbaff [file] [log] [blame]
Gabor Mezeib9030702022-07-18 23:09:45 +02001/**
Janos Follath63184682022-08-11 17:42:59 +01002 * Core bignum functions
3 *
Janos Follathaf3f39c2022-08-22 09:06:32 +01004 * This interface should only be used by the legacy bignum module (bignum.h)
Janos Follath63184682022-08-11 17:42:59 +01005 * and the modular bignum modules (bignum_mod.c, bignum_mod_raw.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).
Gabor Mezeib9030702022-07-18 23:09:45 +02008 *
9 * Copyright The Mbed TLS Contributors
10 * SPDX-License-Identifier: Apache-2.0
11 *
12 * Licensed under the Apache License, Version 2.0 (the "License"); you may
13 * not use this file except in compliance with the License.
14 * You may obtain a copy of the License at
15 *
16 * http://www.apache.org/licenses/LICENSE-2.0
17 *
18 * Unless required by applicable law or agreed to in writing, software
19 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
20 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 * See the License for the specific language governing permissions and
22 * limitations under the License.
23 */
24
25#ifndef MBEDTLS_BIGNUM_CORE_H
26#define MBEDTLS_BIGNUM_CORE_H
27
28#include "common.h"
29
30#if defined(MBEDTLS_BIGNUM_C)
31#include "mbedtls/bignum.h"
32#endif
33
Tom Cosgrove5eefc3d2022-08-31 17:16:50 +010034#define ciL ( sizeof(mbedtls_mpi_uint) ) /* chars in limb */
35#define biL ( ciL << 3 ) /* bits in limb */
36#define biH ( ciL << 2 ) /* half limb size */
37
38/*
39 * Convert between bits/chars and number of limbs
40 * Divide first in order to avoid potential overflows
41 */
42#define BITS_TO_LIMBS(i) ( (i) / biL + ( (i) % biL != 0 ) )
43#define CHARS_TO_LIMBS(i) ( (i) / ciL + ( (i) % ciL != 0 ) )
44/* Get a specific byte, without range checks. */
45#define GET_BYTE( X, i ) \
46 ( ( (X)[(i) / ciL] >> ( ( (i) % ciL ) * 8 ) ) & 0xff )
47
Gabor Mezei37b06362022-08-02 17:22:18 +020048/** Count leading zero bits in a given integer.
49 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010050 * \param a Integer to count leading zero bits.
Gabor Mezei37b06362022-08-02 17:22:18 +020051 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010052 * \return The number of leading zero bits in \p a.
Gabor Mezei37b06362022-08-02 17:22:18 +020053 */
Janos Follath2e328c82022-08-22 11:19:10 +010054size_t mbedtls_mpi_core_clz( mbedtls_mpi_uint a );
Janos Follath4670f882022-07-21 18:25:42 +010055
Janos Follatha95f2042022-08-19 12:09:17 +010056/** Return the minimum number of bits required to represent the value held
Janos Follath63184682022-08-11 17:42:59 +010057 * in the MPI.
58 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010059 * \note This function returns 0 if all the limbs of \p A are 0.
Gabor Mezei37b06362022-08-02 17:22:18 +020060 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010061 * \param[in] A The address of the MPI.
Janos Follathc4596412022-08-22 10:01:27 +010062 * \param A_limbs The number of limbs of \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +020063 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010064 * \return The number of bits in \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +020065 */
Janos Follathaf3f39c2022-08-22 09:06:32 +010066size_t mbedtls_mpi_core_bitlen( const mbedtls_mpi_uint *A, size_t A_limbs );
Janos Follath4670f882022-07-21 18:25:42 +010067
Gabor Mezei37b06362022-08-02 17:22:18 +020068/** Convert a big-endian byte array aligned to the size of mbedtls_mpi_uint
69 * into the storage form used by mbedtls_mpi.
70 *
Janos Follathb7a88ec2022-08-19 12:24:40 +010071 * \param[in,out] A The address of the MPI.
Janos Follathc4596412022-08-22 10:01:27 +010072 * \param A_limbs The number of limbs of \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +020073 */
Janos Follathb7a88ec2022-08-19 12:24:40 +010074void mbedtls_mpi_core_bigendian_to_host( mbedtls_mpi_uint *A,
Janos Follathc4596412022-08-22 10:01:27 +010075 size_t A_limbs );
Janos Follath4670f882022-07-21 18:25:42 +010076
Gabor Mezeie1d31c42022-09-12 16:25:24 +020077/**
78 * \brief Perform a safe conditional copy of MPI which doesn't reveal whether
79 * the condition was true or not.
80 *
Gabor Mezei86dfe382022-09-30 14:03:04 +020081 * \param[out] X The address of the first MPI. This must be initialized.
Gabor Mezeidba26772022-10-03 17:01:02 +020082 * Must have enough limbs to store the full value of \p A.
Gabor Mezei86dfe382022-09-30 14:03:04 +020083 * \param[in] A The address of the second MPI. This must be initialized.
Gabor Mezei1c628d52022-09-27 12:13:51 +020084 * \param limbs The number of limbs of \p A.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020085 * \param assign The condition deciding whether to perform the
86 * assignment or not. Must be either 0 or 1:
Gabor Mezei1c628d52022-09-27 12:13:51 +020087 * * \c 1: Perform the assignment `X = A`.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020088 * * \c 0: Keep the original value of \p X.
89 *
90 * \note This function avoids leaking any information about whether
91 * the assignment was done or not.
92 *
93 * \warning If \p assign is neither 0 nor 1, the result of this function
94 * is indeterminate, and the resulting value in \p X might be
95 * neither its original value nor the value in \p Y.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020096 */
Gabor Mezei9f6615f2022-09-15 19:12:06 +020097void mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X,
Gabor Mezei1c628d52022-09-27 12:13:51 +020098 const mbedtls_mpi_uint *A,
Gabor Mezei3eff4252022-09-26 17:26:42 +020099 size_t limbs,
Gabor Mezei9f6615f2022-09-15 19:12:06 +0200100 unsigned char assign );
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200101
102/**
Gabor Mezei2b5bf4c2022-09-26 17:09:58 +0200103 * \brief Perform a safe conditional swap of MPI which doesn't reveal whether
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200104 * the condition was true or not.
105 *
Gabor Mezei86dfe382022-09-30 14:03:04 +0200106 * \param[in,out] X The address of the first MPI.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200107 * This must be initialized.
Gabor Mezei86dfe382022-09-30 14:03:04 +0200108 * \param[in,out] Y The address of the second MPI.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200109 * This must be initialized.
Gabor Mezeie5b85852022-09-30 13:54:02 +0200110 * \param limbs The number of limbs of \p X and \p Y.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200111 * \param swap The condition deciding whether to perform
112 * the swap or not. Must be either 0 or 1:
Gabor Mezeie5b85852022-09-30 13:54:02 +0200113 * * \c 1: Swap the values of \p X and \p Y.
114 * * \c 0: Keep the original values of \p X and \p Y.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200115 *
116 * \note This function avoids leaking any information about whether
117 * the swap was done or not.
118 *
119 * \warning If \p swap is neither 0 nor 1, the result of this function
Gabor Mezeie5b85852022-09-30 13:54:02 +0200120 * is indeterminate, and both \p X and \p Y might end up with
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200121 * values different to either of the original ones.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200122 */
Gabor Mezeie5b85852022-09-30 13:54:02 +0200123void mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X,
124 mbedtls_mpi_uint *Y,
Gabor Mezeicfc0eb82022-09-15 20:15:34 +0200125 size_t limbs,
Gabor Mezei9f6615f2022-09-15 19:12:06 +0200126 unsigned char swap );
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200127
Janos Follathaf3f39c2022-08-22 09:06:32 +0100128/** Import X from unsigned binary data, little-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200129 *
Janos Follath63184682022-08-11 17:42:59 +0100130 * The MPI needs to have enough limbs to store the full value (including any
131 * most significant zero bytes in the input).
Gabor Mezei37b06362022-08-02 17:22:18 +0200132 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100133 * \param[out] X The address of the MPI.
134 * \param X_limbs The number of limbs of \p X.
135 * \param[in] input The input buffer to import from.
136 * \param input_length The length bytes of \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200137 *
138 * \return \c 0 if successful.
139 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
Janos Follathb7a88ec2022-08-19 12:24:40 +0100140 * large enough to hold the value in \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200141 */
Gabor Mezeib9030702022-07-18 23:09:45 +0200142int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X,
Janos Follathb7a88ec2022-08-19 12:24:40 +0100143 size_t X_limbs,
144 const unsigned char *input,
145 size_t input_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200146
Janos Follathaf3f39c2022-08-22 09:06:32 +0100147/** Import X from unsigned binary data, big-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200148 *
Janos Follath63184682022-08-11 17:42:59 +0100149 * The MPI needs to have enough limbs to store the full value (including any
150 * most significant zero bytes in the input).
Gabor Mezei37b06362022-08-02 17:22:18 +0200151 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100152 * \param[out] X The address of the MPI.
153 * May only be #NULL if \X_limbs is 0 and \p input_length
154 * is 0.
155 * \param X_limbs The number of limbs of \p X.
156 * \param[in] input The input buffer to import from.
157 * May only be #NULL if \p input_length is 0.
158 * \param input_length The length in bytes of \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200159 *
160 * \return \c 0 if successful.
161 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
Janos Follathb7a88ec2022-08-19 12:24:40 +0100162 * large enough to hold the value in \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200163 */
Gabor Mezeib9030702022-07-18 23:09:45 +0200164int mbedtls_mpi_core_read_be( mbedtls_mpi_uint *X,
Janos Follathb7a88ec2022-08-19 12:24:40 +0100165 size_t X_limbs,
166 const unsigned char *input,
167 size_t input_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200168
Janos Follathaf3f39c2022-08-22 09:06:32 +0100169/** Export A into unsigned binary data, little-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200170 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100171 * \note If \p output is shorter than \p A the export is still successful if the
172 * value held in \p A fits in the buffer (that is, if enough of the most
173 * significant bytes of \p A are 0).
Janos Follath63184682022-08-11 17:42:59 +0100174 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100175 * \param[in] A The address of the MPI.
176 * \param A_limbs The number of limbs of \p A.
177 * \param[out] output The output buffer to export to.
178 * \param output_length The length in bytes of \p output.
Gabor Mezei37b06362022-08-02 17:22:18 +0200179 *
180 * \return \c 0 if successful.
Janos Follathb7a88ec2022-08-19 12:24:40 +0100181 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
182 * large enough to hold the value of \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +0200183 */
Janos Follathb7a88ec2022-08-19 12:24:40 +0100184int mbedtls_mpi_core_write_le( const mbedtls_mpi_uint *A,
185 size_t A_limbs,
186 unsigned char *output,
187 size_t output_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200188
Janos Follathaf3f39c2022-08-22 09:06:32 +0100189/** Export A into unsigned binary data, big-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200190 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100191 * \note If \p output is shorter than \p A the export is still successful if the
192 * value held in \p A fits in the buffer (that is, if enough of the most
193 * significant bytes of \p A are 0).
Janos Follath63184682022-08-11 17:42:59 +0100194 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100195 * \param[in] A The address of the MPI.
196 * \param A_limbs The number of limbs of \p A.
197 * \param[out] output The output buffer to export to.
198 * \param output_length The length in bytes of \p output.
Gabor Mezei37b06362022-08-02 17:22:18 +0200199 *
200 * \return \c 0 if successful.
Janos Follathb7a88ec2022-08-19 12:24:40 +0100201 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
202 * large enough to hold the value of \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +0200203 */
Janos Follathb7a88ec2022-08-19 12:24:40 +0100204int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *A,
205 size_t A_limbs,
206 unsigned char *output,
207 size_t output_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200208
Tom Cosgrove90c426b2022-08-23 16:15:19 +0100209/**
Tom Cosgrove5c0e8102022-09-15 15:46:10 +0100210 * \brief Conditional addition of two fixed-size large unsigned integers,
Tom Cosgroved932de82022-08-25 16:43:43 +0100211 * returning the carry.
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100212 *
213 * Functionally equivalent to
214 *
215 * ```
216 * if( cond )
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100217 * X += A;
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100218 * return carry;
219 * ```
220 *
Tom Cosgrove47828232022-09-20 13:51:50 +0100221 * This function operates modulo `2^(biL*limbs)`.
222 *
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100223 * \param[in,out] X The pointer to the (little-endian) array
Tom Cosgrove72594632022-08-24 11:51:58 +0100224 * representing the bignum to accumulate onto.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100225 * \param[in] A The pointer to the (little-endian) array
Tom Cosgrove72594632022-08-24 11:51:58 +0100226 * representing the bignum to conditionally add
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100227 * to \p X. This may be aliased to \p X but may not
Tom Cosgroveed43c6c2022-08-31 11:35:00 +0100228 * overlap otherwise.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100229 * \param limbs Number of limbs of \p X and \p A.
Tom Cosgrove72594632022-08-24 11:51:58 +0100230 * \param cond Condition bit dictating whether addition should
231 * happen or not. This must be \c 0 or \c 1.
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100232 *
Tom Cosgroveecbb1242022-08-25 10:13:44 +0100233 * \warning If \p cond is neither 0 nor 1, the result of this function
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100234 * is unspecified, and the resulting value in \p X might be
235 * neither its original value nor \p X + \p A.
Tom Cosgrove72594632022-08-24 11:51:58 +0100236 *
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100237 * \return 1 if `X + cond * A >= 2^(biL*limbs)`, 0 otherwise.
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100238 */
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100239mbedtls_mpi_uint mbedtls_mpi_core_add_if( mbedtls_mpi_uint *X,
240 const mbedtls_mpi_uint *A,
Tom Cosgrove72594632022-08-24 11:51:58 +0100241 size_t limbs,
Tom Cosgrove90c426b2022-08-23 16:15:19 +0100242 unsigned cond );
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100243
Tom Cosgroveb4964862022-08-30 11:57:22 +0100244/**
Tom Cosgrove5c0e8102022-09-15 15:46:10 +0100245 * \brief Subtract two fixed-size large unsigned integers, returning the borrow.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100246 *
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100247 * Calculate `A - B` where \p A and \p B have the same size.
Tom Cosgrove630110a2022-08-31 17:09:29 +0100248 * This function operates modulo `2^(biL*limbs)` and returns the carry
Tom Cosgroveb4964862022-08-30 11:57:22 +0100249 * (1 if there was a wraparound, i.e. if `A < B`, and 0 otherwise).
250 *
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100251 * \p X may be aliased to \p A or \p B, or even both, but may not overlap
252 * either otherwise.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100253 *
254 * \param[out] X The result of the subtraction.
255 * \param[in] A Little-endian presentation of left operand.
256 * \param[in] B Little-endian presentation of right operand.
257 * \param limbs Number of limbs of \p X, \p A and \p B.
258 *
259 * \return 1 if `A < B`.
260 * 0 if `A >= B`.
261 */
262mbedtls_mpi_uint mbedtls_mpi_core_sub( mbedtls_mpi_uint *X,
263 const mbedtls_mpi_uint *A,
264 const mbedtls_mpi_uint *B,
265 size_t limbs );
266
267/**
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100268 * \brief Perform a fixed-size multiply accumulate operation: X += b * A
Tom Cosgroveb4964862022-08-30 11:57:22 +0100269 *
Tom Cosgroveb0b77e12022-09-20 13:33:40 +0100270 * \p X may be aliased to \p A (when \p X_limbs == \p A_limbs), but may not
271 * otherwise overlap.
272 *
Tom Cosgrove47828232022-09-20 13:51:50 +0100273 * This function operates modulo `2^(biL*X_limbs)`.
274 *
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100275 * \param[in,out] X The pointer to the (little-endian) array
Tom Cosgroveb4964862022-08-30 11:57:22 +0100276 * representing the bignum to accumulate onto.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100277 * \param X_limbs The number of limbs of \p X. This must be
278 * at least \p A_limbs.
279 * \param[in] A The pointer to the (little-endian) array
Tom Cosgroveb4964862022-08-30 11:57:22 +0100280 * representing the bignum to multiply with.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100281 * This may be aliased to \p X but may not overlap
Tom Cosgroveed43c6c2022-08-31 11:35:00 +0100282 * otherwise.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100283 * \param A_limbs The number of limbs of \p A.
284 * \param b X scalar to multiply with.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100285 *
286 * \return The carry at the end of the operation.
287 */
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100288mbedtls_mpi_uint mbedtls_mpi_core_mla( mbedtls_mpi_uint *X, size_t X_limbs,
289 const mbedtls_mpi_uint *A, size_t A_limbs,
290 mbedtls_mpi_uint b );
Tom Cosgroveb4964862022-08-30 11:57:22 +0100291
292/**
293 * \brief Calculate initialisation value for fast Montgomery modular
294 * multiplication
295 *
296 * \param[in] N Little-endian presentation of the modulus. This must have
297 * at least one limb.
298 *
299 * \return The initialisation value for fast Montgomery modular multiplication
300 */
Tom Cosgroveb7438d12022-09-15 15:05:59 +0100301mbedtls_mpi_uint mbedtls_mpi_core_montmul_init( const mbedtls_mpi_uint *N );
Tom Cosgroveb4964862022-08-30 11:57:22 +0100302
303/**
Tom Cosgrove4386ead2022-09-29 14:40:21 +0100304 * \brief Montgomery multiplication: X = A * B * R^-1 mod N (HAC 14.36)
305 *
306 * \p A and \p B must be in canonical form. That is, < \p N.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100307 *
Tom Cosgroveea45c1d2022-09-20 13:17:51 +0100308 * \p X may be aliased to \p A or \p N, or even \p B (if \p AN_limbs ==
309 * \p B_limbs) but may not overlap any parameters otherwise.
310 *
Tom Cosgrove4386ead2022-09-29 14:40:21 +0100311 * \p A and \p B may alias each other, if \p AN_limbs == \p B_limbs. They may
312 * not alias \p N (since they must be in canonical form, they cannot == \p N).
Tom Cosgroveea45c1d2022-09-20 13:17:51 +0100313 *
Tom Cosgroveb4964862022-08-30 11:57:22 +0100314 * \param[out] X The destination MPI, as a little-endian array of
315 * length \p AN_limbs.
316 * On successful completion, X contains the result of
Tom Cosgrove630110a2022-08-31 17:09:29 +0100317 * the multiplication `A * B * R^-1` mod N where
318 * `R = 2^(biL*AN_limbs)`.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100319 * \param[in] A Little-endian presentation of first operand.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100320 * Must have the same number of limbs as \p N.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100321 * \param[in] B Little-endian presentation of second operand.
322 * \param[in] B_limbs The number of limbs in \p B.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100323 * Must be <= \p AN_limbs.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100324 * \param[in] N Little-endian presentation of the modulus.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100325 * This must be odd, and have exactly the same number
326 * of limbs as \p A.
Tom Cosgrove6da3a3b2022-09-29 17:20:18 +0100327 * It may alias \p X, but must not alias or otherwise
328 * overlap any of the other parameters.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100329 * \param[in] AN_limbs The number of limbs in \p X, \p A and \p N.
Tom Cosgrove630110a2022-08-31 17:09:29 +0100330 * \param mm The Montgomery constant for \p N: -N^-1 mod 2^biL.
Tom Cosgroveb7438d12022-09-15 15:05:59 +0100331 * This can be calculated by `mbedtls_mpi_core_montmul_init()`.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100332 * \param[in,out] T Temporary storage of size at least 2*AN_limbs+1 limbs.
333 * Its initial content is unused and
334 * its final content is indeterminate.
Tom Cosgrove4386ead2022-09-29 14:40:21 +0100335 * It must not alias or otherwise overlap any of the
336 * other parameters.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100337 */
338void mbedtls_mpi_core_montmul( mbedtls_mpi_uint *X,
339 const mbedtls_mpi_uint *A,
340 const mbedtls_mpi_uint *B, size_t B_limbs,
341 const mbedtls_mpi_uint *N, size_t AN_limbs,
342 mbedtls_mpi_uint mm, mbedtls_mpi_uint *T );
343
Gabor Mezeib9030702022-07-18 23:09:45 +0200344#endif /* MBEDTLS_BIGNUM_CORE_H */