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_AES_128_GCM_12_DECRYPTER_H_ | 5 #ifndef NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ |
6 #define NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ | 6 #define NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ |
7 | 7 |
8 #include <string> | 8 #include "net/quic/crypto/aead_base_decrypter.h" |
9 | |
10 #include "base/compiler_specific.h" | |
11 #include "net/quic/crypto/quic_decrypter.h" | |
12 | |
13 #if defined(USE_OPENSSL) | |
14 #include "net/quic/crypto/scoped_evp_aead_ctx.h" | |
15 #endif | |
16 | 9 |
17 namespace net { | 10 namespace net { |
18 | 11 |
19 namespace test { | |
20 class Aes128Gcm12DecrypterPeer; | |
21 } // namespace test | |
22 | |
23 // An Aes128Gcm12Decrypter is a QuicDecrypter that implements the | 12 // An Aes128Gcm12Decrypter is a QuicDecrypter that implements the |
24 // AEAD_AES_128_GCM_12 algorithm specified in RFC 5282. Create an instance by | 13 // AEAD_AES_128_GCM_12 algorithm specified in RFC 5282. Create an instance by |
25 // calling QuicDecrypter::Create(kAESG). | 14 // calling QuicDecrypter::Create(kAESG). |
26 // | 15 // |
27 // It uses an authentication tag of 12 bytes (96 bits). The fixed prefix | 16 // It uses an authentication tag of 12 bytes (96 bits). The fixed prefix |
28 // of the nonce is four bytes. | 17 // of the nonce is four bytes. |
29 class NET_EXPORT_PRIVATE Aes128Gcm12Decrypter : public QuicDecrypter { | 18 class NET_EXPORT_PRIVATE Aes128Gcm12Decrypter : public AeadBaseDecrypter { |
30 public: | 19 public: |
31 enum { | 20 enum { |
32 // Authentication tags are truncated to 96 bits. | 21 // Authentication tags are truncated to 96 bits. |
33 kAuthTagSize = 12, | 22 kAuthTagSize = 12, |
34 }; | 23 }; |
35 | 24 |
36 Aes128Gcm12Decrypter(); | 25 Aes128Gcm12Decrypter(); |
37 virtual ~Aes128Gcm12Decrypter(); | 26 virtual ~Aes128Gcm12Decrypter(); |
38 | 27 |
39 // Returns true if the underlying crypto library supports AES GCM. | 28 #if !defined(USE_OPENSSL) |
40 static bool IsSupported(); | 29 protected: |
41 | 30 // AeadBaseDecrypter methods: |
42 // QuicDecrypter implementation | 31 virtual void FillAeadParams(base::StringPiece nonce, |
43 virtual bool SetKey(base::StringPiece key) OVERRIDE; | 32 base::StringPiece associated_data, |
44 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) OVERRIDE; | 33 size_t auth_tag_size, |
45 virtual bool Decrypt(base::StringPiece nonce, | 34 AeadParams* aead_params) const OVERRIDE; |
46 base::StringPiece associated_data, | |
47 base::StringPiece ciphertext, | |
48 unsigned char* output, | |
49 size_t* output_length) OVERRIDE; | |
50 virtual QuicData* DecryptPacket(QuicPacketSequenceNumber sequence_number, | |
51 base::StringPiece associated_data, | |
52 base::StringPiece ciphertext) OVERRIDE; | |
53 virtual base::StringPiece GetKey() const OVERRIDE; | |
54 virtual base::StringPiece GetNoncePrefix() const OVERRIDE; | |
55 | |
56 private: | |
57 // The 128-bit AES key. | |
58 unsigned char key_[16]; | |
59 // The nonce prefix. | |
60 unsigned char nonce_prefix_[4]; | |
61 | |
62 #if defined(USE_OPENSSL) | |
63 ScopedEVPAEADCtx ctx_; | |
64 #endif | 35 #endif |
65 }; | 36 }; |
66 | 37 |
67 } // namespace net | 38 } // namespace net |
68 | 39 |
69 #endif // NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ | 40 #endif // NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_ |
OLD | NEW |