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

Side by Side Diff: components/webcrypto/algorithms/pbkdf2.cc

Issue 2164753002: Reject deriveBits() for PBKDF2 when given a length of 0. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 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 unified diff | Download patch
« no previous file with comments | « no previous file | components/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 <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
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
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
OLDNEW
« no previous file with comments | « no previous file | components/webcrypto/status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698