mbed TLS v2.16.7
bignum.h
Go to the documentation of this file.
1 
6 /*
7  * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
8  * SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
9  *
10  * This file is provided under the Apache License 2.0, or the
11  * GNU General Public License v2.0 or later.
12  *
13  * **********
14  * Apache License 2.0:
15  *
16  * Licensed under the Apache License, Version 2.0 (the "License"); you may
17  * not use this file except in compliance with the License.
18  * You may obtain a copy of the License at
19  *
20  * http://www.apache.org/licenses/LICENSE-2.0
21  *
22  * Unless required by applicable law or agreed to in writing, software
23  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
24  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
25  * See the License for the specific language governing permissions and
26  * limitations under the License.
27  *
28  * **********
29  *
30  * **********
31  * GNU General Public License v2.0 or later:
32  *
33  * This program is free software; you can redistribute it and/or modify
34  * it under the terms of the GNU General Public License as published by
35  * the Free Software Foundation; either version 2 of the License, or
36  * (at your option) any later version.
37  *
38  * This program is distributed in the hope that it will be useful,
39  * but WITHOUT ANY WARRANTY; without even the implied warranty of
40  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
41  * GNU General Public License for more details.
42  *
43  * You should have received a copy of the GNU General Public License along
44  * with this program; if not, write to the Free Software Foundation, Inc.,
45  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
46  *
47  * **********
48  *
49  * This file is part of mbed TLS (https://tls.mbed.org)
50  */
51 #ifndef MBEDTLS_BIGNUM_H
52 #define MBEDTLS_BIGNUM_H
53 
54 #if !defined(MBEDTLS_CONFIG_FILE)
55 #include "config.h"
56 #else
57 #include MBEDTLS_CONFIG_FILE
58 #endif
59 
60 #include <stddef.h>
61 #include <stdint.h>
62 
63 #if defined(MBEDTLS_FS_IO)
64 #include <stdio.h>
65 #endif
66 
67 #define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002
68 #define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004
69 #define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006
70 #define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008
71 #define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A
72 #define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C
73 #define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E
74 #define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010
76 #define MBEDTLS_MPI_CHK(f) \
77  do \
78  { \
79  if( ( ret = (f) ) != 0 ) \
80  goto cleanup; \
81  } while( 0 )
82 
83 /*
84  * Maximum size MPIs are allowed to grow to in number of limbs.
85  */
86 #define MBEDTLS_MPI_MAX_LIMBS 10000
87 
88 #if !defined(MBEDTLS_MPI_WINDOW_SIZE)
89 /*
90  * Maximum window size used for modular exponentiation. Default: 6
91  * Minimum value: 1. Maximum value: 6.
92  *
93  * Result is an array of ( 2 << MBEDTLS_MPI_WINDOW_SIZE ) MPIs used
94  * for the sliding window calculation. (So 64 by default)
95  *
96  * Reduction in size, reduces speed.
97  */
98 #define MBEDTLS_MPI_WINDOW_SIZE 6
99 #endif /* !MBEDTLS_MPI_WINDOW_SIZE */
100 
101 #if !defined(MBEDTLS_MPI_MAX_SIZE)
102 /*
103  * Maximum size of MPIs allowed in bits and bytes for user-MPIs.
104  * ( Default: 512 bytes => 4096 bits, Maximum tested: 2048 bytes => 16384 bits )
105  *
106  * Note: Calculations can temporarily result in larger MPIs. So the number
107  * of limbs required (MBEDTLS_MPI_MAX_LIMBS) is higher.
108  */
109 #define MBEDTLS_MPI_MAX_SIZE 1024
110 #endif /* !MBEDTLS_MPI_MAX_SIZE */
111 
112 #define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE )
114 /*
115  * When reading from files with mbedtls_mpi_read_file() and writing to files with
116  * mbedtls_mpi_write_file() the buffer should have space
117  * for a (short) label, the MPI (in the provided radix), the newline
118  * characters and the '\0'.
119  *
120  * By default we assume at least a 10 char label, a minimum radix of 10
121  * (decimal) and a maximum of 4096 bit numbers (1234 decimal chars).
122  * Autosized at compile time for at least a 10 char label, a minimum radix
123  * of 10 (decimal) for a number of MBEDTLS_MPI_MAX_BITS size.
124  *
125  * This used to be statically sized to 1250 for a maximum of 4096 bit
126  * numbers (1234 decimal chars).
127  *
128  * Calculate using the formula:
129  * MBEDTLS_MPI_RW_BUFFER_SIZE = ceil(MBEDTLS_MPI_MAX_BITS / ln(10) * ln(2)) +
130  * LabelSize + 6
131  */
132 #define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS )
133 #define MBEDTLS_LN_2_DIV_LN_10_SCALE100 332
134 #define MBEDTLS_MPI_RW_BUFFER_SIZE ( ((MBEDTLS_MPI_MAX_BITS_SCALE100 + MBEDTLS_LN_2_DIV_LN_10_SCALE100 - 1) / MBEDTLS_LN_2_DIV_LN_10_SCALE100) + 10 + 6 )
135 
136 /*
137  * Define the base integer type, architecture-wise.
138  *
139  * 32 or 64-bit integer types can be forced regardless of the underlying
140  * architecture by defining MBEDTLS_HAVE_INT32 or MBEDTLS_HAVE_INT64
141  * respectively and undefining MBEDTLS_HAVE_ASM.
142  *
143  * Double-width integers (e.g. 128-bit in 64-bit architectures) can be
144  * disabled by defining MBEDTLS_NO_UDBL_DIVISION.
145  */
146 #if !defined(MBEDTLS_HAVE_INT32)
147  #if defined(_MSC_VER) && defined(_M_AMD64)
148  /* Always choose 64-bit when using MSC */
149  #if !defined(MBEDTLS_HAVE_INT64)
150  #define MBEDTLS_HAVE_INT64
151  #endif /* !MBEDTLS_HAVE_INT64 */
152  typedef int64_t mbedtls_mpi_sint;
153  typedef uint64_t mbedtls_mpi_uint;
154  #elif defined(__GNUC__) && ( \
155  defined(__amd64__) || defined(__x86_64__) || \
156  defined(__ppc64__) || defined(__powerpc64__) || \
157  defined(__ia64__) || defined(__alpha__) || \
158  ( defined(__sparc__) && defined(__arch64__) ) || \
159  defined(__s390x__) || defined(__mips64) )
160  #if !defined(MBEDTLS_HAVE_INT64)
161  #define MBEDTLS_HAVE_INT64
162  #endif /* MBEDTLS_HAVE_INT64 */
163  typedef int64_t mbedtls_mpi_sint;
164  typedef uint64_t mbedtls_mpi_uint;
165  #if !defined(MBEDTLS_NO_UDBL_DIVISION)
166  /* mbedtls_t_udbl defined as 128-bit unsigned int */
167  typedef unsigned int mbedtls_t_udbl __attribute__((mode(TI)));
168  #define MBEDTLS_HAVE_UDBL
169  #endif /* !MBEDTLS_NO_UDBL_DIVISION */
170  #elif defined(__ARMCC_VERSION) && defined(__aarch64__)
171  /*
172  * __ARMCC_VERSION is defined for both armcc and armclang and
173  * __aarch64__ is only defined by armclang when compiling 64-bit code
174  */
175  #if !defined(MBEDTLS_HAVE_INT64)
176  #define MBEDTLS_HAVE_INT64
177  #endif /* !MBEDTLS_HAVE_INT64 */
178  typedef int64_t mbedtls_mpi_sint;
179  typedef uint64_t mbedtls_mpi_uint;
180  #if !defined(MBEDTLS_NO_UDBL_DIVISION)
181  /* mbedtls_t_udbl defined as 128-bit unsigned int */
182  typedef __uint128_t mbedtls_t_udbl;
183  #define MBEDTLS_HAVE_UDBL
184  #endif /* !MBEDTLS_NO_UDBL_DIVISION */
185  #elif defined(MBEDTLS_HAVE_INT64)
186  /* Force 64-bit integers with unknown compiler */
187  typedef int64_t mbedtls_mpi_sint;
188  typedef uint64_t mbedtls_mpi_uint;
189  #endif
190 #endif /* !MBEDTLS_HAVE_INT32 */
191 
192 #if !defined(MBEDTLS_HAVE_INT64)
193  /* Default to 32-bit compilation */
194  #if !defined(MBEDTLS_HAVE_INT32)
195  #define MBEDTLS_HAVE_INT32
196  #endif /* !MBEDTLS_HAVE_INT32 */
197  typedef int32_t mbedtls_mpi_sint;
198  typedef uint32_t mbedtls_mpi_uint;
199  #if !defined(MBEDTLS_NO_UDBL_DIVISION)
200  typedef uint64_t mbedtls_t_udbl;
201  #define MBEDTLS_HAVE_UDBL
202  #endif /* !MBEDTLS_NO_UDBL_DIVISION */
203 #endif /* !MBEDTLS_HAVE_INT64 */
204 
205 #ifdef __cplusplus
206 extern "C" {
207 #endif
208 
212 typedef struct mbedtls_mpi
213 {
214  int s;
215  size_t n;
217 }
219 
229 
238 
252 int mbedtls_mpi_grow( mbedtls_mpi *X, size_t nblimbs );
253 
269 int mbedtls_mpi_shrink( mbedtls_mpi *X, size_t nblimbs );
270 
285 
293 
318 int mbedtls_mpi_safe_cond_assign( mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign );
319 
343 int mbedtls_mpi_safe_cond_swap( mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign );
344 
356 
367 int mbedtls_mpi_get_bit( const mbedtls_mpi *X, size_t pos );
368 
384 int mbedtls_mpi_set_bit( mbedtls_mpi *X, size_t pos, unsigned char val );
385 
398 size_t mbedtls_mpi_lsb( const mbedtls_mpi *X );
399 
412 size_t mbedtls_mpi_bitlen( const mbedtls_mpi *X );
413 
427 size_t mbedtls_mpi_size( const mbedtls_mpi *X );
428 
439 int mbedtls_mpi_read_string( mbedtls_mpi *X, int radix, const char *s );
440 
463 int mbedtls_mpi_write_string( const mbedtls_mpi *X, int radix,
464  char *buf, size_t buflen, size_t *olen );
465 
466 #if defined(MBEDTLS_FS_IO)
467 
488 int mbedtls_mpi_read_file( mbedtls_mpi *X, int radix, FILE *fin );
489 
505 int mbedtls_mpi_write_file( const char *p, const mbedtls_mpi *X,
506  int radix, FILE *fout );
507 #endif /* MBEDTLS_FS_IO */
508 
521 int mbedtls_mpi_read_binary( mbedtls_mpi *X, const unsigned char *buf,
522  size_t buflen );
523 
538 int mbedtls_mpi_write_binary( const mbedtls_mpi *X, unsigned char *buf,
539  size_t buflen );
540 
551 int mbedtls_mpi_shift_l( mbedtls_mpi *X, size_t count );
552 
563 int mbedtls_mpi_shift_r( mbedtls_mpi *X, size_t count );
564 
575 int mbedtls_mpi_cmp_abs( const mbedtls_mpi *X, const mbedtls_mpi *Y );
576 
587 int mbedtls_mpi_cmp_mpi( const mbedtls_mpi *X, const mbedtls_mpi *Y );
588 
605  unsigned *ret );
606 
618 
631  const mbedtls_mpi *B );
632 
646  const mbedtls_mpi *B );
647 
660  const mbedtls_mpi *B );
661 
674  const mbedtls_mpi *B );
675 
688  mbedtls_mpi_sint b );
689 
703  mbedtls_mpi_sint b );
704 
718  const mbedtls_mpi *B );
719 
734  mbedtls_mpi_uint b );
735 
755  const mbedtls_mpi *B );
756 
776  mbedtls_mpi_sint b );
777 
796  const mbedtls_mpi *B );
797 
815  mbedtls_mpi_sint b );
816 
844  const mbedtls_mpi *E, const mbedtls_mpi *N,
845  mbedtls_mpi *_RR );
846 
865  int (*f_rng)(void *, unsigned char *, size_t),
866  void *p_rng );
867 
880  const mbedtls_mpi *B );
881 
899  const mbedtls_mpi *N );
900 
901 #if !defined(MBEDTLS_DEPRECATED_REMOVED)
902 #if defined(MBEDTLS_DEPRECATED_WARNING)
903 #define MBEDTLS_DEPRECATED __attribute__((deprecated))
904 #else
905 #define MBEDTLS_DEPRECATED
906 #endif
907 
927  int (*f_rng)(void *, unsigned char *, size_t),
928  void *p_rng );
929 #undef MBEDTLS_DEPRECATED
930 #endif /* !MBEDTLS_DEPRECATED_REMOVED */
931 
959 int mbedtls_mpi_is_prime_ext( const mbedtls_mpi *X, int rounds,
960  int (*f_rng)(void *, unsigned char *, size_t),
961  void *p_rng );
968 typedef enum {
972 
992 int mbedtls_mpi_gen_prime( mbedtls_mpi *X, size_t nbits, int flags,
993  int (*f_rng)(void *, unsigned char *, size_t),
994  void *p_rng );
995 
996 #if defined(MBEDTLS_SELF_TEST)
997 
1003 int mbedtls_mpi_self_test( int verbose );
1004 
1005 #endif /* MBEDTLS_SELF_TEST */
1006 
1007 #ifdef __cplusplus
1008 }
1009 #endif
1010 
1011 #endif /* bignum.h */
mbedtls_mpi_fill_random
int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Fill an MPI with a number of random bytes.
mbedtls_mpi_is_prime_ext
int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Miller-Rabin primality test.
mbedtls_mpi::n
size_t n
Definition: bignum.h:215
MBEDTLS_MPI_GEN_PRIME_FLAG_DH
@ MBEDTLS_MPI_GEN_PRIME_FLAG_DH
Definition: bignum.h:969
mbedtls_mpi_grow
int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs)
Enlarge an MPI to the specified number of limbs.
mbedtls_mpi_get_bit
int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos)
Get a specific bit from an MPI.
mbedtls_mpi_mod_mpi
int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a modular reduction. R = A mod B.
mbedtls_mpi_is_prime
MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime(const mbedtls_mpi *X, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Perform a Miller-Rabin primality test with error probability of 2-80.
mbedtls_mpi_sub_int
int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
Perform a signed subtraction of an MPI and an integer: X = A - b.
mbedtls_mpi_inv_mod
int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N)
Compute the modular inverse: X = A^-1 mod N.
mbedtls_mpi::p
mbedtls_mpi_uint * p
Definition: bignum.h:216
mbedtls_mpi
MPI structure.
Definition: bignum.h:213
mbedtls_mpi_safe_cond_assign
int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign)
Perform a safe conditional copy of MPI which doesn't reveal whether the condition was true or not.
MBEDTLS_DEPRECATED
#define MBEDTLS_DEPRECATED
Definition: bignum.h:905
mbedtls_mpi_sub_mpi
int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a signed subtraction of MPIs: X = A - B.
mbedtls_mpi_lset
int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z)
Store integer value in MPI.
mbedtls_mpi_free
void mbedtls_mpi_free(mbedtls_mpi *X)
This function frees the components of an MPI context.
MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR
@ MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR
Definition: bignum.h:970
mbedtls_mpi_gcd
int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B)
Compute the greatest common divisor: G = gcd(A, B)
mbedtls_mpi_shift_r
int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count)
Perform a right-shift on an MPI: X >>= count.
mbedtls_mpi_self_test
int mbedtls_mpi_self_test(int verbose)
Checkup routine.
mbedtls_mpi_add_mpi
int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a signed addition of MPIs: X = A + B.
mbedtls_mpi_read_binary
int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buflen)
Import an MPI from unsigned big endian binary data.
mbedtls_mpi
struct mbedtls_mpi mbedtls_mpi
MPI structure.
mbedtls_mpi_lsb
size_t mbedtls_mpi_lsb(const mbedtls_mpi *X)
Return the number of bits of value 0 before the least significant bit of value 1.
mbedtls_mpi_cmp_mpi
int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y)
Compare two MPIs.
mbedtls_mpi_shrink
int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs)
This function resizes an MPI downwards, keeping at least the specified number of limbs.
mbedtls_mpi_copy
int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y)
Make a copy of an MPI.
mbedtls_mpi_write_binary
int mbedtls_mpi_write_binary(const mbedtls_mpi *X, unsigned char *buf, size_t buflen)
Export an MPI into unsigned big endian binary data of fixed size.
mbedtls_mpi_mul_mpi
int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a multiplication of two MPIs: X = A * B.
mbedtls_mpi_write_string
int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix, char *buf, size_t buflen, size_t *olen)
Export an MPI to an ASCII string.
mbedtls_mpi_cmp_int
int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z)
Compare an MPI with an integer.
mbedtls_mpi_add_int
int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
Perform a signed addition of an MPI and an integer: X = A + b.
mbedtls_mpi_cmp_abs
int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y)
Compare the absolute values of two MPIs.
mbedtls_mpi_bitlen
size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X)
Return the number of bits up to and including the most significant bit of value 1.
mbedtls_mpi_set_bit
int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val)
Modify a specific bit in an MPI.
mbedtls_mpi_div_int
int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b)
Perform a division with remainder of an MPI by an integer: A = Q * b + R.
mbedtls_mpi_gen_prime_flag_t
mbedtls_mpi_gen_prime_flag_t
Flags for mbedtls_mpi_gen_prime()
Definition: bignum.h:968
mbedtls_mpi_lt_mpi_ct
int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned *ret)
Check if an MPI is less than the other in constant time.
mbedtls_mpi_div_mpi
int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform a division with remainder of two MPIs: A = Q * B + R.
mbedtls_mpi_mod_int
int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b)
Perform a modular reduction with respect to an integer. r = A mod b.
mbedtls_mpi_gen_prime
int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng)
Generate a prime number.
mbedtls_mpi_read_file
int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin)
Read an MPI from a line in an opened file.
mbedtls_mpi::s
int s
Definition: bignum.h:214
mbedtls_mpi_mul_int
int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b)
Perform a multiplication of an MPI with an unsigned integer: X = A * b.
config.h
Configuration options (set of defines)
mbedtls_mpi_add_abs
int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform an unsigned addition of MPIs: X = |A| + |B|.
mbedtls_mpi_size
size_t mbedtls_mpi_size(const mbedtls_mpi *X)
Return the total size of an MPI value in bytes.
mbedtls_mpi_uint
uint32_t mbedtls_mpi_uint
Definition: bignum.h:198
mbedtls_mpi_sub_abs
int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
Perform an unsigned subtraction of MPIs: X = |A| - |B|.
mbedtls_mpi_shift_l
int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count)
Perform a left-shift on an MPI: X <<= count.
mbedtls_t_udbl
uint64_t mbedtls_t_udbl
Definition: bignum.h:200
mbedtls_mpi_write_file
int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, int radix, FILE *fout)
Export an MPI into an opened file.
mbedtls_mpi_exp_mod
int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *_RR)
Perform a sliding-window exponentiation: X = A^E mod N.
mbedtls_mpi_sint
int32_t mbedtls_mpi_sint
Definition: bignum.h:197
mbedtls_mpi_swap
void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y)
Swap the contents of two MPIs.
mbedtls_mpi_safe_cond_swap
int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char assign)
Perform a safe conditional swap which doesn't reveal whether the condition was true or not.
mbedtls_mpi_read_string
int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s)
Import an MPI from an ASCII string.
mbedtls_mpi_init
void mbedtls_mpi_init(mbedtls_mpi *X)
Initialize an MPI context.