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

Side by Side Diff: content/child/webcrypto/nss/rsa_key_nss.cc

Issue 512023002: Refactor the interface for generating keys. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
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/nss/rsa_key_nss.h" 5 #include "content/child/webcrypto/nss/rsa_key_nss.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "content/child/webcrypto/crypto_data.h" 8 #include "content/child/webcrypto/crypto_data.h"
9 #include "content/child/webcrypto/jwk.h" 9 #include "content/child/webcrypto/jwk.h"
10 #include "content/child/webcrypto/nss/key_nss.h" 10 #include "content/child/webcrypto/nss/key_nss.h"
(...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 *key = blink::WebCryptoKey::create(key_handle.release(), 525 *key = blink::WebCryptoKey::create(key_handle.release(),
526 blink::WebCryptoKeyTypePublic, 526 blink::WebCryptoKeyTypePublic,
527 extractable, 527 extractable,
528 key_algorithm, 528 key_algorithm,
529 usage_mask); 529 usage_mask);
530 return Status::Success(); 530 return Status::Success();
531 } 531 }
532 532
533 } // namespace 533 } // namespace
534 534
535 Status RsaHashedAlgorithm::VerifyKeyUsagesBeforeGenerateKeyPair( 535 Status RsaHashedAlgorithm::GenerateKey(
536 const blink::WebCryptoAlgorithm& algorithm,
537 bool extractable,
536 blink::WebCryptoKeyUsageMask combined_usage_mask, 538 blink::WebCryptoKeyUsageMask combined_usage_mask,
537 blink::WebCryptoKeyUsageMask* public_usage_mask, 539 blink::WebCryptoKey* public_key,
538 blink::WebCryptoKeyUsageMask* private_usage_mask) const { 540 blink::WebCryptoKey* private_key) const {
539 Status status = CheckKeyCreationUsages( 541 Status status = CheckKeyCreationUsages(
540 all_public_key_usages_ | all_private_key_usages_, combined_usage_mask); 542 all_public_key_usages_ | all_private_key_usages_, combined_usage_mask);
541 if (status.IsError()) 543 if (status.IsError())
542 return status; 544 return status;
543 545
544 *public_usage_mask = combined_usage_mask & all_public_key_usages_; 546 const blink::WebCryptoKeyUsageMask public_usage_mask =
545 *private_usage_mask = combined_usage_mask & all_private_key_usages_; 547 combined_usage_mask & all_public_key_usages_;
548 const blink::WebCryptoKeyUsageMask private_usage_mask =
549 combined_usage_mask & all_private_key_usages_;
546 550
547 return Status::Success();
548 }
549
550 Status RsaHashedAlgorithm::GenerateKeyPair(
551 const blink::WebCryptoAlgorithm& algorithm,
552 bool extractable,
553 blink::WebCryptoKeyUsageMask public_usage_mask,
554 blink::WebCryptoKeyUsageMask private_usage_mask,
555 blink::WebCryptoKey* public_key,
556 blink::WebCryptoKey* private_key) const {
557 unsigned int public_exponent = 0; 551 unsigned int public_exponent = 0;
558 unsigned int modulus_length_bits = 0; 552 unsigned int modulus_length_bits = 0;
559 Status status = GetRsaKeyGenParameters(algorithm.rsaHashedKeyGenParams(), 553 status = GetRsaKeyGenParameters(algorithm.rsaHashedKeyGenParams(),
560 &public_exponent, 554 &public_exponent,
561 &modulus_length_bits); 555 &modulus_length_bits);
562 if (status.IsError()) 556 if (status.IsError())
563 return status; 557 return status;
564 558
565 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot()); 559 crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot());
566 if (!slot) 560 if (!slot)
567 return Status::OperationError(); 561 return Status::OperationError();
568 562
569 PK11RSAGenParams rsa_gen_params; 563 PK11RSAGenParams rsa_gen_params;
570 rsa_gen_params.keySizeInBits = modulus_length_bits; 564 rsa_gen_params.keySizeInBits = modulus_length_bits;
571 rsa_gen_params.pe = public_exponent; 565 rsa_gen_params.pe = public_exponent;
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 return Status::Success(); 845 return Status::Success();
852 } 846 }
853 default: 847 default:
854 return Status::ErrorUnexpected(); 848 return Status::ErrorUnexpected();
855 } 849 }
856 } 850 }
857 851
858 } // namespace webcrypto 852 } // namespace webcrypto
859 853
860 } // namespace content 854 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698