Botan 2.19.5 Crypto and TLS for C&

Functions
ffi_mp.cpp File Reference
`#include <botan/ffi.h>`
`#include <botan/internal/ffi_util.h>`
`#include <botan/internal/ffi_rng.h>`
`#include <botan/internal/ffi_mp.h>`
`#include <botan/reducer.h>`
`#include <botan/numthry.h>`
`#include <botan/divide.h>`

Go to the source code of this file.

## Functions
int | botan_mp_add (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_add_u32 (botan_mp_t result, const botan_mp_t x, uint32_t y)
int | botan_mp_clear (botan_mp_t mp)
int | botan_mp_clear_bit (botan_mp_t mp, size_t bit)
int | botan_mp_cmp (int *result, const botan_mp_t x_w, const botan_mp_t y_w)
int | botan_mp_destroy (botan_mp_t mp)
int | botan_mp_div (botan_mp_t quotient, botan_mp_t remainder, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_equal (const botan_mp_t x_w, const botan_mp_t y_w)
int | botan_mp_flip_sign (botan_mp_t mp)
int | botan_mp_from_bin (botan_mp_t mp, const uint8_t bin[], size_t bin_len)
int | botan_mp_gcd (botan_mp_t out, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_get_bit (const botan_mp_t mp, size_t bit)
int | botan_mp_init (botan_mp_t *mp_out)
int | botan_mp_is_even (const botan_mp_t mp)
int | botan_mp_is_negative (const botan_mp_t mp)
int | botan_mp_is_odd (const botan_mp_t mp)
int | botan_mp_is_positive (const botan_mp_t mp)
int | botan_mp_is_prime (const botan_mp_t mp, botan_rng_t rng, size_t test_prob)
int | botan_mp_is_zero (const botan_mp_t mp)
int | botan_mp_lshift (botan_mp_t out, const botan_mp_t in, size_t shift)
int | botan_mp_mod_inverse (botan_mp_t out, const botan_mp_t in, const botan_mp_t modulus)
int | botan_mp_mod_mul (botan_mp_t out, const botan_mp_t x, const botan_mp_t y, const botan_mp_t modulus)
int | botan_mp_mul (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_num_bits (const botan_mp_t mp, size_t *bits)
int | botan_mp_num_bytes (const botan_mp_t mp, size_t *bytes)
int | botan_mp_powmod (botan_mp_t out, const botan_mp_t base, const botan_mp_t exponent, const botan_mp_t modulus)
int | botan_mp_rand_bits (botan_mp_t rand_out, botan_rng_t rng, size_t bits)
int | botan_mp_rand_range (botan_mp_t rand_out, botan_rng_t rng, const botan_mp_t lower, const botan_mp_t upper)
int | botan_mp_rshift (botan_mp_t out, const botan_mp_t in, size_t shift)
int | botan_mp_set_bit (botan_mp_t mp, size_t bit)
int | botan_mp_set_from_int (botan_mp_t mp, int initial_value)
int | botan_mp_set_from_mp (botan_mp_t dest, const botan_mp_t source)
int | botan_mp_set_from_radix_str (botan_mp_t mp, const char *str, size_t radix)
int | botan_mp_set_from_str (botan_mp_t mp, const char *str)
int | botan_mp_sub (botan_mp_t result, const botan_mp_t x, const botan_mp_t y)
int | botan_mp_sub_u32 (botan_mp_t result, const botan_mp_t x, uint32_t y)
int | botan_mp_swap (botan_mp_t x_w, botan_mp_t y_w)
int | botan_mp_to_bin (const botan_mp_t mp, uint8_t vec[])
int | botan_mp_to_hex (const botan_mp_t mp, char *out)
int | botan_mp_to_str (const botan_mp_t mp, uint8_t digit_base, char *out, size_t *out_len)
int | botan_mp_to_uint32 (const botan_mp_t mp, uint32_t *val)

## Function Documentation

## ◆ botan_mp_add()

int botan_mp_add | ( | botan_mp_t | result,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y
| ) |  |

Definition at line 139 of file ffi_mp.cpp.

140 {
141 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
142 if(result == x)
143 res += safe_get(y);
144 else
145 res = safe_get(x) + safe_get(y);
146 });
147 }
Botan::BigInt
Definition: bigint.h:25
BOTAN_FFI_DO
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:92
Botan_FFI::safe_get
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:61

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_add_u32()

int botan_mp_add_u32 | ( | botan_mp_t | result,
|  | const botan_mp_t | x,
|  | uint32_t | y
| ) |  |

Definition at line 159 of file ffi_mp.cpp.

160 {
161 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
162 if(result == x)
163 res += static_cast<Botan::word>(y);
164 else
165 res = safe_get(x) + static_cast<Botan::word>(y);
166 });
167 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_clear()

int botan_mp_clear | ( | botan_mp_t | mp | ) |

Set the MPI to zero

Definition at line 31 of file ffi_mp.cpp.

32 {
33 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.clear(); });
34 }
Botan::BigInt::clear
void clear()
Definition: bigint.h:372

References BOTAN_FFI_DO, and Botan::BigInt::clear().

## ◆ botan_mp_clear_bit()

int botan_mp_clear_bit | ( | botan_mp_t | n,
|  | size_t | bit
| ) |  |

Clear the specified bit

Definition at line 297 of file ffi_mp.cpp.

298 {
299 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
300 }
Botan::BigInt::clear_bit
void clear_bit(size_t n)
Definition: bigint.cpp:278

References BOTAN_FFI_DO, and Botan::BigInt::clear_bit().

## ◆ botan_mp_cmp()

int botan_mp_cmp | ( | int * | result,
|  | const botan_mp_t | x_w,
|  | const botan_mp_t | y_w
| ) |  |

Definition at line 220 of file ffi_mp.cpp.

221 {
222 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { *result = x.cmp(safe_get(y_w)); });
223 }
Botan::BigInt::cmp
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:138

References BOTAN_FFI_DO, Botan::BigInt::cmp(), and Botan_FFI::safe_get().

## ◆ botan_mp_destroy()

int botan_mp_destroy | ( | botan_mp_t | mp | ) |

Destroy (deallocate) an MPI

Returns
  0 if success, error if invalid object handle

Definition at line 134 of file ffi_mp.cpp.

135 {
136 return BOTAN_FFI_CHECKED_DELETE(mp);
137 }
BOTAN_FFI_CHECKED_DELETE
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:129

References BOTAN_FFI_CHECKED_DELETE.

## ◆ botan_mp_div()

int botan_mp_div | ( | botan_mp_t | quotient,
|  | botan_mp_t | remainder,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y
| ) |  |

Definition at line 189 of file ffi_mp.cpp.

192 {
193 return BOTAN_FFI_DO(Botan::BigInt, quotient, q, {
194 Botan::BigInt r;
195 Botan::vartime_divide(safe_get(x), safe_get(y), q, r);
196 safe_get(remainder) = r;
197 });
198 }
Botan::vartime_divide
void vartime_divide(const BigInt &x, const BigInt &y_arg, BigInt &q_out, BigInt &r_out)
Definition: divide.cpp:159

References BOTAN_FFI_DO, Botan_FFI::safe_get(), and Botan::vartime_divide().

## ◆ botan_mp_equal()

int botan_mp_equal | ( | const botan_mp_t | x_w,
|  | const botan_mp_t | y_w
| ) |  |

Definition at line 200 of file ffi_mp.cpp.

201 {
202 return BOTAN_FFI_RETURNING(Botan::BigInt, x_w, x, { return x == safe_get(y_w); });
203 }
BOTAN_FFI_RETURNING
#define BOTAN_FFI_RETURNING(T, obj, param, block)
Definition: ffi_util.h:101

References BOTAN_FFI_RETURNING, and Botan_FFI::safe_get().

## ◆ botan_mp_flip_sign()

int botan_mp_flip_sign | ( | botan_mp_t | mp | ) |

Definition at line 89 of file ffi_mp.cpp.

90 {
91 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.flip_sign(); });
92 }
Botan::BigInt::flip_sign
void flip_sign()
Definition: bigint.h:560

References BOTAN_FFI_DO, and Botan::BigInt::flip_sign().

## ◆ botan_mp_from_bin()

int botan_mp_from_bin | ( | botan_mp_t | mp,
|  | const uint8_t | bin[],
|  | size_t | bin_len
| ) |  |

Definition at line 94 of file ffi_mp.cpp.

95 {
96 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_decode(bin, bin_len); });
97 }
Botan::BigInt::binary_decode
void binary_decode(const uint8_t buf[], size_t length)
Definition: bigint.cpp:440

References Botan::BigInt::binary_decode(), and BOTAN_FFI_DO.

## ◆ botan_mp_gcd()

int botan_mp_gcd | ( | botan_mp_t | out,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y
| ) |  |

Definition at line 275 of file ffi_mp.cpp.

276 {
277 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
278 o = Botan::gcd(safe_get(x), safe_get(y)); });
279 }
Botan::gcd
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:52

References BOTAN_FFI_DO, Botan::gcd(), and Botan_FFI::safe_get().

## ◆ botan_mp_get_bit()

int botan_mp_get_bit | ( | const 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 287 of file ffi_mp.cpp.

288 {
289 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n, { return (n.get_bit(bit)); });
290 }

References BOTAN_FFI_RETURNING.

## ◆ botan_mp_init()

int botan_mp_init | ( | botan_mp_t * | mp | ) |

Initialize an MPI

Definition at line 20 of file ffi_mp.cpp.

21 {
22 return ffi_guard_thunk(__func__, [=]() -> int {
23 if(mp_out == nullptr)
24 return BOTAN_FFI_ERROR_NULL_POINTER;
25
26 *mp_out = new botan_mp_struct(new Botan::BigInt);
27 return BOTAN_FFI_SUCCESS;
28 });
29 }
BOTAN_FFI_ERROR_NULL_POINTER
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:77
BOTAN_FFI_SUCCESS
@ BOTAN_FFI_SUCCESS
Definition: ffi.h:63
Botan_FFI::ffi_guard_thunk
int ffi_guard_thunk(const char *func_name, std::function< int()> thunk)
Definition: ffi.cpp:89

References BOTAN_FFI_ERROR_NULL_POINTER, BOTAN_FFI_SUCCESS, and Botan_FFI::ffi_guard_thunk().

## ◆ botan_mp_is_even()

int botan_mp_is_even | ( | const botan_mp_t | mp | ) |

Definition at line 215 of file ffi_mp.cpp.

216 {
217 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_even(); });
218 }
Botan::BigInt::is_even
bool is_even() const
Definition: bigint.h:409

References BOTAN_FFI_RETURNING, and Botan::BigInt::is_even().

## ◆ botan_mp_is_negative()

int botan_mp_is_negative | ( | const botan_mp_t | mp | ) |

Return 1 iff mp is less than 0

Definition at line 79 of file ffi_mp.cpp.

80 {
81 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_negative() ? 1 : 0; });
82 }
Botan::BigInt::is_negative
bool is_negative() const
Definition: bigint.h:533

References BOTAN_FFI_DO, and Botan::BigInt::is_negative().

## ◆ botan_mp_is_odd()

int botan_mp_is_odd | ( | const botan_mp_t | mp | ) |

Definition at line 210 of file ffi_mp.cpp.

211 {
212 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_odd(); });
213 }
Botan::BigInt::is_odd
bool is_odd() const
Definition: bigint.h:415

References BOTAN_FFI_RETURNING, and Botan::BigInt::is_odd().

## ◆ botan_mp_is_positive()

int botan_mp_is_positive | ( | const 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 84 of file ffi_mp.cpp.

85 {
86 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_positive() ? 1 : 0; });
87 }
Botan::BigInt::is_positive
bool is_positive() const
Definition: bigint.h:539

References BOTAN_FFI_DO, and Botan::BigInt::is_positive().

## ◆ botan_mp_is_prime()

int botan_mp_is_prime | ( | const 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 281 of file ffi_mp.cpp.

282 {
283 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, n,
284 { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
285 }
Botan::is_prime
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:218

References BOTAN_FFI_RETURNING, Botan::is_prime(), and Botan_FFI::safe_get().

## ◆ botan_mp_is_zero()

int botan_mp_is_zero | ( | const botan_mp_t | mp | ) |

Definition at line 205 of file ffi_mp.cpp.

206 {
207 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, { return bn.is_zero(); });
208 }
Botan::BigInt::is_zero
bool is_zero() const
Definition: bigint.h:427

References BOTAN_FFI_RETURNING, and Botan::BigInt::is_zero().

## ◆ botan_mp_lshift()

int botan_mp_lshift | ( | botan_mp_t | out,
|  | const botan_mp_t | in,
|  | size_t | shift
| ) |  |

Definition at line 237 of file ffi_mp.cpp.

238 {
239 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
240 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_mod_inverse()

int botan_mp_mod_inverse | ( | botan_mp_t | out,
|  | const botan_mp_t | in,
|  | const botan_mp_t | modulus
| ) |  |

Definition at line 247 of file ffi_mp.cpp.

248 {
249 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
250 }
Botan::inverse_mod
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: mod_inv.cpp:250

References BOTAN_FFI_DO, Botan::inverse_mod(), and Botan_FFI::safe_get().

## ◆ botan_mp_mod_mul()

int botan_mp_mod_mul | ( | botan_mp_t | out,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y,
|  | const botan_mp_t | modulus
| ) |  |

Definition at line 252 of file ffi_mp.cpp.

253 {
254 return BOTAN_FFI_DO(Botan::BigInt, out, o, {
255 Botan::Modular_Reducer reducer(safe_get(modulus));
256 o = reducer.multiply(safe_get(x), safe_get(y));
257 });
258 }
Botan::Modular_Reducer
Definition: reducer.h:19

References BOTAN_FFI_DO, Botan::Modular_Reducer::multiply(), and Botan_FFI::safe_get().

## ◆ botan_mp_mul()

int botan_mp_mul | ( | botan_mp_t | result,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y
| ) |  |

Definition at line 179 of file ffi_mp.cpp.

180 {
181 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
182 if(result == x)
183 res *= safe_get(y);
184 else
185 res = safe_get(x) * safe_get(y);
186 });
187 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_num_bits()

int botan_mp_num_bits | ( | const 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.

303 {
304 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bits = n.bits(); });
305 }
Botan::BigInt::bits
size_t bits() const
Definition: bigint.cpp:304

References Botan::BigInt::bits(), and BOTAN_FFI_DO.

## ◆ botan_mp_num_bytes()

int botan_mp_num_bytes | ( | const botan_mp_t | n,
|  | size_t * | bytes
| ) |  |

Return the number of significant bytes in the MPI

Definition at line 307 of file ffi_mp.cpp.

308 {
309 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
310 }
Botan::BigInt::bytes
size_t bytes() const
Definition: bigint.cpp:289

References BOTAN_FFI_DO, and Botan::BigInt::bytes().

## ◆ botan_mp_powmod()

int botan_mp_powmod | ( | botan_mp_t | out,
|  | const botan_mp_t | base,
|  | const botan_mp_t | exponent,
|  | const botan_mp_t | modulus
| ) |  |

Definition at line 231 of file ffi_mp.cpp.

232 {
233 return BOTAN_FFI_DO(Botan::BigInt, out, o,
234 { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
235 }
Botan::power_mod
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:141

References BOTAN_FFI_DO, Botan::power_mod(), and Botan_FFI::safe_get().

## ◆ botan_mp_rand_bits()

int botan_mp_rand_bits | ( | botan_mp_t | rand_out,
|  | botan_rng_t | rng,
|  | size_t | bits
| ) |  |

Definition at line 260 of file ffi_mp.cpp.

261 {
262 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, {
263 safe_get(rand_out).randomize(r, bits); });
264 }
Botan::RandomNumberGenerator
Definition: rng.h:26

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_rand_range()

int botan_mp_rand_range | ( | botan_mp_t | rand_out,
|  | botan_rng_t | rng,
|  | const botan_mp_t | lower,
|  | const botan_mp_t | upper
| ) |  |

Definition at line 266 of file ffi_mp.cpp.

270 {
271 return BOTAN_FFI_DO(Botan::RandomNumberGenerator, rng, r, {
272 safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
273 }
Botan::BigInt::random_integer
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45

References BOTAN_FFI_DO, Botan::BigInt::random_integer(), and Botan_FFI::safe_get().

## ◆ botan_mp_rshift()

int botan_mp_rshift | ( | botan_mp_t | out,
|  | const botan_mp_t | in,
|  | size_t | shift
| ) |  |

Definition at line 242 of file ffi_mp.cpp.

243 {
244 return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
245 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_set_bit()

int botan_mp_set_bit | ( | botan_mp_t | n,
|  | size_t | bit
| ) |  |

Set the specified bit

Definition at line 292 of file ffi_mp.cpp.

293 {
294 return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.set_bit(bit); });
295 }
Botan::BigInt::set_bit
void set_bit(size_t n)
Definition: bigint.h:436

References BOTAN_FFI_DO, and Botan::BigInt::set_bit().

## ◆ botan_mp_set_from_int()

int botan_mp_set_from_int | ( | botan_mp_t | mp,
|  | int | initial_value
| ) |  |

Set the MPI value from an int

Definition at line 36 of file ffi_mp.cpp.

37 {
38 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
39 if(initial_value >= 0)
40 {
41 bn = Botan::BigInt(static_cast<uint64_t>(initial_value));
42 }
43 else
44 {
45 bn = Botan::BigInt(static_cast<uint64_t>(-initial_value));
46 bn.flip_sign();
47 }
48 });
49 }

References BOTAN_FFI_DO.

## ◆ botan_mp_set_from_mp()

int botan_mp_set_from_mp | ( | botan_mp_t | dest,
|  | const botan_mp_t | source
| ) |  |

Set the MPI value from another MP object

Definition at line 74 of file ffi_mp.cpp.

75 {
76 return BOTAN_FFI_DO(Botan::BigInt, dest, bn, { bn = safe_get(source); });
77 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_set_from_radix_str()

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 56 of file ffi_mp.cpp.

57 {
58 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
59 Botan::BigInt::Base base;
60 if(radix == 10)
61 base = Botan::BigInt::Decimal;
62 else if(radix == 16)
63 base = Botan::BigInt::Hexadecimal;
64 else
65 return BOTAN_FFI_ERROR_NOT_IMPLEMENTED;
66
67 const uint8_t* bytes = Botan::cast_char_ptr_to_uint8(str);
68 const size_t len = strlen(str);
69
70 bn = Botan::BigInt(bytes, len, base);
71 });
72 }
Botan::BigInt::Base
Base
Definition: bigint.h:30
Botan::BigInt::Decimal
@ Decimal
Definition: bigint.h:30
Botan::BigInt::Hexadecimal
@ Hexadecimal
Definition: bigint.h:30
BOTAN_FFI_ERROR_NOT_IMPLEMENTED
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:83
Botan::cast_char_ptr_to_uint8
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:190

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NOT_IMPLEMENTED, Botan::cast_char_ptr_to_uint8(), Botan::BigInt::Decimal, and Botan::BigInt::Hexadecimal.

## ◆ botan_mp_set_from_str()

int botan_mp_set_from_str | ( | botan_mp_t | dest,
|  | const char * | str
| ) |  |

Set the MPI value from a string

Definition at line 51 of file ffi_mp.cpp.

52 {
53 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn = Botan::BigInt(str); });
54 }

References BOTAN_FFI_DO.

## ◆ botan_mp_sub()

int botan_mp_sub | ( | botan_mp_t | result,
|  | const botan_mp_t | x,
|  | const botan_mp_t | y
| ) |  |

Definition at line 149 of file ffi_mp.cpp.

150 {
151 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
152 if(result == x)
153 res -= safe_get(y);
154 else
155 res = safe_get(x) - safe_get(y);
156 });
157 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_sub_u32()

int botan_mp_sub_u32 | ( | botan_mp_t | result,
|  | const botan_mp_t | x,
|  | uint32_t | y
| ) |  |

Definition at line 169 of file ffi_mp.cpp.

170 {
171 return BOTAN_FFI_DO(Botan::BigInt, result, res, {
172 if(result == x)
173 res -= static_cast<Botan::word>(y);
174 else
175 res = safe_get(x) - static_cast<Botan::word>(y);
176 });
177 }

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

## ◆ botan_mp_swap()

int botan_mp_swap | ( | botan_mp_t | x_w,
|  | botan_mp_t | y_w
| ) |  |

Definition at line 225 of file ffi_mp.cpp.

226 {
227 return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
228 }
Botan::BigInt::swap
void swap(BigInt &other)
Definition: bigint.h:167

References BOTAN_FFI_DO, Botan_FFI::safe_get(), and Botan::BigInt::swap().

## ◆ botan_mp_to_bin()

int botan_mp_to_bin | ( | const botan_mp_t | mp,
|  | uint8_t | vec[]
| ) |  |

Definition at line 120 of file ffi_mp.cpp.

121 {
122 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_encode(vec); });
123 }
Botan::BigInt::binary_encode
void binary_encode(uint8_t buf[]) const
Definition: bigint.cpp:407

References Botan::BigInt::binary_encode(), and BOTAN_FFI_DO.

## ◆ botan_mp_to_hex()

int botan_mp_to_hex | ( | const botan_mp_t | mp,
|  | char * | out
| ) |  |

Convert the MPI to a hex string. Writes botan_mp_num_bytes(mp)*2 + 1 bytes

Definition at line 99 of file ffi_mp.cpp.

100 {
101 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
102 const std::string hex = bn.to_hex_string();
103 std::memcpy(out, hex.c_str(), 1 + hex.size());
104 });
105 }
Botan::BigInt::to_hex_string
std::string to_hex_string() const
Definition: big_code.cpp:42

References BOTAN_FFI_DO, and Botan::BigInt::to_hex_string().

## ◆ botan_mp_to_str()

int botan_mp_to_str | ( | const botan_mp_t | mp,
|  | uint8_t | base,
|  | char * | out,
|  | size_t * | out_len
| ) |  |

Convert the MPI to a string. Currently base == 10 and base == 16 are supported.

Definition at line 107 of file ffi_mp.cpp.

108 {
109 return BOTAN_FFI_RETURNING(Botan::BigInt, mp, bn, {
110
111 if(digit_base == 0 || digit_base == 10)
112 return write_str_output(out, out_len, bn.to_dec_string());
113 else if(digit_base == 16)
114 return write_str_output(out, out_len, bn.to_hex_string());
115 else
116 return BOTAN_FFI_ERROR_BAD_PARAMETER;
117 });
118 }
BOTAN_FFI_ERROR_BAD_PARAMETER
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition: ffi.h:78
Botan_FFI::write_str_output
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:160

References BOTAN_FFI_ERROR_BAD_PARAMETER, BOTAN_FFI_RETURNING, and Botan_FFI::write_str_output().

## ◆ botan_mp_to_uint32()

int botan_mp_to_uint32 | ( | const botan_mp_t | mp,
|  | uint32_t * | val
| ) |  |

Definition at line 125 of file ffi_mp.cpp.

126 {
127 if(val == nullptr)
128 {
129 return BOTAN_FFI_ERROR_NULL_POINTER;
130 }
131 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
132 }
Botan::BigInt::to_u32bit
uint32_t to_u32bit() const
Definition: bigint.cpp:252

References BOTAN_FFI_DO, BOTAN_FFI_ERROR_NULL_POINTER, and Botan::BigInt::to_u32bit().