blob: b626fab6e1490ff1104c825fbf92cbdedb21bf9c [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/**
Gabor Mezei4086de62022-10-14 16:29:42 +020078 * \brief Perform a safe conditional copy of an MPI which doesn't reveal
79 * whether assignment was done or not.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020080 *
Gabor Mezei4086de62022-10-14 16:29:42 +020081 * \param[out] X The address of the destination MPI.
82 * This must be initialized. Must have enough limbs to
83 * store the full value of \p A.
84 * \param[in] A The address of the source MPI. This must be initialized.
Gabor Mezei1c628d52022-09-27 12:13:51 +020085 * \param limbs The number of limbs of \p A.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020086 * \param assign The condition deciding whether to perform the
87 * assignment or not. Must be either 0 or 1:
Gabor Mezei1c628d52022-09-27 12:13:51 +020088 * * \c 1: Perform the assignment `X = A`.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020089 * * \c 0: Keep the original value of \p X.
90 *
91 * \note This function avoids leaking any information about whether
92 * the assignment was done or not.
93 *
94 * \warning If \p assign is neither 0 nor 1, the result of this function
95 * is indeterminate, and the resulting value in \p X might be
Gabor Mezei4086de62022-10-14 16:29:42 +020096 * neither its original value nor the value in \p A.
Gabor Mezeie1d31c42022-09-12 16:25:24 +020097 */
Gabor Mezei9f6615f2022-09-15 19:12:06 +020098void mbedtls_mpi_core_cond_assign( mbedtls_mpi_uint *X,
Gabor Mezei1c628d52022-09-27 12:13:51 +020099 const mbedtls_mpi_uint *A,
Gabor Mezei3eff4252022-09-26 17:26:42 +0200100 size_t limbs,
Gabor Mezei9f6615f2022-09-15 19:12:06 +0200101 unsigned char assign );
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200102
103/**
Gabor Mezei4086de62022-10-14 16:29:42 +0200104 * \brief Perform a safe conditional swap of two MPIs which doesn't reveal
105 * whether the swap was done or not.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200106 *
Gabor Mezei86dfe382022-09-30 14:03:04 +0200107 * \param[in,out] X The address of the first MPI.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200108 * This must be initialized.
Gabor Mezei86dfe382022-09-30 14:03:04 +0200109 * \param[in,out] Y The address of the second MPI.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200110 * This must be initialized.
Gabor Mezeie5b85852022-09-30 13:54:02 +0200111 * \param limbs The number of limbs of \p X and \p Y.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200112 * \param swap The condition deciding whether to perform
113 * the swap or not. Must be either 0 or 1:
Gabor Mezeie5b85852022-09-30 13:54:02 +0200114 * * \c 1: Swap the values of \p X and \p Y.
115 * * \c 0: Keep the original values of \p X and \p Y.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200116 *
117 * \note This function avoids leaking any information about whether
118 * the swap was done or not.
119 *
120 * \warning If \p swap is neither 0 nor 1, the result of this function
Gabor Mezeie5b85852022-09-30 13:54:02 +0200121 * is indeterminate, and both \p X and \p Y might end up with
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200122 * values different to either of the original ones.
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200123 */
Gabor Mezeie5b85852022-09-30 13:54:02 +0200124void mbedtls_mpi_core_cond_swap( mbedtls_mpi_uint *X,
125 mbedtls_mpi_uint *Y,
Gabor Mezeicfc0eb82022-09-15 20:15:34 +0200126 size_t limbs,
Gabor Mezei9f6615f2022-09-15 19:12:06 +0200127 unsigned char swap );
Gabor Mezeie1d31c42022-09-12 16:25:24 +0200128
Janos Follathaf3f39c2022-08-22 09:06:32 +0100129/** Import X from unsigned binary data, little-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200130 *
Janos Follath63184682022-08-11 17:42:59 +0100131 * The MPI needs to have enough limbs to store the full value (including any
132 * most significant zero bytes in the input).
Gabor Mezei37b06362022-08-02 17:22:18 +0200133 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100134 * \param[out] X The address of the MPI.
135 * \param X_limbs The number of limbs of \p X.
136 * \param[in] input The input buffer to import from.
137 * \param input_length The length bytes of \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200138 *
139 * \return \c 0 if successful.
140 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
Janos Follathb7a88ec2022-08-19 12:24:40 +0100141 * large enough to hold the value in \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200142 */
Gabor Mezeib9030702022-07-18 23:09:45 +0200143int mbedtls_mpi_core_read_le( mbedtls_mpi_uint *X,
Janos Follathb7a88ec2022-08-19 12:24:40 +0100144 size_t X_limbs,
145 const unsigned char *input,
146 size_t input_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200147
Janos Follathaf3f39c2022-08-22 09:06:32 +0100148/** Import X from unsigned binary data, big-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200149 *
Janos Follath63184682022-08-11 17:42:59 +0100150 * The MPI needs to have enough limbs to store the full value (including any
151 * most significant zero bytes in the input).
Gabor Mezei37b06362022-08-02 17:22:18 +0200152 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100153 * \param[out] X The address of the MPI.
154 * May only be #NULL if \X_limbs is 0 and \p input_length
155 * is 0.
156 * \param X_limbs The number of limbs of \p X.
157 * \param[in] input The input buffer to import from.
158 * May only be #NULL if \p input_length is 0.
159 * \param input_length The length in bytes of \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200160 *
161 * \return \c 0 if successful.
162 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p X isn't
Janos Follathb7a88ec2022-08-19 12:24:40 +0100163 * large enough to hold the value in \p input.
Gabor Mezei37b06362022-08-02 17:22:18 +0200164 */
Gabor Mezeib9030702022-07-18 23:09:45 +0200165int mbedtls_mpi_core_read_be( mbedtls_mpi_uint *X,
Janos Follathb7a88ec2022-08-19 12:24:40 +0100166 size_t X_limbs,
167 const unsigned char *input,
168 size_t input_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200169
Janos Follathaf3f39c2022-08-22 09:06:32 +0100170/** Export A into unsigned binary data, little-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200171 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100172 * \note If \p output is shorter than \p A the export is still successful if the
173 * value held in \p A fits in the buffer (that is, if enough of the most
174 * significant bytes of \p A are 0).
Janos Follath63184682022-08-11 17:42:59 +0100175 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100176 * \param[in] A The address of the MPI.
177 * \param A_limbs The number of limbs of \p A.
178 * \param[out] output The output buffer to export to.
179 * \param output_length The length in bytes of \p output.
Gabor Mezei37b06362022-08-02 17:22:18 +0200180 *
181 * \return \c 0 if successful.
Janos Follathb7a88ec2022-08-19 12:24:40 +0100182 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
183 * large enough to hold the value of \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +0200184 */
Janos Follathb7a88ec2022-08-19 12:24:40 +0100185int mbedtls_mpi_core_write_le( const mbedtls_mpi_uint *A,
186 size_t A_limbs,
187 unsigned char *output,
188 size_t output_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200189
Janos Follathaf3f39c2022-08-22 09:06:32 +0100190/** Export A into unsigned binary data, big-endian.
Gabor Mezei37b06362022-08-02 17:22:18 +0200191 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100192 * \note If \p output is shorter than \p A the export is still successful if the
193 * value held in \p A fits in the buffer (that is, if enough of the most
194 * significant bytes of \p A are 0).
Janos Follath63184682022-08-11 17:42:59 +0100195 *
Janos Follathb7a88ec2022-08-19 12:24:40 +0100196 * \param[in] A The address of the MPI.
197 * \param A_limbs The number of limbs of \p A.
198 * \param[out] output The output buffer to export to.
199 * \param output_length The length in bytes of \p output.
Gabor Mezei37b06362022-08-02 17:22:18 +0200200 *
201 * \return \c 0 if successful.
Janos Follathb7a88ec2022-08-19 12:24:40 +0100202 * \return #MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if \p output isn't
203 * large enough to hold the value of \p A.
Gabor Mezei37b06362022-08-02 17:22:18 +0200204 */
Janos Follathb7a88ec2022-08-19 12:24:40 +0100205int mbedtls_mpi_core_write_be( const mbedtls_mpi_uint *A,
206 size_t A_limbs,
207 unsigned char *output,
208 size_t output_length );
Gabor Mezeib9030702022-07-18 23:09:45 +0200209
Tom Cosgrove90c426b2022-08-23 16:15:19 +0100210/**
Tom Cosgrove5c0e8102022-09-15 15:46:10 +0100211 * \brief Conditional addition of two fixed-size large unsigned integers,
Tom Cosgroved932de82022-08-25 16:43:43 +0100212 * returning the carry.
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100213 *
214 * Functionally equivalent to
215 *
216 * ```
217 * if( cond )
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100218 * X += A;
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100219 * return carry;
220 * ```
221 *
Tom Cosgrove47828232022-09-20 13:51:50 +0100222 * This function operates modulo `2^(biL*limbs)`.
223 *
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100224 * \param[in,out] X The pointer to the (little-endian) array
Tom Cosgrove72594632022-08-24 11:51:58 +0100225 * representing the bignum to accumulate onto.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100226 * \param[in] A The pointer to the (little-endian) array
Tom Cosgrove72594632022-08-24 11:51:58 +0100227 * representing the bignum to conditionally add
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100228 * to \p X. This may be aliased to \p X but may not
Tom Cosgroveed43c6c2022-08-31 11:35:00 +0100229 * overlap otherwise.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100230 * \param limbs Number of limbs of \p X and \p A.
Tom Cosgrove72594632022-08-24 11:51:58 +0100231 * \param cond Condition bit dictating whether addition should
232 * happen or not. This must be \c 0 or \c 1.
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100233 *
Tom Cosgroveecbb1242022-08-25 10:13:44 +0100234 * \warning If \p cond is neither 0 nor 1, the result of this function
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100235 * is unspecified, and the resulting value in \p X might be
236 * neither its original value nor \p X + \p A.
Tom Cosgrove72594632022-08-24 11:51:58 +0100237 *
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100238 * \return 1 if `X + cond * A >= 2^(biL*limbs)`, 0 otherwise.
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100239 */
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100240mbedtls_mpi_uint mbedtls_mpi_core_add_if( mbedtls_mpi_uint *X,
241 const mbedtls_mpi_uint *A,
Tom Cosgrove72594632022-08-24 11:51:58 +0100242 size_t limbs,
Tom Cosgrove90c426b2022-08-23 16:15:19 +0100243 unsigned cond );
Hanno Becker71f4b0d2022-08-23 12:09:35 +0100244
Tom Cosgroveb4964862022-08-30 11:57:22 +0100245/**
Tom Cosgrove5c0e8102022-09-15 15:46:10 +0100246 * \brief Subtract two fixed-size large unsigned integers, returning the borrow.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100247 *
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100248 * Calculate `A - B` where \p A and \p B have the same size.
Tom Cosgrove630110a2022-08-31 17:09:29 +0100249 * This function operates modulo `2^(biL*limbs)` and returns the carry
Tom Cosgroveb4964862022-08-30 11:57:22 +0100250 * (1 if there was a wraparound, i.e. if `A < B`, and 0 otherwise).
251 *
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100252 * \p X may be aliased to \p A or \p B, or even both, but may not overlap
253 * either otherwise.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100254 *
255 * \param[out] X The result of the subtraction.
256 * \param[in] A Little-endian presentation of left operand.
257 * \param[in] B Little-endian presentation of right operand.
258 * \param limbs Number of limbs of \p X, \p A and \p B.
259 *
260 * \return 1 if `A < B`.
261 * 0 if `A >= B`.
262 */
263mbedtls_mpi_uint mbedtls_mpi_core_sub( mbedtls_mpi_uint *X,
264 const mbedtls_mpi_uint *A,
265 const mbedtls_mpi_uint *B,
266 size_t limbs );
267
268/**
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100269 * \brief Perform a fixed-size multiply accumulate operation: X += b * A
Tom Cosgroveb4964862022-08-30 11:57:22 +0100270 *
Tom Cosgroveb0b77e12022-09-20 13:33:40 +0100271 * \p X may be aliased to \p A (when \p X_limbs == \p A_limbs), but may not
272 * otherwise overlap.
273 *
Tom Cosgrove47828232022-09-20 13:51:50 +0100274 * This function operates modulo `2^(biL*X_limbs)`.
275 *
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100276 * \param[in,out] X The pointer to the (little-endian) array
Tom Cosgroveb4964862022-08-30 11:57:22 +0100277 * representing the bignum to accumulate onto.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100278 * \param X_limbs The number of limbs of \p X. This must be
279 * at least \p A_limbs.
280 * \param[in] A The pointer to the (little-endian) array
Tom Cosgroveb4964862022-08-30 11:57:22 +0100281 * representing the bignum to multiply with.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100282 * This may be aliased to \p X but may not overlap
Tom Cosgroveed43c6c2022-08-31 11:35:00 +0100283 * otherwise.
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100284 * \param A_limbs The number of limbs of \p A.
285 * \param b X scalar to multiply with.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100286 *
287 * \return The carry at the end of the operation.
288 */
Tom Cosgrove3bd7bc32022-09-15 15:55:07 +0100289mbedtls_mpi_uint mbedtls_mpi_core_mla( mbedtls_mpi_uint *X, size_t X_limbs,
290 const mbedtls_mpi_uint *A, size_t A_limbs,
291 mbedtls_mpi_uint b );
Tom Cosgroveb4964862022-08-30 11:57:22 +0100292
293/**
294 * \brief Calculate initialisation value for fast Montgomery modular
295 * multiplication
296 *
297 * \param[in] N Little-endian presentation of the modulus. This must have
298 * at least one limb.
299 *
300 * \return The initialisation value for fast Montgomery modular multiplication
301 */
Tom Cosgroveb7438d12022-09-15 15:05:59 +0100302mbedtls_mpi_uint mbedtls_mpi_core_montmul_init( const mbedtls_mpi_uint *N );
Tom Cosgroveb4964862022-08-30 11:57:22 +0100303
304/**
Tom Cosgrove4386ead2022-09-29 14:40:21 +0100305 * \brief Montgomery multiplication: X = A * B * R^-1 mod N (HAC 14.36)
306 *
307 * \p A and \p B must be in canonical form. That is, < \p N.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100308 *
Tom Cosgroveea45c1d2022-09-20 13:17:51 +0100309 * \p X may be aliased to \p A or \p N, or even \p B (if \p AN_limbs ==
310 * \p B_limbs) but may not overlap any parameters otherwise.
311 *
Tom Cosgrove4386ead2022-09-29 14:40:21 +0100312 * \p A and \p B may alias each other, if \p AN_limbs == \p B_limbs. They may
313 * not alias \p N (since they must be in canonical form, they cannot == \p N).
Tom Cosgroveea45c1d2022-09-20 13:17:51 +0100314 *
Tom Cosgroveb4964862022-08-30 11:57:22 +0100315 * \param[out] X The destination MPI, as a little-endian array of
316 * length \p AN_limbs.
317 * On successful completion, X contains the result of
Tom Cosgrove630110a2022-08-31 17:09:29 +0100318 * the multiplication `A * B * R^-1` mod N where
319 * `R = 2^(biL*AN_limbs)`.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100320 * \param[in] A Little-endian presentation of first operand.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100321 * Must have the same number of limbs as \p N.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100322 * \param[in] B Little-endian presentation of second operand.
323 * \param[in] B_limbs The number of limbs in \p B.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100324 * Must be <= \p AN_limbs.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100325 * \param[in] N Little-endian presentation of the modulus.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100326 * This must be odd, and have exactly the same number
327 * of limbs as \p A.
Tom Cosgrove6da3a3b2022-09-29 17:20:18 +0100328 * It may alias \p X, but must not alias or otherwise
329 * overlap any of the other parameters.
Tom Cosgrove5dd97e62022-08-30 14:31:49 +0100330 * \param[in] AN_limbs The number of limbs in \p X, \p A and \p N.
Tom Cosgrove630110a2022-08-31 17:09:29 +0100331 * \param mm The Montgomery constant for \p N: -N^-1 mod 2^biL.
Tom Cosgroveb7438d12022-09-15 15:05:59 +0100332 * This can be calculated by `mbedtls_mpi_core_montmul_init()`.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100333 * \param[in,out] T Temporary storage of size at least 2*AN_limbs+1 limbs.
334 * Its initial content is unused and
335 * its final content is indeterminate.
Tom Cosgrove4386ead2022-09-29 14:40:21 +0100336 * It must not alias or otherwise overlap any of the
337 * other parameters.
Tom Cosgroveb4964862022-08-30 11:57:22 +0100338 */
339void mbedtls_mpi_core_montmul( mbedtls_mpi_uint *X,
340 const mbedtls_mpi_uint *A,
341 const mbedtls_mpi_uint *B, size_t B_limbs,
342 const mbedtls_mpi_uint *N, size_t AN_limbs,
343 mbedtls_mpi_uint mm, mbedtls_mpi_uint *T );
344
Gabor Mezeib9030702022-07-18 23:09:45 +0200345#endif /* MBEDTLS_BIGNUM_CORE_H */