| OLD | NEW |
| 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 366 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 } | 377 } |
| 378 | 378 |
| 379 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 379 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
| 380 unsigned int 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) | 387 if (keylen_bytes > UINT_MAX / 8) |
| 389 return false; | 388 return false; |
| 390 #endif | |
| 391 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 389 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( |
| 392 algorithm.id(), | 390 algorithm.id(), |
| 393 #if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH) | |
| 394 new blink::WebCryptoHmacKeyAlgorithmParams(hash, keylen_bytes * 8)); | 391 new blink::WebCryptoHmacKeyAlgorithmParams(hash, keylen_bytes * 8)); |
| 395 #else | |
| 396 new blink::WebCryptoHmacKeyAlgorithmParams(hash)); | |
| 397 #endif | |
| 398 return true; | 392 return true; |
| 399 } | 393 } |
| 400 case blink::WebCryptoAlgorithmIdAesKw: | 394 case blink::WebCryptoAlgorithmIdAesKw: |
| 401 case blink::WebCryptoAlgorithmIdAesCbc: | 395 case blink::WebCryptoAlgorithmIdAesCbc: |
| 402 case blink::WebCryptoAlgorithmIdAesCtr: | 396 case blink::WebCryptoAlgorithmIdAesCtr: |
| 403 case blink::WebCryptoAlgorithmIdAesGcm: | 397 case blink::WebCryptoAlgorithmIdAesGcm: |
| 404 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 398 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( |
| 405 algorithm.id(), | 399 algorithm.id(), |
| 406 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 400 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
| 407 return true; | 401 return true; |
| 408 default: | 402 default: |
| 409 return false; | 403 return false; |
| 410 } | 404 } |
| 411 } | 405 } |
| 412 | 406 |
| 413 } // namespace webcrypto | 407 } // namespace webcrypto |
| 414 | 408 |
| 415 } // namespace content | 409 } // namespace content |
| OLD | NEW |