xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/quic/core/crypto/null_decrypter.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // 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 
11 #include "absl/numeric/int128.h"
12 #include "absl/strings/string_view.h"
13 #include "quiche/quic/core/crypto/quic_decrypter.h"
14 #include "quiche/quic/core/quic_types.h"
15 #include "quiche/quic/platform/api/quic_export.h"
16 
17 namespace quic {
18 
19 class 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.
24 class QUICHE_EXPORT NullDecrypter : public QuicDecrypter {
25  public:
26   explicit NullDecrypter(Perspective perspective);
27   NullDecrypter(const NullDecrypter&) = delete;
28   NullDecrypter& operator=(const NullDecrypter&) = delete;
~NullDecrypter()29   ~NullDecrypter() override {}
30 
31   // QuicDecrypter implementation
32   bool SetKey(absl::string_view key) override;
33   bool SetNoncePrefix(absl::string_view nonce_prefix) override;
34   bool SetIV(absl::string_view iv) override;
35   bool SetHeaderProtectionKey(absl::string_view key) override;
36   bool SetPreliminaryKey(absl::string_view key) override;
37   bool SetDiversificationNonce(const DiversificationNonce& nonce) override;
38   bool DecryptPacket(uint64_t packet_number, absl::string_view associated_data,
39                      absl::string_view ciphertext, char* output,
40                      size_t* output_length, size_t max_output_length) override;
41   std::string GenerateHeaderProtectionMask(
42       QuicDataReader* sample_reader) override;
43   size_t GetKeySize() const override;
44   size_t GetNoncePrefixSize() const override;
45   size_t GetIVSize() const override;
46   absl::string_view GetKey() const override;
47   absl::string_view GetNoncePrefix() const override;
48 
49   uint32_t cipher_id() const override;
50   QuicPacketCount GetIntegrityLimit() const override;
51 
52  private:
53   bool ReadHash(QuicDataReader* reader, absl::uint128* hash);
54   absl::uint128 ComputeHash(absl::string_view data1,
55                             absl::string_view data2) const;
56 
57   Perspective perspective_;
58 };
59 
60 }  // namespace quic
61 
62 #endif  // QUICHE_QUIC_CORE_CRYPTO_NULL_DECRYPTER_H_
63