| 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 <pk11pub.h> | 7 #include <pk11pub.h> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "crypto/scoped_nss_types.h" | 10 #include "crypto/scoped_nss_types.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 size_t* output_length, | 55 size_t* output_length, |
| 56 size_t max_output_length) { | 56 size_t max_output_length) { |
| 57 if (ciphertext.length() < auth_tag_size_) { | 57 if (ciphertext.length() < auth_tag_size_) { |
| 58 return false; | 58 return false; |
| 59 } | 59 } |
| 60 | 60 |
| 61 uint8_t nonce[sizeof(nonce_prefix_) + sizeof(packet_number)]; | 61 uint8_t nonce[sizeof(nonce_prefix_) + sizeof(packet_number)]; |
| 62 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); | 62 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); |
| 63 DCHECK_LE(nonce_size, sizeof(nonce)); | 63 DCHECK_LE(nonce_size, sizeof(nonce)); |
| 64 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); | 64 memcpy(nonce, nonce_prefix_, nonce_prefix_size_); |
| 65 if (FLAGS_quic_include_path_id_in_iv) { | 65 uint64_t path_id_packet_number = |
| 66 uint64_t path_id_packet_number = | 66 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); |
| 67 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); | 67 memcpy(nonce + nonce_prefix_size_, &path_id_packet_number, |
| 68 memcpy(nonce + nonce_prefix_size_, &path_id_packet_number, | 68 sizeof(path_id_packet_number)); |
| 69 sizeof(path_id_packet_number)); | |
| 70 } else { | |
| 71 memcpy(nonce + nonce_prefix_size_, &packet_number, sizeof(packet_number)); | |
| 72 } | |
| 73 | 69 |
| 74 // NSS 3.14.x incorrectly requires an output buffer at least as long as | 70 // NSS 3.14.x incorrectly requires an output buffer at least as long as |
| 75 // the ciphertext (NSS bug | 71 // the ciphertext (NSS bug |
| 76 // https://bugzilla.mozilla.org/show_bug.cgi?id= 853674). Fortunately | 72 // https://bugzilla.mozilla.org/show_bug.cgi?id= 853674). Fortunately |
| 77 // QuicDecrypter::Decrypt() specifies that |output| must be as long as | 73 // QuicDecrypter::Decrypt() specifies that |output| must be as long as |
| 78 // |ciphertext| on entry. | 74 // |ciphertext| on entry. |
| 79 size_t plaintext_size = ciphertext.length() - auth_tag_size_; | 75 size_t plaintext_size = ciphertext.length() - auth_tag_size_; |
| 80 | 76 |
| 81 // Import key_ into NSS. | 77 // Import key_ into NSS. |
| 82 SECItem key_item; | 78 SECItem key_item; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 | 126 |
| 131 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { | 127 StringPiece AeadBaseDecrypter::GetNoncePrefix() const { |
| 132 if (nonce_prefix_size_ == 0) { | 128 if (nonce_prefix_size_ == 0) { |
| 133 return StringPiece(); | 129 return StringPiece(); |
| 134 } | 130 } |
| 135 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 131 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 136 nonce_prefix_size_); | 132 nonce_prefix_size_); |
| 137 } | 133 } |
| 138 | 134 |
| 139 } // namespace net | 135 } // namespace net |
| OLD | NEW |