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

Side by Side Diff: content/child/webcrypto/webcrypto_util.cc

Issue 203303006: [webcrypto] Add length parameter to HmacKeyAlgorithm. (chromium) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add bound check Created 6 years, 9 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 | Annotate | Revision Log
« no previous file with comments | « content/child/webcrypto/webcrypto_util.h ('k') | no next file » | 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 "content/child/webcrypto/webcrypto_util.h" 5 #include "content/child/webcrypto/webcrypto_util.h"
6 6
7 #include "base/base64.h" 7 #include "base/base64.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h" 10 #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 case blink::WebCryptoAlgorithmIdSha384: 370 case blink::WebCryptoAlgorithmIdSha384:
371 case blink::WebCryptoAlgorithmIdSha512: 371 case blink::WebCryptoAlgorithmIdSha512:
372 return 128; 372 return 128;
373 default: 373 default:
374 NOTREACHED(); 374 NOTREACHED();
375 return 0; 375 return 0;
376 } 376 }
377 } 377 }
378 378
379 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, 379 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm,
380 unsigned keylen_bytes, 380 unsigned int keylen_bytes,
381 blink::WebCryptoKeyAlgorithm* key_algorithm) { 381 blink::WebCryptoKeyAlgorithm* key_algorithm) {
382 switch (algorithm.id()) { 382 switch (algorithm.id()) {
383 case blink::WebCryptoAlgorithmIdHmac: { 383 case blink::WebCryptoAlgorithmIdHmac: {
384 blink::WebCryptoAlgorithm hash = GetInnerHashAlgorithm(algorithm); 384 blink::WebCryptoAlgorithm hash = GetInnerHashAlgorithm(algorithm);
385 if (hash.isNull()) 385 if (hash.isNull())
386 return false; 386 return false;
387 #if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
388 if (keylen_bytes > UINT_MAX / 8)
389 return false;
390 #endif
387 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( 391 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate(
388 algorithm.id(), new blink::WebCryptoHmacKeyAlgorithmParams(hash)); 392 algorithm.id(),
393 #if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH)
394 new blink::WebCryptoHmacKeyAlgorithmParams(hash, keylen_bytes * 8));
395 #else
396 new blink::WebCryptoHmacKeyAlgorithmParams(hash));
397 #endif
389 return true; 398 return true;
390 } 399 }
391 case blink::WebCryptoAlgorithmIdAesKw: 400 case blink::WebCryptoAlgorithmIdAesKw:
392 case blink::WebCryptoAlgorithmIdAesCbc: 401 case blink::WebCryptoAlgorithmIdAesCbc:
393 case blink::WebCryptoAlgorithmIdAesCtr: 402 case blink::WebCryptoAlgorithmIdAesCtr:
394 case blink::WebCryptoAlgorithmIdAesGcm: 403 case blink::WebCryptoAlgorithmIdAesGcm:
395 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( 404 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate(
396 algorithm.id(), 405 algorithm.id(),
397 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); 406 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8));
398 return true; 407 return true;
399 default: 408 default:
400 return false; 409 return false;
401 } 410 }
402 } 411 }
403 412
404 } // namespace webcrypto 413 } // namespace webcrypto
405 414
406 } // namespace content 415 } // namespace content
OLDNEW
« no previous file with comments | « content/child/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698