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 "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "net/quic/crypto/quic_decrypter.h" | 9 #include "net/quic/crypto/quic_decrypter.h" |
10 | 10 |
(...skipping 24 matching lines...) Expand all Loading... |
35 PK11_DecryptFunction pk11_decrypt, | 35 PK11_DecryptFunction pk11_decrypt, |
36 size_t key_size, | 36 size_t key_size, |
37 size_t auth_tag_size, | 37 size_t auth_tag_size, |
38 size_t nonce_prefix_size); | 38 size_t nonce_prefix_size); |
39 #endif | 39 #endif |
40 ~AeadBaseDecrypter() override; | 40 ~AeadBaseDecrypter() override; |
41 | 41 |
42 // QuicDecrypter implementation | 42 // QuicDecrypter implementation |
43 bool SetKey(base::StringPiece key) override; | 43 bool SetKey(base::StringPiece key) override; |
44 bool SetNoncePrefix(base::StringPiece nonce_prefix) override; | 44 bool SetNoncePrefix(base::StringPiece nonce_prefix) override; |
45 QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number, | 45 bool DecryptPacket(QuicPacketSequenceNumber sequence_number, |
46 base::StringPiece associated_data, | 46 const base::StringPiece& associated_data, |
47 base::StringPiece ciphertext) override; | 47 const base::StringPiece& ciphertext, |
| 48 char* output, |
| 49 size_t* output_length, |
| 50 size_t max_output_length) override; |
48 base::StringPiece GetKey() const override; | 51 base::StringPiece GetKey() const override; |
49 base::StringPiece GetNoncePrefix() const override; | 52 base::StringPiece GetNoncePrefix() const override; |
50 | 53 |
51 protected: | 54 protected: |
52 // Make these constants available to the subclasses so that the subclasses | 55 // 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 | 56 // can assert at compile time their key_size_ and nonce_prefix_size_ do not |
54 // exceed the maximum. | 57 // exceed the maximum. |
55 static const size_t kMaxKeySize = 32; | 58 static const size_t kMaxKeySize = 32; |
56 static const size_t kMaxNoncePrefixSize = 4; | 59 static const size_t kMaxNoncePrefixSize = 4; |
57 | 60 |
58 #if !defined(USE_OPENSSL) | 61 #if !defined(USE_OPENSSL) |
59 struct AeadParams { | 62 struct AeadParams { |
60 unsigned int len; | 63 unsigned int len; |
61 union { | 64 union { |
62 CK_GCM_PARAMS gcm_params; | 65 CK_GCM_PARAMS gcm_params; |
63 #if !defined(USE_NSS) | 66 #if !defined(USE_NSS) |
64 // USE_NSS means we are using system NSS rather than our copy of NSS. | 67 // USE_NSS means we are using system NSS rather than our copy of NSS. |
65 // The system NSS <pkcs11n.h> header doesn't define this type yet. | 68 // The system NSS <pkcs11n.h> header doesn't define this type yet. |
66 CK_NSS_AEAD_PARAMS nss_aead_params; | 69 CK_NSS_AEAD_PARAMS nss_aead_params; |
67 #endif | 70 #endif |
68 } data; | 71 } data; |
69 }; | 72 }; |
70 | 73 |
71 virtual void FillAeadParams(base::StringPiece nonce, | 74 virtual void FillAeadParams(base::StringPiece nonce, |
72 base::StringPiece associated_data, | 75 const base::StringPiece& associated_data, |
73 size_t auth_tag_size, | 76 size_t auth_tag_size, |
74 AeadParams* aead_params) const = 0; | 77 AeadParams* aead_params) const = 0; |
75 #endif // !defined(USE_OPENSSL) | 78 #endif // !defined(USE_OPENSSL) |
76 | 79 |
77 private: | 80 private: |
78 bool Decrypt(base::StringPiece nonce, | 81 bool Decrypt(base::StringPiece nonce, |
79 base::StringPiece associated_data, | 82 const base::StringPiece& associated_data, |
80 base::StringPiece ciphertext, | 83 const base::StringPiece& ciphertext, |
81 unsigned char* output, | 84 uint8* output, |
82 size_t* output_length); | 85 size_t* output_length, |
| 86 size_t max_output_length); |
83 | 87 |
84 #if defined(USE_OPENSSL) | 88 #if defined(USE_OPENSSL) |
85 const EVP_AEAD* const aead_alg_; | 89 const EVP_AEAD* const aead_alg_; |
86 #else | 90 #else |
87 const CK_MECHANISM_TYPE aead_mechanism_; | 91 const CK_MECHANISM_TYPE aead_mechanism_; |
88 const PK11_DecryptFunction pk11_decrypt_; | 92 const PK11_DecryptFunction pk11_decrypt_; |
89 #endif | 93 #endif |
90 const size_t key_size_; | 94 const size_t key_size_; |
91 const size_t auth_tag_size_; | 95 const size_t auth_tag_size_; |
92 const size_t nonce_prefix_size_; | 96 const size_t nonce_prefix_size_; |
93 | 97 |
94 // The key. | 98 // The key. |
95 unsigned char key_[kMaxKeySize]; | 99 unsigned char key_[kMaxKeySize]; |
96 // The nonce prefix. | 100 // The nonce prefix. |
97 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; | 101 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; |
98 | 102 |
99 #if defined(USE_OPENSSL) | 103 #if defined(USE_OPENSSL) |
100 ScopedEVPAEADCtx ctx_; | 104 ScopedEVPAEADCtx ctx_; |
101 #endif | 105 #endif |
102 | 106 |
103 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); | 107 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); |
104 }; | 108 }; |
105 | 109 |
106 } // namespace net | 110 } // namespace net |
107 | 111 |
108 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ | 112 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ |
OLD | NEW |