Botan
2.6.0
Crypto and TLS for C++11
|
#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 ()=default | |
BigInt (uint64_t n) | |
BigInt (const BigInt &other) | |
BigInt (const std::string &str) | |
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 (BigInt &&other) | |
void | binary_decode (const uint8_t buf[], size_t length) |
void | binary_decode (const secure_vector< uint8_t > &buf) |
void | binary_encode (uint8_t buf[]) 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 |
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) |
bool | is_even () 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 & | 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- () const |
BigInt & | operator-- () |
BigInt | operator-- (int) |
BigInt & | operator-= (const BigInt &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) |
void | reduce_below (const BigInt &mod, secure_vector< word > &ws) |
BigInt & | rev_sub (const word y[], size_t y_size, 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 | 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) |
void | swap (BigInt &other) |
void | swap_reg (secure_vector< word > ®) |
uint32_t | to_u32bit () const |
word | word_at (size_t n) const |
Static Public Member Functions | |
static void | const_time_lookup (secure_vector< word > &output, const std::vector< BigInt > &vec, size_t idx) |
static BigInt | decode (const uint8_t buf[], size_t length, Base base=Binary) |
static BigInt | decode (const secure_vector< uint8_t > &buf, Base base=Binary) |
static BigInt | decode (const std::vector< uint8_t > &buf, Base base=Binary) |
static std::vector< uint8_t > | encode (const BigInt &n, Base base=Binary) |
static void | encode (uint8_t buf[], const BigInt &n, Base base=Binary) |
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, Base base=Binary) |
static BigInt | power_of_2 (size_t n) |
static BigInt | random_integer (RandomNumberGenerator &rng, const BigInt &min, const BigInt &max) |
enum Botan::BigInt::Base |
Base enumerator for encoding and decoding
Enumerator | |
---|---|
Decimal | |
Hexadecimal | |
Binary |
enum Botan::BigInt::Sign |
Sign symbol definitions for positive and negative numbers
Enumerator | |
---|---|
Negative | |
Positive |
Definition at line 36 of file bigint.h.
|
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 24 of file bigint.cpp.
References Botan::MP_WORD_MASK.
Botan::BigInt::BigInt | ( | const BigInt & | other | ) |
|
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 57 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 83 of file bigint.cpp.
References binary_decode().
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 91 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 96 of file bigint.cpp.
References bits(), and 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 16 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 111 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 39 of file bigint.cpp.
References Botan::round_up(), and size().
|
inline |
BigInt Botan::BigInt::abs | ( | ) | const |
Definition at line 283 of file bigint.cpp.
References Positive, and set_sign().
Referenced by Botan::abs().
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 314 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().
|
inline |
Read integer value from a byte array (secure_vector<uint8_t>)
buf | the array to load from |
Definition at line 551 of file bigint.h.
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 304 of file bigint.cpp.
References byte_at(), and bytes().
Referenced by botan_mp_to_bin(), encode(), and Botan::GOST_3410_PublicKey::public_key_bits().
size_t Botan::BigInt::bits | ( | ) | const |
Get the bit length of the integer
Definition at line 216 of file bigint.cpp.
References Botan::high_bit(), sig_words(), and word_at().
Referenced by BigInt(), botan_mp_num_bits(), bytes(), Botan::ct_inverse_mod_odd_modulus(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_constrained_integer(), Botan::DL_Group::DL_Group(), Botan::DER_Encoder::encode(), encoded_size(), Botan::Fixed_Window_Exponentiator::execute(), Botan::generate_dsa_primes(), Botan::is_prime(), Botan::RSA_PublicKey::key_length(), 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*(), Botan::operator/(), operator/=(), Botan::operator>>(), random_integer(), Botan::random_prime(), Botan::RSA_PrivateKey::RSA_PrivateKey(), Botan::Fixed_Window_Exponentiator::set_base(), Botan::Montgomery_Exponentiator::set_base(), Botan::srp6_group_identifier(), and to_u32bit().
|
inline |
n | the offset to get a byte from |
Definition at line 388 of file bigint.h.
References Botan::get_byte().
Referenced by binary_encode(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_constrained_integer(), get_substring(), and to_u32bit().
size_t Botan::BigInt::bytes | ( | ) | const |
Give byte length of the integer
Definition at line 208 of file bigint.cpp.
References bits(), and Botan::round_up().
Referenced by binary_encode(), botan_mp_num_bytes(), Botan::ECIES_KA_Operation::derive_secret(), Botan::DER_Encoder::encode(), Botan::PointGFp::encode(), encode_1363(), encode_fixed_length_int_pair(), 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 281 of file bigint.h.
References Botan::zeroise().
Referenced by binary_decode(), botan_mp_clear(), mul(), operator%=(), operator*=(), operator-=(), and randomize().
void Botan::BigInt::clear_bit | ( | size_t | n | ) |
Clear bit at specified position
n | bit position to clear |
Definition at line 200 of file bigint.cpp.
References size().
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 119 of file bigint.cpp.
References Botan::bigint_cmp(), data(), is_negative(), is_positive(), and sig_words().
Referenced by botan_mp_cmp(), Botan::divide(), Botan::operator!=(), Botan::operator<(), Botan::operator<=(), Botan::operator>(), Botan::operator>=(), and Botan::Modular_Reducer::reduce().
|
static |
Set output = vec[idx].m_reg in constant time All words of vec must have the same size
Definition at line 338 of file bigint.cpp.
References BOTAN_ASSERT, Botan::clear_mem(), Botan::CT::is_equal(), Botan::CT::poison(), size(), Botan::CT::unpoison(), and word_at().
|
inline |
Return a const pointer to the register
Definition at line 504 of file bigint.h.
Referenced by Botan::PointGFp::add_affine(), cmp(), Botan::ct_inverse_mod_odd_modulus(), encode_words(), 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().
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 114 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().
Referenced by BigInt(), botan_mp_set_from_radix_str(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), decode(), Botan::BER_Decoder::decode_octet_string_bigint(), Botan::CRL_Entry::encode_into(), Botan::OCSP::CertID::is_id_for(), Botan::OS2ECP(), and Botan::TLS::Callbacks::tls_dh_agree().
|
inlinestatic |
Create a BigInt from an integer in a byte array
buf | the binary value to load |
base | number-base of the integer in buf |
Definition at line 632 of file bigint.h.
References decode().
|
inlinestatic |
Create a BigInt from an integer in a byte array
buf | the binary value to load |
base | number-base of the integer in buf |
Definition at line 644 of file bigint.h.
References decode().
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 |
Definition at line 54 of file big_code.cpp.
References Binary, and encoded_size().
Referenced by botan_mp_to_hex(), botan_mp_to_str(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), Botan::CRL_Entry::decode_from(), Botan::ECIES_KA_Operation::derive_secret(), Botan::DER_Encoder::encode(), encode_1363(), encode_locked(), Botan::FPE_FE1::FPE_FE1(), Botan::operator<<(), and Botan::TLS::Server_Key_Exchange::Server_Key_Exchange().
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 |
Definition at line 18 of file big_code.cpp.
References Binary, binary_encode(), Botan::cast_uint8_ptr_to_char(), Decimal, Botan::Charset::digit2char(), Botan::divide(), encoded_size(), Botan::hex_encode(), Hexadecimal, is_zero(), Positive, set_sign(), and word_at().
|
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 82 of file big_code.cpp.
References bytes().
Referenced by Botan::PK_Verifier::check_signature(), Botan::EC_Group::DER_encode(), Botan::PointGFp::encode(), encode_fixed_length_int_pair(), 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 90 of file big_code.cpp.
References Binary, bytes(), and encode().
|
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 103 of file big_code.cpp.
References bytes(), and encode_1363().
|
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 |
Definition at line 68 of file big_code.cpp.
References Binary, encode(), and encoded_size().
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 138 of file bigint.cpp.
References Botan::clear_mem(), Botan::copy_mem(), data(), sig_words(), and size().
base | the base to measure the size for |
Definition at line 230 of file bigint.cpp.
References Binary, bits(), bytes(), Decimal, and Hexadecimal.
Referenced by encode(), and encode_locked().
|
inline |
Flip the sign of this BigInt
Definition at line 440 of file bigint.h.
Referenced by botan_mp_flip_sign(), Botan::BER_Decoder::decode(), operator-(), and rev_sub().
|
inline |
Return bit value at specified position
n | the bit offset to test |
Definition at line 363 of file bigint.h.
Referenced by Botan::PointGFp::encode(), and Botan::operator*().
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 152 of file bigint.cpp.
References byte_at(), and Botan::ASN1::to_string().
Referenced by Botan::Fixed_Window_Exponentiator::execute(), 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 |
Definition at line 506 of file bigint.h.
Referenced by Botan::PointGFp::add(), Botan::ct_inverse_mod_odd_modulus(), Botan::Montgomery_Int::fix_size(), and Botan::PointGFp::mult2().
|
inline |
void Botan::BigInt::grow_to | ( | size_t | n | ) |
Increase internal register buffer to at least n words
n | new size of register |
Definition at line 290 of file bigint.cpp.
References Botan::round_up(), and size().
Referenced by Botan::ct_inverse_mod_odd_modulus(), Botan::divide(), mul(), Botan::Montgomery_Params::mul_by(), operator%=(), operator*=(), operator+=(), operator-=(), operator<<=(), Botan::Montgomery_Params::redc(), reduce_below(), set_bit(), and Botan::Montgomery_Params::square_this().
|
inline |
Test if the integer has an even value
Definition at line 296 of file bigint.h.
Referenced by Botan::almost_montgomery_inverse(), botan_mp_is_even(), Botan::RSA_PublicKey::check_key(), Botan::RSA_PrivateKey::check_key(), Botan::ct_inverse_mod_odd_modulus(), Botan::inverse_euclid(), Botan::inverse_mod(), Botan::is_prime(), Botan::jacobi(), Botan::Montgomery_Params::Montgomery_Params(), Botan::power_mod(), and Botan::ressol().
|
inline |
Tests if the sign of the integer is negative
Definition at line 413 of file bigint.h.
Referenced by Botan::PointGFp::add(), Botan::PointGFp::add_affine(), botan_mp_is_negative(), cmp(), Botan::ct_inverse_mod_odd_modulus(), Botan::divide(), Botan::inverse_euclid(), Botan::inverse_mod(), Botan::jacobi(), 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::mult2(), Botan::PointGFp_Multi_Point_Precompute::multi_exp(), Botan::operator%(), Botan::operator*(), Botan::Montgomery_Int::operator-(), Botan::Montgomery_Int::operator-=(), Botan::power_mod(), Botan::random_prime(), Botan::Modular_Reducer::reduce(), reduce_below(), Botan::Power_Mod::set_base(), Botan::Power_Mod::set_exponent(), Botan::sub_mul(), and to_u32bit().
|
inline |
Test if the integer is not zero
Definition at line 308 of file bigint.h.
References Botan::CT::is_zero().
Referenced by Botan::gcd(), Botan::inverse_euclid(), and Botan::low_zero_bits().
|
inline |
Test if the integer has an odd value
Definition at line 302 of file bigint.h.
Referenced by botan_mp_is_odd(), Botan::inverse_euclid(), Botan::inverse_mod(), Botan::normalized_montgomery_inverse(), and Botan::Power_Mod::set_modulus().
|
inline |
Tests if the sign of the integer is positive
Definition at line 419 of file bigint.h.
Referenced by botan_mp_is_positive(), cmp(), Botan::low_zero_bits(), and Botan::operator%().
|
inline |
Test if the integer is zero
Definition at line 314 of file bigint.h.
Referenced by Botan::PointGFp::add(), Botan::PointGFp::add_affine(), botan_mp_is_zero(), Botan::ct_inverse_mod_odd_modulus(), Botan::DH_PrivateKey::DH_PrivateKey(), Botan::divide(), Botan::ElGamal_PrivateKey::ElGamal_PrivateKey(), encode(), Botan::gcd(), Botan::inverse_euclid(), Botan::inverse_mod(), Botan::Montgomery_Int::is_zero(), Botan::jacobi(), Botan::mul_sub(), Botan::PointGFp::mult2(), Botan::operator%(), operator>>=(), Botan::DL_Group::PEM_for_named_group(), Botan::power_mod(), Botan::PointGFp::randomize_repr(), Botan::Power_Mod::set_base(), and Botan::DL_Group::verify_public_element().
|
inline |
Clear all but the lowest n bits
n | amount of bits to keep |
Definition at line 340 of file bigint.h.
References Botan::clear_mem().
Referenced by Botan::redc_p521(), and Botan::Modular_Reducer::reduce().
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 142 of file big_ops2.cpp.
References Botan::bigint_linmul2(), Botan::bigint_linmul3(), Botan::bigint_mul(), clear(), data(), grow_to(), mutable_data(), Negative, Positive, set_sign(), sig_words(), sign(), size(), and word_at().
Referenced by operator*=(), and Botan::Modular_Reducer::reduce().
|
inline |
Return a mutable pointer to the register
Definition at line 498 of file bigint.h.
Referenced by Botan::divide(), Botan::Montgomery_Params::mul(), mul(), Botan::mul_add(), Botan::Montgomery_Params::mul_by(), operator*=(), operator+=(), operator-=(), Botan::operator<<(), operator<<=(), operator>>=(), Botan::Montgomery_Params::redc(), Botan::redc_p521(), Botan::Montgomery_Params::sqr(), and Botan::Montgomery_Params::square_this().
|
inline |
Modulo operator
y | the modulus to reduce this by |
Definition at line 229 of file big_ops2.cpp.
word Botan::BigInt::operator%= | ( | word | y | ) |
Modulo operator
y | the modulus (word) to reduce this by |
Definition at line 237 of file big_ops2.cpp.
References Botan::bigint_modop(), clear(), grow_to(), 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 136 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(), clear(), grow_to(), mutable_data(), Positive, set_sign(), sig_words(), and size().
|
inline |
|
inline |
+= operator
y | the BigInt to add to this |
Definition at line 18 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 Botan::zeroise().
BigInt Botan::BigInt::operator- | ( | ) | const |
Unary negation operator
Definition at line 247 of file bigint.cpp.
References flip_sign().
|
inline |
|
inline |
-= operator
y | the BigInt to subtract from this |
Definition at line 59 of file big_ops2.cpp.
References Botan::bigint_add2(), Botan::bigint_cmp(), Botan::bigint_shl1(), Botan::bigint_sub2(), Botan::bigint_sub2_rev(), clear(), data(), grow_to(), mutable_data(), Positive, reverse_sign(), set_sign(), sig_words(), and sign().
/= operator
y | the BigInt to divide this by |
Definition at line 217 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 271 of file big_ops2.cpp.
References Botan::bigint_shl1(), grow_to(), mutable_data(), and sig_words().
BigInt & Botan::BigInt::operator>>= | ( | size_t | shift | ) |
Right shift operator
shift | the number of bits to shift this right by |
Definition at line 298 of file big_ops2.cpp.
References Botan::bigint_shr1(), is_zero(), mutable_data(), Positive, set_sign(), and sig_words().
|
inlinestatic |
Create a power of two
n | the power of two to create |
Definition at line 583 of file bigint.h.
References set_bit().
Referenced by Botan::Modular_Reducer::Modular_Reducer(), Botan::Montgomery_Params::Montgomery_Params(), Botan::Modular_Reducer::reduce(), and Botan::ressol().
|
static |
rng | a random number generator |
min | the minimum value |
max | the maximum value |
Definition at line 45 of file big_rand.cpp.
References bits(), and randomize().
Referenced by botan_mp_rand_range(), Botan::DSA_PrivateKey::DSA_PrivateKey(), Botan::is_prime(), and Botan::EC_Group::random_scalar().
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(), random_integer(), and Botan::PointGFp::randomize_repr().
void Botan::BigInt::reduce_below | ( | const BigInt & | mod, |
secure_vector< word > & | ws | ||
) |
Return *this below 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 of modulo operator.
Definition at line 254 of file bigint.cpp.
References Botan::bigint_sub3(), Botan::clear_mem(), data(), grow_to(), is_negative(), sig_words(), and size().
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(), Botan::PointGFp::mult2(), Botan::Montgomery_Int::operator+(), Botan::Montgomery_Int::operator+=(), Botan::redc_p521(), and Botan::Modular_Reducer::reduce().
BigInt & Botan::BigInt::rev_sub | ( | const word | y[], |
size_t | y_size, | ||
secure_vector< word > & | ws | ||
) |
Set *this to y - *this
y | the BigInt to subtract from as a sequence of words |
y_size | length of y in words |
ws | a temp workspace |
Definition at line 98 of file big_ops2.cpp.
References Botan::bigint_cmp(), Botan::bigint_sub3(), Botan::clear_mem(), data(), flip_sign(), Positive, sig_words(), and sign().
Referenced by Botan::Modular_Reducer::reduce().
|
inline |
Definition at line 430 of file bigint.h.
Referenced by Botan::operator-(), and operator-=().
void Botan::BigInt::set_bit | ( | size_t | n | ) |
Set bit at specified position
n | bit position to set |
Definition at line 189 of file bigint.cpp.
References grow_to(), and size().
Referenced by botan_mp_set_bit(), Botan::generate_dsa_primes(), power_of_2(), and Botan::random_prime().
|
inline |
Set sign of the integer
sign | new Sign to set |
Definition at line 449 of file bigint.h.
References Botan::CT::is_zero().
Referenced by abs(), BigInt(), Botan::divide(), encode(), Botan::gcd(), mul(), operator%=(), operator*=(), operator+=(), operator-=(), operator>>=(), randomize(), and square().
|
inline |
void Botan::BigInt::shrink_to_fit | ( | size_t | min_size = 0 | ) |
Resize the vector to the minimum word size to hold the integer, or min_size words, whichever is larger
Definition at line 332 of file bigint.cpp.
References sig_words().
|
inline |
Return how many words we need to hold this value
Definition at line 472 of file bigint.h.
Referenced by bits(), cmp(), Botan::ct_inverse_mod_odd_modulus(), Botan::divide(), encode_words(), Botan::Montgomery_Int::fix_size(), 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*(), operator*=(), Botan::operator+(), operator+=(), Botan::operator-(), operator-=(), Botan::operator/(), operator/=(), Botan::operator<<(), operator<<=(), Botan::operator>>(), operator>>=(), Botan::redc_p521(), Botan::Modular_Reducer::reduce(), reduce_below(), rev_sub(), shrink_to_fit(), Botan::Montgomery_Params::sqr(), square(), and Botan::Montgomery_Params::square_this().
|
inline |
Return the sign of the integer
Definition at line 425 of file bigint.h.
Referenced by mul(), Botan::mul_add(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator+(), operator+=(), Botan::operator-(), operator-=(), Botan::operator<<(), Botan::operator>>(), and rev_sub().
|
inline |
Give size of internal register
Definition at line 466 of file bigint.h.
Referenced by Botan::PointGFp::add_affine(), BigInt(), clear_bit(), const_time_lookup(), encode_words(), grow_to(), Botan::low_zero_bits(), Botan::Montgomery_Params::mul(), mul(), Botan::mul_add(), Botan::Montgomery_Params::mul_by(), Botan::operator*(), operator*=(), Botan::redc_p521(), Botan::Modular_Reducer::reduce(), reduce_below(), set_bit(), 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 180 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 150 of file bigint.h.
Referenced by botan_mp_swap(), and Botan::PointGFp::swap().
|
inline |
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 173 of file bigint.cpp.
References bits(), byte_at(), and is_negative().
Referenced by botan_mp_to_uint32().
|
inline |
Return the word at a specified position of the internal register
n | position in the register |
Definition at line 399 of file bigint.h.
Referenced by bits(), const_time_lookup(), Botan::divide(), encode(), Botan::is_prime(), Botan::low_zero_bits(), Botan::Montgomery_Params::Montgomery_Params(), mul(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator/(), operator/=(), and Botan::redc_p521().