| 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/core/crypto/aead_base_encrypter.h" | 5 #include "net/quic/core/crypto/aead_base_encrypter.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "net/quic/core/quic_utils.h" | 9 #include "net/quic/core/quic_utils.h" |
| 10 #include "net/quic/platform/api/quic_aligned.h" | 10 #include "net/quic/platform/api/quic_aligned.h" |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 reinterpret_cast<const uint8_t*>(associated_data.data()), | 96 reinterpret_cast<const uint8_t*>(associated_data.data()), |
| 97 associated_data.size())) { | 97 associated_data.size())) { |
| 98 DLogOpenSslErrors(); | 98 DLogOpenSslErrors(); |
| 99 return false; | 99 return false; |
| 100 } | 100 } |
| 101 | 101 |
| 102 return true; | 102 return true; |
| 103 } | 103 } |
| 104 | 104 |
| 105 bool AeadBaseEncrypter::EncryptPacket(QuicVersion /*version*/, | 105 bool AeadBaseEncrypter::EncryptPacket(QuicVersion /*version*/, |
| 106 QuicPathId path_id, | |
| 107 QuicPacketNumber packet_number, | 106 QuicPacketNumber packet_number, |
| 108 StringPiece associated_data, | 107 StringPiece associated_data, |
| 109 StringPiece plaintext, | 108 StringPiece plaintext, |
| 110 char* output, | 109 char* output, |
| 111 size_t* output_length, | 110 size_t* output_length, |
| 112 size_t max_output_length) { | 111 size_t max_output_length) { |
| 113 size_t ciphertext_size = GetCiphertextSize(plaintext.length()); | 112 size_t ciphertext_size = GetCiphertextSize(plaintext.length()); |
| 114 if (max_output_length < ciphertext_size) { | 113 if (max_output_length < ciphertext_size) { |
| 115 return false; | 114 return false; |
| 116 } | 115 } |
| 117 // TODO(ianswett): Introduce a check to ensure that we don't encrypt with the | 116 // TODO(ianswett): Introduce a check to ensure that we don't encrypt with the |
| 118 // same packet number twice. | 117 // same packet number twice. |
| 119 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); | 118 const size_t nonce_size = nonce_prefix_size_ + sizeof(packet_number); |
| 120 QUIC_ALIGNED(4) char nonce_buffer[kMaxNonceSize]; | 119 QUIC_ALIGNED(4) char nonce_buffer[kMaxNonceSize]; |
| 121 memcpy(nonce_buffer, nonce_prefix_, nonce_prefix_size_); | 120 memcpy(nonce_buffer, nonce_prefix_, nonce_prefix_size_); |
| 122 uint64_t path_id_packet_number = | 121 memcpy(nonce_buffer + nonce_prefix_size_, &packet_number, |
| 123 QuicUtils::PackPathIdAndPacketNumber(path_id, packet_number); | 122 sizeof(packet_number)); |
| 124 memcpy(nonce_buffer + nonce_prefix_size_, &path_id_packet_number, | |
| 125 sizeof(path_id_packet_number)); | |
| 126 | 123 |
| 127 if (!Encrypt(StringPiece(nonce_buffer, nonce_size), associated_data, | 124 if (!Encrypt(StringPiece(nonce_buffer, nonce_size), associated_data, |
| 128 plaintext, reinterpret_cast<unsigned char*>(output))) { | 125 plaintext, reinterpret_cast<unsigned char*>(output))) { |
| 129 return false; | 126 return false; |
| 130 } | 127 } |
| 131 *output_length = ciphertext_size; | 128 *output_length = ciphertext_size; |
| 132 return true; | 129 return true; |
| 133 } | 130 } |
| 134 | 131 |
| 135 size_t AeadBaseEncrypter::GetKeySize() const { | 132 size_t AeadBaseEncrypter::GetKeySize() const { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 154 | 151 |
| 155 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { | 152 StringPiece AeadBaseEncrypter::GetNoncePrefix() const { |
| 156 if (nonce_prefix_size_ == 0) { | 153 if (nonce_prefix_size_ == 0) { |
| 157 return StringPiece(); | 154 return StringPiece(); |
| 158 } | 155 } |
| 159 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), | 156 return StringPiece(reinterpret_cast<const char*>(nonce_prefix_), |
| 160 nonce_prefix_size_); | 157 nonce_prefix_size_); |
| 161 } | 158 } |
| 162 | 159 |
| 163 } // namespace net | 160 } // namespace net |
| OLD | NEW |