| Index: components/webcrypto/webcrypto_util.cc
|
| diff --git a/components/webcrypto/webcrypto_util.cc b/components/webcrypto/webcrypto_util.cc
|
| index 9e0f04451275e654c4b4066680b735eb7301f052..26d428fca8bfedca4efd1347a72f5cf34e434cc2 100644
|
| --- a/components/webcrypto/webcrypto_util.cc
|
| +++ b/components/webcrypto/webcrypto_util.cc
|
| @@ -5,7 +5,6 @@
|
| #include "components/webcrypto/webcrypto_util.h"
|
|
|
| #include "base/logging.h"
|
| -#include "base/numerics/safe_math.h"
|
| #include "components/webcrypto/status.h"
|
| #include "third_party/WebKit/public/platform/WebCryptoAlgorithm.h"
|
| #include "third_party/WebKit/public/platform/WebCryptoAlgorithmParams.h"
|
| @@ -35,21 +34,6 @@ bool BigIntegerToUint(const uint8_t* data,
|
| return true;
|
| }
|
|
|
| -Status GetShaBlockSizeBits(const blink::WebCryptoAlgorithm& algorithm,
|
| - unsigned int* block_size_bits) {
|
| - switch (algorithm.id()) {
|
| - case blink::WebCryptoAlgorithmIdSha1:
|
| - case blink::WebCryptoAlgorithmIdSha256:
|
| - *block_size_bits = 512;
|
| - return Status::Success();
|
| - case blink::WebCryptoAlgorithmIdSha384:
|
| - case blink::WebCryptoAlgorithmIdSha512:
|
| - *block_size_bits = 1024;
|
| - return Status::Success();
|
| - default:
|
| - return Status::ErrorUnsupported();
|
| - }
|
| -}
|
|
|
| } // namespace
|
|
|
| @@ -57,24 +41,6 @@ blink::WebCryptoAlgorithm CreateAlgorithm(blink::WebCryptoAlgorithmId id) {
|
| return blink::WebCryptoAlgorithm::adoptParamsAndCreate(id, NULL);
|
| }
|
|
|
| -blink::WebCryptoAlgorithm CreateHmacImportAlgorithm(
|
| - blink::WebCryptoAlgorithmId hash_id,
|
| - unsigned int length_bits) {
|
| - DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id));
|
| - return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
| - blink::WebCryptoAlgorithmIdHmac,
|
| - new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id), true,
|
| - length_bits));
|
| -}
|
| -
|
| -blink::WebCryptoAlgorithm CreateHmacImportAlgorithmNoLength(
|
| - blink::WebCryptoAlgorithmId hash_id) {
|
| - DCHECK(blink::WebCryptoAlgorithm::isHash(hash_id));
|
| - return blink::WebCryptoAlgorithm::adoptParamsAndCreate(
|
| - blink::WebCryptoAlgorithmIdHmac,
|
| - new blink::WebCryptoHmacImportParams(CreateAlgorithm(hash_id), false, 0));
|
| -}
|
| -
|
| blink::WebCryptoAlgorithm CreateRsaHashedImportAlgorithm(
|
| blink::WebCryptoAlgorithmId id,
|
| blink::WebCryptoAlgorithmId hash_id) {
|
| @@ -95,92 +61,6 @@ bool ContainsKeyUsages(blink::WebCryptoKeyUsageMask a,
|
| return (a & b) == b;
|
| }
|
|
|
| -// The WebCrypto spec defines the default value for the tag length, as well as
|
| -// the allowed values for tag length.
|
| -Status GetAesGcmTagLengthInBits(const blink::WebCryptoAesGcmParams* params,
|
| - unsigned int* tag_length_bits) {
|
| - *tag_length_bits = 128;
|
| - if (params->hasTagLengthBits())
|
| - *tag_length_bits = params->optionalTagLengthBits();
|
| -
|
| - if (*tag_length_bits != 32 && *tag_length_bits != 64 &&
|
| - *tag_length_bits != 96 && *tag_length_bits != 104 &&
|
| - *tag_length_bits != 112 && *tag_length_bits != 120 &&
|
| - *tag_length_bits != 128)
|
| - return Status::ErrorInvalidAesGcmTagLength();
|
| -
|
| - return Status::Success();
|
| -}
|
| -
|
| -Status GetAesKeyGenLengthInBits(const blink::WebCryptoAesKeyGenParams* params,
|
| - unsigned int* keylen_bits) {
|
| - *keylen_bits = params->lengthBits();
|
| -
|
| - if (*keylen_bits == 128 || *keylen_bits == 256)
|
| - return Status::Success();
|
| -
|
| - // BoringSSL does not support 192-bit AES.
|
| - if (*keylen_bits == 192)
|
| - return Status::ErrorAes192BitUnsupported();
|
| -
|
| - return Status::ErrorGenerateAesKeyLength();
|
| -}
|
| -
|
| -Status GetHmacKeyGenLengthInBits(const blink::WebCryptoHmacKeyGenParams* params,
|
| - unsigned int* keylen_bits) {
|
| - if (!params->hasLengthBits())
|
| - return GetShaBlockSizeBits(params->hash(), keylen_bits);
|
| -
|
| - *keylen_bits = params->optionalLengthBits();
|
| -
|
| - // Zero-length HMAC keys are disallowed by the spec.
|
| - if (*keylen_bits == 0)
|
| - return Status::ErrorGenerateHmacKeyLengthZero();
|
| -
|
| - return Status::Success();
|
| -}
|
| -
|
| -Status GetHmacImportKeyLengthBits(
|
| - const blink::WebCryptoHmacImportParams* params,
|
| - unsigned int key_data_byte_length,
|
| - unsigned int* keylen_bits) {
|
| - if (key_data_byte_length == 0)
|
| - return Status::ErrorHmacImportEmptyKey();
|
| -
|
| - // Make sure that the key data's length can be represented in bits without
|
| - // overflow.
|
| - base::CheckedNumeric<unsigned int> checked_keylen_bits(key_data_byte_length);
|
| - checked_keylen_bits *= 8;
|
| -
|
| - if (!checked_keylen_bits.IsValid())
|
| - return Status::ErrorDataTooLarge();
|
| -
|
| - unsigned int data_keylen_bits = checked_keylen_bits.ValueOrDie();
|
| -
|
| - // Determine how many bits of the input to use.
|
| - *keylen_bits = data_keylen_bits;
|
| - if (params->hasLengthBits()) {
|
| - // The requested bit length must be:
|
| - // * No longer than the input data length
|
| - // * At most 7 bits shorter.
|
| - if (NumBitsToBytes(params->optionalLengthBits()) != key_data_byte_length)
|
| - return Status::ErrorHmacImportBadLength();
|
| - *keylen_bits = params->optionalLengthBits();
|
| - }
|
| -
|
| - return Status::Success();
|
| -}
|
| -
|
| -Status VerifyAesKeyLengthForImport(unsigned int keylen_bytes) {
|
| - if (keylen_bytes == 16 || keylen_bytes == 32)
|
| - return Status::Success();
|
| -
|
| - // BoringSSL does not support 192-bit AES.
|
| - if (keylen_bytes == 24)
|
| - return Status::ErrorAes192BitUnsupported();
|
| -
|
| - return Status::ErrorImportAesKeyLength();
|
| -}
|
|
|
| Status CheckKeyCreationUsages(blink::WebCryptoKeyUsageMask all_possible_usages,
|
| blink::WebCryptoKeyUsageMask actual_usages,
|
| @@ -264,42 +144,6 @@ void TruncateToBitLength(size_t length_bits, std::vector<uint8_t>* bytes) {
|
| (*bytes)[bytes->size() - 1] &= ~((0xFF) >> remainder_bits);
|
| }
|
|
|
| -Status GetAesKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
|
| - bool* has_length_bits,
|
| - unsigned int* length_bits) {
|
| - const blink::WebCryptoAesDerivedKeyParams* params =
|
| - key_length_algorithm.aesDerivedKeyParams();
|
| -
|
| - *has_length_bits = true;
|
| - *length_bits = params->lengthBits();
|
| -
|
| - if (*length_bits == 128 || *length_bits == 256)
|
| - return Status::Success();
|
| -
|
| - // BoringSSL does not support 192-bit AES.
|
| - if (*length_bits == 192)
|
| - return Status::ErrorAes192BitUnsupported();
|
| -
|
| - return Status::ErrorGetAesKeyLength();
|
| -}
|
| -
|
| -Status GetHmacKeyLength(const blink::WebCryptoAlgorithm& key_length_algorithm,
|
| - bool* has_length_bits,
|
| - unsigned int* length_bits) {
|
| - const blink::WebCryptoHmacImportParams* params =
|
| - key_length_algorithm.hmacImportParams();
|
| -
|
| - if (params->hasLengthBits()) {
|
| - *has_length_bits = true;
|
| - *length_bits = params->optionalLengthBits();
|
| - if (*length_bits == 0)
|
| - return Status::ErrorGetHmacKeyLengthZero();
|
| - return Status::Success();
|
| - }
|
| -
|
| - *has_length_bits = true;
|
| - return GetShaBlockSizeBits(params->hash(), length_bits);
|
| -}
|
|
|
| Status GetUsagesForGenerateAsymmetricKey(
|
| blink::WebCryptoKeyUsageMask combined_usages,
|
|
|