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

Unified Diff: base/crypto/symmetric_key_openssl.cc

Issue 6683060: Private API for extensions like ssh-client that need access to TCP. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 9 years, 9 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
Index: base/crypto/symmetric_key_openssl.cc
diff --git a/base/crypto/symmetric_key_openssl.cc b/base/crypto/symmetric_key_openssl.cc
index d055b61dcb11cf81c1ec0905a424577a7368cc19..ab9fc49784b3c62a5252a234b65e0056d1a33a26 100644
--- a/base/crypto/symmetric_key_openssl.cc
+++ b/base/crypto/symmetric_key_openssl.cc
@@ -21,6 +21,18 @@ SymmetricKey::~SymmetricKey() {
}
// static
+bool SymmetricKey::GenerateRandomBytes(size_t num_bytes, uint8* out) {
+LOG(ERROR) << "GenerateRandomBytes openssl" << num_bytes;
+ if (num_bytes == 0)
+ return true;
+ if (out == NULL)
+ return false;
+LOG(ERROR) << "GenerateRandomBytes openssl pnt1";
+ OpenSSLErrStackTracer err_tracer(FROM_HERE);
+ return RAND_bytes(out, num_bytes) == 1;
+}
+
+// static
SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
size_t key_size_in_bits) {
DCHECK_EQ(AES, algorithm);
@@ -29,14 +41,14 @@ SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
if (key_size_in_bits == 0)
return NULL;
-
- OpenSSLErrStackTracer err_tracer(FROM_HERE);
scoped_ptr<SymmetricKey> key(new SymmetricKey);
- uint8* key_data =
- reinterpret_cast<uint8*>(WriteInto(&key->key_, key_size_in_bytes + 1));
-
- int rv = RAND_bytes(key_data, key_size_in_bytes);
- return rv == 1 ? key.release() : NULL;
+ if (GenerateRandomBytes(
+ key_size_in_bytes,
+ reinterpret_cast<uint8*>(WriteInto(&key->key_, key_size_in_bytes + 1)))) {
+ return key.release();
+ } else {
+ return NULL;
+ }
}
// static

Powered by Google App Engine
This is Rietveld 408576698