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

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

Powered by Google App Engine
This is Rietveld 408576698