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

Unified Diff: LayoutTests/crypto/subtle/derive-hkdf-keys.html

Issue 822083003: Webcrypto: add layout tests for HKDF algorithm (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: remove duplicate test case Created 5 years, 11 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: LayoutTests/crypto/subtle/derive-hkdf-keys.html
diff --git a/LayoutTests/crypto/subtle/derive-hkdf-keys.html b/LayoutTests/crypto/subtle/derive-hkdf-keys.html
new file mode 100644
index 0000000000000000000000000000000000000000..8c846275900d18eea779cb8635010f8c3e456b0e
--- /dev/null
+++ b/LayoutTests/crypto/subtle/derive-hkdf-keys.html
@@ -0,0 +1,83 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../resources/js-test.js"></script>
+<script src="resources/common.js"></script>
+</head>
+<body>
+<p id="description"></p>
+<div id="console"></div>
+
+<script>
+description("Test deriving HKDF keys with deriveKey()");
+
+jsTestIsAsync = true;
+
+var extractable = true;
+var derivingKeyAlgorithm = {
+ name: "HKDF",
+ hash: "SHA-256",
+ salt: new Uint8Array(),
+ info: new Uint8Array()
+};
+
+var privateKeyJSON = {
+ "kty": "EC",
+ "crv": "P-256",
+ "d": "1mGcHOo_eTxXMTgSjWLLa5DCZIf0o8NNySooVNefCIw",
+ "x": "QcD58SaUjtYiUaUnTaOMWC7YKyfQ5yD0-8F9RStayBU",
+ "y": "CjHmp9BL54FleRbhJVQb1MgVu5YsFn7tJt0VWof_jj0"
+};
+
+var publicKeyJSON = {
+ "kty": "EC",
+ "crv": "P-256",
+ "x": "AGzVMZDcNVrG7e8m9bLFTy7Si7o1IcU-SNyI8_Up62E",
+ "y": "bSVna0fR_BTIgH5--cEXXgOB3J2IlxKTmb8YeOZ7UKE"
+};
+
+var secret = hexStringToUint8Array("82b17497eefdeee07fb108496b1e88b1975e42a98046b5521d18edc96a639fea");
+
+var hkdfAlgorithm = {
+ name: "HKDF",
+ hash: "SHA-256",
+ salt: new Uint8Array(),
+ info: new Uint8Array()
+}
+
+Promise.resolve(null).then(function(result) {
+ return crypto.subtle.importKey("jwk", privateKeyJSON, {name: "ECDH", namedCurve: "P-256"}, true, ["deriveKey"]);
+}).then(function(result) {
+ privateKey = result;
+
+ return crypto.subtle.importKey("jwk", publicKeyJSON, {name: "ECDH", namedCurve: "P-256"}, true, []);
+}).then(function(result) {
+ publicKey = result;
+
+ debug("Derive an HKDF key from ECDH keys");
+ return crypto.subtle.deriveKey({name: "ECDH", namedCurve: "P-256", public: publicKey}, privateKey, "HKDF", true, ['deriveKey', 'deriveBits']);
+}).then(function(result) {
+ hkdfKey = result;
+
+ shouldEvaluateAs("hkdfKey.algorithm.name", "HKDF");
+ shouldEvaluateAs("hkdfKey.extractable", true);
+ shouldEvaluateAs("hkdfKey.usages.join(',')", "deriveKey,deriveBits");
+
+ debug("\nDerive 128 bits from the HKDF key");
+ return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128);
+}).then(function(result) {
+ derivedBits = result;
+
+ return crypto.subtle.importKey("raw", secret, hkdfAlgorithm, true, ['deriveBits']);
+}).then(function(hkdfKey) {
+ return crypto.subtle.deriveBits(hkdfAlgorithm, hkdfKey, 128);
+}).then(function(result) {
+ expectedDerivedBits = result;
+
+ shouldEvaluateAs("bytesToHexString(derivedBits)", bytesToHexString(expectedDerivedBits));
+}).then(finishJSTest, failAndFinishJSTest);
+
+</script>
+
+</body>
+</html>
« no previous file with comments | « LayoutTests/crypto/subtle/clone-hmacKey.html ('k') | LayoutTests/crypto/subtle/derive-hkdf-keys-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698