|
Botan 3.13.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 | 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 & | 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 925 of file bitvector.h.
|
inlineconstexpr |
Definition at line 927 of file bitvector.h.
|
inline |
|
inline |
Definition at line 721 of file bitvector.h.
|
inline |
Definition at line 716 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 937 of file bitvector.h.
|
inlinenoexcept |
Definition at line 935 of file bitvector.h.
|
inline |
Definition at line 573 of file bitvector.h.
|
inlinenoexcept |
Definition at line 939 of file bitvector.h.
|
inlinenoexcept |
Definition at line 945 of file bitvector.h.
|
inline |
Implements::
if(condition) { *this ^= other; }
omitting runtime dependence on any of the parameters.
Definition at line 903 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 943 of file bitvector.h.
|
inlinenoexcept |
Definition at line 941 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 690 of file bitvector.h.
|
inline |
Flips the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 681 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 706 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any().
|
inline |
Definition at line 699 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any_vartime().
|
inline |
Definition at line 872 of file bitvector.h.
|
inline |
Definition at line 731 of file bitvector.h.
|
inline |
Definition at line 734 of file bitvector.h.
|
inline |
Definition at line 880 of file bitvector.h.
|
inline |
Definition at line 864 of file bitvector.h.
|
inline |
Definition at line 857 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 |
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 >::subvector(), Botan::bitvector_base< secure_allocator >::subvector(), Botan::bitvector_base< secure_allocator >::subvector_replace(), and Botan::bitvector_base< secure_allocator >::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 786 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 746 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 823 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 670 of file bitvector.h.
|
inline |
Unsets the bit at position pos.
| Botan::Invalid_Argument | if pos is out of range |
Definition at line 661 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.