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

Unified Diff: base/rand_util.cc

Issue 6873156: Move crypto_helpers from sync to base (Closed) Base URL: http://git.chromium.org/git/chromium.git@trunk
Patch Set: Correct doc and test Created 9 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/rand_util.h ('k') | base/rand_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/rand_util.cc
diff --git a/base/rand_util.cc b/base/rand_util.cc
index d89f8b725080d3912944b5b7bc60c19096c683ae..9d90a88e9de3db6685c0f7eb6567be40a6e4045d 100644
--- a/base/rand_util.cc
+++ b/base/rand_util.cc
@@ -41,6 +41,17 @@ uint64 RandGenerator(uint64 max) {
return base::RandUint64() % max;
}
+void RandBytes(void* output, size_t output_length) {
+ uint64 random_int;
+ const char* random_int_bytes = reinterpret_cast<const char*>(&random_int);
+ size_t random_int_size = sizeof(random_int);
+ for (size_t i = 0; i < output_length; i += random_int_size) {
+ random_int = base::RandUint64();
+ size_t copy_count = std::min(output_length - i, random_int_size);
+ memcpy(((uint8*)output) + i, random_int_bytes, copy_count);
+ }
abarth-chromium 2011/05/02 18:23:20 I'd recommend re-implementing RandBytesAsString in
+}
+
std::string RandBytesAsString(size_t length) {
const size_t kBitsPerChar = 8;
const int kCharsPerInt64 = sizeof(uint64)/sizeof(char);
« no previous file with comments | « base/rand_util.h ('k') | base/rand_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698