OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <html> | 2 <html> |
3 <head> | 3 <head> |
4 <script src="../fast/js/resources/js-test-pre.js"></script> | 4 <script src="../fast/js/resources/js-test-pre.js"></script> |
5 <script src="resources/common.js"></script> | 5 <script src="resources/common.js"></script> |
6 </head> | 6 </head> |
7 <body> | 7 <body> |
8 <p id="description"></p> | 8 <p id="description"></p> |
9 <div id="console"></div> | 9 <div id="console"></div> |
10 | 10 |
11 <script> | 11 <script> |
12 description("Tests cypto.subtle.digest."); | 12 description("Tests cypto.subtle.digest."); |
13 | 13 |
14 jsTestIsAsync = true; | 14 jsTestIsAsync = true; |
15 | 15 |
16 function printRejectedResult(value) | 16 // These SHA-* test vectors were taking from: |
17 { | 17 // http://csrc.nist.gov/groups/STM/cavp/documents/shs/shabytetestvectors.zip |
18 debug(" rejected with value of " + value); | 18 // |
| 19 // This is not intended to be an exhaustive test, but rather give basic |
| 20 // confidence that things work. |
| 21 // |
| 22 // Both inputs and outputs are written as a hex-encoded string. |
| 23 kDigestTestVectors = [ |
| 24 { |
| 25 algorithm: "SHA-1", |
| 26 input: "", |
| 27 output: "da39a3ee5e6b4b0d3255bfef95601890afd80709" |
| 28 }, |
| 29 { |
| 30 algorithm: "SHA-224", |
| 31 input: "", |
| 32 output: "d14a028c2a3a2bc9476102bb288234c415a2b01f828ea62ac5b3e42f" |
| 33 }, |
| 34 { |
| 35 algorithm: "SHA-256", |
| 36 input: "", |
| 37 output: "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" |
| 38 }, |
| 39 { |
| 40 algorithm: "SHA-384", |
| 41 input: "", |
| 42 output: "38b060a751ac96384cd9327eb1b1e36a21fdb71114be07434c0cc7bf63f6e1da274
edebfe76f65fbd51ad2f14898b95b" |
| 43 }, |
| 44 { |
| 45 algorithm: "SHA-512", |
| 46 input: "", |
| 47 output: "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d
0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e" |
| 48 }, |
| 49 { |
| 50 algorithm: "SHA-1", |
| 51 input: "00", |
| 52 output: "5ba93c9db0cff93f52b521d7420e43f6eda2784f" |
| 53 }, |
| 54 { |
| 55 algorithm: "SHA-224", |
| 56 input: "00", |
| 57 output: "fff9292b4201617bdc4d3053fce02734166a683d7d858a7f5f59b073" |
| 58 }, |
| 59 { |
| 60 algorithm: "SHA-256", |
| 61 input: "00", |
| 62 output: "6e340b9cffb37a989ca544e6bb780a2c78901d3fb33738768511a30617afa01d" |
| 63 }, |
| 64 { |
| 65 algorithm: "SHA-384", |
| 66 input: "00", |
| 67 output: "bec021b4f368e3069134e012c2b4307083d3a9bdd206e24e5f0d86e13d663665593
3ec2b413465966817a9c208a11717" |
| 68 }, |
| 69 { |
| 70 algorithm: "SHA-512", |
| 71 input: "00", |
| 72 output: "b8244d028981d693af7b456af8efa4cad63d282e19ff14942c246e50d9351d22704
a802a71c3580b6370de4ceb293c324a8423342557d4e5c38438f0e36910ee" |
| 73 }, |
| 74 { |
| 75 algorithm: "SHA-1", |
| 76 input: "000102030405", |
| 77 output: "868460d98d09d8bbb93d7b6cdd15cc7fbec676b9" |
| 78 }, |
| 79 { |
| 80 algorithm: "SHA-224", |
| 81 input: "000102030405", |
| 82 output: "7d92e7f1cad1818ed1d13ab41f04ebabfe1fef6bb4cbeebac34c29bc" |
| 83 }, |
| 84 { |
| 85 algorithm: "SHA-256", |
| 86 input: "000102030405", |
| 87 output: "17e88db187afd62c16e5debf3e6527cd006bc012bc90b51a810cd80c2d511f43" |
| 88 }, |
| 89 { |
| 90 algorithm: "SHA-384", |
| 91 input: "000102030405", |
| 92 output: "79f4738706fce9650ac60266675c3cd07298b09923850d525604d040e6e448adc7d
c22780d7e1b95bfeaa86a678e4552" |
| 93 }, |
| 94 { |
| 95 algorithm: "SHA-512", |
| 96 input: "000102030405", |
| 97 output: "2f3831bccc94cf061bcfa5f8c23c1429d26e3bc6b76edad93d9025cb91c903af6cf
9c935dc37193c04c2c66e7d9de17c358284418218afea2160147aaa912f4c" |
| 98 }, |
| 99 ]; |
| 100 |
| 101 // Run each test. |
| 102 for (var i = 0; i < kDigestTestVectors.length; ++i) { |
| 103 var testCase = kDigestTestVectors[i]; |
| 104 var promise = crypto.subtle.digest({name: testCase.algorithm}, hexStringToUi
nt8Array(testCase.input)); |
| 105 promise.then(onTestCaseComplete.bind(null, testCase), failAndFinishJSTest); |
19 } | 106 } |
20 | 107 |
21 function printAcceptedResult(result) | 108 function onTestCaseComplete(testCase, result) |
22 { | 109 { |
23 debug(" = " + byteArrayToHexString(new Uint8Array(result))); | 110 var testDescription = testCase.algorithm + " of [" + testCase.input + "]"; |
| 111 bytesShouldMatchHexString(testDescription, testCase.output, result); |
| 112 |
| 113 // Once the last test has completed, done. |
| 114 if (testCase == kDigestTestVectors[kDigestTestVectors.length - 1]) { |
| 115 finishJSTest(); |
| 116 } |
24 } | 117 } |
25 | 118 |
26 Promise.resolve(null).then(function() { | 119 // Pass invalid data to digeset() |
27 debug("SHA1 of []"); | 120 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); |
28 return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([])); | 121 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); |
29 }).then(function(result) { | 122 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); |
30 printAcceptedResult(result); | |
31 | 123 |
32 debug("SHA1 of [0x0]") | 124 // Pass invalid algorithmIdentifiers to digest() |
33 return crypto.subtle.digest({name: 'sha-1'}, new Uint8Array([0])); | 125 data = new Uint8Array([0]); |
34 }).then(function(result) { | 126 shouldThrow("crypto.subtle.digest({name: 'sha'}, data)"); |
35 printAcceptedResult(result); | 127 shouldThrow("crypto.subtle.digest(null, data)"); |
36 | 128 shouldThrow("crypto.subtle.digest({}, data)"); |
37 // Pass invalid data to digeset() | |
38 shouldThrow("crypto.subtle.digest({name: 'sha-1'})"); | |
39 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, null)"); | |
40 shouldThrow("crypto.subtle.digest({name: 'sha-1'}, 10)"); | |
41 | |
42 // Pass invalid algorithmIdentifiers to digest() | |
43 data = new Uint8Array([0]); | |
44 shouldThrow("crypto.subtle.digest({name: 'sha'}, data)"); | |
45 shouldThrow("crypto.subtle.digest(null, data)"); | |
46 shouldThrow("crypto.subtle.digest({}, data)"); | |
47 }).then(finishJSTest, failAndFinishJSTest); | |
48 | 129 |
49 </script> | 130 </script> |
50 | 131 |
51 <script src="../fast/js/resources/js-test-post.js"></script> | 132 <script src="../fast/js/resources/js-test-post.js"></script> |
52 </body> | 133 </body> |
53 </html> | 134 </html> |
OLD | NEW |