| Index: base/rand_util_nacl.cc
|
| diff --git a/base/rand_util_nacl.cc b/base/rand_util_nacl.cc
|
| index 47450aaba68be254001da2f5e9d84e182b19ed76..f9751217326b4c72730b98fa1018be49f12a4b1a 100644
|
| --- a/base/rand_util_nacl.cc
|
| +++ b/base/rand_util_nacl.cc
|
| @@ -14,21 +14,21 @@ namespace {
|
| class NaclRandom {
|
| public:
|
| NaclRandom() {
|
| - size_t result = nacl_interface_query(NACL_IRT_RANDOM_v0_1,
|
| - &random_, sizeof(random_));
|
| + const size_t result =
|
| + nacl_interface_query(NACL_IRT_RANDOM_v0_1, &random_, sizeof(random_));
|
| CHECK_EQ(result, sizeof(random_));
|
| }
|
|
|
| - ~NaclRandom() {
|
| - }
|
| + ~NaclRandom() {}
|
|
|
| - void GetRandomBytes(char* buffer, uint32_t num_bytes) {
|
| + void GetRandomBytes(void* output, size_t num_bytes) {
|
| + char* output_ptr = static_cast<char*>(output);
|
| while (num_bytes > 0) {
|
| size_t nread;
|
| - int error = random_.get_random_bytes(buffer, num_bytes, &nread);
|
| + const int error = random_.get_random_bytes(output_ptr, num_bytes, &nread);
|
| CHECK_EQ(error, 0);
|
| CHECK_LE(nread, num_bytes);
|
| - buffer += nread;
|
| + output_ptr += nread;
|
| num_bytes -= nread;
|
| }
|
| }
|
| @@ -43,11 +43,15 @@ base::LazyInstance<NaclRandom>::Leaky g_nacl_random = LAZY_INSTANCE_INITIALIZER;
|
|
|
| namespace base {
|
|
|
| +// NOTE: This function must be cryptographically secure. http://crbug.com/140076
|
| uint64 RandUint64() {
|
| uint64 result;
|
| - g_nacl_random.Pointer()->GetRandomBytes(
|
| - reinterpret_cast<char*>(&result), sizeof(result));
|
| + g_nacl_random.Pointer()->GetRandomBytes(&result, sizeof(result));
|
| return result;
|
| }
|
|
|
| +void RandBytes(void* output, size_t output_length) {
|
| + g_nacl_random.Pointer()->GetRandomBytes(output, output_length);
|
| +}
|
| +
|
| } // namespace base
|
|
|