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

Unified Diff: content/child/webcrypto/nss/rsa_key_nss.cc

Issue 401233004: Refactor RSA key generation for WebCrypto's NSS implementation. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
Index: content/child/webcrypto/nss/rsa_key_nss.cc
diff --git a/content/child/webcrypto/nss/rsa_key_nss.cc b/content/child/webcrypto/nss/rsa_key_nss.cc
index 4ad79870710d24f83bdaf60dda99f2328e5f2bfb..37c15e7f955fa54ed5adee9ff4428cb7f0c071cb 100644
--- a/content/child/webcrypto/nss/rsa_key_nss.cc
+++ b/content/child/webcrypto/nss/rsa_key_nss.cc
@@ -21,27 +21,6 @@ namespace webcrypto {
namespace {
-// Converts a (big-endian) WebCrypto BigInteger, with or without leading zeros,
-// to unsigned long.
-bool BigIntegerToLong(const uint8_t* data,
- unsigned int data_size,
- unsigned long* result) {
- // TODO(eroman): Fix handling of empty biginteger. http://crubg.com/373552
- if (data_size == 0)
- return false;
-
- *result = 0;
- for (size_t i = 0; i < data_size; ++i) {
- size_t reverse_i = data_size - i - 1;
-
- if (reverse_i >= sizeof(unsigned long) && data[i])
- return false; // Too large for a long.
-
- *result |= data[i] << 8 * reverse_i;
- }
- return true;
-}
-
bool CreatePublicKeyAlgorithm(const blink::WebCryptoAlgorithm& algorithm,
SECKEYPublicKey* key,
blink::WebCryptoKeyAlgorithm* key_algorithm) {
@@ -578,29 +557,20 @@ Status RsaHashedAlgorithm::GenerateKeyPair(
blink::WebCryptoKeyUsageMask private_usage_mask,
blink::WebCryptoKey* public_key,
blink::WebCryptoKey* private_key) const {
- const blink::WebCryptoRsaHashedKeyGenParams* params =
- algorithm.rsaHashedKeyGenParams();
-
- if (!params->modulusLengthBits())
- return Status::ErrorGenerateRsaZeroModulus();
-
- unsigned long public_exponent = 0;
- if (!BigIntegerToLong(params->publicExponent().data(),
- params->publicExponent().size(),
- &public_exponent) ||
- (public_exponent != 3 && public_exponent != 65537)) {
- return Status::ErrorGenerateKeyPublicExponent();
- }
+ unsigned int public_exponent = 0;
+ unsigned int modulus_length_bits = 0;
+ Status status = GetRsaKeyGenGetParameters(algorithm.rsaHashedKeyGenParams(),
+ &public_exponent,
+ &modulus_length_bits);
+ if (status.IsError())
+ return status;
crypto::ScopedPK11Slot slot(PK11_GetInternalKeySlot());
if (!slot)
return Status::OperationError();
PK11RSAGenParams rsa_gen_params;
- // keySizeInBits is a signed type, don't pass in a negative value.
- if (params->modulusLengthBits() > INT_MAX)
- return Status::OperationError();
- rsa_gen_params.keySizeInBits = params->modulusLengthBits();
+ rsa_gen_params.keySizeInBits = modulus_length_bits;
rsa_gen_params.pe = public_exponent;
const CK_FLAGS operation_flags_mask =
« no previous file with comments | « no previous file | content/child/webcrypto/shared_crypto_unittest.cc » ('j') | content/child/webcrypto/shared_crypto_unittest.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698