| 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_encrypter.h" | 5 #include "net/quic/crypto/aead_base_encrypter.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 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 size_t max_output_length) { | 128 size_t max_output_length) { |
| 129 size_t ciphertext_size = GetCiphertextSize(plaintext.length()); | 129 size_t ciphertext_size = GetCiphertextSize(plaintext.length()); |
| 130 if (max_output_length < ciphertext_size) { | 130 if (max_output_length < ciphertext_size) { |
| 131 return false; | 131 return false; |
| 132 } | 132 } |
| 133 // TODO(ianswett): Introduce a check to ensure that we don't encrypt with the | 133 // TODO(ianswett): Introduce a check to ensure that we don't encrypt with the |
| 134 // same packet number twice. | 134 // same packet number twice. |
| 135 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); | 135 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); |
| 136 ALIGNAS(4) char nonce_buffer[kMaxNonceSize]; | 136 ALIGNAS(4) char nonce_buffer[kMaxNonceSize]; |
| 137 memcpy(nonce_buffer, nonce_prefix_, nonce_prefix_size_); | 137 memcpy(nonce_buffer, nonce_prefix_, nonce_prefix_size_); |
| 138 if (FLAGS_quic_include_path_id_in_iv) { | 138 uint64_t path_id_packet_number = |
| 139 uint64_t path_id_packet_number = | 139 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); |
| 140 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); | 140 memcpy(nonce_buffer + nonce_prefix_size_, &path_id_packet_number, |
| 141 memcpy(nonce_buffer + nonce_prefix_size_, &path_id_packet_number, | 141 sizeof(path_id_packet_number)); |
| 142 sizeof(path_id_packet_number)); | |
| 143 } else { | |
| 144 memcpy(nonce_buffer + nonce_prefix_size_, &packet_number, | |
| 145 sizeof(packet_number)); | |
| 146 } | |
| 147 if (!Encrypt(StringPiece(nonce_buffer, nonce_size), associated_data, | 142 if (!Encrypt(StringPiece(nonce_buffer, nonce_size), associated_data, |
| 148 plaintext, reinterpret_cast<unsigned char*>(output))) { | 143 plaintext, reinterpret_cast<unsigned char*>(output))) { |
| 149 return false; | 144 return false; |
| 150 } | 145 } |
| 151 *output_length = ciphertext_size; | 146 *output_length = ciphertext_size; |
| 152 return true; | 147 return true; |
| 153 } | 148 } |
| 154 | 149 |
| 155 size_t AeadBaseEncrypter::GetKeySize() const { | 150 size_t AeadBaseEncrypter::GetKeySize() const { |
| 156 return key_size_; | 151 return key_size_; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 174 | 169 |
| 175 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { | 170 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { |
| 176 if (nonce_prefix_size_ == 0) { | 171 if (nonce_prefix_size_ == 0) { |
| 177 return StringPiece(); | 172 return StringPiece(); |
| 178 } | 173 } |
| 179 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 174 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 180 nonce_prefix_size_); | 175 nonce_prefix_size_); |
| 181 } | 176 } |
| 182 | 177 |
| 183 } // namespace net | 178 } // namespace net |
| OLD | NEW |