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

Unified Diff: crypto/symmetric_key_openssl.cc

Issue 8418034: Make string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 1 month 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 | « crypto/symmetric_key.h ('k') | media/audio/win/audio_manager_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/symmetric_key_openssl.cc
===================================================================
--- crypto/symmetric_key_openssl.cc (revision 111826)
+++ crypto/symmetric_key_openssl.cc (working copy)
@@ -24,10 +24,10 @@
SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
size_t key_size_in_bits) {
DCHECK_EQ(AES, algorithm);
- int key_size_in_bytes = key_size_in_bits / 8;
- DCHECK_EQ(static_cast<int>(key_size_in_bits), key_size_in_bytes * 8);
+ size_t key_size_in_bytes = key_size_in_bits / 8;
+ DCHECK_EQ(key_size_in_bits, key_size_in_bytes * 8);
- if (key_size_in_bits == 0)
+ if (key_size_in_bytes == 0)
return NULL;
OpenSSLErrStackTracer err_tracer(FROM_HERE);
@@ -35,7 +35,7 @@
uint8* key_data =
reinterpret_cast<uint8*>(WriteInto(&key->key_, key_size_in_bytes + 1));
- int rv = RAND_bytes(key_data, key_size_in_bytes);
+ int rv = RAND_bytes(key_data, static_cast<int>(key_size_in_bytes));
return rv == 1 ? key.release() : NULL;
}
@@ -46,9 +46,12 @@
size_t iterations,
size_t key_size_in_bits) {
DCHECK(algorithm == AES || algorithm == HMAC_SHA1);
- int key_size_in_bytes = key_size_in_bits / 8;
- DCHECK_EQ(static_cast<int>(key_size_in_bits), key_size_in_bytes * 8);
+ size_t key_size_in_bytes = key_size_in_bits / 8;
+ DCHECK_EQ(key_size_in_bits, key_size_in_bytes * 8);
+ if (key_size_in_bytes == 0)
+ return NULL;
+
OpenSSLErrStackTracer err_tracer(FROM_HERE);
scoped_ptr<SymmetricKey> key(new SymmetricKey);
uint8* key_data =
@@ -56,7 +59,8 @@
int rv = PKCS5_PBKDF2_HMAC_SHA1(password.data(), password.length(),
reinterpret_cast<const uint8*>(salt.data()),
salt.length(), iterations,
- key_size_in_bytes, key_data);
+ static_cast<int>(key_size_in_bytes),
+ key_data);
return rv == 1 ? key.release() : NULL;
}
« no previous file with comments | « crypto/symmetric_key.h ('k') | media/audio/win/audio_manager_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698