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
;
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
,
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
) {
34 uint128 hash
= QuicUtils::FNV1a_128_Hash_Two(
35 associated_data
.data(), associated_data
.size(), plaintext
.data(),
37 QuicUtils::SerializeUint128Short(hash
,
38 reinterpret_cast<unsigned char*>(output
));
39 memcpy(output
+ GetHashLength(), plaintext
.data(), plaintext
.length());
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
;