|
Botan 3.13.0
Crypto and TLS for C&
|
#include <bigint.h>
Public Types | |
| enum | Base : uint16_t { Decimal = 10 , Hexadecimal = 16 , Binary = 256 } |
| enum | Sign : uint8_t { Negative = 0 , Positive = 1 } |
Public Member Functions | |
| std::span< const word > | _as_span () const |
| void | _assign_from_bytes (std::span< const uint8_t > bytes) |
| void | _const_time_poison () const |
| void | _const_time_unpoison () const |
| const word * | _data () const |
| BigInt | abs () const |
| BigInt & | add (const word y[], size_t y_words, Sign sign) |
| BigInt ()=default | |
| BigInt (BigInt &&other) noexcept | |
| BigInt (const BigInt &other)=default | |
| 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::span< const uint8_t > bytes) | |
| BigInt (std::string_view str) | |
| BigInt (uint64_t n) | |
| void | binary_decode (const uint8_t buf[], size_t length) |
| void | binary_decode (std::span< const uint8_t > buf) |
| 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) |
| void | ct_shift_left (size_t shift) |
| 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) noexcept |
| 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 |
| template<typename T = std::vector<uint8_t>> | |
| T | serialize () const |
| template<typename T = std::vector<uint8_t>> | |
| T | serialize (size_t len) const |
| void | serialize_to (std::span< uint8_t > out) 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 |
| int | signum () 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) noexcept |
| 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 | _from_words (secure_vector< word > &words) |
| static BigInt | add2 (const BigInt &x, const word y[], size_t y_words, Sign y_sign) |
| static BigInt | decode (const uint8_t buf[], size_t length) |
| static BigInt | decode (const uint8_t buf[], size_t length, Base base) |
| static BigInt | decode (std::span< const uint8_t > buf) |
| static BigInt | decode (std::span< const uint8_t > buf, 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 (std::span< uint8_t > out, const BigInt &n) |
| 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 (std::span< const uint8_t > bytes) |
| static BigInt | from_bytes_with_max_bits (const uint8_t buf[], size_t length, size_t max_bits) |
| static BigInt | from_radix_digits (std::string_view digits, size_t radix) |
| static BigInt | from_s32 (int32_t n) |
| static BigInt | from_string (std::string_view str) |
| 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 () |
Friends | |
| void | swap (BigInt &x, BigInt &y) noexcept |
| enum Botan::BigInt::Base : uint16_t |
| enum Botan::BigInt::Sign : uint8_t |
|
default |
Create empty (zero) BigInt
Referenced by _from_words(), abs(), add(), add2(), BigInt(), BigInt(), BigInt(), cmp(), ct_cond_add(), ct_cond_assign(), ct_cond_swap(), ct_reduce_below(), decode(), decode(), decode(), decode(), encode(), encode_1363(), encode_1363(), encode_1363(), encode_fixed_length_int_pair(), encode_locked(), from_bytes(), from_bytes_with_max_bits(), from_radix_digits(), from_s32(), from_string(), from_u64(), from_word(), is_equal(), is_less_than(), mod_add(), mod_mul(), mod_sub(), mul(), one(), operator%=(), operator*=(), operator*=(), operator++(), operator++(), operator+=(), operator+=(), operator-(), operator--(), operator--(), operator-=(), operator-=(), operator/=(), operator<<=(), operator=(), operator=(), operator>>=(), power_of_2(), random_integer(), reduce_below(), rev_sub(), square(), sub(), swap(), swap, to_dec_string(), with_capacity(), and zero().
| Botan::BigInt::BigInt | ( | uint64_t | n | ) |
Create BigInt from an unsigned 64 bit integer
| n | initial value of this BigInt |
Prefer BigInt::from_u64
Definition at line 20 of file bigint.cpp.
|
default |
|
inlineexplicit |
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 98 of file bigint.h.
References BigInt(), and from_string().
|
inline |
|
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 Types | is the number base of the integer in buf |
Definition at line 92 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.
| Random Number Generators | random number generator |
| bits | size in bits |
| set_high_bit | if true, the highest bit is always set |
Definition at line 114 of file bigint.cpp.
References bits(), and randomize().
|
inlinenoexcept |
|
inline |
Definition at line 185 of file bigint.h.
References _const_time_unpoison().
|
inline |
Return a span over the register
Definition at line 1023 of file bigint.h.
References _as_span().
Referenced by _as_span(), Botan::Montgomery_Int::Montgomery_Int(), and Botan::Barrett_Reduction::reduce().
|
inline |
Read integer value from a byte vector (big endian)
| bytes | the span of bytes to load |
Definition at line 1044 of file bigint.h.
References bytes().
Referenced by Botan::generate_dsa_primes(), Botan::ASN1::integer_from_contents(), and Botan::RFC6979_Nonce_Generator::nonce_for().
| void Botan::BigInt::_const_time_poison | ( | ) | const |
Mark this BigInt as holding secret data
Definition at line 555 of file bigint.cpp.
References Botan::CT::poison().
Referenced by const_time_poison().
| void Botan::BigInt::_const_time_unpoison | ( | ) | const |
Mark this BigInt as no longer holding secret data
Definition at line 559 of file bigint.cpp.
References Botan::CT::unpoison().
Referenced by const_time_unpoison(), and ~BigInt().
|
inline |
Return a const pointer to the register
Definition at line 1033 of file bigint.h.
Referenced by add(), Botan::EC_Point::add(), add2(), Botan::EC_Point::add_affine(), cmp(), cmp_word(), ct_cond_add(), Botan::ct_divide(), Botan::ct_divide_pow2k(), Botan::ct_modulo(), ct_reduce_below(), ct_shift_left(), encode_words(), is_equal(), is_less_than(), mod_add(), mod_sub(), mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul_by(), Botan::Barrett_Reduction::multiply(), Botan::operator*(), Botan::operator*(), Botan::operator+(), operator+=(), Botan::operator-(), operator-=(), Botan::operator<<(), Botan::operator>>(), reduce_below(), Botan::Montgomery_Params::sqr(), Botan::Montgomery_Params::sqr(), Botan::Montgomery_Params::sqr(), Botan::Barrett_Reduction::square(), and square().
|
inlinestatic |
Create a BigInt from a word vector
Definition at line 1052 of file bigint.h.
References BigInt().
Referenced by Botan::Montgomery_Int::value().
| BigInt Botan::BigInt::abs | ( | ) | const |
Return the absolute value of this integer
Definition at line 386 of file bigint.cpp.
References BigInt(), Positive, and set_sign().
Referenced by Botan::abs().
Add a signed word array to *this
| y | the words of the addend |
| y_words | the number of words in y |
| sign | the sign of the addend |
Definition at line 32 of file big_ops2.cpp.
References _data(), BigInt(), Botan::bigint_add2(), Botan::bigint_cmp(), Botan::bigint_sub2(), Botan::bigint_sub2_rev(), Botan::carry(), grow_to(), mutable_data(), Positive, set_sign(), sig_words(), sign(), and size().
Referenced by operator+=(), operator+=(), and sub().
|
static |
Add a signed word array to an integer
| x | the first addend |
| y | the words of the second addend |
| y_words | the number of words in y |
| y_sign | the sign of the second addend |
Definition at line 20 of file big_ops3.cpp.
References _data(), BigInt(), Botan::bigint_add3(), Botan::bigint_cmp(), Botan::bigint_sub3(), Botan::carry(), data(), mutable_data(), set_sign(), sig_words(), sign(), and with_capacity().
Referenced by Botan::operator+(), Botan::operator+(), Botan::operator-(), and Botan::operator-().
|
inline |
Read integer value from a byte array with given size
| buf | byte array buffer containing the integer |
| length | size of buf |
Definition at line 836 of file bigint.h.
References binary_decode(), and BOTAN_DEPRECATED.
Referenced by binary_decode(), and binary_decode().
|
inline |
Read integer value from a byte vector
| buf | the vector to load from |
Definition at line 844 of file bigint.h.
References binary_decode().
|
inline |
Store BigInt-value in a given byte array
| buf | destination byte array for the integer value |
Definition at line 811 of file bigint.h.
References binary_encode(), bytes(), and serialize_to().
Referenced by binary_encode(), and serialize_to().
| 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.
Zero-padding the binary encoding is useful to ensure that other applications correctly parse the encoded value as "positive integer", as a leading 1-bit may be interpreted as a sign bit.
| buf | destination byte array for the integer value |
| len | how many bytes to write |
Definition at line 404 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 307 of file bigint.cpp.
References sig_words(), and top_bits_free().
Referenced by BigInt(), bytes(), Botan::ct_divide(), Botan::ct_divide_pow2k(), Botan::ct_divide_word(), Botan::ct_mod_word(), Botan::ct_modulo(), Botan::BER_Decoder::decode(), Botan::BER_Decoder::decode_constrained_integer(), Botan::DL_Group::DL_Group(), Botan::EC_Group::EC_Group(), Botan::generate_dsa_primes(), Botan::generate_rfc6979_nonce(), Botan::generate_rsa_prime(), Botan::inverse_mod_general(), Botan::is_lucas_probable_prime(), Botan::is_perfect_square(), Botan::is_prime(), Botan::TPM_PrivateKey::key_length(), Botan::monty_multi_exp(), Botan::EC_Point::mul(), Botan::EC_Point_Base_Point_Precompute::mul(), Botan::EC_Point_Var_Point_Precompute::mul(), Botan::EC_Point_Multi_Point_Precompute::multi_exp(), Botan::RFC6979_Nonce_Generator::nonce_for(), operator/=(), Botan::passes_miller_rabin_test(), Botan::DL_Group::power_b_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(), to_u32bit(), Botan::DL_Group::verify_element_pair(), and Botan::EC_Group::verify_group().
| uint8_t Botan::BigInt::byte_at | ( | size_t | n | ) | const |
Return a byte of the big-endian encoding of this integer
| n | the offset to get a byte from |
Definition at line 118 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 294 of file bigint.cpp.
References bits(), and Botan::round_up().
Referenced by _assign_from_bytes(), Botan::base58_decode(), BigInt(), binary_encode(), encode_1363(), encode_1363(), encode_fixed_length_int_pair(), Botan::ASN1::integer_contents(), Botan::OS2ECP(), serialize(), serialize_to(), and to_hex_string().
|
inline |
Zeroize the BigInt. The size of the underlying register is not modified.
Definition at line 441 of file bigint.h.
References clear(), and Positive.
Referenced by clear(), mul(), 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 285 of file bigint.cpp.
| 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 138 of file bigint.cpp.
References _data(), BigInt(), Botan::bigint_cmp(), signum(), 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 122 of file bigint.cpp.
References _data(), Botan::bigint_cmp(), sig_words(), and signum().
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 521 of file bigint.cpp.
References Botan::CT::Mask< T >::expand_bool(), set_sign(), and sign().
Referenced by ct_cond_assign(), and Botan::operator*().
|
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 526 of file bigint.h.
References word_at().
Referenced by Botan::ct_divide(), Botan::ct_divide_pow2k(), Botan::ct_divide_word(), Botan::ct_modulo(), and set_bit().
|
inline |
Mark this value as secret for constant time analysis tooling
Definition at line 885 of file bigint.h.
References _const_time_poison(), BOTAN_DEPRECATED, and const_time_poison().
Referenced by const_time_poison().
|
inline |
Mark this value as no longer secret for constant time analysis tooling
Definition at line 890 of file bigint.h.
References _const_time_unpoison(), and const_time_unpoison().
Referenced by const_time_unpoison().
| void Botan::BigInt::ct_cond_add | ( | bool | predicate, |
| const BigInt & | value ) |
If predicate is true add value to *this
Definition at line 449 of file bigint.cpp.
References _data(), BigInt(), Botan::carry(), Botan::CT::Mask< T >::expand(), grow_to(), mutable_data(), sig_words(), signum(), size(), and Botan::word_add().
Referenced by Botan::inverse_mod_general(), 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 533 of file bigint.cpp.
References BigInt(), cond_flip_sign(), Botan::CT::Mask< T >::expand_bool(), grow_to(), Botan::CT::Mask< T >::is_equal(), set_word_at(), sign(), size(), and word_at().
Referenced by Botan::inverse_mod_general(), 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 513 of file bigint.cpp.
References BigInt(), Botan::bigint_cnd_swap(), grow_to(), mutable_data(), and size().
| 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 361 of file bigint.cpp.
References _data(), BigInt(), Botan::bigint_sub3(), Botan::clear_mem(), grow_to(), Botan::CT::Mask< T >::is_zero(), mutable_data(), sig_words(), signum(), and size().
| void Botan::BigInt::ct_shift_left | ( | size_t | shift | ) |
Shift shift bits to the left, runtime is independent of the value of shift.
Definition at line 475 of file bigint.cpp.
References _data(), Botan::bigint_shl2(), BOTAN_ASSERT_NOMSG, Botan::ceil_log2(), Botan::CT::Mask< T >::expand_bool(), size(), and word_at().
|
inline |
Return a const pointer to the register
Definition at line 718 of file bigint.h.
References data().
Referenced by add2(), data(), Botan::FPE::fe1_decrypt(), and Botan::FPE::fe1_encrypt().
|
inlinestatic |
Create a BigInt from an integer in a byte array
| buf | the binary value to load |
| length | size of buf |
Definition at line 943 of file bigint.h.
References BigInt(), decode(), and from_bytes().
Referenced by BigInt(), decode(), decode(), decode(), and Botan::OS2ECP().
Create a BigInt from an integer in a byte array
| buf | the binary value to load |
| length | size of buf |
| Base Types | number-base of the integer in buf |
Definition at line 210 of file big_code.cpp.
References BigInt(), Binary, Botan::cast_uint8_ptr_to_char(), Decimal, from_bytes(), from_radix_digits(), and Hexadecimal.
|
inlinestatic |
Create a BigInt from an integer in a byte array
| buf | the binary value to load |
| Base Types | number-base of the integer in buf |
Definition at line 200 of file big_code.cpp.
References BigInt(), Binary, decode(), and from_bytes().
|
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 917 of file bigint.h.
References BigInt(), and encode().
Referenced by encode().
|
inlinestatic |
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 981 of file bigint.h.
References BigInt(), bytes(), and encode_1363().
Referenced by encode_1363(), encode_1363(), encode_1363(), Botan::EC_Point::x_bytes(), Botan::EC_Point::xy_bytes(), and Botan::EC_Point::y_bytes().
|
inlinestatic |
Encode an integer as a fixed length big-endian string per IEEE 1363
| out | the buffer to write to; its size determines the encoding length |
| n | the integer to encode |
Definition at line 990 of file bigint.h.
References BigInt(), and encode_1363().
|
inlinestatic |
|
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 186 of file big_code.cpp.
References BigInt(), bytes(), Botan::BufferStuffer::next(), serialize_to(), and signum().
|
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 926 of file bigint.h.
References BigInt(), and encode_locked().
Referenced by encode_locked().
| 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 180 of file bigint.cpp.
References _data(), Botan::clear_mem(), Botan::copy_mem(), sig_words(), and size().
|
inline |
Flip the sign of this BigInt
Definition at line 657 of file bigint.h.
References flip_sign(), reverse_sign(), and set_sign().
Referenced by Botan::ct_divide_word(), flip_sign(), Botan::is_lucas_probable_prime(), and operator-().
|
static |
Create a BigInt from an integer in a byte array
| bytes | the binary value to load |
Definition at line 83 of file bigint.cpp.
References BigInt().
Referenced by botan_srp6_client_agree(), botan_srp6_server_session_step1(), botan_srp6_server_session_step2(), Botan::TLS::Client_Key_Exchange::Client_Key_Exchange(), decode(), decode(), decode(), decode(), Botan::BER_Decoder::decode_octet_string_bigint(), from_bytes_with_max_bits(), from_radix_digits(), Botan::TPM_PrivateKey::get_e(), Botan::TPM_PrivateKey::get_n(), Botan::TLS::Callbacks::tls_deserialize_peer_public_key(), and Botan::EC_Scalar::to_bigint().
|
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 97 of file bigint.cpp.
References BigInt(), and from_bytes().
|
static |
Create BigInt from a sequence of digits
The string is interpreted as a sequence of digits in base radix.
Each character must be interpretable as such a digit; there is no support for whitespace or prefixes (eg '0x' or '-').
Currently radix must be 10 or 16.
| digits | the sequence of digits |
| radix | the base |
Definition at line 125 of file big_code.cpp.
References BigInt(), BOTAN_ARG_CHECK, from_bytes(), and Botan::hex_decode_locked().
Referenced by botan_mp_set_from_radix_str(), decode(), and from_string().
|
static |
Create BigInt from a signed 32 bit integer
| n | initial value of this BigInt |
Definition at line 42 of file bigint.cpp.
References BigInt(), and from_u64().
Referenced by botan_mp_set_from_int(), Botan::EC_Group::EC_Group(), Botan::EC_Group::EC_Group(), Botan::EC_Point::randomize_repr(), Botan::sqrt_modulo_prime(), and Botan::EC_Group::verify_group().
|
static |
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.
A prefix of "-" will result in a negative integer
| str | the string to parse for an integer value |
Definition at line 57 of file bigint.cpp.
References BigInt(), from_radix_digits(), Negative, Positive, and set_sign().
Referenced by BigInt().
|
static |
Create BigInt from an unsigned 64 bit integer
| n | initial value of this BigInt |
Definition at line 30 of file bigint.cpp.
References BigInt().
Referenced by Botan::DER_Encoder::encode(), Botan::DER_Encoder::encode(), from_s32(), one(), and Botan::RSA_PrivateKey::RSA_PrivateKey().
Create BigInt from a word (limb)
| n | initial value of this BigInt |
Definition at line 35 of file bigint.cpp.
References BigInt(), and 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 549 of file bigint.h.
References word_at().
Referenced by Botan::ct_divide(), Botan::ct_divide_word(), Botan::ct_mod_word(), Botan::ct_modulo(), Botan::EC_Point::encode(), Botan::inverse_mod_general(), is_even(), Botan::is_lucas_probable_prime(), is_odd(), Botan::EC_Point::mul(), 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 239 of file bigint.cpp.
References 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 723 of file bigint.h.
References get_word_vector().
Referenced by get_word_vector(), and get_word_vector().
|
inline |
Don't use this function in application code
Definition at line 730 of file bigint.h.
References get_word_vector().
|
inline |
Increase internal register buffer to at least n words
| n | new size of register |
Definition at line 738 of file bigint.h.
References grow_to().
Referenced by add(), ct_cond_add(), ct_cond_assign(), ct_cond_swap(), ct_reduce_below(), grow_to(), mod_add(), mod_sub(), mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul_by(), Botan::Montgomery_Params::redc(), Botan::Barrett_Reduction::reduce(), reduce_below(), Botan::Montgomery_Params::sqr(), Botan::vartime_divide(), Botan::vartime_divide_pow2k(), 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 156 of file bigint.cpp.
References _data(), BigInt(), Botan::bigint_ct_is_eq(), sign(), and size().
Referenced by Botan::operator!=().
|
inline |
Test if the integer has an even value
Definition at line 481 of file bigint.h.
References get_bit().
Referenced by Botan::generate_rsa_prime(), Botan::inverse_mod(), Botan::inverse_mod_general(), Botan::is_bailie_psw_probable_prime(), Botan::is_lucas_probable_prime(), Botan::is_miller_rabin_probable_prime(), Botan::is_prime(), 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 164 of file bigint.cpp.
References _data(), BigInt(), Botan::bigint_ct_is_lt(), signum(), and size().
Referenced by Botan::operator<(), and Botan::operator>().
|
inline |
Tests if the sign of the integer is negative
Definition at line 623 of file bigint.h.
References is_negative(), and signum().
Referenced by Botan::BER_Decoder::decode_constrained_integer(), and is_negative().
|
inline |
Test if the integer is not zero
Definition at line 504 of file bigint.h.
References is_nonzero(), and signum().
Referenced by is_nonzero().
|
inline |
Test if the integer has an odd value
Definition at line 487 of file bigint.h.
References get_bit().
Referenced by Botan::inverse_mod_general(), Botan::inverse_mod_public_prime(), Botan::inverse_mod_rsa_public_modulus(), Botan::inverse_mod_secret_prime(), Botan::is_lucas_probable_prime(), Botan::jacobi(), Botan::power_mod(), and Botan::sqrt_modulo_prime().
|
inline |
Tests if the sign of the integer is positive
Note that this is testing the sign, thus it returns true also for zero Prefer signum which is unambiguous
Definition at line 633 of file bigint.h.
References is_positive(), and signum().
Referenced by is_positive().
|
inline |
Test if the integer is zero
Definition at line 510 of file bigint.h.
References sig_words().
Referenced by Botan::EC_Point::add(), Botan::EC_Point::add_affine(), Botan::ct_divide(), Botan::DL_Group::DL_Group(), Botan::EC_PrivateKey::EC_PrivateKey(), Botan::gcd(), Botan::inverse_mod(), Botan::inverse_mod_general(), Botan::EC_Scalar_Data_BN::is_zero(), operator!(), Botan::operator%(), Botan::operator<<(), Botan::operator>>(), Botan::power_mod(), Botan::RSA_PrivateKey::RSA_PrivateKey(), Botan::EC_Group_Data::scalar_deserialize(), set_sign(), Botan::srp6_client_agree(), Botan::SRP6_Server_Session::step2(), 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 542 of file bigint.h.
References mask_bits().
Referenced by Botan::inverse_mod_general(), and mask_bits().
| 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 61 of file big_ops2.cpp.
References _data(), BigInt(), Botan::bigint_add3(), Botan::bigint_sub3(), BOTAN_ARG_CHECK, BOTAN_DEBUG_ASSERT, BOTAN_UNUSED, Botan::CT::conditional_copy_mem(), grow_to(), set_words(), sig_words(), and signum().
Referenced by Botan::EC_Point::mult2().
| 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 138 of file big_ops2.cpp.
References BigInt(), BOTAN_ARG_CHECK, BOTAN_DEBUG_ASSERT, reduce_below(), and signum().
| 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 110 of file big_ops2.cpp.
References _data(), BigInt(), Botan::bigint_cnd_add(), Botan::bigint_sub3(), BOTAN_DEBUG_ASSERT, grow_to(), mutable_data(), sig_words(), signum(), and Botan::unchecked_copy_memory().
Referenced by Botan::EC_Point::add(), Botan::EC_Point::add_affine(), and Botan::EC_Point::mult2().
| 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 165 of file big_ops2.cpp.
References _data(), BigInt(), Botan::bigint_linmul3(), Botan::bigint_mul(), clear(), grow_to(), mutable_data(), Negative, Positive, set_sign(), sig_words(), sign(), size(), swap_reg(), and word_at().
Referenced by operator*=().
|
inline |
Return a mutable pointer to the register
Definition at line 712 of file bigint.h.
References BOTAN_DEPRECATED, and mutable_data().
Referenced by add(), add2(), ct_cond_add(), ct_cond_swap(), Botan::ct_divide(), Botan::ct_divide_pow2k(), Botan::ct_modulo(), ct_reduce_below(), mod_sub(), mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul_by(), mutable_data(), Botan::operator*(), Botan::operator*(), operator*=(), Botan::operator<<(), Botan::operator>>(), Botan::Montgomery_Params::redc(), Botan::Montgomery_Params::sqr(), Botan::vartime_divide(), and Botan::vartime_divide_pow2k().
|
inlinestatic |
Create a 1-value BigInt
Definition at line 55 of file bigint.h.
References BigInt(), and from_u64().
Referenced by Botan::is_lucas_probable_prime(), Botan::is_perfect_square(), Botan::X509_CA::new_crl(), Botan::power_mod(), Botan::EC_Group_Data::scalar_one(), and Botan::EC_Group_Data::scalar_random().
|
inline |
Modulo operator
| y | the modulus to reduce this by |
Definition at line 232 of file big_ops2.cpp.
References BigInt().
Modulo operator
| y | the modulus (word) to reduce this by |
Definition at line 239 of file big_ops2.cpp.
References Botan::is_power_of_2(), Negative, Positive, set_sign(), sig_words(), sign(), Botan::divide_precomp< W >::vartime_mod_2to1(), and word_at().
*= operator
| y | the BigInt to multiply with this |
Definition at line 160 of file big_ops2.cpp.
*= operator
| y | the word to multiply with this |
Definition at line 205 of file big_ops2.cpp.
References BigInt(), 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 16 of file big_ops2.cpp.
References _data(), add(), BigInt(), sig_words(), and sign().
| BigInt Botan::BigInt::operator- | ( | ) | const |
Unary negation operator
Definition at line 323 of file bigint.cpp.
References BigInt(), and flip_sign().
|
inline |
|
inline |
-= operator
| y | the BigInt to subtract from this |
Definition at line 23 of file big_ops2.cpp.
References _data(), BigInt(), clear(), Positive, set_sign(), sig_words(), sign(), and sub().
/= operator
| y | the BigInt to divide this by |
Definition at line 220 of file big_ops2.cpp.
References BigInt(), bits(), Botan::is_power_of_2(), sig_words(), signum(), 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 269 of file big_ops2.cpp.
References BigInt(), Botan::bigint_shl1(), 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 287 of file big_ops2.cpp.
References BigInt(), Botan::bigint_shr1(), Negative, Positive, and sig_words().
|
inlinestatic |
Create a power of two
| n | the power of two to create |
Definition at line 906 of file bigint.h.
References BigInt(), and set_bit().
Referenced by Botan::EC_Group::EC_Group(), Botan::inverse_mod_general(), Botan::is_perfect_square(), and Botan::sqrt_modulo_prime().
|
static |
Generate a random integer within a range
| Random Number Generators | 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 44 of file big_rand.cpp.
References BigInt(), bits(), BOTAN_DEBUG_ASSERT, random_integer(), randomize(), signum(), and zero().
Referenced by botan_mp_rand_range(), Botan::is_miller_rabin_probable_prime(), random_integer(), Botan::EC_Point::randomize_repr(), and Botan::EC_Group_Data::scalar_random().
| 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.
| Random Number Generators | 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 19 of file big_rand.cpp.
References clear(), Positive, Botan::RandomNumberGenerator::random_vec(), Botan::round_up(), and set_sign().
Referenced by BigInt(), Botan::DL_Group::DL_Group(), 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 329 of file bigint.cpp.
References _data(), BigInt(), Botan::bigint_sub3(), Botan::clear_mem(), grow_to(), sig_words(), signum(), size(), and swap_reg().
Referenced by mod_mul(), Botan::vartime_divide(), and Botan::vartime_divide_pow2k().
|
inline |
| 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 149 of file big_ops2.cpp.
References BigInt(), and BOTAN_UNUSED.
|
inline |
Return the sign opposite to that of this integer
Definition at line 647 of file bigint.h.
References Negative, Positive, and sign().
Referenced by flip_sign(), and Botan::operator-().
|
inline |
Serialize the value of this BigInt as a big endian encoding.
Definition at line 803 of file bigint.h.
References bytes(), and serialize().
|
inline |
Serialize the value of this BigInt as a big endian encoding, always returning the specified number of bytes.
Throws if the BigInt is too large to encode in the length specified.
Definition at line 790 of file bigint.h.
References serialize_to().
Referenced by Botan::base58_decode(), Botan::ASN1::integer_contents(), Botan::X509_Serial_Number::magnitude(), Botan::EC_Group_Data::scalar_from_bigint(), serialize(), Botan::Montgomery_Int::serialize(), Botan::sm2_compute_za(), Botan::srp6_client_agree(), and Botan::SRP6_Server_Session::step2().
| void Botan::BigInt::serialize_to | ( | std::span< uint8_t > | out | ) | const |
Serialize the absolute value of this BigInt as a big endian encoding.
If out is smaller than the total bytes of the BigInt then an exception is thrown.
If out is larger than the total bytes of the BigInt then the necessary number of zeros are prefixed to produce the desired output length
Zero-padding the binary encoding is useful to ensure that other applications correctly parse the encoded value as "positive integer", as a leading 1-bit may be interpreted as a sign bit. It also is necessary when using a fixed size encoding for the integers.
| out | destination byte span for the integer value |
Definition at line 395 of file bigint.cpp.
References binary_encode(), BOTAN_ARG_CHECK, and bytes().
Referenced by binary_encode(), Botan::EC_Point::encode(), encode_fixed_length_int_pair(), Botan::EC_AffinePoint::from_bigint_xy(), Botan::RFC6979_Nonce_Generator::nonce_for(), Botan::RFC6979_Nonce_Generator::RFC6979_Nonce_Generator(), serialize(), and to_hex_string().
|
inline |
Set bit at specified position
| n | bit position to set |
Definition at line 516 of file bigint.h.
References conditionally_set_bit().
Referenced by Botan::ct_divide_pow2k(), Botan::EC_Group::EC_Group(), Botan::generate_dsa_primes(), Botan::generate_rsa_prime(), power_of_2(), and Botan::vartime_divide_pow2k().
|
inline |
Set sign of the integer
Definition at line 663 of file bigint.h.
References is_zero(), Negative, Positive, and sign().
Referenced by abs(), add(), add2(), cond_flip_sign(), flip_sign(), from_string(), Botan::ASN1::integer_from_contents(), Botan::inverse_mod_general(), Botan::lcm(), mul(), operator%=(), Botan::operator*(), operator*=(), operator-=(), Botan::operator<<(), Botan::operator>>(), randomize(), resize(), square(), to_dec_string(), and Botan::vartime_divide().
|
inline |
Set the word at a specified position of the internal register
| i | position in the register |
| w | the value to set |
Definition at line 608 of file bigint.h.
References set_word_at().
Referenced by ct_cond_assign(), from_word(), operator*=(), and set_word_at().
|
inline |
Replace the internal register with the given words
| w | the words to set |
| len | the number of words in w |
Definition at line 615 of file bigint.h.
References set_words().
Referenced by mod_add(), and set_words().
|
inline |
Return how many words we need to hold this value
Definition at line 687 of file bigint.h.
Referenced by add(), add2(), bits(), cmp_word(), ct_cond_add(), Botan::ct_divide(), Botan::ct_divide_pow2k(), Botan::ct_divide_word(), Botan::ct_modulo(), ct_reduce_below(), encode_words(), Botan::Barrett_Reduction::for_public_modulus(), Botan::Barrett_Reduction::for_secret_modulus(), Botan::gcd(), is_zero(), mod_add(), mod_sub(), mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul_by(), Botan::operator%(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator*(), Botan::operator+(), operator+=(), Botan::operator-(), operator-=(), Botan::operator/(), operator/=(), Botan::operator<<(), operator<<=(), Botan::operator>>(), operator>>=(), Botan::Barrett_Reduction::reduce(), reduce_below(), signum(), Botan::Montgomery_Params::sqr(), square(), top_bits_free(), Botan::vartime_divide(), and Botan::vartime_divide_pow2k().
|
inline |
Return the sign of the integer
Definition at line 641 of file bigint.h.
Referenced by add(), add2(), cond_flip_sign(), ct_cond_assign(), is_equal(), mul(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator*(), Botan::operator+(), operator+=(), operator-=(), Botan::operator<<(), Botan::operator>>(), resize(), reverse_sign(), set_sign(), signum(), and sub().
|
inline |
Return the signum of this integer
Definition at line 493 of file bigint.h.
References Negative, sig_words(), and sign().
Referenced by Botan::EC_Point::_is_x_eq_to_v_mod_order(), cmp(), cmp_word(), ct_cond_add(), Botan::ct_divide_pow2k(), Botan::ct_divide_word(), Botan::ct_mod_word(), Botan::ct_modulo(), ct_reduce_below(), Botan::BER_Decoder::decode(), Botan::FPE_FE1::decrypt(), encode_fixed_length_int_pair(), Botan::FPE_FE1::encrypt(), Botan::Barrett_Reduction::for_public_modulus(), Botan::Barrett_Reduction::for_secret_modulus(), Botan::EC_AffinePoint::from_bigint_xy(), Botan::ASN1::integer_contents(), Botan::inverse_mod(), Botan::inverse_mod_general(), Botan::inverse_mod_public_prime(), Botan::inverse_mod_rsa_public_modulus(), Botan::inverse_mod_secret_prime(), is_less_than(), Botan::is_lucas_probable_prime(), is_negative(), is_nonzero(), is_positive(), mod_add(), mod_mul(), mod_sub(), Botan::Montgomery_Int::Montgomery_Int(), Botan::monty_multi_exp(), Botan::monty_precompute(), Botan::EC_Point::mul(), 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::operator>>(), Botan::power_mod(), random_integer(), Botan::random_prime(), Botan::Barrett_Reduction::reduce(), reduce_below(), Botan::SRP6_Server_Session::step1(), to_dec_string(), to_hex_string(), to_u32bit(), Botan::vartime_divide(), and Botan::vartime_divide_pow2k().
|
inline |
Give size of internal register
Definition at line 681 of file bigint.h.
Referenced by add(), Botan::EC_Point::add(), Botan::EC_Point::add_affine(), clear_bit(), cmp(), ct_cond_add(), ct_cond_assign(), ct_cond_swap(), Botan::ct_divide_pow2k(), ct_reduce_below(), ct_shift_left(), encode_words(), is_equal(), is_less_than(), Botan::low_zero_bits(), mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul(), Botan::Montgomery_Params::mul_by(), Botan::Barrett_Reduction::multiply(), Botan::operator*(), operator*=(), reduce_below(), Botan::Montgomery_Params::sqr(), Botan::Montgomery_Params::sqr(), Botan::Montgomery_Params::sqr(), Botan::Barrett_Reduction::square(), square(), and with_capacity().
| BigInt & Botan::BigInt::square | ( | secure_vector< word > & | ws | ) |
Square value of *this
| ws | a temp workspace |
Definition at line 191 of file big_ops2.cpp.
References _data(), BigInt(), Botan::bigint_sqr(), Positive, set_sign(), sig_words(), size(), and swap_reg().
Referenced by Botan::EC_Group_Data::EC_Group_Data(), Botan::sqrt_modulo_prime(), Botan::square(), Botan::DL_Group::square_mod_q(), and Botan::EC_Group::verify_group().
Subtract a signed word array from *this
| y | the words of the subtrahend |
| y_words | the number of words in y |
| sign | the sign of the subtrahend |
Definition at line 358 of file bigint.h.
References add(), BigInt(), Negative, Positive, and sign().
Referenced by operator-=(), and operator-=().
|
inlinenoexcept |
Swap this value with another
| other | BigInt to swap values with |
Definition at line 207 of file bigint.h.
References BigInt().
Referenced by Botan::EC_Point::add_affine(), BigInt(), Botan::EC_Point::mult2(), and operator=().
|
inline |
Swap the internal register with the provided one, leaving the sign unchanged
| reg | the register to swap with |
Definition at line 218 of file bigint.h.
References swap_reg().
Referenced by mul(), reduce_below(), square(), and swap_reg().
| 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 40 of file big_code.cpp.
References BigInt(), bits(), BOTAN_ASSERT_NOMSG, Botan::ct_divide_word(), Botan::divide_10(), is_zero(), Positive, set_sign(), and signum().
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 107 of file big_code.cpp.
References bits(), bytes(), Botan::hex_encode(), serialize_to(), and signum().
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 267 of file bigint.cpp.
| size_t Botan::BigInt::top_bits_free | ( | ) | const |
Get the number of high bits unset in the top (allocated) word of this integer. Returns (sizeof(word) * 8) only iff *this is zero. Ignores sign.
Definition at line 298 of file bigint.cpp.
References Botan::high_bit(), sig_words(), Botan::CT::unpoison(), Botan::CT::value_barrier(), and word_at().
Referenced by bits(), Botan::vartime_divide(), and Botan::vartime_divide_pow2k().
|
static |
Create BigInt of specified size, all zeros
| n | size of the internal register in words |
Definition at line 51 of file bigint.cpp.
References BigInt(), grow_to(), and size().
Referenced by add2(), Botan::ct_divide(), Botan::ct_divide_pow2k(), Botan::ct_divide_word(), Botan::ct_modulo(), Botan::gcd(), Botan::Montgomery_Params::mul(), Botan::operator*(), Botan::operator*(), Botan::operator<<(), and Botan::operator>>().
|
inline |
Return the word at a specified position of the internal register
| n | position in the register |
Definition at line 601 of file bigint.h.
References word_at().
Referenced by binary_encode(), byte_at(), clear_bit(), conditionally_set_bit(), ct_cond_assign(), ct_shift_left(), Botan::EC_Group::EC_group_identity_from_order(), get_bit(), get_substring(), Botan::is_prime(), Botan::jacobi(), Botan::low_zero_bits(), mul(), Botan::operator%(), Botan::operator%(), operator%=(), Botan::operator*(), Botan::operator/(), operator/=(), top_bits_free(), Botan::vartime_divide(), Botan::vartime_divide_pow2k(), and word_at().
|
inlinestatic |
Create a 0-value BigInt
Definition at line 50 of file bigint.h.
References BigInt().
Referenced by botan_mp_mod_inverse(), Botan::ct_divide_pow2k(), Botan::EC_Group_Data::gk_x_mod_order(), Botan::inverse_mod(), Botan::is_perfect_square(), Botan::operator<<(), Botan::operator>>(), Botan::power_mod(), random_integer(), Botan::random_safe_prime(), Botan::X509_CA::update_crl(), Botan::vartime_divide(), and Botan::vartime_divide_pow2k().