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

Side by Side Diff: components/rappor/byte_vector_utils.h

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 (c) 2013 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 #ifndef COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
6 #define COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <vector>
11
12 #include "components/rappor/rappor_parameters.h"
13 #include "crypto/hmac.h"
14
15 namespace rappor {
16
17 // A vector of one byte integers used to store a set of binary bits.
18 typedef std::vector<uint8_t> ByteVector;
19
20 // Bitwise operations on ByteVectors. These methods modify the lhs to be the
21 // result of the bitwise AND, OR, or AND NOT.
22 ByteVector* ByteVectorAnd(ByteVector* lhs, const ByteVector& rhs);
Alexei Svitkine (slow) 2014/01/09 19:23:09 Per style guide, non-const parameters should be la
Steven Holte 2014/01/09 22:03:01 Done.
23 ByteVector* ByteVectorOr(ByteVector* lhs, const ByteVector& rhs);
24 ByteVector* ByteVectorMerge(ByteVector* lhs,
Alexei Svitkine (slow) 2014/01/09 19:23:09 This needs its own more specific comment to explai
Steven Holte 2014/01/09 22:03:01 Done.
25 const ByteVector& rhs,
26 const ByteVector& mask);
27
28 // A utility object for generating random binary data with different
29 // likelihood of bits being true.
30 class ByteVectorGenerator {
31 public:
32 explicit ByteVectorGenerator(size_t byte_count);
Alexei Svitkine (slow) 2014/01/09 19:23:09 Add an explicit destructor and define it in the C+
Steven Holte 2014/01/09 22:03:01 Done.
33 // Generates a random byte vector where each bit is independently set with
Alexei Svitkine (slow) 2014/01/09 19:23:09 Nit: Add an empty line above this.
Steven Holte 2014/01/09 22:03:01 Done.
34 // the given probability.
35 ByteVector GetWeightedRandomByteVector(Probability probability);
36
37 protected:
38 // Generates a random byte from a uniform distribution.
39 virtual uint8_t RandByte();
40
41 private:
42 // Generates a random vector of bytes from a uniform distribution.
43 ByteVector GetRandomByteVector();
Alexei Svitkine (slow) 2014/01/09 19:23:09 Add a line after this.
Steven Holte 2014/01/09 22:03:01 Done.
44 size_t byte_count_;
45 };
Alexei Svitkine (slow) 2014/01/09 19:23:09 DISALLOW_COPY_AND_ASSIGN()? Also below.
Steven Holte 2014/01/09 22:03:01 Done.
46
47 // A ByteVectorGenerator that uses a psuedo-random function to generate
48 // deterministicly random bits.
49 class HmacByteVectorGenerator : public ByteVectorGenerator {
50 public:
51 HmacByteVectorGenerator(size_t byte_count, const std::string& secret);
Alexei Svitkine (slow) 2014/01/09 19:23:09 Document params.
Steven Holte 2014/01/09 22:03:01 Done.
52
53 protected:
54 virtual uint8_t RandByte();
Alexei Svitkine (slow) 2014/01/09 19:23:09 OVERRIDE
Steven Holte 2014/01/09 22:03:01 Done.
55
56 private:
57 crypto::HMAC hmac_;
58 uint64_t hmac_state_;
59 };
60
61 } // namespace rappor
62
63 #endif // COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698