OLD | NEW |
(Empty) | |
| 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_DECRYPTER_H_ |
| 6 #define NET_QUIC_CRYPTO_AES_128_GCM_DECRYPTER_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "base/compiler_specific.h" |
| 11 #include "net/quic/crypto/quic_decrypter.h" |
| 12 |
| 13 namespace net { |
| 14 |
| 15 namespace test { |
| 16 class Aes128GcmDecrypterPeer; |
| 17 } // namespace test |
| 18 |
| 19 // An Aes128GcmDecrypter is a QuicDecrypter that implements the |
| 20 // AEAD_AES_128_GCM algorithm specified in RFC 5116. Create an instance by |
| 21 // calling QuicDecrypter::Create(kAESG). |
| 22 // |
| 23 // It uses an authentication tag of 16 bytes (128 bits). The fixed prefix |
| 24 // of the nonce is four bytes. |
| 25 class NET_EXPORT_PRIVATE Aes128GcmDecrypter : public QuicDecrypter { |
| 26 public: |
| 27 virtual ~Aes128GcmDecrypter() {} |
| 28 |
| 29 // Returns true if the underlying crypto library supports AES GCM. |
| 30 #if defined(USE_OPENSSL) |
| 31 static bool IsSupported() { return true; } |
| 32 #else |
| 33 static bool IsSupported(); |
| 34 #endif |
| 35 |
| 36 // QuicDecrypter implementation |
| 37 virtual bool SetKey(base::StringPiece key) OVERRIDE; |
| 38 virtual bool SetNoncePrefix(base::StringPiece nonce_prefix) OVERRIDE; |
| 39 virtual QuicData* Decrypt(QuicPacketSequenceNumber sequence_number, |
| 40 base::StringPiece associated_data, |
| 41 base::StringPiece ciphertext) OVERRIDE; |
| 42 virtual base::StringPiece GetKey() const OVERRIDE; |
| 43 virtual base::StringPiece GetNoncePrefix() const OVERRIDE; |
| 44 |
| 45 private: |
| 46 friend class test::Aes128GcmDecrypterPeer; |
| 47 |
| 48 // The same as Decrypt(), except that the supplied |nonce| argument rather |
| 49 // than the |nonce_| member is used as the nonce. This method is useful |
| 50 // for testing the underlying AES GCM implementation. |
| 51 QuicData* DecryptWithNonce(base::StringPiece nonce, |
| 52 base::StringPiece associated_data, |
| 53 base::StringPiece ciphertext); |
| 54 |
| 55 // The 128-bit AES key. |
| 56 unsigned char key_[16]; |
| 57 // The nonce, a concatenation of a four-byte fixed prefix and a 8-byte |
| 58 // packet sequence number. |
| 59 unsigned char nonce_[12]; |
| 60 }; |
| 61 |
| 62 } // namespace net |
| 63 |
| 64 #endif // NET_QUIC_CRYPTO_AES_128_GCM_DECRYPTER_H_ |
OLD | NEW |