OLD | NEW |
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 <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <unistd.h> | 9 #include <unistd.h> |
10 | 10 |
(...skipping 28 matching lines...) Expand all Loading... |
39 | 39 |
40 } // namespace | 40 } // namespace |
41 | 41 |
42 namespace base { | 42 namespace base { |
43 | 43 |
44 // NOTE: This function must be cryptographically secure. http://crbug.com/140076 | 44 // NOTE: This function must be cryptographically secure. http://crbug.com/140076 |
45 uint64 RandUint64() { | 45 uint64 RandUint64() { |
46 uint64 number; | 46 uint64 number; |
47 | 47 |
48 int urandom_fd = g_urandom_fd.Pointer()->fd(); | 48 int urandom_fd = g_urandom_fd.Pointer()->fd(); |
49 bool success = file_util::ReadFromFD(urandom_fd, | 49 bool success = ReadFromFD(urandom_fd, reinterpret_cast<char*>(&number), |
50 reinterpret_cast<char*>(&number), | 50 sizeof(number)); |
51 sizeof(number)); | |
52 CHECK(success); | 51 CHECK(success); |
53 | 52 |
54 return number; | 53 return number; |
55 } | 54 } |
56 | 55 |
57 int GetUrandomFD(void) { | 56 int GetUrandomFD(void) { |
58 return g_urandom_fd.Pointer()->fd(); | 57 return g_urandom_fd.Pointer()->fd(); |
59 } | 58 } |
60 | 59 |
61 } // namespace base | 60 } // namespace base |
OLD | NEW |