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

Unified Diff: components/webcrypto/algorithms/hmac.cc

Issue 1355923002: [refactor] Misc post-NSS WebCrypto cleanups. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@util_split
Patch Set: add an explicit size_t --> unsigned cast 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
Index: components/webcrypto/algorithms/hmac.cc
diff --git a/components/webcrypto/algorithms/hmac.cc b/components/webcrypto/algorithms/hmac.cc
index 2bc8e84e5998b09b3cef296973ed74c9270167be..021facdff564d3ca8f0b34daf3dc8454e6a3eb30 100644
--- a/components/webcrypto/algorithms/hmac.cc
+++ b/components/webcrypto/algorithms/hmac.cc
@@ -24,21 +24,13 @@ namespace webcrypto {
namespace {
-// TODO(eroman): Use EVP_MD_block_size() instead.
-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();
- }
+Status GetDigestBlockSizeBits(const blink::WebCryptoAlgorithm& algorithm,
+ unsigned int* block_size_bits) {
+ const EVP_MD* md = GetDigest(algorithm.id());
+ if (!md)
+ return Status::ErrorUnsupported();
+ *block_size_bits = static_cast<unsigned int>(8 * EVP_MD_block_size(md));
+ return Status::Success();
}
// Gets the requested key length in bits for an HMAC import operation.
@@ -138,7 +130,7 @@ class HmacImplementation : public AlgorithmImplementation {
if (keylen_bits == 0)
return Status::ErrorGenerateHmacKeyLengthZero();
} else {
- status = GetShaBlockSizeBits(params->hash(), &keylen_bits);
+ status = GetDigestBlockSizeBits(params->hash(), &keylen_bits);
if (status.IsError())
return status;
}
@@ -291,7 +283,7 @@ class HmacImplementation : public AlgorithmImplementation {
return Status::Success();
}
- return GetShaBlockSizeBits(params->hash(), length_bits);
+ return GetDigestBlockSizeBits(params->hash(), length_bits);
}
};
« no previous file with comments | « components/webcrypto/algorithms/ecdsa_unittest.cc ('k') | components/webcrypto/algorithms/rsa_pss_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698