[Android WebView] Fix webview perf bot switchover to use org.chromium.webview_shell...
[chromium-blink-merge.git] / net / quic / crypto / null_encrypter.cc
blobc1e823e78ccb29d46f4f02de0793b8160898a213
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
3 // found in the LICENSE file.
5 #include "net/quic/crypto/null_encrypter.h"
6 #include "net/quic/quic_data_writer.h"
7 #include "net/quic/quic_utils.h"
9 using base::StringPiece;
10 using std::string;
12 namespace net {
14 const size_t kHashSizeShort = 12; // size of uint128 serialized short
16 NullEncrypter::NullEncrypter() {}
18 bool NullEncrypter::SetKey(StringPiece key) { return key.empty(); }
20 bool NullEncrypter::SetNoncePrefix(StringPiece nonce_prefix) {
21 return nonce_prefix.empty();
24 bool NullEncrypter::EncryptPacket(QuicPacketSequenceNumber /*sequence_number*/,
25 StringPiece associated_data,
26 StringPiece plaintext,
27 char* output,
28 size_t* output_length,
29 size_t max_output_length) {
30 const size_t len = plaintext.size() + GetHashLength();
31 if (max_output_length < len) {
32 return false;
34 uint128 hash = QuicUtils::FNV1a_128_Hash_Two(
35 associated_data.data(), associated_data.size(), plaintext.data(),
36 plaintext.size());
37 QuicUtils::SerializeUint128Short(hash,
38 reinterpret_cast<unsigned char*>(output));
39 memcpy(output + GetHashLength(), plaintext.data(), plaintext.length());
40 *output_length = len;
41 return true;
44 size_t NullEncrypter::GetKeySize() const { return 0; }
46 size_t NullEncrypter::GetNoncePrefixSize() const { return 0; }
48 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
49 return ciphertext_size - GetHashLength();
52 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const {
53 return plaintext_size + GetHashLength();
56 StringPiece NullEncrypter::GetKey() const { return StringPiece(); }
58 StringPiece NullEncrypter::GetNoncePrefix() const { return StringPiece(); }
60 size_t NullEncrypter::GetHashLength() const {
61 return kHashSizeShort;
64 } // namespace net