Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(446)

Side by Side Diff: base/rand_util_nacl.cc

Issue 1647803004: Move base to DEPS (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « base/rand_util.cc ('k') | base/rand_util_posix.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // 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
7 #include <nacl/nacl_random.h>
8
9 #include "base/basictypes.h"
10 #include "base/logging.h"
11
12 namespace {
13
14 void GetRandomBytes(void* output, size_t num_bytes) {
15 char* output_ptr = static_cast<char*>(output);
16 while (num_bytes > 0) {
17 size_t nread;
18 const int error = nacl_secure_random(output_ptr, num_bytes, &nread);
19 CHECK_EQ(error, 0);
20 CHECK_LE(nread, num_bytes);
21 output_ptr += nread;
22 num_bytes -= nread;
23 }
24 }
25
26 } // namespace
27
28 namespace base {
29
30 // NOTE: This function must be cryptographically secure. http://crbug.com/140076
31 uint64 RandUint64() {
32 uint64 result;
33 GetRandomBytes(&result, sizeof(result));
34 return result;
35 }
36
37 void RandBytes(void* output, size_t output_length) {
38 GetRandomBytes(output, output_length);
39 }
40
41 } // namespace base
OLDNEW
« no previous file with comments | « base/rand_util.cc ('k') | base/rand_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698