proxygen
fizz::KeyDerivationImpl< Hash > Class Template Reference

#include <KeyDerivation.h>

Inheritance diagram for fizz::KeyDerivationImpl< Hash >:
fizz::KeyDerivation

Public Member Functions

 ~KeyDerivationImpl () override=default
 
 KeyDerivationImpl (const std::string &labelPrefix)
 
size_t hashLength () const override
 
void hash (const folly::IOBuf &in, folly::MutableByteRange out) override
 
void hmac (folly::ByteRange key, const folly::IOBuf &in, folly::MutableByteRange out) override
 
folly::ByteRange blankHash () const override
 
Buf expandLabel (folly::ByteRange secret, folly::StringPiece label, Buf hashValue, uint16_t length) override
 
std::vector< uint8_tderiveSecret (folly::ByteRange secret, folly::StringPiece label, folly::ByteRange messageHash) override
 
virtual Buf hkdfExpand (folly::ByteRange secret, Buf info, uint16_t length) override
 
std::vector< uint8_thkdfExtract (folly::ByteRange salt, folly::ByteRange ikm) override
 
- Public Member Functions inherited from fizz::KeyDerivation
virtual ~KeyDerivation ()=default
 

Private Attributes

std::string labelPrefix_
 

Detailed Description

template<typename Hash>
class fizz::KeyDerivationImpl< Hash >

Definition at line 60 of file KeyDerivation.h.

Constructor & Destructor Documentation

template<typename Hash>
fizz::KeyDerivationImpl< Hash >::~KeyDerivationImpl ( )
overridedefault
template<typename Hash >
fizz::KeyDerivationImpl< Hash >::KeyDerivationImpl ( const std::string labelPrefix)

Definition at line 12 of file KeyDerivation-inl.h.

13  : labelPrefix_(labelPrefix) {}

Member Function Documentation

template<typename Hash>
folly::ByteRange fizz::KeyDerivationImpl< Hash >::blankHash ( ) const
inlineoverridevirtual

Returns the hash of a blank input (ie Hash("")).

Implements fizz::KeyDerivation.

Definition at line 81 of file KeyDerivation.h.

References fizz::KeyDerivation::deriveSecret(), fizz::KeyDerivation::expandLabel(), fizz::KeyDerivation::hkdfExpand(), deadlock::info(), fizz::test::label, secret, and uint16_t.

81  {
82  return Hash::BlankHash;
83  }
template<typename Hash >
std::vector< uint8_t > fizz::KeyDerivationImpl< Hash >::deriveSecret ( folly::ByteRange  secret,
folly::StringPiece  label,
folly::ByteRange  messageHash 
)
overridevirtual

Implements fizz::KeyDerivation.

Definition at line 36 of file KeyDerivation-inl.h.

References folly::IOBuf::copyBuffer(), fizz::KeyDerivationImpl< Hash >::expandLabel(), min, folly::gen::move, and folly::Range< Iter >::size().

39  {
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 }
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr size_type size() const
Definition: Range.h:431
Buf expandLabel(folly::ByteRange secret, folly::StringPiece label, Buf hashValue, uint16_t length) override
LogLevel min
Definition: LogLevel.cpp:30
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
template<typename Hash >
Buf fizz::KeyDerivationImpl< Hash >::expandLabel ( folly::ByteRange  secret,
folly::StringPiece  label,
Buf  hashValue,
uint16_t  length 
)
overridevirtual

Implements fizz::KeyDerivation.

Definition at line 16 of file KeyDerivation-inl.h.

References folly::Range< Iter >::begin(), fizz::encodeHkdfLabel(), folly::Range< Iter >::end(), fizz::KeyDerivationImpl< Hash >::labelPrefix_, folly::gen::move, and string.

Referenced by fizz::KeyDerivationImpl< Hash >::deriveSecret().

20  {
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 }
Buf encodeHkdfLabel(HkdfLabel &&label, const std::string &hkdfLabelPrefix)
Definition: Types-inl.h:488
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
constexpr Iter end() const
Definition: Range.h:455
constexpr Iter begin() const
Definition: Range.h:452
const char * string
Definition: Conv.cpp:212
template<typename Hash>
void fizz::KeyDerivationImpl< Hash >::hash ( const folly::IOBuf in,
folly::MutableByteRange  out 
)
inlineoverridevirtual

Implements fizz::KeyDerivation.

Definition at line 70 of file KeyDerivation.h.

70  {
71  Hash::hash(in, out);
72  }
template<typename Hash>
size_t fizz::KeyDerivationImpl< Hash >::hashLength ( ) const
inlineoverridevirtual

Implements fizz::KeyDerivation.

Definition at line 66 of file KeyDerivation.h.

66  {
67  return Hash::HashLen;
68  }
template<typename Hash >
Buf fizz::KeyDerivationImpl< Hash >::hkdfExpand ( folly::ByteRange  secret,
Buf  info,
uint16_t  length 
)
overridevirtual

Performs HDKF expansion.

Implements fizz::KeyDerivation.

Definition at line 28 of file KeyDerivation-inl.h.

31  {
32  return HkdfImpl<Hash>().expand(secret, *info, length);
33 }
def info()
Definition: deadlock.py:447
template<typename Hash>
std::vector<uint8_t> fizz::KeyDerivationImpl< Hash >::hkdfExtract ( folly::ByteRange  salt,
folly::ByteRange  ikm 
)
inlineoverridevirtual

Implements fizz::KeyDerivation.

Definition at line 99 of file KeyDerivation.h.

100  {
101  return HkdfImpl<Hash>().extract(salt, ikm);
102  }
template<typename Hash>
void fizz::KeyDerivationImpl< Hash >::hmac ( folly::ByteRange  key,
const folly::IOBuf in,
folly::MutableByteRange  out 
)
inlineoverridevirtual

Implements fizz::KeyDerivation.

Definition at line 74 of file KeyDerivation.h.

77  {
78  Hash::hmac(key, in, out);
79  }

Member Data Documentation

template<typename Hash>
std::string fizz::KeyDerivationImpl< Hash >::labelPrefix_
private

Definition at line 105 of file KeyDerivation.h.

Referenced by fizz::KeyDerivationImpl< Hash >::expandLabel().


The documentation for this class was generated from the following files: