OLD | NEW |
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 Loading... |
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 Loading... |
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 |
OLD | NEW |