bignum.h
mbedtls/private_access.h
mbedtls/build_info.h
mbedtls/platform_util.h
stddef.h
stdint.h
stdio.h
asn1.h
dhm.h
ecp.h
rsa.h
ssl.h
x509_crt.h
bignum.h
mbedtls/build_info.h
mbedtls/check_config.h
mbedtls/config_adjust_legacy_crypto.h
mbedtls/config_adjust_psa_from_legacy.h
mbedtls/config_adjust_psa_superset_legacy.h
mbedtls/config_adjust_ssl.h
mbedtls/config_adjust_x509.h
mbedtls/config_psa.h
mbedtls/mbedtls_config.h
mbedtls/platform_time.h
mbedtls/platform_util.h
mbedtls/private_access.h
psa/crypto_adjust_auto_enabled.h
psa/crypto_adjust_config_dependencies.h
psa/crypto_adjust_config_key_pair_types.h
psa/crypto_adjust_config_synonyms.h
psa/crypto_legacy.h
inttypes.h
limits.h
stddef.h
stdint.h
stdio.h
time.h
asn1.h
asn1write.h
bignum.h
debug.h
dhm.h
ecdh.h
ecdsa.h
ecjpake.h
ecp.h
net_sockets.h
oid.h
pk.h
pkcs12.h
pkcs5.h
pkcs7.h
psa_util.h
rsa.h
ssl.h
ssl_cache.h
ssl_ciphersuites.h
ssl_cookie.h
ssl_ticket.h
x509.h
x509_crl.h
x509_crt.h
x509_csr.h
crypto.h
crypto_builtin_composites.h
crypto_driver_contexts_composites.h
crypto_struct.h
mbedtls_mpi
MBEDTLS_ERR_MPI_FILE_IO_ERROR
-0x0002

An error occurred while reading from or writing to a file.

MBEDTLS_ERR_MPI_BAD_INPUT_DATA
-0x0004

Bad input parameters to function.

MBEDTLS_ERR_MPI_INVALID_CHARACTER
-0x0006

There is an invalid character in the digit string.

MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL
-0x0008

The buffer is too small to write to.

MBEDTLS_ERR_MPI_NEGATIVE_VALUE
-0x000A

The input arguments are negative or result in illegal output.

MBEDTLS_ERR_MPI_DIVISION_BY_ZERO
-0x000C

The input argument for division is zero, which is not allowed.

MBEDTLS_ERR_MPI_NOT_ACCEPTABLE
-0x000E

The input arguments are not acceptable.

MBEDTLS_ERR_MPI_ALLOC_FAILED
-0x0010

Memory allocation failed.

MBEDTLS_MPI_CHK
f
do \ { \ if ((ret = (f)) != 0) \ goto cleanup; \ } while (0)
MBEDTLS_MPI_MAX_LIMBS
10000
MBEDTLS_MPI_WINDOW_SIZE
3

Maximum window size used.

MBEDTLS_MPI_MAX_SIZE
1024

Maximum number of bytes for usable MPIs.

MBEDTLS_MPI_MAX_BITS
(8 * MBEDTLS_MPI_MAX_SIZE)

Maximum number of bits for usable MPIs.

MBEDTLS_MPI_MAX_BITS_SCALE100
(100 * MBEDTLS_MPI_MAX_BITS)
MBEDTLS_LN_2_DIV_LN_10_SCALE100
332
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)
MBEDTLS_HAVE_INT32
MBEDTLS_MPI_UINT_MAX
UINT32_MAX
MBEDTLS_HAVE_UDBL
mbedtls_mpi_gen_prime_flag_t
MBEDTLS_MPI_GEN_PRIME_FLAG_DH
= 0x0001

(X-1)/2 is prime too

MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR
= 0x0002

lower error rate from 2-80 to 2-128

Flags for mbedtls_mpi_gen_prime().

Each of these flags is a constraint on the result X returned by mbedtls_mpi_gen_prime().

int32_t typedef int32_t mbedtls_mpi_sint mbedtls_mpi_sint

The signed type corresponding to mbedtls_mpi_uint.

This is always an signed integer type with no padding bits. The size is platform-dependent.

uint32_t typedef uint32_t mbedtls_mpi_uint mbedtls_mpi_uint

The type of machine digits in a bignum, called limbs.

This is always an unsigned integer type with no padding bits. The size is platform-dependent.

uint64_t typedef uint64_t mbedtls_t_udbl mbedtls_t_udbl
struct mbedtls_mpi typedef struct mbedtls_mpi mbedtls_mpi mbedtls_mpi

MPI structure.

void void mbedtls_mpi_init (mbedtls_mpi *X) mbedtls_mpi_init mbedtls_mpi * X

Initialize an MPI context.

This makes the MPI ready to be set or freed, but does not define a value for the MPI.

X

The MPI context to initialize. This must not be `NULL`.

void void mbedtls_mpi_free (mbedtls_mpi *X) mbedtls_mpi_free mbedtls_mpi * X

This function frees the components of an MPI context.

X

The MPI context to be cleared. This may be `NULL`, in which case this function is a no-op. If it is not `NULL`, it must point to an initialized MPI.

int int mbedtls_mpi_grow (mbedtls_mpi *X, size_t nblimbs) mbedtls_mpi_grow mbedtls_mpi * X size_t nblimbs

Enlarge an MPI to the specified number of limbs.

This function does nothing if the MPI is already large enough.

X

The MPI to grow. It must be initialized.

nblimbs

The target number of limbs.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on other kinds of failure.

int int mbedtls_mpi_shrink (mbedtls_mpi *X, size_t nblimbs) mbedtls_mpi_shrink mbedtls_mpi * X size_t nblimbs

This function resizes an MPI downwards, keeping at least the specified number of limbs.

If `X` is smaller than `nblimbs`, it is resized up instead.

X

The MPI to shrink. This must point to an initialized MPI.

nblimbs

The minimum number of limbs to keep.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed (this can only happen when resizing up).

Another negative error code on other kinds of failure.

int int mbedtls_mpi_copy (mbedtls_mpi *X, const mbedtls_mpi *Y) mbedtls_mpi_copy mbedtls_mpi * X const mbedtls_mpi * Y

Make a copy of an MPI.

X

The destination MPI. This must point to an initialized MPI.

Y

The source MPI. This must point to an initialized MPI.

The limb-buffer in the destination MPI is enlarged if necessary to hold the value in the source MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on other kinds of failure.

void void mbedtls_mpi_swap (mbedtls_mpi *X, mbedtls_mpi *Y) mbedtls_mpi_swap mbedtls_mpi * X mbedtls_mpi * Y

Swap the contents of two MPIs.

X

The first MPI. It must be initialized.

Y

The second MPI. It must be initialized.

int int mbedtls_mpi_safe_cond_assign (mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned char assign) 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.

X

The MPI to conditionally assign to. This must point to an initialized MPI.

Y

The MPI to be assigned from. This must point to an initialized MPI.

assign

The condition deciding whether to perform the assignment or not. Must be either 0 or 1:

- `1`: Perform the assignment `X = Y`.

- `0`: Keep the original value of `X`.

This function is equivalent to `if( assign ) mbedtls_mpi_copy( X, Y );` except that it avoids leaking any information about whether the assignment was done or not (the above code may leak information through branch prediction and/or memory access patterns analysis).

If `assign` is neither 0 nor 1, the result of this function is indeterminate, and the resulting value in `X` might be neither its original value nor the value in `Y`.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on other kinds of failure.

int int mbedtls_mpi_safe_cond_swap (mbedtls_mpi *X, mbedtls_mpi *Y, unsigned char swap) mbedtls_mpi_safe_cond_swap mbedtls_mpi * X mbedtls_mpi * Y unsigned char swap

Perform a safe conditional swap which doesn't reveal whether the condition was true or not.

X

The first MPI. This must be initialized.

Y

The second MPI. This must be initialized.

swap

The condition deciding whether to perform the swap or not. Must be either 0 or 1:

- `1`: Swap the values of `X` and `Y`.

- `0`: Keep the original values of `X` and `Y`.

This function is equivalent to if( swap ) mbedtls_mpi_swap( X, Y ); except that it avoids leaking any information about whether the swap was done or not (the above code may leak information through branch prediction and/or memory access patterns analysis).

If `swap` is neither 0 nor 1, the result of this function is indeterminate, and both `X` and `Y` might end up with values different to either of the original ones.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on other kinds of failure.

int int mbedtls_mpi_lset (mbedtls_mpi *X, mbedtls_mpi_sint z) mbedtls_mpi_lset mbedtls_mpi * X mbedtls_mpi_sint z

Store integer value in MPI.

X

The MPI to set. This must be initialized.

z

The value to use.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on other kinds of failure.

int int mbedtls_mpi_get_bit (const mbedtls_mpi *X, size_t pos) mbedtls_mpi_get_bit const mbedtls_mpi * X size_t pos

Get a specific bit from an MPI.

X

The MPI to query. This must be initialized.

pos

Zero-based index of the bit to query.

`0` or `1` on success, depending on whether bit `pos` of `X` is unset or set.

A negative error code on failure.

int int mbedtls_mpi_set_bit (mbedtls_mpi *X, size_t pos, unsigned char val) mbedtls_mpi_set_bit mbedtls_mpi * X size_t pos unsigned char val

Modify a specific bit in an MPI.

This function will grow the target MPI if necessary to set a bit to `1` in a not yet existing limb. It will not grow if the bit should be set to `0`.

X

The MPI to modify. This must be initialized.

pos

Zero-based index of the bit to modify.

val

The desired value of bit `pos:` `0` or `1`.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on other kinds of failure.

size_t size_t mbedtls_mpi_lsb (const mbedtls_mpi *X) mbedtls_mpi_lsb const mbedtls_mpi * X

Return the number of bits of value `0` before the least significant bit of value `1`.

This is the same as the zero-based index of the least significant bit of value `1`.

X

The MPI to query.

The number of bits of value `0` before the least significant bit of value `1` in `X`.

size_t size_t mbedtls_mpi_bitlen (const mbedtls_mpi *X) mbedtls_mpi_bitlen const mbedtls_mpi * X

Return the number of bits up to and including the most significant bit of value `1`.

- This is same as the one-based index of the most significant bit of value `1`.

  X

  The MPI to query. This must point to an initialized MPI.

  The number of bits up to and including the most significant bit of value `1`.

size_t size_t mbedtls_mpi_size (const mbedtls_mpi *X) mbedtls_mpi_size const mbedtls_mpi * X

Return the total size of an MPI value in bytes.

X

The MPI to use. This must point to an initialized MPI.

The value returned by this function may be less than the number of bytes used to store `X` internally. This happens if and only if there are trailing bytes of value zero.

The least number of bytes capable of storing the absolute value of `X`.

int int mbedtls_mpi_read_string (mbedtls_mpi *X, int radix, const char *s) mbedtls_mpi_read_string mbedtls_mpi * X int radix const char * s

Import an MPI from an ASCII string.

X

The destination MPI. This must point to an initialized MPI.

radix

The numeric base of the input string.

s

Null-terminated string buffer.

`0` if successful.

A negative error code on failure.

int int mbedtls_mpi_write_string (const mbedtls_mpi *X, int radix, char *buf, size_t buflen, size_t *olen) 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.

X

The source MPI. This must point to an initialized MPI.

radix

The numeric base of the output string.

buf

The buffer to write the string to. This must be writable buffer of length `buflen` Bytes.

buflen

The available size in Bytes of `buf`.

olen

The address at which to store the length of the string written, including the final `NULL` byte. This must not be `NULL`.

You can call this function with `buflen == 0` to obtain the minimum required buffer size in `*olen`.

`0` if successful.

MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the target buffer `buf` is too small to hold the value of `X` in the desired base. In this case, `*olen` is nonetheless updated to contain the size of `buf` required for a successful call.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_read_file (mbedtls_mpi *X, int radix, FILE *fin) mbedtls_mpi_read_file mbedtls_mpi * X int radix FILE * fin

Read an MPI from a line in an opened file.

X

The destination MPI. This must point to an initialized MPI.

radix

The numeric base of the string representation used in the source line.

fin

The input file handle to use. This must not be `NULL`.

On success, this function advances the file stream to the end of the current line or to EOF.

The function returns `0` on an empty line.

Leading whitespaces are ignored, as is a '0x' prefix for radix `16`.

`0` if successful.

MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if the file read buffer is too small.

Another negative error code on failure.

int int mbedtls_mpi_write_file (const char *p, const mbedtls_mpi *X, int radix, FILE *fout) mbedtls_mpi_write_file const char * p const mbedtls_mpi * X int radix FILE * fout

Export an MPI into an opened file.

p

A string prefix to emit prior to the MPI data. For example, this might be a label, or "0x" when printing in base `16`. This may be `NULL` if no prefix is needed.

X

The source MPI. This must point to an initialized MPI.

radix

The numeric base to be used in the emitted string.

fout

The output file handle. This may be `NULL`, in which case the output is written to `stdout`.

`0` if successful.

A negative error code on failure.

int int mbedtls_mpi_read_binary (mbedtls_mpi *X, const unsigned char *buf, size_t buflen) mbedtls_mpi_read_binary mbedtls_mpi * X const unsigned char * buf size_t buflen

Import an MPI from unsigned big endian binary data.

X

The destination MPI. This must point to an initialized MPI.

buf

The input buffer. This must be a readable buffer of length `buflen` Bytes.

buflen

The length of the input buffer `buf` in Bytes.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_read_binary_le (mbedtls_mpi *X, const unsigned char *buf, size_t buflen) mbedtls_mpi_read_binary_le mbedtls_mpi * X const unsigned char * buf size_t buflen

Import X from unsigned binary data, little endian.

X

The destination MPI. This must point to an initialized MPI.

buf

The input buffer. This must be a readable buffer of length `buflen` Bytes.

buflen

The length of the input buffer `buf` in Bytes.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_write_binary (const mbedtls_mpi *X, unsigned char *buf, size_t buflen) mbedtls_mpi_write_binary const mbedtls_mpi * X unsigned char * buf size_t buflen

Export X into unsigned binary data, big endian. Always fills the whole buffer, which will start with zeros if the number is smaller.

X

The source MPI. This must point to an initialized MPI.

buf

The output buffer. This must be a writable buffer of length `buflen` Bytes.

buflen

The size of the output buffer `buf` in Bytes.

`0` if successful.

MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if `buf` isn't large enough to hold the value of `X`.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_write_binary_le (const mbedtls_mpi *X, unsigned char *buf, size_t buflen) mbedtls_mpi_write_binary_le const mbedtls_mpi * X unsigned char * buf size_t buflen

Export X into unsigned binary data, little endian. Always fills the whole buffer, which will end with zeros if the number is smaller.

X

The source MPI. This must point to an initialized MPI.

buf

The output buffer. This must be a writable buffer of length `buflen` Bytes.

buflen

The size of the output buffer `buf` in Bytes.

`0` if successful.

MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL if `buf` isn't large enough to hold the value of `X`.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_shift_l (mbedtls_mpi *X, size_t count) mbedtls_mpi_shift_l mbedtls_mpi * X size_t count

Perform a left-shift on an MPI: X <<= count.

X

The MPI to shift. This must point to an initialized MPI. The MPI pointed by `X` may be resized to fit the resulting number.

count

The number of bits to shift by.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_shift_r (mbedtls_mpi *X, size_t count) mbedtls_mpi_shift_r mbedtls_mpi * X size_t count

Perform a right-shift on an MPI: X >>= count.

X

The MPI to shift. This must point to an initialized MPI.

count

The number of bits to shift by.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_cmp_abs (const mbedtls_mpi *X, const mbedtls_mpi *Y) mbedtls_mpi_cmp_abs const mbedtls_mpi * X const mbedtls_mpi * Y

Compare the absolute values of two MPIs.

X

The left-hand MPI. This must point to an initialized MPI.

Y

The right-hand MPI. This must point to an initialized MPI.

`1` if `|X|` is greater than `|Y|`.

`-1` if `|X|` is lesser than `|Y|`.

`0` if `|X|` is equal to `|Y|`.

int int mbedtls_mpi_cmp_mpi (const mbedtls_mpi *X, const mbedtls_mpi *Y) mbedtls_mpi_cmp_mpi const mbedtls_mpi * X const mbedtls_mpi * Y

Compare two MPIs.

X

The left-hand MPI. This must point to an initialized MPI.

Y

The right-hand MPI. This must point to an initialized MPI.

`1` if `X` is greater than `Y`.

`-1` if `X` is lesser than `Y`.

`0` if `X` is equal to `Y`.

int int mbedtls_mpi_lt_mpi_ct (const mbedtls_mpi *X, const mbedtls_mpi *Y, unsigned *ret) 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.

X

The left-hand MPI. This must point to an initialized MPI with the same allocated length as Y.

Y

The right-hand MPI. This must point to an initialized MPI with the same allocated length as X.

ret

The result of the comparison: `1` if `X` is less than `Y`. `0` if `X` is greater than or equal to `Y`.

0 on success.

MBEDTLS_ERR_MPI_BAD_INPUT_DATA if the allocated length of the two input MPIs is not the same.

int int mbedtls_mpi_cmp_int (const mbedtls_mpi *X, mbedtls_mpi_sint z) mbedtls_mpi_cmp_int const mbedtls_mpi * X mbedtls_mpi_sint z

Compare an MPI with an integer.

X

The left-hand MPI. This must point to an initialized MPI.

z

The integer value to compare `X` to.

`1` if `X` is greater than `z`.

`-1` if `X` is lesser than `z`.

`0` if `X` is equal to `z`.

int int mbedtls_mpi_add_abs (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_add_abs mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * B

Perform an unsigned addition of MPIs: X = |A| + |B|.

X

The destination MPI. This must point to an initialized MPI.

A

The first summand. This must point to an initialized MPI.

B

The second summand. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_sub_abs (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_sub_abs mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * B

Perform an unsigned subtraction of MPIs: X = |A| - |B|.

X

The destination MPI. This must point to an initialized MPI.

A

The minuend. This must point to an initialized MPI.

B

The subtrahend. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_NEGATIVE_VALUE if `B` is greater than `A`.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_add_mpi (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_add_mpi mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * B

Perform a signed addition of MPIs: X = A + B.

X

The destination MPI. This must point to an initialized MPI.

A

The first summand. This must point to an initialized MPI.

B

The second summand. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_sub_mpi (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_sub_mpi mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * B

Perform a signed subtraction of MPIs: X = A - B.

X

The destination MPI. This must point to an initialized MPI.

A

The minuend. This must point to an initialized MPI.

B

The subtrahend. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_add_int (mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b) 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.

X

The destination MPI. This must point to an initialized MPI.

A

The first summand. This must point to an initialized MPI.

b

The second summand.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_sub_int (mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b) 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.

X

The destination MPI. This must point to an initialized MPI.

A

The minuend. This must point to an initialized MPI.

b

The subtrahend.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_mul_mpi (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_mul_mpi mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * B

Perform a multiplication of two MPIs: X = A * B.

X

The destination MPI. This must point to an initialized MPI.

A

The first factor. This must point to an initialized MPI.

B

The second factor. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_mul_int (mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b) 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.

X

The destination MPI. This must point to an initialized MPI.

A

The first factor. This must point to an initialized MPI.

b

The second factor.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_div_mpi (mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B) 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.

Q

The destination MPI for the quotient. This may be `NULL` if the value of the quotient is not needed. This must not alias A or B.

R

The destination MPI for the remainder value. This may be `NULL` if the value of the remainder is not needed. This must not alias A or B.

A

The dividend. This must point to an initialized MPI.

B

The divisor. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if `B` equals zero.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_div_int (mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A, mbedtls_mpi_sint b) 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.

Q

The destination MPI for the quotient. This may be `NULL` if the value of the quotient is not needed. This must not alias A.

R

The destination MPI for the remainder value. This may be `NULL` if the value of the remainder is not needed. This must not alias A.

A

The dividend. This must point to an initialized MPi.

b

The divisor.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if memory allocation failed.

MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if `b` equals zero.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_mod_mpi (mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_mod_mpi mbedtls_mpi * R const mbedtls_mpi * A const mbedtls_mpi * B

Perform a modular reduction. R = A mod B.

R

The destination MPI for the residue value. This must point to an initialized MPI.

A

The MPI to compute the residue of. This must point to an initialized MPI.

B

The base of the modular reduction. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if `B` equals zero.

MBEDTLS_ERR_MPI_NEGATIVE_VALUE if `B` is negative.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_mod_int (mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b) 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.

r

The address at which to store the residue. This must not be `NULL`.

A

The MPI to compute the residue of. This must point to an initialized MPi.

b

The integer base of the modular reduction.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_DIVISION_BY_ZERO if `b` equals zero.

MBEDTLS_ERR_MPI_NEGATIVE_VALUE if `b` is negative.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_exp_mod (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *E, const mbedtls_mpi *N, mbedtls_mpi *prec_RR) mbedtls_mpi_exp_mod mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * E const mbedtls_mpi * N mbedtls_mpi * prec_RR

Perform a modular exponentiation: X = A^E mod N.

X

The destination MPI. This must point to an initialized MPI. This must not alias E or N.

A

The base of the exponentiation. This must point to an initialized MPI.

E

The exponent MPI. This must point to an initialized MPI.

N

The base for the modular reduction. This must point to an initialized MPI.

prec_RR

A helper MPI depending solely on `N` which can be used to speed-up multiple modular exponentiations for the same value of `N`. This may be `NULL`. If it is not `NULL`, it must point to an initialized MPI. If it hasn't been used after the call to mbedtls_mpi_init(), this function will compute the helper value and store it in `prec_RR` for reuse on subsequent calls to this function. Otherwise, the function will assume that `prec_RR` holds the helper value set by a previous call to mbedtls_mpi_exp_mod(), and reuse it.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `N` is negative or even, or if `E` is negative.

Another negative error code on different kinds of failures.

int int mbedtls_mpi_fill_random (mbedtls_mpi *X, size_t size, mbedtls_f_rng_t *f_rng, void *p_rng) mbedtls_mpi_fill_random mbedtls_mpi * X size_t size mbedtls_f_rng_t * f_rng void * p_rng

Fill an MPI with a number of random bytes.

X

The destination MPI. This must point to an initialized MPI.

size

The number of random bytes to generate.

f_rng

The RNG function to use. This must not be `NULL`.

p_rng

The RNG parameter to be passed to `f_rng`. This may be `NULL` if `f_rng` doesn't need a context argument.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on failure.

The bytes obtained from the RNG are interpreted as a big-endian representation of an MPI; this can be relevant in applications like deterministic ECDSA.

int int mbedtls_mpi_random (mbedtls_mpi *X, mbedtls_mpi_sint min, const mbedtls_mpi *N, mbedtls_f_rng_t *f_rng, void *p_rng) mbedtls_mpi_random mbedtls_mpi * X mbedtls_mpi_sint min const mbedtls_mpi * N mbedtls_f_rng_t * f_rng void * p_rng

Generate a random number uniformly in a range.

This function generates a random number between `min` inclusive and `N` exclusive.

The procedure complies with RFC 6979 §3.3 (deterministic ECDSA) when the RNG is a suitably parametrized instance of HMAC_DRBG and `min` is `1`.

There are `N - min` possible outputs. The lower bound `min` can be reached, but the upper bound `N` cannot.

X

The destination MPI. This must point to an initialized MPI.

min

The minimum value to return. It must be nonnegative.

N

The upper bound of the range, exclusive. In other words, this is one plus the maximum value to return. `N` must be strictly larger than `min`.

f_rng

The RNG function to use. This must not be `NULL`.

p_rng

The RNG parameter to be passed to `f_rng`.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `min` or `N` is invalid or if they are incompatible.

MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if the implementation was unable to find a suitable value within a limited number of attempts. This has a negligible probability if `N` is significantly larger than `min`, which is the case for all usual cryptographic applications.

Another negative error code on failure.

int int mbedtls_mpi_gcd (mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) mbedtls_mpi_gcd mbedtls_mpi * G const mbedtls_mpi * A const mbedtls_mpi * B

Compute the greatest common divisor: G = gcd(A, B).

G

The destination MPI. This must point to an initialized MPI. This will always be positive or 0.

A

The first operand. This must point to an initialized MPI.

B

The second operand. This must point to an initialized MPI.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

Another negative error code on different kinds of failure.

int int mbedtls_mpi_inv_mod (mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N) mbedtls_mpi_inv_mod mbedtls_mpi * X const mbedtls_mpi * A const mbedtls_mpi * N

Compute the modular inverse: X = A^-1 mod N.

X

The destination MPI. This must point to an initialized MPI. The value returned on success will be between [1, N-1].

A

The MPI to calculate the modular inverse of. This must point to an initialized MPI. This value can be negative, in which case a positive answer will still be returned in `X`.

N

The base of the modular inversion. This must point to an initialized MPI and be greater than one.

`0` if successful.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `N` is less than or equal to one.

MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if `A` has no modular inverse with respect to `N`.

int int mbedtls_mpi_is_prime_ext (const mbedtls_mpi *X, int rounds, mbedtls_f_rng_t *f_rng, void *p_rng) mbedtls_mpi_is_prime_ext const mbedtls_mpi * X int rounds mbedtls_f_rng_t * f_rng void * p_rng

Miller-Rabin primality test.

If `X` is potentially generated by an adversary, for example when validating cryptographic parameters that you didn't generate yourself and that are supposed to be prime, then `rounds` should be at least the half of the security strength of the cryptographic algorithm. On the other hand, if `X` is chosen uniformly or non-adversarially (as is the case when mbedtls_mpi_gen_prime calls this function), then `rounds` can be much lower.

X

The MPI to check for primality. This must point to an initialized MPI.

rounds

The number of bases to perform the Miller-Rabin primality test for. The probability of returning 0 on a composite is at most 2-2*`rounds` .

f_rng

The RNG function to use. This must not be `NULL`.

p_rng

The RNG parameter to be passed to `f_rng`. This may be `NULL` if `f_rng` doesn't use a context parameter.

`0` if successful, i.e. `X` is probably prime.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_NOT_ACCEPTABLE if `X` is not prime.

Another negative error code on other kinds of failure.

int int mbedtls_mpi_gen_prime (mbedtls_mpi *X, size_t nbits, int flags, mbedtls_f_rng_t *f_rng, void *p_rng) mbedtls_mpi_gen_prime mbedtls_mpi * X size_t nbits int flags mbedtls_f_rng_t * f_rng void * p_rng

Generate a prime number.

X

The destination MPI to store the generated prime in. This must point to an initialized MPi.

nbits

The required size of the destination MPI in bits. This must be between `3` and MBEDTLS_MPI_MAX_BITS.

flags

A mask of flags of type mbedtls_mpi_gen_prime_flag_t.

f_rng

The RNG function to use. This must not be `NULL`.

p_rng

The RNG parameter to be passed to `f_rng`. This may be `NULL` if `f_rng` doesn't use a context parameter.

`0` if successful, in which case `X` holds a probably prime number.

MBEDTLS_ERR_MPI_ALLOC_FAILED if a memory allocation failed.

MBEDTLS_ERR_MPI_BAD_INPUT_DATA if `nbits` is not between `3` and MBEDTLS_MPI_MAX_BITS.

int int mbedtls_mpi_self_test (int verbose) mbedtls_mpi_self_test int verbose

Checkup routine.

0 if successful, or 1 if the test failed

Multi-precision integer library.

    /*
    *CopyrightTheMbedTLSContributors
    *SPDX-License-Identifier:Apache-2.0ORGPL-2.0-or-later
    */
    #ifndefMBEDTLS_BIGNUM_H
    #defineMBEDTLS_BIGNUM_H
    #include"mbedtls/private_access.h"

    #include"mbedtls/build_info.h"
    #include"mbedtls/platform_util.h"

    #include<stddef.h>
    #include<stdint.h>

    #ifdefined(MBEDTLS_FS_IO)
    #include<stdio.h>
    #endif

    #defineMBEDTLS_ERR_MPI_FILE_IO_ERROR-0x0002
    #defineMBEDTLS_ERR_MPI_BAD_INPUT_DATA-0x0004
    #defineMBEDTLS_ERR_MPI_INVALID_CHARACTER-0x0006
    #defineMBEDTLS_ERR_MPI_BUFFER_TOO_SMALL-0x0008
    #defineMBEDTLS_ERR_MPI_NEGATIVE_VALUE-0x000A
    #defineMBEDTLS_ERR_MPI_DIVISION_BY_ZERO-0x000C
    #defineMBEDTLS_ERR_MPI_NOT_ACCEPTABLE-0x000E
    #defineMBEDTLS_ERR_MPI_ALLOC_FAILED-0x0010

    #defineMBEDTLS_MPI_CHK(f)\
    do\
    {\
    if((ret=(f))!=0)\
    gotocleanup;\
    }while(0)

    /*
    *MaximumsizeMPIsareallowedtogrowtoinnumberoflimbs.
    */
    #defineMBEDTLS_MPI_MAX_LIMBS10000

    #if!defined(MBEDTLS_MPI_WINDOW_SIZE)
    /*
    *Maximumwindowsizeusedformodularexponentiation.Default:3
    *Minimumvalue:1.Maximumvalue:6.
    *
    *Resultisanarrayof(2**MBEDTLS_MPI_WINDOW_SIZE)MPIsused
    *fortheslidingwindowcalculation.(So8bydefault)
    *
    *Reductioninsize,reducesspeed.
    */
    #defineMBEDTLS_MPI_WINDOW_SIZE3
    #endif/*!MBEDTLS_MPI_WINDOW_SIZE*/

    #if!defined(MBEDTLS_MPI_MAX_SIZE)
    /*
    *MaximumsizeofMPIsallowedinbitsandbytesforuser-MPIs.
    *(Default:512bytes=>4096bits,Maximumtested:2048bytes=>16384bits)
    *
    *Note:CalculationscantemporarilyresultinlargerMPIs.Sothenumber
    *oflimbsrequired(MBEDTLS_MPI_MAX_LIMBS)ishigher.
    */
    #defineMBEDTLS_MPI_MAX_SIZE1024
    #endif/*!MBEDTLS_MPI_MAX_SIZE*/

    #defineMBEDTLS_MPI_MAX_BITS(8*MBEDTLS_MPI_MAX_SIZE)

    /*
    *Whenreadingfromfileswithmbedtls_mpi_read_file()andwritingtofileswith
    *mbedtls_mpi_write_file()thebuffershouldhavespace
    *fora(short)label,theMPI(intheprovidedradix),thenewline
    *charactersandthe'\0'.
    *
    *Bydefaultweassumeatleasta10charlabel,aminimumradixof10
    *(decimal)andamaximumof4096bitnumbers(1234decimalchars).
    *Autosizedatcompiletimeforatleasta10charlabel,aminimumradix
    *of10(decimal)foranumberofMBEDTLS_MPI_MAX_BITSsize.
    *
    *Thisusedtobestaticallysizedto1250foramaximumof4096bit
    *numbers(1234decimalchars).
    *
    *Calculateusingtheformula:
    *MBEDTLS_MPI_RW_BUFFER_SIZE=ceil(MBEDTLS_MPI_MAX_BITS/ln(10)*ln(2))+
    *LabelSize+6
    */
    #defineMBEDTLS_MPI_MAX_BITS_SCALE100(100*MBEDTLS_MPI_MAX_BITS)
    #defineMBEDTLS_LN_2_DIV_LN_10_SCALE100332
    #defineMBEDTLS_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)

    /*
    *Definethebaseintegertype,architecture-wise.
    *
    *32or64-bitintegertypescanbeforcedregardlessoftheunderlying
    *architecturebydefiningMBEDTLS_HAVE_INT32orMBEDTLS_HAVE_INT64
    *respectivelyandundefiningMBEDTLS_HAVE_ASM.
    *
    *Double-widthintegers(e.g.128-bitin64-bitarchitectures)canbe
    *disabledbydefiningMBEDTLS_NO_UDBL_DIVISION.
    */
    #if!defined(MBEDTLS_HAVE_INT32)
    #ifdefined(_MSC_VER)&&defined(_M_AMD64)
    /*Alwayschoose64-bitwhenusingMSC*/
    #if!defined(MBEDTLS_HAVE_INT64)
    #defineMBEDTLS_HAVE_INT64
    #endif/*!MBEDTLS_HAVE_INT64*/
    typedefint64_tmbedtls_mpi_sint;
    typedefuint64_tmbedtls_mpi_uint;
    #defineMBEDTLS_MPI_UINT_MAXUINT64_MAX
    #elifdefined(__GNUC__)&&(\
    defined(__amd64__)||defined(__x86_64__)||\
    defined(__ppc64__)||defined(__powerpc64__)||\
    defined(__ia64__)||defined(__alpha__)||\
    (defined(__sparc__)&&defined(__arch64__))||\
    defined(__s390x__)||defined(__mips64)||\
    defined(__aarch64__))
    #if!defined(MBEDTLS_HAVE_INT64)
    #defineMBEDTLS_HAVE_INT64
    #endif/*MBEDTLS_HAVE_INT64*/
    typedefint64_tmbedtls_mpi_sint;
    typedefuint64_tmbedtls_mpi_uint;
    #defineMBEDTLS_MPI_UINT_MAXUINT64_MAX
    #if!defined(MBEDTLS_NO_UDBL_DIVISION)
    /*mbedtls_t_udbldefinedas128-bitunsignedint*/
    typedefunsignedintmbedtls_t_udbl__attribute__((mode(TI)));
    #defineMBEDTLS_HAVE_UDBL
    #endif/*!MBEDTLS_NO_UDBL_DIVISION*/
    #elifdefined(__ARMCC_VERSION)&&defined(__aarch64__)
    /*
    *__ARMCC_VERSIONisdefinedforbotharmccandarmclangand
    *__aarch64__isonlydefinedbyarmclangwhencompiling64-bitcode
    */
    #if!defined(MBEDTLS_HAVE_INT64)
    #defineMBEDTLS_HAVE_INT64
    #endif/*!MBEDTLS_HAVE_INT64*/
    typedefint64_tmbedtls_mpi_sint;
    typedefuint64_tmbedtls_mpi_uint;
    #defineMBEDTLS_MPI_UINT_MAXUINT64_MAX
    #if!defined(MBEDTLS_NO_UDBL_DIVISION)
    /*mbedtls_t_udbldefinedas128-bitunsignedint*/
    typedef__uint128_tmbedtls_t_udbl;
    #defineMBEDTLS_HAVE_UDBL
    #endif/*!MBEDTLS_NO_UDBL_DIVISION*/
    #elifdefined(MBEDTLS_HAVE_INT64)
    /*Force64-bitintegerswithunknowncompiler*/
    typedefint64_tmbedtls_mpi_sint;
    typedefuint64_tmbedtls_mpi_uint;
    #defineMBEDTLS_MPI_UINT_MAXUINT64_MAX
    #endif
    #endif/*!MBEDTLS_HAVE_INT32*/

    #if!defined(MBEDTLS_HAVE_INT64)
    /*Defaultto32-bitcompilation*/
    #if!defined(MBEDTLS_HAVE_INT32)
    #defineMBEDTLS_HAVE_INT32
    #endif/*!MBEDTLS_HAVE_INT32*/
    typedefint32_tmbedtls_mpi_sint;
    typedefuint32_tmbedtls_mpi_uint;
    #defineMBEDTLS_MPI_UINT_MAXUINT32_MAX
    #if!defined(MBEDTLS_NO_UDBL_DIVISION)
    typedefuint64_tmbedtls_t_udbl;
    #defineMBEDTLS_HAVE_UDBL
    #endif/*!MBEDTLS_NO_UDBL_DIVISION*/
    #endif/*!MBEDTLS_HAVE_INT64*/

    /*
    *SanitycheckthatexactlyoneofMBEDTLS_HAVE_INT32orMBEDTLS_HAVE_INT64isdefined,
    *sothatcodeelsewheredoesn'thavetocheck.
    */
    #if(!(defined(MBEDTLS_HAVE_INT32)||defined(MBEDTLS_HAVE_INT64)))||\
    (defined(MBEDTLS_HAVE_INT32)&&defined(MBEDTLS_HAVE_INT64))
    #error"Only32-bitor64-bitlimbsaresupportedinbignum"
    #endif

    #ifdef__cplusplus
    extern"C"{
    #endif

    typedefstructmbedtls_mpi{
    mbedtls_mpi_uint*MBEDTLS_PRIVATE(p);

    signedshortMBEDTLS_PRIVATE(s);

    unsignedshortMBEDTLS_PRIVATE(n);
    /*MakesurethatMBEDTLS_MPI_MAX_LIMBSfitsinn.
    *Usethesamelimitvalueonallplatformssothatwedon'thaveto
    *thinkaboutdifferentbehaviorontherareplatformswhere
    *unsignedshortcanstorevalueslargerthantheminimumrequiredby
    *theClanguage,whichis65535.
    */
    #ifMBEDTLS_MPI_MAX_LIMBS>65535
    #error"MBEDTLS_MPI_MAX_LIMBS>65535isnotsupported"
    #endif
    }
    mbedtls_mpi;

    voidmbedtls_mpi_init(mbedtls_mpi*X);

    voidmbedtls_mpi_free(mbedtls_mpi*X);

    intmbedtls_mpi_grow(mbedtls_mpi*X,size_tnblimbs);

    intmbedtls_mpi_shrink(mbedtls_mpi*X,size_tnblimbs);

    intmbedtls_mpi_copy(mbedtls_mpi*X,constmbedtls_mpi*Y);

    voidmbedtls_mpi_swap(mbedtls_mpi*X,mbedtls_mpi*Y);

    intmbedtls_mpi_safe_cond_assign(mbedtls_mpi*X,constmbedtls_mpi*Y,unsignedcharassign);

    intmbedtls_mpi_safe_cond_swap(mbedtls_mpi*X,mbedtls_mpi*Y,unsignedcharswap);

    intmbedtls_mpi_lset(mbedtls_mpi*X,mbedtls_mpi_sintz);

    intmbedtls_mpi_get_bit(constmbedtls_mpi*X,size_tpos);

    intmbedtls_mpi_set_bit(mbedtls_mpi*X,size_tpos,unsignedcharval);

    size_tmbedtls_mpi_lsb(constmbedtls_mpi*X);

    size_tmbedtls_mpi_bitlen(constmbedtls_mpi*X);

    size_tmbedtls_mpi_size(constmbedtls_mpi*X);

    intmbedtls_mpi_read_string(mbedtls_mpi*X,intradix,constchar*s);

    intmbedtls_mpi_write_string(constmbedtls_mpi*X,intradix,
    char*buf,size_tbuflen,size_t*olen);

    #ifdefined(MBEDTLS_FS_IO)
    intmbedtls_mpi_read_file(mbedtls_mpi*X,intradix,FILE*fin);

    intmbedtls_mpi_write_file(constchar*p,constmbedtls_mpi*X,
    intradix,FILE*fout);
    #endif/*MBEDTLS_FS_IO*/

    intmbedtls_mpi_read_binary(mbedtls_mpi*X,constunsignedchar*buf,
    size_tbuflen);

    intmbedtls_mpi_read_binary_le(mbedtls_mpi*X,
    constunsignedchar*buf,size_tbuflen);

    intmbedtls_mpi_write_binary(constmbedtls_mpi*X,unsignedchar*buf,
    size_tbuflen);

    intmbedtls_mpi_write_binary_le(constmbedtls_mpi*X,
    unsignedchar*buf,size_tbuflen);

    intmbedtls_mpi_shift_l(mbedtls_mpi*X,size_tcount);

    intmbedtls_mpi_shift_r(mbedtls_mpi*X,size_tcount);

    intmbedtls_mpi_cmp_abs(constmbedtls_mpi*X,constmbedtls_mpi*Y);

    intmbedtls_mpi_cmp_mpi(constmbedtls_mpi*X,constmbedtls_mpi*Y);

    intmbedtls_mpi_lt_mpi_ct(constmbedtls_mpi*X,constmbedtls_mpi*Y,
    unsigned*ret);

    intmbedtls_mpi_cmp_int(constmbedtls_mpi*X,mbedtls_mpi_sintz);

    intmbedtls_mpi_add_abs(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_sub_abs(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_add_mpi(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_sub_mpi(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_add_int(mbedtls_mpi*X,constmbedtls_mpi*A,
    mbedtls_mpi_sintb);

    intmbedtls_mpi_sub_int(mbedtls_mpi*X,constmbedtls_mpi*A,
    mbedtls_mpi_sintb);

    intmbedtls_mpi_mul_mpi(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_mul_int(mbedtls_mpi*X,constmbedtls_mpi*A,
    mbedtls_mpi_uintb);

    intmbedtls_mpi_div_mpi(mbedtls_mpi*Q,mbedtls_mpi*R,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_div_int(mbedtls_mpi*Q,mbedtls_mpi*R,constmbedtls_mpi*A,
    mbedtls_mpi_sintb);

    intmbedtls_mpi_mod_mpi(mbedtls_mpi*R,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_mod_int(mbedtls_mpi_uint*r,constmbedtls_mpi*A,
    mbedtls_mpi_sintb);

    intmbedtls_mpi_exp_mod(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*E,constmbedtls_mpi*N,
    mbedtls_mpi*prec_RR);

    intmbedtls_mpi_fill_random(mbedtls_mpi*X,size_tsize,
    mbedtls_f_rng_t*f_rng,
    void*p_rng);

    intmbedtls_mpi_random(mbedtls_mpi*X,
    mbedtls_mpi_sintmin,
    constmbedtls_mpi*N,
    mbedtls_f_rng_t*f_rng,
    void*p_rng);

    intmbedtls_mpi_gcd(mbedtls_mpi*G,constmbedtls_mpi*A,
    constmbedtls_mpi*B);

    intmbedtls_mpi_inv_mod(mbedtls_mpi*X,constmbedtls_mpi*A,
    constmbedtls_mpi*N);

    intmbedtls_mpi_is_prime_ext(constmbedtls_mpi*X,introunds,
    mbedtls_f_rng_t*f_rng,
    void*p_rng);
    typedefenum{
    MBEDTLS_MPI_GEN_PRIME_FLAG_DH=0x0001,
    MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR=0x0002,
    }mbedtls_mpi_gen_prime_flag_t;

    intmbedtls_mpi_gen_prime(mbedtls_mpi*X,size_tnbits,intflags,
    mbedtls_f_rng_t*f_rng,
    void*p_rng);

    #ifdefined(MBEDTLS_SELF_TEST)

    intmbedtls_mpi_self_test(intverbose);

    #endif/*MBEDTLS_SELF_TEST*/

    #ifdef__cplusplus
    }
    #endif

    #endif/*bignum.h*/