blob: 2945173f421d16ab6304258e3cfb55eeff04a944 [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
danzh02893172019-06-05 15:54:11 -07008#include <vector>
9
QUICHE teama6ef0a62019-03-07 20:34:33 -050010#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
dmcardle904ef182019-12-13 08:34:33 -080011#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050012
13namespace quic {
14
15// QuicHKDF implements the key derivation function specified in RFC 5869
16// (using SHA-256) and outputs key material, as needed by QUIC.
17// See https://tools.ietf.org/html/rfc5869 for details.
dschinazif25169a2019-10-23 08:12:18 -070018class QUIC_EXPORT_PRIVATE QuicHKDF {
QUICHE teama6ef0a62019-03-07 20:34:33 -050019 public:
20 // |secret|: the input shared secret (or, from RFC 5869, the IKM).
21 // |salt|: an (optional) public salt / non-secret random value. While
22 // optional, callers are strongly recommended to provide a salt. There is no
23 // added security value in making this larger than the SHA-256 block size of
24 // 64 bytes.
25 // |info|: an (optional) label to distinguish different uses of HKDF. It is
26 // optional context and application specific information (can be a zero-length
27 // string).
28 // |key_bytes_to_generate|: the number of bytes of key material to generate
29 // for both client and server.
30 // |iv_bytes_to_generate|: the number of bytes of IV to generate for both
31 // client and server.
32 // |subkey_secret_bytes_to_generate|: the number of bytes of subkey secret to
33 // generate, shared between client and server.
dmcardle904ef182019-12-13 08:34:33 -080034 QuicHKDF(quiche::QuicheStringPiece secret,
35 quiche::QuicheStringPiece salt,
36 quiche::QuicheStringPiece info,
QUICHE teama6ef0a62019-03-07 20:34:33 -050037 size_t key_bytes_to_generate,
38 size_t iv_bytes_to_generate,
39 size_t subkey_secret_bytes_to_generate);
40
41 // An alternative constructor that allows the client and server key/IV
42 // lengths to be different.
dmcardle904ef182019-12-13 08:34:33 -080043 QuicHKDF(quiche::QuicheStringPiece secret,
44 quiche::QuicheStringPiece salt,
45 quiche::QuicheStringPiece info,
QUICHE teama6ef0a62019-03-07 20:34:33 -050046 size_t client_key_bytes_to_generate,
47 size_t server_key_bytes_to_generate,
48 size_t client_iv_bytes_to_generate,
49 size_t server_iv_bytes_to_generate,
50 size_t subkey_secret_bytes_to_generate);
51
52 ~QuicHKDF();
53
dmcardle904ef182019-12-13 08:34:33 -080054 quiche::QuicheStringPiece client_write_key() const {
55 return client_write_key_;
56 }
57 quiche::QuicheStringPiece client_write_iv() const { return client_write_iv_; }
58 quiche::QuicheStringPiece server_write_key() const {
59 return server_write_key_;
60 }
61 quiche::QuicheStringPiece server_write_iv() const { return server_write_iv_; }
62 quiche::QuicheStringPiece subkey_secret() const { return subkey_secret_; }
63 quiche::QuicheStringPiece client_hp_key() const { return client_hp_key_; }
64 quiche::QuicheStringPiece server_hp_key() const { return server_hp_key_; }
QUICHE teama6ef0a62019-03-07 20:34:33 -050065
66 private:
67 std::vector<uint8_t> output_;
68
dmcardle904ef182019-12-13 08:34:33 -080069 quiche::QuicheStringPiece client_write_key_;
70 quiche::QuicheStringPiece server_write_key_;
71 quiche::QuicheStringPiece client_write_iv_;
72 quiche::QuicheStringPiece server_write_iv_;
73 quiche::QuicheStringPiece subkey_secret_;
74 quiche::QuicheStringPiece client_hp_key_;
75 quiche::QuicheStringPiece server_hp_key_;
QUICHE teama6ef0a62019-03-07 20:34:33 -050076};
77
78} // namespace quic
79
80#endif // QUICHE_QUIC_CORE_CRYPTO_QUIC_HKDF_H_