We started redesigning GpuMemoryBuffer interface to handle multiple buffers [0].
[chromium-blink-merge.git] / net / quic / crypto / null_encrypter.cc
blob286694ad7b24885fdcb1865c03235ee28330786d
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::Encrypt(
25 StringPiece /*nonce*/,
26 StringPiece associated_data,
27 StringPiece plaintext,
28 unsigned char* output) {
29 string buffer = associated_data.as_string();
30 plaintext.AppendToString(&buffer);
31 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length());
32 QuicUtils::SerializeUint128Short(hash, output);
33 memcpy(output + GetHashLength(), plaintext.data(), plaintext.size());
34 return true;
37 bool NullEncrypter::EncryptPacket(QuicPacketSequenceNumber /*sequence_number*/,
38 StringPiece associated_data,
39 StringPiece plaintext,
40 char* output,
41 size_t* output_length,
42 size_t max_output_length) {
43 const size_t len = plaintext.size() + GetHashLength();
44 if (max_output_length < len) {
45 return false;
47 Encrypt(StringPiece(), associated_data, plaintext,
48 reinterpret_cast<unsigned char*>(output));
49 *output_length = len;
50 return true;
53 size_t NullEncrypter::GetKeySize() const { return 0; }
55 size_t NullEncrypter::GetNoncePrefixSize() const { return 0; }
57 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
58 return ciphertext_size - GetHashLength();
61 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const {
62 return plaintext_size + GetHashLength();
65 StringPiece NullEncrypter::GetKey() const { return StringPiece(); }
67 StringPiece NullEncrypter::GetNoncePrefix() const { return StringPiece(); }
69 size_t NullEncrypter::GetHashLength() const {
70 return kHashSizeShort;
73 } // namespace net