webcrypto: add AES and HMAC key generation

Use a SymKeyHandle to represent these keys internally. Add generateKey() and
GenerateKeyInternal() to do key generation. Add unit tests for AES key
generation, odd key lengths (non-multiple of 8 bit counts), HMAC key generation,
and HMAC key generation with no length supplied.

BUG=chromium:245025
TEST=unit,trybot

Review URL: https://codereview.chromium.org/23707057

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@227974 0039d316-1c4b-4281-b951-d872f2087c98
diff --git a/content/renderer/webcrypto/webcrypto_impl.cc b/content/renderer/webcrypto/webcrypto_impl.cc
index 6eeb3daf..f794c59 100644
--- a/content/renderer/webcrypto/webcrypto_impl.cc
+++ b/content/renderer/webcrypto/webcrypto_impl.cc
@@ -56,6 +56,23 @@
   }
 }
 
+void WebCryptoImpl::generateKey(
+    const WebKit::WebCryptoAlgorithm& algorithm,
+    bool exportable,
+    WebKit::WebCryptoKeyUsageMask usage,
+    WebKit::WebCryptoResult result) {
+  scoped_ptr<WebKit::WebCryptoKeyHandle> handle;
+  WebKit::WebCryptoKeyType type;
+  if (!GenerateKeyInternal(algorithm, &handle, &type)) {
+    result.completeWithError();
+  } else {
+    WebKit::WebCryptoKey key(
+        WebKit::WebCryptoKey::create(handle.release(), type, exportable,
+                                     algorithm, usage));
+    result.completeWithKey(key);
+  }
+}
+
 void WebCryptoImpl::importKey(
     WebKit::WebCryptoKeyFormat format,
     const unsigned char* key_data,