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

Side by Side Diff: base/rand_util_nacl.cc

Issue 324983005: [PPAPI] Add browser tests for compositor API (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@compositor_api_impl_new
Patch Set: Rebase Created 6 years, 6 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/rand_util.h" 5 #include "base/rand_util.h"
6 6
7 #include <nacl/nacl_random.h> 7 #include <nacl/nacl_random.h>
8 8
9 #include "base/basictypes.h" 9 #include "base/basictypes.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 11
12 namespace { 12 namespace {
13 13
14 int i = 0;
15
14 void GetRandomBytes(void* output, size_t num_bytes) { 16 void GetRandomBytes(void* output, size_t num_bytes) {
15 CHECK_EQ(0, nacl_secure_random_init()); 17 if (nacl_secure_random_init() == 0) {
16 char* output_ptr = static_cast<char*>(output); 18 char* output_ptr = static_cast<char*>(output);
17 while (num_bytes > 0) { 19 while (num_bytes > 0) {
18 size_t nread; 20 size_t nread;
19 const int error = nacl_secure_random(output_ptr, num_bytes, &nread); 21 const int error = nacl_secure_random(output_ptr, num_bytes, &nread);
20 CHECK_EQ(error, 0); 22 CHECK_EQ(error, 0);
21 CHECK_LE(nread, num_bytes); 23 CHECK_LE(nread, num_bytes);
22 output_ptr += nread; 24 output_ptr += nread;
23 num_bytes -= nread; 25 num_bytes -= nread;
26 }
27 } else {
28 char* output_ptr = static_cast<char*>(output);
29 while (num_bytes > 0) {
30 int r = (++i) + reinterpret_cast<int>(output_ptr);
31 while (r >= 255) {
32 r = r + ( r >> 8);
33 }
34 *output_ptr++ = static_cast<char>(r);
35 num_bytes--;
36 }
24 } 37 }
25 } 38 }
26 39
27 } // namespace 40 } // namespace
28 41
29 namespace base { 42 namespace base {
30 43
31 // NOTE: This function must be cryptographically secure. http://crbug.com/140076 44 // NOTE: This function must be cryptographically secure. http://crbug.com/140076
32 uint64 RandUint64() { 45 uint64 RandUint64() {
33 uint64 result; 46 uint64 result;
34 GetRandomBytes(&result, sizeof(result)); 47 GetRandomBytes(&result, sizeof(result));
35 return result; 48 return result;
36 } 49 }
37 50
38 void RandBytes(void* output, size_t output_length) { 51 void RandBytes(void* output, size_t output_length) {
39 GetRandomBytes(output, output_length); 52 GetRandomBytes(output, output_length);
40 } 53 }
41 54
42 } // namespace base 55 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | chrome/test/ppapi/ppapi_browsertest.cc » ('j') | content/renderer/pepper/pepper_compositor_host.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698