| 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 =
|
|
|