proxygen
KeyDerivation-inl.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 namespace fizz {
10 
11 template <typename Hash>
13  : labelPrefix_(labelPrefix) {}
14 
15 template <typename Hash>
19  Buf hashValue,
20  uint16_t length) {
21  HkdfLabel hkdfLabel = {
22  length, std::string(label.begin(), label.end()), std::move(hashValue)};
23  return HkdfImpl<Hash>().expand(
24  secret, *encodeHkdfLabel(std::move(hkdfLabel), labelPrefix_), length);
25 }
26 
27 template <typename Hash>
30  Buf info,
31  uint16_t length) {
32  return HkdfImpl<Hash>().expand(secret, *info, length);
33 }
34 
35 template <typename Hash>
39  folly::ByteRange messageHash) {
40  CHECK_EQ(secret.size(), Hash::HashLen);
41  CHECK_EQ(messageHash.size(), Hash::HashLen);
42  // Copying the buffer to avoid violating constness of the data.
43  auto hashBuf = folly::IOBuf::copyBuffer(messageHash);
44  auto out = expandLabel(secret, label, std::move(hashBuf), Hash::HashLen);
45  std::vector<uint8_t> prk(Hash::HashLen);
46  size_t offset = 0;
47  for (auto buf : *out) {
48  size_t remaining = Hash::HashLen - offset;
49  size_t length = std::min(buf.size(), remaining);
50  memcpy(prk.data() + offset, buf.data(), length);
51  offset += length;
52  }
53  return prk;
54 }
55 } // namespace fizz
def info()
Definition: deadlock.py:447
Buf encodeHkdfLabel(HkdfLabel &&label, const std::string &hkdfLabelPrefix)
Definition: Types-inl.h:488
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr size_type size() const
Definition: Range.h:431
virtual Buf hkdfExpand(folly::ByteRange secret, Buf info, uint16_t length) override
Buf expandLabel(folly::ByteRange secret, folly::StringPiece label, Buf hashValue, uint16_t length) override
LogLevel min
Definition: LogLevel.cpp:30
KeyDerivationImpl(const std::string &labelPrefix)
Definition: Actions.h:16
constexpr Iter end() const
Definition: Range.h:455
constexpr Iter begin() const
Definition: Range.h:452
const char * string
Definition: Conv.cpp:212
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
std::vector< uint8_t > deriveSecret(folly::ByteRange secret, folly::StringPiece label, folly::ByteRange messageHash) override
static constexpr StringPiece secret
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587
StringPiece label