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

Unified Diff: base/crypto/symmetric_key_nss.cc

Issue 1347002: Add Mac implementations of new SymmetricKey and Encryptor classes. (Closed)
Patch Set: Responding to feedback Created 10 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_nss.cc
diff --git a/base/crypto/symmetric_key_nss.cc b/base/crypto/symmetric_key_nss.cc
index 7196ae4e7c9277e8528a283e033fab4bdb063540..0fb8cfa537336a56d3cd50659254bf1859799f96 100644
--- a/base/crypto/symmetric_key_nss.cc
+++ b/base/crypto/symmetric_key_nss.cc
@@ -13,19 +13,20 @@
namespace base {
// static
-SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm, size_t key_size) {
+SymmetricKey* SymmetricKey::GenerateRandomKey(Algorithm algorithm,
+ size_t key_size_in_bits) {
DCHECK_EQ(AES, algorithm);
EnsureNSSInit();
- if (key_size == 0)
+ if (key_size_in_bits == 0)
return NULL;
ScopedPK11Slot slot(PK11_GetBestSlot(CKM_AES_KEY_GEN, NULL));
if (!slot.get())
return NULL;
- PK11SymKey* sym_key = PK11_KeyGen(slot.get(), CKM_AES_KEY_GEN, NULL, key_size,
- NULL);
+ PK11SymKey* sym_key = PK11_KeyGen(slot.get(), CKM_AES_KEY_GEN, NULL,
+ key_size_in_bits / 8, NULL);
if (!sym_key)
return NULL;
@@ -37,9 +38,9 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
const std::string& password,
const std::string& salt,
size_t iterations,
- size_t key_size) {
+ size_t key_size_in_bits) {
EnsureNSSInit();
- if (salt.empty() || iterations == 0 || key_size == 0)
+ if (salt.empty() || iterations == 0 || key_size_in_bits == 0)
return NULL;
SECItem password_item;
@@ -60,7 +61,7 @@ SymmetricKey* SymmetricKey::DeriveKeyFromPassword(Algorithm algorithm,
ScopedSECAlgorithmID alg_id(PK11_CreatePBEV2AlgorithmID(SEC_OID_PKCS5_PBKDF2,
cipher_algorithm,
SEC_OID_HMAC_SHA1,
- key_size,
+ key_size_in_bits / 8,
iterations,
&salt_item));
if (!alg_id.get())

Powered by Google App Engine
This is Rietveld 408576698