Botan 3.8.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 | 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 374 of file bitvector.h.
|
inline |
Definition at line 376 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 391 of file bitvector.h.
|
inline |
Definition at line 395 of file bitvector.h.
|
inlineconstexpr |
Definition at line 876 of file bitvector.h.
|
inlineconstexpr |
Definition at line 878 of file bitvector.h.
|
inline |
|
inline |
Definition at line 673 of file bitvector.h.
|
inline |
Definition at line 668 of file bitvector.h.
|
inline |
|
inline |
OutT
Definition at line 430 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::to_bytes().
|
inline |
Definition at line 567 of file bitvector.h.
|
inline |
Definition at line 573 of file bitvector.h.
|
inline |
Definition at line 583 of file bitvector.h.
|
inline |
Definition at line 586 of file bitvector.h.
|
inlinenoexcept |
Definition at line 888 of file bitvector.h.
|
inlinenoexcept |
Definition at line 886 of file bitvector.h.
|
inline |
Definition at line 536 of file bitvector.h.
|
inlinenoexcept |
Definition at line 890 of file bitvector.h.
|
inlinenoexcept |
Definition at line 896 of file bitvector.h.
|
inline |
Implements::
if(condition) { *this ^= other; }
omitting runtime dependence on any of the parameters.
Definition at line 854 of file bitvector.h.
|
inline |
Definition at line 398 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::pop_back().
|
inlinenoexcept |
Definition at line 894 of file bitvector.h.
|
inlinenoexcept |
Definition at line 892 of file bitvector.h.
|
inlinenoexcept |
other
contains the same bit pattern as this Definition at line 449 of file bitvector.h.
|
inlinenoexcept |
other
contains the same bit pattern as this Definition at line 438 of file bitvector.h.
|
inline |
Flips all currently allocated bits.
Definition at line 642 of file bitvector.h.
|
inline |
Flips the bit at position pos
.
Botan::Invalid_Argument | if pos is out of range |
Definition at line 633 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 464 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::bitvector_base().
|
inline |
Definition at line 578 of file bitvector.h.
|
inline |
Definition at line 581 of file bitvector.h.
|
inline |
Counts the number of 1-bits in the bitvector in constant time.
Definition at line 420 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::all(), and Botan::bitvector_base< secure_allocator >::none().
|
inline |
Definition at line 405 of file bitvector.h.
|
inline |
Definition at line 658 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any().
|
inline |
Definition at line 651 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any_vartime().
|
inline |
Definition at line 823 of file bitvector.h.
|
inline |
Definition at line 683 of file bitvector.h.
|
inline |
Definition at line 686 of file bitvector.h.
|
inline |
Definition at line 831 of file bitvector.h.
|
inline |
Definition at line 815 of file bitvector.h.
|
inline |
Definition at line 808 of file bitvector.h.
|
inline |
Definition at line 556 of file bitvector.h.
|
inline |
|
inline |
Definition at line 538 of file bitvector.h.
|
inline |
Definition at line 540 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::from_bytes(), Botan::bitvector_base< secure_allocator >::pop_back(), and Botan::bitvector_base< secure_allocator >::push_back().
|
inline |
Sets all currently allocated bits.
Definition at line 601 of file bitvector.h.
|
inline |
Sets the bit at position pos
.
Botan::Invalid_Argument | if pos is out of range |
Definition at line 592 of file bitvector.h.
|
inline |
Definition at line 400 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_vartime(), Botan::bitvector_base< secure_allocator >::pop_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 738 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 698 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 774 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 490 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 501 of file bitvector.h.
|
inline |
|
inline |
Unsets all currently allocated bits.
Definition at line 622 of file bitvector.h.
|
inline |
Unsets the bit at position pos
.
Botan::Invalid_Argument | if pos is out of range |
Definition at line 613 of file bitvector.h.
|
friend |
Definition at line 247 of file bitvector.h.
|
staticconstexpr |
Definition at line 242 of file bitvector.h.
|
staticconstexpr |
Definition at line 241 of file bitvector.h.
|
staticconstexpr |
Definition at line 243 of file bitvector.h.