| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/null_encrypter.h" | 5 #include "net/quic/crypto/null_encrypter.h" |
| 6 #include "net/quic/quic_data_writer.h" | 6 #include "net/quic/quic_data_writer.h" |
| 7 #include "net/quic/quic_utils.h" | 7 #include "net/quic/quic_utils.h" |
| 8 | 8 |
| 9 using base::StringPiece; | 9 using base::StringPiece; |
| 10 using std::string; | 10 using std::string; |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 StringPiece plaintext, | 27 StringPiece plaintext, |
| 28 unsigned char* output) { | 28 unsigned char* output) { |
| 29 string buffer = associated_data.as_string(); | 29 string buffer = associated_data.as_string(); |
| 30 plaintext.AppendToString(&buffer); | 30 plaintext.AppendToString(&buffer); |
| 31 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length()); | 31 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length()); |
| 32 QuicUtils::SerializeUint128Short(hash, output); | 32 QuicUtils::SerializeUint128Short(hash, output); |
| 33 memcpy(output + GetHashLength(), plaintext.data(), plaintext.size()); | 33 memcpy(output + GetHashLength(), plaintext.data(), plaintext.size()); |
| 34 return true; | 34 return true; |
| 35 } | 35 } |
| 36 | 36 |
| 37 QuicData* NullEncrypter::EncryptPacket( | 37 bool NullEncrypter::EncryptPacket(QuicPacketSequenceNumber /*sequence_number*/, |
| 38 QuicPacketSequenceNumber /*sequence_number*/, | 38 StringPiece associated_data, |
| 39 StringPiece associated_data, | 39 StringPiece plaintext, |
| 40 StringPiece plaintext) { | 40 char* output, |
| 41 size_t* output_length, |
| 42 size_t max_output_length) { |
| 41 const size_t len = plaintext.size() + GetHashLength(); | 43 const size_t len = plaintext.size() + GetHashLength(); |
| 42 uint8* buffer = new uint8[len]; | 44 if (max_output_length < len) { |
| 43 Encrypt(StringPiece(), associated_data, plaintext, buffer); | 45 return false; |
| 44 return new QuicData(reinterpret_cast<char*>(buffer), len, true); | 46 } |
| 47 Encrypt(StringPiece(), associated_data, plaintext, |
| 48 reinterpret_cast<unsigned char*>(output)); |
| 49 *output_length = len; |
| 50 return true; |
| 45 } | 51 } |
| 46 | 52 |
| 47 size_t NullEncrypter::GetKeySize() const { return 0; } | 53 size_t NullEncrypter::GetKeySize() const { return 0; } |
| 48 | 54 |
| 49 size_t NullEncrypter::GetNoncePrefixSize() const { return 0; } | 55 size_t NullEncrypter::GetNoncePrefixSize() const { return 0; } |
| 50 | 56 |
| 51 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const { | 57 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const { |
| 52 return ciphertext_size - GetHashLength(); | 58 return ciphertext_size - GetHashLength(); |
| 53 } | 59 } |
| 54 | 60 |
| 55 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const { | 61 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const { |
| 56 return plaintext_size + GetHashLength(); | 62 return plaintext_size + GetHashLength(); |
| 57 } | 63 } |
| 58 | 64 |
| 59 StringPiece NullEncrypter::GetKey() const { return StringPiece(); } | 65 StringPiece NullEncrypter::GetKey() const { return StringPiece(); } |
| 60 | 66 |
| 61 StringPiece NullEncrypter::GetNoncePrefix() const { return StringPiece(); } | 67 StringPiece NullEncrypter::GetNoncePrefix() const { return StringPiece(); } |
| 62 | 68 |
| 63 size_t NullEncrypter::GetHashLength() const { | 69 size_t NullEncrypter::GetHashLength() const { |
| 64 return kHashSizeShort; | 70 return kHashSizeShort; |
| 65 } | 71 } |
| 66 | 72 |
| 67 } // namespace net | 73 } // namespace net |
| OLD | NEW |