botan icon indicating copy to clipboard operation
botan copied to clipboard

Add `Hash_Function::final_truncated()`

Open reneme opened this issue 1 year ago • 0 comments

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

reneme avatar Jan 09 '25 17:01 reneme