| 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/webcrypto/algorithm_implementation.h" | 9 #include "components/webcrypto/algorithm_implementation.h" |
| 10 #include "components/webcrypto/algorithms/secret_key_util.h" | 10 #include "components/webcrypto/algorithms/secret_key_util.h" |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 unsigned int optional_length_bits, | 57 unsigned int optional_length_bits, |
| 58 std::vector<uint8_t>* derived_bytes) const override { | 58 std::vector<uint8_t>* derived_bytes) const override { |
| 59 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); | 59 crypto::OpenSSLErrStackTracer err_tracer(FROM_HERE); |
| 60 | 60 |
| 61 if (!has_optional_length_bits) | 61 if (!has_optional_length_bits) |
| 62 return Status::ErrorPbkdf2DeriveBitsLengthNotSpecified(); | 62 return Status::ErrorPbkdf2DeriveBitsLengthNotSpecified(); |
| 63 | 63 |
| 64 if (optional_length_bits % 8) | 64 if (optional_length_bits % 8) |
| 65 return Status::ErrorPbkdf2InvalidLength(); | 65 return Status::ErrorPbkdf2InvalidLength(); |
| 66 | 66 |
| 67 // According to RFC 2898 "dkLength" (derived key length) is |
| 68 // described as being a "positive integer", so it is an error for |
| 69 // it to be 0. |
| 70 if (optional_length_bits == 0) |
| 71 return Status::ErrorPbkdf2DeriveBitsLengthZero(); |
| 72 |
| 67 const blink::WebCryptoPbkdf2Params* params = algorithm.pbkdf2Params(); | 73 const blink::WebCryptoPbkdf2Params* params = algorithm.pbkdf2Params(); |
| 68 | 74 |
| 69 if (params->iterations() == 0) | 75 if (params->iterations() == 0) |
| 70 return Status::ErrorPbkdf2Iterations0(); | 76 return Status::ErrorPbkdf2Iterations0(); |
| 71 | 77 |
| 72 const EVP_MD* digest_algorithm = GetDigest(params->hash()); | 78 const EVP_MD* digest_algorithm = GetDigest(params->hash()); |
| 73 if (!digest_algorithm) | 79 if (!digest_algorithm) |
| 74 return Status::ErrorUnsupported(); | 80 return Status::ErrorUnsupported(); |
| 75 | 81 |
| 76 unsigned int keylen_bytes = optional_length_bits / 8; | 82 unsigned int keylen_bytes = optional_length_bits / 8; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 105 } | 111 } |
| 106 }; | 112 }; |
| 107 | 113 |
| 108 } // namespace | 114 } // namespace |
| 109 | 115 |
| 110 std::unique_ptr<AlgorithmImplementation> CreatePbkdf2Implementation() { | 116 std::unique_ptr<AlgorithmImplementation> CreatePbkdf2Implementation() { |
| 111 return base::WrapUnique(new Pbkdf2Implementation); | 117 return base::WrapUnique(new Pbkdf2Implementation); |
| 112 } | 118 } |
| 113 | 119 |
| 114 } // namespace webcrypto | 120 } // namespace webcrypto |
| OLD | NEW |