OLD | NEW |
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 "components/variations/entropy_provider.h" | 5 #include "components/variations/entropy_provider.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <limits> | 8 #include <limits> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 // it has been observed that this method does not result in a uniform | 87 // it has been observed that this method does not result in a uniform |
88 // distribution given the same |trial_name|. When using such a low entropy | 88 // distribution given the same |trial_name|. When using such a low entropy |
89 // source, PermutedEntropyProvider should be used instead. | 89 // source, PermutedEntropyProvider should be used instead. |
90 std::string input(entropy_source_ + trial_name); | 90 std::string input(entropy_source_ + trial_name); |
91 unsigned char sha1_hash[base::kSHA1Length]; | 91 unsigned char sha1_hash[base::kSHA1Length]; |
92 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()), | 92 base::SHA1HashBytes(reinterpret_cast<const unsigned char*>(input.c_str()), |
93 input.size(), | 93 input.size(), |
94 sha1_hash); | 94 sha1_hash); |
95 | 95 |
96 uint64 bits; | 96 uint64 bits; |
97 COMPILE_ASSERT(sizeof(bits) < sizeof(sha1_hash), need_more_data); | 97 static_assert(sizeof(bits) < sizeof(sha1_hash), "more data required"); |
98 memcpy(&bits, sha1_hash, sizeof(bits)); | 98 memcpy(&bits, sha1_hash, sizeof(bits)); |
99 bits = base::ByteSwapToLE64(bits); | 99 bits = base::ByteSwapToLE64(bits); |
100 | 100 |
101 return base::BitsToOpenEndedUnitInterval(bits); | 101 return base::BitsToOpenEndedUnitInterval(bits); |
102 } | 102 } |
103 | 103 |
104 PermutedEntropyProvider::PermutedEntropyProvider( | 104 PermutedEntropyProvider::PermutedEntropyProvider( |
105 uint16 low_entropy_source, | 105 uint16 low_entropy_source, |
106 size_t low_entropy_source_max) | 106 size_t low_entropy_source_max) |
107 : low_entropy_source_(low_entropy_source), | 107 : low_entropy_source_(low_entropy_source), |
(...skipping 16 matching lines...) Expand all Loading... |
124 } | 124 } |
125 | 125 |
126 uint16 PermutedEntropyProvider::GetPermutedValue( | 126 uint16 PermutedEntropyProvider::GetPermutedValue( |
127 uint32 randomization_seed) const { | 127 uint32 randomization_seed) const { |
128 std::vector<uint16> mapping(low_entropy_source_max_); | 128 std::vector<uint16> mapping(low_entropy_source_max_); |
129 internal::PermuteMappingUsingRandomizationSeed(randomization_seed, &mapping); | 129 internal::PermuteMappingUsingRandomizationSeed(randomization_seed, &mapping); |
130 return mapping[low_entropy_source_]; | 130 return mapping[low_entropy_source_]; |
131 } | 131 } |
132 | 132 |
133 } // namespace metrics | 133 } // namespace metrics |
OLD | NEW |