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/hkdf.cc

Issue 2837383002: Raise an error when calling WebCrypto's deriveBits() for HKDF with (Closed)
Patch Set: checkpoint Created 3 years, 8 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
« no previous file with comments | « no previous file | components/webcrypto/status.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: components/webcrypto/algorithms/hkdf.cc
diff --git a/components/webcrypto/algorithms/hkdf.cc b/components/webcrypto/algorithms/hkdf.cc
index f3381100e1628e0826a009432d19dc3f0c2e3a83..be01683478d926c33accad73618aeaeac07cca71 100644
--- a/components/webcrypto/algorithms/hkdf.cc
+++ b/components/webcrypto/algorithms/hkdf.cc
@@ -71,6 +71,9 @@ class HkdfImplementation : public AlgorithmImplementation {
if (!has_optional_length_bits)
return Status::ErrorHkdfDeriveBitsLengthNotSpecified();
+ if (optional_length_bits % 8)
+ return Status::ErrorHkdfLengthNotWholeByte();
+
const blink::WebCryptoHkdfParams* params = algorithm.HkdfParams();
const EVP_MD* digest_algorithm = GetDigest(params->GetHash());
@@ -78,7 +81,7 @@ class HkdfImplementation : public AlgorithmImplementation {
return Status::ErrorUnsupported();
// Size output to fit length
- unsigned int derived_bytes_len = NumBitsToBytes(optional_length_bits);
+ unsigned int derived_bytes_len = optional_length_bits / 8;
derived_bytes->resize(derived_bytes_len);
// Algorithm dispatch checks that the algorithm in |base_key| matches
@@ -96,7 +99,6 @@ class HkdfImplementation : public AlgorithmImplementation {
return Status::OperationError();
}
- TruncateToBitLength(optional_length_bits, derived_bytes);
return Status::Success();
}
« no previous file with comments | « no previous file | components/webcrypto/status.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698