summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/child/webcrypto/algorithm_dispatch.cc18
-rw-r--r--content/child/webcrypto/algorithm_dispatch.h5
-rw-r--r--content/child/webcrypto/algorithm_implementation.cc8
-rw-r--r--content/child/webcrypto/algorithm_implementation.h6
-rw-r--r--content/child/webcrypto/webcrypto_impl.cc45
-rw-r--r--content/child/webcrypto/webcrypto_impl.h5
6 files changed, 87 insertions, 0 deletions
diff --git a/content/child/webcrypto/algorithm_dispatch.cc b/content/child/webcrypto/algorithm_dispatch.cc
index 5c1de70..1c9b409 100644
--- a/content/child/webcrypto/algorithm_dispatch.cc
+++ b/content/child/webcrypto/algorithm_dispatch.cc
@@ -241,6 +241,24 @@ Status UnwrapKey(blink::WebCryptoKeyFormat format,
key);
}
+Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ std::vector<uint8_t>* derived_bytes) {
+ if (!KeyUsageAllows(base_key, blink::WebCryptoKeyUsageDeriveBits))
+ return Status::ErrorUnexpected();
+
+ if (algorithm.id() != base_key.algorithm().id())
+ return Status::ErrorUnexpected();
+
+ const AlgorithmImplementation* impl = NULL;
+ Status status = GetAlgorithmImplementation(algorithm.id(), &impl);
+ if (status.IsError())
+ return status;
+
+ return impl->DeriveBits(algorithm, base_key, length_bits, derived_bytes);
+}
+
scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
blink::WebCryptoAlgorithmId algorithm) {
PlatformInit();
diff --git a/content/child/webcrypto/algorithm_dispatch.h b/content/child/webcrypto/algorithm_dispatch.h
index 40812ee..977b792 100644
--- a/content/child/webcrypto/algorithm_dispatch.h
+++ b/content/child/webcrypto/algorithm_dispatch.h
@@ -87,6 +87,11 @@ UnwrapKey(blink::WebCryptoKeyFormat format,
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoKey* key);
+CONTENT_EXPORT Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ std::vector<uint8_t>* derived_bytes);
+
CONTENT_EXPORT scoped_ptr<blink::WebCryptoDigestor> CreateDigestor(
blink::WebCryptoAlgorithmId algorithm);
diff --git a/content/child/webcrypto/algorithm_implementation.cc b/content/child/webcrypto/algorithm_implementation.cc
index 8a4c67a..6b9f7f9 100644
--- a/content/child/webcrypto/algorithm_implementation.cc
+++ b/content/child/webcrypto/algorithm_implementation.cc
@@ -60,6 +60,14 @@ Status AlgorithmImplementation::GenerateKey(
return Status::ErrorUnsupported();
}
+Status AlgorithmImplementation::DeriveBits(
+ const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ std::vector<uint8_t>* derived_bytes) const {
+ return Status::ErrorUnsupported();
+}
+
Status AlgorithmImplementation::VerifyKeyUsagesBeforeImportKey(
blink::WebCryptoKeyFormat format,
blink::WebCryptoKeyUsageMask usages) const {
diff --git a/content/child/webcrypto/algorithm_implementation.h b/content/child/webcrypto/algorithm_implementation.h
index ba40d66..2726137 100644
--- a/content/child/webcrypto/algorithm_implementation.h
+++ b/content/child/webcrypto/algorithm_implementation.h
@@ -81,6 +81,12 @@ class AlgorithmImplementation {
blink::WebCryptoKeyUsageMask usages,
GenerateKeyResult* result) const;
+ // This method corresponds to Web Crypto's "derive bits" operation.
+ virtual Status DeriveBits(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ std::vector<uint8_t>* derived_bytes) const;
+
// -----------------------------------------------
// Key import
// -----------------------------------------------
diff --git a/content/child/webcrypto/webcrypto_impl.cc b/content/child/webcrypto/webcrypto_impl.cc
index 5b033a5..8efd9de 100644
--- a/content/child/webcrypto/webcrypto_impl.cc
+++ b/content/child/webcrypto/webcrypto_impl.cc
@@ -333,6 +333,23 @@ struct UnwrapKeyState : public BaseState {
blink::WebCryptoKey unwrapped_key;
};
+struct DeriveBitsState : public BaseState {
+ DeriveBitsState(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ const blink::WebCryptoResult& result)
+ : BaseState(result),
+ algorithm(algorithm),
+ base_key(base_key),
+ length_bits(length_bits) {}
+
+ const blink::WebCryptoAlgorithm algorithm;
+ const blink::WebCryptoKey base_key;
+ const unsigned int length_bits;
+
+ std::vector<uint8_t> derived_bytes;
+};
+
// --------------------------------------------------------------------
// Wrapper functions
// --------------------------------------------------------------------
@@ -519,6 +536,22 @@ void DoUnwrapKey(scoped_ptr<UnwrapKeyState> passed_state) {
FROM_HERE, base::Bind(DoUnwrapKeyReply, Passed(&passed_state)));
}
+void DoDeriveBitsReply(scoped_ptr<DeriveBitsState> state) {
+ CompleteWithBufferOrError(state->status, state->derived_bytes,
+ &state->result);
+}
+
+void DoDeriveBits(scoped_ptr<DeriveBitsState> passed_state) {
+ DeriveBitsState* state = passed_state.get();
+ if (state->cancelled())
+ return;
+ state->status =
+ webcrypto::DeriveBits(state->algorithm, state->base_key,
+ state->length_bits, &state->derived_bytes);
+ state->origin_thread->PostTask(
+ FROM_HERE, base::Bind(DoDeriveBitsReply, Passed(&passed_state)));
+}
+
} // namespace
WebCryptoImpl::WebCryptoImpl() {
@@ -670,6 +703,18 @@ void WebCryptoImpl::unwrapKey(
}
}
+void WebCryptoImpl::deriveBits(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ blink::WebCryptoResult result) {
+ scoped_ptr<DeriveBitsState> state(
+ new DeriveBitsState(algorithm, base_key, length_bits, result));
+ if (!CryptoThreadPool::PostTask(FROM_HERE,
+ base::Bind(DoDeriveBits, Passed(&state)))) {
+ CompleteWithThreadPoolError(&result);
+ }
+}
+
blink::WebCryptoDigestor* WebCryptoImpl::createDigestor(
blink::WebCryptoAlgorithmId algorithm_id) {
return webcrypto::CreateDigestor(algorithm_id).release();
diff --git a/content/child/webcrypto/webcrypto_impl.h b/content/child/webcrypto/webcrypto_impl.h
index e7714a5..d9afb88 100644
--- a/content/child/webcrypto/webcrypto_impl.h
+++ b/content/child/webcrypto/webcrypto_impl.h
@@ -84,6 +84,11 @@ class WebCryptoImpl : public blink::WebCrypto {
blink::WebCryptoKeyUsageMask usages,
blink::WebCryptoResult result);
+ virtual void deriveBits(const blink::WebCryptoAlgorithm& algorithm,
+ const blink::WebCryptoKey& base_key,
+ unsigned int length_bits,
+ blink::WebCryptoResult result);
+
// This method returns a digestor object that can be used to synchronously
// compute a digest one chunk at a time. Thus, the consume does not need to
// hold onto a large buffer with all the data to digest. Chunks can be given