blob: c3bd203f5d588153caf7743ad8cc81116162552e [file] [log] [blame]
QUICHE teama6ef0a62019-03-07 20:34:33 -05001// Copyright (c) 2012 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_NULL_DECRYPTER_H_
6#define QUICHE_QUIC_CORE_CRYPTO_NULL_DECRYPTER_H_
7
8#include <cstddef>
9#include <cstdint>
10
QUICHE teama6ef0a62019-03-07 20:34:33 -050011#include "net/third_party/quiche/src/quic/core/crypto/quic_decrypter.h"
12#include "net/third_party/quiche/src/quic/core/quic_types.h"
13#include "net/third_party/quiche/src/quic/platform/api/quic_export.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050014#include "net/third_party/quiche/src/quic/platform/api/quic_uint128.h"
dmcardle904ef182019-12-13 08:34:33 -080015#include "net/third_party/quiche/src/common/platform/api/quiche_string_piece.h"
QUICHE teama6ef0a62019-03-07 20:34:33 -050016
17namespace quic {
18
19class QuicDataReader;
20
21// A NullDecrypter is a QuicDecrypter used before a crypto negotiation
22// has occurred. It does not actually decrypt the payload, but does
23// verify a hash (fnv128) over both the payload and associated data.
24class QUIC_EXPORT_PRIVATE NullDecrypter : public QuicDecrypter {
25 public:
26 explicit NullDecrypter(Perspective perspective);
27 NullDecrypter(const NullDecrypter&) = delete;
28 NullDecrypter& operator=(const NullDecrypter&) = delete;
29 ~NullDecrypter() override {}
30
31 // QuicDecrypter implementation
dmcardle904ef182019-12-13 08:34:33 -080032 bool SetKey(quiche::QuicheStringPiece key) override;
33 bool SetNoncePrefix(quiche::QuicheStringPiece nonce_prefix) override;
34 bool SetIV(quiche::QuicheStringPiece iv) override;
35 bool SetHeaderProtectionKey(quiche::QuicheStringPiece key) override;
36 bool SetPreliminaryKey(quiche::QuicheStringPiece key) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050037 bool SetDiversificationNonce(const DiversificationNonce& nonce) override;
38 bool DecryptPacket(uint64_t packet_number,
dmcardle904ef182019-12-13 08:34:33 -080039 quiche::QuicheStringPiece associated_data,
40 quiche::QuicheStringPiece ciphertext,
QUICHE teama6ef0a62019-03-07 20:34:33 -050041 char* output,
42 size_t* output_length,
43 size_t max_output_length) override;
QUICHE team2d187972019-03-19 16:23:47 -070044 std::string GenerateHeaderProtectionMask(
45 QuicDataReader* sample_reader) override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050046 size_t GetKeySize() const override;
nharper965e5922019-09-23 22:33:54 -070047 size_t GetNoncePrefixSize() const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050048 size_t GetIVSize() const override;
dmcardle904ef182019-12-13 08:34:33 -080049 quiche::QuicheStringPiece GetKey() const override;
50 quiche::QuicheStringPiece GetNoncePrefix() const override;
QUICHE teama6ef0a62019-03-07 20:34:33 -050051
52 uint32_t cipher_id() const override;
53
54 private:
55 bool ReadHash(QuicDataReader* reader, QuicUint128* hash);
dmcardle904ef182019-12-13 08:34:33 -080056 QuicUint128 ComputeHash(quiche::QuicheStringPiece data1,
57 quiche::QuicheStringPiece data2) const;
QUICHE teama6ef0a62019-03-07 20:34:33 -050058
59 Perspective perspective_;
60};
61
62} // namespace quic
63
64#endif // QUICHE_QUIC_CORE_CRYPTO_NULL_DECRYPTER_H_