| 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 #include "net/quic/crypto/aead_base_decrypter.h" | 5 #include "net/quic/crypto/aead_base_decrypter.h" |
| 6 | 6 |
| 7 #include <openssl/err.h> | 7 #include <openssl/err.h> |
| 8 #include <openssl/evp.h> | 8 #include <openssl/evp.h> |
| 9 | 9 |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 char* output, | 86 char* output, |
| 87 size_t* output_length, | 87 size_t* output_length, |
| 88 size_t max_output_length) { | 88 size_t max_output_length) { |
| 89 if (ciphertext.length() < auth_tag_size_) { | 89 if (ciphertext.length() < auth_tag_size_) { |
| 90 return false; | 90 return false; |
| 91 } | 91 } |
| 92 | 92 |
| 93 uint8_t nonce[sizeof(nonce_prefix_) + sizeof(packet_number)]; | 93 uint8_t nonce[sizeof(nonce_prefix_) + sizeof(packet_number)]; |
| 94 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); | 94 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); |
| 95 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); | 95 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); |
| 96 if (FLAGS_quic_include_path_id_in_iv) { | 96 uint64_t path_id_packet_number = |
| 97 uint64_t path_id_packet_number = | 97 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); |
| 98 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); | 98 memcpy(nonce + nonce_prefix_size_, &path_id_packet_number, |
| 99 memcpy(nonce + nonce_prefix_size_, &path_id_packet_number, | 99 sizeof(path_id_packet_number)); |
| 100 sizeof(path_id_packet_number)); | |
| 101 } else { | |
| 102 memcpy(nonce + nonce_prefix_size_, &packet_number, sizeof(packet_number)); | |
| 103 } | |
| 104 if (!EVP_AEAD_CTX_open( | 100 if (!EVP_AEAD_CTX_open( |
| 105 ctx_.get(), reinterpret_cast<uint8_t*>(output), output_length, | 101 ctx_.get(), reinterpret_cast<uint8_t*>(output), output_length, |
| 106 max_output_length, reinterpret_cast<const uint8_t*>(nonce), | 102 max_output_length, reinterpret_cast<const uint8_t*>(nonce), |
| 107 nonce_size, reinterpret_cast<const uint8_t*>(ciphertext.data()), | 103 nonce_size, reinterpret_cast<const uint8_t*>(ciphertext.data()), |
| 108 ciphertext.size(), | 104 ciphertext.size(), |
| 109 reinterpret_cast<const uint8_t*>(associated_data.data()), | 105 reinterpret_cast<const uint8_t*>(associated_data.data()), |
| 110 associated_data.size())) { | 106 associated_data.size())) { |
| 111 // Because QuicFramer does trial decryption, decryption errors are expected | 107 // Because QuicFramer does trial decryption, decryption errors are expected |
| 112 // when encryption level changes. So we don't log decryption errors. | 108 // when encryption level changes. So we don't log decryption errors. |
| 113 ClearOpenSslErrors(); | 109 ClearOpenSslErrors(); |
| 114 return false; | 110 return false; |
| 115 } | 111 } |
| 116 return true; | 112 return true; |
| 117 } | 113 } |
| 118 | 114 |
| 119 StringPiece AeadBaseDecrypter::GetKey() const { | 115 StringPiece AeadBaseDecrypter::GetKey() const { |
| 120 return StringPiece(reinterpret_cast<const char*>(key_), key_size_); | 116 return StringPiece(reinterpret_cast<const char*>(key_), key_size_); |
| 121 } | 117 } |
| 122 | 118 |
| 123 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { | 119 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { |
| 124 if (nonce_prefix_size_ == 0) { | 120 if (nonce_prefix_size_ == 0) { |
| 125 return StringPiece(); | 121 return StringPiece(); |
| 126 } | 122 } |
| 127 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 123 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 128 nonce_prefix_size_); | 124 nonce_prefix_size_); |
| 129 } | 125 } |
| 130 | 126 |
| 131 } // namespace net | 127 } // namespace net |
| OLD | NEW |