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

Unified Diff: components/webcrypto/webcrypto_util.cc

Issue 1355873002: [refactor] More post-NSS WebCrypto cleanups (utility functions). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix bug Created 5 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 side-by-side diff with in-line comments
Download patch
« components/webcrypto/jwk.h ('K') | « components/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webcrypto/webcrypto_util.cc
diff --git a/components/webcrypto/webcrypto_util.cc b/components/webcrypto/webcrypto_util.cc
index 9e0f04451275e654c4b4066680b735eb7301f052..cf26478b2210c3e4a2692c58458ba9c5a22b7de3 100644
--- a/components/webcrypto/webcrypto_util.cc
+++ b/components/webcrypto/webcrypto_util.cc
@@ -35,21 +35,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 +42,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 +62,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 +145,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,
« components/webcrypto/jwk.h ('K') | « components/webcrypto/webcrypto_util.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698