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

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: additional checks, per eroman 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
« no previous file with comments | « components/webcrypto/algorithms/hkdf.cc ('k') | components/webcrypto/algorithms/pbkdf2.cc » ('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 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 type != blink::WebCryptoKeyTypeSecret)
296 return Status::ErrorUnexpected();
297
294 return CreateWebCryptoSecretKey(key_data, algorithm, extractable, usages, 298 return CreateWebCryptoSecretKey(key_data, algorithm, extractable, usages,
295 key); 299 key);
296 } 300 }
297 301
298 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm, 302 Status GetKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
299 bool* has_length_bits, 303 bool* has_length_bits,
300 unsigned int* length_bits) const override { 304 unsigned int* length_bits) const override {
301 const blink::WebCryptoHmacImportParams* params = 305 const blink::WebCryptoHmacImportParams* params =
302 key_length_algorithm.hmacImportParams(); 306 key_length_algorithm.hmacImportParams();
303 307
304 *has_length_bits = true; 308 *has_length_bits = true;
305 if (params->hasLengthBits()) { 309 if (params->hasLengthBits()) {
306 *length_bits = params->optionalLengthBits(); 310 *length_bits = params->optionalLengthBits();
307 if (*length_bits == 0) 311 if (*length_bits == 0)
308 return Status::ErrorGetHmacKeyLengthZero(); 312 return Status::ErrorGetHmacKeyLengthZero();
309 return Status::Success(); 313 return Status::Success();
310 } 314 }
311 315
312 return GetDigestBlockSizeBits(params->hash(), length_bits); 316 return GetDigestBlockSizeBits(params->hash(), length_bits);
313 } 317 }
314 }; 318 };
315 319
316 } // namespace 320 } // namespace
317 321
318 std::unique_ptr<AlgorithmImplementation> CreateHmacImplementation() { 322 std::unique_ptr<AlgorithmImplementation> CreateHmacImplementation() {
319 return base::WrapUnique(new HmacImplementation); 323 return base::WrapUnique(new HmacImplementation);
320 } 324 }
321 325
322 } // namespace webcrypto 326 } // namespace webcrypto
OLDNEW
« no previous file with comments | « components/webcrypto/algorithms/hkdf.cc ('k') | components/webcrypto/algorithms/pbkdf2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698