OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "components/rappor/rappor_metric.h" | |
6 | |
7 #include "base/logging.h" | |
8 | |
9 namespace rappor { | |
10 | |
11 RapporMetric::RapporMetric(const RapporParameters& parameters, | |
12 int32_t cohort) | |
13 : parameters_(parameters), | |
14 bloom_(parameters.bloom_filter_size_bytes, | |
15 parameters.bloom_filter_hash_function_count, | |
16 cohort * parameters.bloom_filter_hash_function_count) { | |
17 DCHECK_GE(cohort, 0); | |
Alexei Svitkine (slow)
2014/01/24 22:09:03
Bad indentation.
| |
18 } | |
19 | |
20 RapporMetric::~RapporMetric() {} | |
21 | |
22 void RapporMetric::AddSamples(const std::vector<std::string>& strings) { | |
23 bloom_.AddStrings(strings); | |
24 } | |
25 | |
26 void RapporMetric::AddSample(const std::string& str) { bloom_.AddString(str); } | |
27 | |
28 ByteVector RapporMetric::GetReport(const std::string& secret) const { | |
29 // Start with the real bloom filter data. | |
30 const ByteVector real_bits(bytes()); | |
31 | |
32 // Generate a deterministically random mask of fake data based on the | |
33 // client's secret key. | |
34 HmacByteVectorGenerator hmac_generator(real_bits.size(), | |
35 secret + parameters()->rappor_name); | |
36 const ByteVector fake_mask = | |
37 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_prob); | |
38 ByteVector fake_ones = | |
39 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_one_prob); | |
40 | |
41 // Redact most of the real data by replacing it with the fake data, hiding | |
42 // and limiting the amount of information an individual client reports on. | |
43 const ByteVector* redacted_bits = | |
44 ByteVectorMerge(fake_mask, real_bits, &fake_ones); | |
45 | |
46 // Generate biased coin flips for each bit. | |
47 ByteVectorGenerator coin_generator(real_bits.size()); | |
48 const ByteVector zero_coins = | |
49 coin_generator.GetWeightedRandomByteVector(parameters()->zero_coin_prob); | |
50 ByteVector one_coins = | |
51 coin_generator.GetWeightedRandomByteVector(parameters()->one_coin_prob); | |
52 | |
53 // Use the redacted data to select which coin type is used for each bit in | |
54 // the final report. | |
55 const ByteVector* output = | |
56 ByteVectorMerge(*redacted_bits, zero_coins, &one_coins); | |
57 | |
58 return *output; | |
59 } | |
60 | |
61 } // namespace rappor | |
OLD | NEW |