Chromium Code Reviews| Index: base/rand_util_nacl.cc |
| diff --git a/base/rand_util_nacl.cc b/base/rand_util_nacl.cc |
| index a8ea202fc7edde189c612969cad9bde5b13af0eb..c5375e7229fabe7e6eacc68186630355b4dcd74e 100644 |
| --- a/base/rand_util_nacl.cc |
| +++ b/base/rand_util_nacl.cc |
| @@ -11,16 +11,29 @@ |
| namespace { |
| +int i = 0; |
| + |
| void GetRandomBytes(void* output, size_t num_bytes) { |
| - CHECK_EQ(0, nacl_secure_random_init()); |
| - char* output_ptr = static_cast<char*>(output); |
| - while (num_bytes > 0) { |
| - size_t nread; |
| - const int error = nacl_secure_random(output_ptr, num_bytes, &nread); |
| - CHECK_EQ(error, 0); |
| - CHECK_LE(nread, num_bytes); |
| - output_ptr += nread; |
| - num_bytes -= nread; |
| + if (nacl_secure_random_init() == 0) { |
| + char* output_ptr = static_cast<char*>(output); |
| + while (num_bytes > 0) { |
| + size_t nread; |
| + const int error = nacl_secure_random(output_ptr, num_bytes, &nread); |
| + CHECK_EQ(error, 0); |
| + CHECK_LE(nread, num_bytes); |
| + output_ptr += nread; |
| + num_bytes -= nread; |
| + } |
| + } else { |
| + char* output_ptr = static_cast<char*>(output); |
| + while (num_bytes > 0) { |
| + int r = (++i) + reinterpret_cast<int>(output_ptr); |
| + while (r >= 255) { |
| + r = r + ( r >> 8); |
| + } |
| + *output_ptr++ = static_cast<char>(r); |
| + num_bytes--; |
| + } |
|
raymes
2014/06/18 05:58:44
I'm not sure that adding this is the right thing t
Peng
2014/06/18 11:14:36
Please ignore changes in base folder. It is a temp
|
| } |
| } |