| 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
|
|
|