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

Side by Side Diff: base/rand_util_posix.cc

Issue 10698177: Added crypto random-number generator (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Comment changes Created 8 years, 4 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 <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
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. crypto/ relies on this.
Ryan Sleevi 2012/08/01 17:52:28 Rather than say "crypto/ relies on this" (which ag
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
OLDNEW
« base/rand_util.h ('K') | « base/rand_util.h ('k') | base/rand_util_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698