Botan 3.6.1
Crypto and TLS for C&
|
Alignment buffer helper. More...
#include <alignment_buffer.h>
Public Member Functions | |
std::tuple< std::span< const uint8_t >, size_t > | aligned_data_to_process (BufferSlicer &slicer) const |
AlignmentBuffer () | |
AlignmentBuffer (AlignmentBuffer &&other) noexcept=default | |
AlignmentBuffer (const AlignmentBuffer &other)=default | |
void | append (std::span< const T > elements) |
void | clear () |
std::span< const T > | consume () |
std::span< const T > | consume_partial () |
constexpr bool | defers_final_block () const |
std::span< T > | directly_modify_first (size_t elements) |
std::span< T > | directly_modify_last (size_t elements) |
size_t | elements_in_buffer () const |
size_t | elements_until_alignment () const |
void | fill_up_with_zeros () |
std::optional< std::span< const T > > | handle_unaligned_data (BufferSlicer &slicer) |
bool | in_alignment () const |
std::optional< std::span< const uint8_t > > | next_aligned_block_to_process (BufferSlicer &slicer) const |
AlignmentBuffer & | operator= (AlignmentBuffer &&other) noexcept=default |
AlignmentBuffer & | operator= (const AlignmentBuffer &other)=default |
bool | ready_to_consume () const |
constexpr size_t | size () const |
~AlignmentBuffer () | |
Alignment buffer helper.
Many algorithms have an intrinsic block size in which they consume input data. When streaming arbitrary data chunks to such algorithms we must store some data intermittently to honor the algorithm's alignment requirements.
This helper encapsulates such an alignment buffer. The API of this class is designed to minimize user errors in the algorithm implementations. Therefore, it is strongly opinionated on its use case. Don't try to use it for anything but the described circumstance.
T | the element type of the internal buffer |
BLOCK_SIZE | the buffer size to use for the alignment buffer |
FINAL_BLOCK_STRATEGY | defines whether the final input data block is retained in handle_unaligned_data() and must be manually consumed |
Definition at line 61 of file alignment_buffer.h.
|
inline |
Definition at line 63 of file alignment_buffer.h.
|
inline |
Definition at line 65 of file alignment_buffer.h.
References Botan::secure_scrub_memory().
|
default |
|
defaultnoexcept |
|
inlinenodiscard |
Once the buffer reached alignment, this can be used to consume as many input bytes from the given slider
as possible. The output always contains data elements that are a multiple of the intrinsic block size.
slicer
and the number of full blocks that are represented by this view. Definition at line 127 of file alignment_buffer.h.
References BOTAN_ASSERT_NOMSG, Botan::BufferSlicer::remaining(), and Botan::BufferSlicer::take().
Referenced by Botan::BLAKE2b::add_data(), and Botan::MerkleDamgard_Hash< MD >::update().
|
inline |
Appends the provided elements
to the buffer. The user has to make sure that elements
fits in the remaining capacity of the buffer.
Definition at line 91 of file alignment_buffer.h.
References BOTAN_ASSERT_NOMSG.
Referenced by Botan::Streebog::final_result().
|
inline |
Definition at line 72 of file alignment_buffer.h.
References Botan::clear_mem().
Referenced by Botan::BLAKE2b::clear(), Botan::GMAC::clear(), Botan::GOST_34_11::clear(), Botan::MerkleDamgard_Hash< MD >::clear(), Botan::Poly1305::clear(), Botan::Skein_512::clear(), and Botan::Streebog::clear().
|
inlinenodiscard |
Explicitly consume the currently collected block. It is the caller's responsibility to ensure that the buffer is filled fully. After consumption, the buffer is cleared and ready to collect new data.
Definition at line 201 of file alignment_buffer.h.
References BOTAN_ASSERT_NOMSG.
Referenced by Botan::BLAKE2b::final_result(), and Botan::Streebog::final_result().
|
inlinenodiscard |
Explicitly consumes however many bytes are currently stored in the buffer. After consumption, the buffer is cleared and ready to collect new data.
Definition at line 212 of file alignment_buffer.h.
|
inlineconstexpr |
Definition at line 234 of file alignment_buffer.h.
References Botan::must_be_deferred.
|
inline |
Allows direct modification of the first elements
in the buffer. This is a low-level accessor that neither takes the buffer's current capacity into account nor does it change the internal cursor. Beware not to overwrite unconsumed bytes.
Definition at line 103 of file alignment_buffer.h.
References BOTAN_ASSERT_NOMSG.
Referenced by Botan::Streebog::final_result().
|
inline |
Allows direct modification of the last elements
in the buffer. This is a low-level accessor that neither takes the buffer's current capacity into account nor does it change the internal cursor. Beware not to overwrite unconsumed bytes.
Definition at line 114 of file alignment_buffer.h.
References BOTAN_ASSERT_NOMSG.
|
inline |
Definition at line 220 of file alignment_buffer.h.
Referenced by Botan::BLAKE2b::final_result(), and Botan::Streebog::final_result().
|
inline |
Definition at line 222 of file alignment_buffer.h.
|
inline |
Fills the currently unused bytes of the buffer with zero bytes
Definition at line 80 of file alignment_buffer.h.
References Botan::clear_mem().
Referenced by Botan::BLAKE2b::final_result(), and Botan::Streebog::final_result().
|
inlinenodiscard |
Intermittently buffers potentially unaligned data provided in slicer
. If the internal buffer already contains some elements, data is appended. Once a full block is collected, it is returned to the caller for processing.
slicer | the input data source to be (partially) consumed |
Definition at line 167 of file alignment_buffer.h.
References Botan::BufferSlicer::empty(), Botan::BufferSlicer::remaining(), and Botan::BufferSlicer::take().
Referenced by Botan::BLAKE2b::add_data(), Botan::Streebog::add_data(), and Botan::MerkleDamgard_Hash< MD >::update().
|
inline |
Definition at line 227 of file alignment_buffer.h.
Referenced by Botan::BLAKE2b::add_data(), Botan::Streebog::add_data(), and Botan::MerkleDamgard_Hash< MD >::update().
|
inlinenodiscard |
Once the buffer reached alignment, this can be used to consume full blocks from the input data represented by slicer
.
slicer
or std::nullopt if not enough data is available in slicer
. Definition at line 144 of file alignment_buffer.h.
References BOTAN_ASSERT_NOMSG, Botan::BufferSlicer::remaining(), and Botan::BufferSlicer::take().
Referenced by Botan::Streebog::add_data().
|
defaultnoexcept |
|
default |
|
inline |
Definition at line 232 of file alignment_buffer.h.
|
inlineconstexpr |
Definition at line 218 of file alignment_buffer.h.
Referenced by Botan::BLAKE2b::key_schedule().