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

Side by Side Diff: content/child/webcrypto/openssl/pbkdf2_openssl.cc

Issue 889493002: Allow PBKDF2 key derivation using an empty password. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 unified diff | Download patch
« no previous file with comments | « no previous file | content/child/webcrypto/status.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/child/webcrypto/algorithm_implementation.h" 5 #include "content/child/webcrypto/algorithm_implementation.h"
6 #include "content/child/webcrypto/crypto_data.h" 6 #include "content/child/webcrypto/crypto_data.h"
7 #include "content/child/webcrypto/openssl/key_openssl.h" 7 #include "content/child/webcrypto/openssl/key_openssl.h"
8 #include "content/child/webcrypto/openssl/util_openssl.h" 8 #include "content/child/webcrypto/openssl/util_openssl.h"
9 #include "content/child/webcrypto/status.h" 9 #include "content/child/webcrypto/status.h"
10 #include "content/child/webcrypto/webcrypto_util.h" 10 #include "content/child/webcrypto/webcrypto_util.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 const EVP_MD* digest_algorithm = GetDigest(hash.id()); 68 const EVP_MD* digest_algorithm = GetDigest(hash.id());
69 if (!digest_algorithm) 69 if (!digest_algorithm)
70 return Status::ErrorUnsupported(); 70 return Status::ErrorUnsupported();
71 71
72 unsigned int keylen_bytes = optional_length_bits / 8; 72 unsigned int keylen_bytes = optional_length_bits / 8;
73 derived_bytes->resize(keylen_bytes); 73 derived_bytes->resize(keylen_bytes);
74 74
75 const std::vector<uint8_t>& password = 75 const std::vector<uint8_t>& password =
76 SymKeyOpenSsl::Cast(base_key)->raw_key_data(); 76 SymKeyOpenSsl::Cast(base_key)->raw_key_data();
77 77
78 // TODO(xun.sun): Empty password would derive random keys with
79 // PKCS5_PBKDF2_HMAC().
80 // https://code.google.com/p/chromium/issues/detail?id=449409
81 //
82 // Rejecting them until it is addressed in BoringSSL.
83 if (password.empty())
84 return Status::ErrorPbkdf2EmptyPassword();
85
86 if (keylen_bytes == 0) 78 if (keylen_bytes == 0)
87 return Status::Success(); 79 return Status::Success();
88 80
89 const char* password_ptr = 81 const char* password_ptr =
90 password.empty() ? NULL : reinterpret_cast<const char*>(&password[0]); 82 password.empty() ? NULL : reinterpret_cast<const char*>(&password[0]);
91 83
92 if (!PKCS5_PBKDF2_HMAC(password_ptr, password.size(), params->salt().data(), 84 if (!PKCS5_PBKDF2_HMAC(password_ptr, password.size(), params->salt().data(),
93 params->salt().size(), params->iterations(), 85 params->salt().size(), params->iterations(),
94 digest_algorithm, keylen_bytes, 86 digest_algorithm, keylen_bytes,
95 &derived_bytes->front())) { 87 &derived_bytes->front())) {
(...skipping 29 matching lines...) Expand all
125 117
126 } // namespace 118 } // namespace
127 119
128 AlgorithmImplementation* CreatePlatformPbkdf2Implementation() { 120 AlgorithmImplementation* CreatePlatformPbkdf2Implementation() {
129 return new Pbkdf2Implementation; 121 return new Pbkdf2Implementation;
130 } 122 }
131 123
132 } // namespace webcrypto 124 } // namespace webcrypto
133 125
134 } // namespace content 126 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/child/webcrypto/status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698