| 6 |
| 7 | #include <nacl/nacl_random.h> |
| 8 | #include <stddef.h> |
| 9 | #include <stdint.h> |
| 10 |
| 11 | #include "base/logging.h" |
| 12 |
| 13 | namespace base { |
| 14 |
| 15 | void RandBytes(void* output, size_t output_length) { |
| 16 | char* output_ptr = static_cast<char*>(output); |
| 17 | while (output_length > 0) { |
| 18 | size_t nread; |
| 19 | const int error = nacl_secure_random(output_ptr, output_length, &nread); |
| 20 | CHECK_EQ(error, 0); |
| 21 | CHECK_LE(nread, output_length); |
| 22 | output_ptr += nread; |
| 23 | output_length -= nread; |
| 24 | } |
| 25 | } |
| 26 |
| 27 | } // namespace base |
| 28 |