Chromium Code Reviews| 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 23 matching lines...) Expand all Loading... | |
| 34 private: | 34 private: |
| 35 int fd_; | 35 int fd_; |
| 36 }; | 36 }; |
| 37 | 37 |
| 38 base::LazyInstance<URandomFd> g_urandom_fd = LAZY_INSTANCE_INITIALIZER; | 38 base::LazyInstance<URandomFd> g_urandom_fd = LAZY_INSTANCE_INITIALIZER; |
| 39 | 39 |
| 40 } // namespace | 40 } // namespace |
| 41 | 41 |
| 42 namespace base { | 42 namespace base { |
| 43 | 43 |
| 44 // NOTE: This function must be cryptographically secure: crbug.com/140076 | |
|
akalin
2012/08/02 07:01:12
end with a period.
Prefix with http:// (so it lin
| |
| 44 uint64 RandUint64() { | 45 uint64 RandUint64() { |
| 45 uint64 number; | 46 uint64 number; |
| 46 | 47 |
| 47 int urandom_fd = g_urandom_fd.Pointer()->fd(); | 48 int urandom_fd = g_urandom_fd.Pointer()->fd(); |
| 48 bool success = file_util::ReadFromFD(urandom_fd, | 49 bool success = file_util::ReadFromFD(urandom_fd, |
| 49 reinterpret_cast<char*>(&number), | 50 reinterpret_cast<char*>(&number), |
| 50 sizeof(number)); | 51 sizeof(number)); |
| 51 CHECK(success); | 52 CHECK(success); |
| 52 | 53 |
| 53 return number; | 54 return number; |
| 54 } | 55 } |
| 55 | 56 |
| 56 int GetUrandomFD(void) { | 57 int GetUrandomFD(void) { |
| 57 return g_urandom_fd.Pointer()->fd(); | 58 return g_urandom_fd.Pointer()->fd(); |
| 58 } | 59 } |
| 59 | 60 |
| 60 } // namespace base | 61 } // namespace base |
| OLD | NEW |