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

Side by Side Diff: components/variations/entropy_provider.h

Issue 2503683005: Making the SHA1 entropy provider use the randomization_seed. (Closed)
Patch Set: Updating comments Created 4 years, 1 month 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 | « no previous file | components/variations/entropy_provider.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 #ifndef COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ 5 #ifndef COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_
6 #define COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ 6 #define COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
(...skipping 23 matching lines...) Expand all
34 MersenneTwister mersenne_twister_; 34 MersenneTwister mersenne_twister_;
35 }; 35 };
36 36
37 // Fills |mapping| to create a bijection of values in the range of 37 // Fills |mapping| to create a bijection of values in the range of
38 // [0, |mapping.size()|), permuted based on |randomization_seed|. 38 // [0, |mapping.size()|), permuted based on |randomization_seed|.
39 void PermuteMappingUsingRandomizationSeed(uint32_t randomization_seed, 39 void PermuteMappingUsingRandomizationSeed(uint32_t randomization_seed,
40 std::vector<uint16_t>* mapping); 40 std::vector<uint16_t>* mapping);
41 41
42 } // namespace internal 42 } // namespace internal
43 43
44 // SHA1EntropyProvider is an entropy provider suitable for high entropy 44 // SHA1EntropyProvider is an entropy provider suitable for high entropy sources.
45 // sources. It works by taking the first 64 bits of the SHA1 hash of the 45 // It works by taking the first 64 bits of the SHA1 hash of the entropy source
46 // entropy source concatenated with the trial name and using that for the 46 // concatenated with the trial name, or randomization seed and using that for
47 // final entropy value. 47 // the final entropy value.
48 class SHA1EntropyProvider : public base::FieldTrial::EntropyProvider { 48 class SHA1EntropyProvider : public base::FieldTrial::EntropyProvider {
49 public: 49 public:
50 // Creates a SHA1EntropyProvider with the given |entropy_source|, which 50 // Creates a SHA1EntropyProvider with the given |entropy_source|, which
51 // should contain a large amount of entropy - for example, a textual 51 // should contain a large amount of entropy - for example, a textual
52 // representation of a persistent randomly-generated 128-bit value. 52 // representation of a persistent randomly-generated 128-bit value.
53 explicit SHA1EntropyProvider(const std::string& entropy_source); 53 explicit SHA1EntropyProvider(const std::string& entropy_source);
54 ~SHA1EntropyProvider() override; 54 ~SHA1EntropyProvider() override;
55 55
56 // base::FieldTrial::EntropyProvider implementation: 56 // base::FieldTrial::EntropyProvider implementation:
57 double GetEntropyForTrial(const std::string& trial_name, 57 double GetEntropyForTrial(const std::string& trial_name,
58 uint32_t randomization_seed) const override; 58 uint32_t randomization_seed) const override;
59 59
60 private: 60 private:
61 std::string entropy_source_; 61 std::string entropy_source_;
62 62
63 DISALLOW_COPY_AND_ASSIGN(SHA1EntropyProvider); 63 DISALLOW_COPY_AND_ASSIGN(SHA1EntropyProvider);
64 }; 64 };
65 65
66 // PermutedEntropyProvider is an entropy provider suitable for low entropy 66 // PermutedEntropyProvider is an entropy provider suitable for low entropy
67 // sources (below 16 bits). It uses the field trial name to generate a 67 // sources (below 16 bits). It uses the field trial name or randomization seed
68 // permutation of a mapping array from an initial entropy value to a new value. 68 // to generate a permutation of a mapping array from an initial entropy value to
69 // Note: This provider's performance is O(2^n), where n is the number of bits 69 // a new value. Note: This provider's performance is O(2^n), where n is the
70 // in the entropy source. 70 // number of bits in the entropy source.
71 class PermutedEntropyProvider : public base::FieldTrial::EntropyProvider { 71 class PermutedEntropyProvider : public base::FieldTrial::EntropyProvider {
72 public: 72 public:
73 // Creates a PermutedEntropyProvider with the given |low_entropy_source|, 73 // Creates a PermutedEntropyProvider with the given |low_entropy_source|,
74 // which should have a value in the range of [0, low_entropy_source_max). 74 // which should have a value in the range of [0, low_entropy_source_max).
75 PermutedEntropyProvider(uint16_t low_entropy_source, 75 PermutedEntropyProvider(uint16_t low_entropy_source,
76 size_t low_entropy_source_max); 76 size_t low_entropy_source_max);
77 ~PermutedEntropyProvider() override; 77 ~PermutedEntropyProvider() override;
78 78
79 // base::FieldTrial::EntropyProvider implementation: 79 // base::FieldTrial::EntropyProvider implementation:
80 double GetEntropyForTrial(const std::string& trial_name, 80 double GetEntropyForTrial(const std::string& trial_name,
81 uint32_t randomization_seed) const override; 81 uint32_t randomization_seed) const override;
82 82
83 protected: 83 protected:
84 // Performs the permutation algorithm and returns the permuted value that 84 // Performs the permutation algorithm and returns the permuted value that
85 // corresponds to |low_entropy_source_|. 85 // corresponds to |low_entropy_source_|.
86 virtual uint16_t GetPermutedValue(uint32_t randomization_seed) const; 86 virtual uint16_t GetPermutedValue(uint32_t randomization_seed) const;
87 87
88 private: 88 private:
89 uint16_t low_entropy_source_; 89 uint16_t low_entropy_source_;
90 size_t low_entropy_source_max_; 90 size_t low_entropy_source_max_;
91 91
92 DISALLOW_COPY_AND_ASSIGN(PermutedEntropyProvider); 92 DISALLOW_COPY_AND_ASSIGN(PermutedEntropyProvider);
93 }; 93 };
94 94
95 } // namespace metrics 95 } // namespace metrics
96 96
97 #endif // COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_ 97 #endif // COMPONENTS_VARIATIONS_ENTROPY_PROVIDER_H_
OLDNEW
« no previous file with comments | « no previous file | components/variations/entropy_provider.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698