|
Botan 3.10.0
Crypto and TLS for C&
|
#include <bitvector.h>
Classes | |
| class | bitref |
| class | bitref< BlockT > |
Public Types | |
| using | allocator_type = AllocatorT<block_type> |
| using | block_type = uint8_t |
| using | const_iterator = detail::bitvector_iterator<const bitvector_base<AllocatorT>> |
| using | iterator = detail::bitvector_iterator<bitvector_base<AllocatorT>> |
| using | size_type = size_t |
| using | value_type = block_type |
Public Member Functions | |
| template<bitvectorish OutT> | |
| OutT | as () const |
| bitvector_base () | |
| bitvector_base (size_type bits) | |
| bitvector_base (std::initializer_list< block_type > blocks, std::optional< size_type > bits=std::nullopt) | |
| bitvector_base (std::span< const uint8_t > bytes, std::optional< size_type > bits=std::nullopt) | |
| bool | empty () const |
| template<bitvectorish OtherT> | |
| bool | equals (const OtherT &other) const noexcept |
| template<bitvectorish OtherT> | |
| bool | equals_vartime (const OtherT &other) const noexcept |
| size_type | hamming_weight () const |
| CT::Choice | has_odd_hamming_weight () const |
| size_type | size () const |
Serialization | |
| void | from_bytes (std::span< const uint8_t > bytes, std::optional< size_type > bits=std::nullopt) |
| template<concepts::resizable_byte_buffer OutT = std::conditional_t<uses_secure_allocator, secure_vector<uint8_t>, std::vector<uint8_t>>> | |
| OutT | to_bytes () const |
| void | to_bytes (std::span< uint8_t > out) const |
| std::string | to_string () const |
Capacity Accessors and Modifiers | |
| size_type | capacity () const |
| void | reserve (size_type bits) |
| void | resize (size_type bits) |
| void | push_back (bool bit) |
| void | pop_back () |
Bitwise and Global Accessors and Modifiers | |
| auto | at (size_type pos) |
| auto | at (size_type pos) const |
| auto | front () |
| auto | front () const |
| auto | back () |
| auto | back () const |
| bitvector_base & | set (size_type pos) |
| bitvector_base & | set () |
| bitvector_base & | unset (size_type pos) |
| bitvector_base & | unset () |
| bitvector_base & | flip (size_type pos) |
| bitvector_base & | flip () |
| bool | none_vartime () const |
| bool | none () const |
| bool | any_vartime () const |
| bool | any () const |
| bool | all_vartime () const |
| bool | all () const |
| auto | operator[] (size_type pos) |
| auto | operator[] (size_type pos) const |
Subvectors | |
| template<bitvectorish OutT = bitvector_base<AllocatorT>> | |
| auto | subvector (size_type pos, std::optional< size_type > length=std::nullopt) const |
| template<typename OutT > requires (std::unsigned_integral<strong_type_wrapped_type<OutT>> && !std::same_as<bool, strong_type_wrapped_type<OutT>>) | |
| OutT | subvector (size_type pos) const |
| template<typename InT > requires (std::unsigned_integral<strong_type_wrapped_type<InT>> && !std::same_as<bool, InT>) | |
| void | subvector_replace (size_type pos, InT value) |
Operators | |
| auto | operator~ () |
| template<bitvectorish OtherT> | |
| auto & | operator|= (const OtherT &other) |
| template<bitvectorish OtherT> | |
| auto & | operator&= (const OtherT &other) |
| template<bitvectorish OtherT> | |
| auto & | operator^= (const OtherT &other) |
Constant Time Operations | |
| template<bitvectorish OtherT> | |
| void | ct_conditional_xor (CT::Choice condition, const OtherT &other) |
| constexpr void | _const_time_poison () const |
| constexpr void | _const_time_unpoison () const |
Iterators | |
| iterator | begin () noexcept |
| const_iterator | begin () const noexcept |
| const_iterator | cbegin () const noexcept |
| iterator | end () noexcept |
| const_iterator | end () const noexcept |
| const_iterator | cend () noexcept |
Static Public Attributes | |
| static constexpr size_type | block_size_bits = block_size_bytes * 8 |
| static constexpr size_type | block_size_bytes = sizeof(block_type) |
| static constexpr bool | uses_secure_allocator = std::is_same_v<allocator_type, secure_allocator<block_type>> |
Friends | |
| template<template< typename > typename FriendAllocatorT> | |
| class | bitvector_base |
An arbitrarily large bitvector with typical bit manipulation and convenient bitwise access methods. Don't use bitvector_base directly, but the type aliases::
Definition at line 232 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::allocator_type = AllocatorT<block_type> |
Definition at line 236 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::block_type = uint8_t |
Definition at line 234 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::const_iterator = detail::bitvector_iterator<const bitvector_base<AllocatorT>> |
Definition at line 239 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::iterator = detail::bitvector_iterator<bitvector_base<AllocatorT>> |
Definition at line 238 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::size_type = size_t |
Definition at line 235 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::value_type = block_type |
Definition at line 237 of file bitvector.h.
|
inline |
Definition at line 375 of file bitvector.h.
|
inlineexplicit |
Definition at line 377 of file bitvector.h.
|
inline |
Initialize the bitvector from a byte-array. Bits are taken byte-wise from least significant to most significant. Example::
bitvector[0] -> LSB(Byte[0]) bitvector[1] -> LSB+1(Byte[0]) ... bitvector[8] -> LSB(Byte[1])
| bytes | The byte vector to be loaded |
| bits | The number of bits to be loaded. This must not be more than the number of bytes in bytes. |
Definition at line 392 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::from_bytes().
|
inline |
Definition at line 398 of file bitvector.h.
|
inlineconstexpr |
Definition at line 881 of file bitvector.h.
References Botan::CT::poison().
|
inlineconstexpr |
Definition at line 883 of file bitvector.h.
References Botan::CT::unpoison().
|
inline |
Definition at line 686 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::hamming_weight().
|
inline |
Definition at line 678 of file bitvector.h.
|
inline |
Definition at line 673 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::none().
|
inline |
Definition at line 668 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::none_vartime().
|
inline |
OutT Definition at line 433 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::size(), and Botan::bitvector_base< AllocatorT >::subvector().
Referenced by Botan::bitvector_base< AllocatorT >::to_bytes().
|
inline |
Definition at line 570 of file bitvector.h.
|
inline |
Definition at line 576 of file bitvector.h.
|
inline |
|
inline |
|
inlinenoexcept |
Definition at line 893 of file bitvector.h.
|
inlinenoexcept |
Definition at line 891 of file bitvector.h.
|
inline |
Definition at line 539 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::block_size_bits.
|
inlinenoexcept |
Definition at line 895 of file bitvector.h.
|
inlinenoexcept |
|
inline |
Implements::
if(condition) { *this ^= other; }
omitting runtime dependence on any of the parameters.
Definition at line 859 of file bitvector.h.
References BOTAN_ASSERT_NOMSG, Botan::CT::Mask< T >::from_choice(), and Botan::unwrap_strong_type().
|
inline |
Definition at line 401 of file bitvector.h.
Referenced by Botan::bitvector_base< AllocatorT >::pop_back().
|
inlinenoexcept |
|
inlinenoexcept |
Definition at line 897 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::size().
|
inlinenoexcept |
other contains the same bit pattern as this Definition at line 452 of file bitvector.h.
|
inlinenoexcept |
other contains the same bit pattern as this Definition at line 441 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::size(), and Botan::unwrap_strong_type().
|
inline |
Flips all currently allocated bits.
Definition at line 647 of file bitvector.h.
|
inline |
Flips the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 638 of file bitvector.h.
|
inline |
Re-initialize the bitvector with the given bytes. See the respective constructor for details. This should be used only when trying to save allocations. Otherwise, use the constructor.
| bytes | the byte range to load bits from |
| bits | (optional) if not all bytes should be loaded in full |
Definition at line 467 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::block_size_bits, Botan::bitvector_base< AllocatorT >::block_size_bytes, BOTAN_ARG_CHECK, Botan::bitvector_base< AllocatorT >::resize(), and Botan::typecast_copy().
Referenced by Botan::bitvector_base< AllocatorT >::bitvector_base().
|
inline |
Definition at line 581 of file bitvector.h.
|
inline |
Definition at line 584 of file bitvector.h.
|
inline |
Counts the number of 1-bits in the bitvector in constant time.
Definition at line 423 of file bitvector.h.
References Botan::ct_popcount().
Referenced by Botan::bitvector_base< AllocatorT >::all(), and Botan::bitvector_base< AllocatorT >::none().
|
inline |
Definition at line 408 of file bitvector.h.
References Botan::CT::Choice::from_int().
|
inline |
Definition at line 663 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::hamming_weight().
Referenced by Botan::bitvector_base< AllocatorT >::any().
|
inline |
Definition at line 656 of file bitvector.h.
Referenced by Botan::bitvector_base< AllocatorT >::any_vartime().
|
inline |
Definition at line 828 of file bitvector.h.
References Botan::unwrap_strong_type().
|
inline |
Definition at line 688 of file bitvector.h.
|
inline |
Definition at line 691 of file bitvector.h.
|
inline |
Definition at line 836 of file bitvector.h.
References Botan::unwrap_strong_type().
|
inline |
Definition at line 820 of file bitvector.h.
References Botan::unwrap_strong_type().
|
inline |
Definition at line 813 of file bitvector.h.
|
inline |
Definition at line 559 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::empty(), Botan::bitvector_base< AllocatorT >::resize(), and Botan::bitvector_base< AllocatorT >::size().
|
inline |
Definition at line 553 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::resize(), and Botan::bitvector_base< AllocatorT >::size().
|
inline |
Definition at line 541 of file bitvector.h.
|
inline |
Definition at line 543 of file bitvector.h.
Referenced by Botan::bitvector_base< AllocatorT >::from_bytes(), Botan::bitvector_base< AllocatorT >::pop_back(), and Botan::bitvector_base< AllocatorT >::push_back().
|
inline |
Sets all currently allocated bits.
Definition at line 604 of file bitvector.h.
|
inline |
Sets the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 595 of file bitvector.h.
|
inline |
Definition at line 403 of file bitvector.h.
Referenced by Botan::bitvector_base< AllocatorT >::as(), Botan::bitvector_base< AllocatorT >::back(), Botan::bitvector_base< AllocatorT >::back(), Botan::bitvector_base< AllocatorT >::cend(), Botan::Classic_McEliece_Field_Ordering::create_from_control_bits(), Botan::bitvector_base< AllocatorT >::end(), Botan::bitvector_base< AllocatorT >::end(), Botan::bitvector_base< AllocatorT >::equals_vartime(), Botan::bitvector_base< AllocatorT >::pop_back(), Botan::bitvector_base< AllocatorT >::push_back(), Botan::bitvector_base< AllocatorT >::subvector(), Botan::bitvector_base< AllocatorT >::subvector(), Botan::bitvector_base< AllocatorT >::subvector_replace(), and Botan::bitvector_base< AllocatorT >::to_string().
|
inline |
Extracts a subvector of bits as an unsigned integral type OutT starting from bit pos and copying exactly sizeof(OutT)*8 bits.
Hint: The bits are in big-endian order, i.e. the least significant bit is the 0th bit and the most significant bit it the n-th. Hence, addressing the bits with bitwise operations is done like so: bool bit = (out_int >> pos) & 1;
Definition at line 743 of file bitvector.h.
References BOTAN_ARG_CHECK, Botan::load_le(), Botan::bitvector_base< AllocatorT >::size(), and Botan::wrap_strong_type().
|
inline |
Creates a new bitvector with a subsection of this bitvector starting at pos copying exactly length bits.
Definition at line 703 of file bitvector.h.
References Botan::bitlen(), BOTAN_ARG_CHECK, Botan::copy_mem(), Botan::bitvector_base< AllocatorT >::size(), and Botan::unwrap_strong_type().
Referenced by Botan::bitvector_base< AllocatorT >::as().
|
inline |
Replaces a subvector of bits with the bits of another bitvector value starting at bit pos. The number of bits to replace is determined by the size of value.
pos only.| Not_Implemented | when called with pos not divisible by 8. |
| pos | the position to start replacing bits |
| value | the bitvector to copy bits from |
Definition at line 779 of file bitvector.h.
References BOTAN_ARG_CHECK, Botan::bitvector_base< AllocatorT >::size(), Botan::store_le(), and Botan::unwrap_strong_type().
|
inline |
Renders the bitvector into a byte array. By default, this will use std::vector<uint8_t> or Botan::secure_vector<uint8_t>, depending on the allocator used by the bitvector. The rendering is compatible with the bit layout explained in the respective constructor.
Definition at line 493 of file bitvector.h.
References Botan::ceil_tobytes(), and Botan::bitvector_base< AllocatorT >::to_bytes().
Referenced by Botan::Classic_McEliece_PrivateKeyInternal::serialize(), and Botan::bitvector_base< AllocatorT >::to_bytes().
|
inline |
Renders the bitvector into a properly sized byte range.
| out | a byte range that has a length of at least ceil_tobytes(size()). |
Definition at line 504 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::as(), Botan::bitvector_base< AllocatorT >::block_size_bits, Botan::bitvector_base< AllocatorT >::block_size_bytes, BOTAN_ARG_CHECK, Botan::ceil_tobytes(), Botan::clear_mem(), and Botan::typecast_copy().
|
inline |
Renders this bitvector into a sequence of "0"s and "1"s. This is meant for debugging purposes and is not efficient.
Definition at line 526 of file bitvector.h.
References Botan::bitvector_base< AllocatorT >::size().
|
inline |
Unsets all currently allocated bits.
Definition at line 627 of file bitvector.h.
|
inline |
Unsets the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 618 of file bitvector.h.
|
friend |
Definition at line 247 of file bitvector.h.
|
staticconstexpr |
Definition at line 242 of file bitvector.h.
Referenced by Botan::bitvector_base< AllocatorT >::capacity(), Botan::bitvector_base< AllocatorT >::from_bytes(), and Botan::bitvector_base< AllocatorT >::to_bytes().
|
staticconstexpr |
Definition at line 241 of file bitvector.h.
Referenced by Botan::bitvector_base< AllocatorT >::from_bytes(), and Botan::bitvector_base< AllocatorT >::to_bytes().
|
staticconstexpr |
Definition at line 243 of file bitvector.h.