11 template <
typename Hash>
15 auto zeros = std::vector<uint8_t>(Hash::HashLen, 0);
17 std::vector<uint8_t> extractedKey(Hash::HashLen);
24 template <
typename Hash>
28 size_t outputBytes)
const {
29 CHECK_EQ(extractedKey.
size(), Hash::HashLen);
30 if (
UNLIKELY(outputBytes > 255 * Hash::HashLen)) {
31 throw std::runtime_error(
"Output too long");
34 size_t numRounds = (outputBytes + Hash::HashLen - 1) / Hash::HashLen;
39 in->prependChain(info.
clone());
45 roundNum->writableData()[0] =
round;
48 size_t outputStartIdx = (
round - 1) * Hash::HashLen;
52 {expanded->writableData() + outputStartIdx, Hash::HashLen});
53 expanded->append(Hash::HashLen);
55 in = expanded->clone();
56 in->trimStart(outputStartIdx);
58 expanded->trimEnd(numRounds * Hash::HashLen - outputBytes);
62 template <
typename Hash>
67 size_t outputBytes)
const {
68 return expand(
folly::range(extract(salt, ikm)), info, outputBytes);
static std::unique_ptr< IOBuf > create(std::size_t capacity)
constexpr To round(std::chrono::duration< Rep, Period > const &d)
std::unique_ptr< folly::IOBuf > hkdf(folly::ByteRange ikm, folly::ByteRange salt, const folly::IOBuf &info, size_t outputBytes) const override
constexpr detail::Map< Move > move
constexpr size_type size() const
std::unique_ptr< IOBuf > clone() const
constexpr bool empty() const
constexpr Range< Iter > range(Iter first, Iter last)
static IOBuf wrapBufferAsValue(const void *buf, std::size_t capacity) noexcept
std::unique_ptr< folly::IOBuf > expand(folly::ByteRange extractedKey, const folly::IOBuf &info, size_t outputBytes) const override
std::vector< uint8_t > extract(folly::ByteRange salt, folly::ByteRange ikm) const override