|
Botan 3.14.1
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 | push_back (CT::Choice 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 & | set_range (size_type offset, size_type length) |
| bitvector_base & | unset_range (size_type offset, size_type length) |
| 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> | |
| OutT | subvector (size_type pos) const |
| template<typename 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 233 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::allocator_type = AllocatorT<block_type> |
Definition at line 237 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::block_type = uint8_t |
Definition at line 235 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::const_iterator = detail::bitvector_iterator<const bitvector_base<AllocatorT>> |
Definition at line 240 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::iterator = detail::bitvector_iterator<bitvector_base<AllocatorT>> |
Definition at line 239 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::size_type = size_t |
Definition at line 236 of file bitvector.h.
| using Botan::bitvector_base< AllocatorT >::value_type = block_type |
Definition at line 238 of file bitvector.h.
|
inline |
Definition at line 397 of file bitvector.h.
|
inlineexplicit |
Definition at line 399 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 414 of file bitvector.h.
|
inline |
Definition at line 420 of file bitvector.h.
|
inlineconstexpr |
Definition at line 977 of file bitvector.h.
|
inlineconstexpr |
Definition at line 979 of file bitvector.h.
|
inline |
|
inline |
Definition at line 773 of file bitvector.h.
|
inline |
Definition at line 768 of file bitvector.h.
|
inline |
|
inline |
OutT Definition at line 455 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::to_bytes().
|
inline |
Definition at line 613 of file bitvector.h.
|
inline |
Definition at line 619 of file bitvector.h.
|
inline |
Definition at line 629 of file bitvector.h.
|
inline |
Definition at line 632 of file bitvector.h.
|
inlinenoexcept |
Definition at line 989 of file bitvector.h.
|
inlinenoexcept |
Definition at line 987 of file bitvector.h.
|
inline |
Definition at line 573 of file bitvector.h.
|
inlinenoexcept |
Definition at line 991 of file bitvector.h.
|
inlinenoexcept |
Definition at line 997 of file bitvector.h.
|
inline |
Implements::
if(condition) { *this ^= other; }
omitting runtime dependence on any of the parameters.
Definition at line 955 of file bitvector.h.
|
inline |
Definition at line 423 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::pop_back().
|
inlinenoexcept |
Definition at line 995 of file bitvector.h.
|
inlinenoexcept |
Definition at line 993 of file bitvector.h.
|
inlinenoexcept |
|
inlinenoexcept |
other contains the same bit pattern as this Definition at line 463 of file bitvector.h.
|
inline |
Flips all currently allocated bits.
Definition at line 742 of file bitvector.h.
|
inline |
Flips the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 733 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 498 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::bitvector_base().
|
inline |
Definition at line 624 of file bitvector.h.
|
inline |
Definition at line 627 of file bitvector.h.
|
inline |
Counts the number of 1-bits in the bitvector in constant time.
Definition at line 445 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::all(), and Botan::bitvector_base< secure_allocator >::none().
|
inline |
Definition at line 430 of file bitvector.h.
|
inline |
Definition at line 758 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any().
|
inline |
Definition at line 751 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any_vartime().
|
inline |
Definition at line 924 of file bitvector.h.
|
inline |
Definition at line 783 of file bitvector.h.
|
inline |
Definition at line 786 of file bitvector.h.
|
inline |
Definition at line 932 of file bitvector.h.
|
inline |
Definition at line 916 of file bitvector.h.
|
inline |
Definition at line 909 of file bitvector.h.
|
inline |
Definition at line 602 of file bitvector.h.
|
inline |
|
inline |
|
inline |
Definition at line 575 of file bitvector.h.
|
inline |
Definition at line 577 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::from_bytes(), Botan::bitvector_base< secure_allocator >::pop_back(), Botan::bitvector_base< secure_allocator >::push_back(), and Botan::bitvector_base< secure_allocator >::push_back().
|
inline |
Sets all currently allocated bits.
Definition at line 647 of file bitvector.h.
|
inline |
Sets the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 638 of file bitvector.h.
|
inline |
Sets all bits in the range [offset, offset + length). Bits outside of this range remain unchanged.
| offset | the position of the first bit to be set |
| length | the number of bits to be set |
| Botan::Invalid_Argument | if the range is out of range |
Definition at line 665 of file bitvector.h.
|
inline |
Definition at line 425 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::as(), Botan::bitvector_base< secure_allocator >::back(), Botan::bitvector_base< secure_allocator >::back(), Botan::bitvector_base< secure_allocator >::cend(), Botan::Classic_McEliece_Field_Ordering::create_from_control_bits(), Botan::bitvector_base< secure_allocator >::end(), Botan::bitvector_base< secure_allocator >::end(), Botan::bitvector_base< secure_allocator >::equals(), Botan::bitvector_base< secure_allocator >::equals_vartime(), Botan::bitvector_base< secure_allocator >::pop_back(), Botan::bitvector_base< secure_allocator >::push_back(), Botan::bitvector_base< secure_allocator >::push_back(), Botan::bitvector_base< secure_allocator >::set_range(), Botan::bitvector_base< secure_allocator >::subvector(), Botan::bitvector_base< secure_allocator >::subvector(), Botan::bitvector_base< secure_allocator >::subvector_replace(), Botan::bitvector_base< secure_allocator >::to_string(), and Botan::bitvector_base< secure_allocator >::unset_range().
|
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 838 of file bitvector.h.
|
inline |
Creates a new bitvector with a subsection of this bitvector starting at pos copying exactly length bits.
Definition at line 798 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::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 875 of file bitvector.h.
|
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 527 of file bitvector.h.
Referenced by Botan::Classic_McEliece_Encryptor::raw_kem_encrypt(), and Botan::bitvector_base< secure_allocator >::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 538 of file bitvector.h.
|
inline |
|
inline |
Unsets all currently allocated bits.
Definition at line 722 of file bitvector.h.
|
inline |
Unsets the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 713 of file bitvector.h.
|
inline |
Unsets all bits in the range [offset, offset + length). Bits outside of this range remain unchanged.
| offset | the position of the first bit to be unset |
| length | the number of bits to be unset |
| Botan::Invalid_Argument | if the range is out of range |
Definition at line 691 of file bitvector.h.
|
friend |
Definition at line 248 of file bitvector.h.
|
staticconstexpr |
Definition at line 243 of file bitvector.h.
|
staticconstexpr |
Definition at line 242 of file bitvector.h.
|
staticconstexpr |
Definition at line 244 of file bitvector.h.