| 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/aes_128_gcm_12_decrypter.h" | 5 #include "net/quic/crypto/aes_128_gcm_12_decrypter.h" |
| 6 | 6 |
| 7 #include "net/quic/quic_flags.h" | 7 #include "net/quic/quic_flags.h" |
| 8 #include "net/quic/test_tools/quic_test_utils.h" | 8 #include "net/quic/test_tools/quic_test_utils.h" |
| 9 | 9 |
| 10 using base::StringPiece; | 10 using base::StringPiece; |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter, | 199 QuicData* DecryptWithNonce(Aes128Gcm12Decrypter* decrypter, |
| 200 StringPiece nonce, | 200 StringPiece nonce, |
| 201 StringPiece associated_data, | 201 StringPiece associated_data, |
| 202 StringPiece ciphertext) { | 202 StringPiece ciphertext) { |
| 203 QuicPathId path_id = kDefaultPathId; | 203 QuicPathId path_id = kDefaultPathId; |
| 204 QuicPacketNumber packet_number; | 204 QuicPacketNumber packet_number; |
| 205 StringPiece nonce_prefix(nonce.data(), nonce.size() - sizeof(packet_number)); | 205 StringPiece nonce_prefix(nonce.data(), nonce.size() - sizeof(packet_number)); |
| 206 decrypter->SetNoncePrefix(nonce_prefix); | 206 decrypter->SetNoncePrefix(nonce_prefix); |
| 207 memcpy(&packet_number, nonce.data() + nonce_prefix.size(), | 207 memcpy(&packet_number, nonce.data() + nonce_prefix.size(), |
| 208 sizeof(packet_number)); | 208 sizeof(packet_number)); |
| 209 if (FLAGS_quic_include_path_id_in_iv) { | 209 path_id = static_cast<QuicPathId>( |
| 210 path_id = static_cast<QuicPathId>( | 210 packet_number >> 8 * (sizeof(packet_number) - sizeof(path_id))); |
| 211 packet_number >> 8 * (sizeof(packet_number) - sizeof(path_id))); | 211 packet_number &= UINT64_C(0x00FFFFFFFFFFFFFF); |
| 212 packet_number &= UINT64_C(0x00FFFFFFFFFFFFFF); | |
| 213 } | |
| 214 scoped_ptr<char[]> output(new char[ciphertext.length()]); | 212 scoped_ptr<char[]> output(new char[ciphertext.length()]); |
| 215 size_t output_length = 0; | 213 size_t output_length = 0; |
| 216 const bool success = decrypter->DecryptPacket( | 214 const bool success = decrypter->DecryptPacket( |
| 217 path_id, packet_number, associated_data, ciphertext, output.get(), | 215 path_id, packet_number, associated_data, ciphertext, output.get(), |
| 218 &output_length, ciphertext.length()); | 216 &output_length, ciphertext.length()); |
| 219 if (!success) { | 217 if (!success) { |
| 220 return nullptr; | 218 return nullptr; |
| 221 } | 219 } |
| 222 return new QuicData(output.release(), output_length, true); | 220 return new QuicData(output.release(), output_length, true); |
| 223 } | 221 } |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 282 | 280 |
| 283 ASSERT_EQ(pt.length(), decrypted->length()); | 281 ASSERT_EQ(pt.length(), decrypted->length()); |
| 284 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), | 282 test::CompareCharArraysWithHexError("plaintext", decrypted->data(), |
| 285 pt.length(), pt.data(), pt.length()); | 283 pt.length(), pt.data(), pt.length()); |
| 286 } | 284 } |
| 287 } | 285 } |
| 288 } | 286 } |
| 289 | 287 |
| 290 } // namespace test | 288 } // namespace test |
| 291 } // namespace net | 289 } // namespace net |
| OLD | NEW |