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