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/platform_crypto.h" | 5 #include "content/child/webcrypto/platform_crypto.h" |
6 | 6 |
7 #include <cryptohi.h> | 7 #include <cryptohi.h> |
8 #include <pk11pub.h> | 8 #include <pk11pub.h> |
9 #include <sechash.h> | 9 #include <sechash.h> |
10 #include <secoid.h> | 10 #include <secoid.h> |
(...skipping 396 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (!key || key->keyType != rsaKey) | 407 if (!key || key->keyType != rsaKey) |
408 return false; | 408 return false; |
409 | 409 |
410 unsigned int modulus_length_bits = SECKEY_PublicKeyStrength(key) * 8; | 410 unsigned int modulus_length_bits = SECKEY_PublicKeyStrength(key) * 8; |
411 CryptoData public_exponent(key->u.rsa.publicExponent.data, | 411 CryptoData public_exponent(key->u.rsa.publicExponent.data, |
412 key->u.rsa.publicExponent.len); | 412 key->u.rsa.publicExponent.len); |
413 | 413 |
414 switch (algorithm.paramsType()) { | 414 switch (algorithm.paramsType()) { |
415 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: | 415 case blink::WebCryptoAlgorithmParamsTypeRsaHashedImportParams: |
416 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: | 416 case blink::WebCryptoAlgorithmParamsTypeRsaHashedKeyGenParams: |
417 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 417 *key_algorithm = blink::WebCryptoKeyAlgorithm::createRsaHashed( |
418 algorithm.id(), | 418 algorithm.id(), |
419 new blink::WebCryptoRsaHashedKeyAlgorithmParams( | 419 modulus_length_bits, |
420 modulus_length_bits, | 420 public_exponent.bytes(), |
421 public_exponent.bytes(), | 421 public_exponent.byte_length(), |
422 public_exponent.byte_length(), | 422 GetInnerHashAlgorithm(algorithm).id()); |
423 GetInnerHashAlgorithm(algorithm))); | |
424 return true; | 423 return true; |
425 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: | 424 case blink::WebCryptoAlgorithmParamsTypeRsaKeyGenParams: |
426 case blink::WebCryptoAlgorithmParamsTypeNone: | 425 case blink::WebCryptoAlgorithmParamsTypeNone: |
427 *key_algorithm = blink::WebCryptoKeyAlgorithm::adoptParamsAndCreate( | 426 *key_algorithm = blink::WebCryptoKeyAlgorithm::createRsa( |
428 algorithm.id(), | 427 algorithm.id(), |
429 new blink::WebCryptoRsaKeyAlgorithmParams( | 428 modulus_length_bits, |
430 modulus_length_bits, | 429 public_exponent.bytes(), |
431 public_exponent.bytes(), | 430 public_exponent.byte_length()); |
432 public_exponent.byte_length())); | |
433 return true; | 431 return true; |
434 default: | 432 default: |
435 return false; | 433 return false; |
436 } | 434 } |
437 } | 435 } |
438 | 436 |
439 bool CreatePrivateKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, | 437 bool CreatePrivateKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm, |
440 SECKEYPrivateKey* key, | 438 SECKEYPrivateKey* key, |
441 blink::WebCryptoKeyAlgorithm* key_algorithm) { | 439 blink::WebCryptoKeyAlgorithm* key_algorithm) { |
442 crypto::ScopedSECKEYPublicKey public_key(SECKEY_ConvertToPublicKey(key)); | 440 crypto::ScopedSECKEYPublicKey public_key(SECKEY_ConvertToPublicKey(key)); |
(...skipping 1042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1485 key_algorithm, | 1483 key_algorithm, |
1486 usage_mask); | 1484 usage_mask); |
1487 return Status::Success(); | 1485 return Status::Success(); |
1488 } | 1486 } |
1489 | 1487 |
1490 } // namespace platform | 1488 } // namespace platform |
1491 | 1489 |
1492 } // namespace webcrypto | 1490 } // namespace webcrypto |
1493 | 1491 |
1494 } // namespace content | 1492 } // namespace content |
OLD | NEW |