| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ | 5 #ifndef NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ |
| 6 #define NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ | 6 #define NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "net/quic/crypto/quic_decrypter.h" | 12 #include "net/quic/crypto/quic_decrypter.h" |
| 13 #include "net/quic/crypto/scoped_evp_aead_ctx.h" | 13 #include "net/quic/crypto/scoped_evp_aead_ctx.h" |
| 14 | 14 |
| 15 namespace net { | 15 namespace net { |
| 16 | 16 |
| 17 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses. | 17 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses. |
| 18 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter { | 18 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter { |
| 19 public: | 19 public: |
| 20 AeadBaseDecrypter(const EVP_AEAD* aead_alg, | 20 AeadBaseDecrypter(const EVP_AEAD* aead_alg, |
| 21 size_t key_size, | 21 size_t key_size, |
| 22 size_t auth_tag_size, | 22 size_t auth_tag_size, |
| 23 size_t nonce_prefix_size); | 23 size_t nonce_prefix_size); |
| 24 ~AeadBaseDecrypter() override; | 24 ~AeadBaseDecrypter() override; |
| 25 | 25 |
| 26 // QuicDecrypter implementation | 26 // QuicDecrypter implementation |
| 27 bool SetKey(base::StringPiece key) override; | 27 bool SetKey(base::StringPiece key) override; |
| 28 bool SetNoncePrefix(base::StringPiece nonce_prefix) override; | 28 bool SetNoncePrefix(base::StringPiece nonce_prefix) override; |
| 29 bool SetPreliminaryKey(base::StringPiece key) override; |
| 30 bool SetDiversificationNonce(DiversificationNonce nonce) override; |
| 29 bool DecryptPacket(QuicPathId path_id, | 31 bool DecryptPacket(QuicPathId path_id, |
| 30 QuicPacketNumber packet_number, | 32 QuicPacketNumber packet_number, |
| 31 base::StringPiece associated_data, | 33 base::StringPiece associated_data, |
| 32 base::StringPiece ciphertext, | 34 base::StringPiece ciphertext, |
| 33 char* output, | 35 char* output, |
| 34 size_t* output_length, | 36 size_t* output_length, |
| 35 size_t max_output_length) override; | 37 size_t max_output_length) override; |
| 36 base::StringPiece GetKey() const override; | 38 base::StringPiece GetKey() const override; |
| 37 base::StringPiece GetNoncePrefix() const override; | 39 base::StringPiece GetNoncePrefix() const override; |
| 38 | 40 |
| 39 protected: | 41 protected: |
| 40 // Make these constants available to the subclasses so that the subclasses | 42 // Make these constants available to the subclasses so that the subclasses |
| 41 // can assert at compile time their key_size_ and nonce_prefix_size_ do not | 43 // can assert at compile time their key_size_ and nonce_prefix_size_ do not |
| 42 // exceed the maximum. | 44 // exceed the maximum. |
| 43 static const size_t kMaxKeySize = 32; | 45 static const size_t kMaxKeySize = 32; |
| 44 static const size_t kMaxNoncePrefixSize = 4; | 46 static const size_t kMaxNoncePrefixSize = 4; |
| 45 | 47 |
| 46 private: | 48 private: |
| 47 const EVP_AEAD* const aead_alg_; | 49 const EVP_AEAD* const aead_alg_; |
| 48 const size_t key_size_; | 50 const size_t key_size_; |
| 49 const size_t auth_tag_size_; | 51 const size_t auth_tag_size_; |
| 50 const size_t nonce_prefix_size_; | 52 const size_t nonce_prefix_size_; |
| 53 bool have_preliminary_key_; |
| 51 | 54 |
| 52 // The key. | 55 // The key. |
| 53 unsigned char key_[kMaxKeySize]; | 56 unsigned char key_[kMaxKeySize]; |
| 54 // The nonce prefix. | 57 // The nonce prefix. |
| 55 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; | 58 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; |
| 56 | 59 |
| 57 ScopedEVPAEADCtx ctx_; | 60 ScopedEVPAEADCtx ctx_; |
| 58 | 61 |
| 59 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); | 62 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); |
| 60 }; | 63 }; |
| 61 | 64 |
| 62 } // namespace net | 65 } // namespace net |
| 63 | 66 |
| 64 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ | 67 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ |
| OLD | NEW |