botan
botan copied to clipboard
Add `Hash_Function::final_truncated()`
For certain applications it would actually be nice if Hash_Function could truncate internally. Something like:
void Hash_Function::final_truncated(std::span<uint8_t> out) {
if(out.size() == output_length()) {
final(out);
} else {
const auto h = final();
copy_mem(out, std::span{h}.first(out.size()));
}
}
Or perhaps even pass the shorter span down into the individual hash functions to partially-copy straight from the hash's internal state (if possible).
Originally posted by @reneme in https://github.com/randombit/botan/pull/4455#discussion_r1908443873