Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 1 | <?xml version = "1.0" encoding="utf-8" ?>
|
| 2 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
| 3 | "DTD/xhtml1-strict.dtd">
|
Jeff Burke | 92dd8e4 | 2012-12-08 11:40:31 -0800 | [diff] [blame] | 4 | <!--
|
| 5 | See COPYING for copyright and distribution information.
|
| 6 | -->
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 7 | <html xmlns = "http://www.w3.org/1999/xhtml">
|
| 8 |
|
| 9 | <head>
|
Jeff Thompson | 8ecc076 | 2012-08-18 17:09:11 -0700 | [diff] [blame] | 10 | <title>Test SHA-256</title>
|
Jeff Thompson | 38422f4 | 2012-11-15 00:20:39 -0800 | [diff] [blame] | 11 |
|
| 12 | <script type="text/javascript" src="../Helper.js"></script>
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 13 |
|
Meki Cherkaoui | 8f17361 | 2012-06-06 01:05:40 -0700 | [diff] [blame] | 14 | <script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/sha256.js"></script>
|
| 15 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 16 | <script type="text/javascript">
|
Jeff Thompson | f9a0bc2 | 2012-12-02 22:16:16 -0800 | [diff] [blame] | 17 | function hash(){
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 18 | var input = document.getElementById('contentname').value;
|
| 19 |
|
Jeff Thompson | 9b288b3 | 2012-12-01 14:25:05 -0800 | [diff] [blame] | 20 | var output = "from string- " + hex_sha256(input) + "<br/>";
|
Jeff Thompson | f9a0bc2 | 2012-12-02 22:16:16 -0800 | [diff] [blame] | 21 |
|
| 22 | var sha256 = new Sha256();
|
| 23 | var data = DataUtils.toNumbersFromString(input);
|
| 24 | // Call update multiple times in small chunks to test the buffering.
|
| 25 | var chunkSize = 3;
|
| 26 | var nCalls = Math.floor(data / chunkSize);
|
| 27 | for (var i = 0; i < nCalls; ++i)
|
| 28 | sha256.update(data.subarray(i * chunkSize, chunkSize));
|
| 29 | sha256.update(data.subarray(i * nCalls, data.length));
|
| 30 | output += "from bytes-- " + DataUtils.toHex(sha256.finalize()) + "<br/>";
|
| 31 |
|
Jeff Thompson | 9b288b3 | 2012-12-01 14:25:05 -0800 | [diff] [blame] | 32 | output += "reference---- " + CryptoJS.SHA256(input);
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 33 |
|
| 34 | document.getElementById('result').innerHTML = output;
|
Jeff Thompson | 9b288b3 | 2012-12-01 14:25:05 -0800 | [diff] [blame] | 35 | }
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 36 | </script>
|
| 37 |
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 38 | </head>
|
| 39 | <body >
|
| 40 | <form>
|
Jeff Thompson | bd82926 | 2012-11-30 22:28:37 -0800 | [diff] [blame] | 41 | Please Enter Text to Hash:<br /><input id="contentname" type="text" name="CONTENTNAME" value="/ndn/abc" /> <br />
|
Meki Cherkaoui | 88d59cd | 2012-05-14 07:34:58 -0700 | [diff] [blame] | 42 | </form>
|
| 43 | <button onclick="hash()">Hash</button>
|
| 44 |
|
| 45 | <p id="result"></p>
|
| 46 |
|
| 47 | </body>
|
jeff | 6c38857 | 2012-09-02 15:30:17 -0700 | [diff] [blame] | 48 | </html>
|