- add sources.
[platform/framework/web/crosswalk.git] / src / net / quic / crypto / aes_128_gcm_12_decrypter.h
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
3 // found in the LICENSE file.
4
5 #ifndef NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_
6 #define NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_
7
8 #include <string>
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_cipher_ctx.h"
15 #endif
16
17 namespace net {
18
19 namespace test {
20 class Aes128Gcm12DecrypterPeer;
21 }  // namespace test
22
23 // An Aes128Gcm12Decrypter is a QuicDecrypter that implements the
24 // AEAD_AES_128_GCM_12 algorithm specified in RFC 5282. Create an instance by
25 // calling QuicDecrypter::Create(kAESG).
26 //
27 // It uses an authentication tag of 12 bytes (96 bits). The fixed prefix
28 // of the nonce is four bytes.
29 class NET_EXPORT_PRIVATE Aes128Gcm12Decrypter : public QuicDecrypter {
30  public:
31   enum {
32     // Authentication tags are truncated to 96 bits.
33     kAuthTagSize = 12,
34   };
35
36   Aes128Gcm12Decrypter();
37   virtual ~Aes128Gcm12Decrypter();
38
39   // Returns true if the underlying crypto library supports AES GCM.
40   static bool IsSupported();
41
42   // QuicDecrypter implementation
43   virtual bool SetKey(base::StringPiece key) OVERRIDE;
44   virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) OVERRIDE;
45   virtual bool Decrypt(base::StringPiece nonce,
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   // TODO(rtenneti): when Chromium's version of OpenSSL has EVP_AEAD_CTX, merge
64   // internal CL 53267501.
65   ScopedEVPCipherCtx ctx_;
66 #endif
67 };
68
69 }  // namespace net
70
71 #endif  // NET_QUIC_CRYPTO_AES_128_GCM_12_DECRYPTER_H_