Botan 2.19.3
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 }
#define BOTAN_FFI_DO(T, obj, param, block)
Definition ffi_util.h:92
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 }
void clear()
Definition bigint.h:366

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 }
void clear_bit(size_t n)
Definition bigint.cpp:270

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 }
int32_t cmp(const BigInt &n, bool check_signs=true) const
Definition bigint.cpp:130

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 }
#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, {
196 safe_get(remainder) = r;
197 });
198 }
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 }
#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 }
void flip_sign()
Definition bigint.h:554

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 }
void binary_decode(const uint8_t buf[], size_t length)
Definition bigint.cpp:432

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 }
BigInt gcd(const BigInt &a, const BigInt &b)
Definition numthry.cpp:81

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)
25
26 *mp_out = new botan_mp_struct(new Botan::BigInt);
27 return BOTAN_FFI_SUCCESS;
28 });
29 }
@ BOTAN_FFI_ERROR_NULL_POINTER
Definition ffi.h:77
@ BOTAN_FFI_SUCCESS
Definition ffi.h:63
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 }
bool is_even() const
Definition bigint.h:403

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 }
bool is_negative() const
Definition bigint.h:527

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 }
bool is_odd() const
Definition bigint.h:409

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 }
bool is_positive() const
Definition bigint.h:533

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 {
284 { return (Botan::is_prime(n, safe_get(rng), test_prob)) ? 1 : 0; });
285 }
bool is_prime(const BigInt &n, RandomNumberGenerator &rng, size_t prob, bool is_random)
Definition numthry.cpp:228

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 }
bool is_zero() const
Definition bigint.h:421

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 }
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 }

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 }
size_t bits() const
Definition bigint.cpp:296

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 }
size_t bytes() const
Definition bigint.cpp:281

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 }
BigInt power_mod(const BigInt &base, const BigInt &exp, const BigInt &mod)
Definition numthry.cpp:151

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 {
263 safe_get(rand_out).randomize(r, bits); });
264 }
virtual void randomize(uint8_t output[], size_t length)=0

References BOTAN_FFI_DO, Botan::RandomNumberGenerator::randomize(), 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 {
272 safe_get(rand_out) = Botan::BigInt::random_integer(r, safe_get(lower), safe_get(upper)); });
273 }
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 }
void set_bit(size_t n)
Definition bigint.h:430

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, {
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(bytes, len, base);
71 });
72 }
@ BOTAN_FFI_ERROR_NOT_IMPLEMENTED
Definition ffi.h:83
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 }
void swap(BigInt &other)
Definition bigint.h:161

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 }
void binary_encode(uint8_t buf[]) const
Definition bigint.cpp:399

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 }
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
117 });
118 }
@ BOTAN_FFI_ERROR_BAD_PARAMETER
Definition ffi.h:78
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 {
130 }
131 return BOTAN_FFI_DO(Botan::BigInt, mp, bn, { *val = bn.to_u32bit(); });
132 }
uint32_t to_u32bit() const
Definition bigint.cpp:244

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