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

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

Issue 49753002: RAPPOR implementation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 10 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
OLDNEW
(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);
18 }
19
20 RapporMetric::~RapporMetric() {}
21
22 void RapporMetric::AddSample(const std::string& str) { bloom_.AddString(str); }
23
24 ByteVector RapporMetric::GetReport(const std::string& secret) const {
25 // Start with the real bloom filter data.
26 const ByteVector real_bits(bytes());
27
28 // Generate a deterministically random mask of fake data using the
29 // client's secret key + real data as a seed.
30 std::string seed = secret + parameters()->rappor_name +
31 std::string(real_bits.begin(), real_bits.end());
32 HmacByteVectorGenerator hmac_generator(real_bits.size(), seed);
33 const ByteVector fake_mask =
34 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_prob);
35 ByteVector fake_ones =
36 hmac_generator.GetWeightedRandomByteVector(parameters()->fake_one_prob);
37
38 // Redact most of the real data by replacing it with the fake data, hiding
39 // and limiting the amount of information an individual client reports on.
40 const ByteVector* redacted_bits =
41 ByteVectorMerge(fake_mask, real_bits, &fake_ones);
42
43 // Generate biased coin flips for each bit.
44 ByteVectorGenerator coin_generator(real_bits.size());
45 const ByteVector zero_coins =
46 coin_generator.GetWeightedRandomByteVector(parameters()->zero_coin_prob);
47 ByteVector one_coins =
48 coin_generator.GetWeightedRandomByteVector(parameters()->one_coin_prob);
49
50 // Use the redacted data to select which coin type is used for each bit in
51 // the final report.
52 const ByteVector* output =
53 ByteVectorMerge(*redacted_bits, zero_coins, &one_coins);
54
55 return *output;
56 }
57
58 } // namespace rappor
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698