Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(687)

Side by Side Diff: net/quic/crypto/null_encrypter.cc

Issue 14816006: Land Recent QUIC changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing NET_PRIVATE_EXPORT to QuicWallTime Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/quic/crypto/null_decrypter_test.cc ('k') | net/quic/crypto/null_encrypter_test.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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;
11 11
12 namespace net { 12 namespace net {
13 13
14 const size_t kHashSize = 16; // size of uint128 serialized 14 const size_t kHashSize = 16; // size of uint128 serialized
15 15
16 bool NullEncrypter::SetKey(StringPiece key) { 16 bool NullEncrypter::SetKey(StringPiece key) { return key.empty(); }
17 return key.empty();
18 }
19 17
20 bool NullEncrypter::SetNoncePrefix(StringPiece nonce_prefix) { 18 bool NullEncrypter::SetNoncePrefix(StringPiece nonce_prefix) {
21 return nonce_prefix.empty(); 19 return nonce_prefix.empty();
22 } 20 }
23 21
24 bool NullEncrypter::Encrypt( 22 bool NullEncrypter::Encrypt(
25 StringPiece /*nonce*/, 23 StringPiece /*nonce*/,
26 StringPiece associated_data, 24 StringPiece associated_data,
27 StringPiece plaintext, 25 StringPiece plaintext,
28 unsigned char* output) { 26 unsigned char* output) {
29 string buffer = associated_data.as_string(); 27 string buffer = associated_data.as_string();
30 plaintext.AppendToString(&buffer); 28 plaintext.AppendToString(&buffer);
31 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length()); 29 uint128 hash = QuicUtils::FNV1a_128_Hash(buffer.data(), buffer.length());
32 QuicUtils::SerializeUint128(hash, output); 30 QuicUtils::SerializeUint128(hash, output);
33 memcpy(output + sizeof(hash), plaintext.data(), plaintext.size()); 31 memcpy(output + sizeof(hash), plaintext.data(), plaintext.size());
34 return true; 32 return true;
35 } 33 }
36 34
37 QuicData* NullEncrypter::EncryptPacket( 35 QuicData* NullEncrypter::EncryptPacket(
38 QuicPacketSequenceNumber /*sequence_number*/, 36 QuicPacketSequenceNumber /*sequence_number*/,
39 StringPiece associated_data, 37 StringPiece associated_data,
40 StringPiece plaintext) { 38 StringPiece plaintext) {
41 const size_t len = plaintext.size() + sizeof(uint128); 39 const size_t len = plaintext.size() + sizeof(uint128);
42 uint8* buffer = new uint8[len]; 40 uint8* buffer = new uint8[len];
43 Encrypt(StringPiece(), associated_data, plaintext, buffer); 41 Encrypt(StringPiece(), associated_data, plaintext, buffer);
44 return new QuicData(reinterpret_cast<char*>(buffer), len, true); 42 return new QuicData(reinterpret_cast<char*>(buffer), len, true);
45 } 43 }
46 44
47 size_t NullEncrypter::GetKeySize() const { 45 size_t NullEncrypter::GetKeySize() const { return 0; }
48 return 0;
49 }
50 46
51 size_t NullEncrypter::GetNoncePrefixSize() const { 47 size_t NullEncrypter::GetNoncePrefixSize() const { return 0; }
52 return 0;
53 }
54 48
55 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const { 49 size_t NullEncrypter::GetMaxPlaintextSize(size_t ciphertext_size) const {
56 return ciphertext_size - kHashSize; 50 return ciphertext_size - kHashSize;
57 } 51 }
58 52
59 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const { 53 size_t NullEncrypter::GetCiphertextSize(size_t plaintext_size) const {
60 return plaintext_size + kHashSize; 54 return plaintext_size + kHashSize;
61 } 55 }
62 56
63 StringPiece NullEncrypter::GetKey() const { 57 StringPiece NullEncrypter::GetKey() const { return StringPiece(); }
64 return StringPiece();
65 }
66 58
67 StringPiece NullEncrypter::GetNoncePrefix() const { 59 StringPiece NullEncrypter::GetNoncePrefix() const { return StringPiece(); }
68 return StringPiece();
69 }
70 60
71 } // namespace net 61 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/crypto/null_decrypter_test.cc ('k') | net/quic/crypto/null_encrypter_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698