|
Botan 3.13.0
Crypto and TLS for C&
|
#include <botan/ffi.h>#include <botan/assert.h>#include <botan/numthry.h>#include <botan/internal/barrett.h>#include <botan/internal/divide.h>#include <botan/internal/ffi_mp.h>#include <botan/internal/ffi_rng.h>#include <botan/internal/ffi_util.h>#include <botan/internal/mem_utils.h>#include <botan/internal/mod_inv.h>Go to the source code of this file.
| int botan_mp_add | ( | botan_mp_t | result, |
| botan_mp_t | x, | ||
| botan_mp_t | y ) |
Set result to x + y
| result | set to the sum |
| x | the first addend |
| y | the second addend |
Definition at line 161 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_add_u32 | ( | botan_mp_t | result, |
| botan_mp_t | x, | ||
| uint32_t | y ) |
Set result to x + y
| result | set to the sum |
| x | the first addend |
| y | the second addend |
Definition at line 181 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_clear | ( | botan_mp_t | mp | ) |
| int botan_mp_clear_bit | ( | botan_mp_t | n, |
| size_t | bit ) |
| int botan_mp_cmp | ( | int * | result, |
| botan_mp_t | x, | ||
| botan_mp_t | y ) |
Compare two integers
| result | set to -1 if x < y, 0 if x == y, 1 if x > y |
| x | the first integer |
| y | the second integer |
Definition at line 235 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_destroy | ( | botan_mp_t | mp | ) |
Destroy (deallocate) an MPI
Definition at line 157 of file ffi_mp.cpp.
References BOTAN_FFI_CHECKED_DELETE.
| int botan_mp_div | ( | botan_mp_t | quotient, |
| botan_mp_t | remainder, | ||
| botan_mp_t | x, | ||
| botan_mp_t | y ) |
Divide x by y, producing both the quotient and the remainder
| quotient | set to x / y |
| remainder | set to x % y |
| x | the dividend |
| y | the divisor, which must not be zero |
Definition at line 211 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan_FFI::safe_get(), and Botan::vartime_divide().
| int botan_mp_equal | ( | botan_mp_t | x, |
| botan_mp_t | y ) |
Test if two integers are equal
| x | the first integer |
| y | the second integer |
Definition at line 219 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_flip_sign | ( | botan_mp_t | mp | ) |
Negate the MPI, ie replace it by its additive inverse
| Big Integer (Low-Level) | the integer to negate, modified in place |
Definition at line 80 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_from_bin | ( | botan_mp_t | mp, |
| const uint8_t | vec[], | ||
| size_t | vec_len ) |
Set an MP to the big-endian binary value
| Big Integer (Low-Level) | the integer to set |
| vec | the big-endian encoding to decode |
| vec_len | length of vec in bytes |
Definition at line 84 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_gcd | ( | botan_mp_t | out, |
| botan_mp_t | x, | ||
| botan_mp_t | y ) |
Set out to the greatest common divisor of x and y
| out | set to gcd(x, y) |
| x | the first integer |
| y | the second integer |
Definition at line 282 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan::gcd(), and Botan_FFI::safe_get().
| int botan_mp_get_bit | ( | botan_mp_t | n, |
| size_t | bit ) |
Returns 0 if specified bit of n is not set Returns 1 if specified bit of n is set Returns negative number on error
Definition at line 290 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_init | ( | botan_mp_t * | mp | ) |
Initialize an MPI
Definition at line 24 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, Botan_FFI::ffi_guard_thunk(), and Botan_FFI::ffi_new_object().
| int botan_mp_is_even | ( | botan_mp_t | mp | ) |
Return 1 iff mp is even
| Big Integer (Low-Level) | the integer to test |
Definition at line 231 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_is_negative | ( | botan_mp_t | mp | ) |
Return 1 iff mp is less than 0
Definition at line 72 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_is_odd | ( | botan_mp_t | mp | ) |
Return 1 iff mp is odd
| Big Integer (Low-Level) | the integer to test |
Definition at line 227 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_is_positive | ( | botan_mp_t | mp | ) |
This function should have been named mp_is_non_negative. Returns 1 iff mp is greater than or equal to zero. Use botan_mp_is_negative to detect negative numbers, botan_mp_is_zero to check for zero.
Definition at line 76 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_is_prime | ( | botan_mp_t | n, |
| botan_rng_t | rng, | ||
| size_t | test_prob ) |
Returns 0 if n is not prime Returns 1 if n is prime Returns negative number on error
Definition at line 286 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan::is_prime(), and Botan_FFI::safe_get().
| int botan_mp_is_zero | ( | botan_mp_t | mp | ) |
Return 1 iff mp is equal to zero
| Big Integer (Low-Level) | the integer to test |
Definition at line 223 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT.
| int botan_mp_lshift | ( | botan_mp_t | out, |
| botan_mp_t | in, | ||
| size_t | shift ) |
Set out to in shifted left by the specified number of bits
| out | set to the shifted value |
| in | the integer to shift |
| shift | the number of bits to shift by |
Definition at line 252 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_mod_inverse | ( | botan_mp_t | out, |
| botan_mp_t | in, | ||
| botan_mp_t | modulus ) |
Set out to the inverse of in modulo the specified modulus. If no inverse exists, out is set to zero.
| out | set to the modular inverse |
| in | the value to invert |
| modulus | the modulus |
Definition at line 260 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan::inverse_mod_general(), Botan_FFI::safe_get(), and Botan::BigInt::zero().
| int botan_mp_mod_mul | ( | botan_mp_t | result, |
| botan_mp_t | x, | ||
| botan_mp_t | y, | ||
| botan_mp_t | mod ) |
Set result to (x * y) % mod
| result | set to the modular product |
| x | the first factor |
| y | the second factor |
| mod | the modulus, which must be positive |
Definition at line 266 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan::Barrett_Reduction::for_secret_modulus(), and Botan_FFI::safe_get().
| int botan_mp_mul | ( | botan_mp_t | result, |
| botan_mp_t | x, | ||
| botan_mp_t | y ) |
Set result to x * y
| result | set to the product |
| x | the first factor |
| y | the second factor |
Definition at line 201 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_num_bits | ( | botan_mp_t | n, |
| size_t * | bits ) |
Return the number of significant bits in the MPI
Definition at line 302 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_num_bytes | ( | botan_mp_t | n, |
| size_t * | bytes ) |
Return the number of significant bytes in the MPI
Definition at line 309 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_powmod | ( | botan_mp_t | out, |
| botan_mp_t | base, | ||
| botan_mp_t | exponent, | ||
| botan_mp_t | modulus ) |
Set out to (base^exponent) % modulus
| out | set to the result of the modular exponentiation |
| Base Types | the base |
| exponent | the exponent |
| modulus | the modulus, which must be positive |
Definition at line 247 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan::power_mod(), and Botan_FFI::safe_get().
| int botan_mp_rand_bits | ( | botan_mp_t | rand_out, |
| botan_rng_t | rng, | ||
| size_t | bits ) |
Set rand_out to a random integer of the specified bit length
| rand_out | set to the random integer |
| Random Number Generators | a random number generator |
| bits | the desired bit length |
Definition at line 273 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_rand_range | ( | botan_mp_t | rand_out, |
| botan_rng_t | rng, | ||
| botan_mp_t | lower_bound, | ||
| botan_mp_t | upper_bound ) |
Set rand_out to a random integer within the half-open range [lower_bound, upper_bound)
| rand_out | set to the random integer |
| Random Number Generators | a random number generator |
| lower_bound | the inclusive lower bound |
| upper_bound | the exclusive upper bound |
Definition at line 277 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, Botan::BigInt::random_integer(), and Botan_FFI::safe_get().
| int botan_mp_rshift | ( | botan_mp_t | out, |
| botan_mp_t | in, | ||
| size_t | shift ) |
Set out to in shifted right by the specified number of bits
| out | set to the shifted value |
| in | the integer to shift |
| shift | the number of bits to shift by |
Definition at line 256 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_set_bit | ( | botan_mp_t | n, |
| size_t | bit ) |
| int botan_mp_set_from_int | ( | botan_mp_t | mp, |
| int | initial_value ) |
Set the MPI value from an int
Definition at line 39 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan::BigInt::from_s32().
| int botan_mp_set_from_mp | ( | botan_mp_t | dest, |
| botan_mp_t | source ) |
Set the MPI value from another MP object
Definition at line 68 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_set_from_radix_str | ( | botan_mp_t | dest, |
| const char * | str, | ||
| size_t | radix ) |
Set the MPI value from a string with arbitrary radix. For arbitrary being 10 or 16.
Definition at line 51 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NOT_IMPLEMENTED, BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, BOTAN_FFI_VISIT, and Botan::BigInt::from_radix_digits().
| int botan_mp_set_from_str | ( | botan_mp_t | dest, |
| const char * | str ) |
Set the MPI value from a string
Definition at line 43 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_sub | ( | botan_mp_t | result, |
| botan_mp_t | x, | ||
| botan_mp_t | y ) |
Set result to x - y
| result | set to the difference |
| x | the minuend |
| y | the subtrahend |
Definition at line 171 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_sub_u32 | ( | botan_mp_t | result, |
| botan_mp_t | x, | ||
| uint32_t | y ) |
Set result to x - y
| result | set to the difference |
| x | the minuend |
| y | the subtrahend |
Definition at line 191 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_swap | ( | botan_mp_t | x, |
| botan_mp_t | y ) |
Swap the values of two integers
| x | the first integer |
| y | the second integer |
Definition at line 242 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::safe_get().
| int botan_mp_to_bin | ( | botan_mp_t | mp, |
| uint8_t | vec[] ) |
Convert the MPI to a big-endian binary string. Writes botan_mp_num_bytes to vec
Note that the sign of the integer is ignored here; only the absolute value is copied
| Big Integer (Low-Level) | the integer to encode |
| vec | output buffer of at least botan_mp_num_bytes(mp) bytes |
Definition at line 136 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_to_hex | ( | botan_mp_t | mp, |
| char * | out ) |
Convert the MPI to a hex string. Writes up to botan_mp_num_bytes(mp)*2 + 5 bytes
Prefer botan_mp_view_hex
Definition at line 91 of file ffi_mp.cpp.
References BOTAN_ASSERT_NOMSG, BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_to_str | ( | botan_mp_t | mp, |
| uint8_t | radix, | ||
| char * | out, | ||
| size_t * | out_len ) |
Convert the MPI to a string. Currently radix == 10 and radix == 16 are supported.
Definition at line 112 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_VISIT, and Botan_FFI::write_str_output().
| int botan_mp_to_uint32 | ( | botan_mp_t | mp, |
| uint32_t * | val ) |
Convert the MPI to a uint32_t, if possible. Fails if MPI is negative or too large.
| Big Integer (Low-Level) | the integer to convert |
| val | set to the value of mp |
Definition at line 150 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_NULL_POINTER, and BOTAN_FFI_VISIT.
| int botan_mp_view_bin | ( | botan_mp_t | mp, |
| botan_view_ctx | ctx, | ||
| botan_view_bin_fn | view ) |
View the big-endian binary string encoding of this integer
Note that the sign of the integer is ignored here; only the absolute value is viewed
| Big Integer (Low-Level) | the integer to encode |
| ctx | an application context passed to the view function |
| view | the view callback which receives the encoding |
Definition at line 143 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().
| int botan_mp_view_hex | ( | botan_mp_t | mp, |
| botan_view_ctx | ctx, | ||
| botan_view_str_fn | view ) |
View the hex string encoding of the MPI.
Definition at line 105 of file ffi_mp.cpp.
References BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().
| int botan_mp_view_str | ( | botan_mp_t | mp, |
| uint8_t | radix, | ||
| botan_view_ctx | ctx, | ||
| botan_view_str_fn | view ) |
View the MPI as a radix-N integer. Currently only radix 10 and radix 16 are supported
Definition at line 124 of file ffi_mp.cpp.
References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_VISIT, and Botan_FFI::invoke_view_callback().