 Chromium Code Reviews
 Chromium Code Reviews Issue 6873156:
  Move crypto_helpers from sync to base  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk
    
  
    Issue 6873156:
  Move crypto_helpers from sync to base  (Closed) 
  Base URL: http://git.chromium.org/git/chromium.git@trunk| OLD | NEW | 
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "crypto/random.h" | |
| 6 | |
| 7 #include <string> | |
| 8 | |
| 9 #include "base/base64.h" | |
| 10 #include "base/rand_util.h" | |
| 11 | |
| 12 void GetRandomBytes(char* output, int output_length) { | |
| 13 uint64 random_int; | |
| 14 const char* random_int_bytes = reinterpret_cast<const char*>(&random_int); | |
| 15 int random_int_size = sizeof(random_int); | |
| 16 for (int i = 0; i < output_length; i += random_int_size) { | |
| 17 random_int = base::RandUint64(); | |
| 
agl
2011/04/26 13:59:37
This is not cryptographically strong on Windows.
 | |
| 18 int copy_count = std::min(output_length - i, random_int_size); | |
| 19 memcpy(output + i, random_int_bytes, copy_count); | |
| 20 } | |
| 21 } | |
| 22 | |
| 23 std::string Generate128BitRandomHexString() { | |
| 24 const int kNumberBytes = 128 / 8; | |
| 25 std::string random_bytes(kNumberBytes, ' '); | |
| 
agl
2011/04/26 13:59:37
no need for a std::string here, a uint8[] will do.
 
qsr (NOT THE RIGHT qsr)
2011/04/26 15:24:18
Except that the base64_encode function expect stri
 | |
| 26 GetRandomBytes(&random_bytes[0], kNumberBytes); | |
| 27 std::string base64_encoded_bytes; | |
| 28 base::Base64Encode(random_bytes, &base64_encoded_bytes); | |
| 
agl
2011/04/26 13:59:37
The function name suggests that the data should be
 
qsr (NOT THE RIGHT qsr)
2011/04/26 15:24:18
As this is a refactoring, I will modify the name o
 | |
| 29 return base64_encoded_bytes; | |
| 30 } | |
| OLD | NEW |