#include "common.h"
#if defined(MBEDTLS_BIGNUM_C)
#include "mbedtls/bignum.h"
#include "bignum_core.h"
#include "bignum_internal.h"
#include "bn_mul.h"
#include "mbedtls/platform_util.h"
#include "mbedtls/error.h"
#include "constant_time_internal.h"
#include <limits.h>
#include <string.h>
#include "mbedtls/platform.h"
static inline signed short mbedtls_ct_mpi_sign_if(mbedtls_ct_condition_t cond,
signed short sign1, signed short sign2)
{ … }
int mbedtls_mpi_lt_mpi_ct(const mbedtls_mpi *X,
const mbedtls_mpi *Y,
unsigned *ret)
{ … }
#if defined(_MSC_VER) && defined(MBEDTLS_PLATFORM_IS_WINDOWS_ON_ARM64) && \
(_MSC_FULL_VER < 193131103)
__declspec(noinline)
#endif
int mbedtls_mpi_safe_cond_assign(mbedtls_mpi *X,
const mbedtls_mpi *Y,
unsigned char assign)
{ … }
int mbedtls_mpi_safe_cond_swap(mbedtls_mpi *X,
mbedtls_mpi *Y,
unsigned char swap)
{ … }
#define mbedtls_mpi_zeroize_and_free(v, n) …
void mbedtls_mpi_init(mbedtls_mpi *X)
{ … }
void mbedtls_mpi_free(mbedtls_mpi *X)
{ … }
int mbedtls_mpi_grow(mbedtls_mpi *X, size_t nblimbs)
{ … }
int mbedtls_mpi_shrink(mbedtls_mpi *X, size_t nblimbs)
{ … }
static int mbedtls_mpi_resize_clear(mbedtls_mpi *X, size_t limbs)
{ … }
int mbedtls_mpi_copy(mbedtls_mpi *X, const mbedtls_mpi *Y)
{ … }
void mbedtls_mpi_swap(mbedtls_mpi *X, mbedtls_mpi *Y)
{ … }
static inline mbedtls_mpi_uint mpi_sint_abs(mbedtls_mpi_sint z)
{ … }
#define TO_SIGN(x) …
int mbedtls_mpi_lset(mbedtls_mpi *X, mbedtls_mpi_sint z)
{ … }
int mbedtls_mpi_get_bit(const mbedtls_mpi *X, size_t pos)
{ … }
int mbedtls_mpi_set_bit(mbedtls_mpi *X, size_t pos, unsigned char val)
{ … }
size_t mbedtls_mpi_lsb(const mbedtls_mpi *X)
{ … }
size_t mbedtls_mpi_bitlen(const mbedtls_mpi *X)
{ … }
size_t mbedtls_mpi_size(const mbedtls_mpi *X)
{ … }
static int mpi_get_digit(mbedtls_mpi_uint *d, int radix, char c)
{ … }
int mbedtls_mpi_read_string(mbedtls_mpi *X, int radix, const char *s)
{ … }
static int mpi_write_hlp(mbedtls_mpi *X, int radix,
char **p, const size_t buflen)
{ … }
int mbedtls_mpi_write_string(const mbedtls_mpi *X, int radix,
char *buf, size_t buflen, size_t *olen)
{ … }
#if defined(MBEDTLS_FS_IO)
int mbedtls_mpi_read_file(mbedtls_mpi *X, int radix, FILE *fin)
{ … }
int mbedtls_mpi_write_file(const char *p, const mbedtls_mpi *X, int radix, FILE *fout)
{ … }
#endif
int mbedtls_mpi_read_binary_le(mbedtls_mpi *X,
const unsigned char *buf, size_t buflen)
{ … }
int mbedtls_mpi_read_binary(mbedtls_mpi *X, const unsigned char *buf, size_t buflen)
{ … }
int mbedtls_mpi_write_binary_le(const mbedtls_mpi *X,
unsigned char *buf, size_t buflen)
{ … }
int mbedtls_mpi_write_binary(const mbedtls_mpi *X,
unsigned char *buf, size_t buflen)
{ … }
int mbedtls_mpi_shift_l(mbedtls_mpi *X, size_t count)
{ … }
int mbedtls_mpi_shift_r(mbedtls_mpi *X, size_t count)
{ … }
int mbedtls_mpi_cmp_abs(const mbedtls_mpi *X, const mbedtls_mpi *Y)
{ … }
int mbedtls_mpi_cmp_mpi(const mbedtls_mpi *X, const mbedtls_mpi *Y)
{ … }
int mbedtls_mpi_cmp_int(const mbedtls_mpi *X, mbedtls_mpi_sint z)
{ … }
int mbedtls_mpi_add_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_sub_abs(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
static int add_sub_mpi(mbedtls_mpi *X,
const mbedtls_mpi *A, const mbedtls_mpi *B,
int flip_B)
{ … }
int mbedtls_mpi_add_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_sub_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_add_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
{ … }
int mbedtls_mpi_sub_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_sint b)
{ … }
int mbedtls_mpi_mul_mpi(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_mul_int(mbedtls_mpi *X, const mbedtls_mpi *A, mbedtls_mpi_uint b)
{ … }
static mbedtls_mpi_uint mbedtls_int_div_int(mbedtls_mpi_uint u1,
mbedtls_mpi_uint u0,
mbedtls_mpi_uint d,
mbedtls_mpi_uint *r)
{ … }
int mbedtls_mpi_div_mpi(mbedtls_mpi *Q, mbedtls_mpi *R, const mbedtls_mpi *A,
const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_div_int(mbedtls_mpi *Q, mbedtls_mpi *R,
const mbedtls_mpi *A,
mbedtls_mpi_sint b)
{ … }
int mbedtls_mpi_mod_mpi(mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_mod_int(mbedtls_mpi_uint *r, const mbedtls_mpi *A, mbedtls_mpi_sint b)
{ … }
static int mbedtls_mpi_exp_mod_optionally_safe(mbedtls_mpi *X, const mbedtls_mpi *A,
const mbedtls_mpi *E, int E_public,
const mbedtls_mpi *N, mbedtls_mpi *prec_RR)
{ … }
int mbedtls_mpi_exp_mod(mbedtls_mpi *X, const mbedtls_mpi *A,
const mbedtls_mpi *E, const mbedtls_mpi *N,
mbedtls_mpi *prec_RR)
{ … }
int mbedtls_mpi_exp_mod_unsafe(mbedtls_mpi *X, const mbedtls_mpi *A,
const mbedtls_mpi *E, const mbedtls_mpi *N,
mbedtls_mpi *prec_RR)
{ … }
int mbedtls_mpi_gcd(mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B)
{ … }
int mbedtls_mpi_fill_random(mbedtls_mpi *X, size_t size,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_mpi_random(mbedtls_mpi *X,
mbedtls_mpi_sint min,
const mbedtls_mpi *N,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_mpi_inv_mod(mbedtls_mpi *X, const mbedtls_mpi *A, const mbedtls_mpi *N)
{ … }
#if defined(MBEDTLS_GENPRIME)
static const unsigned char small_prime_gaps[] = …;
static int mpi_check_small_factors(const mbedtls_mpi *X)
{ … }
static int mpi_miller_rabin(const mbedtls_mpi *X, size_t rounds,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_mpi_is_prime_ext(const mbedtls_mpi *X, int rounds,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
int mbedtls_mpi_gen_prime(mbedtls_mpi *X, size_t nbits, int flags,
int (*f_rng)(void *, unsigned char *, size_t),
void *p_rng)
{ … }
#endif
#if defined(MBEDTLS_SELF_TEST)
#define GCD_PAIR_COUNT …
static const int gcd_pairs[GCD_PAIR_COUNT][3] = …;
int mbedtls_mpi_self_test(int verbose)
{ … }
#endif
#endif