Botan  2.4.0
Crypto and TLS for C++11
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_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_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 143 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

144  {
145  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) + safe_get(y); });
146  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_clear()

int botan_mp_clear ( botan_mp_t  mp)

Definition at line 31 of file ffi_mp.cpp.

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

32  {
33  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.clear(); });
34  }
void clear()
Definition: bigint.h:222
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_clear_bit()

int botan_mp_clear_bit ( botan_mp_t  n,
size_t  bit 
)

Clear the specified bit

Definition at line 266 of file ffi_mp.cpp.

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

267  {
268  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.clear_bit(bit); });
269  }
void clear_bit(size_t n)
Definition: bigint.cpp:167
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_cmp()

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

Definition at line 189 of file ffi_mp.cpp.

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

190  {
191  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { *result = x.cmp(safe_get(y_w)); });
192  }
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition: bigint.cpp:97
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_destroy()

int botan_mp_destroy ( botan_mp_t  mp)

Definition at line 138 of file ffi_mp.cpp.

References BOTAN_FFI_CHECKED_DELETE.

139  {
140  return BOTAN_FFI_CHECKED_DELETE(mp);
141  }
#define BOTAN_FFI_CHECKED_DELETE(o)
Definition: ffi_util.h:126

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

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

161  {
162  return BOTAN_FFI_DO(Botan::BigInt, quotient, q, {
163  Botan::BigInt r;
164  Botan::divide(safe_get(x), safe_get(y), q, r);
165  safe_get(remainder) = r;
166  });
167  }
void divide(const BigInt &x, const BigInt &y_arg, BigInt &q, BigInt &r)
Definition: divide.cpp:58
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_equal()

int botan_mp_equal ( const botan_mp_t  x_w,
const botan_mp_t  y_w 
)

Definition at line 169 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

170  {
171  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { return x == safe_get(y_w); });
172  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_flip_sign()

int botan_mp_flip_sign ( botan_mp_t  mp)

Definition at line 89 of file ffi_mp.cpp.

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

90  {
91  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.flip_sign(); });
92  }
void flip_sign()
Definition: bigint.cpp:225
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ 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.

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

95  {
96  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_decode(bin, bin_len); });
97  }
void binary_decode(const uint8_t buf[], size_t length)
Definition: bigint.cpp:279
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_gcd()

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

Definition at line 244 of file ffi_mp.cpp.

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

245  {
246  return BOTAN_FFI_DO(Botan::BigInt, out, o, {
247  o = Botan::gcd(safe_get(x), safe_get(y)); });
248  }
BigInt gcd(const BigInt &a, const BigInt &b)
Definition: numthry.cpp:47
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

References BOTAN_FFI_DO.

257  {
258  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { return (n.get_bit(bit)); });
259  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_init()

int botan_mp_init ( botan_mp_t mp_out)

Definition at line 20 of file ffi_mp.cpp.

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

21  {
22  return ffi_guard_thunk(BOTAN_CURRENT_FUNCTION, [=]() -> int {
23  if(mp_out == nullptr)
25 
26  *mp_out = new botan_mp_struct(new Botan::BigInt);
27  return BOTAN_FFI_SUCCESS;
28  });
29  }
#define BOTAN_FFI_SUCCESS
Definition: ffi.h:137
int ffi_guard_thunk(const char *func_name, Thunk thunk)
Definition: ffi_util.h:64
#define BOTAN_CURRENT_FUNCTION
Definition: compiler.h:143
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147

◆ botan_mp_is_even()

int botan_mp_is_even ( const botan_mp_t  mp)

Definition at line 184 of file ffi_mp.cpp.

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

185  {
186  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_even(); });
187  }
bool is_even() const
Definition: bigint.h:237
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ 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.

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

80  {
81  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_negative() ? 1 : 0; });
82  }
bool is_negative() const
Definition: bigint.h:353
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_odd()

int botan_mp_is_odd ( const botan_mp_t  mp)

Definition at line 179 of file ffi_mp.cpp.

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

180  {
181  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_odd(); });
182  }
bool is_odd() const
Definition: bigint.h:243
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_positive()

int botan_mp_is_positive ( const botan_mp_t  mp)

This function is not well named. 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.

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

85  {
86  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_positive() ? 1 : 0; });
87  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
bool is_positive() const
Definition: bigint.h:359

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

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

251  {
252  return BOTAN_FFI_DO(Botan::BigInt, mp, n,
253  { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
254  }
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition: numthry.cpp:455
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_is_zero()

int botan_mp_is_zero ( const botan_mp_t  mp)

Definition at line 174 of file ffi_mp.cpp.

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

175  {
176  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { return bn.is_zero(); });
177  }
bool is_zero() const
Definition: bigint.h:255
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_lshift()

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

Definition at line 206 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

207  {
208  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) << shift; });
209  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

217  {
218  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = Botan::inverse_mod(safe_get(in), safe_get(modulus)); });
219  }
BigInt inverse_mod(const BigInt &n, const BigInt &mod)
Definition: numthry.cpp:277
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

222  {
223  return BOTAN_FFI_DO(Botan::BigInt, out, o, {
224  Botan::Modular_Reducer reducer(safe_get(modulus));
225  o = reducer.multiply(safe_get(x), safe_get(y));
226  });
227  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_mul()

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

Definition at line 153 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

154  {
155  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) * safe_get(y); });
156  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_num_bits()

int botan_mp_num_bits ( const botan_mp_t  mp,
size_t *  bits 
)

Definition at line 271 of file ffi_mp.cpp.

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

272  {
273  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bits = n.bits(); });
274  }
size_t bits() const
Definition: bigint.cpp:183
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_num_bytes()

int botan_mp_num_bytes ( const botan_mp_t  mp,
size_t *  bytes 
)

Definition at line 276 of file ffi_mp.cpp.

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

277  {
278  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { *bytes = n.bytes(); });
279  }
size_t bytes() const
Definition: bigint.cpp:175
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

201  {
202  return BOTAN_FFI_DO(Botan::BigInt, out, o,
203  { o = Botan::power_mod(safe_get(base), safe_get(exponent), safe_get(modulus)); });
204  }
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition: numthry.cpp:374
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_rand_bits()

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

Definition at line 229 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

230  {
232  safe_get(rand_out).randomize(r, bits); });
233  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

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

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

239  {
241  safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
242  }
static BigInt random_integer(RandomNumberGenerator &rng, const BigInt &min, const BigInt &max)
Definition: big_rand.cpp:45
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_rshift()

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

Definition at line 211 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

212  {
213  return BOTAN_FFI_DO(Botan::BigInt, out, o, { o = safe_get(in) >> shift; });
214  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_bit()

int botan_mp_set_bit ( botan_mp_t  n,
size_t  bit 
)

Set the specified bit

Definition at line 261 of file ffi_mp.cpp.

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

262  {
263  return BOTAN_FFI_DO(Botan::BigInt, mp, n, { n.set_bit(bit); });
264  }
void set_bit(size_t n)
Definition: bigint.cpp:156
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_from_int()

int botan_mp_set_from_int ( botan_mp_t  mp,
int  initial_value 
)

Definition at line 36 of file ffi_mp.cpp.

References BOTAN_FFI_DO.

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  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_from_mp()

int botan_mp_set_from_mp ( botan_mp_t  dest,
const botan_mp_t  source 
)

Definition at line 74 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

75  {
76  return BOTAN_FFI_DO(Botan::BigInt, dest, bn, { bn = safe_get(source); });
77  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_set_from_radix_str()

int botan_mp_set_from_radix_str ( botan_mp_t  mp,
const char *  str,
size_t  radix 
)

Definition at line 56 of file ffi_mp.cpp.

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

57  {
58  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
60  if(radix == 10)
62  else if(radix == 16)
64  else
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::decode(bytes, len, base);
71  });
72  }
const uint8_t * cast_char_ptr_to_uint8(const char *s)
Definition: mem_ops.h:120
#define BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition: ffi.h:149
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98
static BigInt decode(const uint8_t buf[], size_t length, Base base=Binary)
Definition: big_code.cpp:114

◆ botan_mp_set_from_str()

int botan_mp_set_from_str ( botan_mp_t  mp,
const char *  str 
)

Definition at line 51 of file ffi_mp.cpp.

References BOTAN_FFI_DO.

52  {
53  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn = Botan::BigInt(str); });
54  }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_sub()

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

Definition at line 148 of file ffi_mp.cpp.

References BOTAN_FFI_DO, and Botan_FFI::safe_get().

149  {
150  return BOTAN_FFI_DO(Botan::BigInt, result, res, { res = safe_get(x) - safe_get(y); });
151  }
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_swap()

int botan_mp_swap ( botan_mp_t  x_w,
botan_mp_t  y_w 
)

Definition at line 194 of file ffi_mp.cpp.

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

195  {
196  return BOTAN_FFI_DO(Botan::BigInt, x_w, x, { x.swap(safe_get(y_w)); });
197  }
void swap(BigInt &other)
Definition: bigint.h:127
T & safe_get(botan_struct< T, M > *p)
Definition: ffi_util.h:49
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_bin()

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

Definition at line 125 of file ffi_mp.cpp.

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

126  {
127  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { bn.binary_encode(vec); });
128  }
void binary_encode(uint8_t buf[]) const
Definition: bigint.cpp:269
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_hex()

int botan_mp_to_hex ( const botan_mp_t  mp,
char *  out 
)

Definition at line 99 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan::BigInt::encode(), and Botan::BigInt::Hexadecimal.

100  {
101  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
102  std::vector<uint8_t> hex = Botan::BigInt::encode(bn, Botan::BigInt::Hexadecimal);
103  std::memcpy(out, hex.data(), hex.size());
104  out[hex.size()] = 0; // null terminate
105  });
106  }
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_str()

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

Definition at line 108 of file ffi_mp.cpp.

References BOTAN_FFI_DO, Botan::BigInt::Decimal, Botan::BigInt::encode(), Botan::BigInt::Hexadecimal, and Botan_FFI::write_str_output().

109  {
110  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, {
111  Botan::BigInt::Base base;
112  if(digit_base == 0 || digit_base == 10)
113  base = Botan::BigInt::Decimal;
114  else if(digit_base == 16)
116  else
117  throw FFI_Error("botan_mp_to_str invalid digit base");
118 
119  std::vector<uint8_t> hex = Botan::BigInt::encode(bn, base);
120  hex.push_back(0); // null terminator
121  return write_str_output(out, out_len, hex);
122  });
123  }
int write_str_output(uint8_t out[], size_t *out_len, const std::string &str)
Definition: ffi_util.h:151
static std::vector< uint8_t > encode(const BigInt &n, Base base=Binary)
Definition: big_code.cpp:54
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98

◆ botan_mp_to_uint32()

int botan_mp_to_uint32 ( const botan_mp_t  mp,
uint32_t *  val 
)

Definition at line 130 of file ffi_mp.cpp.

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

131  {
132  if(val == nullptr) {
134  }
135  return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
136  }
uint32_t to_u32bit() const
Definition: bigint.cpp:140
#define BOTAN_FFI_ERROR_NULL_POINTER
Definition: ffi.h:147
#define BOTAN_FFI_DO(T, obj, param, block)
Definition: ffi_util.h:98