| OLD | NEW |
| 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 <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 // based on a secret seed. | 73 // based on a secret seed. |
| 74 class HmacByteVectorGenerator : public ByteVectorGenerator { | 74 class HmacByteVectorGenerator : public ByteVectorGenerator { |
| 75 public: | 75 public: |
| 76 // Constructor takes the size of the vector to generate, along with a | 76 // Constructor takes the size of the vector to generate, along with a |
| 77 // |entropy_input| and |personalization_string| to seed the pseudo-random | 77 // |entropy_input| and |personalization_string| to seed the pseudo-random |
| 78 // number generator. The string parameters are treated as byte arrays. | 78 // number generator. The string parameters are treated as byte arrays. |
| 79 HmacByteVectorGenerator(size_t byte_count, | 79 HmacByteVectorGenerator(size_t byte_count, |
| 80 const std::string& entropy_input, | 80 const std::string& entropy_input, |
| 81 const std::string& personalization_string); | 81 const std::string& personalization_string); |
| 82 | 82 |
| 83 virtual ~HmacByteVectorGenerator(); | 83 ~HmacByteVectorGenerator() override; |
| 84 | 84 |
| 85 // Generates a random string suitable for passing to the constructor as | 85 // Generates a random string suitable for passing to the constructor as |
| 86 // |entropy_input|. | 86 // |entropy_input|. |
| 87 static std::string GenerateEntropyInput(); | 87 static std::string GenerateEntropyInput(); |
| 88 | 88 |
| 89 // Key size required for 128-bit security strength (including nonce). | 89 // Key size required for 128-bit security strength (including nonce). |
| 90 static const size_t kEntropyInputSize; | 90 static const size_t kEntropyInputSize; |
| 91 | 91 |
| 92 protected: | 92 protected: |
| 93 // Generate byte vector generator that streams from the next request instead | 93 // Generate byte vector generator that streams from the next request instead |
| 94 // of the current one. For testing against NIST test vectors only. | 94 // of the current one. For testing against NIST test vectors only. |
| 95 explicit HmacByteVectorGenerator(const HmacByteVectorGenerator& prev_request); | 95 explicit HmacByteVectorGenerator(const HmacByteVectorGenerator& prev_request); |
| 96 | 96 |
| 97 // ByteVector implementation: | 97 // ByteVector implementation: |
| 98 virtual ByteVector GetRandomByteVector() override; | 98 ByteVector GetRandomByteVector() override; |
| 99 | 99 |
| 100 private: | 100 private: |
| 101 // HMAC initalized with the value of "Key" HMAC_DRBG_Initialize. | 101 // HMAC initalized with the value of "Key" HMAC_DRBG_Initialize. |
| 102 crypto::HMAC hmac_; | 102 crypto::HMAC hmac_; |
| 103 | 103 |
| 104 // The "V" value from HMAC_DRBG. | 104 // The "V" value from HMAC_DRBG. |
| 105 ByteVector value_; | 105 ByteVector value_; |
| 106 | 106 |
| 107 // Total number of bytes streamed from the HMAC_DRBG Generate Process. | 107 // Total number of bytes streamed from the HMAC_DRBG Generate Process. |
| 108 size_t generated_bytes_; | 108 size_t generated_bytes_; |
| 109 | 109 |
| 110 DISALLOW_ASSIGN(HmacByteVectorGenerator); | 110 DISALLOW_ASSIGN(HmacByteVectorGenerator); |
| 111 }; | 111 }; |
| 112 | 112 |
| 113 } // namespace rappor | 113 } // namespace rappor |
| 114 | 114 |
| 115 #endif // COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_ | 115 #endif // COMPONENTS_RAPPOR_BYTE_VECTOR_UTILS_H_ |
| OLD | NEW |