| 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 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 } | 333 } |
| 334 | 334 |
| 335 blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( | 335 blink::WebCryptoAlgorithm CreateHmacImportAlgorithm( |
| 336 blink::WebCryptoAlgorithmId hash_id) { | 336 blink::WebCryptoAlgorithmId hash_id) { |
| 337 DCHECK(IsHashAlgorithm(hash_id)); | 337 DCHECK(IsHashAlgorithm(hash_id)); |
| 338 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 338 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 339 blink::WebCryptoAlgorithmIdHmac, | 339 blink::WebCryptoAlgorithmIdHmac, |
| 340 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); | 340 new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id))); |
| 341 } | 341 } |
| 342 | 342 |
| 343 blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm( |
| 344 blink::WebCryptoAlgorithmId id, |
| 345 blink::WebCryptoAlgorithmId hash_id) { |
| 346 DCHECK(IsHashAlgorithm(hash_id)); |
| 347 DCHECK(id == blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5 || |
| 348 id == blink::WebCryptoAlgorithmIdRsaOaep); |
| 349 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( |
| 350 id, new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); |
| 351 } |
| 352 |
| 343 blink::WebCryptoAlgorithm CreateRsaSsaImportAlgorithm( | 353 blink::WebCryptoAlgorithm CreateRsaSsaImportAlgorithm( |
| 344 blink::WebCryptoAlgorithmId hash_id) { | 354 blink::WebCryptoAlgorithmId hash_id) { |
| 345 DCHECK(IsHashAlgorithm(hash_id)); | 355 return CreateRsaHashedImportAlgorithm( |
| 346 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 356 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, hash_id); |
| 347 blink::WebCryptoAlgorithmIdRsaSsaPkcs1v1_5, | |
| 348 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | |
| 349 } | 357 } |
| 350 | 358 |
| 351 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( | 359 blink::WebCryptoAlgorithm CreateRsaOaepImportAlgorithm( |
| 352 blink::WebCryptoAlgorithmId hash_id) { | 360 blink::WebCryptoAlgorithmId hash_id) { |
| 353 DCHECK(IsHashAlgorithm(hash_id)); | 361 return CreateRsaHashedImportAlgorithm(blink::WebCryptoAlgorithmIdRsaOaep, |
| 354 return blink::WebCryptoAlgorithm::adoptParamsAndCreate( | 362 hash_id); |
| 355 blink::WebCryptoAlgorithmIdRsaOaep, | |
| 356 new blink::WebCryptoRsaHashedImportParams(CreateAlgorithm(hash_id))); | |
| 357 } | 363 } |
| 358 | 364 |
| 359 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { | 365 unsigned int ShaBlockSizeBytes(blink::WebCryptoAlgorithmId hash_id) { |
| 360 switch (hash_id) { | 366 switch (hash_id) { |
| 361 case blink::WebCryptoAlgorithmIdSha1: | 367 case blink::WebCryptoAlgorithmIdSha1: |
| 362 case blink::WebCryptoAlgorithmIdSha256: | 368 case blink::WebCryptoAlgorithmIdSha256: |
| 363 return 64; | 369 return 64; |
| 364 case blink::WebCryptoAlgorithmIdSha384: | 370 case blink::WebCryptoAlgorithmIdSha384: |
| 365 case blink::WebCryptoAlgorithmIdSha512: | 371 case blink::WebCryptoAlgorithmIdSha512: |
| 366 return 128; | 372 return 128; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 391 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); | 397 new blink::WebCryptoAesKeyAlgorithmParams(keylen_bytes * 8)); |
| 392 return true; | 398 return true; |
| 393 default: | 399 default: |
| 394 return false; | 400 return false; |
| 395 } | 401 } |
| 396 } | 402 } |
| 397 | 403 |
| 398 } // namespace webcrypto | 404 } // namespace webcrypto |
| 399 | 405 |
| 400 } // namespace content | 406 } // namespace content |
| OLD | NEW |