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

Side by Side Diff: components/rappor/byte_vector_utils.cc

Issue 1112003002: Use 64 bit shift when convert uint64_t to ByteVector (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Restore the cast Created 5 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
« no previous file with comments | « components/rappor/byte_vector_utils.h ('k') | components/rappor/byte_vector_utils_unittest.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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "components/rappor/byte_vector_utils.h" 5 #include "components/rappor/byte_vector_utils.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/rand_util.h" 10 #include "base/rand_util.h"
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 return true; 71 return true;
72 // 4. K = HMAC(K, V || 0x01 || provided_data) 72 // 4. K = HMAC(K, V || 0x01 || provided_data)
73 if (!HMAC_Rotate(*hmac2, Concat(*value, 0x01, provided_data), out_hmac)) 73 if (!HMAC_Rotate(*hmac2, Concat(*value, 0x01, provided_data), out_hmac))
74 return false; 74 return false;
75 // 5. V = HMAC(K, V) 75 // 5. V = HMAC(K, V)
76 return HMAC_Rehash(*out_hmac, value); 76 return HMAC_Rehash(*out_hmac, value);
77 } 77 }
78 78
79 } // namespace 79 } // namespace
80 80
81 void Uint64ToByteVector(uint64_t value, size_t size, ByteVector* output) {
82 DCHECK_LE(size, 8u);
83 DCHECK_EQ(size, output->size());
84 for (size_t i = 0; i < size; i++) {
85 // Get the value of the i-th smallest byte and copy it to the byte vector.
86 uint64_t shift = i * 8;
87 uint64_t byte_mask = static_cast<uint64_t>(0xff) << shift;
88 (*output)[i] = (value & byte_mask) >> shift;
89 }
90 }
91
81 ByteVector* ByteVectorAnd(const ByteVector& lhs, ByteVector* rhs) { 92 ByteVector* ByteVectorAnd(const ByteVector& lhs, ByteVector* rhs) {
82 DCHECK_EQ(lhs.size(), rhs->size()); 93 DCHECK_EQ(lhs.size(), rhs->size());
83 for (size_t i = 0; i < lhs.size(); ++i) { 94 for (size_t i = 0; i < lhs.size(); ++i) {
84 (*rhs)[i] = lhs[i] & (*rhs)[i]; 95 (*rhs)[i] = lhs[i] & (*rhs)[i];
85 } 96 }
86 return rhs; 97 return rhs;
87 } 98 }
88 99
89 ByteVector* ByteVectorOr(const ByteVector& lhs, ByteVector* rhs) { 100 ByteVector* ByteVectorOr(const ByteVector& lhs, ByteVector* rhs) {
90 DCHECK_EQ(lhs.size(), rhs->size()); 101 DCHECK_EQ(lhs.size(), rhs->size());
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 bytes_to_go -= n; 227 bytes_to_go -= n;
217 generated_bytes_ += n; 228 generated_bytes_ += n;
218 // Check max_number_of_bits_per_request from 10.1 Table 2 229 // Check max_number_of_bits_per_request from 10.1 Table 2
219 // max_number_of_bits_per_request == 2^19 bits == 2^16 bytes 230 // max_number_of_bits_per_request == 2^19 bits == 2^16 bytes
220 DCHECK_LT(generated_bytes_, 1U << 16); 231 DCHECK_LT(generated_bytes_, 1U << 16);
221 } 232 }
222 return bytes; 233 return bytes;
223 } 234 }
224 235
225 } // namespace rappor 236 } // namespace rappor
OLDNEW
« no previous file with comments | « components/rappor/byte_vector_utils.h ('k') | components/rappor/byte_vector_utils_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698