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 // Generating 2048-bit keys takes some time.
26 SimpleTest
.requestLongerTimeout(2);
28 // -----------------------------------------------------------------------------
30 "RSA-OAEP encrypt/decrypt round-trip",
34 var alg
= {name
: "RSA-OAEP", hash
: "SHA-1"};
36 function setPriv(x
) { privKey
= x
; }
37 function setPub(x
) { pubKey
= x
; }
38 function doEncrypt() {
39 return crypto
.subtle
.encrypt(alg
, pubKey
, tv
.rsaoaep
.data
);
41 function doDecrypt(x
) {
42 return crypto
.subtle
.decrypt(alg
, privKey
, x
);
46 crypto
.subtle
.importKey("pkcs8", tv
.rsaoaep
.pkcs8
, alg
, false, ["decrypt"])
47 .then(setPriv
, error(that
)),
48 crypto
.subtle
.importKey("spki", tv
.rsaoaep
.spki
, alg
, false, ["encrypt"])
49 .then(setPub
, error(that
)),
50 ]).then(doEncrypt
, error(that
))
51 .then(doDecrypt
, error(that
))
53 memcmp_complete(that
, tv
.rsaoaep
.data
),
59 // -----------------------------------------------------------------------------
61 "RSA-OAEP key generation and encrypt/decrypt round-trip (SHA-256)",
68 publicExponent
: new Uint8Array([0x01, 0x00, 0x01]),
71 var privKey
, pubKey
, data
= crypto
.getRandomValues(new Uint8Array(128));
72 function setKey(x
) { pubKey
= x
.publicKey
; privKey
= x
.privateKey
; }
73 function doEncrypt() {
74 return crypto
.subtle
.encrypt(alg
, pubKey
, data
);
76 function doDecrypt(x
) {
77 return crypto
.subtle
.decrypt(alg
, privKey
, x
);
80 crypto
.subtle
.generateKey(alg
, false, ["encrypt", "decrypt"])
81 .then(setKey
, error(that
))
82 .then(doEncrypt
, error(that
))
83 .then(doDecrypt
, error(that
))
85 memcmp_complete(that
, data
),
91 // -----------------------------------------------------------------------------
93 "RSA-OAEP decryption known answer",
96 var alg
= {name
: "RSA-OAEP", hash
: "SHA-1"};
98 function doDecrypt(x
) {
99 return crypto
.subtle
.decrypt(alg
, x
, tv
.rsaoaep
.result
);
101 function fail() { error(that
); }
103 crypto
.subtle
.importKey("pkcs8", tv
.rsaoaep
.pkcs8
, alg
, false, ["decrypt"])
104 .then( doDecrypt
, fail
)
105 .then( memcmp_complete(that
, tv
.rsaoaep
.data
), fail
);
109 // -----------------------------------------------------------------------------
111 "RSA-OAEP input data length checks (2048-bit key)",
119 publicExponent
: new Uint8Array([0x01, 0x00, 0x01]),
122 function setKey(x
) { pubKey
= x
.publicKey
; }
123 function doEncrypt(n
) {
124 console
.log("entered encrypt(" + n
+ ")");
126 return crypto
.subtle
.encrypt(alg
, pubKey
, new Uint8Array(n
));
130 crypto
.subtle
.generateKey(alg
, false, ["encrypt", "decrypt"])
131 .then(setKey
, error(that
))
132 .then(doEncrypt(214), error(that
))
133 .then(doEncrypt(215), error(that
))
134 .then(error(that
), complete(that
));
138 // -----------------------------------------------------------------------------
140 "RSA-OAEP key import with invalid hash",
143 var alg
= {name
: "RSA-OAEP", hash
: "SHA-123"};
145 crypto
.subtle
.importKey("pkcs8", tv
.rsaoaep
.pkcs8
, alg
, false, ["decrypt"])
146 .then(error(that
), complete(that
));
150 // -----------------------------------------------------------------------------
152 "Test that RSA-OAEP encrypt/decrypt accepts strings as AlgorithmIdentifiers",
159 publicExponent
: new Uint8Array([0x01, 0x00, 0x01]),
162 var privKey
, pubKey
, data
= crypto
.getRandomValues(new Uint8Array(128));
163 function setKey(x
) { pubKey
= x
.publicKey
; privKey
= x
.privateKey
; }
164 function doEncrypt() {
165 return crypto
.subtle
.encrypt("RSA-OAEP", pubKey
, data
);
167 function doDecrypt(x
) {
168 return crypto
.subtle
.decrypt("RSA-OAEP", privKey
, x
);
171 crypto
.subtle
.generateKey(alg
, false, ["encrypt", "decrypt"])
175 .then(memcmp_complete(that
, data
), error(that
));
188 <div id=
"start" onclick=
"start();">RUN ALL
</div>
190 <div id=
"resultDiv" class=
"content">
192 <span class=
"pass"><span id=
"passN">0</span> passed,
</span>
193 <span class=
"fail"><span id=
"failN">0</span> failed,
</span>
194 <span class=
"pending"><span id=
"pendingN">0</span> pending.
</span>
208 <div id=
"foot"></div>