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

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

Issue 266243004: Clang format slam. Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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
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_decrypter.h" 5 #include "net/quic/crypto/null_decrypter.h"
6 #include "net/quic/quic_utils.h" 6 #include "net/quic/quic_utils.h"
7 #include "net/quic/quic_data_reader.h" 7 #include "net/quic/quic_data_reader.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 NullDecrypter::NullDecrypter() {} 14 NullDecrypter::NullDecrypter() {
15 }
15 16
16 bool NullDecrypter::SetKey(StringPiece key) { return key.empty(); } 17 bool NullDecrypter::SetKey(StringPiece key) {
18 return key.empty();
19 }
17 20
18 bool NullDecrypter::SetNoncePrefix(StringPiece nonce_prefix) { 21 bool NullDecrypter::SetNoncePrefix(StringPiece nonce_prefix) {
19 return nonce_prefix.empty(); 22 return nonce_prefix.empty();
20 } 23 }
21 24
22 bool NullDecrypter::Decrypt(StringPiece /*nonce*/, 25 bool NullDecrypter::Decrypt(StringPiece /*nonce*/,
23 StringPiece associated_data, 26 StringPiece associated_data,
24 StringPiece ciphertext, 27 StringPiece ciphertext,
25 unsigned char* output, 28 unsigned char* output,
26 size_t* output_length) { 29 size_t* output_length) {
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 // TODO(rch): avoid buffer copy here 64 // TODO(rch): avoid buffer copy here
62 string buffer = associated_data.as_string(); 65 string buffer = associated_data.as_string();
63 plaintext.AppendToString(&buffer); 66 plaintext.AppendToString(&buffer);
64 67
65 if (hash != ComputeHash(buffer)) { 68 if (hash != ComputeHash(buffer)) {
66 return NULL; 69 return NULL;
67 } 70 }
68 return new QuicData(plaintext.data(), plaintext.length()); 71 return new QuicData(plaintext.data(), plaintext.length());
69 } 72 }
70 73
71 StringPiece NullDecrypter::GetKey() const { return StringPiece(); } 74 StringPiece NullDecrypter::GetKey() const {
75 return StringPiece();
76 }
72 77
73 StringPiece NullDecrypter::GetNoncePrefix() const { return StringPiece(); } 78 StringPiece NullDecrypter::GetNoncePrefix() const {
79 return StringPiece();
80 }
74 81
75 bool NullDecrypter::ReadHash(QuicDataReader* reader, uint128* hash) { 82 bool NullDecrypter::ReadHash(QuicDataReader* reader, uint128* hash) {
76 uint64 lo; 83 uint64 lo;
77 uint32 hi; 84 uint32 hi;
78 if (!reader->ReadUInt64(&lo) || 85 if (!reader->ReadUInt64(&lo) || !reader->ReadUInt32(&hi)) {
79 !reader->ReadUInt32(&hi)) {
80 return false; 86 return false;
81 } 87 }
82 *hash = hi; 88 *hash = hi;
83 *hash <<= 64; 89 *hash <<= 64;
84 *hash += lo; 90 *hash += lo;
85 return true; 91 return true;
86 } 92 }
87 93
88 uint128 NullDecrypter::ComputeHash(const string& data) const { 94 uint128 NullDecrypter::ComputeHash(const string& data) const {
89 uint128 correct_hash = QuicUtils::FNV1a_128_Hash(data.data(), data.length()); 95 uint128 correct_hash = QuicUtils::FNV1a_128_Hash(data.data(), data.length());
90 uint128 mask(GG_UINT64_C(0x0), GG_UINT64_C(0xffffffff)); 96 uint128 mask(GG_UINT64_C(0x0), GG_UINT64_C(0xffffffff));
91 mask <<= 96; 97 mask <<= 96;
92 correct_hash &= ~mask; 98 correct_hash &= ~mask;
93 return correct_hash; 99 return correct_hash;
94 } 100 }
95 101
96 } // namespace net 102 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698