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

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

Issue 2156383002: Avoid some string copies in RAPPOR code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | components/rappor/byte_vector_utils.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_ 5 #ifndef COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
6 #define COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_ 6 #define COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
7 7
8 #include <stddef.h> 8 #include <stddef.h>
9 #include <stdint.h> 9 #include <stdint.h>
10 10
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/strings/string_piece.h"
14 #include "components/rappor/rappor_parameters.h" 15 #include "components/rappor/rappor_parameters.h"
15 #include "crypto/hmac.h" 16 #include "crypto/hmac.h"
16 17
17 namespace rappor { 18 namespace rappor {
18 19
19 // A vector of 8-bit integers used to store a set of binary bits. 20 // A vector of 8-bit integers used to store a set of binary bits.
20 typedef std::vector<uint8_t> ByteVector; 21 typedef std::vector<uint8_t> ByteVector;
21 22
22 // Converts the lowest |size| bytes of |value| into a ByteVector. 23 // Converts the lowest |size| bytes of |value| into a ByteVector.
23 void Uint64ToByteVector(uint64_t value, size_t size, ByteVector* output); 24 void Uint64ToByteVector(uint64_t value, size_t size, ByteVector* output);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 // we're choosing to use HMAC_DRBG here, as it is one of the best studied 77 // we're choosing to use HMAC_DRBG here, as it is one of the best studied
77 // and standardized ways of generating deterministic, unpredictable sequences 78 // and standardized ways of generating deterministic, unpredictable sequences
78 // based on a secret seed. 79 // based on a secret seed.
79 class HmacByteVectorGenerator : public ByteVectorGenerator { 80 class HmacByteVectorGenerator : public ByteVectorGenerator {
80 public: 81 public:
81 // Constructor takes the size of the vector to generate, along with a 82 // Constructor takes the size of the vector to generate, along with a
82 // |entropy_input| and |personalization_string| to seed the pseudo-random 83 // |entropy_input| and |personalization_string| to seed the pseudo-random
83 // number generator. The string parameters are treated as byte arrays. 84 // number generator. The string parameters are treated as byte arrays.
84 HmacByteVectorGenerator(size_t byte_count, 85 HmacByteVectorGenerator(size_t byte_count,
85 const std::string& entropy_input, 86 const std::string& entropy_input,
86 const std::string& personalization_string); 87 base::StringPiece personalization_string);
87 88
88 ~HmacByteVectorGenerator() override; 89 ~HmacByteVectorGenerator() override;
89 90
90 // Generates a random string suitable for passing to the constructor as 91 // Generates a random string suitable for passing to the constructor as
91 // |entropy_input|. 92 // |entropy_input|.
92 static std::string GenerateEntropyInput(); 93 static std::string GenerateEntropyInput();
93 94
94 // Key size required for 128-bit security strength (including nonce). 95 // Key size required for 128-bit security strength (including nonce).
95 static const size_t kEntropyInputSize; 96 static const size_t kEntropyInputSize;
96 97
(...skipping 14 matching lines...) Expand all
111 112
112 // Total number of bytes streamed from the HMAC_DRBG Generate Process. 113 // Total number of bytes streamed from the HMAC_DRBG Generate Process.
113 size_t generated_bytes_; 114 size_t generated_bytes_;
114 115
115 DISALLOW_ASSIGN(HmacByteVectorGenerator); 116 DISALLOW_ASSIGN(HmacByteVectorGenerator);
116 }; 117 };
117 118
118 } // namespace rappor 119 } // namespace rappor
119 120
120 #endif // COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_ 121 #endif // COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_
OLDNEW
« no previous file with comments | « no previous file | components/rappor/byte_vector_utils.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698