Sort unlaunched apps on app list start page by apps grid order.
[chromium-blink-merge.git] / net / quic / crypto / null_decrypter.cc
blob8a18172a5c299ded7443f1cbfae583fe8fbd18e2
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_decrypter.h"
6 #include "net/quic/quic_utils.h"
7 #include "net/quic/quic_data_reader.h"
9 using base::StringPiece;
10 using std::string;
12 namespace net {
14 NullDecrypter::NullDecrypter() {}
16 bool NullDecrypter::SetKey(StringPiece key) { return key.empty(); }
18 bool NullDecrypter::SetNoncePrefix(StringPiece nonce_prefix) {
19 return nonce_prefix.empty();
22 bool NullDecrypter::DecryptPacket(QuicPacketSequenceNumber /*seq_number*/,
23 const StringPiece& associated_data,
24 const StringPiece& ciphertext,
25 char* output,
26 size_t* output_length,
27 size_t max_output_length) {
28 QuicDataReader reader(ciphertext.data(), ciphertext.length());
29 uint128 hash;
31 if (!ReadHash(&reader, &hash)) {
32 return false;
35 StringPiece plaintext = reader.ReadRemainingPayload();
36 if (plaintext.length() > max_output_length) {
37 LOG(DFATAL) << "Output buffer must be larger than the plaintext.";
38 return false;
40 if (hash != ComputeHash(associated_data, plaintext)) {
41 return false;
43 // Copy the plaintext to output.
44 memcpy(output, plaintext.data(), plaintext.length());
45 *output_length = plaintext.length();
46 return true;
49 StringPiece NullDecrypter::GetKey() const { return StringPiece(); }
51 StringPiece NullDecrypter::GetNoncePrefix() const { return StringPiece(); }
53 bool NullDecrypter::ReadHash(QuicDataReader* reader, uint128* hash) {
54 uint64 lo;
55 uint32 hi;
56 if (!reader->ReadUInt64(&lo) ||
57 !reader->ReadUInt32(&hi)) {
58 return false;
60 *hash = hi;
61 *hash <<= 64;
62 *hash += lo;
63 return true;
66 uint128 NullDecrypter::ComputeHash(const StringPiece& data1,
67 const StringPiece& data2) const {
68 uint128 correct_hash = QuicUtils::FNV1a_128_Hash_Two(
69 data1.data(), data1.length(), data2.data(), data2.length());
70 uint128 mask(GG_UINT64_C(0x0), GG_UINT64_C(0xffffffff));
71 mask <<= 96;
72 correct_hash &= ~mask;
73 return correct_hash;
76 } // namespace net