Botan 2.19.1
Crypto and TLS for C&
|
#include <bigint.h>
Classes | |
class | DivideByZero |
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 | |
BigInt (const std::string &str) | |
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 (const uint8_t buf[], size_t length, size_t max_bits) | |
BigInt (const word words[], size_t length) | |
BigInt (RandomNumberGenerator &rng, size_t bits, bool set_high_bit=true) | |
Create a random BigInt of the specified size. More... | |
BigInt (Sign sign, size_t n) | |
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 |
size_t | encoded_size (Base base=Binary) 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) |
void | shrink_to_fit (size_t min_size=0) |
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) |
static void | const_time_lookup (secure_vector< word > &output, const std::vector< BigInt > &vec, size_t idx) |
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 std::vector< uint8_t > | encode (const BigInt &n, Base base) |
static void | encode (uint8_t buf[], const BigInt &n) |
static void | encode (uint8_t buf[], const BigInt &n, Base base) |
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 secure_vector< uint8_t > | encode_locked (const BigInt &n, Base base) |
static BigInt | power_of_2 (size_t n) |
static BigInt | random_integer (RandomNumberGenerator &rng, const BigInt &min, const BigInt &max) |
enum Botan::BigInt::Base |
enum Botan::BigInt::Sign |
|
default |
Create empty BigInt
Botan::BigInt::BigInt | ( | uint64_t | n | ) |
Create BigInt from 64 bit integer
n | initial value of this BigInt |
Definition at line 25 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 51 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 77 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 85 of file bigint.cpp.
References decode().
Botan::BigInt::BigInt | ( | const uint8_t | buf[], |
size_t | length, | ||
size_t | max_bits | ||
) |
Create a BigInt from an integer in a byte array
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 90 of file bigint.cpp.
References binary_decode().
Botan::BigInt::BigInt | ( | const word | words[], |
size_t | length | ||
) |
Create a BigInt from an array of words
words | the words |
length | number of words |
Definition at line 17 of file bigint.cpp.
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 104 of file bigint.cpp.
References bits(), and randomize().
Botan::BigInt::BigInt | ( | Sign | sign, |
size_t | n | ||
) |
Create BigInt of specified size, all zeros
sign | the sign |
n | size of the internal register in words |
Definition at line 42 of file bigint.cpp.
References size().
|
inline |
|
inline |
Definition at line 139 of file bigint.h.
BigInt Botan::BigInt::abs | ( | ) | const |
Definition at line 392 of file bigint.cpp.
References Positive, and set_sign().
Referenced by Botan::abs().
Definition at line 15 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 18 of file big_ops3.cpp.
References Botan::bigint_add3(), Botan::bigint_sub_abs(), data(), mutable_data(), Positive, set_sign(), sig_words(), and sign().
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 432 of file bigint.cpp.
References clear(), and Botan::round_up().
Referenced by BigInt(), botan_mp_from_bin(), decode(), 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 399 of file bigint.cpp.
References binary_encode(), and bytes().
Referenced by Botan::base58_decode(), binary_encode(), botan_mp_to_bin(), encode(), Botan::DER_Encoder::encode(), encode_1363(), encode_fixed_length_int_pair(), encode_locked(), and Botan::GOST_3410_PublicKey::public_key_bits().
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 407 of file bigint.cpp.
References Botan::get_byte(), Botan::store_be(), and word_at().
size_t Botan::BigInt::bits | ( | ) | const |
Get the bit length of the integer
Definition at line 296 of file bigint.cpp.
References sig_words(), and top_bits_free().
Referenced by BigInt(), botan_mp_num_bits(), bytes(), Botan::ct_divide(), Botan::ct_divide_u8(), Botan::ct_modulo(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_constrained_integer(), Botan::DL_Group::DL_Group(), Botan::DER_Encoder::encode(), encoded_size(), Botan::gcd(), Botan::generate_dsa_primes(), Botan::generate_rsa_prime(), Botan::generate_srp6_verifier(), Botan::inverse_mod(), Botan::is_lucas_probable_prime(), Botan::is_perfect_square(), Botan::is_prime(), Botan::TPM_PrivateKey::key_length(), Botan::monty_multi_exp(), Botan::PointGFp_Base_Point_Precompute::mul(), Botan::PointGFp_Var_Point_Precompute::mul(), Botan::PointGFp_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_group_identifier(), 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 109 of file bigint.cpp.
References Botan::get_byte(), 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 281 of file bigint.cpp.
References bits(), and Botan::round_up().
Referenced by Botan::base58_decode(), binary_encode(), botan_mp_num_bytes(), Botan::ECIES_KA_Operation::derive_secret(), encode(), Botan::DER_Encoder::encode(), Botan::PointGFp::encode(), encode_1363(), encode_fixed_length_int_pair(), encode_locked(), encoded_size(), Botan::EC_PrivateKey::private_key_bits(), Botan::GOST_3410_PublicKey::public_key_bits(), and Botan::SRP6_Server_Session::step1().
|
inline |
Zeroize the BigInt. The size of the underlying register is not modified.
Definition at line 366 of file bigint.h.
Referenced by Botan::PointGFp::add(), Botan::PointGFp::add_affine(), binary_decode(), botan_mp_clear(), 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 270 of file bigint.cpp.
References size(), and word_at().
Referenced by botan_mp_clear_bit().
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 130 of file bigint.cpp.
References Botan::bigint_cmp(), data(), is_negative(), is_positive(), and size().
Referenced by botan_mp_cmp(), 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 115 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 475 of file bigint.cpp.
References Botan::CT::Mask< T >::expand(), set_sign(), and sign().
Referenced by ct_cond_assign(), Botan::operator*(), and rev_sub().
void Botan::BigInt::conditionally_set_bit | ( | size_t | n, |
bool | set_it | ||
) |
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 260 of file bigint.cpp.
References word_at().
Referenced by Botan::ct_divide(), Botan::ct_divide_u8(), and Botan::ct_modulo().
|
static |
Set output = vec[idx].m_reg in constant time
All elements of vec must have the same size, and output must be pre-allocated with the same size.
Definition at line 523 of file bigint.cpp.
References BOTAN_ASSERT, Botan::clear_mem(), Botan::CT::Mask< T >::is_equal(), Botan::CT::poison(), size(), and Botan::CT::unpoison().
|
inline |
|
inline |
void Botan::BigInt::ct_cond_add | ( | bool | predicate, |
const BigInt & | value | ||
) |
If predicate is true add value to *this
Definition at line 455 of file bigint.cpp.
References Botan::bigint_cnd_add(), data(), grow_to(), is_negative(), mutable_data(), sig_words(), and size().
Referenced by Botan::gcd(), 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 488 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 466 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 366 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 620 of file bigint.h.
Referenced by Botan::PointGFp::add(), add(), add2(), Botan::PointGFp::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::mul_add(), 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 805 of file bigint.h.
Referenced by BigInt(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), decode(), 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_dh_agree().
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 146 of file big_code.cpp.
References Binary, binary_decode(), Botan::cast_uint8_ptr_to_char(), Botan::Charset::char2digit(), Decimal, Botan::hex_decode_locked(), Hexadecimal, Botan::Charset::is_digit(), and Botan::Charset::is_space().
|
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 770 of file bigint.h.
References binary_encode(), and bytes().
Referenced by Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::CRL_Entry::decode_from(), encode(), Botan::FPE_FE1::FPE_FE1(), Botan::TLS::Server_Key_Exchange::Server_Key_Exchange(), and to_hex_string().
Encode the integer value from a BigInt to a std::vector of bytes
n | the BigInt to use as integer source |
base | number-base of resulting byte array representation |
Deprecated. If you need Binary, call the version of encode that doesn't take a Base. If you need Hex or Decimal output, use to_hex_string or to_dec_string resp.
Definition at line 81 of file big_code.cpp.
References Binary, Decimal, encode(), Hexadecimal, to_dec_string(), and to_hex_string().
|
inlinestatic |
Encode the integer value from a BigInt to a byte array
buf | destination byte array for the encoded integer value with given base |
n | the BigInt to use as integer source |
base | number-base of resulting byte array representation |
Deprecated. If you need Binary, call binary_encode. If you need Hex or Decimal output, use to_hex_string or to_dec_string resp.
Definition at line 54 of file big_code.cpp.
References Botan::copy_mem(), and encode_locked().
|
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 111 of file big_code.cpp.
References binary_encode(), and bytes().
Referenced by Botan::PK_Verifier::check_signature(), Botan::EC_Group::DER_encode(), Botan::PointGFp::encode(), Botan::RFC6979_Nonce_Generator::nonce_for(), Botan::EC_PrivateKey::private_key_bits(), Botan::DH_PublicKey::public_value(), 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 122 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 133 of file big_code.cpp.
References binary_encode(), and bytes().
|
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 782 of file bigint.h.
References binary_encode(), and bytes().
Referenced by encode(), and encode_locked().
|
static |
Encode the integer value from a BigInt to a secure_vector of bytes
n | the BigInt to use as integer source |
base | number-base of resulting byte array representation |
Deprecated. If you need Binary, call the version of encode_locked that doesn't take a Base. If you need Hex or Decimal output, use to_hex_string or to_dec_string resp.
Definition at line 96 of file big_code.cpp.
References Binary, Decimal, encode_locked(), Hexadecimal, to_dec_string(), and to_hex_string().
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 176 of file bigint.cpp.
References Botan::clear_mem(), Botan::copy_mem(), data(), sig_words(), and size().
base | the base to measure the size for |
Deprecated. This is only needed when using the encode
and encode_locked
functions, which are also deprecated.
Definition at line 312 of file bigint.cpp.
References Binary, bits(), bytes(), Decimal, and Hexadecimal.
|
inline |
Flip the sign of this BigInt
Definition at line 554 of file bigint.h.
Referenced by botan_mp_flip_sign(), Botan::ct_divide_u8(), Botan::BER_Decoder::decode(), Botan::is_lucas_probable_prime(), and operator-().
|
inline |
Return bit value at specified position
n | the bit offset to test |
Definition at line 465 of file bigint.h.
Referenced by Botan::ct_divide(), Botan::ct_divide_u8(), Botan::ct_modulo(), Botan::PointGFp::encode(), Botan::is_lucas_probable_prime(), 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 213 of file bigint.cpp.
References word_at().
Referenced by Botan::monty_multi_exp(), Botan::PointGFp_Base_Point_Precompute::mul(), Botan::PointGFp_Var_Point_Precompute::mul(), and Botan::PointGFp_Multi_Point_Precompute::multi_exp().
|
inline |
|
inline |
|
inline |
Increase internal register buffer to at least n words
n | new size of register |
Definition at line 636 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(), and Botan::vartime_divide().
bool Botan::BigInt::is_equal | ( | const BigInt & | n | ) | const |
Compare this to another BigInt
n | the BigInt value to compare with |
Definition at line 149 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 403 of file bigint.h.
Referenced by Botan::almost_montgomery_inverse(), botan_mp_is_even(), Botan::gcd(), Botan::generate_rsa_prime(), Botan::inverse_mod(), Botan::is_lucas_probable_prime(), Botan::is_prime(), Botan::jacobi(), Botan::Montgomery_Params::Montgomery_Params(), Botan::random_prime(), and Botan::ressol().
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 158 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 527 of file bigint.h.
Referenced by botan_mp_is_negative(), cmp(), cmp_word(), ct_cond_add(), Botan::ct_divide_u8(), Botan::ct_modulo(), ct_reduce_below(), Botan::BER_Decoder::decode(), Botan::inverse_mod(), is_less_than(), Botan::is_lucas_probable_prime(), mod_add(), mod_mul(), mod_sub(), Botan::Montgomery_Params::Montgomery_Params(), Botan::monty_multi_exp(), Botan::PointGFp_Base_Point_Precompute::mul(), Botan::PointGFp_Var_Point_Precompute::mul(), Botan::mul_add(), Botan::mul_sub(), Botan::PointGFp_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(), Botan::Power_Mod::set_base(), Botan::Power_Mod::set_exponent(), Botan::sub_mul(), to_u32bit(), and Botan::vartime_divide().
|
inline |
Test if the integer is not zero
Definition at line 415 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 409 of file bigint.h.
Referenced by botan_mp_is_odd(), Botan::gcd(), Botan::inverse_mod(), Botan::is_lucas_probable_prime(), Botan::normalized_montgomery_inverse(), Botan::power_mod(), and Botan::Power_Mod::set_modulus().
|
inline |
Tests if the sign of the integer is positive
Definition at line 533 of file bigint.h.
Referenced by botan_mp_is_positive(), cmp(), is_less_than(), and Botan::operator%().
|
inline |
Test if the integer is zero
Definition at line 421 of file bigint.h.
Referenced by Botan::PointGFp::add(), Botan::PointGFp::add_affine(), botan_mp_is_zero(), Botan::ct_modulo(), Botan::DH_PrivateKey::DH_PrivateKey(), Botan::ElGamal_PrivateKey::ElGamal_PrivateKey(), Botan::gcd(), Botan::inverse_mod(), Botan::Montgomery_Int::is_zero(), Botan::jacobi(), Botan::mul_sub(), Botan::PointGFp::mult2(), Botan::PointGFp::mult2i(), Botan::operator%(), Botan::operator>>(), operator>>=(), Botan::DL_Group::PEM_for_named_group(), Botan::power_mod(), Botan::random_prime(), Botan::RSA_PrivateKey::RSA_PrivateKey(), 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 455 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 50 of file big_ops2.cpp.
References Botan::bigint_add3_nc(), Botan::bigint_sub3(), BOTAN_ARG_CHECK, BOTAN_DEBUG_ASSERT, Botan::CT::conditional_copy_mem(), data(), grow_to(), is_negative(), set_words(), and sig_words().
Referenced by Botan::Montgomery_Int::add(), Botan::PointGFp::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 120 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::PointGFp::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 93 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::PointGFp::add(), Botan::PointGFp::add_affine(), Botan::PointGFp::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 159 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 614 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::mul_add(), 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().
|
inline |
Modulo operator
y | the modulus to reduce this by |
Definition at line 243 of file big_ops2.cpp.
word Botan::BigInt::operator%= | ( | word | y | ) |
Modulo operator
y | the modulus (word) to reduce this by |
Definition at line 251 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 153 of file big_ops2.cpp.
References mul().
BigInt & Botan::BigInt::operator*= | ( | word | y | ) |
*= operator
y | the word to multiply with this |
Definition at line 214 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 177 of file bigint.h.
References data(), sig_words(), and sign().
|
inline |
BigInt Botan::BigInt::operator- | ( | ) | const |
Unary negation operator
Definition at line 329 of file bigint.cpp.
References flip_sign().
|
inline |
|
inline |
|
inline |
/= operator
y | the BigInt to divide this by |
Definition at line 231 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 281 of file big_ops2.cpp.
References Botan::bigint_shl1(), 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 301 of file big_ops2.cpp.
References Botan::bigint_shr1(), is_negative(), is_zero(), Positive, and set_sign().
|
inlinestatic |
Create a power of two
n | the power of two to create |
Definition at line 758 of file bigint.h.
References set_bit().
Referenced by Botan::inverse_mod(), Botan::is_perfect_square(), Botan::Montgomery_Params::Montgomery_Params(), and Botan::ressol().
|
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 45 of file big_rand.cpp.
References bits(), is_negative(), and randomize().
Referenced by botan_mp_rand_range(), Botan::DSA_PrivateKey::DSA_PrivateKey(), Botan::is_miller_rabin_probable_prime(), Botan::EC_Group::random_scalar(), and Botan::PointGFp::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 17 of file big_rand.cpp.
References binary_decode(), clear(), Positive, Botan::RandomNumberGenerator::random_vec(), Botan::round_up(), and set_sign().
Referenced by BigInt(), Botan::DH_PrivateKey::DH_PrivateKey(), Botan::ElGamal_PrivateKey::ElGamal_PrivateKey(), 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 336 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 647 of file bigint.h.
Referenced by Botan::PointGFp::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 132 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_mp_set_bit(), 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 563 of file bigint.h.
Referenced by abs(), add(), add2(), BigInt(), cond_flip_sign(), Botan::gcd(), Botan::inverse_mod(), mul(), operator%=(), Botan::operator*(), operator*=(), Botan::operator>>(), operator>>=(), randomize(), Botan::Modular_Reducer::reduce(), square(), to_dec_string(), and Botan::vartime_divide().
|
inline |
Definition at line 513 of file bigint.h.
Referenced by ct_cond_assign(), mul(), and operator*=().
|
inline |
Definition at line 518 of file bigint.h.
Referenced by Botan::PointGFp::add(), Botan::PointGFp::add_affine(), and mod_add().
|
inline |
|
inline |
Return how many words we need to hold this value
Definition at line 586 of file bigint.h.
Referenced by add(), add2(), bits(), cmp_word(), ct_cond_add(), Botan::ct_divide(), Botan::ct_divide_u8(), 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::mul_add(), 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 539 of file bigint.h.
Referenced by add(), add2(), cond_flip_sign(), ct_cond_assign(), is_equal(), mul(), Botan::mul_add(), 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 580 of file bigint.h.
Referenced by Botan::PointGFp::add(), add(), Botan::PointGFp::add_affine(), BigInt(), clear_bit(), cmp(), const_time_lookup(), 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::mul_add(), 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(), and Botan::Montgomery_Params::square_this().
BigInt & Botan::BigInt::square | ( | secure_vector< word > & | ws | ) |
Square value of *this
ws | a temp workspace |
Definition at line 197 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 161 of file bigint.h.
Referenced by Botan::PointGFp::add_affine(), botan_mp_swap(), Botan::PointGFp::mult2(), Botan::PointGFp::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
Definition at line 15 of file big_code.cpp.
References Botan::ct_divide_u8(), Botan::Charset::digit2char(), Positive, and set_sign().
Referenced by encode(), encode_locked(), and Botan::operator<<().
std::string Botan::BigInt::to_hex_string | ( | ) | const |
Convert this value to a hexadecimal string.
Definition at line 42 of file big_code.cpp.
References bits(), encode(), and Botan::hex_encode().
Referenced by botan_mp_to_hex(), encode(), encode_locked(), and 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 244 of file bigint.cpp.
References bits(), byte_at(), and is_negative().
Referenced by botan_mp_to_uint32().
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 286 of file bigint.cpp.
References Botan::high_bit(), sig_words(), Botan::CT::unpoison(), and word_at().
Referenced by bits(), operator<<=(), and Botan::vartime_divide().
|
inline |
Return the word at a specified position of the internal register
n | position in the register |
Definition at line 508 of file bigint.h.
Referenced by binary_encode(), byte_at(), clear_bit(), conditionally_set_bit(), ct_cond_assign(), 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().