| 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 | 13 |
| 14 #if defined(USE_OPENSSL) | |
| 15 #include "net/quic/crypto/scoped_evp_aead_ctx.h" | 14 #include "net/quic/crypto/scoped_evp_aead_ctx.h" |
| 16 #else | |
| 17 #include <pkcs11t.h> | |
| 18 #endif | |
| 19 | 15 |
| 20 namespace net { | 16 namespace net { |
| 21 | 17 |
| 22 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses. | 18 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses. |
| 23 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter { | 19 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter { |
| 24 public: | 20 public: |
| 25 #if defined(USE_OPENSSL) | |
| 26 AeadBaseDecrypter(const EVP_AEAD* aead_alg, | 21 AeadBaseDecrypter(const EVP_AEAD* aead_alg, |
| 27 size_t key_size, | 22 size_t key_size, |
| 28 size_t auth_tag_size, | 23 size_t auth_tag_size, |
| 29 size_t nonce_prefix_size); | 24 size_t nonce_prefix_size); |
| 30 #else | |
| 31 AeadBaseDecrypter(CK_MECHANISM_TYPE aead_mechanism, | |
| 32 size_t key_size, | |
| 33 size_t auth_tag_size, | |
| 34 size_t nonce_prefix_size); | |
| 35 #endif | |
| 36 ~AeadBaseDecrypter() override; | 25 ~AeadBaseDecrypter() override; |
| 37 | 26 |
| 38 // QuicDecrypter implementation | 27 // QuicDecrypter implementation |
| 39 bool SetKey(base::StringPiece key) override; | 28 bool SetKey(base::StringPiece key) override; |
| 40 bool SetNoncePrefix(base::StringPiece nonce_prefix) override; | 29 bool SetNoncePrefix(base::StringPiece nonce_prefix) override; |
| 41 bool DecryptPacket(QuicPathId path_id, | 30 bool DecryptPacket(QuicPathId path_id, |
| 42 QuicPacketNumber packet_number, | 31 QuicPacketNumber packet_number, |
| 43 base::StringPiece associated_data, | 32 base::StringPiece associated_data, |
| 44 base::StringPiece ciphertext, | 33 base::StringPiece ciphertext, |
| 45 char* output, | 34 char* output, |
| 46 size_t* output_length, | 35 size_t* output_length, |
| 47 size_t max_output_length) override; | 36 size_t max_output_length) override; |
| 48 base::StringPiece GetKey() const override; | 37 base::StringPiece GetKey() const override; |
| 49 base::StringPiece GetNoncePrefix() const override; | 38 base::StringPiece GetNoncePrefix() const override; |
| 50 | 39 |
| 51 protected: | 40 protected: |
| 52 // Make these constants available to the subclasses so that the subclasses | 41 // Make these constants available to the subclasses so that the subclasses |
| 53 // can assert at compile time their key_size_ and nonce_prefix_size_ do not | 42 // can assert at compile time their key_size_ and nonce_prefix_size_ do not |
| 54 // exceed the maximum. | 43 // exceed the maximum. |
| 55 static const size_t kMaxKeySize = 32; | 44 static const size_t kMaxKeySize = 32; |
| 56 static const size_t kMaxNoncePrefixSize = 4; | 45 static const size_t kMaxNoncePrefixSize = 4; |
| 57 | 46 |
| 58 #if !defined(USE_OPENSSL) | |
| 59 struct AeadParams { | |
| 60 unsigned int len; | |
| 61 union { | |
| 62 CK_GCM_PARAMS gcm_params; | |
| 63 CK_NSS_AEAD_PARAMS nss_aead_params; | |
| 64 } data; | |
| 65 }; | |
| 66 | |
| 67 virtual void FillAeadParams(base::StringPiece nonce, | |
| 68 base::StringPiece associated_data, | |
| 69 size_t auth_tag_size, | |
| 70 AeadParams* aead_params) const = 0; | |
| 71 #endif // !defined(USE_OPENSSL) | |
| 72 | |
| 73 private: | 47 private: |
| 74 #if defined(USE_OPENSSL) | |
| 75 const EVP_AEAD* const aead_alg_; | 48 const EVP_AEAD* const aead_alg_; |
| 76 #else | |
| 77 const CK_MECHANISM_TYPE aead_mechanism_; | |
| 78 #endif | |
| 79 const size_t key_size_; | 49 const size_t key_size_; |
| 80 const size_t auth_tag_size_; | 50 const size_t auth_tag_size_; |
| 81 const size_t nonce_prefix_size_; | 51 const size_t nonce_prefix_size_; |
| 82 | 52 |
| 83 // The key. | 53 // The key. |
| 84 unsigned char key_[kMaxKeySize]; | 54 unsigned char key_[kMaxKeySize]; |
| 85 // The nonce prefix. | 55 // The nonce prefix. |
| 86 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; | 56 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; |
| 87 | 57 |
| 88 #if defined(USE_OPENSSL) | |
| 89 ScopedEVPAEADCtx ctx_; | 58 ScopedEVPAEADCtx ctx_; |
| 90 #endif | |
| 91 | 59 |
| 92 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); | 60 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); |
| 93 }; | 61 }; |
| 94 | 62 |
| 95 } // namespace net | 63 } // namespace net |
| 96 | 64 |
| 97 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ | 65 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ |
| OLD | NEW |