Botan 3.7.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 231 of file bitvector.h.
using Botan::bitvector_base< AllocatorT >::allocator_type = AllocatorT<block_type> |
Definition at line 235 of file bitvector.h.
using Botan::bitvector_base< AllocatorT >::block_type = uint8_t |
Definition at line 233 of file bitvector.h.
using Botan::bitvector_base< AllocatorT >::const_iterator = detail::bitvector_iterator<const bitvector_base<AllocatorT>> |
Definition at line 238 of file bitvector.h.
using Botan::bitvector_base< AllocatorT >::iterator = detail::bitvector_iterator<bitvector_base<AllocatorT>> |
Definition at line 237 of file bitvector.h.
using Botan::bitvector_base< AllocatorT >::size_type = size_t |
Definition at line 234 of file bitvector.h.
using Botan::bitvector_base< AllocatorT >::value_type = block_type |
Definition at line 236 of file bitvector.h.
|
inline |
Definition at line 373 of file bitvector.h.
|
inline |
Definition at line 375 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 390 of file bitvector.h.
|
inline |
Definition at line 394 of file bitvector.h.
|
inlineconstexpr |
Definition at line 875 of file bitvector.h.
|
inlineconstexpr |
Definition at line 877 of file bitvector.h.
|
inline |
|
inline |
Definition at line 672 of file bitvector.h.
|
inline |
Definition at line 667 of file bitvector.h.
|
inline |
|
inline |
OutT
Definition at line 429 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::to_bytes().
|
inline |
Definition at line 566 of file bitvector.h.
|
inline |
Definition at line 572 of file bitvector.h.
|
inline |
Definition at line 582 of file bitvector.h.
|
inline |
Definition at line 585 of file bitvector.h.
|
inlinenoexcept |
Definition at line 887 of file bitvector.h.
|
inlinenoexcept |
Definition at line 885 of file bitvector.h.
|
inline |
Definition at line 535 of file bitvector.h.
|
inlinenoexcept |
Definition at line 889 of file bitvector.h.
|
inlinenoexcept |
Definition at line 895 of file bitvector.h.
|
inline |
Implements::
if(condition) { *this ^= other; }
omitting runtime dependence on any of the parameters.
Definition at line 853 of file bitvector.h.
|
inline |
Definition at line 397 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::pop_back().
|
inlinenoexcept |
Definition at line 893 of file bitvector.h.
|
inlinenoexcept |
Definition at line 891 of file bitvector.h.
|
inlinenoexcept |
other
contains the same bit pattern as this Definition at line 448 of file bitvector.h.
|
inlinenoexcept |
other
contains the same bit pattern as this Definition at line 437 of file bitvector.h.
|
inline |
Flips all currently allocated bits.
Definition at line 641 of file bitvector.h.
|
inline |
Flips the bit at position pos
.
Botan::Invalid_Argument | if pos is out of range |
Definition at line 632 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 463 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::bitvector_base().
|
inline |
Definition at line 577 of file bitvector.h.
|
inline |
Definition at line 580 of file bitvector.h.
|
inline |
Counts the number of 1-bits in the bitvector in constant time.
Definition at line 419 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::all(), and Botan::bitvector_base< secure_allocator >::none().
|
inline |
Definition at line 404 of file bitvector.h.
|
inline |
Definition at line 657 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any().
|
inline |
Definition at line 650 of file bitvector.h.
Referenced by Botan::bitvector_base< secure_allocator >::any_vartime().
|
inline |
Definition at line 822 of file bitvector.h.
|
inline |
Definition at line 682 of file bitvector.h.
|
inline |
Definition at line 685 of file bitvector.h.
|
inline |
Definition at line 830 of file bitvector.h.
|
inline |
Definition at line 814 of file bitvector.h.
|
inline |
Definition at line 807 of file bitvector.h.
|
inline |
Definition at line 555 of file bitvector.h.
|
inline |
|
inline |
Definition at line 537 of file bitvector.h.
|
inline |
Definition at line 539 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 600 of file bitvector.h.
|
inline |
Sets the bit at position pos
.
Botan::Invalid_Argument | if pos is out of range |
Definition at line 591 of file bitvector.h.
|
inline |
Definition at line 399 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 737 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 697 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 773 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 489 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 500 of file bitvector.h.
|
inline |
|
inline |
Unsets all currently allocated bits.
Definition at line 621 of file bitvector.h.
|
inline |
Unsets the bit at position pos
.
Botan::Invalid_Argument | if pos is out of range |
Definition at line 612 of file bitvector.h.
|
friend |
Definition at line 246 of file bitvector.h.
|
staticconstexpr |
Definition at line 241 of file bitvector.h.
|
staticconstexpr |
Definition at line 240 of file bitvector.h.
|
staticconstexpr |
Definition at line 242 of file bitvector.h.