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

Unified 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, 12 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 side-by-side diff with in-line comments
Download patch
Index: components/rappor/byte_vector_utils.h
diff --git a/components/rappor/byte_vector_utils.h b/components/rappor/byte_vector_utils.h
new file mode 100644
index 0000000000000000000000000000000000000000..31ac711294139087ce0329d811f7627f66ff60a0
--- /dev/null
+++ b/components/rappor/byte_vector_utils.h
@@ -0,0 +1,63 @@
+// Copyright (c) 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
+#define COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
+
+#include <stddef.h>
+#include <stdint.h>
+#include <vector>
+
+#include "components/rappor/rappor_parameters.h"
+#include "crypto/hmac.h"
+
+namespace rappor {
+
+// A vector of one byte integers used to store a set of binary bits.
+typedef std::vector<uint8_t> ByteVector;
+
+// Bitwise operations on ByteVectors. These methods modify the lhs to be the
+// result of the bitwise AND, OR, or AND NOT.
+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.
+ByteVector* ByteVectorOr(ByteVector* lhs, const ByteVector& rhs);
+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.
+ const ByteVector& rhs,
+ const ByteVector& mask);
+
+// A utility object for generating random binary data with different
+// likelihood of bits being true.
+class ByteVectorGenerator {
+ public:
+ 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.
+ // 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.
+ // the given probability.
+ ByteVector GetWeightedRandomByteVector(Probability probability);
+
+ protected:
+ // Generates a random byte from a uniform distribution.
+ virtual uint8_t RandByte();
+
+ private:
+ // Generates a random vector of bytes from a uniform distribution.
+ 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.
+ size_t byte_count_;
+};
Alexei Svitkine (slow) 2014/01/09 19:23:09 DISALLOW_COPY_AND_ASSIGN()? Also below.
Steven Holte 2014/01/09 22:03:01 Done.
+
+// A ByteVectorGenerator that uses a psuedo-random function to generate
+// deterministicly random bits.
+class HmacByteVectorGenerator : public ByteVectorGenerator {
+ public:
+ 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.
+
+ protected:
+ virtual uint8_t RandByte();
Alexei Svitkine (slow) 2014/01/09 19:23:09 OVERRIDE
Steven Holte 2014/01/09 22:03:01 Done.
+
+ private:
+ crypto::HMAC hmac_;
+ uint64_t hmac_state_;
+};
+
+} // namespace rappor
+
+#endif // COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_

Powered by Google App Engine
This is Rietveld 408576698