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 367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
378 | 378 |
379 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 379 bool CreateSecretKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
380 unsigned keylen_bytes, | 380 unsigned 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 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 387 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( |
388 algorithm.id(), new blink::WebCryptoHmacKeyAlgorithmParams(hash)); | 388 algorithm.id(), |
389 #if defined(WEBCRYPTO_HMAC_KEY_HAS_LENGTH) | |
390 new blink::WebCryptoHmacKeyAlgorithmParams(hash, keylen_bytes * 8)); | |
eroman
2014/03/18 23:50:01
I didn't check for overflow, probably should. wdyt
eroman
2014/03/19 00:04:19
OK done.
| |
391 #else | |
392 new blink::WebCryptoHmacKeyAlgorithmParams(hash)); | |
393 #endif | |
389 return true; | 394 return true; |
390 } | 395 } |
391 case blink::WebCryptoAlgorithmIdAesKw: | 396 case blink::WebCryptoAlgorithmIdAesKw: |
392 case blink::WebCryptoAlgorithmIdAesCbc: | 397 case blink::WebCryptoAlgorithmIdAesCbc: |
393 case blink::WebCryptoAlgorithmIdAesCtr: | 398 case blink::WebCryptoAlgorithmIdAesCtr: |
394 case blink::WebCryptoAlgorithmIdAesGcm: | 399 case blink::WebCryptoAlgorithmIdAesGcm: |
395 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 400 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( |
396 algorithm.id(), | 401 algorithm.id(), |
397 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 402 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
398 return true; | 403 return true; |
399 default: | 404 default: |
400 return false; | 405 return false; |
401 } | 406 } |
402 } | 407 } |
403 | 408 |
404 } // namespace webcrypto | 409 } // namespace webcrypto |
405 | 410 |
406 } // namespace content | 411 } // namespace content |
OLD | NEW |