ReactOS 0.4.16-dev-306-g647d351
|
Multi-precision integer library. More...
Go to the source code of this file.
Classes | |
struct | mbedtls_mpi |
MPI structure. More... | |
Macros | |
#define | MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 |
#define | MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 |
#define | MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 |
#define | MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 |
#define | MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A |
#define | MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C |
#define | MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E |
#define | MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 |
#define | MBEDTLS_MPI_CHK(f) |
#define | MBEDTLS_MPI_MAX_LIMBS 10000 |
#define | MBEDTLS_MPI_WINDOW_SIZE 6 |
#define | MBEDTLS_MPI_MAX_SIZE 1024 |
#define | MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) |
#define | MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS ) |
#define | MBEDTLS_LN_2_DIV_LN_10_SCALE100 332 |
#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 ) |
#define | MBEDTLS_HAVE_INT32 |
#define | MBEDTLS_HAVE_UDBL |
#define | MBEDTLS_DEPRECATED |
Typedefs | |
typedef int32_t | mbedtls_mpi_sint |
typedef uint32_t | mbedtls_mpi_uint |
typedef uint64_t | mbedtls_t_udbl |
typedef struct mbedtls_mpi | mbedtls_mpi |
MPI structure. | |
Enumerations | |
enum | mbedtls_mpi_gen_prime_flag_t { MBEDTLS_MPI_GEN_PRIME_FLAG_DH = 0x0001 , MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR = 0x0002 } |
Flags for mbedtls_mpi_gen_prime() More... | |
Functions | |
void | mbedtls_mpi_init (mbedtls_mpi *X) |
Initialize an MPI context. | |
void | mbedtls_mpi_free (mbedtls_mpi *X) |
This function frees the components of an MPI context. | |
int | mbedtls_mpi_grow (mbedtls_mpi *X, size_t nblimbs) |
Enlarge an MPI to the specified number of limbs. | |
int | mbedtls_mpi_shrink (mbedtls_mpi *X, size_t nblimbs) |
This function resizes an MPI downwards, keeping at least the specified number of limbs. | |
int | mbedtls_mpi_copy (mbedtls_mpi *X, const mbedtls_mpi *Y) |
Make a copy of an MPI. | |
void | mbedtls_mpi_swap (mbedtls_mpi *X, mbedtls_mpi *Y) |
Swap the contents of two MPIs. | |
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. | |
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. | |
int | mbedtls_mpi_lset (mbedtls_mpi *X, mbedtls_mpi_sint z) |
Store integer value in MPI. | |
int | mbedtls_mpi_get_bit (const mbedtls_mpi *X, size_t pos) |
Get a specific bit from an MPI. | |
int | mbedtls_mpi_set_bit (mbedtls_mpi *X, size_t pos, unsigned char val) |
Modify a specific bit in an MPI. | |
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 . | |
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 . | |
size_t | mbedtls_mpi_size (const mbedtls_mpi *X) |
Return the total size of an MPI value in bytes. | |
int | mbedtls_mpi_read_string (mbedtls_mpi *X, int radix, const char *s) |
Import an MPI from an ASCII 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. | |
int | mbedtls_mpi_read_binary (mbedtls_mpi *X, const unsigned char *buf, size_t buflen) |
Import an MPI from unsigned big endian binary data. | |
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. | |
int | mbedtls_mpi_shift_l (mbedtls_mpi *X, size_t count) |
Perform a left-shift on an MPI: X <<= count. | |
int | mbedtls_mpi_shift_r (mbedtls_mpi *X, size_t count) |
Perform a right-shift on an MPI: X >>= count. | |
int | mbedtls_mpi_cmp_abs (const mbedtls_mpi *X, const mbedtls_mpi *Y) |
Compare the absolute values of two MPIs. | |
int | mbedtls_mpi_cmp_mpi (const mbedtls_mpi *X, const mbedtls_mpi *Y) |
Compare two MPIs. | |
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. | |
int | mbedtls_mpi_cmp_int (const mbedtls_mpi *X, mbedtls_mpi_sint z) |
Compare an MPI with an integer. | |
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|. | |
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|. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
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. | |
int | mbedtls_mpi_mod_mpi (mbedtls_mpi *R, const mbedtls_mpi *A, const mbedtls_mpi *B) |
Perform a modular reduction. R = A mod B. | |
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. | |
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. | |
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. | |
int | mbedtls_mpi_gcd (mbedtls_mpi *G, const mbedtls_mpi *A, const mbedtls_mpi *B) |
Compute the greatest common divisor: G = gcd(A, B) | |
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_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. | |
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. | |
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. | |
Multi-precision integer library.
Definition in file bignum.h.
#define MBEDTLS_ERR_MPI_ALLOC_FAILED -0x0010 |
#define MBEDTLS_ERR_MPI_BAD_INPUT_DATA -0x0004 |
#define MBEDTLS_ERR_MPI_BUFFER_TOO_SMALL -0x0008 |
#define MBEDTLS_ERR_MPI_DIVISION_BY_ZERO -0x000C |
#define MBEDTLS_ERR_MPI_FILE_IO_ERROR -0x0002 |
#define MBEDTLS_ERR_MPI_INVALID_CHARACTER -0x0006 |
#define MBEDTLS_ERR_MPI_NEGATIVE_VALUE -0x000A |
#define MBEDTLS_ERR_MPI_NOT_ACCEPTABLE -0x000E |
#define MBEDTLS_MPI_MAX_BITS ( 8 * MBEDTLS_MPI_MAX_SIZE ) |
#define MBEDTLS_MPI_MAX_BITS_SCALE100 ( 100 * MBEDTLS_MPI_MAX_BITS ) |
#define MBEDTLS_MPI_MAX_SIZE 1024 |
#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 ) |
typedef struct mbedtls_mpi mbedtls_mpi |
MPI structure.
typedef int32_t mbedtls_mpi_sint |
typedef uint32_t mbedtls_mpi_uint |
typedef uint64_t mbedtls_t_udbl |
Flags for mbedtls_mpi_gen_prime()
Each of these flags is a constraint on the result X returned by mbedtls_mpi_gen_prime().
Enumerator | |
---|---|
MBEDTLS_MPI_GEN_PRIME_FLAG_DH | (X-1)/2 is prime too |
MBEDTLS_MPI_GEN_PRIME_FLAG_LOW_ERR | lower error rate from 2-80 to 2-128 |
Definition at line 966 of file bignum.h.
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|.
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. 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.
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. 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.
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. 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
.
int mbedtls_mpi_cmp_abs | ( | const mbedtls_mpi * | X, |
const mbedtls_mpi * | Y | ||
) |
int mbedtls_mpi_cmp_int | ( | const mbedtls_mpi * | X, |
mbedtls_mpi_sint | z | ||
) |
int mbedtls_mpi_cmp_mpi | ( | const mbedtls_mpi * | X, |
const mbedtls_mpi * | Y | ||
) |
int 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. |
0
if successful. 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.
Q | The destination MPI for the quotient. This may be NULL if the value of the quotient is not needed. |
R | The destination MPI for the remainder value. This may be NULL if the value of the remainder is not needed. |
A | The dividend. This must point to an initialized MPi. |
b | The divisor. |
0
if successful. b
equals zero. 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.
Q | The destination MPI for the quotient. This may be NULL if the value of the quotient is not needed. |
R | The destination MPI for the remainder value. This may be NULL if the value of the remainder is not needed. |
A | The dividend. This must point to an initialized MPi. |
B | The divisor. This must point to an initialized MPI. |
0
if successful. B
equals zero. 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.
X | The destination MPI. This must point to an initialized MPI. |
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. |
_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 _RR for reuse on subsequent calls to this function. Otherwise, the function will assume that _RR holds the helper value set by a previous call to mbedtls_mpi_exp_mod(), and reuse it. |
0
if successful. N
is negative or even, or if E
is negative. int mbedtls_mpi_fill_random | ( | mbedtls_mpi * | X, |
size_t | size, | ||
int(*)(void *, unsigned char *, size_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. void mbedtls_mpi_free | ( | mbedtls_mpi * | X | ) |
int 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. |
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. int mbedtls_mpi_gen_prime | ( | mbedtls_mpi * | X, |
size_t | nbits, | ||
int | flags, | ||
int(*)(void *, unsigned char *, size_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. nbits
is not between 3
and MBEDTLS_MPI_MAX_BITS. int mbedtls_mpi_get_bit | ( | const mbedtls_mpi * | X, |
size_t | pos | ||
) |
int mbedtls_mpi_grow | ( | mbedtls_mpi * | X, |
size_t | nblimbs | ||
) |
Enlarge an MPI to the specified number of limbs.
0
if successful. void mbedtls_mpi_init | ( | mbedtls_mpi * | X | ) |
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.
X | The destination MPI. This must point to an initialized MPI. |
A | The MPI to calculate the modular inverse of. This must point to an initialized MPI. |
N | The base of the modular inversion. This must point to an initialized MPI. |
0
if successful. N
is less than or equal to one. has
no modular inverse with respect to N
. MBEDTLS_DEPRECATED int mbedtls_mpi_is_prime | ( | const mbedtls_mpi * | X, |
int(*)(void *, unsigned char *, size_t) | f_rng, | ||
void * | p_rng | ||
) |
Perform a Miller-Rabin primality test with error probability of 2-80.
X | The MPI to check for primality. This must point to an initialized MPI. |
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. X
is not prime. int mbedtls_mpi_is_prime_ext | ( | const mbedtls_mpi * | X, |
int | rounds, | ||
int(*)(void *, unsigned char *, size_t) | f_rng, | ||
void * | p_rng | ||
) |
Miller-Rabin primality test.
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-adversially (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. X
is not prime. size_t mbedtls_mpi_lsb | ( | const mbedtls_mpi * | X | ) |
int mbedtls_mpi_lset | ( | mbedtls_mpi * | X, |
mbedtls_mpi_sint | z | ||
) |
Store integer value in MPI.
0
if successful. 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.
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 . |
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.
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. b
equals zero. b
is negative. int 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. B
equals zero. B
is negative. 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.
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. 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.
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. 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 p in Bytes. |
0
if successful. int mbedtls_mpi_read_string | ( | mbedtls_mpi * | X, |
int | radix, | ||
const char * | s | ||
) |
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.
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. Possible values: |
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).0
if successful. 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.
X | The first MPI. This must be initialized. |
Y | The second MPI. This must be initialized. |
assign | The condition deciding whether to perform the swap or not. Possible values: |
0
if successful. int mbedtls_mpi_set_bit | ( | mbedtls_mpi * | X, |
size_t | pos, | ||
unsigned char | val | ||
) |
Modify a specific bit in an MPI.
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. int 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. |
count | The number of bits to shift by. |
0
if successful. int 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. int 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. size_t mbedtls_mpi_size | ( | const mbedtls_mpi * | X | ) |
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|.
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. B
is greater than A
. 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.
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. 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.
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. void mbedtls_mpi_swap | ( | mbedtls_mpi * | X, |
mbedtls_mpi * | Y | ||
) |
Export an MPI into unsigned big endian binary data of fixed size.
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. buf
isn't large enough to hold the value of X
. 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.
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 . |
buflen == 0
to obtain the minimum required buffer size in *olen
.0
if successful. 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.