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

Unified Diff: crypto/symmetric_key_nss.cc

Issue 420883003: Desupport AES-192 in crypto::SymmetricKey. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Whitelist rather than blacklist Created 6 years, 5 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
« no previous file with comments | « crypto/encryptor_unittest.cc ('k') | crypto/symmetric_key_openssl.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: crypto/symmetric_key_nss.cc
diff --git a/crypto/symmetric_key_nss.cc b/crypto/symmetric_key_nss.cc
index b438b376b256050ca950be4557389ae41211353d..95ca9bd073ed8bbedbdbe547b5342f645ad38892 100644
--- a/crypto/symmetric_key_nss.cc
+++ b/crypto/symmetric_key_nss.cc
@@ -20,7 +20,11 @@ SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
DCHECK_EQ(AES, algorithm);
EnsureNSSInit();
- if (key_size_in_bits == 0)
+
+ // Whitelist supported key sizes to avoid accidentaly relying on
+ // algorithms available in NSS but not BoringSSL and vice
+ // versa. Note that BoringSSL does not support AES-192.
+ if (key_size_in_bits != 128 && key_size_in_bits != 256)
return NULL;
ScopedPK11Slot slot(PK11_GetInternalSlot());
@@ -45,6 +49,14 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
if (salt.empty() || iterations == 0 || key_size_in_bits == 0)
return NULL;
+ if (algorithm == AES) {
+ // Whitelist supported key sizes to avoid accidentaly relying on
+ // algorithms available in NSS but not BoringSSL and vice
+ // versa. Note that BoringSSL does not support AES-192.
+ if (key_size_in_bits != 128 && key_size_in_bits != 256)
+ return NULL;
+ }
+
SECItem password_item;
password_item.type = siBuffer;
password_item.data = reinterpret_cast<unsigned char*>(
@@ -84,6 +96,15 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
SymmetricKey* SymmetricKey::Import(Algorithm algorithm,
const std::string& raw_key) {
EnsureNSSInit();
+
+ if (algorithm == AES) {
+ // Whitelist supported key sizes to avoid accidentaly relying on
+ // algorithms available in NSS but not BoringSSL and vice
+ // versa. Note that BoringSSL does not support AES-192.
+ if (raw_key.size() != 128/8 && raw_key.size() != 256/8)
+ return NULL;
+ }
+
CK_MECHANISM_TYPE cipher =
algorithm == AES ? CKM_AES_CBC : CKM_SHA_1_HMAC;
« no previous file with comments | « crypto/encryptor_unittest.cc ('k') | crypto/symmetric_key_openssl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698