1 // Copyright (c) 2012 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 #include "quiche/quic/core/crypto/quic_encrypter.h" 6 7 #include <utility> 8 9 #include "openssl/tls1.h" 10 #include "quiche/quic/core/crypto/aes_128_gcm_12_encrypter.h" 11 #include "quiche/quic/core/crypto/aes_128_gcm_encrypter.h" 12 #include "quiche/quic/core/crypto/aes_256_gcm_encrypter.h" 13 #include "quiche/quic/core/crypto/chacha20_poly1305_encrypter.h" 14 #include "quiche/quic/core/crypto/chacha20_poly1305_tls_encrypter.h" 15 #include "quiche/quic/core/crypto/crypto_protocol.h" 16 #include "quiche/quic/core/crypto/null_encrypter.h" 17 #include "quiche/quic/platform/api/quic_bug_tracker.h" 18 #include "quiche/quic/platform/api/quic_logging.h" 19 20 namespace quic { 21 22 // static Create(const ParsedQuicVersion & version,QuicTag algorithm)23std::unique_ptr<QuicEncrypter> QuicEncrypter::Create( 24 const ParsedQuicVersion& version, QuicTag algorithm) { 25 switch (algorithm) { 26 case kAESG: 27 if (version.UsesInitialObfuscators()) { 28 return std::make_unique<Aes128GcmEncrypter>(); 29 } else { 30 return std::make_unique<Aes128Gcm12Encrypter>(); 31 } 32 case kCC20: 33 if (version.UsesInitialObfuscators()) { 34 return std::make_unique<ChaCha20Poly1305TlsEncrypter>(); 35 } else { 36 return std::make_unique<ChaCha20Poly1305Encrypter>(); 37 } 38 default: 39 QUIC_LOG(FATAL) << "Unsupported algorithm: " << algorithm; 40 return nullptr; 41 } 42 } 43 44 // static CreateFromCipherSuite(uint32_t cipher_suite)45std::unique_ptr<QuicEncrypter> QuicEncrypter::CreateFromCipherSuite( 46 uint32_t cipher_suite) { 47 switch (cipher_suite) { 48 case TLS1_CK_AES_128_GCM_SHA256: 49 return std::make_unique<Aes128GcmEncrypter>(); 50 case TLS1_CK_AES_256_GCM_SHA384: 51 return std::make_unique<Aes256GcmEncrypter>(); 52 case TLS1_CK_CHACHA20_POLY1305_SHA256: 53 return std::make_unique<ChaCha20Poly1305TlsEncrypter>(); 54 default: 55 QUIC_BUG(quic_bug_10711_1) << "TLS cipher suite is unknown to QUIC"; 56 return nullptr; 57 } 58 } 59 60 } // namespace quic 61