5 <title>WebCrypto Test Suite
</title>
6 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8" />
7 <link rel=
"stylesheet" href=
"./test_WebCrypto.css"/>
8 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
10 <!-- Utilities for manipulating ABVs -->
11 <script src=
"util.js"></script>
13 <!-- A simple wrapper around IndexedDB -->
14 <script src=
"simpledb.js"></script>
16 <!-- Test vectors drawn from the literature -->
17 <script src=
"./test-vectors.js"></script>
19 <!-- General testing framework -->
20 <script src=
"./test-array.js"></script>
22 <script>/* <![CDATA[*/
25 // -----------------------------------------------------------------------------
27 "Structured Cloning: AES-CTR",
30 var data
= crypto
.getRandomValues(new Uint8Array(128));
31 var iv
= crypto
.getRandomValues(new Uint8Array(16));
32 var alg
= {name
: "AES-CTR", length
: 128, iv
};
34 var counter
= new Uint8Array(16);
35 var algEncrypt
= {name
: "AES-CTR", length
: 128, counter
};
37 crypto
.subtle
.generateKey(alg
, true, ["encrypt"])
38 .then(util
.cloneExportCompareKeys
)
39 .then(x
=> crypto
.subtle
.encrypt(algEncrypt
, x
, data
))
40 .then(complete(that
), error(that
));
44 // -----------------------------------------------------------------------------
46 "Structured Cloning: AES-CBC",
49 var data
= crypto
.getRandomValues(new Uint8Array(128));
50 var iv
= crypto
.getRandomValues(new Uint8Array(16));
51 var alg
= {name
: "AES-CBC", length
: 128, iv
};
53 crypto
.subtle
.generateKey(alg
, true, ["encrypt"])
54 .then(util
.cloneExportCompareKeys
)
55 .then(x
=> crypto
.subtle
.encrypt(alg
, x
, data
))
56 .then(complete(that
), error(that
));
60 // -----------------------------------------------------------------------------
62 "Structured Cloning: AES-GCM",
65 var data
= crypto
.getRandomValues(new Uint8Array(128));
66 var iv
= crypto
.getRandomValues(new Uint8Array(16));
67 var alg
= {name
: "AES-GCM", length
: 128, iv
};
69 crypto
.subtle
.generateKey(alg
, true, ["encrypt"])
70 .then(util
.cloneExportCompareKeys
)
71 .then(x
=> crypto
.subtle
.encrypt(alg
, x
, data
))
72 .then(complete(that
), error(that
));
76 // -----------------------------------------------------------------------------
78 "Structured Cloning: AES-KW",
81 var alg
= {name
: "AES-KW", length
: 128};
83 crypto
.subtle
.generateKey(alg
, true, ["wrapKey"])
84 .then(util
.cloneExportCompareKeys
)
85 .then(x
=> crypto
.subtle
.wrapKey("raw", x
, x
, "AES-KW"))
86 .then(complete(that
), error(that
));
90 // -----------------------------------------------------------------------------
92 "Structured Cloning: HMAC",
95 var data
= crypto
.getRandomValues(new Uint8Array(128));
96 var alg
= {name
: "HMAC", length
: 256, hash
: "SHA-256"};
98 crypto
.subtle
.generateKey(alg
, true, ["sign", "verify"])
99 .then(util
.cloneExportCompareKeys
)
100 .then(x
=> crypto
.subtle
.sign("HMAC", x
, data
))
101 .then(complete(that
), error(that
));
105 // -----------------------------------------------------------------------------
107 "Structured Cloning: PBKDF2",
110 var key
= new TextEncoder().encode("password");
115 salt
: crypto
.getRandomValues(new Uint8Array(8)),
119 crypto
.subtle
.importKey("raw", key
, "PBKDF2", true, ["deriveBits"])
120 .then(util
.cloneExportCompareKeys
)
121 .then(x
=> crypto
.subtle
.deriveBits(alg
, x
, 160))
122 .then(complete(that
), error(that
));
126 // -----------------------------------------------------------------------------
128 "Structured Cloning: HKDF",
131 var key
= new TextEncoder().encode("password");
136 salt
: new Uint8Array(),
137 info
: new Uint8Array(),
140 crypto
.subtle
.importKey("raw", key
, "HKDF", false, ["deriveBits"])
142 .then(x
=> crypto
.subtle
.deriveBits(alg
, x
, 16))
143 .then(complete(that
), error(that
));
147 // -----------------------------------------------------------------------------
149 "Structured Cloning: RSA-OAEP",
152 var data
= crypto
.getRandomValues(new Uint8Array(128));
158 publicExponent
: new Uint8Array([1, 0, 1]),
161 crypto
.subtle
.generateKey(alg
, true, ["encrypt", "decrypt"])
162 .then(util
.cloneExportCompareKeys
)
164 return crypto
.subtle
.encrypt(alg
, x
.publicKey
, data
)
165 .then(ct
=> crypto
.subtle
.decrypt(alg
, x
.privateKey
, ct
));
167 .then(complete(that
), error(that
));
171 // -----------------------------------------------------------------------------
173 "Structured Cloning: RSASSA-PKCS1-v1_5",
176 var data
= crypto
.getRandomValues(new Uint8Array(128));
179 name
: "RSASSA-PKCS1-v1_5",
182 publicExponent
: new Uint8Array([1, 0, 1]),
185 crypto
.subtle
.generateKey(alg
, true, ["sign", "verify"])
186 .then(util
.cloneExportCompareKeys
)
188 return crypto
.subtle
.sign(alg
, x
.privateKey
, data
)
189 .then(sig
=> crypto
.subtle
.verify(alg
, x
.publicKey
, sig
, data
));
191 .then(complete(that
, x
=> x
), error(that
));
195 // -----------------------------------------------------------------------------
197 "Structured Cloning: RSA-PSS",
200 var data
= crypto
.getRandomValues(new Uint8Array(128));
206 publicExponent
: new Uint8Array([1, 0, 1]),
210 crypto
.subtle
.generateKey(alg
, true, ["sign", "verify"])
211 .then(util
.cloneExportCompareKeys
)
213 return crypto
.subtle
.sign(alg
, x
.privateKey
, data
)
214 .then(sig
=> crypto
.subtle
.verify(alg
, x
.publicKey
, sig
, data
));
216 .then(complete(that
, x
=> x
), error(that
));
220 // -----------------------------------------------------------------------------
221 /* TestArray.addTest(
222 "Structured Cloning: DH",
225 var alg = {name: "DH", prime: tv.dh.prime, generator: new Uint8Array([2])};
227 crypto.subtle.generateKey(alg, true, ["deriveBits"])
228 .then(util.cloneExportCompareKeys)
230 var alg = {name: "DH", public: x.publicKey};
231 return crypto.subtle.deriveBits(alg, x.privateKey, 16);
233 .then(complete(that), error(that));
237 // -----------------------------------------------------------------------------
238 /* TestArray.addTest(
239 "Structured Cloning: ECDH",
242 var alg = {name: "ECDH", namedCurve: "P-256"};
244 crypto.subtle.generateKey(alg, true, ["deriveBits"])
245 .then(util.cloneExportCompareKeys)
247 var alg = {name: "ECDH", public: x.publicKey};
248 return crypto.subtle.deriveBits(alg, x.privateKey, 16);
250 .then(complete(that), error(that));
254 // -----------------------------------------------------------------------------
255 /* TestArray.addTest(
256 "Structured Cloning: ECDSA",
259 var data = crypto.getRandomValues(new Uint8Array(128));
260 var alg = {name: "ECDSA", namedCurve: "P-256", hash: "SHA-256"};
262 crypto.subtle.generateKey(alg, true, ["sign", "verify"])
263 .then(util.cloneExportCompareKeys)
265 return crypto.subtle.sign(alg, x.privateKey, data)
266 .then(sig => crypto.subtle.verify(alg, x.publicKey, sig, data));
268 .then(complete(that), error(that));
281 <div id=
"start" onclick=
"start();">RUN ALL
</div>
283 <div id=
"resultDiv" class=
"content">
285 <span class=
"pass"><span id=
"passN">0</span> passed,
</span>
286 <span class=
"fail"><span id=
"failN">0</span> failed,
</span>
287 <span class=
"pending"><span id=
"pendingN">0</span> pending.
</span>
301 <div id=
"foot"></div>