Botan 3.1.1
Crypto and TLS for C&
|
#include <bigint.h>
Public Types | |
enum | Base { Decimal = 10 , Hexadecimal = 16 , Binary = 256 } |
enum | Sign { Negative = 0 , Positive = 1 } |
Public Member Functions | |
BigInt | abs () const |
BigInt & | add (const word y[], size_t y_words, Sign sign) |
BigInt ()=default | |
BigInt (BigInt &&other) | |
BigInt (const BigInt &other)=default | |
template<typename Alloc > | |
BigInt (const std::vector< uint8_t, Alloc > &vec) | |
BigInt (const uint8_t buf[], size_t length) | |
BigInt (const uint8_t buf[], size_t length, Base base) | |
BigInt (RandomNumberGenerator &rng, size_t bits, bool set_high_bit=true) | |
Create a random BigInt of the specified size. | |
BigInt (std::string_view str) | |
BigInt (uint64_t n) | |
template<typename Alloc > | |
void | binary_decode (const std::vector< uint8_t, Alloc > &buf) |
void | binary_decode (const uint8_t buf[], size_t length) |
void | binary_encode (uint8_t buf[]) const |
void | binary_encode (uint8_t buf[], size_t len) const |
size_t | bits () const |
uint8_t | byte_at (size_t n) const |
size_t | bytes () const |
void | clear () |
void | clear_bit (size_t n) |
int32_t | cmp (const BigInt &n, bool check_signs=true) const |
int32_t | cmp_word (word n) const |
void | cond_flip_sign (bool predicate) |
void | conditionally_set_bit (size_t n, bool set_it) |
void | const_time_poison () const |
void | const_time_unpoison () const |
void | ct_cond_add (bool predicate, const BigInt &value) |
void | ct_cond_assign (bool predicate, const BigInt &other) |
void | ct_cond_swap (bool predicate, BigInt &other) |
void | ct_reduce_below (const BigInt &mod, secure_vector< word > &ws, size_t bound) |
const word * | data () const |
void | encode_words (word out[], size_t size) const |
void | flip_sign () |
bool | get_bit (size_t n) const |
uint32_t | get_substring (size_t offset, size_t length) const |
secure_vector< word > & | get_word_vector () |
const secure_vector< word > & | get_word_vector () const |
void | grow_to (size_t n) const |
bool | is_equal (const BigInt &n) const |
bool | is_even () const |
bool | is_less_than (const BigInt &n) const |
bool | is_negative () const |
bool | is_nonzero () const |
bool | is_odd () const |
bool | is_positive () const |
bool | is_zero () const |
void | mask_bits (size_t n) |
BigInt & | mod_add (const BigInt &y, const BigInt &mod, secure_vector< word > &ws) |
BigInt & | mod_mul (uint8_t y, const BigInt &mod, secure_vector< word > &ws) |
BigInt & | mod_sub (const BigInt &y, const BigInt &mod, secure_vector< word > &ws) |
BigInt & | mul (const BigInt &y, secure_vector< word > &ws) |
word * | mutable_data () |
bool | operator! () const |
BigInt & | operator%= (const BigInt &y) |
word | operator%= (word y) |
BigInt & | operator*= (const BigInt &y) |
BigInt & | operator*= (word y) |
BigInt & | operator++ () |
BigInt | operator++ (int) |
BigInt & | operator+= (const BigInt &y) |
BigInt & | operator+= (word y) |
BigInt | operator- () const |
BigInt & | operator-- () |
BigInt | operator-- (int) |
BigInt & | operator-= (const BigInt &y) |
BigInt & | operator-= (word y) |
BigInt & | operator/= (const BigInt &y) |
BigInt & | operator<<= (size_t shift) |
BigInt & | operator= (BigInt &&other) |
BigInt & | operator= (const BigInt &)=default |
BigInt & | operator>>= (size_t shift) |
void | randomize (RandomNumberGenerator &rng, size_t bitsize, bool set_high_bit=true) |
size_t | reduce_below (const BigInt &mod, secure_vector< word > &ws) |
void | resize (size_t s) |
BigInt & | rev_sub (const word y[], size_t y_words, secure_vector< word > &ws) |
Sign | reverse_sign () const |
void | set_bit (size_t n) |
void | set_sign (Sign sign) |
void | set_word_at (size_t i, word w) |
void | set_words (const word w[], size_t len) |
size_t | sig_words () const |
Sign | sign () const |
size_t | size () const |
BigInt & | square (secure_vector< word > &ws) |
BigInt & | sub (const word y[], size_t y_words, Sign sign) |
void | swap (BigInt &other) |
void | swap_reg (secure_vector< word > ®) |
std::string | to_dec_string () const |
std::string | to_hex_string () const |
uint32_t | to_u32bit () const |
size_t | top_bits_free () const |
word | word_at (size_t n) const |
~BigInt () | |
Static Public Member Functions | |
static BigInt | add2 (const BigInt &x, const word y[], size_t y_words, Sign y_sign) |
template<typename Alloc > | |
static BigInt | decode (const std::vector< uint8_t, Alloc > &buf) |
template<typename Alloc > | |
static BigInt | decode (const std::vector< uint8_t, Alloc > &buf, Base base) |
static BigInt | decode (const uint8_t buf[], size_t length) |
static BigInt | decode (const uint8_t buf[], size_t length, Base base) |
static std::vector< uint8_t > | encode (const BigInt &n) |
static secure_vector< uint8_t > | encode_1363 (const BigInt &n, size_t bytes) |
static void | encode_1363 (uint8_t out[], size_t bytes, const BigInt &n) |
static secure_vector< uint8_t > | encode_fixed_length_int_pair (const BigInt &n1, const BigInt &n2, size_t bytes) |
static secure_vector< uint8_t > | encode_locked (const BigInt &n) |
static BigInt | from_bytes_with_max_bits (const uint8_t buf[], size_t length, size_t max_bits) |
static BigInt | from_s32 (int32_t n) |
static BigInt | from_u64 (uint64_t n) |
static BigInt | from_word (word n) |
static BigInt | one () |
static BigInt | power_of_2 (size_t n) |
static BigInt | random_integer (RandomNumberGenerator &rng, const BigInt &min, const BigInt &max) |
static BigInt | with_capacity (size_t n) |
static BigInt | zero () |
enum Botan::BigInt::Base |
enum Botan::BigInt::Sign |
|
default |
Create empty (zero) BigInt
Botan::BigInt::BigInt | ( | uint64_t | n | ) |
Create BigInt from an unsigned 64 bit integer
n | initial value of this BigInt |
Definition at line 18 of file bigint.cpp.
|
default |
Copy Constructor
other | the BigInt to copy |
|
explicit |
Create BigInt from a string. If the string starts with 0x the rest of the string will be interpreted as hexadecimal digits. Otherwise, it will be interpreted as a decimal number.
str | the string to parse for an integer value |
Definition at line 67 of file bigint.cpp.
References Botan::cast_char_ptr_to_uint8(), Decimal, decode(), Hexadecimal, Negative, Positive, and set_sign().
Botan::BigInt::BigInt | ( | const uint8_t | buf[], |
size_t | length | ||
) |
Create a BigInt from an integer in a byte array
buf | the byte array holding the value |
length | size of buf |
Definition at line 91 of file bigint.cpp.
References binary_decode().
|
inlineexplicit |
Botan::BigInt::BigInt | ( | const uint8_t | buf[], |
size_t | length, | ||
Base | base | ||
) |
Create a BigInt from an integer in a byte array
buf | the byte array holding the value |
length | size of buf |
base | is the number base of the integer in buf |
Definition at line 98 of file bigint.cpp.
References decode().
Botan::BigInt::BigInt | ( | RandomNumberGenerator & | rng, |
size_t | bits, | ||
bool | set_high_bit = true |
||
) |
Create a random BigInt of the specified size.
rng | random number generator |
bits | size in bits |
set_high_bit | if true, the highest bit is always set |
Definition at line 121 of file bigint.cpp.
References bits(), and randomize().
|
inline |
|
inline |
Definition at line 147 of file bigint.h.
BigInt Botan::BigInt::abs | ( | ) | const |
Definition at line 369 of file bigint.cpp.
References Positive, and set_sign().
Referenced by Botan::abs().
Definition at line 16 of file big_ops2.cpp.
References Botan::bigint_add2(), Botan::bigint_cmp(), Botan::bigint_sub2(), Botan::bigint_sub2_rev(), data(), grow_to(), mutable_data(), Positive, set_sign(), sig_words(), sign(), and size().
Referenced by Botan::Modular_Reducer::reduce().
|
static |
Definition at line 19 of file big_ops3.cpp.
References Botan::bigint_add3(), Botan::bigint_sub_abs(), data(), mutable_data(), Positive, set_sign(), sig_words(), sign(), and with_capacity().
Referenced by Botan::operator+(), and Botan::operator-().
|
inline |
Read integer value from a byte vector
buf | the vector to load from |
void Botan::BigInt::binary_decode | ( | const uint8_t | buf[], |
size_t | length | ||
) |
Read integer value from a byte array with given size
buf | byte array buffer containing the integer |
length | size of buf |
Definition at line 403 of file bigint.cpp.
References clear(), and Botan::round_up().
Referenced by BigInt(), decode(), from_bytes_with_max_bits(), Botan::generate_dsa_primes(), Botan::RFC6979_Nonce_Generator::nonce_for(), and randomize().
void Botan::BigInt::binary_encode | ( | uint8_t | buf[] | ) | const |
Store BigInt-value in a given byte array
buf | destination byte array for the integer value |
Definition at line 375 of file bigint.cpp.
References binary_encode(), and bytes().
Referenced by Botan::base58_decode(), binary_encode(), encode(), Botan::DER_Encoder::encode(), encode_1363(), encode_fixed_length_int_pair(), encode_locked(), Botan::GOST_3410_PublicKey::public_key_bits(), and to_hex_string().
void Botan::BigInt::binary_encode | ( | uint8_t | buf[], |
size_t | len | ||
) | const |
Store BigInt-value in a given byte array. If len is less than the size of the value, then it will be truncated. If len is greater than the size of the value, it will be zero-padded. If len exactly equals this->bytes(), this function behaves identically to binary_encode.
buf | destination byte array for the integer value |
len | how many bytes to write |
Definition at line 382 of file bigint.cpp.
References Botan::get_byte_var(), Botan::store_be(), and word_at().
size_t Botan::BigInt::bits | ( | ) | const |
Get the bit length of the integer
Definition at line 290 of file bigint.cpp.
References BOTAN_MP_WORD_BITS, sig_words(), and top_bits_free().
Referenced by BigInt(), bytes(), Botan::ct_divide(), Botan::ct_divide_word(), Botan::ct_modulo(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_constrained_integer(), Botan::DL_Group::DL_Group(), Botan::EC_Point_Base_Point_Precompute::EC_Point_Base_Point_Precompute(), Botan::EC_Point_Var_Point_Precompute::EC_Point_Var_Point_Precompute(), Botan::DER_Encoder::encode(), Botan::gcd(), Botan::generate_dsa_primes(), Botan::generate_rsa_prime(), Botan::inverse_mod(), Botan::is_perfect_square(), Botan::is_prime(), Botan::TPM_PrivateKey::key_length(), Botan::monty_multi_exp(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::EC_Point_Multi_Point_Precompute::multi_exp(), Botan::operator*(), operator/=(), Botan::passes_miller_rabin_test(), Botan::DL_Group::power_g_p(), Botan::power_mod(), random_integer(), Botan::random_prime(), Botan::RSA_PrivateKey::RSA_PrivateKey(), Botan::srp6_client_agree(), Botan::srp6_group_identifier(), to_dec_string(), to_hex_string(), and to_u32bit().
uint8_t Botan::BigInt::byte_at | ( | size_t | n | ) | const |
n | the offset to get a byte from |
Definition at line 125 of file bigint.cpp.
References Botan::get_byte_var(), and word_at().
Referenced by Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_constrained_integer(), and to_u32bit().
size_t Botan::BigInt::bytes | ( | ) | const |
Give byte length of the integer
Definition at line 277 of file bigint.cpp.
References bits(), and Botan::round_up().
Referenced by Botan::base58_decode(), binary_encode(), Botan::ECIES_KA_Operation::derive_secret(), encode(), Botan::DER_Encoder::encode(), Botan::EC_Point::encode(), encode_1363(), encode_fixed_length_int_pair(), encode_locked(), Botan::EC_PrivateKey::private_key_bits(), Botan::GOST_3410_PublicKey::public_key_bits(), and to_hex_string().
|
inline |
Zeroize the BigInt. The size of the underlying register is not modified.
Definition at line 366 of file bigint.h.
Referenced by Botan::EC_Point::add(), Botan::EC_Point::add_affine(), binary_decode(), Botan::BER_Decoder::decode(), mul(), operator*=(), and randomize().
void Botan::BigInt::clear_bit | ( | size_t | n | ) |
Clear bit at specified position
n | bit position to clear |
Definition at line 268 of file bigint.cpp.
References BOTAN_MP_WORD_BITS, size(), and word_at().
int32_t Botan::BigInt::cmp | ( | const BigInt & | n, |
bool | check_signs = true |
||
) | const |
Compare this to another BigInt
n | the BigInt value to compare with |
check_signs | include sign in comparison? |
Definition at line 145 of file bigint.cpp.
References Botan::bigint_cmp(), data(), is_negative(), is_positive(), and size().
Referenced by Botan::operator<=(), and Botan::operator>=().
int32_t Botan::BigInt::cmp_word | ( | word | n | ) | const |
Compare this to an integer
n | the value to compare with |
Definition at line 129 of file bigint.cpp.
References Botan::bigint_cmp(), data(), is_negative(), and sig_words().
Referenced by Botan::operator!=(), Botan::operator<(), Botan::operator<=(), Botan::operator==(), Botan::operator>(), and Botan::operator>=().
void Botan::BigInt::cond_flip_sign | ( | bool | predicate | ) |
If predicate is true flip the sign of *this
Definition at line 441 of file bigint.cpp.
References Botan::CT::Mask< T >::expand(), set_sign(), and sign().
Referenced by ct_cond_assign(), Botan::operator*(), and rev_sub().
|
inline |
Conditionally set bit at specified position. Note if set_it is false, nothing happens, and if the bit is already set, it remains set.
n | bit position to set |
set_it | if the bit should be set |
Definition at line 440 of file bigint.h.
References BOTAN_MP_WORD_BITS.
Referenced by Botan::ct_divide(), Botan::ct_divide_word(), and Botan::ct_modulo().
|
inline |
|
inline |
void Botan::BigInt::ct_cond_add | ( | bool | predicate, |
const BigInt & | value | ||
) |
If predicate is true add value to *this
Definition at line 424 of file bigint.cpp.
References Botan::bigint_cnd_add(), data(), grow_to(), is_negative(), mutable_data(), sig_words(), and size().
Referenced by Botan::gcd(), Botan::inverse_mod(), and Botan::is_lucas_probable_prime().
void Botan::BigInt::ct_cond_assign | ( | bool | predicate, |
const BigInt & | other | ||
) |
If predicate is true assign other to *this Uses a masked operation to avoid side channels
Definition at line 453 of file bigint.cpp.
References cond_flip_sign(), Botan::CT::Mask< T >::expand(), grow_to(), set_word_at(), sign(), size(), and word_at().
Referenced by Botan::inverse_mod(), Botan::is_lucas_probable_prime(), and Botan::power_mod().
void Botan::BigInt::ct_cond_swap | ( | bool | predicate, |
BigInt & | other | ||
) |
If predicate is true swap *this and other Uses a masked operation to avoid side channels
Definition at line 433 of file bigint.cpp.
References Botan::bigint_cnd_swap(), grow_to(), mutable_data(), and size().
Referenced by Botan::ct_divide(), Botan::ct_modulo(), and Botan::gcd().
void Botan::BigInt::ct_reduce_below | ( | const BigInt & | mod, |
secure_vector< word > & | ws, | ||
size_t | bound | ||
) |
Return *this % mod
Assumes that *this is (if anything) only slightly larger than mod and performs repeated subtractions. It should not be used if *this is much larger than mod, instead use modulo operator.
Performs exactly bound subtractions, so if *this is >= bound*mod then the result will not be fully reduced. If bound is zero, nothing happens.
Definition at line 344 of file bigint.cpp.
References Botan::bigint_sub3(), Botan::clear_mem(), data(), grow_to(), is_negative(), Botan::CT::Mask< T >::is_zero(), mutable_data(), sig_words(), and size().
Referenced by Botan::Modular_Reducer::reduce().
|
inline |
Return a const pointer to the register
Definition at line 609 of file bigint.h.
Referenced by Botan::EC_Point::add(), add(), add2(), Botan::EC_Point::add_affine(), cmp(), cmp_word(), ct_cond_add(), Botan::ct_divide(), Botan::ct_modulo(), ct_reduce_below(), Botan::CurveGFp_Repr::curve_mul(), Botan::CurveGFp_Repr::curve_sqr(), encode_words(), is_equal(), is_less_than(), mod_add(), mod_sub(), Botan::Montgomery_Params::mul(), mul(), Botan::Montgomery_Params::mul_by(), Botan::operator*(), Botan::operator+(), operator+=(), Botan::operator-(), operator-=(), Botan::operator<<(), Botan::operator>>(), Botan::Montgomery_Params::redc(), Botan::redc_p521(), Botan::Modular_Reducer::reduce(), reduce_below(), rev_sub(), Botan::Montgomery_Params::sqr(), square(), and Botan::Montgomery_Params::square_this().
|
inlinestatic |
|
inlinestatic |
|
inlinestatic |
Create a BigInt from an integer in a byte array
buf | the binary value to load |
length | size of buf |
Definition at line 760 of file bigint.h.
Referenced by BigInt(), botan_srp6_client_agree(), botan_srp6_server_session_step1(), botan_srp6_server_session_step2(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::BER_Decoder::decode_octet_string_bigint(), Botan::CRL_Entry::encode_into(), Botan::TPM_PrivateKey::get_e(), Botan::TPM_PrivateKey::get_n(), Botan::OCSP::CertID::is_id_for(), Botan::OS2ECP(), and Botan::TLS::Callbacks::tls_ephemeral_key_agreement().
Create a BigInt from an integer in a byte array
buf | the binary value to load |
length | size of buf |
base | number-base of the integer in buf |
Definition at line 143 of file big_code.cpp.
References Binary, binary_decode(), BOTAN_ASSERT_NOMSG, Botan::cast_uint8_ptr_to_char(), Decimal, Botan::hex_decode_locked(), and Hexadecimal.
|
inlinestatic |
Encode the integer value from a BigInt to a std::vector of bytes
n | the BigInt to use as integer source |
Definition at line 737 of file bigint.h.
References binary_encode(), and bytes().
Referenced by botan_srp6_client_agree(), botan_srp6_generate_verifier(), botan_srp6_server_session_step1(), Botan::CRL_Entry::decode_from(), Botan::FPE_FE1::FPE_FE1(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().
|
static |
Encode a BigInt to a byte array according to IEEE 1363
n | the BigInt to encode |
bytes | the length of the resulting secure_vector<uint8_t> |
Definition at line 105 of file big_code.cpp.
References binary_encode(), and bytes().
Referenced by Botan::EC_Group::DER_encode(), Botan::EC_Point::encode(), Botan::RFC6979_Nonce_Generator::nonce_for(), Botan::EC_PrivateKey::private_key_bits(), Botan::DL_PublicKey::public_key_as_bytes(), Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator(), Botan::Montgomery_Int::serialize(), Botan::sm2_compute_za(), Botan::srp6_client_agree(), and Botan::SRP6_Server_Session::step2().
|
static |
Definition at line 116 of file big_code.cpp.
References binary_encode(), and bytes().
|
static |
Encode two BigInt to a byte array according to IEEE 1363
n1 | the first BigInt to encode |
n2 | the second BigInt to encode |
bytes | the length of the encoding of each single BigInt |
Definition at line 127 of file big_code.cpp.
References binary_encode(), bytes(), and is_negative().
|
inlinestatic |
Encode the integer value from a BigInt to a secure_vector of bytes
n | the BigInt to use as integer source |
Definition at line 748 of file bigint.h.
References binary_encode(), and bytes().
Referenced by Botan::DL_PrivateKey::raw_private_key_bits(), and Botan::EC_PrivateKey::raw_private_key_bits().
void Botan::BigInt::encode_words | ( | word | out[], |
size_t | size | ||
) | const |
Place the value into out, zero-padding up to size words Throw if *this cannot be represented in size words
Definition at line 187 of file bigint.cpp.
References Botan::clear_mem(), Botan::copy_mem(), data(), sig_words(), and size().
|
inline |
Flip the sign of this BigInt
Definition at line 550 of file bigint.h.
Referenced by Botan::ct_divide_word(), Botan::BER_Decoder::decode(), Botan::is_lucas_probable_prime(), and operator-().
|
static |
Create a BigInt from an integer in a byte array
Note this function is primarily used for implementing signature schemes and is not useful in typical applications.
buf | the byte array holding the value |
length | size of buf |
max_bits | if the resulting integer is more than max_bits, it will be shifted so it is at most max_bits in length. |
Definition at line 103 of file bigint.cpp.
References binary_decode().
|
static |
Create BigInt from a signed 32 bit integer
n | initial value of this BigInt |
Definition at line 49 of file bigint.cpp.
References from_u64().
Referenced by botan_mp_set_from_int(), and Botan::sqrt_modulo_prime().
|
static |
Create BigInt from an unsigned 64 bit integer
n | initial value of this BigInt |
Definition at line 28 of file bigint.cpp.
References set_word_at().
Referenced by Botan::DER_Encoder::encode(), from_s32(), and Botan::RSA_PrivateKey::RSA_PrivateKey().
|
static |
Create BigInt from a word (limb)
n | initial value of this BigInt |
Definition at line 42 of file bigint.cpp.
References set_word_at().
Referenced by Botan::DL_Group::DL_Group(), Botan::is_bailie_psw_probable_prime(), Botan::is_lucas_probable_prime(), Botan::is_miller_rabin_probable_prime(), Botan::operator%(), Botan::random_prime(), Botan::sqrt_modulo_prime(), and Botan::DL_Group::verify_group().
|
inline |
Return bit value at specified position
n | the bit offset to test |
Definition at line 463 of file bigint.h.
References BOTAN_MP_WORD_BITS.
Referenced by Botan::ct_divide(), Botan::ct_divide_word(), Botan::ct_modulo(), Botan::EC_Point::encode(), Botan::inverse_mod(), Botan::operator*(), and Botan::power_mod().
uint32_t Botan::BigInt::get_substring | ( | size_t | offset, |
size_t | length | ||
) | const |
Return (a maximum of) 32 bits of the complete value
offset | the offset to start extracting |
length | amount of bits to extract (starting at offset) |
Definition at line 222 of file bigint.cpp.
References BOTAN_MP_WORD_BITS, and word_at().
Referenced by Botan::monty_multi_exp(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), and Botan::EC_Point_Multi_Point_Precompute::multi_exp().
|
inline |
Don't use this function in application code
Definition at line 614 of file bigint.h.
Referenced by Botan::EC_Point_Var_Point_Precompute::EC_Point_Var_Point_Precompute().
|
inline |
|
inline |
Increase internal register buffer to at least n words
n | new size of register |
Definition at line 625 of file bigint.h.
Referenced by add(), ct_cond_add(), ct_cond_assign(), ct_cond_swap(), ct_reduce_below(), Botan::Montgomery_Int::fix_size(), mod_add(), mod_sub(), mul(), Botan::Montgomery_Params::mul_by(), Botan::Montgomery_Params::redc(), Botan::redc_p192(), Botan::redc_p224(), Botan::redc_p256(), Botan::redc_p384(), Botan::redc_p521(), reduce_below(), Botan::Montgomery_Params::square_this(), Botan::vartime_divide(), and with_capacity().
bool Botan::BigInt::is_equal | ( | const BigInt & | n | ) | const |
Compare this to another BigInt
n | the BigInt value to compare with |
Definition at line 163 of file bigint.cpp.
References Botan::bigint_ct_is_eq(), data(), sig_words(), and sign().
Referenced by Botan::operator!=().
|
inline |
Test if the integer has an even value
Definition at line 406 of file bigint.h.
Referenced by Botan::gcd(), Botan::generate_rsa_prime(), Botan::inverse_mod(), Botan::is_bailie_psw_probable_prime(), Botan::is_lucas_probable_prime(), Botan::is_miller_rabin_probable_prime(), Botan::is_prime(), Botan::jacobi(), Botan::Montgomery_Params::Montgomery_Params(), Botan::passes_miller_rabin_test(), and Botan::random_prime().
bool Botan::BigInt::is_less_than | ( | const BigInt & | n | ) | const |
Compare this to another BigInt
n | the BigInt value to compare with |
Definition at line 171 of file bigint.cpp.
References Botan::bigint_ct_is_lt(), data(), is_negative(), is_positive(), and sig_words().
Referenced by Botan::operator<(), and Botan::operator>().
|
inline |
Tests if the sign of the integer is negative
Definition at line 524 of file bigint.h.
Referenced by cmp(), cmp_word(), ct_cond_add(), Botan::ct_divide_word(), Botan::ct_modulo(), ct_reduce_below(), Botan::BER_Decoder::decode(), encode_fixed_length_int_pair(), Botan::inverse_mod(), is_less_than(), Botan::is_lucas_probable_prime(), mod_add(), mod_mul(), mod_sub(), Botan::monty_multi_exp(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::EC_Point_Multi_Point_Precompute::multi_exp(), Botan::operator%(), Botan::operator*(), Botan::operator>>(), operator>>=(), Botan::power_mod(), random_integer(), Botan::random_prime(), Botan::Modular_Reducer::reduce(), reduce_below(), to_dec_string(), to_hex_string(), to_u32bit(), and Botan::vartime_divide().
|
inline |
Test if the integer is not zero
Definition at line 418 of file bigint.h.
Referenced by Botan::ct_modulo(), Botan::inverse_mod(), and Botan::Modular_Reducer::reduce().
|
inline |
Test if the integer has an odd value
Definition at line 412 of file bigint.h.
Referenced by Botan::gcd(), Botan::inverse_mod(), Botan::is_lucas_probable_prime(), Botan::power_mod(), and Botan::sqrt_modulo_prime().
|
inline |
Tests if the sign of the integer is positive
Definition at line 530 of file bigint.h.
Referenced by cmp(), is_less_than(), Botan::operator%(), Botan::redc_p192(), Botan::redc_p224(), Botan::redc_p256(), Botan::redc_p384(), and Botan::redc_p521().
|
inline |
Test if the integer is zero
Definition at line 424 of file bigint.h.
Referenced by Botan::EC_Point::add(), Botan::EC_Point::add_affine(), Botan::ct_divide(), Botan::ct_modulo(), Botan::gcd(), Botan::inverse_mod(), Botan::Montgomery_Int::is_zero(), Botan::jacobi(), Botan::EC_Point::mult2(), Botan::EC_Point::mult2i(), Botan::operator%(), Botan::operator>>(), operator>>=(), Botan::power_mod(), Botan::random_prime(), Botan::RSA_PrivateKey::RSA_PrivateKey(), to_dec_string(), Botan::vartime_divide(), and Botan::DL_Group::verify_public_element().
|
inline |
Clear all but the lowest n bits
n | amount of bits to keep |
Definition at line 456 of file bigint.h.
Referenced by Botan::inverse_mod(), Botan::redc_p192(), Botan::redc_p224(), Botan::redc_p256(), Botan::redc_p384(), Botan::redc_p521(), and Botan::Modular_Reducer::reduce().
BigInt & Botan::BigInt::mod_add | ( | const BigInt & | y, |
const BigInt & | mod, | ||
secure_vector< word > & | ws | ||
) |
Set *this to (*this + y) % mod This function assumes *this is >= 0 && < mod
y | the BigInt to add - assumed y >= 0 and y < mod |
mod | the positive modulus |
ws | a temp workspace |
Definition at line 45 of file big_ops2.cpp.
References Botan::bigint_add3_nc(), Botan::bigint_sub3(), BOTAN_ARG_CHECK, BOTAN_DEBUG_ASSERT, BOTAN_UNUSED, Botan::CT::conditional_copy_mem(), data(), grow_to(), is_negative(), set_words(), and sig_words().
Referenced by Botan::Montgomery_Int::add(), Botan::EC_Point::mult2(), and Botan::Montgomery_Int::operator+().
BigInt & Botan::BigInt::mod_mul | ( | uint8_t | y, |
const BigInt & | mod, | ||
secure_vector< word > & | ws | ||
) |
Set *this to (*this * y) % mod This function assumes *this is >= 0 && < mod y should be small, less than 16
y | the small integer to multiply by |
mod | the positive modulus |
ws | a temp workspace |
Definition at line 119 of file big_ops2.cpp.
References BOTAN_ARG_CHECK, BOTAN_DEBUG_ASSERT, is_negative(), and reduce_below().
Referenced by Botan::Montgomery_Int::mul_by_2(), Botan::Montgomery_Int::mul_by_3(), Botan::Montgomery_Int::mul_by_4(), Botan::Montgomery_Int::mul_by_8(), and Botan::EC_Point::mult2().
BigInt & Botan::BigInt::mod_sub | ( | const BigInt & | y, |
const BigInt & | mod, | ||
secure_vector< word > & | ws | ||
) |
Set *this to (*this - y) % mod This function assumes *this is >= 0 && < mod
y | the BigInt to subtract - assumed y >= 0 and y < mod |
mod | the positive modulus |
ws | a temp workspace |
Definition at line 90 of file big_ops2.cpp.
References Botan::bigint_mod_sub(), BOTAN_DEBUG_ASSERT, data(), grow_to(), is_negative(), mutable_data(), and sig_words().
Referenced by Botan::EC_Point::add(), Botan::EC_Point::add_affine(), Botan::EC_Point::mult2(), Botan::Montgomery_Int::operator-(), and Botan::Montgomery_Int::sub().
BigInt & Botan::BigInt::mul | ( | const BigInt & | y, |
secure_vector< word > & | ws | ||
) |
Multiply this with y
y | the BigInt to multiply with this |
ws | a temp workspace |
Definition at line 156 of file big_ops2.cpp.
References Botan::bigint_linmul2(), Botan::bigint_linmul3(), Botan::bigint_mul(), Botan::carry(), clear(), data(), grow_to(), mutable_data(), Negative, Positive, set_sign(), set_word_at(), sig_words(), sign(), size(), swap_reg(), and word_at().
Referenced by operator*=(), and Botan::Modular_Reducer::reduce().
|
inline |
Return a mutable pointer to the register
Definition at line 603 of file bigint.h.
Referenced by add(), add2(), ct_cond_add(), ct_cond_swap(), Botan::ct_divide(), Botan::ct_modulo(), ct_reduce_below(), mod_sub(), Botan::Montgomery_Params::mul(), mul(), Botan::Montgomery_Params::mul_by(), Botan::operator*(), operator*=(), Botan::operator<<(), Botan::operator>>(), Botan::Montgomery_Params::redc(), Botan::redc_p192(), Botan::redc_p224(), Botan::redc_p256(), Botan::redc_p384(), Botan::redc_p521(), Botan::Montgomery_Params::sqr(), Botan::Montgomery_Params::square_this(), and Botan::vartime_divide().
|
inlinestatic |
Create a 1-value BigInt
Definition at line 49 of file bigint.h.
Referenced by Botan::gcd(), Botan::is_lucas_probable_prime(), Botan::is_perfect_square(), Botan::power_mod(), and Botan::EC_Group::random_scalar().
|
inline |
Modulo operator
y | the modulus to reduce this by |
Definition at line 224 of file big_ops2.cpp.
word Botan::BigInt::operator%= | ( | word | y | ) |
Modulo operator
y | the modulus (word) to reduce this by |
Definition at line 231 of file big_ops2.cpp.
References Botan::bigint_modop(), Botan::is_power_of_2(), Negative, Positive, set_sign(), sig_words(), sign(), and word_at().
*= operator
y | the BigInt to multiply with this |
Definition at line 151 of file big_ops2.cpp.
References mul().
BigInt & Botan::BigInt::operator*= | ( | word | y | ) |
*= operator
y | the word to multiply with this |
Definition at line 197 of file big_ops2.cpp.
References Botan::bigint_linmul2(), Botan::carry(), clear(), mutable_data(), Positive, set_sign(), set_word_at(), and size().
|
inline |
|
inline |
+= operator
y | the BigInt to add to this |
Definition at line 182 of file bigint.h.
References data(), sig_words(), and sign().
|
inline |
BigInt Botan::BigInt::operator- | ( | ) | const |
Unary negation operator
Definition at line 306 of file bigint.cpp.
References flip_sign().
|
inline |
|
inline |
|
inline |
/= operator
y | the BigInt to divide this by |
Definition at line 212 of file big_ops2.cpp.
References bits(), Botan::is_power_of_2(), sig_words(), and word_at().
BigInt & Botan::BigInt::operator<<= | ( | size_t | shift | ) |
Left shift operator
shift | the number of bits to shift this left by |
Definition at line 260 of file big_ops2.cpp.
References Botan::bigint_shl1(), BOTAN_MP_WORD_BITS, sig_words(), size(), and top_bits_free().
BigInt & Botan::BigInt::operator>>= | ( | size_t | shift | ) |
Right shift operator
shift | the number of bits to shift this right by |
Definition at line 279 of file big_ops2.cpp.
References Botan::bigint_shr1(), BOTAN_MP_WORD_BITS, is_negative(), is_zero(), Positive, and set_sign().
|
inlinestatic |
Create a power of two
n | the power of two to create |
Definition at line 726 of file bigint.h.
References set_bit().
Referenced by Botan::inverse_mod(), Botan::is_perfect_square(), Botan::Montgomery_Params::Montgomery_Params(), and Botan::sqrt_modulo_prime().
|
static |
rng | a random number generator |
min | the minimum value (must be non-negative) |
max | the maximum value (must be non-negative and > min) |
Definition at line 43 of file big_rand.cpp.
References bits(), BOTAN_DEBUG_ASSERT, is_negative(), random_integer(), randomize(), and zero().
Referenced by botan_mp_rand_range(), Botan::is_miller_rabin_probable_prime(), random_integer(), Botan::EC_Group::random_scalar(), and Botan::EC_Point::randomize_repr().
void Botan::BigInt::randomize | ( | RandomNumberGenerator & | rng, |
size_t | bitsize, | ||
bool | set_high_bit = true |
||
) |
Fill BigInt with a random number with size of bitsize
If set_high_bit
is true, the highest bit will be set, which causes the entropy to be bits-1. Otherwise the highest bit is randomly chosen by the rng, causing the entropy to be bits.
rng | the random number generator to use |
bitsize | number of bits the created random value should have |
set_high_bit | if true, the highest bit is always set |
Definition at line 18 of file big_rand.cpp.
References binary_decode(), clear(), Positive, Botan::RandomNumberGenerator::random_vec(), Botan::round_up(), and set_sign().
Referenced by BigInt(), Botan::EC_Point_Var_Point_Precompute::EC_Point_Var_Point_Precompute(), and random_integer().
size_t Botan::BigInt::reduce_below | ( | const BigInt & | mod, |
secure_vector< word > & | ws | ||
) |
Return *this % mod
Assumes that *this is (if anything) only slightly larger than mod and performs repeated subtractions. It should not be used if *this is much larger than mod, instead use modulo operator.
Definition at line 312 of file bigint.cpp.
References Botan::bigint_sub3(), Botan::clear_mem(), data(), grow_to(), is_negative(), sig_words(), size(), and swap_reg().
Referenced by mod_mul(), and Botan::vartime_divide().
|
inline |
Definition at line 627 of file bigint.h.
Referenced by Botan::EC_Point::force_all_affine().
BigInt & Botan::BigInt::rev_sub | ( | const word | y[], |
size_t | y_words, | ||
secure_vector< word > & | ws | ||
) |
Set *this to y - *this
y | the BigInt to subtract from as a sequence of words |
y_words | length of y in words |
ws | a temp workspace |
Definition at line 130 of file big_ops2.cpp.
References Botan::bigint_sub_abs(), Botan::clear_mem(), cond_flip_sign(), data(), Positive, sig_words(), sign(), and swap_reg().
Referenced by Botan::Modular_Reducer::reduce().
|
inline |
|
inline |
Set bit at specified position
n | bit position to set |
Definition at line 430 of file bigint.h.
Referenced by Botan::EC_Point_Var_Point_Precompute::EC_Point_Var_Point_Precompute(), Botan::generate_dsa_primes(), Botan::generate_rsa_prime(), Botan::Modular_Reducer::Modular_Reducer(), power_of_2(), and Botan::random_prime().
|
inline |
Set sign of the integer
sign | new Sign to set |
Definition at line 556 of file bigint.h.
Referenced by abs(), add(), add2(), BigInt(), cond_flip_sign(), Botan::gcd(), Botan::inverse_mod(), Botan::lcm(), mul(), operator%=(), Botan::operator*(), operator*=(), Botan::operator<<(), Botan::operator>>(), operator>>=(), randomize(), Botan::Modular_Reducer::reduce(), square(), to_dec_string(), and Botan::vartime_divide().
|
inline |
Definition at line 516 of file bigint.h.
Referenced by ct_cond_assign(), from_u64(), from_word(), mul(), and operator*=().
|
inline |
Definition at line 518 of file bigint.h.
Referenced by Botan::EC_Point::add(), Botan::EC_Point::add_affine(), mod_add(), and Botan::Montgomery_Int::Montgomery_Int().
|
inline |
Return how many words we need to hold this value
Definition at line 578 of file bigint.h.
Referenced by add(), add2(), bits(), cmp_word(), ct_cond_add(), Botan::ct_divide(), Botan::ct_divide_word(), Botan::ct_modulo(), ct_reduce_below(), Botan::CurveGFp_Repr::curve_mul(), Botan::CurveGFp_Repr::curve_sqr(), encode_words(), Botan::Montgomery_Int::fix_size(), is_equal(), is_less_than(), mod_add(), mod_sub(), Botan::Modular_Reducer::Modular_Reducer(), Botan::Montgomery_Params::Montgomery_Params(), Botan::Montgomery_Params::mul(), mul(), Botan::Montgomery_Params::mul_by(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator+(), operator+=(), Botan::operator-(), operator-=(), Botan::operator/(), operator/=(), Botan::operator<<(), operator<<=(), Botan::operator>>(), Botan::Modular_Reducer::reduce(), reduce_below(), rev_sub(), Botan::Montgomery_Params::sqr(), square(), Botan::Montgomery_Params::square_this(), top_bits_free(), and Botan::vartime_divide().
|
inline |
Return the sign of the integer
Definition at line 536 of file bigint.h.
Referenced by add(), add2(), cond_flip_sign(), ct_cond_assign(), is_equal(), mul(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator+(), operator+=(), operator-=(), Botan::operator<<(), Botan::operator>>(), and rev_sub().
|
inline |
Give size of internal register
Definition at line 572 of file bigint.h.
Referenced by Botan::EC_Point::add(), add(), Botan::EC_Point::add_affine(), clear_bit(), cmp(), ct_cond_add(), ct_cond_assign(), ct_cond_swap(), Botan::ct_divide(), Botan::ct_modulo(), ct_reduce_below(), Botan::CurveGFp_Repr::curve_mul(), Botan::CurveGFp_Repr::curve_sqr(), encode_words(), Botan::low_zero_bits(), Botan::Montgomery_Params::mul(), mul(), Botan::Montgomery_Params::mul_by(), Botan::operator*(), operator*=(), operator<<=(), Botan::redc_p192(), Botan::redc_p224(), Botan::redc_p256(), Botan::redc_p384(), Botan::redc_p521(), Botan::Modular_Reducer::reduce(), reduce_below(), Botan::Montgomery_Params::sqr(), square(), Botan::Montgomery_Params::square_this(), and with_capacity().
BigInt & Botan::BigInt::square | ( | secure_vector< word > & | ws | ) |
Square value of *this
ws | a temp workspace |
Definition at line 183 of file big_ops2.cpp.
References Botan::bigint_sqr(), data(), Positive, set_sign(), sig_words(), size(), and swap_reg().
Referenced by Botan::square().
|
inline |
Swap this value with another
other | BigInt to swap values with |
Definition at line 168 of file bigint.h.
Referenced by Botan::EC_Point::add_affine(), Botan::EC_Point::mult2(), Botan::EC_Point::swap(), and std::swap< Botan::BigInt >().
|
inline |
std::string Botan::BigInt::to_dec_string | ( | ) | const |
Convert this value to a decimal string. Warning: decimal conversions are relatively slow
If the integer is zero then "0" is returned. If the integer is negative then "-" is prefixed.
Definition at line 15 of file big_code.cpp.
References bits(), BOTAN_ASSERT_NOMSG, Botan::ct_divide_word(), is_negative(), is_zero(), Positive, and set_sign().
Referenced by Botan::operator<<().
std::string Botan::BigInt::to_hex_string | ( | ) | const |
Convert this value to a hexadecimal string.
If the integer is negative then "-" is prefixed. Then a prefix of "0x" is added. Follows is a sequence of hexadecimal characters in uppercase.
The number of hexadecimal characters is always an even number, with a zero prefix being included if necessary. For example encoding the integer "5" results in "0x05"
Definition at line 85 of file big_code.cpp.
References binary_encode(), bits(), bytes(), Botan::hex_encode(), and is_negative().
Referenced by Botan::operator<<().
uint32_t Botan::BigInt::to_u32bit | ( | ) | const |
Convert this value into a uint32_t, if it is in the range [0 ... 2**32-1], or otherwise throw an exception.
Definition at line 250 of file bigint.cpp.
References bits(), byte_at(), and is_negative().
size_t Botan::BigInt::top_bits_free | ( | ) | const |
Get the number of high bits unset in the top (allocated) word of this integer. Returns BOTAN_MP_WORD_BITS only iff *this is zero. Ignores sign.
Definition at line 281 of file bigint.cpp.
References BOTAN_MP_WORD_BITS, Botan::high_bit(), sig_words(), Botan::CT::unpoison(), and word_at().
Referenced by bits(), operator<<=(), and Botan::vartime_divide().
|
static |
Create BigInt of specified size, all zeros
n | size of the internal register in words |
Definition at line 58 of file bigint.cpp.
References grow_to(), and size().
Referenced by add2(), Botan::ct_divide(), Botan::ct_divide_word(), Botan::ct_modulo(), Botan::Montgomery_Params::mul(), Botan::operator*(), Botan::operator<<(), Botan::operator>>(), and Botan::Montgomery_Params::sqr().
|
inline |
Return the word at a specified position of the internal register
n | position in the register |
Definition at line 514 of file bigint.h.
Referenced by binary_encode(), byte_at(), clear_bit(), ct_cond_assign(), Botan::EC_Group::EC_group_identity_from_order(), get_substring(), Botan::is_prime(), Botan::low_zero_bits(), Botan::Montgomery_Params::Montgomery_Params(), mul(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator/(), operator/=(), Botan::redc_p521(), top_bits_free(), and Botan::vartime_divide().
|
inlinestatic |
Create a 0-value BigInt
Definition at line 44 of file bigint.h.
Referenced by Botan::EC_Group::blinded_base_point_multiply_x(), Botan::DL_Group::DL_Group(), Botan::inverse_mod(), Botan::is_perfect_square(), Botan::operator>>(), Botan::power_mod(), random_integer(), Botan::random_safe_prime(), and Botan::vartime_divide().