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

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

Issue 2544533002: Have all overloads of webcrypto::AlgorithmImplementation::DeserializeKeyForClone check the params t… (Closed)
Patch Set: add a test for a case similar to the one the fuzzer found Created 4 years 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/ptr_util.h" 9 #include "base/memory/ptr_util.h"
10 #include "base/numerics/safe_math.h" 10 #include "base/numerics/safe_math.h"
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 284
285 return Status::Success(); 285 return Status::Success();
286 } 286 }
287 287
288 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm, 288 Status DeserializeKeyForClone(const blink::WebCryptoKeyAlgorithm& algorithm,
289 blink::WebCryptoKeyType type, 289 blink::WebCryptoKeyType type,
290 bool extractable, 290 bool extractable,
291 blink::WebCryptoKeyUsageMask usages, 291 blink::WebCryptoKeyUsageMask usages,
292 const CryptoData& key_data, 292 const CryptoData& key_data,
293 blink::WebCryptoKey* key) const override { 293 blink::WebCryptoKey* key) const override {
294 if (algorithm.paramsType() != blink::WebCryptoKeyAlgorithmParamsTypeHmac)
295 return Status::ErrorUnexpected();
296
eroman 2016/11/30 19:15:50 Can you also add a test for: type == WebCryptoK
294 return CreateWebCryptoSecretKey(key_data, algorithm, extractable, usages, 297 return CreateWebCryptoSecretKey(key_data, algorithm, extractable, usages,
295 key); 298 key);
296 } 299 }
297 300
298 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm, 301 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
299 bool* has_length_bits, 302 bool* has_length_bits,
300 unsigned int* length_bits) const override { 303 unsigned int* length_bits) const override {
301 const blink::WebCryptoHmacImportParams* params = 304 const blink::WebCryptoHmacImportParams* params =
302 key_length_algorithm.hmacImportParams(); 305 key_length_algorithm.hmacImportParams();
303 306
304 *has_length_bits = true; 307 *has_length_bits = true;
305 if (params->hasLengthBits()) { 308 if (params->hasLengthBits()) {
306 *length_bits = params->optionalLengthBits(); 309 *length_bits = params->optionalLengthBits();
307 if (*length_bits == 0) 310 if (*length_bits == 0)
308 return Status::ErrorGetHmacKeyLengthZero(); 311 return Status::ErrorGetHmacKeyLengthZero();
309 return Status::Success(); 312 return Status::Success();
310 } 313 }
311 314
312 return GetDigestBlockSizeBits(params->hash(), length_bits); 315 return GetDigestBlockSizeBits(params->hash(), length_bits);
313 } 316 }
314 }; 317 };
315 318
316 } // namespace 319 } // namespace
317 320
318 std::unique_ptr<AlgorithmImplementation> CreateHmacImplementation() { 321 std::unique_ptr<AlgorithmImplementation> CreateHmacImplementation() {
319 return base::WrapUnique(new HmacImplementation); 322 return base::WrapUnique(new HmacImplementation);
320 } 323 }
321 324
322 } // namespace webcrypto 325 } // namespace webcrypto
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698