| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #include "net/quic/core/crypto/quic_decrypter.h" | 5 #include "net/quic/core/crypto/quic_decrypter.h" |
| 6 | 6 |
| 7 #include "crypto/hkdf.h" | 7 #include "crypto/hkdf.h" |
| 8 #include "net/quic/core/crypto/aes_128_gcm_12_decrypter.h" | 8 #include "net/quic/core/crypto/aes_128_gcm_12_decrypter.h" |
| 9 #include "net/quic/core/crypto/chacha20_poly1305_decrypter.h" | 9 #include "net/quic/core/crypto/chacha20_poly1305_decrypter.h" |
| 10 #include "net/quic/core/crypto/crypto_protocol.h" | 10 #include "net/quic/core/crypto/crypto_protocol.h" |
| 11 #include "net/quic/core/crypto/null_decrypter.h" | 11 #include "net/quic/core/crypto/null_decrypter.h" |
| 12 #include "net/quic/platform/api/quic_logging.h" | 12 #include "net/quic/platform/api/quic_logging.h" |
| 13 | 13 |
| 14 using base::StringPiece; | |
| 15 using std::string; | 14 using std::string; |
| 16 | 15 |
| 17 namespace net { | 16 namespace net { |
| 18 | 17 |
| 19 // static | 18 // static |
| 20 QuicDecrypter* QuicDecrypter::Create(QuicTag algorithm) { | 19 QuicDecrypter* QuicDecrypter::Create(QuicTag algorithm) { |
| 21 switch (algorithm) { | 20 switch (algorithm) { |
| 22 case kAESG: | 21 case kAESG: |
| 23 return new Aes128Gcm12Decrypter(); | 22 return new Aes128Gcm12Decrypter(); |
| 24 case kCC20: | 23 case kCC20: |
| 25 return new ChaCha20Poly1305Decrypter(); | 24 return new ChaCha20Poly1305Decrypter(); |
| 26 default: | 25 default: |
| 27 QUIC_LOG(FATAL) << "Unsupported algorithm: " << algorithm; | 26 QUIC_LOG(FATAL) << "Unsupported algorithm: " << algorithm; |
| 28 return nullptr; | 27 return nullptr; |
| 29 } | 28 } |
| 30 } | 29 } |
| 31 | 30 |
| 32 // static | 31 // static |
| 33 void QuicDecrypter::DiversifyPreliminaryKey(StringPiece preliminary_key, | 32 void QuicDecrypter::DiversifyPreliminaryKey(QuicStringPiece preliminary_key, |
| 34 StringPiece nonce_prefix, | 33 QuicStringPiece nonce_prefix, |
| 35 const DiversificationNonce& nonce, | 34 const DiversificationNonce& nonce, |
| 36 size_t key_size, | 35 size_t key_size, |
| 37 size_t nonce_prefix_size, | 36 size_t nonce_prefix_size, |
| 38 string* out_key, | 37 string* out_key, |
| 39 string* out_nonce_prefix) { | 38 string* out_nonce_prefix) { |
| 40 crypto::HKDF hkdf(preliminary_key.as_string() + nonce_prefix.as_string(), | 39 crypto::HKDF hkdf(preliminary_key.as_string() + nonce_prefix.as_string(), |
| 41 StringPiece(nonce.data(), nonce.size()), | 40 QuicStringPiece(nonce.data(), nonce.size()), |
| 42 "QUIC key diversification", 0, key_size, 0, | 41 "QUIC key diversification", 0, key_size, 0, |
| 43 nonce_prefix_size, 0); | 42 nonce_prefix_size, 0); |
| 44 *out_key = hkdf.server_write_key().as_string(); | 43 *out_key = hkdf.server_write_key().as_string(); |
| 45 *out_nonce_prefix = hkdf.server_write_iv().as_string(); | 44 *out_nonce_prefix = hkdf.server_write_iv().as_string(); |
| 46 } | 45 } |
| 47 | 46 |
| 48 } // namespace net | 47 } // namespace net |
| OLD | NEW |