blob: c57b894b52ced4dee33972f0ffeb6f69b4c69b83 [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright 2018 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef QUICHE_QUIC_CORE_CRYPTO_QUIC_HKDF_H_
6#define QUICHE_QUIC_CORE_CRYPTO_QUIC_HKDF_H_
7
8#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
9#include "net/third_party/quiche/src/quic/platform/api/quic_string_piece.h"
10
11namespace quic {
12
13// QuicHKDF implements the key derivation function specified in RFC 5869
14// (using SHA-256) and outputs key material, as needed by QUIC.
15// See https://tools.ietf.org/html/rfc5869 for details.
16class QUIC_EXPORT QuicHKDF {
17 public:
18 // |secret|: the input shared secret (or, from RFC 5869, the IKM).
19 // |salt|: an (optional) public salt / non-secret random value. While
20 // optional, callers are strongly recommended to provide a salt. There is no
21 // added security value in making this larger than the SHA-256 block size of
22 // 64 bytes.
23 // |info|: an (optional) label to distinguish different uses of HKDF. It is
24 // optional context and application specific information (can be a zero-length
25 // string).
26 // |key_bytes_to_generate|: the number of bytes of key material to generate
27 // for both client and server.
28 // |iv_bytes_to_generate|: the number of bytes of IV to generate for both
29 // client and server.
30 // |subkey_secret_bytes_to_generate|: the number of bytes of subkey secret to
31 // generate, shared between client and server.
32 QuicHKDF(QuicStringPiece secret,
33 QuicStringPiece salt,
34 QuicStringPiece info,
35 size_t key_bytes_to_generate,
36 size_t iv_bytes_to_generate,
37 size_t subkey_secret_bytes_to_generate);
38
39 // An alternative constructor that allows the client and server key/IV
40 // lengths to be different.
41 QuicHKDF(QuicStringPiece secret,
42 QuicStringPiece salt,
43 QuicStringPiece info,
44 size_t client_key_bytes_to_generate,
45 size_t server_key_bytes_to_generate,
46 size_t client_iv_bytes_to_generate,
47 size_t server_iv_bytes_to_generate,
48 size_t subkey_secret_bytes_to_generate);
49
50 ~QuicHKDF();
51
52 QuicStringPiece client_write_key() const { return client_write_key_; }
53 QuicStringPiece client_write_iv() const { return client_write_iv_; }
54 QuicStringPiece server_write_key() const { return server_write_key_; }
55 QuicStringPiece server_write_iv() const { return server_write_iv_; }
56 QuicStringPiece subkey_secret() const { return subkey_secret_; }
nharper55fa6132019-05-07 19:37:21 -070057 QuicStringPiece client_hp_key() const { return client_hp_key_; }
58 QuicStringPiece server_hp_key() const { return server_hp_key_; }
QUICHE teama6ef0a62019-03-07 20:34:33 -050059
60 private:
61 std::vector<uint8_t> output_;
62
63 QuicStringPiece client_write_key_;
64 QuicStringPiece server_write_key_;
65 QuicStringPiece client_write_iv_;
66 QuicStringPiece server_write_iv_;
67 QuicStringPiece subkey_secret_;
nharper55fa6132019-05-07 19:37:21 -070068 QuicStringPiece client_hp_key_;
69 QuicStringPiece server_hp_key_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050070};
71
72} // namespace quic
73
74#endif // QUICHE_QUIC_CORE_CRYPTO_QUIC_HKDF_H_