proxygen
KeyDerivation.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 #pragma once
10 
11 #include <fizz/crypto/Hkdf.h>
12 #include <fizz/record/Types.h>
13 
14 namespace fizz {
15 
20  public:
21  virtual ~KeyDerivation() = default;
22 
23  virtual size_t hashLength() const = 0;
24 
28  virtual folly::ByteRange blankHash() const = 0;
29 
30  virtual Buf expandLabel(
33  Buf hashValue,
34  uint16_t length) = 0;
35 
36  virtual std::vector<uint8_t> deriveSecret(
37  folly::ByteRange secret,
38  folly::StringPiece label,
39  folly::ByteRange messageHash) = 0;
40 
44  virtual Buf
45  hkdfExpand(folly::ByteRange secret, Buf info, uint16_t length) = 0;
46 
47  virtual std::vector<uint8_t> hkdfExtract(
48  folly::ByteRange salt,
49  folly::ByteRange ikm) = 0;
50 
51  virtual void hash(const folly::IOBuf& in, folly::MutableByteRange out) = 0;
52 
53  virtual void hmac(
54  folly::ByteRange key,
55  const folly::IOBuf& in,
56  folly::MutableByteRange out) = 0;
57 };
58 
59 template <typename Hash>
61  public:
62  ~KeyDerivationImpl() override = default;
63 
64  KeyDerivationImpl(const std::string& labelPrefix);
65 
66  size_t hashLength() const override {
67  return Hash::HashLen;
68  }
69 
70  void hash(const folly::IOBuf& in, folly::MutableByteRange out) override {
71  Hash::hash(in, out);
72  }
73 
74  void hmac(
75  folly::ByteRange key,
76  const folly::IOBuf& in,
77  folly::MutableByteRange out) override {
78  Hash::hmac(key, in, out);
79  }
80 
81  folly::ByteRange blankHash() const override {
82  return Hash::BlankHash;
83  }
84 
88  Buf hashValue,
89  uint16_t length) override;
90 
91  std::vector<uint8_t> deriveSecret(
92  folly::ByteRange secret,
93  folly::StringPiece label,
94  folly::ByteRange messageHash) override;
95 
96  virtual Buf hkdfExpand(folly::ByteRange secret, Buf info, uint16_t length)
97  override;
98 
99  std::vector<uint8_t> hkdfExtract(folly::ByteRange salt, folly::ByteRange ikm)
100  override {
101  return HkdfImpl<Hash>().extract(salt, ikm);
102  }
103 
104  private:
106 };
107 } // namespace fizz
108 
void hash(const folly::IOBuf &in, folly::MutableByteRange out) override
Definition: KeyDerivation.h:70
virtual size_t hashLength() const =0
def info()
Definition: deadlock.py:447
std::vector< uint8_t > hkdfExtract(folly::ByteRange salt, folly::ByteRange ikm) override
Definition: KeyDerivation.h:99
folly::ByteRange blankHash() const override
Definition: KeyDerivation.h:81
virtual void hmac(folly::ByteRange key, const folly::IOBuf &in, folly::MutableByteRange out)=0
Definition: Actions.h:16
virtual folly::ByteRange blankHash() const =0
virtual Buf hkdfExpand(folly::ByteRange secret, Buf info, uint16_t length)=0
virtual std::vector< uint8_t > hkdfExtract(folly::ByteRange salt, folly::ByteRange ikm)=0
virtual Buf expandLabel(folly::ByteRange secret, folly::StringPiece label, Buf hashValue, uint16_t length)=0
const char * string
Definition: Conv.cpp:212
std::unique_ptr< folly::IOBuf > Buf
Definition: Types.h:22
virtual void hash(const folly::IOBuf &in, folly::MutableByteRange out)=0
static constexpr StringPiece secret
void hmac(folly::ByteRange key, const folly::IOBuf &in, folly::MutableByteRange out) override
Definition: KeyDerivation.h:74
virtual ~KeyDerivation()=default
size_t hashLength() const override
Definition: KeyDerivation.h:66
virtual std::vector< uint8_t > deriveSecret(folly::ByteRange secret, folly::StringPiece label, folly::ByteRange messageHash)=0
StringPiece label