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 | |
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 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses. | 17 // AeadBaseDecrypter is the base class of AEAD QuicDecrypter subclasses. |
23 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter { | 18 class NET_EXPORT_PRIVATE AeadBaseDecrypter : public QuicDecrypter { |
24 public: | 19 public: |
25 #if defined(USE_OPENSSL) | |
26 AeadBaseDecrypter(const EVP_AEAD* aead_alg, | 20 AeadBaseDecrypter(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 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; | 24 ~AeadBaseDecrypter() override; |
37 | 25 |
38 // QuicDecrypter implementation | 26 // QuicDecrypter 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 DecryptPacket(QuicPathId path_id, | 29 bool DecryptPacket(QuicPathId path_id, |
42 QuicPacketNumber packet_number, | 30 QuicPacketNumber packet_number, |
43 base::StringPiece associated_data, | 31 base::StringPiece associated_data, |
44 base::StringPiece ciphertext, | 32 base::StringPiece ciphertext, |
45 char* output, | 33 char* output, |
46 size_t* output_length, | 34 size_t* output_length, |
47 size_t max_output_length) override; | 35 size_t max_output_length) override; |
48 base::StringPiece GetKey() const override; | 36 base::StringPiece GetKey() const override; |
49 base::StringPiece GetNoncePrefix() const override; | 37 base::StringPiece GetNoncePrefix() const override; |
50 | 38 |
51 protected: | 39 protected: |
52 // Make these constants available to the subclasses so that the subclasses | 40 // 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 | 41 // can assert at compile time their key_size_ and nonce_prefix_size_ do not |
54 // exceed the maximum. | 42 // exceed the maximum. |
55 static const size_t kMaxKeySize = 32; | 43 static const size_t kMaxKeySize = 32; |
56 static const size_t kMaxNoncePrefixSize = 4; | 44 static const size_t kMaxNoncePrefixSize = 4; |
57 | 45 |
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: | 46 private: |
74 #if defined(USE_OPENSSL) | |
75 const EVP_AEAD* const aead_alg_; | 47 const EVP_AEAD* const aead_alg_; |
76 #else | |
77 const CK_MECHANISM_TYPE aead_mechanism_; | |
78 #endif | |
79 const size_t key_size_; | 48 const size_t key_size_; |
80 const size_t auth_tag_size_; | 49 const size_t auth_tag_size_; |
81 const size_t nonce_prefix_size_; | 50 const size_t nonce_prefix_size_; |
82 | 51 |
83 // The key. | 52 // The key. |
84 unsigned char key_[kMaxKeySize]; | 53 unsigned char key_[kMaxKeySize]; |
85 // The nonce prefix. | 54 // The nonce prefix. |
86 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; | 55 unsigned char nonce_prefix_[kMaxNoncePrefixSize]; |
87 | 56 |
88 #if defined(USE_OPENSSL) | |
89 ScopedEVPAEADCtx ctx_; | 57 ScopedEVPAEADCtx ctx_; |
90 #endif | |
91 | 58 |
92 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); | 59 DISALLOW_COPY_AND_ASSIGN(AeadBaseDecrypter); |
93 }; | 60 }; |
94 | 61 |
95 } // namespace net | 62 } // namespace net |
96 | 63 |
97 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ | 64 #endif // NET_QUIC_CRYPTO_AEAD_BASE_DECRYPTER_H_ |
OLD | NEW |