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

Unified Diff: content/child/webcrypto/algorithm_dispatch.cc

Issue 749183004: WebCrypto: Implement crypto.subtle.deriveKey (chromium-side). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@ecdh
Patch Set: rebase Created 6 years 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 | « content/child/webcrypto/algorithm_dispatch.h ('k') | content/child/webcrypto/algorithm_implementation.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/child/webcrypto/algorithm_dispatch.cc
diff --git a/content/child/webcrypto/algorithm_dispatch.cc b/content/child/webcrypto/algorithm_dispatch.cc
index 253dc311a4d4df5412d4bd7d2b29c5d0dbce92bc..fee957ba8cf3492a968134323aa6f996d38e63ae 100644
--- a/content/child/webcrypto/algorithm_dispatch.cc
+++ b/content/child/webcrypto/algorithm_dispatch.cc
@@ -275,7 +275,61 @@ Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm,
if (status.IsError())
return status;
- return impl->DeriveBits(algorithm, base_key, length_bits, derived_bytes);
+ return impl->DeriveBits(algorithm, base_key, true, length_bits,
+ derived_bytes);
+}
+
+Status DeriveKey(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ const blink::WebCryptoAlgorithm& import_algorithm,
+ const blink::WebCryptoAlgorithm& key_length_algorithm,
+ bool extractable,
+ blink::WebCryptoKeyUsageMask usages,
+ blink::WebCryptoKey* derived_key) {
+ if (!KeyUsageAllows(base_key, blink::WebCryptoKeyUsageDeriveKey))
+ return Status::ErrorUnexpected();
+
+ if (algorithm.id() != base_key.algorithm().id())
+ return Status::ErrorUnexpected();
+
+ if (import_algorithm.id() != key_length_algorithm.id())
+ return Status::ErrorUnexpected();
+
+ const AlgorithmImplementation* import_impl = NULL;
+ Status status =
+ GetAlgorithmImplementation(import_algorithm.id(), &import_impl);
+ if (status.IsError())
+ return status;
+
+ // Fail fast if the requested key usages are incorect.
+ status = import_impl->VerifyKeyUsagesBeforeImportKey(
+ blink::WebCryptoKeyFormatRaw, usages);
+ if (status.IsError())
+ return status;
+
+ // Determine how many bits long the derived key should be.
+ unsigned int length_bits = 0;
+ bool has_length_bits = false;
+ status = import_impl->GetKeyLength(key_length_algorithm, &has_length_bits,
+ &length_bits);
+ if (status.IsError())
+ return status;
+
+ // Derive the key bytes.
+ const AlgorithmImplementation* derive_impl = NULL;
+ status = GetAlgorithmImplementation(algorithm.id(), &derive_impl);
+ if (status.IsError())
+ return status;
+
+ std::vector<uint8_t> derived_bytes;
+ status = derive_impl->DeriveBits(algorithm, base_key, has_length_bits,
+ length_bits, &derived_bytes);
+ if (status.IsError())
+ return status;
+
+ // Create the key using the derived bytes.
+ return ImportKey(blink::WebCryptoKeyFormatRaw, CryptoData(derived_bytes),
+ import_algorithm, extractable, usages, derived_key);
}
scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
« no previous file with comments | « content/child/webcrypto/algorithm_dispatch.h ('k') | content/child/webcrypto/algorithm_implementation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698