blob: b26b4086551ffb48cfd314b89b42679f0efdbebc [file] [log] [blame]
[email protected]1968d9772012-07-26 22:53:131// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "base/rand_util.h"
6
[email protected]4a887832014-06-17 20:28:477#include <nacl/nacl_random.h>
avi9b6f42932015-12-26 22:15:148#include <stddef.h>
9#include <stdint.h>
[email protected]4a887832014-06-17 20:28:4710
[email protected]1968d9772012-07-26 22:53:1311#include "base/logging.h"
[email protected]1968d9772012-07-26 22:53:1312
[email protected]1968d9772012-07-26 22:53:1313namespace base {
14
[email protected]c910c5a2014-01-23 02:14:2815void RandBytes(void* output, size_t output_length) {
John Mellorafab972d2017-09-26 16:28:1916 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 }
[email protected]c910c5a2014-01-23 02:14:2825}
26
[email protected]1968d9772012-07-26 22:53:1327} // namespace base