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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 | 55 |
56 // Generates a random vector of bytes from a uniform distribution. | 56 // Generates a random vector of bytes from a uniform distribution. |
57 virtual ByteVector GetRandomByteVector(); | 57 virtual ByteVector GetRandomByteVector(); |
58 | 58 |
59 private: | 59 private: |
60 size_t byte_count_; | 60 size_t byte_count_; |
61 | 61 |
62 DISALLOW_COPY_AND_ASSIGN(ByteVectorGenerator); | 62 DISALLOW_COPY_AND_ASSIGN(ByteVectorGenerator); |
63 }; | 63 }; |
64 | 64 |
65 // A ByteVectorGenerator that uses a psuedo-random function to generate a | 65 // A ByteVectorGenerator that uses a pseudo-random function to generate a |
66 // deterministically random bits. This class only implements a single request | 66 // deterministically random bits. This class only implements a single request |
67 // from HMAC_DRBG and streams up to 2^19 bits from that request. | 67 // from HMAC_DRBG and streams up to 2^19 bits from that request. |
68 // Ref: http://csrc.nist.gov/publications/nistpubs/800-90A/SP800-90A.pdf | 68 // Ref: http://csrc.nist.gov/publications/nistpubs/800-90A/SP800-90A.pdf |
69 // We're using our own PRNG instead of crypto::RandBytes because we need to | 69 // We're using our own PRNG instead of crypto::RandBytes because we need to |
70 // generate a repeatable sequence of bits from the same seed. Conservatively, | 70 // generate a repeatable sequence of bits from the same seed. Conservatively, |
71 // we're choosing to use HMAC_DRBG here, as it is one of the best studied | 71 // we're choosing to use HMAC_DRBG here, as it is one of the best studied |
72 // and standardized ways of generating deterministic, unpredictable sequences | 72 // and standardized ways of generating deterministic, unpredictable sequences |
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: |
(...skipping 30 matching lines...) Expand all Loading... |
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 |