summaryrefslogtreecommitdiffstats
path: root/crypto/symmetric_key_openssl.cc
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-29 20:06:18 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-29 20:06:18 +0000
commitfdce4788af32cb9af8d77361cfddb96249263437 (patch)
tree30c6e4b04a7f46658a57a1265729e0b5ebd2de10 /crypto/symmetric_key_openssl.cc
parent7d1025eeb76f1fe0e7bfe19f9f23b64974a63820 (diff)
downloadchromium_src-fdce4788af32cb9af8d77361cfddb96249263437.zip
chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.tar.gz
chromium_src-fdce4788af32cb9af8d77361cfddb96249263437.tar.bz2
ake string_util::WriteInto() DCHECK() that the supplied |length_with_null| > 1, meaning that the without-'\0' string is non-empty. This replaces the conditional code added recently that makes this case return NULL. It's easier to understand if it's simply an error to call WriteInto() in this case at all.
Add DCHECK()s or conditionals as appropriate to callers in order to ensure this assertion holds. BUG=none TEST=none Review URL: http://codereview.chromium.org/8418034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@112005 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'crypto/symmetric_key_openssl.cc')
-rw-r--r--crypto/symmetric_key_openssl.cc18
1 files changed, 11 insertions, 7 deletions
diff --git a/crypto/symmetric_key_openssl.cc b/crypto/symmetric_key_openssl.cc
index 1d1ad23..899a942 100644
--- a/crypto/symmetric_key_openssl.cc
+++ b/crypto/symmetric_key_openssl.cc
@@ -24,10 +24,10 @@ SymmetricKey::~SymmetricKey() {
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 @@ SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
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,8 +46,11 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
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);
@@ -56,7 +59,8 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
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;
}