summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian Turek <brian.turek@gmail.com>2010-08-31 17:35:55 +0000
committerBrian Turek <brian.turek@gmail.com>2010-08-31 17:35:55 +0000
commitf6c93ebedad54bd47955b8a0d4083aba2019fe47 (patch)
treebdb34c8532398e2e4d88908704568aaf2127667b
parent2a7cd5d52861064d110c0de24b140c1cc212d1ef (diff)
parentbbb954541cdb1021674ee155f2b8286ae60a4273 (diff)
downloadjsSHA-f6c93ebedad54bd47955b8a0d4083aba2019fe47.zip
jsSHA-f6c93ebedad54bd47955b8a0d4083aba2019fe47.tar.gz
jsSHA-f6c93ebedad54bd47955b8a0d4083aba2019fe47.tar.bz2
Merged optimizations into trunk
-rw-r--r--CHANGELOG23
-rw-r--r--LICENSE27
-rw-r--r--README44
-rw-r--r--src/sha.js1095
-rw-r--r--src/sha1.js10
-rw-r--r--src/sha1_nice.js440
-rw-r--r--src/sha256.js12
-rw-r--r--src/sha256_nice.js535
-rw-r--r--src/sha512.js10
-rw-r--r--src/sha512_nice.js646
-rw-r--r--test/test.html1038
11 files changed, 2150 insertions, 1730 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 813b808..42c0fc9 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -2,11 +2,20 @@
jsSHA - ChangeLog
-------------------------
+1.3 (2010-09-01)
+=========================
+- Changed method of declaring objects/classes
+- Moved non-instance specific variables and methods to class scope
+- Removed logically correct but unneeded conditionals
+
1.2 (2009-07-22)
=========================
-- Added the HMAC algorithm for all supported hashes (using both ASCII and hex keys)
-- As a result of adding HMAC, added support for hash input text to be hex (ASCII representation of hex)
-- Added multiple variants of safeAdd functions, resulting in a significant performance gain
+- Added the HMAC algorithm for all supported hashes (using both ASCII and hex
+ keys)
+- As a result of adding HMAC, added support for hash input text to be hex
+ (ASCII representation of hex)
+- Added multiple variants of safeAdd functions, resulting in a significant
+ performance gain
- Removed wrapper.js file
- Used a different JavaScript compressor resulting in smaller file sizes
@@ -16,16 +25,18 @@
1.1 (2008-09-25)
=========================
-- Fixed an issue with incorrect hashes being generated when jsSHA ojbects were used to generate
- multiple hashes
+- Fixed an issue with incorrect hashes being generated when jsSHA ojbects were
+ used to generate multiple hashes
1.0 (2008-09-25)
=========================
- Made all functions/variables follow an object-orientated methodology
- Removed support for string hash output as the hash is rarely ASCII friendly
- Changed the interface to calculate hashes (see README)
-- Made sha.js validate against JSLint (http://www.jslint.com/) using "Recommended" settings
+- Made sha.js validate against JSLint (http://www.jslint.com/) using
+ "Recommended" settings
0.1 (2008-02-21)
=========================
- Initial public release
+
diff --git a/LICENSE b/LICENSE
index d4472bf..3ce63b8 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,8 +1,8 @@
-Copyright (c) 2009, Brian Turek
+Copyright (c) 2008-2010, Brian Turek
All rights reserved.
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
@@ -12,13 +12,14 @@ are permitted provided that the following conditions are met:
* The names of the contributors may not be used to endorse or promote products
derived from this software without specific prior written permission.
-THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
-ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
-IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
-INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
-OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
-OF THE POSSIBILITY OF SUCH DAMAGE.
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ANDANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIEDWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT,INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING,BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ LOSS OF USE,DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OFLIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCEOR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISEDOF THE POSSIBILITY OF SUCH DAMAGE.
+
diff --git a/README b/README
index c52bfd8..21356c8 100644
--- a/README
+++ b/README
@@ -1,19 +1,22 @@
jsSHA - A JavaScript implementation of the complete Secure Hash Standard family
- (SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512) as well as HMAC by Brian Turek
+ (SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512) as well as HMAC by
+ Brian Turek
About
-------------------------
-jsSHA is a javaScript implementation of the complete Secure Hash Algorithm family as defined
-by FIPS PUB 180-2 (http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf). It
-also includes the HMAC algorithm with SHA support as defined by FIPS PUB 198a
+jsSHA is a javaScript implementation of the complete Secure Hash Algorithm
+family as defined by FIPS PUB 180-2
+(http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf).
+It also includes the HMAC algorithm with SHA support as defined by FIPS PUB 198a
(http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf)
-With the slow phasing out of MD5 as the standard hash to use in web applications, a client-side
-implementation of the complete Secure Hash Standard family was needed. Due to SHA-384 and SHA-512's
-use of 64-bit values throughout the algorithm, JavaScript can not easily natively support the calculation
-of these hashes. As a result, a bit of hacking had to be done to make sure the values behaved themselves.
-SHA-224 was added to the Secure Hash Standard family on 25 February 2004 so it was also included in this
-package.
+With the slow phasing out of MD5 as the standard hash to use in web
+applications, a client-side implementation of the complete Secure Hash Standard
+family was needed. Due to SHA-384 and SHA-512's use of 64-bit values throughout
+the algorithm, JavaScript can not easily natively support the calculation of
+these hashes. As a result, a bit of hacking had to be done to make sure the
+values behaved themselves. SHA-224 was added to the Secure Hash Standard family
+on 25 February 2004 so it was also included in this package.
Files
@@ -34,26 +37,31 @@ test/test.html
A test page that calculates various hashes and has their correct values.
test/HMACGen.py
-A Python 3.X script that generates the correct HMAC hashes as the specification did not provide hashes for
-algorithms other than SHA-1
+A Python 3.X script that generates the correct HMAC hashes as the specification
+did not provide hashes for algorithms other than SHA-1
Usage
-------------------------
-Include the desired JavaScript file (sha.js, sha1.js, sha256.js, or sha512.js) in your header (sha.js used below):
+Include the desired JavaScript file (sha.js, sha1.js, sha256.js, or sha512.js)
+in your header (sha.js used below):
<script type="text/javascript" src="/path/to/sha.js"></script>
-Instantiate a new jsSHA object with your string to be hashed as the only parameter. Then, call getHash with the desired
-hash variant (SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512) and output type (HEX or B64). In the example below,
-"This is a Test" and "SHA-512" were used as the string to be hashed and variant respectively. Also, the HMAC using ASCII
-key "SecretKey" and hashing algorithm SHA-512 was calculated.
+Instantiate a new jsSHA object with your string to be hashed as the only
+parameter. Then, call getHash with the desired hash variant (SHA-1, SHA-224,
+SHA-256, SHA-384, or SHA-512) and output type (HEX or B64). In the example
+below, "This is a Test" and "SHA-512" were used as the string to be hashed and
+variant respectively. Also, the HMAC using ASCII key "SecretKey" and hashing
+algorithm SHA-512 was calculated.
var shaObj = new jsSHA("This is a Test", "ASCII");
var hash = shaObj.getHash("SHA-512", "HEX");
var hmac = shaObj.getHMAC("SecretKey", "ASCII", "SHA-512", "HEX");
-NOTE: If you are using sha1.js, omit the SHA variant parameter as there is only one option.
+NOTE: If you are using sha1.js, omit the SHA variant parameter as there is only
+one option.
Contact Info
-------------------------
The project's website is located at http://jssha.sourceforge.net/
+
diff --git a/src/sha.js b/src/sha.js
index 484a496..9ee68a4 100644
--- a/src/sha.js
+++ b/src/sha.js
@@ -1,66 +1,59 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
-
-/*
- * Int_64 is a object/container for 2 32-bit numbers emulating a 64-bit number
- *
- * @constructor
- * @param {Number} msint_32 The most significant 32-bits of a 64-bit number
- * @param {Number} lsint_32 The least significant 32-bits of a 64-bit number
- */
-function Int_64(msint_32, lsint_32) {
- this.highOrder = msint_32;
- this.lowOrder = lsint_32;
-}
-
-/*
- * jsSHA is the workhorse of the library. Instantiate it with the string to be hashed
- * as the parameter
- *
- * @constructor
- * @param {String} srcString The string to be hashed
- * @param {String} inputFormat The format of srcString, ASCII or HEX
- */
-function jsSHA(srcString, inputFormat) {
-
+(function ()
+{
/*
* Configurable variables. Defaults typically work
*/
- jsSHA.charSize = 8; // Number of Bits Per character (8 for ASCII, 16 for Unicode)
- jsSHA.b64pad = ""; // base-64 pad character. "=" for strict RFC compliance
- jsSHA.hexCase = 0; // hex output format. 0 - lowercase; 1 - uppercase
+ /* Number of Bits Per character (8 for ASCII, 16 for Unicode) */
+ var charSize = 8,
+ /* base-64 pad character. "=" for strict RFC compliance */
+ b64pad = "",
+ /* hex output format. 0 - lowercase; 1 - uppercase */
+ hexCase = 0,
- var sha1 = null;
- var sha224 = null;
- var sha256 = null;
- var sha384 = null;
- var sha512 = null;
+ /*
+ * Int_64 is a object for 2 32-bit numbers emulating a 64-bit number
+ *
+ * @constructor
+ * @param {Number} msint_32 The most significant 32-bits of a 64-bit number
+ * @param {Number} lsint_32 The least significant 32-bits of a 64-bit number
+ */
+ Int_64 = function (msint_32, lsint_32)
+ {
+ this.highOrder = msint_32;
+ this.lowOrder = lsint_32;
+ },
/*
* Convert a string to an array of big-endian words
- * If charSize is ASCII, characters >255 have their hi-byte silently ignored.
+ * If charSize is ASCII, characters >255 have their hi-byte silently
+ * ignored.
*
* @param {String} str String to be converted to binary representation
* @return Integer array representation of the parameter
*/
- var str2binb = function (str) {
- var bin = [];
- var mask = (1 << jsSHA.charSize) - 1;
- var length = str.length * jsSHA.charSize;
+ str2binb = function (str)
+ {
+ var bin = [], mask = (1 << charSize) - 1,
+ length = str.length * charSize, i;
- for (var i = 0; i < length; i += jsSHA.charSize) {
- bin[i >> 5] |= (str.charCodeAt(i / jsSHA.charSize) & mask) <<
- (32 - jsSHA.charSize - i % 32);
+ for (i = 0; i < length; i += charSize)
+ {
+ bin[i >> 5] |= (str.charCodeAt(i / charSize) & mask) <<
+ (32 - charSize - (i % 32));
}
return bin;
- };
+ },
/*
* Convert a hex string to an array of big-endian words
@@ -68,86 +61,82 @@ function jsSHA(srcString, inputFormat) {
* @param {String} str String to be converted to binary representation
* @return Integer array representation of the parameter
*/
- var hex2binb = function (str) {
- var bin = [];
- var length = str.length;
+ hex2binb = function (str)
+ {
+ var bin = [], length = str.length, i, num;
- for (var i = 0; i < length; i += 2) {
- var num = parseInt(str.substr(i, 2), 16);
- if (!isNaN(num)) {
+ for (i = 0; i < length; i += 2)
+ {
+ num = parseInt(str.substr(i, 2), 16);
+ if (!isNaN(num))
+ {
bin[i >> 3] |= num << (24 - (4 * (i % 8)));
- } else {
+ }
+ else
+ {
return "INVALID HEX STRING";
}
}
return bin;
- };
-
- var strBinLen = null;
- var strToHash = null;
-
- // Convert the input string into the correct type
- if ("HEX" === inputFormat) {
- if (0 !== (srcString.length % 2)) {
- return "TEXT MUST BE IN BYTE INCREMENTS";
- }
- strBinLen = srcString.length * 4;
- strToHash = hex2binb(srcString);
- } else if (("ASCII" === inputFormat) ||
- ('undefined' === typeof(inputFormat))) {
- strBinLen = srcString.length * jsSHA.charSize;
- strToHash = str2binb(srcString);
- } else {
- return "UNKNOWN TEXT INPUT TYPE";
- }
+ },
/*
* Convert an array of big-endian words to a hex string.
*
* @private
- * @param {Array} binarray Array of integers to be converted to hexidecimal representation
+ * @param {Array} binarray Array of integers to be converted to hexidecimal
+ * representation
* @return Hexidecimal representation of the parameter in String form
*/
- var binb2hex = function (binarray) {
- var hex_tab = jsSHA.hexCase ? "0123456789ABCDEF" : "0123456789abcdef";
- var str = "";
- var length = binarray.length * 4;
+ binb2hex = function (binarray)
+ {
+ var hex_tab = (hexCase) ? "0123456789ABCDEF" : "0123456789abcdef",
+ str = "", length = binarray.length * 4, i, srcByte;
- for (var i = 0; i < length; i++) {
- str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) +
- hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
+ for (i = 0; i < length; i += 1)
+ {
+ srcByte = binarray[i >> 2] >> ((3 - (i % 4)) * 8);
+ str += hex_tab.charAt((srcByte >> 4) & 0xF) +
+ hex_tab.charAt(srcByte & 0xF);
}
return str;
- };
+ },
/*
* Convert an array of big-endian words to a base-64 string
*
* @private
- * @param {Array} binarray Array of integers to be converted to base-64 representation
+ * @param {Array} binarray Array of integers to be converted to base-64
+ * representation
* @return Base-64 encoded representation of the parameter in String form
*/
- var binb2b64 = function (binarray) {
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var str = "";
- var length = binarray.length * 4;
- for (var i = 0; i < length; i += 3)
+ binb2b64 = function (binarray)
+ {
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
+ "0123456789+/", str = "", length = binarray.length * 4, i, j,
+ triplet;
+
+ for (i = 0; i < length; i += 3)
{
- var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) |
+ triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) |
(((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
- for (var j = 0; j < 4; j++) {
- if (i * 8 + j * 6 > binarray.length * 32) {
- str += jsSHA.b64pad;
- } else {
+ for (j = 0; j < 4; j += 1)
+ {
+ if (i * 8 + j * 6 <= binarray.length * 32)
+ {
str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
}
+ else
+ {
+ str += b64pad;
+ }
}
}
return str;
- };
+ },
/*
* The 32-bit implementation of circular rotate left
@@ -157,13 +146,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} n The number of bits to shift
* @return The x shifted circularly by n bits
*/
- var rotl_32 = function (x, n) {
- if (n < 32) {
- return (x << n) | (x >>> (32 - n));
- } else {
- return x;
- }
- };
+ rotl_32 = function (x, n)
+ {
+ return (x << n) | (x >>> (32 - n));
+ },
/*
* The 32-bit implementation of circular rotate right
@@ -173,13 +159,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} n The number of bits to shift
* @return The x shifted circularly by n bits
*/
- var rotr_32 = function (x, n) {
- if (n < 32) {
- return (x >>> n) | (x << (32 - n));
- } else {
- return x;
- }
- };
+ rotr_32 = function (x, n)
+ {
+ return (x >>> n) | (x << (32 - n));
+ },
/*
* The 64-bit implementation of circular rotate right
@@ -189,18 +172,23 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} n The number of bits to shift
* @return The x shifted circularly by n bits
*/
- var rotr_64 = function (x, n) {
- if (n < 32) {
+ rotr_64 = function (x, n)
+ {
+ if (n <= 32)
+ {
return new Int_64(
(x.highOrder >>> n) | (x.lowOrder << (32 - n)),
(x.lowOrder >>> n) | (x.highOrder << (32 - n))
);
- } else if (n === 32) { // Apparently in JS, shifting a 32-bit value by 32 yields original value
- return new Int_64(x.lowOrder, x.highOrder);
- } else {
- return rotr_64(rotr_64(x, 32), n - 32);
}
- };
+ else
+ {
+ return new Int_64(
+ (x.lowOrder >>> n) | (x.highOrder << (32 - n)),
+ (x.highOrder >>> n) | (x.lowOrder << (32 - n))
+ );
+ }
+ },
/*
* The 32-bit implementation of shift right
@@ -210,13 +198,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} n The number of bits to shift
* @return The x shifted by n bits
*/
- var shr_32 = function (x, n) {
- if (n < 32) {
- return x >>> n;
- } else {
- return 0;
- }
- };
+ shr_32 = function (x, n)
+ {
+ return x >>> n;
+ },
/*
* The 64-bit implementation of shift right
@@ -226,18 +211,23 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} n The number of bits to shift
* @return The x shifted by n bits
*/
- var shr_64 = function (x, n) {
- if (n < 32) {
+ shr_64 = function (x, n)
+ {
+ if (n <= 32)
+ {
return new Int_64(
x.highOrder >>> n,
x.lowOrder >>> n | (x.highOrder << (32 - n))
);
- } else if (n === 32) { // Apparently in JS, shifting a 32-bit value by 32 yields original value
- return new Int_64(0, x.highOrder);
- } else {
- return shr_64(shr_64(x, 32), n - 32);
}
- };
+ else
+ {
+ return new Int_64(
+ 0,
+ x.highOrder << (32 - n)
+ );
+ }
+ },
/*
* The 32-bit implementation of the NIST specified Parity function
@@ -248,9 +238,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} z The third 32-bit integer argument
* @return The NIST specified output of the function
*/
- var parity_32 = function (x, y, z) {
+ parity_32 = function (x, y, z)
+ {
return x ^ y ^ z;
- };
+ },
/*
* The 32-bit implementation of the NIST specified Ch function
@@ -261,9 +252,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} z The third 32-bit integer argument
* @return The NIST specified output of the function
*/
- var ch_32 = function (x, y, z) {
+ ch_32 = function (x, y, z)
+ {
return (x & y) ^ (~x & z);
- };
+ },
/*
* The 64-bit implementation of the NIST specified Ch function
@@ -274,12 +266,13 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} z The third 64-bit integer argument
* @return The NIST specified output of the function
*/
- var ch_64 = function (x, y, z) {
+ ch_64 = function (x, y, z)
+ {
return new Int_64(
(x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),
(x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)
);
- };
+ },
/*
* The 32-bit implementation of the NIST specified Maj function
@@ -290,9 +283,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} z The third 32-bit integer argument
* @return The NIST specified output of the function
*/
- var maj_32 = function (x, y, z) {
+ maj_32 = function (x, y, z)
+ {
return (x & y) ^ (x & z) ^ (y & z);
- };
+ },
/*
* The 64-bit implementation of the NIST specified Maj function
@@ -303,12 +297,17 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} z The third 64-bit integer argument
* @return The NIST specified output of the function
*/
- var maj_64 = function (x, y, z) {
+ maj_64 = function (x, y, z)
+ {
return new Int_64(
- (x.highOrder & y.highOrder) ^ (x.highOrder & z.highOrder) ^ (y.highOrder & z.highOrder),
- (x.lowOrder & y.lowOrder) ^ (x.lowOrder & z.lowOrder) ^ (y.lowOrder & z.lowOrder)
+ (x.highOrder & y.highOrder) ^
+ (x.highOrder & z.highOrder) ^
+ (y.highOrder & z.highOrder),
+ (x.lowOrder & y.lowOrder) ^
+ (x.lowOrder & z.lowOrder) ^
+ (y.lowOrder & z.lowOrder)
);
- };
+ },
/*
* The 32-bit implementation of the NIST specified Sigma0 function
@@ -317,9 +316,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} x The 32-bit integer argument
* @return The NIST specified output of the function
*/
- var sigma0_32 = function (x) {
+ sigma0_32 = function (x)
+ {
return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22);
- };
+ },
/*
* The 64-bit implementation of the NIST specified Sigma0 function
@@ -328,15 +328,15 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} x The 64-bit integer argument
* @return The NIST specified output of the function
*/
- var sigma0_64 = function (x) {
- var rotr28 = rotr_64(x, 28);
- var rotr34 = rotr_64(x, 34);
- var rotr39 = rotr_64(x, 39);
+ sigma0_64 = function (x)
+ {
+ var rotr28 = rotr_64(x, 28), rotr34 = rotr_64(x, 34),
+ rotr39 = rotr_64(x, 39);
return new Int_64(
rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder);
- };
+ },
/*
* The 32-bit implementation of the NIST specified Sigma1 function
@@ -345,9 +345,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} x The 32-bit integer argument
* @return The NIST specified output of the function
*/
- var sigma1_32 = function (x) {
+ sigma1_32 = function (x)
+ {
return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25);
- };
+ },
/*
* The 64-bit implementation of the NIST specified Sigma1 function
@@ -356,15 +357,15 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} x The 64-bit integer argument
* @return The NIST specified output of the function
*/
- var sigma1_64 = function (x) {
- var rotr14 = rotr_64(x, 14);
- var rotr18 = rotr_64(x, 18);
- var rotr41 = rotr_64(x, 41);
+ sigma1_64 = function (x)
+ {
+ var rotr14 = rotr_64(x, 14), rotr18 = rotr_64(x, 18),
+ rotr41 = rotr_64(x, 41);
return new Int_64(
rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,
rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder);
- };
+ },
/*
* The 32-bit implementation of the NIST specified Gamma0 function
@@ -373,9 +374,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} x The 32-bit integer argument
* @return The NIST specified output of the function
*/
- var gamma0_32 = function (x) {
+ gamma0_32 = function (x)
+ {
return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3);
- };
+ },
/*
* The 64-bit implementation of the NIST specified Gamma0 function
@@ -384,15 +386,15 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} x The 64-bit integer argument
* @return The NIST specified output of the function
*/
- var gamma0_64 = function (x) {
- var rotr1 = rotr_64(x, 1);
- var rotr8 = rotr_64(x, 8);
- var shr7 = shr_64(x, 7);
+ gamma0_64 = function (x)
+ {
+ var rotr1 = rotr_64(x, 1), rotr8 = rotr_64(x, 8), shr7 = shr_64(x, 7);
return new Int_64(
rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,
- rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder);
- };
+ rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder
+ );
+ },
/*
* The 32-bit implementation of the NIST specified Gamma1 function
@@ -401,9 +403,10 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} x The 32-bit integer argument
* @return The NIST specified output of the function
*/
- var gamma1_32 = function (x) {
+ gamma1_32 = function (x)
+ {
return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10);
- };
+ },
/*
* The 64-bit implementation of the NIST specified Gamma1 function
@@ -412,35 +415,37 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} x The 64-bit integer argument
* @return The NIST specified output of the function
*/
- var gamma1_64 = function (x) {
- var rotr19 = rotr_64(x, 19);
- var rotr61 = rotr_64(x, 61);
- var shr6 = shr_64(x, 6);
+ gamma1_64 = function (x)
+ {
+ var rotr19 = rotr_64(x, 19), rotr61 = rotr_64(x, 61),
+ shr6 = shr_64(x, 6);
return new Int_64(
rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,
- rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder);
- };
+ rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder
+ );
+ },
/*
- * Add two 32-bit integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
+ * Add two 32-bit integers, wrapping at 2^32. This uses 16-bit operations
+ * internally to work around bugs in some JS interpreters.
*
* @private
* @param {Number} x The first 32-bit integer argument to be added
* @param {Number} y The second 32-bit integer argument to be added
* @return The sum of x + y
*/
- var safeAdd_32_2 = function (x, y) {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16);
+ safeAdd_32_2 = function (x, y)
+ {
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF),
+ msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
+ },
/*
- * Add four 32-bit integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
+ * Add four 32-bit integers, wrapping at 2^32. This uses 16-bit operations
+ * internally to work around bugs in some JS interpreters.
*
* @private
* @param {Number} a The first 32-bit integer argument to be added
@@ -449,16 +454,18 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} d The fourth 32-bit integer argument to be added
* @return The sum of a + b + c + d
*/
- var safeAdd_32_4 = function (a, b, c, d) {
- var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF);
- var msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (lsw >>> 16);
+ safeAdd_32_4 = function (a, b, c, d)
+ {
+ var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF),
+ msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
+ (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
+ },
/*
- * Add five 32-bit integers, wrapping at 2^32. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
+ * Add five 32-bit integers, wrapping at 2^32. This uses 16-bit operations
+ * internally to work around bugs in some JS interpreters.
*
* @private
* @param {Number} a The first 32-bit integer argument to be added
@@ -468,39 +475,43 @@ function jsSHA(srcString, inputFormat) {
* @param {Number} e The fifth 32-bit integer argument to be added
* @return The sum of a + b + c + d + e
*/
- var safeAdd_32_5 = function (a, b, c, d, e) {
+ safeAdd_32_5 = function (a, b, c, d, e)
+ {
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) +
- (e & 0xFFFF);
- var msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
- (e >>> 16) + (lsw >>> 16);
+ (e & 0xFFFF),
+ msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
+ (e >>> 16) + (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
+ },
/*
- * Add two 64-bit integers, wrapping at 2^64. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
+ * Add two 64-bit integers, wrapping at 2^64. This uses 16-bit operations
+ * internally to work around bugs in some JS interpreters.
*
* @private
* @param {Int_64} x The first 64-bit integer argument to be added
* @param {Int_64} y The second 64-bit integer argument to be added
* @return The sum of x + y
*/
- var safeAdd_64_2 = function (x, y) {
- var lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
- var msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);
- var lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ safeAdd_64_2 = function (x, y)
+ {
+ var lsw, msw, lowOrder, highOrder;
+
+ lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
+ msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);
+ lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
lsw = (x.highOrder & 0xFFFF) + (y.highOrder & 0xFFFF) + (msw >>> 16);
msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16);
- var highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
return new Int_64(highOrder, lowOrder);
- };
+ },
/*
- * Add four 64-bit integers, wrapping at 2^64. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
+ * Add four 64-bit integers, wrapping at 2^64. This uses 16-bit operations
+ * internally to work around bugs in some JS interpreters.
*
* @private
* @param {Int_64} a The first 64-bit integer argument to be added
@@ -509,25 +520,28 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} d The fouth 64-bit integer argument to be added
* @return The sum of a + b + c + d
*/
- var safeAdd_64_4 = function (a, b, c, d) {
- var lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
+ safeAdd_64_4 = function (a, b, c, d)
+ {
+ var lsw, msw, lowOrder, highOrder;
+
+ lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
(c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF);
- var msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
+ msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
(c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16);
- var lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) +
(c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (msw >>> 16);
msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) +
(c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16);
- var highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
return new Int_64(highOrder, lowOrder);
- };
+ },
/*
- * Add five 64-bit integers, wrapping at 2^64. This uses 16-bit operations internally
- * to work around bugs in some JS interpreters.
+ * Add five 64-bit integers, wrapping at 2^64. This uses 16-bit operations
+ * internally to work around bugs in some JS interpreters.
*
* @private
* @param {Int_64} a The first 64-bit integer argument to be added
@@ -537,91 +551,107 @@ function jsSHA(srcString, inputFormat) {
* @param {Int_64} e The fouth 64-bit integer argument to be added
* @return The sum of a + b + c + d + e
*/
- var safeAdd_64_5 = function (a, b, c, d, e) {
- var lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
- (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) + (e.lowOrder & 0xFFFF);
- var msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
+ safeAdd_64_5 = function (a, b, c, d, e)
+ {
+ var lsw, msw, lowOrder, highOrder;
+
+ lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
+ (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) +
+ (e.lowOrder & 0xFFFF);
+ msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
(c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (e.lowOrder >>> 16) +
(lsw >>> 16);
- var lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) +
(c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) +
- (e.highOrder & 0xFFFF) + (msw >>> 16);
+ (e.highOrder & 0xFFFF) + (msw >>> 16);
msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) +
- (c.highOrder >>> 16) + (d.highOrder >>> 16) + (e.highOrder >>> 16) +
- (lsw >>> 16);
- var highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ (c.highOrder >>> 16) + (d.highOrder >>> 16) +
+ (e.highOrder >>> 16) + (lsw >>> 16);
+ highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
return new Int_64(highOrder, lowOrder);
- };
+ },
/*
* Calculates the SHA-1 hash of the string set at instantiation
*
* @private
- * @param {Array} message The binary array representation of the string to hash
+ * @param {Array} message The binary array representation of the string to
+ * hash
* @param {Number} messageLen The number of bits in the message
* @return The array of integers representing the SHA-1 hash of message
*/
- var coreSHA1 = function (message, messageLen) {
- var W = [];
- var a, b, c, d, e;
- var T;
- var ch = ch_32, parity = parity_32, maj = maj_32, rotl = rotl_32,
- safeAdd_2 = safeAdd_32_2, safeAdd_5 = safeAdd_32_5;
- var H = [
- 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
- ];
- var K = [
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6
- ];
-
- // Append '1' at the end of the binary string
- message[messageLen >> 5] |= 0x80 << (24 - messageLen % 32);
- // Append length of binary string in the position such that the new length is a multiple of 512
- message[((messageLen + 1 + 64 >> 9) << 4) + 15] = messageLen;
+ coreSHA1 = function (message, messageLen)
+ {
+ var W = [], a, b, c, d, e, T, ch = ch_32, parity = parity_32,
+ maj = maj_32, rotl = rotl_32, safeAdd_2 = safeAdd_32_2, i, t,
+ safeAdd_5 = safeAdd_32_5, appendedMessageLength,
+ H = [
+ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
+ ],
+ K = [
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6
+ ];
+
+ /* Append '1' at the end of the binary string */
+ message[messageLen >> 5] |= 0x80 << (24 - (messageLen % 32));
+ /* Append length of binary string in the position such that the new
+ length is a multiple of 512. Logic does not work for even multiples
+ of 512 but there can never be even multiples of 512 */
+ message[(((messageLen + 65) >> 9) << 4) + 15] = messageLen;
- var appendedMessageLength = message.length;
+ appendedMessageLength = message.length;
- for (var i = 0; i < appendedMessageLength; i += 16) {
+ for (i = 0; i < appendedMessageLength; i += 16)
+ {
a = H[0];
b = H[1];
c = H[2];
d = H[3];
e = H[4];
- for (var t = 0; t < 80; t++) {
- if (t < 16) {
+ for (t = 0; t < 80; t += 1)
+ {
+ if (t < 16)
+ {
W[t] = message[t + i];
- } else {
+ }
+ else
+ {
W[t] = rotl(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
}
- if (t < 20) {
+ if (t < 20)
+ {
T = safeAdd_5(rotl(a, 5), ch(b, c, d), e, K[t], W[t]);
- } else if (t < 40) {
+ }
+ else if (t < 40)
+ {
T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, K[t], W[t]);
- } else if (t < 60) {
+ }
+ else if (t < 60)
+ {
T = safeAdd_5(rotl(a, 5), maj(b, c, d), e, K[t], W[t]);
} else {
T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, K[t], W[t]);
@@ -642,7 +672,7 @@ function jsSHA(srcString, inputFormat) {
}
return H;
- };
+ },
/*
* Calculates the desired SHA-2 hash of the string set at instantiation
@@ -653,21 +683,20 @@ function jsSHA(srcString, inputFormat) {
* @param {String} variant The desired SHA-2 variant
* @return The array of integers representing the SHA-2 hash of message
*/
- var coreSHA2 = function (message, messageLen, variant) {
- var W = [];
- var a, b, c, d, e, f, g, h;
- var T1, T2;
- var H;
- var numRounds, lengthPosition, binaryStringInc, binaryStringMult;
- var safeAdd_2, safeAdd_4, safeAdd_5, gamma0, gamma1, sigma0, sigma1,
- ch, maj, Int;
- var K;
-
- // Set up the various function handles and variable for the specific variant
- if (variant === "SHA-224" || variant === "SHA-256") // 32-bit variant
+ coreSHA2 = function (message, messageLen, variant)
+ {
+ var a, b, c, d, e, f, g, h, T1, T2, H, numRounds, lengthPosition, i, t,
+ binaryStringInc, binaryStringMult, safeAdd_2, safeAdd_4, safeAdd_5,
+ gamma0, gamma1, sigma0, sigma1, ch, maj, Int, K, W = [],
+ appendedMessageLength;
+
+ /* Set up the various function handles and variable for the specific
+ * variant */
+ if (variant === "SHA-224" || variant === "SHA-256")
{
+ /* 32-bit variant */
numRounds = 64;
- lengthPosition = ((messageLen + 1 + 64 >> 9) << 4) + 15;
+ lengthPosition = (((messageLen + 65) >> 9) << 4) + 15;
binaryStringInc = 16;
binaryStringMult = 1;
Int = Number;
@@ -699,20 +728,26 @@ function jsSHA(srcString, inputFormat) {
0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
];
- if (variant === "SHA-224") {
+ if (variant === "SHA-224")
+ {
H = [
0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
];
- } else {
+ }
+ else
+ {
H = [
0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
];
}
- } else if (variant === "SHA-384" || variant === "SHA-512") {// 64-bit variant
+ }
+ else if (variant === "SHA-384" || variant === "SHA-512")
+ {
+ /* 64-bit variant */
numRounds = 80;
- lengthPosition = ((messageLen + 1 + 128 >> 10) << 5) + 31;
+ lengthPosition = (((messageLen + 128) >> 10) << 5) + 31;
binaryStringInc = 32;
binaryStringMult = 2;
Int = Int_64;
@@ -727,49 +762,78 @@ function jsSHA(srcString, inputFormat) {
ch = ch_64;
K = [
- new Int_64(0x428a2f98, 0xd728ae22), new Int_64(0x71374491, 0x23ef65cd), new Int_64(0xb5c0fbcf, 0xec4d3b2f), new Int_64(0xe9b5dba5, 0x8189dbbc),
- new Int_64(0x3956c25b, 0xf348b538), new Int_64(0x59f111f1, 0xb605d019), new Int_64(0x923f82a4, 0xaf194f9b), new Int_64(0xab1c5ed5, 0xda6d8118),
- new Int_64(0xd807aa98, 0xa3030242), new Int_64(0x12835b01, 0x45706fbe), new Int_64(0x243185be, 0x4ee4b28c), new Int_64(0x550c7dc3, 0xd5ffb4e2),
- new Int_64(0x72be5d74, 0xf27b896f), new Int_64(0x80deb1fe, 0x3b1696b1), new Int_64(0x9bdc06a7, 0x25c71235), new Int_64(0xc19bf174, 0xcf692694),
- new Int_64(0xe49b69c1, 0x9ef14ad2), new Int_64(0xefbe4786, 0x384f25e3), new Int_64(0x0fc19dc6, 0x8b8cd5b5), new Int_64(0x240ca1cc, 0x77ac9c65),
- new Int_64(0x2de92c6f, 0x592b0275), new Int_64(0x4a7484aa, 0x6ea6e483), new Int_64(0x5cb0a9dc, 0xbd41fbd4), new Int_64(0x76f988da, 0x831153b5),
- new Int_64(0x983e5152, 0xee66dfab), new Int_64(0xa831c66d, 0x2db43210), new Int_64(0xb00327c8, 0x98fb213f), new Int_64(0xbf597fc7, 0xbeef0ee4),
- new Int_64(0xc6e00bf3, 0x3da88fc2), new Int_64(0xd5a79147, 0x930aa725), new Int_64(0x06ca6351, 0xe003826f), new Int_64(0x14292967, 0x0a0e6e70),
- new Int_64(0x27b70a85, 0x46d22ffc), new Int_64(0x2e1b2138, 0x5c26c926), new Int_64(0x4d2c6dfc, 0x5ac42aed), new Int_64(0x53380d13, 0x9d95b3df),
- new Int_64(0x650a7354, 0x8baf63de), new Int_64(0x766a0abb, 0x3c77b2a8), new Int_64(0x81c2c92e, 0x47edaee6), new Int_64(0x92722c85, 0x1482353b),
- new Int_64(0xa2bfe8a1, 0x4cf10364), new Int_64(0xa81a664b, 0xbc423001), new Int_64(0xc24b8b70, 0xd0f89791), new Int_64(0xc76c51a3, 0x0654be30),
- new Int_64(0xd192e819, 0xd6ef5218), new Int_64(0xd6990624, 0x5565a910), new Int_64(0xf40e3585, 0x5771202a), new Int_64(0x106aa070, 0x32bbd1b8),
- new Int_64(0x19a4c116, 0xb8d2d0c8), new Int_64(0x1e376c08, 0x5141ab53), new Int_64(0x2748774c, 0xdf8eeb99), new Int_64(0x34b0bcb5, 0xe19b48a8),
- new Int_64(0x391c0cb3, 0xc5c95a63), new Int_64(0x4ed8aa4a, 0xe3418acb), new Int_64(0x5b9cca4f, 0x7763e373), new Int_64(0x682e6ff3, 0xd6b2b8a3),
- new Int_64(0x748f82ee, 0x5defb2fc), new Int_64(0x78a5636f, 0x43172f60), new Int_64(0x84c87814, 0xa1f0ab72), new Int_64(0x8cc70208, 0x1a6439ec),
- new Int_64(0x90befffa, 0x23631e28), new Int_64(0xa4506ceb, 0xde82bde9), new Int_64(0xbef9a3f7, 0xb2c67915), new Int_64(0xc67178f2, 0xe372532b),
- new Int_64(0xca273ece, 0xea26619c), new Int_64(0xd186b8c7, 0x21c0c207), new Int_64(0xeada7dd6, 0xcde0eb1e), new Int_64(0xf57d4f7f, 0xee6ed178),
- new Int_64(0x06f067aa, 0x72176fba), new Int_64(0x0a637dc5, 0xa2c898a6), new Int_64(0x113f9804, 0xbef90dae), new Int_64(0x1b710b35, 0x131c471b),
- new Int_64(0x28db77f5, 0x23047d84), new Int_64(0x32caab7b, 0x40c72493), new Int_64(0x3c9ebe0a, 0x15c9bebc), new Int_64(0x431d67c4, 0x9c100d4c),
- new Int_64(0x4cc5d4be, 0xcb3e42b6), new Int_64(0x597f299c, 0xfc657e2a), new Int_64(0x5fcb6fab, 0x3ad6faec), new Int_64(0x6c44198c, 0x4a475817)
- ];
+ new Int(0x428a2f98, 0xd728ae22), new Int(0x71374491, 0x23ef65cd),
+ new Int(0xb5c0fbcf, 0xec4d3b2f), new Int(0xe9b5dba5, 0x8189dbbc),
+ new Int(0x3956c25b, 0xf348b538), new Int(0x59f111f1, 0xb605d019),
+ new Int(0x923f82a4, 0xaf194f9b), new Int(0xab1c5ed5, 0xda6d8118),
+ new Int(0xd807aa98, 0xa3030242), new Int(0x12835b01, 0x45706fbe),
+ new Int(0x243185be, 0x4ee4b28c), new Int(0x550c7dc3, 0xd5ffb4e2),
+ new Int(0x72be5d74, 0xf27b896f), new Int(0x80deb1fe, 0x3b1696b1),
+ new Int(0x9bdc06a7, 0x25c71235), new Int(0xc19bf174, 0xcf692694),
+ new Int(0xe49b69c1, 0x9ef14ad2), new Int(0xefbe4786, 0x384f25e3),
+ new Int(0x0fc19dc6, 0x8b8cd5b5), new Int(0x240ca1cc, 0x77ac9c65),
+ new Int(0x2de92c6f, 0x592b0275), new Int(0x4a7484aa, 0x6ea6e483),
+ new Int(0x5cb0a9dc, 0xbd41fbd4), new Int(0x76f988da, 0x831153b5),
+ new Int(0x983e5152, 0xee66dfab), new Int(0xa831c66d, 0x2db43210),
+ new Int(0xb00327c8, 0x98fb213f), new Int(0xbf597fc7, 0xbeef0ee4),
+ new Int(0xc6e00bf3, 0x3da88fc2), new Int(0xd5a79147, 0x930aa725),
+ new Int(0x06ca6351, 0xe003826f), new Int(0x14292967, 0x0a0e6e70),
+ new Int(0x27b70a85, 0x46d22ffc), new Int(0x2e1b2138, 0x5c26c926),
+ new Int(0x4d2c6dfc, 0x5ac42aed), new Int(0x53380d13, 0x9d95b3df),
+ new Int(0x650a7354, 0x8baf63de), new Int(0x766a0abb, 0x3c77b2a8),
+ new Int(0x81c2c92e, 0x47edaee6), new Int(0x92722c85, 0x1482353b),
+ new Int(0xa2bfe8a1, 0x4cf10364), new Int(0xa81a664b, 0xbc423001),
+ new Int(0xc24b8b70, 0xd0f89791), new Int(0xc76c51a3, 0x0654be30),
+ new Int(0xd192e819, 0xd6ef5218), new Int(0xd6990624, 0x5565a910),
+ new Int(0xf40e3585, 0x5771202a), new Int(0x106aa070, 0x32bbd1b8),
+ new Int(0x19a4c116, 0xb8d2d0c8), new Int(0x1e376c08, 0x5141ab53),
+ new Int(0x2748774c, 0xdf8eeb99), new Int(0x34b0bcb5, 0xe19b48a8),
+ new Int(0x391c0cb3, 0xc5c95a63), new Int(0x4ed8aa4a, 0xe3418acb),
+ new Int(0x5b9cca4f, 0x7763e373), new Int(0x682e6ff3, 0xd6b2b8a3),
+ new Int(0x748f82ee, 0x5defb2fc), new Int(0x78a5636f, 0x43172f60),
+ new Int(0x84c87814, 0xa1f0ab72), new Int(0x8cc70208, 0x1a6439ec),
+ new Int(0x90befffa, 0x23631e28), new Int(0xa4506ceb, 0xde82bde9),
+ new Int(0xbef9a3f7, 0xb2c67915), new Int(0xc67178f2, 0xe372532b),
+ new Int(0xca273ece, 0xea26619c), new Int(0xd186b8c7, 0x21c0c207),
+ new Int(0xeada7dd6, 0xcde0eb1e), new Int(0xf57d4f7f, 0xee6ed178),
+ new Int(0x06f067aa, 0x72176fba), new Int(0x0a637dc5, 0xa2c898a6),
+ new Int(0x113f9804, 0xbef90dae), new Int(0x1b710b35, 0x131c471b),
+ new Int(0x28db77f5, 0x23047d84), new Int(0x32caab7b, 0x40c72493),
+ new Int(0x3c9ebe0a, 0x15c9bebc), new Int(0x431d67c4, 0x9c100d4c),
+ new Int(0x4cc5d4be, 0xcb3e42b6), new Int(0x597f299c, 0xfc657e2a),
+ new Int(0x5fcb6fab, 0x3ad6faec), new Int(0x6c44198c, 0x4a475817)
+ ];
- if (variant === "SHA-384") {
+ if (variant === "SHA-384")
+ {
H = [
- new Int_64(0xcbbb9d5d, 0xc1059ed8), new Int_64(0x0629a292a, 0x367cd507), new Int_64(0x9159015a, 0x3070dd17), new Int_64(0x152fecd8, 0xf70e5939),
- new Int_64(0x67332667, 0xffc00b31), new Int_64(0x98eb44a87, 0x68581511), new Int_64(0xdb0c2e0d, 0x64f98fa7), new Int_64(0x47b5481d, 0xbefa4fa4)
- ];
- } else {
+ new Int(0xcbbb9d5d, 0xc1059ed8), new Int(0x0629a292a, 0x367cd507),
+ new Int(0x9159015a, 0x3070dd17), new Int(0x0152fecd8, 0xf70e5939),
+ new Int(0x67332667, 0xffc00b31), new Int(0x98eb44a87, 0x68581511),
+ new Int(0xdb0c2e0d, 0x64f98fa7), new Int(0x047b5481d, 0xbefa4fa4)
+ ];
+ }
+ else
+ {
H = [
- new Int_64(0x6a09e667, 0xf3bcc908), new Int_64(0xbb67ae85, 0x84caa73b), new Int_64(0x3c6ef372, 0xfe94f82b), new Int_64(0xa54ff53a, 0x5f1d36f1),
- new Int_64(0x510e527f, 0xade682d1), new Int_64(0x9b05688c, 0x2b3e6c1f), new Int_64(0x1f83d9ab, 0xfb41bd6b), new Int_64(0x5be0cd19, 0x137e2179)
- ];
+ new Int(0x6a09e667, 0xf3bcc908), new Int(0xbb67ae85, 0x84caa73b),
+ new Int(0x3c6ef372, 0xfe94f82b), new Int(0xa54ff53a, 0x5f1d36f1),
+ new Int(0x510e527f, 0xade682d1), new Int(0x9b05688c, 0x2b3e6c1f),
+ new Int(0x1f83d9ab, 0xfb41bd6b), new Int(0x5be0cd19, 0x137e2179)
+ ];
}
}
- // Append '1' at the end of the binary string
+ /* Append '1' at the end of the binary string */
message[messageLen >> 5] |= 0x80 << (24 - messageLen % 32);
- // Append length of binary string in the position such that the new length is correct
+ /* Append length of binary string in the position such that the new
+ * length is correct */
message[lengthPosition] = messageLen;
- var appendedMessageLength = message.length;
+ appendedMessageLength = message.length;
- for (var i = 0; i < appendedMessageLength; i += binaryStringInc) {
+ for (i = 0; i < appendedMessageLength; i += binaryStringInc)
+ {
a = H[0];
b = H[1];
c = H[2];
@@ -779,12 +843,20 @@ function jsSHA(srcString, inputFormat) {
g = H[6];
h = H[7];
- for (var t = 0; t < numRounds; t++) {
- if (t < 16) {
- // Bit of a hack - for 32-bit, the second term is ignored
- W[t] = new Int(message[t * binaryStringMult + i], message[t * binaryStringMult + i + 1]);
- } else {
- W[t] = safeAdd_4(gamma1(W[t - 2]), W[t - 7], gamma0(W[t - 15]), W[t - 16]);
+ for (t = 0; t < numRounds; t += 1)
+ {
+ if (t < 16)
+ {
+ /* Bit of a hack - for 32-bit, the second term is ignored */
+ W[t] = new Int(message[t * binaryStringMult + i],
+ message[t * binaryStringMult + i + 1]);
+ }
+ else
+ {
+ W[t] = safeAdd_4(
+ gamma1(W[t - 2]), W[t - 7],
+ gamma0(W[t - 15]), W[t - 16]
+ );
}
T1 = safeAdd_5(h, sigma1(e), ch(e, f, g), K[t], W[t]);
@@ -809,16 +881,17 @@ function jsSHA(srcString, inputFormat) {
H[7] = safeAdd_2(h, H[7]);
}
- switch (variant) {
+ switch (variant)
+ {
case "SHA-224":
return [
- H[0], H[1], H[2], H[3],
- H[4], H[5], H[6]
+ H[0], H[1], H[2], H[3],
+ H[4], H[5], H[6]
];
case "SHA-256":
return H;
case "SHA-384":
- return [
+ return [
H[0].highOrder, H[0].lowOrder,
H[1].highOrder, H[1].lowOrder,
H[2].highOrder, H[2].lowOrder,
@@ -827,7 +900,7 @@ function jsSHA(srcString, inputFormat) {
H[5].highOrder, H[5].lowOrder
];
case "SHA-512":
- return [
+ return [
H[0].highOrder, H[0].lowOrder,
H[1].highOrder, H[1].lowOrder,
H[2].highOrder, H[2].lowOrder,
@@ -838,175 +911,255 @@ function jsSHA(srcString, inputFormat) {
H[7].highOrder, H[7].lowOrder
];
default:
- return []; // This should near be reached
+ /* This should never be reached */
+ return [];
}
- };
+ },
/*
- * Returns the desired SHA hash of the string specified at instantiation
- * using the specified parameters
+ * jsSHA is the workhorse of the library. Instantiate it with the string to
+ * be hashed as the parameter
*
- * @param {String} variant The desired SHA variant (SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512)
- * @param {String} format The desired output formatting (B64 or HEX)
- * @return The string representation of the hash in the format specified
+ * @constructor
+ * @param {String} srcString The string to be hashed
+ * @param {String} inputFormat The format of srcString, ASCII or HEX
*/
- this.getHash = function (variant, format) {
- var formatFunc = null;
- var message = strToHash.slice();
+ jsSHA = function (srcString, inputFormat)
+ {
- switch (format) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
- }
+ this.sha1 = null;
+ this.sha224 = null;
+ this.sha256 = null;
+ this.sha384 = null;
+ this.sha512 = null;
- switch (variant) {
- case "SHA-1":
- if (sha1 === null) {
- sha1 = coreSHA1(message, strBinLen);
+ this.strBinLen = null;
+ this.strToHash = null;
+
+ /* Convert the input string into the correct type */
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (srcString.length % 2))
+ {
+ return "TEXT MUST BE IN BYTE INCREMENTS";
}
- return formatFunc(sha1);
- case "SHA-224":
- if (sha224 === null) {
- sha224 = coreSHA2(message, strBinLen, variant);
+ this.strBinLen = srcString.length * 4;
+ this.strToHash = hex2binb(srcString);
+ }
+ else if (("ASCII" === inputFormat) ||
+ ('undefined' === typeof(inputFormat)))
+ {
+ this.strBinLen = srcString.length * charSize;
+ this.strToHash = str2binb(srcString);
+ }
+ else
+ {
+ return "UNKNOWN TEXT INPUT TYPE";
+ }
+ };
+
+ jsSHA.prototype = {
+ /*
+ * Returns the desired SHA hash of the string specified at instantiation
+ * using the specified parameters
+ *
+ * @param {String} variant The desired SHA variant (SHA-1, SHA-224,
+ * SHA-256, SHA-384, or SHA-512)
+ * @param {String} format The desired output formatting (B64 or HEX)
+ * @return The string representation of the hash in the format specified
+ */
+ getHash : function (variant, format)
+ {
+ var formatFunc = null, message = this.strToHash.slice();
+
+ switch (format)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
}
- return formatFunc(sha224);
- case "SHA-256":
- if (sha256 === null) {
- sha256 = coreSHA2(message, strBinLen, variant);
+
+ switch (variant)
+ {
+ case "SHA-1":
+ if (null === this.sha1)
+ {
+ this.sha1 = coreSHA1(message, this.strBinLen);
+ }
+ return formatFunc(this.sha1);
+ case "SHA-224":
+ if (null === this.sha224)
+ {
+ this.sha224 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha224);
+ case "SHA-256":
+ if (null === this.sha256)
+ {
+ this.sha256 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha256);
+ case "SHA-384":
+ if (null === this.sha384)
+ {
+ this.sha384 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha384);
+ case "SHA-512":
+ if (null === this.sha512)
+ {
+ this.sha512 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha512);
+ default:
+ return "HASH NOT RECOGNIZED";
}
- return formatFunc(sha256);
- case "SHA-384":
- if (sha384 === null) {
- sha384 = coreSHA2(message, strBinLen, variant);
+ },
+
+ /*
+ * Returns the desired HMAC of the string specified at instantiation
+ * using the key and variant param.
+ *
+ * @param {String} key The key used to calculate the HMAC
+ * @param {String} inputFormat The format of key, ASCII or HEX
+ * @param {String} variant The desired SHA variant (SHA-1, SHA-224,
+ * SHA-256, SHA-384, or SHA-512)
+ * @param {String} outputFormat The desired output formatting
+ * (B64 or HEX)
+ * @return The string representation of the hash in the format specified
+ */
+ getHMAC : function (key, inputFormat, variant, outputFormat)
+ {
+ var formatFunc, keyToUse, blockByteSize, blockBitSize, i,
+ retVal, lastArrayIndex, keyBinLen, hashBitSize,
+ keyWithIPad = [], keyWithOPad = [];
+
+ /* Validate the output format selection */
+ switch (outputFormat)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
}
- return formatFunc(sha384);
- case "SHA-512":
- if (sha512 === null) {
- sha512 = coreSHA2(message, strBinLen, variant);
+
+ /* Validate the hash variant selection and set needed variables */
+ switch (variant)
+ {
+ case "SHA-1":
+ blockByteSize = 64;
+ hashBitSize = 160;
+ break;
+ case "SHA-224":
+ blockByteSize = 64;
+ hashBitSize = 224;
+ break;
+ case "SHA-256":
+ blockByteSize = 64;
+ hashBitSize = 256;
+ break;
+ case "SHA-384":
+ blockByteSize = 128;
+ hashBitSize = 384;
+ break;
+ case "SHA-512":
+ blockByteSize = 128;
+ hashBitSize = 512;
+ break;
+ default:
+ return "HASH NOT RECOGNIZED";
}
- return formatFunc(sha512);
- default:
- return "HASH NOT RECOGNIZED";
- }
- };
- /*
- * Returns the desired HMAC of the string specified at instantiation using
- * the key and variant param.
- *
- * @param {String} key The key used to calculate the HMAC
- * @param {String} inputFormat The format of key, ASCII or HEX
- * @param {String} variant The desired SHA variant (SHA-1, SHA-224, SHA-256, SHA-384, or SHA-512)
- * @param {String} outputFormat The desired output formatting (B64 or HEX)
- * @return The string representation of the hash in the format specified
- */
- this.getHMAC = function (key, inputFormat, variant, outputFormat) {
- var formatFunc = null;
- var keyToUse = null;
- var blockByteSize = null;
- var blockBitSize = null;
- var keyWithIPad = [];
- var keyWithOPad = [];
- var lastArrayIndex = null;
- var retVal = null;
- var keyBinLen = null;
- var hashBitSize = null;
-
- // Validate the output format selection
- switch (outputFormat) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
- }
+ /* Validate input format selection */
+ if ("HEX" === inputFormat)
+ {
+ /* Nibbles must come in pairs */
+ if (0 !== (key.length % 2))
+ {
+ return "KEY MUST BE IN BYTE INCREMENTS";
+ }
+ keyToUse = hex2binb(key);
+ keyBinLen = key.length * 4;
+ }
+ else if ("ASCII" === inputFormat)
+ {
+ keyToUse = str2binb(key);
+ keyBinLen = key.length * charSize;
+ }
+ else
+ {
+ return "UNKNOWN KEY INPUT TYPE";
+ }
- // Validate the hash variant selection and set needed variables
- switch (variant) {
- case "SHA-1":
- blockByteSize = 64;
- hashBitSize = 160;
- break;
- case "SHA-224":
- blockByteSize = 64;
- hashBitSize = 224;
- break;
- case "SHA-256":
- blockByteSize = 64;
- hashBitSize = 256;
- break;
- case "SHA-384":
- blockByteSize = 128;
- hashBitSize = 384;
- break;
- case "SHA-512":
- blockByteSize = 128;
- hashBitSize = 512;
- break;
- default:
- return "HASH NOT RECOGNIZED";
- }
+ /* These are used multiple times, calculate and store them */
+ blockBitSize = blockByteSize * 8;
+ lastArrayIndex = (blockByteSize / 4) - 1;
+
+ /* Figure out what to do with the key based on its size relative to
+ * the hash's block size */
+ if (blockByteSize < (keyBinLen / 8))
+ {
+ if ("SHA-1" === variant)
+ {
+ keyToUse = coreSHA1(keyToUse, keyBinLen);
+ }
+ else
+ {
+ keyToUse = coreSHA2(keyToUse, keyBinLen, variant);
+ }
+ /* For all variants, the block size is bigger than the output
+ * size so there will never be a useful byte at the end of the
+ * string */
+ keyToUse[lastArrayIndex] &= 0xFFFFFF00;
+ }
+ else if (blockByteSize > (keyBinLen / 8))
+ {
+ /* If the blockByteSize is greater than the key length, there
+ * will always be at LEAST one "useless" byte at the end of the
+ * string */
+ keyToUse[lastArrayIndex] &= 0xFFFFFF00;
+ }
- // Validate input format selection
- if ("HEX" === inputFormat) {
- // Nibbles must come in pairs
- if (0 !== (key.length % 2)) {
- return "KEY MUST BE IN BYTE INCREMENTS";
+ /* Create ipad and opad */
+ for (i = 0; i <= lastArrayIndex; i += 1)
+ {
+ keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
+ keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
}
- keyToUse = hex2binb(key);
- keyBinLen = key.length * 4;
- } else if ("ASCII" === inputFormat) {
- keyToUse = str2binb(key);
- keyBinLen = key.length * jsSHA.charSize;
- } else {
- return "UNKNOWN KEY INPUT TYPE";
- }
- // These are used multiple times, calculate and store them
- blockBitSize = blockByteSize * 8;
- lastArrayIndex = (blockByteSize / 4) - 1;
-
- // Figure out what to do with the key based on its size relative to
- // the hash's block size
- if (blockByteSize < (keyBinLen / 8)) {
- if ("SHA-1" === variant) {
- keyToUse = coreSHA1(keyToUse, keyBinLen);
- } else {
- keyToUse = coreSHA2(keyToUse, keyBinLen, variant);
+ /* Calculate the HMAC */
+ if ("SHA-1" === variant)
+ {
+ retVal = coreSHA1(
+ keyWithIPad.concat(this.strToHash),
+ blockBitSize + this.strBinLen);
+ retVal = coreSHA1(
+ keyWithOPad.concat(retVal),
+ blockBitSize + hashBitSize);
+ }
+ else
+ {
+ retVal = coreSHA2(
+ keyWithIPad.concat(this.strToHash),
+ blockBitSize + this.strBinLen, variant);
+ retVal = coreSHA2(
+ keyWithOPad.concat(retVal),
+ blockBitSize + hashBitSize, variant);
}
- // For all variants, the block size is bigger than the output size
- // so there will never be a useful byte at the end of the string
- keyToUse[lastArrayIndex] &= 0xFFFFFF00;
- } else if (blockByteSize > (keyBinLen / 8)) {
- // If the blockByteSize is greater than the key length, there will
- // always be at LEAST one "useless" byte at the end of the string
- keyToUse[lastArrayIndex] &= 0xFFFFFF00;
- }
- // Create ipad and opad
- for (var i = 0; i <= lastArrayIndex; i++) {
- keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
- keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
+ return (formatFunc(retVal));
}
+ };
- // Calculate the HMAC
- if ("SHA-1" === variant) {
- retVal = coreSHA1(keyWithIPad.concat(strToHash), blockBitSize + strBinLen);
- retVal = coreSHA1(keyWithOPad.concat(retVal), blockBitSize + hashBitSize);
- } else {
- retVal = coreSHA2(keyWithIPad.concat(strToHash), blockBitSize + strBinLen, variant);
- retVal = coreSHA2(keyWithOPad.concat(retVal), blockBitSize + hashBitSize, variant);
- }
+ window.jsSHA = jsSHA;
+}());
- return (formatFunc(retVal));
- };
-}
diff --git a/src/sha1.js b/src/sha1.js
index 863918c..245276f 100644
--- a/src/sha1.js
+++ b/src/sha1.js
@@ -1,10 +1,12 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
+(function(){var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotl=function(x,n){return(x<<n)|(x>>>(32-n))},parity=function(x,y,z){return x^y^z},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA1=function(f,g){var W=[],a,b,c,d,e,T,i,t,appendedMessageLength,H=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0],K=[0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6];f[g>>5]|=0x80<<(24-(g%32));f[(((g+65)>>9)<<4)+15]=g;appendedMessageLength=f.length;for(i=0;i<appendedMessageLength;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];for(t=0;t<80;t+=1){if(t<16){W[t]=f[t+i]}else{W[t]=rotl(W[t-3]^W[t-8]^W[t-14]^W[t-16],1)}if(t<20){T=safeAdd_5(rotl(a,5),ch(b,c,d),e,K[t],W[t])}else if(t<40){T=safeAdd_5(rotl(a,5),parity(b,c,d),e,K[t],W[t])}else if(t<60){T=safeAdd_5(rotl(a,5),maj(b,c,d),e,K[t],W[t])}else{T=safeAdd_5(rotl(a,5),parity(b,c,d),e,K[t],W[t])}e=d;d=c;c=rotl(b,30);b=a;a=T}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4])}return H},jsSHA=function(a,b){this.sha1=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a){var b=null,message=this.strToHash.slice();switch(a){case"HEX":b=binb2hex;break;case"B64":b=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}if(null===this.sha1){this.sha1=coreSHA1(message,this.strBinLen)}return b(this.sha1)},getHMAC:function(a,b,c){var d,keyToUse,i,retVal,keyBinLen,keyWithIPad=[],keyWithOPad=[];switch(c){case"HEX":d=binb2hex;break;case"B64":d=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(64<(keyBinLen/8)){keyToUse=coreSHA1(keyToUse,keyBinLen);keyToUse[15]&=0xFFFFFF00}else if(64>(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA1(keyWithIPad.concat(this.strToHash),512+this.strBinLen);retVal=coreSHA1(keyWithOPad.concat(retVal),672);return(d(retVal))}};window.jsSHA=jsSHA}());
-function jsSHA(k,l){jsSHA.charSize=8;jsSHA.b64pad="";jsSHA.hexCase=0;var m=null;var o=function(a){var b=[];var c=(1<<jsSHA.charSize)-1;var d=a.length*jsSHA.charSize;for(var i=0;i<d;i+=jsSHA.charSize){b[i>>5]|=(a.charCodeAt(i/jsSHA.charSize)&c)<<(32-jsSHA.charSize-i%32)}return b};var p=function(a){var b=[];var c=a.length;for(var i=0;i<c;i+=2){var d=parseInt(a.substr(i,2),16);if(!isNaN(d)){b[i>>3]|=d<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b};var q=null;var r=null;if("HEX"===l){if(0!==(k.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}q=k.length*4;r=p(k)}else if(("ASCII"===l)||('undefined'===typeof(l))){q=k.length*jsSHA.charSize;r=o(k)}else{return"UNKNOWN TEXT INPUT TYPE"}var s=function(a){var b=jsSHA.hexCase?"0123456789ABCDEF":"0123456789abcdef";var c="";var d=a.length*4;for(var i=0;i<d;i++){c+=b.charAt((a[i>>2]>>((3-i%4)*8+4))&0xF)+b.charAt((a[i>>2]>>((3-i%4)*8))&0xF)}return c};var u=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var c="";var d=a.length*4;for(var i=0;i<d;i+=3){var e=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(var j=0;j<4;j++){if(i*8+j*6>a.length*32){c+=jsSHA.b64pad}else{c+=b.charAt((e>>6*(3-j))&0x3F)}}}return c};var v=function(x,n){if(n<32){return(x<<n)|(x>>>(32-n))}else{return x}};var w=function(x,y,z){return x^y^z};var A=function(x,y,z){return(x&y)^(~x&z)};var B=function(x,y,z){return(x&y)^(x&z)^(y&z)};var C=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF);var b=(x>>>16)+(y>>>16)+(a>>>16);return((b&0xFFFF)<<16)|(a&0xFFFF)};var D=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);var g=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((g&0xFFFF)<<16)|(f&0xFFFF)};var E=function(f,g){var W=[];var a,b,c,d,e;var T;var H=[0x67452301,0xefcdab89,0x98badcfe,0x10325476,0xc3d2e1f0];var K=[0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x5a827999,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6];f[g>>5]|=0x80<<(24-g%32);f[((g+1+64>>9)<<4)+15]=g;var h=f.length;for(var i=0;i<h;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];for(var t=0;t<80;t++){if(t<16){W[t]=f[t+i]}else{W[t]=v(W[t-3]^W[t-8]^W[t-14]^W[t-16],1)}if(t<20){T=D(v(a,5),A(b,c,d),e,K[t],W[t])}else if(t<40){T=D(v(a,5),w(b,c,d),e,K[t],W[t])}else if(t<60){T=D(v(a,5),B(b,c,d),e,K[t],W[t])}else{T=D(v(a,5),w(b,c,d),e,K[t],W[t])}e=d;d=c;c=v(b,30);b=a;a=T}H[0]=C(a,H[0]);H[1]=C(b,H[1]);H[2]=C(c,H[2]);H[3]=C(d,H[3]);H[4]=C(e,H[4])}return H};this.getHash=function(a){var b=null;var c=r.slice();if(m===null){m=m=E(c,q)}switch(a){case"HEX":b=s;break;case"B64":b=u;break;default:return"FORMAT NOT RECOGNIZED"}return b(m)};this.getHMAC=function(a,b,c){var d=null;var e=null;var f=[];var g=[];var h=null;var j=null;switch(c){case"HEX":d=s;break;case"B64":d=u;break;default:return"FORMAT NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}e=p(a);j=a.length*4}else if("ASCII"===b){e=o(a);j=a.length*jsSHA.charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(512<j){e=E(e,j);e[15]&=0xFFFFFF00}else if(512>j){e[15]&=0xFFFFFF00}for(var i=0;i<=15;i++){f[i]=e[i]^0x36363636;g[i]=e[i]^0x5C5C5C5C}h=E(f.concat(r),512+q);h=E(g.concat(h),672);return(d(h))}}
diff --git a/src/sha1_nice.js b/src/sha1_nice.js
index aa03dfe..9ea56fe 100644
--- a/src/sha1_nice.js
+++ b/src/sha1_nice.js
@@ -1,184 +1,195 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
-
-function jsSHA(srcString, inputFormat) {
-
- jsSHA.charSize = 8;
- jsSHA.b64pad = "";
- jsSHA.hexCase = 0;
-
- var sha1 = null;
-
- var str2binb = function (str) {
- var bin = [];
- var mask = (1 << jsSHA.charSize) - 1;
- var length = str.length * jsSHA.charSize;
-
- for (var i = 0; i < length; i += jsSHA.charSize) {
- bin[i >> 5] |= (str.charCodeAt(i / jsSHA.charSize) & mask) << (32 - jsSHA.charSize - i % 32);
+(function ()
+{
+ var charSize = 8,
+ b64pad = "",
+ hexCase = 0,
+
+ str2binb = function (str)
+ {
+ var bin = [], mask = (1 << charSize) - 1,
+ length = str.length * charSize, i;
+
+ for (i = 0; i < length; i += charSize)
+ {
+ bin[i >> 5] |= (str.charCodeAt(i / charSize) & mask) <<
+ (32 - charSize - (i % 32));
}
return bin;
- };
-
- var hex2binb = function (str) {
- var bin = [];
- var length = str.length;
-
- for (var i = 0; i < length; i += 2) {
- var num = parseInt(str.substr(i, 2), 16);
- if (!isNaN(num)) {
+ },
+
+ hex2binb = function (str)
+ {
+ var bin = [], length = str.length, i, num;
+
+ for (i = 0; i < length; i += 2)
+ {
+ num = parseInt(str.substr(i, 2), 16);
+ if (!isNaN(num))
+ {
bin[i >> 3] |= num << (24 - (4 * (i % 8)));
- } else {
+ }
+ else
+ {
return "INVALID HEX STRING";
}
}
return bin;
- };
+ },
- var strBinLen = null;
- var strToHash = null;
+ binb2hex = function (binarray)
+ {
+ var hex_tab = (hexCase) ? "0123456789ABCDEF" : "0123456789abcdef",
+ str = "", length = binarray.length * 4, i, srcByte;
- if ("HEX" === inputFormat) {
- if (0 !== (srcString.length % 2)) {
- return "TEXT MUST BE IN BYTE INCREMENTS";
- }
- strBinLen = srcString.length * 4;
- strToHash = hex2binb(srcString);
- } else if (("ASCII" === inputFormat) ||
- ('undefined' === typeof(inputFormat))) {
- strBinLen = srcString.length * jsSHA.charSize;
- strToHash = str2binb(srcString);
- } else {
- return "UNKNOWN TEXT INPUT TYPE";
- }
-
- var binb2hex = function (binarray) {
- var hex_tab = jsSHA.hexCase ? "0123456789ABCDEF" : "0123456789abcdef";
- var str = "";
- var length = binarray.length * 4;
-
- for (var i = 0; i < length; i++) {
- str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
+ for (i = 0; i < length; i += 1)
+ {
+ srcByte = binarray[i >> 2] >> ((3 - (i % 4)) * 8);
+ str += hex_tab.charAt((srcByte >> 4) & 0xF) +
+ hex_tab.charAt(srcByte & 0xF);
}
return str;
- };
+ },
+
+ binb2b64 = function (binarray)
+ {
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
+ "0123456789+/", str = "", length = binarray.length * 4, i, j,
+ triplet;
- var binb2b64 = function (binarray) {
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var str = "";
- var length = binarray.length * 4;
- for (var i = 0; i < length; i += 3)
+ for (i = 0; i < length; i += 3)
{
- var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
- for (var j = 0; j < 4; j++) {
- if (i * 8 + j * 6 > binarray.length * 32) {
- str += jsSHA.b64pad;
- } else {
+ triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) |
+ (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
+ ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
+ for (j = 0; j < 4; j += 1)
+ {
+ if (i * 8 + j * 6 <= binarray.length * 32)
+ {
str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
}
+ else
+ {
+ str += b64pad;
+ }
}
}
return str;
- };
+ },
- var rotl = function (x, n) {
- if (n < 32) {
- return (x << n) | (x >>> (32 - n));
- } else {
- return x;
- }
- };
+ rotl = function (x, n)
+ {
+ return (x << n) | (x >>> (32 - n));
+ },
- var parity = function (x, y, z) {
+ parity = function (x, y, z)
+ {
return x ^ y ^ z;
- };
+ },
- var ch = function (x, y, z) {
+ ch = function (x, y, z)
+ {
return (x & y) ^ (~x & z);
- };
+ },
- var maj = function (x, y, z) {
+ maj = function (x, y, z)
+ {
return (x & y) ^ (x & z) ^ (y & z);
- };
+ },
- var safeAdd_2 = function (x, y) {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16);
+ safeAdd_2 = function (x, y)
+ {
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF),
+ msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
-
- var safeAdd_5 = function (a, b, c, d, e) {
+ },
+
+ safeAdd_5 = function (a, b, c, d, e)
+ {
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) +
- (e & 0xFFFF);
- var msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
- (e >>> 16) + (lsw >>> 16);
+ (e & 0xFFFF),
+ msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
+ (e >>> 16) + (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
-
- var coreSHA1 = function (message, messageLen) {
- var W = [];
- var a, b, c, d, e;
- var T;
- var H = [
- 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
- ];
- var K = [
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
- 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6
- ];
-
- message[messageLen >> 5] |= 0x80 << (24 - messageLen % 32);
- message[((messageLen + 1 + 64 >> 9) << 4) + 15] = messageLen;
- var appendedMessageLength = message.length;
-
- for (var i = 0; i < appendedMessageLength; i += 16) {
+ },
+
+ coreSHA1 = function (message, messageLen)
+ {
+ var W = [], a, b, c, d, e, T, i, t, appendedMessageLength,
+ H = [
+ 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
+ ],
+ K = [
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x5a827999, 0x5a827999, 0x5a827999, 0x5a827999,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1, 0x6ed9eba1,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc, 0x8f1bbcdc,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6,
+ 0xca62c1d6, 0xca62c1d6, 0xca62c1d6, 0xca62c1d6
+ ];
+
+ message[messageLen >> 5] |= 0x80 << (24 - (messageLen % 32));
+ message[(((messageLen + 65) >> 9) << 4) + 15] = messageLen;
+
+ appendedMessageLength = message.length;
+
+ for (i = 0; i < appendedMessageLength; i += 16)
+ {
a = H[0];
b = H[1];
c = H[2];
d = H[3];
e = H[4];
- for (var t = 0; t < 80; t++) {
- if (t < 16) {
+ for (t = 0; t < 80; t += 1)
+ {
+ if (t < 16)
+ {
W[t] = message[t + i];
- } else {
+ }
+ else
+ {
W[t] = rotl(W[t - 3] ^ W[t - 8] ^ W[t - 14] ^ W[t - 16], 1);
}
- if (t < 20) {
+ if (t < 20)
+ {
T = safeAdd_5(rotl(a, 5), ch(b, c, d), e, K[t], W[t]);
- } else if (t < 40) {
+ }
+ else if (t < 40)
+ {
T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, K[t], W[t]);
- } else if (t < 60) {
+ }
+ else if (t < 60)
+ {
T = safeAdd_5(rotl(a, 5), maj(b, c, d), e, K[t], W[t]);
} else {
T = safeAdd_5(rotl(a, 5), parity(b, c, d), e, K[t], W[t]);
@@ -199,77 +210,122 @@ function jsSHA(srcString, inputFormat) {
}
return H;
- };
+ },
- this.getHash = function (format) {
- var formatFunc = null;
- var message = strToHash.slice();
+ jsSHA = function (srcString, inputFormat)
+ {
- if (sha1 === null) {
- sha1 = sha1 = coreSHA1(message, strBinLen);
- }
+ this.sha1 = null;
- switch (format) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
- }
+ this.strBinLen = null;
+ this.strToHash = null;
- return formatFunc(sha1);
- };
-
- this.getHMAC = function (key, inputFormat, outputFormat) {
- var formatFunc = null;
- var keyToUse = null;
- var keyWithIPad = [];
- var keyWithOPad = [];
- var retVal = null;
- var keyBinLen = null;
-
- switch (outputFormat) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (srcString.length % 2))
+ {
+ return "TEXT MUST BE IN BYTE INCREMENTS";
+ }
+ this.strBinLen = srcString.length * 4;
+ this.strToHash = hex2binb(srcString);
+ }
+ else if (("ASCII" === inputFormat) ||
+ ('undefined' === typeof(inputFormat)))
+ {
+ this.strBinLen = srcString.length * charSize;
+ this.strToHash = str2binb(srcString);
+ }
+ else
+ {
+ return "UNKNOWN TEXT INPUT TYPE";
}
+ };
- if ("HEX" === inputFormat) {
- if (0 !== (key.length % 2)) {
- return "KEY MUST BE IN BYTE INCREMENTS";
+ jsSHA.prototype = {
+ getHash : function (format)
+ {
+ var formatFunc = null, message = this.strToHash.slice();
+
+ switch (format)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
}
- keyToUse = hex2binb(key);
- keyBinLen = key.length * 4;
- } else if ("ASCII" === inputFormat) {
- keyToUse = str2binb(key);
- keyBinLen = key.length * jsSHA.charSize;
- } else {
- return "UNKNOWN KEY INPUT TYPE";
- }
- if (512 < keyBinLen) {
- keyToUse = coreSHA1(keyToUse, keyBinLen);
- keyToUse[15] &= 0xFFFFFF00;
- } else if (512 > keyBinLen) {
- keyToUse[15] &= 0xFFFFFF00;
- }
+ if (null === this.sha1)
+ {
+ this.sha1 = coreSHA1(message, this.strBinLen);
+ }
+ return formatFunc(this.sha1);
+ },
- for (var i = 0; i <= 15; i++) {
- keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
- keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
- }
+ getHMAC : function (key, inputFormat, outputFormat)
+ {
+ var formatFunc, keyToUse, i, retVal, keyBinLen,
+ keyWithIPad = [], keyWithOPad = [];
+
+ switch (outputFormat)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
+ }
+
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (key.length % 2))
+ {
+ return "KEY MUST BE IN BYTE INCREMENTS";
+ }
+ keyToUse = hex2binb(key);
+ keyBinLen = key.length * 4;
+ }
+ else if ("ASCII" === inputFormat)
+ {
+ keyToUse = str2binb(key);
+ keyBinLen = key.length * charSize;
+ }
+ else
+ {
+ return "UNKNOWN KEY INPUT TYPE";
+ }
- retVal = coreSHA1(keyWithIPad.concat(strToHash), 512 + strBinLen);
- retVal = coreSHA1(keyWithOPad.concat(retVal), 672);
+ if (64 < (keyBinLen / 8))
+ {
+ keyToUse = coreSHA1(keyToUse, keyBinLen);
+ keyToUse[15] &= 0xFFFFFF00;
+ }
+ else if (64 > (keyBinLen / 8))
+ {
+ keyToUse[15] &= 0xFFFFFF00;
+ }
+
+ for (i = 0; i <= 15; i += 1)
+ {
+ keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
+ keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
+ }
- return (formatFunc(retVal));
+ retVal = coreSHA1(
+ keyWithIPad.concat(this.strToHash),
+ 512 + this.strBinLen);
+ retVal = coreSHA1(keyWithOPad.concat(retVal), 672);
+
+ return (formatFunc(retVal));
+ }
};
-}
+
+ window.jsSHA = jsSHA;
+}());
+
diff --git a/src/sha256.js b/src/sha256.js
index 3f0d25f..eda73ca 100644
--- a/src/sha256.js
+++ b/src/sha256.js
@@ -1,10 +1,12 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
-
-function jsSHA(o,p){jsSHA.charSize=8;jsSHA.b64pad="";jsSHA.hexCase=0;var q=null;var r=null;var s=function(a){var b=[];var c=(1<<jsSHA.charSize)-1;var d=a.length*jsSHA.charSize;for(var i=0;i<d;i+=jsSHA.charSize){b[i>>5]|=(a.charCodeAt(i/jsSHA.charSize)&c)<<(32-jsSHA.charSize-i%32)}return b};var u=function(a){var b=[];var c=a.length;for(var i=0;i<c;i+=2){var d=parseInt(a.substr(i,2),16);if(!isNaN(d)){b[i>>3]|=d<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b};var v=null;var w=null;if("HEX"===p){if(0!==(o.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}v=o.length*4;w=u(o)}else if(("ASCII"===p)||('undefined'===typeof(p))){v=o.length*jsSHA.charSize;w=s(o)}else{return"UNKNOWN TEXT INPUT TYPE"}var A=function(a){var b=jsSHA.hexCase?"0123456789ABCDEF":"0123456789abcdef";var c="";var d=a.length*4;for(var i=0;i<d;i++){c+=b.charAt((a[i>>2]>>((3-i%4)*8+4))&0xF)+b.charAt((a[i>>2]>>((3-i%4)*8))&0xF)}return c};var B=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var c="";var d=a.length*4;for(var i=0;i<d;i+=3){var e=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(var j=0;j<4;j++){if(i*8+j*6>a.length*32){c+=jsSHA.b64pad}else{c+=b.charAt((e>>6*(3-j))&0x3F)}}}return c};var C=function(x,n){if(n<32){return(x>>>n)|(x<<(32-n))}else{return x}};var D=function(x,n){if(n<32){return x>>>n}else{return 0}};var E=function(x,y,z){return(x&y)^(~x&z)};var F=function(x,y,z){return(x&y)^(x&z)^(y&z)};var G=function(x){return C(x,2)^C(x,13)^C(x,22)};var I=function(x){return C(x,6)^C(x,11)^C(x,25)};var J=function(x){return C(x,7)^C(x,18)^D(x,3)};var L=function(x){return C(x,17)^C(x,19)^D(x,10)};var M=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF);var b=(x>>>16)+(y>>>16)+(a>>>16);return((b&0xFFFF)<<16)|(a&0xFFFF)};var N=function(a,b,c,d){var e=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF);var f=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16);return((f&0xFFFF)<<16)|(e&0xFFFF)};var O=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF);var g=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((g&0xFFFF)<<16)|(f&0xFFFF)};var P=function(j,k,l){var W=[];var a,b,c,d,e,f,g,h;var m,T2;var H;var K=[0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0x0FC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x06CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2];if(l==="SHA-224"){H=[0xc1059ed8,0x367cd507,0x3070dd17,0xf70e5939,0xffc00b31,0x68581511,0x64f98fa7,0xbefa4fa4]}else{H=[0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19]}j[k>>5]|=0x80<<(24-k%32);j[((k+1+64>>9)<<4)+15]=k;var n=j.length;for(var i=0;i<n;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];f=H[5];g=H[6];h=H[7];for(var t=0;t<64;t++){if(t<16){W[t]=j[t+i]}else{W[t]=N(L(W[t-2]),W[t-7],J(W[t-15]),W[t-16])}m=O(h,I(e),E(e,f,g),K[t],W[t]);T2=M(G(a),F(a,b,c));h=g;g=f;f=e;e=M(d,m);d=c;c=b;b=a;a=M(m,T2)}H[0]=M(a,H[0]);H[1]=M(b,H[1]);H[2]=M(c,H[2]);H[3]=M(d,H[3]);H[4]=M(e,H[4]);H[5]=M(f,H[5]);H[6]=M(g,H[6]);H[7]=M(h,H[7])}switch(l){case"SHA-224":return[H[0],H[1],H[2],H[3],H[4],H[5],H[6]];case"SHA-256":return H;default:return[]}};this.getHash=function(a,b){var c=null;var d=w.slice();switch(b){case"HEX":c=A;break;case"B64":c=B;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case"SHA-224":if(q===null){q=P(d,v,a)}return c(q);case"SHA-256":if(r===null){r=P(d,v,a)}return c(r);default:return"HASH NOT RECOGNIZED"}};this.getHMAC=function(a,b,c,d){var e=null;var f=null;var g=[];var h=[];var j=null;var k=null;var l=null;switch(d){case"HEX":e=A;break;case"B64":e=B;break;default:return"FORMAT NOT RECOGNIZED"}switch(c){case"SHA-224":l=224;break;case"SHA-256":l=256;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}f=u(a);k=a.length*4}else if("ASCII"===b){f=s(a);k=a.length*jsSHA.charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(512<k){f=P(f,k,c);f[15]&=0xFFFFFF00}else if(512>k){f[15]&=0xFFFFFF00}for(var i=0;i<=15;i++){g[i]=f[i]^0x36363636;h[i]=f[i]^0x5C5C5C5C}j=P(g.concat(w),512+v,c);j=P(h.concat(j),512+l,c);return(e(j))}}
+(function(){var charSize=8,b64pad="",hexCase=0,str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotr=function(x,n){return(x>>>n)|(x<<(32-n))},shr=function(x,n){return x>>>n},ch=function(x,y,z){return(x&y)^(~x&z)},maj=function(x,y,z){return(x&y)^(x&z)^(y&z)},sigma0=function(x){return rotr(x,2)^rotr(x,13)^rotr(x,22)},sigma1=function(x){return rotr(x,6)^rotr(x,11)^rotr(x,25)},gamma0=function(x){return rotr(x,7)^rotr(x,18)^shr(x,3)},gamma1=function(x){return rotr(x,17)^rotr(x,19)^shr(x,10)},safeAdd_2=function(x,y){var a=(x&0xFFFF)+(y&0xFFFF),msw=(x>>>16)+(y>>>16)+(a>>>16);return((msw&0xFFFF)<<16)|(a&0xFFFF)},safeAdd_4=function(a,b,c,d){var e=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16);return((msw&0xFFFF)<<16)|(e&0xFFFF)},safeAdd_5=function(a,b,c,d,e){var f=(a&0xFFFF)+(b&0xFFFF)+(c&0xFFFF)+(d&0xFFFF)+(e&0xFFFF),msw=(a>>>16)+(b>>>16)+(c>>>16)+(d>>>16)+(e>>>16)+(f>>>16);return((msw&0xFFFF)<<16)|(f&0xFFFF)},coreSHA2=function(j,k,l){var a,b,c,d,e,f,g,h,T1,T2,H,lengthPosition,i,t,K,W=[],appendedMessageLength;if(l==="SHA-224"||l==="SHA-256"){lengthPosition=(((k+65)>>9)<<4)+15;K=[0x428A2F98,0x71374491,0xB5C0FBCF,0xE9B5DBA5,0x3956C25B,0x59F111F1,0x923F82A4,0xAB1C5ED5,0xD807AA98,0x12835B01,0x243185BE,0x550C7DC3,0x72BE5D74,0x80DEB1FE,0x9BDC06A7,0xC19BF174,0xE49B69C1,0xEFBE4786,0x0FC19DC6,0x240CA1CC,0x2DE92C6F,0x4A7484AA,0x5CB0A9DC,0x76F988DA,0x983E5152,0xA831C66D,0xB00327C8,0xBF597FC7,0xC6E00BF3,0xD5A79147,0x06CA6351,0x14292967,0x27B70A85,0x2E1B2138,0x4D2C6DFC,0x53380D13,0x650A7354,0x766A0ABB,0x81C2C92E,0x92722C85,0xA2BFE8A1,0xA81A664B,0xC24B8B70,0xC76C51A3,0xD192E819,0xD6990624,0xF40E3585,0x106AA070,0x19A4C116,0x1E376C08,0x2748774C,0x34B0BCB5,0x391C0CB3,0x4ED8AA4A,0x5B9CCA4F,0x682E6FF3,0x748F82EE,0x78A5636F,0x84C87814,0x8CC70208,0x90BEFFFA,0xA4506CEB,0xBEF9A3F7,0xC67178F2];if(l==="SHA-224"){H=[0xc1059ed8,0x367cd507,0x3070dd17,0xf70e5939,0xffc00b31,0x68581511,0x64f98fa7,0xbefa4fa4]}else{H=[0x6A09E667,0xBB67AE85,0x3C6EF372,0xA54FF53A,0x510E527F,0x9B05688C,0x1F83D9AB,0x5BE0CD19]}}j[k>>5]|=0x80<<(24-k%32);j[lengthPosition]=k;appendedMessageLength=j.length;for(i=0;i<appendedMessageLength;i+=16){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];f=H[5];g=H[6];h=H[7];for(t=0;t<64;t+=1){if(t<16){W[t]=j[t+i]}else{W[t]=safeAdd_4(gamma1(W[t-2]),W[t-7],gamma0(W[t-15]),W[t-16])}T1=safeAdd_5(h,sigma1(e),ch(e,f,g),K[t],W[t]);T2=safeAdd_2(sigma0(a),maj(a,b,c));h=g;g=f;f=e;e=safeAdd_2(d,T1);d=c;c=b;b=a;a=safeAdd_2(T1,T2)}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4]);H[5]=safeAdd_2(f,H[5]);H[6]=safeAdd_2(g,H[6]);H[7]=safeAdd_2(h,H[7])}switch(l){case"SHA-224":return[H[0],H[1],H[2],H[3],H[4],H[5],H[6]];case"SHA-256":return H;default:return[]}},jsSHA=function(a,b){this.sha224=null;this.sha256=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a,b){var c=null,message=this.strToHash.slice();switch(b){case"HEX":c=binb2hex;break;case"B64":c=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case"SHA-224":if(null===this.sha224){this.sha224=coreSHA2(message,this.strBinLen,a)}return c(this.sha224);case"SHA-256":if(null===this.sha256){this.sha256=coreSHA2(message,this.strBinLen,a)}return c(this.sha256);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,b,c,d){var e,keyToUse,i,retVal,keyBinLen,hashBitSize,keyWithIPad=[],keyWithOPad=[];switch(d){case"HEX":e=binb2hex;break;case"B64":e=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(c){case"SHA-224":hashBitSize=224;break;case"SHA-256":hashBitSize=256;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(64<(keyBinLen/8)){keyToUse=coreSHA2(keyToUse,keyBinLen,c);keyToUse[15]&=0xFFFFFF00}else if(64>(keyBinLen/8)){keyToUse[15]&=0xFFFFFF00}for(i=0;i<=15;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA2(keyWithIPad.concat(this.strToHash),512+this.strBinLen,c);retVal=coreSHA2(keyWithOPad.concat(retVal),512+hashBitSize,c);return(e(retVal))}};window.jsSHA=jsSHA}());
+
diff --git a/src/sha256_nice.js b/src/sha256_nice.js
index 710ba2b..7ac80f8 100644
--- a/src/sha256_nice.js
+++ b/src/sha256_nice.js
@@ -1,201 +1,211 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
-
-function jsSHA(srcString, inputFormat) {
-
- jsSHA.charSize = 8;
- jsSHA.b64pad = "";
- jsSHA.hexCase = 0;
-
- var sha224 = null;
- var sha256 = null;
-
- var str2binb = function (str) {
- var bin = [];
- var mask = (1 << jsSHA.charSize) - 1;
- var length = str.length * jsSHA.charSize;
-
- for (var i = 0; i < length; i += jsSHA.charSize) {
- bin[i >> 5] |= (str.charCodeAt(i / jsSHA.charSize) & mask) << (32 - jsSHA.charSize - i % 32);
+(function ()
+{
+ var charSize = 8,
+ b64pad = "",
+ hexCase = 0,
+
+ str2binb = function (str)
+ {
+ var bin = [], mask = (1 << charSize) - 1,
+ length = str.length * charSize, i;
+
+ for (i = 0; i < length; i += charSize)
+ {
+ bin[i >> 5] |= (str.charCodeAt(i / charSize) & mask) <<
+ (32 - charSize - (i % 32));
}
return bin;
- };
-
- var hex2binb = function (str) {
- var bin = [];
- var length = str.length;
-
- for (var i = 0; i < length; i += 2) {
- var num = parseInt(str.substr(i, 2), 16);
- if (!isNaN(num)) {
+ },
+
+ hex2binb = function (str)
+ {
+ var bin = [], length = str.length, i, num;
+
+ for (i = 0; i < length; i += 2)
+ {
+ num = parseInt(str.substr(i, 2), 16);
+ if (!isNaN(num))
+ {
bin[i >> 3] |= num << (24 - (4 * (i % 8)));
- } else {
+ }
+ else
+ {
return "INVALID HEX STRING";
}
}
return bin;
- };
+ },
- var strBinLen = null;
- var strToHash = null;
+ binb2hex = function (binarray)
+ {
+ var hex_tab = (hexCase) ? "0123456789ABCDEF" : "0123456789abcdef",
+ str = "", length = binarray.length * 4, i, srcByte;
- if ("HEX" === inputFormat) {
- if (0 !== (srcString.length % 2)) {
- return "TEXT MUST BE IN BYTE INCREMENTS";
- }
- strBinLen = srcString.length * 4;
- strToHash = hex2binb(srcString);
- } else if (("ASCII" === inputFormat) ||
- ('undefined' === typeof(inputFormat))) {
- strBinLen = srcString.length * jsSHA.charSize;
- strToHash = str2binb(srcString);
- } else {
- return "UNKNOWN TEXT INPUT TYPE";
- }
-
- var binb2hex = function (binarray) {
- var hex_tab = jsSHA.hexCase ? "0123456789ABCDEF" : "0123456789abcdef";
- var str = "";
- var length = binarray.length * 4;
-
- for (var i = 0; i < length; i++) {
- str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
+ for (i = 0; i < length; i += 1)
+ {
+ srcByte = binarray[i >> 2] >> ((3 - (i % 4)) * 8);
+ str += hex_tab.charAt((srcByte >> 4) & 0xF) +
+ hex_tab.charAt(srcByte & 0xF);
}
return str;
- };
+ },
+
+ binb2b64 = function (binarray)
+ {
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
+ "0123456789+/", str = "", length = binarray.length * 4, i, j,
+ triplet;
- var binb2b64 = function (binarray) {
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var str = "";
- var length = binarray.length * 4;
- for (var i = 0; i < length; i += 3)
+ for (i = 0; i < length; i += 3)
{
- var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
- for (var j = 0; j < 4; j++) {
- if (i * 8 + j * 6 > binarray.length * 32) {
- str += jsSHA.b64pad;
- } else {
+ triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) |
+ (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
+ ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
+ for (j = 0; j < 4; j += 1)
+ {
+ if (i * 8 + j * 6 <= binarray.length * 32)
+ {
str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
}
+ else
+ {
+ str += b64pad;
+ }
}
}
return str;
- };
+ },
- var rotr = function (x, n) {
- if (n < 32) {
- return (x >>> n) | (x << (32 - n));
- } else {
- return x;
- }
- };
+ rotr = function (x, n)
+ {
+ return (x >>> n) | (x << (32 - n));
+ },
- var shr = function (x, n) {
- if (n < 32) {
- return x >>> n;
- } else {
- return 0;
- }
- };
+ shr = function (x, n)
+ {
+ return x >>> n;
+ },
- var ch = function (x, y, z) {
+ ch = function (x, y, z)
+ {
return (x & y) ^ (~x & z);
- };
+ },
- var maj = function (x, y, z) {
+ maj = function (x, y, z)
+ {
return (x & y) ^ (x & z) ^ (y & z);
- };
+ },
- var sigma0 = function (x) {
+ sigma0 = function (x)
+ {
return rotr(x, 2) ^ rotr(x, 13) ^ rotr(x, 22);
- };
+ },
- var sigma1 = function (x) {
+ sigma1 = function (x)
+ {
return rotr(x, 6) ^ rotr(x, 11) ^ rotr(x, 25);
- };
+ },
- var gamma0 = function (x) {
+ gamma0 = function (x)
+ {
return rotr(x, 7) ^ rotr(x, 18) ^ shr(x, 3);
- };
+ },
- var gamma1 = function (x) {
+ gamma1 = function (x)
+ {
return rotr(x, 17) ^ rotr(x, 19) ^ shr(x, 10);
- };
+ },
- var safeAdd_2 = function (x, y) {
- var lsw = (x & 0xFFFF) + (y & 0xFFFF);
- var msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16);
+ safeAdd_2 = function (x, y)
+ {
+ var lsw = (x & 0xFFFF) + (y & 0xFFFF),
+ msw = (x >>> 16) + (y >>> 16) + (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
-
- var safeAdd_4 = function (a, b, c, d) {
- var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF);
- var msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) + (lsw >>> 16);
+ },
+
+ safeAdd_4 = function (a, b, c, d)
+ {
+ var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF),
+ msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
+ (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
+ },
- var safeAdd_5 = function (a, b, c, d, e) {
+ safeAdd_5 = function (a, b, c, d, e)
+ {
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) +
- (e & 0xFFFF);
- var msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
- (e >>> 16) + (lsw >>> 16);
+ (e & 0xFFFF),
+ msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
+ (e >>> 16) + (lsw >>> 16);
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
- };
-
- var coreSHA2 = function (message, messageLen, variant) {
- var W = [];
- var a, b, c, d, e, f, g, h;
- var T1, T2;
- var H;
- var K = [
- 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
- 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
- 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
- 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
- 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
- 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
- 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
- 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
- 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
- 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
- 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
- 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
- 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
- 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
- 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
- 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
- ];
+ },
- if (variant === "SHA-224") {
- H = [
- 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
- 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
- ];
- } else {
- H = [
- 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
- 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
+ coreSHA2 = function (message, messageLen, variant)
+ {
+ var a, b, c, d, e, f, g, h, T1, T2, H, lengthPosition, i, t, K, W = [],
+ appendedMessageLength;
+
+ if (variant === "SHA-224" || variant === "SHA-256")
+ {
+ lengthPosition = (((messageLen + 65) >> 9) << 4) + 15;
+ K = [
+ 0x428A2F98, 0x71374491, 0xB5C0FBCF, 0xE9B5DBA5,
+ 0x3956C25B, 0x59F111F1, 0x923F82A4, 0xAB1C5ED5,
+ 0xD807AA98, 0x12835B01, 0x243185BE, 0x550C7DC3,
+ 0x72BE5D74, 0x80DEB1FE, 0x9BDC06A7, 0xC19BF174,
+ 0xE49B69C1, 0xEFBE4786, 0x0FC19DC6, 0x240CA1CC,
+ 0x2DE92C6F, 0x4A7484AA, 0x5CB0A9DC, 0x76F988DA,
+ 0x983E5152, 0xA831C66D, 0xB00327C8, 0xBF597FC7,
+ 0xC6E00BF3, 0xD5A79147, 0x06CA6351, 0x14292967,
+ 0x27B70A85, 0x2E1B2138, 0x4D2C6DFC, 0x53380D13,
+ 0x650A7354, 0x766A0ABB, 0x81C2C92E, 0x92722C85,
+ 0xA2BFE8A1, 0xA81A664B, 0xC24B8B70, 0xC76C51A3,
+ 0xD192E819, 0xD6990624, 0xF40E3585, 0x106AA070,
+ 0x19A4C116, 0x1E376C08, 0x2748774C, 0x34B0BCB5,
+ 0x391C0CB3, 0x4ED8AA4A, 0x5B9CCA4F, 0x682E6FF3,
+ 0x748F82EE, 0x78A5636F, 0x84C87814, 0x8CC70208,
+ 0x90BEFFFA, 0xA4506CEB, 0xBEF9A3F7, 0xC67178F2
];
+
+ if (variant === "SHA-224")
+ {
+ H = [
+ 0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
+ 0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
+ ];
+ }
+ else
+ {
+ H = [
+ 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
+ 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
+ ];
+ }
}
message[messageLen >> 5] |= 0x80 << (24 - messageLen % 32);
- message[((messageLen + 1 + 64 >> 9) << 4) + 15] = messageLen;
+ message[lengthPosition] = messageLen;
- var appendedMessageLength = message.length;
+ appendedMessageLength = message.length;
- for (var i = 0; i < appendedMessageLength; i += 16) {
+ for (i = 0; i < appendedMessageLength; i += 16)
+ {
a = H[0];
b = H[1];
c = H[2];
@@ -205,11 +215,18 @@ function jsSHA(srcString, inputFormat) {
g = H[6];
h = H[7];
- for (var t = 0; t < 64; t++) {
- if (t < 16) {
+ for (t = 0; t < 64; t += 1)
+ {
+ if (t < 16)
+ {
W[t] = message[t + i];
- } else {
- W[t] = safeAdd_4(gamma1(W[t - 2]), W[t - 7], gamma0(W[t - 15]), W[t - 16]);
+ }
+ else
+ {
+ W[t] = safeAdd_4(
+ gamma1(W[t - 2]), W[t - 7],
+ gamma0(W[t - 15]), W[t - 16]
+ );
}
T1 = safeAdd_5(h, sigma1(e), ch(e, f, g), K[t], W[t]);
@@ -234,109 +251,161 @@ function jsSHA(srcString, inputFormat) {
H[7] = safeAdd_2(h, H[7]);
}
- switch (variant) {
+ switch (variant)
+ {
case "SHA-224":
- return [
- H[0], H[1], H[2], H[3],
- H[4], H[5], H[6]
+ return [
+ H[0], H[1], H[2], H[3],
+ H[4], H[5], H[6]
];
case "SHA-256":
return H;
default:
- return [];
+ return [];
}
- };
+ },
- this.getHash = function (variant, format) {
- var formatFunc = null;
- var message = strToHash.slice();
-
- switch (format) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
- }
+ jsSHA = function (srcString, inputFormat)
+ {
- switch (variant) {
- case "SHA-224":
- if (sha224 === null) {
- sha224 = coreSHA2(message, strBinLen, variant);
- }
- return formatFunc(sha224);
- case "SHA-256":
- if (sha256 === null) {
- sha256 = coreSHA2(message, strBinLen, variant);
+ this.sha224 = null;
+ this.sha256 = null;
+
+ this.strBinLen = null;
+ this.strToHash = null;
+
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (srcString.length % 2))
+ {
+ return "TEXT MUST BE IN BYTE INCREMENTS";
}
- return formatFunc(sha256);
- default:
- return "HASH NOT RECOGNIZED";
+ this.strBinLen = srcString.length * 4;
+ this.strToHash = hex2binb(srcString);
}
- };
-
- this.getHMAC = function (key, inputFormat, variant, outputFormat) {
- var formatFunc = null;
- var keyToUse = null;
- var keyWithIPad = [];
- var keyWithOPad = [];
- var retVal = null;
- var keyBinLen = null;
- var hashBitSize = null;
-
- switch (outputFormat) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
+ else if (("ASCII" === inputFormat) ||
+ ('undefined' === typeof(inputFormat)))
+ {
+ this.strBinLen = srcString.length * charSize;
+ this.strToHash = str2binb(srcString);
}
-
- switch (variant) {
- case "SHA-224":
- hashBitSize = 224;
- break;
- case "SHA-256":
- hashBitSize = 256;
- break;
- default:
- return "HASH NOT RECOGNIZED";
+ else
+ {
+ return "UNKNOWN TEXT INPUT TYPE";
}
+ };
- if ("HEX" === inputFormat) {
- if (0 !== (key.length % 2)) {
- return "KEY MUST BE IN BYTE INCREMENTS";
+ jsSHA.prototype = {
+ getHash : function (variant, format)
+ {
+ var formatFunc = null, message = this.strToHash.slice();
+
+ switch (format)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
}
- keyToUse = hex2binb(key);
- keyBinLen = key.length * 4;
- } else if ("ASCII" === inputFormat) {
- keyToUse = str2binb(key);
- keyBinLen = key.length * jsSHA.charSize;
- } else {
- return "UNKNOWN KEY INPUT TYPE";
- }
- if (512 < keyBinLen) {
- keyToUse = coreSHA2(keyToUse, keyBinLen, variant);
- keyToUse[15] &= 0xFFFFFF00;
- } else if (512 > keyBinLen) {
- keyToUse[15] &= 0xFFFFFF00;
- }
+ switch (variant)
+ {
+ case "SHA-224":
+ if (null === this.sha224)
+ {
+ this.sha224 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha224);
+ case "SHA-256":
+ if (null === this.sha256)
+ {
+ this.sha256 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha256);
+ default:
+ return "HASH NOT RECOGNIZED";
+ }
+ },
- for (var i = 0; i <= 15; i++) {
- keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
- keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
- }
+ getHMAC : function (key, inputFormat, variant, outputFormat)
+ {
+ var formatFunc, keyToUse, i, retVal, keyBinLen, hashBitSize,
+ keyWithIPad = [], keyWithOPad = [];
+
+ switch (outputFormat)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
+ }
- retVal = coreSHA2(keyWithIPad.concat(strToHash), 512 + strBinLen, variant);
- retVal = coreSHA2(keyWithOPad.concat(retVal), 512 + hashBitSize, variant);
+ switch (variant)
+ {
+ case "SHA-224":
+ hashBitSize = 224;
+ break;
+ case "SHA-256":
+ hashBitSize = 256;
+ break;
+ default:
+ return "HASH NOT RECOGNIZED";
+ }
- return (formatFunc(retVal));
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (key.length % 2))
+ {
+ return "KEY MUST BE IN BYTE INCREMENTS";
+ }
+ keyToUse = hex2binb(key);
+ keyBinLen = key.length * 4;
+ }
+ else if ("ASCII" === inputFormat)
+ {
+ keyToUse = str2binb(key);
+ keyBinLen = key.length * charSize;
+ }
+ else
+ {
+ return "UNKNOWN KEY INPUT TYPE";
+ }
+
+ if (64 < (keyBinLen / 8))
+ {
+ keyToUse = coreSHA2(keyToUse, keyBinLen, variant);
+ keyToUse[15] &= 0xFFFFFF00;
+ }
+ else if (64 > (keyBinLen / 8))
+ {
+ keyToUse[15] &= 0xFFFFFF00;
+ }
+
+ for (i = 0; i <= 15; i += 1)
+ {
+ keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
+ keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
+ }
+
+ retVal = coreSHA2(
+ keyWithIPad.concat(this.strToHash),
+ 512 + this.strBinLen, variant);
+ retVal = coreSHA2(
+ keyWithOPad.concat(retVal),
+ 512 + hashBitSize, variant);
+
+ return (formatFunc(retVal));
+ }
};
-}
+
+ window.jsSHA = jsSHA;
+}());
+
diff --git a/src/sha512.js b/src/sha512.js
index b2ce993..716d740 100644
--- a/src/sha512.js
+++ b/src/sha512.js
@@ -1,10 +1,12 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
+(function(){var charSize=8,b64pad="",hexCase=0,Int_64=function(a,b){this.highOrder=a;this.lowOrder=b},str2binb=function(a){var b=[],mask=(1<<charSize)-1,length=a.length*charSize,i;for(i=0;i<length;i+=charSize){b[i>>5]|=(a.charCodeAt(i/charSize)&mask)<<(32-charSize-(i%32))}return b},hex2binb=function(a){var b=[],length=a.length,i,num;for(i=0;i<length;i+=2){num=parseInt(a.substr(i,2),16);if(!isNaN(num)){b[i>>3]|=num<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b},binb2hex=function(a){var b=(hexCase)?"0123456789ABCDEF":"0123456789abcdef",str="",length=a.length*4,i,srcByte;for(i=0;i<length;i+=1){srcByte=a[i>>2]>>((3-(i%4))*8);str+=b.charAt((srcByte>>4)&0xF)+b.charAt(srcByte&0xF)}return str},binb2b64=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"+"0123456789+/",str="",length=a.length*4,i,j,triplet;for(i=0;i<length;i+=3){triplet=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(j=0;j<4;j+=1){if(i*8+j*6<=a.length*32){str+=b.charAt((triplet>>6*(3-j))&0x3F)}else{str+=b64pad}}}return str},rotr=function(x,n){if(n<=32){return new Int_64((x.highOrder>>>n)|(x.lowOrder<<(32-n)),(x.lowOrder>>>n)|(x.highOrder<<(32-n)))}else{return new Int_64((x.lowOrder>>>n)|(x.highOrder<<(32-n)),(x.highOrder>>>n)|(x.lowOrder<<(32-n)))}},shr=function(x,n){if(n<=32){return new Int_64(x.highOrder>>>n,x.lowOrder>>>n|(x.highOrder<<(32-n)))}else{return new Int_64(0,x.highOrder<<(32-n))}},ch=function(x,y,z){return new Int_64((x.highOrder&y.highOrder)^(~x.highOrder&z.highOrder),(x.lowOrder&y.lowOrder)^(~x.lowOrder&z.lowOrder))},maj=function(x,y,z){return new Int_64((x.highOrder&y.highOrder)^(x.highOrder&z.highOrder)^(y.highOrder&z.highOrder),(x.lowOrder&y.lowOrder)^(x.lowOrder&z.lowOrder)^(y.lowOrder&z.lowOrder))},sigma0=function(x){var a=rotr(x,28),rotr34=rotr(x,34),rotr39=rotr(x,39);return new Int_64(a.highOrder^rotr34.highOrder^rotr39.highOrder,a.lowOrder^rotr34.lowOrder^rotr39.lowOrder)},sigma1=function(x){var a=rotr(x,14),rotr18=rotr(x,18),rotr41=rotr(x,41);return new Int_64(a.highOrder^rotr18.highOrder^rotr41.highOrder,a.lowOrder^rotr18.lowOrder^rotr41.lowOrder)},gamma0=function(x){var a=rotr(x,1),rotr8=rotr(x,8),shr7=shr(x,7);return new Int_64(a.highOrder^rotr8.highOrder^shr7.highOrder,a.lowOrder^rotr8.lowOrder^shr7.lowOrder)},gamma1=function(x){var a=rotr(x,19),rotr61=rotr(x,61),shr6=shr(x,6);return new Int_64(a.highOrder^rotr61.highOrder^shr6.highOrder,a.lowOrder^rotr61.lowOrder^shr6.lowOrder)},safeAdd_2=function(x,y){var a,msw,lowOrder,highOrder;a=(x.lowOrder&0xFFFF)+(y.lowOrder&0xFFFF);msw=(x.lowOrder>>>16)+(y.lowOrder>>>16)+(a>>>16);lowOrder=((msw&0xFFFF)<<16)|(a&0xFFFF);a=(x.highOrder&0xFFFF)+(y.highOrder&0xFFFF)+(msw>>>16);msw=(x.highOrder>>>16)+(y.highOrder>>>16)+(a>>>16);highOrder=((msw&0xFFFF)<<16)|(a&0xFFFF);return new Int_64(highOrder,lowOrder)},safeAdd_4=function(a,b,c,d){var e,msw,lowOrder,highOrder;e=(a.lowOrder&0xFFFF)+(b.lowOrder&0xFFFF)+(c.lowOrder&0xFFFF)+(d.lowOrder&0xFFFF);msw=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e>>>16);lowOrder=((msw&0xFFFF)<<16)|(e&0xFFFF);e=(a.highOrder&0xFFFF)+(b.highOrder&0xFFFF)+(c.highOrder&0xFFFF)+(d.highOrder&0xFFFF)+(msw>>>16);msw=(a.highOrder>>>16)+(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e>>>16);highOrder=((msw&0xFFFF)<<16)|(e&0xFFFF);return new Int_64(highOrder,lowOrder)},safeAdd_5=function(a,b,c,d,e){var f,msw,lowOrder,highOrder;f=(a.lowOrder&0xFFFF)+(b.lowOrder&0xFFFF)+(c.lowOrder&0xFFFF)+(d.lowOrder&0xFFFF)+(e.lowOrder&0xFFFF);msw=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);lowOrder=((msw&0xFFFF)<<16)|(f&0xFFFF);f=(a.highOrder&0xFFFF)+(b.highOrder&0xFFFF)+(c.highOrder&0xFFFF)+(d.highOrder&0xFFFF)+(e.highOrder&0xFFFF)+(msw>>>16);msw=(a.highOrder>>>16)+(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);highOrder=((msw&0xFFFF)<<16)|(f&0xFFFF);return new Int_64(highOrder,lowOrder)},coreSHA2=function(j,k,l){var a,b,c,d,e,f,g,h,T1,T2,H,lengthPosition,i,t,K,W=[],appendedMessageLength;if(l==="SHA-384"||l==="SHA-512"){lengthPosition=(((k+128)>>10)<<5)+31;K=[new Int_64(0x428a2f98,0xd728ae22),new Int_64(0x71374491,0x23ef65cd),new Int_64(0xb5c0fbcf,0xec4d3b2f),new Int_64(0xe9b5dba5,0x8189dbbc),new Int_64(0x3956c25b,0xf348b538),new Int_64(0x59f111f1,0xb605d019),new Int_64(0x923f82a4,0xaf194f9b),new Int_64(0xab1c5ed5,0xda6d8118),new Int_64(0xd807aa98,0xa3030242),new Int_64(0x12835b01,0x45706fbe),new Int_64(0x243185be,0x4ee4b28c),new Int_64(0x550c7dc3,0xd5ffb4e2),new Int_64(0x72be5d74,0xf27b896f),new Int_64(0x80deb1fe,0x3b1696b1),new Int_64(0x9bdc06a7,0x25c71235),new Int_64(0xc19bf174,0xcf692694),new Int_64(0xe49b69c1,0x9ef14ad2),new Int_64(0xefbe4786,0x384f25e3),new Int_64(0x0fc19dc6,0x8b8cd5b5),new Int_64(0x240ca1cc,0x77ac9c65),new Int_64(0x2de92c6f,0x592b0275),new Int_64(0x4a7484aa,0x6ea6e483),new Int_64(0x5cb0a9dc,0xbd41fbd4),new Int_64(0x76f988da,0x831153b5),new Int_64(0x983e5152,0xee66dfab),new Int_64(0xa831c66d,0x2db43210),new Int_64(0xb00327c8,0x98fb213f),new Int_64(0xbf597fc7,0xbeef0ee4),new Int_64(0xc6e00bf3,0x3da88fc2),new Int_64(0xd5a79147,0x930aa725),new Int_64(0x06ca6351,0xe003826f),new Int_64(0x14292967,0x0a0e6e70),new Int_64(0x27b70a85,0x46d22ffc),new Int_64(0x2e1b2138,0x5c26c926),new Int_64(0x4d2c6dfc,0x5ac42aed),new Int_64(0x53380d13,0x9d95b3df),new Int_64(0x650a7354,0x8baf63de),new Int_64(0x766a0abb,0x3c77b2a8),new Int_64(0x81c2c92e,0x47edaee6),new Int_64(0x92722c85,0x1482353b),new Int_64(0xa2bfe8a1,0x4cf10364),new Int_64(0xa81a664b,0xbc423001),new Int_64(0xc24b8b70,0xd0f89791),new Int_64(0xc76c51a3,0x0654be30),new Int_64(0xd192e819,0xd6ef5218),new Int_64(0xd6990624,0x5565a910),new Int_64(0xf40e3585,0x5771202a),new Int_64(0x106aa070,0x32bbd1b8),new Int_64(0x19a4c116,0xb8d2d0c8),new Int_64(0x1e376c08,0x5141ab53),new Int_64(0x2748774c,0xdf8eeb99),new Int_64(0x34b0bcb5,0xe19b48a8),new Int_64(0x391c0cb3,0xc5c95a63),new Int_64(0x4ed8aa4a,0xe3418acb),new Int_64(0x5b9cca4f,0x7763e373),new Int_64(0x682e6ff3,0xd6b2b8a3),new Int_64(0x748f82ee,0x5defb2fc),new Int_64(0x78a5636f,0x43172f60),new Int_64(0x84c87814,0xa1f0ab72),new Int_64(0x8cc70208,0x1a6439ec),new Int_64(0x90befffa,0x23631e28),new Int_64(0xa4506ceb,0xde82bde9),new Int_64(0xbef9a3f7,0xb2c67915),new Int_64(0xc67178f2,0xe372532b),new Int_64(0xca273ece,0xea26619c),new Int_64(0xd186b8c7,0x21c0c207),new Int_64(0xeada7dd6,0xcde0eb1e),new Int_64(0xf57d4f7f,0xee6ed178),new Int_64(0x06f067aa,0x72176fba),new Int_64(0x0a637dc5,0xa2c898a6),new Int_64(0x113f9804,0xbef90dae),new Int_64(0x1b710b35,0x131c471b),new Int_64(0x28db77f5,0x23047d84),new Int_64(0x32caab7b,0x40c72493),new Int_64(0x3c9ebe0a,0x15c9bebc),new Int_64(0x431d67c4,0x9c100d4c),new Int_64(0x4cc5d4be,0xcb3e42b6),new Int_64(0x597f299c,0xfc657e2a),new Int_64(0x5fcb6fab,0x3ad6faec),new Int_64(0x6c44198c,0x4a475817)];if(l==="SHA-384"){H=[new Int_64(0xcbbb9d5d,0xc1059ed8),new Int_64(0x0629a292a,0x367cd507),new Int_64(0x9159015a,0x3070dd17),new Int_64(0x0152fecd8,0xf70e5939),new Int_64(0x67332667,0xffc00b31),new Int_64(0x98eb44a87,0x68581511),new Int_64(0xdb0c2e0d,0x64f98fa7),new Int_64(0x047b5481d,0xbefa4fa4)]}else{H=[new Int_64(0x6a09e667,0xf3bcc908),new Int_64(0xbb67ae85,0x84caa73b),new Int_64(0x3c6ef372,0xfe94f82b),new Int_64(0xa54ff53a,0x5f1d36f1),new Int_64(0x510e527f,0xade682d1),new Int_64(0x9b05688c,0x2b3e6c1f),new Int_64(0x1f83d9ab,0xfb41bd6b),new Int_64(0x5be0cd19,0x137e2179)]}}j[k>>5]|=0x80<<(24-k%32);j[lengthPosition]=k;appendedMessageLength=j.length;for(i=0;i<appendedMessageLength;i+=32){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];f=H[5];g=H[6];h=H[7];for(t=0;t<80;t+=1){if(t<16){W[t]=new Int_64(j[t*2+i],j[t*2+i+1])}else{W[t]=safeAdd_4(gamma1(W[t-2]),W[t-7],gamma0(W[t-15]),W[t-16])}T1=safeAdd_5(h,sigma1(e),ch(e,f,g),K[t],W[t]);T2=safeAdd_2(sigma0(a),maj(a,b,c));h=g;g=f;f=e;e=safeAdd_2(d,T1);d=c;c=b;b=a;a=safeAdd_2(T1,T2)}H[0]=safeAdd_2(a,H[0]);H[1]=safeAdd_2(b,H[1]);H[2]=safeAdd_2(c,H[2]);H[3]=safeAdd_2(d,H[3]);H[4]=safeAdd_2(e,H[4]);H[5]=safeAdd_2(f,H[5]);H[6]=safeAdd_2(g,H[6]);H[7]=safeAdd_2(h,H[7])}switch(l){case"SHA-384":return[H[0].highOrder,H[0].lowOrder,H[1].highOrder,H[1].lowOrder,H[2].highOrder,H[2].lowOrder,H[3].highOrder,H[3].lowOrder,H[4].highOrder,H[4].lowOrder,H[5].highOrder,H[5].lowOrder];case"SHA-512":return[H[0].highOrder,H[0].lowOrder,H[1].highOrder,H[1].lowOrder,H[2].highOrder,H[2].lowOrder,H[3].highOrder,H[3].lowOrder,H[4].highOrder,H[4].lowOrder,H[5].highOrder,H[5].lowOrder,H[6].highOrder,H[6].lowOrder,H[7].highOrder,H[7].lowOrder];default:return[]}},jsSHA=function(a,b){this.sha384=null;this.sha512=null;this.strBinLen=null;this.strToHash=null;if("HEX"===b){if(0!==(a.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}this.strBinLen=a.length*4;this.strToHash=hex2binb(a)}else if(("ASCII"===b)||('undefined'===typeof(b))){this.strBinLen=a.length*charSize;this.strToHash=str2binb(a)}else{return"UNKNOWN TEXT INPUT TYPE"}};jsSHA.prototype={getHash:function(a,b){var c=null,message=this.strToHash.slice();switch(b){case"HEX":c=binb2hex;break;case"B64":c=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case"SHA-384":if(null===this.sha384){this.sha384=coreSHA2(message,this.strBinLen,a)}return c(this.sha384);case"SHA-512":if(null===this.sha512){this.sha512=coreSHA2(message,this.strBinLen,a)}return c(this.sha512);default:return"HASH NOT RECOGNIZED"}},getHMAC:function(a,b,c,d){var e,keyToUse,i,retVal,keyBinLen,hashBitSize,keyWithIPad=[],keyWithOPad=[];switch(d){case"HEX":e=binb2hex;break;case"B64":e=binb2b64;break;default:return"FORMAT NOT RECOGNIZED"}switch(c){case"SHA-384":hashBitSize=384;break;case"SHA-512":hashBitSize=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}keyToUse=hex2binb(a);keyBinLen=a.length*4}else if("ASCII"===b){keyToUse=str2binb(a);keyBinLen=a.length*charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(128<(keyBinLen/8)){keyToUse=coreSHA2(keyToUse,keyBinLen,c);keyToUse[31]&=0xFFFFFF00}else if(128>(keyBinLen/8)){keyToUse[31]&=0xFFFFFF00}for(i=0;i<=31;i+=1){keyWithIPad[i]=keyToUse[i]^0x36363636;keyWithOPad[i]=keyToUse[i]^0x5C5C5C5C}retVal=coreSHA2(keyWithIPad.concat(this.strToHash),1024+this.strBinLen,c);retVal=coreSHA2(keyWithOPad.concat(retVal),1024+hashBitSize,c);return(e(retVal))}};window.jsSHA=jsSHA}());
-function Int_64(a,b){this.highOrder=a;this.lowOrder=b}function jsSHA(o,p){jsSHA.charSize=8;jsSHA.b64pad="";jsSHA.hexCase=0;var q=null;var r=null;var s=function(a){var b=[];var c=(1<<jsSHA.charSize)-1;var d=a.length*jsSHA.charSize;for(var i=0;i<d;i+=jsSHA.charSize){b[i>>5]|=(a.charCodeAt(i/jsSHA.charSize)&c)<<(32-jsSHA.charSize-i%32)}return b};var u=function(a){var b=[];var c=a.length;for(var i=0;i<c;i+=2){var d=parseInt(a.substr(i,2),16);if(!isNaN(d)){b[i>>3]|=d<<(24-(4*(i%8)))}else{return"INVALID HEX STRING"}}return b};var v=null;var w=null;if("HEX"===p){if(0!==(o.length%2)){return"TEXT MUST BE IN BYTE INCREMENTS"}v=o.length*4;w=u(o)}else if(("ASCII"===p)||('undefined'===typeof(p))){v=o.length*jsSHA.charSize;w=s(o)}else{return"UNKNOWN TEXT INPUT TYPE"}var A=function(a){var b=jsSHA.hexCase?"0123456789ABCDEF":"0123456789abcdef";var c="";var d=a.length*4;for(var i=0;i<d;i++){c+=b.charAt((a[i>>2]>>((3-i%4)*8+4))&0xF)+b.charAt((a[i>>2]>>((3-i%4)*8))&0xF)}return c};var B=function(a){var b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";var c="";var d=a.length*4;for(var i=0;i<d;i+=3){var e=(((a[i>>2]>>8*(3-i%4))&0xFF)<<16)|(((a[i+1>>2]>>8*(3-(i+1)%4))&0xFF)<<8)|((a[i+2>>2]>>8*(3-(i+2)%4))&0xFF);for(var j=0;j<4;j++){if(i*8+j*6>a.length*32){c+=jsSHA.b64pad}else{c+=b.charAt((e>>6*(3-j))&0x3F)}}}return c};var C=function(x,n){if(n<32){return new Int_64((x.highOrder>>>n)|(x.lowOrder<<(32-n)),(x.lowOrder>>>n)|(x.highOrder<<(32-n)))}else if(n===32){return new Int_64(x.lowOrder,x.highOrder)}else{return C(C(x,32),n-32)}};var D=function(x,n){if(n<32){return new Int_64(x.highOrder>>>n,x.lowOrder>>>n|(x.highOrder<<(32-n)))}else if(n===32){return new Int_64(0,x.highOrder)}else{return D(D(x,32),n-32)}};var E=function(x,y,z){return new Int_64((x.highOrder&y.highOrder)^(~x.highOrder&z.highOrder),(x.lowOrder&y.lowOrder)^(~x.lowOrder&z.lowOrder))};var F=function(x,y,z){return new Int_64((x.highOrder&y.highOrder)^(x.highOrder&z.highOrder)^(y.highOrder&z.highOrder),(x.lowOrder&y.lowOrder)^(x.lowOrder&z.lowOrder)^(y.lowOrder&z.lowOrder))};var G=function(x){var a=C(x,28);var b=C(x,34);var c=C(x,39);return new Int_64(a.highOrder^b.highOrder^c.highOrder,a.lowOrder^b.lowOrder^c.lowOrder)};var I=function(x){var a=C(x,14);var b=C(x,18);var c=C(x,41);return new Int_64(a.highOrder^b.highOrder^c.highOrder,a.lowOrder^b.lowOrder^c.lowOrder)};var J=function(x){var a=C(x,1);var b=C(x,8);var c=D(x,7);return new Int_64(a.highOrder^b.highOrder^c.highOrder,a.lowOrder^b.lowOrder^c.lowOrder)};var L=function(x){var a=C(x,19);var b=C(x,61);var c=D(x,6);return new Int_64(a.highOrder^b.highOrder^c.highOrder,a.lowOrder^b.lowOrder^c.lowOrder)};var M=function(x,y){var a=(x.lowOrder&0xFFFF)+(y.lowOrder&0xFFFF);var b=(x.lowOrder>>>16)+(y.lowOrder>>>16)+(a>>>16);var c=((b&0xFFFF)<<16)|(a&0xFFFF);a=(x.highOrder&0xFFFF)+(y.highOrder&0xFFFF)+(b>>>16);b=(x.highOrder>>>16)+(y.highOrder>>>16)+(a>>>16);var d=((b&0xFFFF)<<16)|(a&0xFFFF);return new Int_64(d,c)};var N=function(a,b,c,d){var e=(a.lowOrder&0xFFFF)+(b.lowOrder&0xFFFF)+(c.lowOrder&0xFFFF)+(d.lowOrder&0xFFFF);var f=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e>>>16);var g=((f&0xFFFF)<<16)|(e&0xFFFF);e=(a.highOrder&0xFFFF)+(b.highOrder&0xFFFF)+(c.highOrder&0xFFFF)+(d.highOrder&0xFFFF)+(f>>>16);f=(a.highOrder>>>16)+(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e>>>16);var h=((f&0xFFFF)<<16)|(e&0xFFFF);return new Int_64(h,g)};var O=function(a,b,c,d,e){var f=(a.lowOrder&0xFFFF)+(b.lowOrder&0xFFFF)+(c.lowOrder&0xFFFF)+(d.lowOrder&0xFFFF)+(e.lowOrder&0xFFFF);var g=(a.lowOrder>>>16)+(b.lowOrder>>>16)+(c.lowOrder>>>16)+(d.lowOrder>>>16)+(e.lowOrder>>>16)+(f>>>16);var h=((g&0xFFFF)<<16)|(f&0xFFFF);f=(a.highOrder&0xFFFF)+(b.highOrder&0xFFFF)+(c.highOrder&0xFFFF)+(d.highOrder&0xFFFF)+(e.highOrder&0xFFFF)+(g>>>16);g=(a.highOrder>>>16)+(b.highOrder>>>16)+(c.highOrder>>>16)+(d.highOrder>>>16)+(e.highOrder>>>16)+(f>>>16);var i=((g&0xFFFF)<<16)|(f&0xFFFF);return new Int_64(i,h)};var P=function(j,k,l){var W=[];var a,b,c,d,e,f,g,h;var m,T2;var H;var K=[new Int_64(0x428a2f98,0xd728ae22),new Int_64(0x71374491,0x23ef65cd),new Int_64(0xb5c0fbcf,0xec4d3b2f),new Int_64(0xe9b5dba5,0x8189dbbc),new Int_64(0x3956c25b,0xf348b538),new Int_64(0x59f111f1,0xb605d019),new Int_64(0x923f82a4,0xaf194f9b),new Int_64(0xab1c5ed5,0xda6d8118),new Int_64(0xd807aa98,0xa3030242),new Int_64(0x12835b01,0x45706fbe),new Int_64(0x243185be,0x4ee4b28c),new Int_64(0x550c7dc3,0xd5ffb4e2),new Int_64(0x72be5d74,0xf27b896f),new Int_64(0x80deb1fe,0x3b1696b1),new Int_64(0x9bdc06a7,0x25c71235),new Int_64(0xc19bf174,0xcf692694),new Int_64(0xe49b69c1,0x9ef14ad2),new Int_64(0xefbe4786,0x384f25e3),new Int_64(0x0fc19dc6,0x8b8cd5b5),new Int_64(0x240ca1cc,0x77ac9c65),new Int_64(0x2de92c6f,0x592b0275),new Int_64(0x4a7484aa,0x6ea6e483),new Int_64(0x5cb0a9dc,0xbd41fbd4),new Int_64(0x76f988da,0x831153b5),new Int_64(0x983e5152,0xee66dfab),new Int_64(0xa831c66d,0x2db43210),new Int_64(0xb00327c8,0x98fb213f),new Int_64(0xbf597fc7,0xbeef0ee4),new Int_64(0xc6e00bf3,0x3da88fc2),new Int_64(0xd5a79147,0x930aa725),new Int_64(0x06ca6351,0xe003826f),new Int_64(0x14292967,0x0a0e6e70),new Int_64(0x27b70a85,0x46d22ffc),new Int_64(0x2e1b2138,0x5c26c926),new Int_64(0x4d2c6dfc,0x5ac42aed),new Int_64(0x53380d13,0x9d95b3df),new Int_64(0x650a7354,0x8baf63de),new Int_64(0x766a0abb,0x3c77b2a8),new Int_64(0x81c2c92e,0x47edaee6),new Int_64(0x92722c85,0x1482353b),new Int_64(0xa2bfe8a1,0x4cf10364),new Int_64(0xa81a664b,0xbc423001),new Int_64(0xc24b8b70,0xd0f89791),new Int_64(0xc76c51a3,0x0654be30),new Int_64(0xd192e819,0xd6ef5218),new Int_64(0xd6990624,0x5565a910),new Int_64(0xf40e3585,0x5771202a),new Int_64(0x106aa070,0x32bbd1b8),new Int_64(0x19a4c116,0xb8d2d0c8),new Int_64(0x1e376c08,0x5141ab53),new Int_64(0x2748774c,0xdf8eeb99),new Int_64(0x34b0bcb5,0xe19b48a8),new Int_64(0x391c0cb3,0xc5c95a63),new Int_64(0x4ed8aa4a,0xe3418acb),new Int_64(0x5b9cca4f,0x7763e373),new Int_64(0x682e6ff3,0xd6b2b8a3),new Int_64(0x748f82ee,0x5defb2fc),new Int_64(0x78a5636f,0x43172f60),new Int_64(0x84c87814,0xa1f0ab72),new Int_64(0x8cc70208,0x1a6439ec),new Int_64(0x90befffa,0x23631e28),new Int_64(0xa4506ceb,0xde82bde9),new Int_64(0xbef9a3f7,0xb2c67915),new Int_64(0xc67178f2,0xe372532b),new Int_64(0xca273ece,0xea26619c),new Int_64(0xd186b8c7,0x21c0c207),new Int_64(0xeada7dd6,0xcde0eb1e),new Int_64(0xf57d4f7f,0xee6ed178),new Int_64(0x06f067aa,0x72176fba),new Int_64(0x0a637dc5,0xa2c898a6),new Int_64(0x113f9804,0xbef90dae),new Int_64(0x1b710b35,0x131c471b),new Int_64(0x28db77f5,0x23047d84),new Int_64(0x32caab7b,0x40c72493),new Int_64(0x3c9ebe0a,0x15c9bebc),new Int_64(0x431d67c4,0x9c100d4c),new Int_64(0x4cc5d4be,0xcb3e42b6),new Int_64(0x597f299c,0xfc657e2a),new Int_64(0x5fcb6fab,0x3ad6faec),new Int_64(0x6c44198c,0x4a475817)];if(l==="SHA-384"){H=[new Int_64(0xcbbb9d5d,0xc1059ed8),new Int_64(0x0629a292a,0x367cd507),new Int_64(0x9159015a,0x3070dd17),new Int_64(0x152fecd8,0xf70e5939),new Int_64(0x67332667,0xffc00b31),new Int_64(0x98eb44a87,0x68581511),new Int_64(0xdb0c2e0d,0x64f98fa7),new Int_64(0x47b5481d,0xbefa4fa4)]}else{H=[new Int_64(0x6a09e667,0xf3bcc908),new Int_64(0xbb67ae85,0x84caa73b),new Int_64(0x3c6ef372,0xfe94f82b),new Int_64(0xa54ff53a,0x5f1d36f1),new Int_64(0x510e527f,0xade682d1),new Int_64(0x9b05688c,0x2b3e6c1f),new Int_64(0x1f83d9ab,0xfb41bd6b),new Int_64(0x5be0cd19,0x137e2179)]}j[k>>5]|=0x80<<(24-k%32);j[((k+1+128>>10)<<5)+31]=k;var n=j.length;for(var i=0;i<n;i+=32){a=H[0];b=H[1];c=H[2];d=H[3];e=H[4];f=H[5];g=H[6];h=H[7];for(var t=0;t<80;t++){if(t<16){W[t]=new Int_64(j[t*2+i],j[t*2+i+1])}else{W[t]=N(L(W[t-2]),W[t-7],J(W[t-15]),W[t-16])}m=O(h,I(e),E(e,f,g),K[t],W[t]);T2=M(G(a),F(a,b,c));h=g;g=f;f=e;e=M(d,m);d=c;c=b;b=a;a=M(m,T2)}H[0]=M(a,H[0]);H[1]=M(b,H[1]);H[2]=M(c,H[2]);H[3]=M(d,H[3]);H[4]=M(e,H[4]);H[5]=M(f,H[5]);H[6]=M(g,H[6]);H[7]=M(h,H[7])}switch(l){case"SHA-384":return[H[0].highOrder,H[0].lowOrder,H[1].highOrder,H[1].lowOrder,H[2].highOrder,H[2].lowOrder,H[3].highOrder,H[3].lowOrder,H[4].highOrder,H[4].lowOrder,H[5].highOrder,H[5].lowOrder];case"SHA-512":return[H[0].highOrder,H[0].lowOrder,H[1].highOrder,H[1].lowOrder,H[2].highOrder,H[2].lowOrder,H[3].highOrder,H[3].lowOrder,H[4].highOrder,H[4].lowOrder,H[5].highOrder,H[5].lowOrder,H[6].highOrder,H[6].lowOrder,H[7].highOrder,H[7].lowOrder];default:return[]}};this.getHash=function(a,b){var c=null;var d=w.slice();switch(b){case"HEX":c=A;break;case"B64":c=B;break;default:return"FORMAT NOT RECOGNIZED"}switch(a){case"SHA-384":if(q===null){q=P(d,v,a)}return c(q);case"SHA-512":if(r===null){r=P(d,v,a)}return c(r);default:return"HASH NOT RECOGNIZED"}};this.getHMAC=function(a,b,c,d){var e=null;var f=null;var g=[];var h=[];var j=null;var k=null;var l=null;switch(d){case"HEX":e=A;break;case"B64":e=B;break;default:return"FORMAT NOT RECOGNIZED"}switch(c){case"SHA-384":l=384;break;case"SHA-512":l=512;break;default:return"HASH NOT RECOGNIZED"}if("HEX"===b){if(0!==(a.length%2)){return"KEY MUST BE IN BYTE INCREMENTS"}f=u(a);k=a.length*4}else if("ASCII"===b){f=s(a);k=a.length*jsSHA.charSize}else{return"UNKNOWN KEY INPUT TYPE"}if(1024<k){f=P(f,k,c);f[31]&=0xFFFFFF00}else if(1024>k){f[31]&=0xFFFFFF00}for(var i=0;i<=31;i++){g[i]=f[i]^0x36363636;h[i]=f[i]^0x5C5C5C5C}j=P(g.concat(w),1024+v,c);j=P(h.concat(j),1024+l,c);return(e(j))}}
diff --git a/src/sha512_nice.js b/src/sha512_nice.js
index 994298f..490ffdf 100644
--- a/src/sha512_nice.js
+++ b/src/sha512_nice.js
@@ -1,274 +1,330 @@
-/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS PUB 180-2
- * as well as the corresponding HMAC implementation as defined in FIPS PUB 198a
- * Version 1.2 Copyright Brian Turek 2009
+/* A JavaScript implementation of the SHA family of hashes, as defined in FIPS
+ * PUB 180-2 as well as the corresponding HMAC implementation as defined in
+ * FIPS PUB 198a
+ *
+ * Version 1.3 Copyright Brian Turek 2008-2010
* Distributed under the BSD License
* See http://jssha.sourceforge.net/ for more information
*
* Several functions taken from Paul Johnson
*/
-
-function Int_64(msint_32, lsint_32) {
- this.highOrder = msint_32;
- this.lowOrder = lsint_32;
-}
-
-function jsSHA(srcString, inputFormat) {
-
- jsSHA.charSize = 8;
- jsSHA.b64pad = "";
- jsSHA.hexCase = 0;
-
- var sha384 = null;
- var sha512 = null;
-
- var str2binb = function (str) {
- var bin = [];
- var mask = (1 << jsSHA.charSize) - 1;
- var length = str.length * jsSHA.charSize;
-
- for (var i = 0; i < length; i += jsSHA.charSize) {
- bin[i >> 5] |= (str.charCodeAt(i / jsSHA.charSize) & mask) << (32 - jsSHA.charSize - i % 32);
+(function ()
+{
+ var charSize = 8,
+ b64pad = "",
+ hexCase = 0,
+
+ Int_64 = function (msint_32, lsint_32)
+ {
+ this.highOrder = msint_32;
+ this.lowOrder = lsint_32;
+ },
+
+ str2binb = function (str)
+ {
+ var bin = [], mask = (1 << charSize) - 1,
+ length = str.length * charSize, i;
+
+ for (i = 0; i < length; i += charSize)
+ {
+ bin[i >> 5] |= (str.charCodeAt(i / charSize) & mask) <<
+ (32 - charSize - (i % 32));
}
return bin;
- };
-
- var hex2binb = function (str) {
- var bin = [];
- var length = str.length;
-
- for (var i = 0; i < length; i += 2) {
- var num = parseInt(str.substr(i, 2), 16);
- if (!isNaN(num)) {
+ },
+
+ hex2binb = function (str)
+ {
+ var bin = [], length = str.length, i, num;
+
+ for (i = 0; i < length; i += 2)
+ {
+ num = parseInt(str.substr(i, 2), 16);
+ if (!isNaN(num))
+ {
bin[i >> 3] |= num << (24 - (4 * (i % 8)));
- } else {
+ }
+ else
+ {
return "INVALID HEX STRING";
}
}
return bin;
- };
+ },
- var strBinLen = null;
- var strToHash = null;
+ binb2hex = function (binarray)
+ {
+ var hex_tab = (hexCase) ? "0123456789ABCDEF" : "0123456789abcdef",
+ str = "", length = binarray.length * 4, i, srcByte;
- if ("HEX" === inputFormat) {
- if (0 !== (srcString.length % 2)) {
- return "TEXT MUST BE IN BYTE INCREMENTS";
- }
- strBinLen = srcString.length * 4;
- strToHash = hex2binb(srcString);
- } else if (("ASCII" === inputFormat) ||
- ('undefined' === typeof(inputFormat))) {
- strBinLen = srcString.length * jsSHA.charSize;
- strToHash = str2binb(srcString);
- } else {
- return "UNKNOWN TEXT INPUT TYPE";
- }
-
- var binb2hex = function (binarray) {
- var hex_tab = jsSHA.hexCase ? "0123456789ABCDEF" : "0123456789abcdef";
- var str = "";
- var length = binarray.length * 4;
-
- for (var i = 0; i < length; i++) {
- str += hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8 + 4)) & 0xF) + hex_tab.charAt((binarray[i >> 2] >> ((3 - i % 4) * 8)) & 0xF);
+ for (i = 0; i < length; i += 1)
+ {
+ srcByte = binarray[i >> 2] >> ((3 - (i % 4)) * 8);
+ str += hex_tab.charAt((srcByte >> 4) & 0xF) +
+ hex_tab.charAt(srcByte & 0xF);
}
return str;
- };
+ },
+
+ binb2b64 = function (binarray)
+ {
+ var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz" +
+ "0123456789+/", str = "", length = binarray.length * 4, i, j,
+ triplet;
- var binb2b64 = function (binarray) {
- var tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
- var str = "";
- var length = binarray.length * 4;
- for (var i = 0; i < length; i += 3)
+ for (i = 0; i < length; i += 3)
{
- var triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) | (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) | ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
- for (var j = 0; j < 4; j++) {
- if (i * 8 + j * 6 > binarray.length * 32) {
- str += jsSHA.b64pad;
- } else {
+ triplet = (((binarray[i >> 2] >> 8 * (3 - i % 4)) & 0xFF) << 16) |
+ (((binarray[i + 1 >> 2] >> 8 * (3 - (i + 1) % 4)) & 0xFF) << 8) |
+ ((binarray[i + 2 >> 2] >> 8 * (3 - (i + 2) % 4)) & 0xFF);
+ for (j = 0; j < 4; j += 1)
+ {
+ if (i * 8 + j * 6 <= binarray.length * 32)
+ {
str += tab.charAt((triplet >> 6 * (3 - j)) & 0x3F);
}
+ else
+ {
+ str += b64pad;
+ }
}
}
return str;
- };
+ },
- var rotr = function (x, n) {
- if (n < 32) {
+ rotr = function (x, n)
+ {
+ if (n <= 32)
+ {
return new Int_64(
(x.highOrder >>> n) | (x.lowOrder << (32 - n)),
(x.lowOrder >>> n) | (x.highOrder << (32 - n))
);
- } else if (n === 32) {
- return new Int_64(x.lowOrder, x.highOrder);
- } else {
- return rotr(rotr(x, 32), n - 32);
}
- };
+ else
+ {
+ return new Int_64(
+ (x.lowOrder >>> n) | (x.highOrder << (32 - n)),
+ (x.highOrder >>> n) | (x.lowOrder << (32 - n))
+ );
+ }
+ },
- var shr = function (x, n) {
- if (n < 32) {
+ shr = function (x, n)
+ {
+ if (n <= 32)
+ {
return new Int_64(
x.highOrder >>> n,
x.lowOrder >>> n | (x.highOrder << (32 - n))
);
- } else if (n === 32) {
- return new Int_64(0, x.highOrder);
- } else {
- return shr(shr(x, 32), n - 32);
}
- };
+ else
+ {
+ return new Int_64(
+ 0,
+ x.highOrder << (32 - n)
+ );
+ }
+ },
- var ch = function (x, y, z) {
+ ch = function (x, y, z)
+ {
return new Int_64(
(x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),
(x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)
);
- };
+ },
- var maj = function (x, y, z) {
+ maj = function (x, y, z)
+ {
return new Int_64(
- (x.highOrder & y.highOrder) ^ (x.highOrder & z.highOrder) ^ (y.highOrder & z.highOrder),
- (x.lowOrder & y.lowOrder) ^ (x.lowOrder & z.lowOrder) ^ (y.lowOrder & z.lowOrder)
+ (x.highOrder & y.highOrder) ^
+ (x.highOrder & z.highOrder) ^
+ (y.highOrder & z.highOrder),
+ (x.lowOrder & y.lowOrder) ^
+ (x.lowOrder & z.lowOrder) ^
+ (y.lowOrder & z.lowOrder)
);
- };
+ },
- var sigma0 = function (x) {
- var rotr28 = rotr(x, 28);
- var rotr34 = rotr(x, 34);
- var rotr39 = rotr(x, 39);
+ sigma0 = function (x)
+ {
+ var rotr28 = rotr(x, 28), rotr34 = rotr(x, 34), rotr39 = rotr(x, 39);
return new Int_64(
rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder);
- };
+ },
- var sigma1 = function (x) {
- var rotr14 = rotr(x, 14);
- var rotr18 = rotr(x, 18);
- var rotr41 = rotr(x, 41);
+ sigma1 = function (x)
+ {
+ var rotr14 = rotr(x, 14), rotr18 = rotr(x, 18), rotr41 = rotr(x, 41);
return new Int_64(
rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,
rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder);
- };
+ },
- var gamma0 = function (x) {
- var rotr1 = rotr(x, 1);
- var rotr8 = rotr(x, 8);
- var shr7 = shr(x, 7);
+ gamma0 = function (x)
+ {
+ var rotr1 = rotr(x, 1), rotr8 = rotr(x, 8), shr7 = shr(x, 7);
return new Int_64(
rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,
- rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder);
- };
+ rotr1.lowOrder ^ rotr8.lowOrder ^ shr7.lowOrder
+ );
+ },
- var gamma1 = function (x) {
- var rotr19 = rotr(x, 19);
- var rotr61 = rotr(x, 61);
- var shr6 = shr(x, 6);
+ gamma1 = function (x)
+ {
+ var rotr19 = rotr(x, 19), rotr61 = rotr(x, 61), shr6 = shr(x, 6);
return new Int_64(
rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,
- rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder);
- };
+ rotr19.lowOrder ^ rotr61.lowOrder ^ shr6.lowOrder
+ );
+ },
+
+ safeAdd_2 = function (x, y)
+ {
+ var lsw, msw, lowOrder, highOrder;
- var safeAdd_2 = function (x, y) {
- var lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
- var msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);
- var lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
+ msw = (x.lowOrder >>> 16) + (y.lowOrder >>> 16) + (lsw >>> 16);
+ lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
lsw = (x.highOrder & 0xFFFF) + (y.highOrder & 0xFFFF) + (msw >>> 16);
msw = (x.highOrder >>> 16) + (y.highOrder >>> 16) + (lsw >>> 16);
- var highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
return new Int_64(highOrder, lowOrder);
- };
-
- var safeAdd_4 = function (a, b, c, d) {
- var lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
+ },
+
+ safeAdd_4 = function (a, b, c, d)
+ {
+ var lsw, msw, lowOrder, highOrder;
+
+ lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
(c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF);
- var msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
+ msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
(c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (lsw >>> 16);
- var lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) +
(c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) + (msw >>> 16);
msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) +
(c.highOrder >>> 16) + (d.highOrder >>> 16) + (lsw >>> 16);
- var highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
return new Int_64(highOrder, lowOrder);
- };
+ },
+
+ safeAdd_5 = function (a, b, c, d, e)
+ {
+ var lsw, msw, lowOrder, highOrder;
- var safeAdd_5 = function (a, b, c, d, e) {
- var lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
- (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) + (e.lowOrder & 0xFFFF);
- var msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
+ lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
+ (c.lowOrder & 0xFFFF) + (d.lowOrder & 0xFFFF) +
+ (e.lowOrder & 0xFFFF);
+ msw = (a.lowOrder >>> 16) + (b.lowOrder >>> 16) +
(c.lowOrder >>> 16) + (d.lowOrder >>> 16) + (e.lowOrder >>> 16) +
(lsw >>> 16);
- var lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ lowOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
lsw = (a.highOrder & 0xFFFF) + (b.highOrder & 0xFFFF) +
(c.highOrder & 0xFFFF) + (d.highOrder & 0xFFFF) +
(e.highOrder & 0xFFFF) + (msw >>> 16);
msw = (a.highOrder >>> 16) + (b.highOrder >>> 16) +
- (c.highOrder >>> 16) + (d.highOrder >>> 16) + (e.highOrder >>> 16) +
- (lsw >>> 16);
- var highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
+ (c.highOrder >>> 16) + (d.highOrder >>> 16) +
+ (e.highOrder >>> 16) + (lsw >>> 16);
+ highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
return new Int_64(highOrder, lowOrder);
- };
+ },
+
+ coreSHA2 = function (message, messageLen, variant)
+ {
+ var a, b, c, d, e, f, g, h, T1, T2, H, lengthPosition, i, t,
+ K, W = [], appendedMessageLength;
+
+ if (variant === "SHA-384" || variant === "SHA-512")
+ {
+ lengthPosition = (((messageLen + 128) >> 10) << 5) + 31;
+
+ K = [
+ new Int_64(0x428a2f98, 0xd728ae22), new Int_64(0x71374491, 0x23ef65cd),
+ new Int_64(0xb5c0fbcf, 0xec4d3b2f), new Int_64(0xe9b5dba5, 0x8189dbbc),
+ new Int_64(0x3956c25b, 0xf348b538), new Int_64(0x59f111f1, 0xb605d019),
+ new Int_64(0x923f82a4, 0xaf194f9b), new Int_64(0xab1c5ed5, 0xda6d8118),
+ new Int_64(0xd807aa98, 0xa3030242), new Int_64(0x12835b01, 0x45706fbe),
+ new Int_64(0x243185be, 0x4ee4b28c), new Int_64(0x550c7dc3, 0xd5ffb4e2),
+ new Int_64(0x72be5d74, 0xf27b896f), new Int_64(0x80deb1fe, 0x3b1696b1),
+ new Int_64(0x9bdc06a7, 0x25c71235), new Int_64(0xc19bf174, 0xcf692694),
+ new Int_64(0xe49b69c1, 0x9ef14ad2), new Int_64(0xefbe4786, 0x384f25e3),
+ new Int_64(0x0fc19dc6, 0x8b8cd5b5), new Int_64(0x240ca1cc, 0x77ac9c65),
+ new Int_64(0x2de92c6f, 0x592b0275), new Int_64(0x4a7484aa, 0x6ea6e483),
+ new Int_64(0x5cb0a9dc, 0xbd41fbd4), new Int_64(0x76f988da, 0x831153b5),
+ new Int_64(0x983e5152, 0xee66dfab), new Int_64(0xa831c66d, 0x2db43210),
+ new Int_64(0xb00327c8, 0x98fb213f), new Int_64(0xbf597fc7, 0xbeef0ee4),
+ new Int_64(0xc6e00bf3, 0x3da88fc2), new Int_64(0xd5a79147, 0x930aa725),
+ new Int_64(0x06ca6351, 0xe003826f), new Int_64(0x14292967, 0x0a0e6e70),
+ new Int_64(0x27b70a85, 0x46d22ffc), new Int_64(0x2e1b2138, 0x5c26c926),
+ new Int_64(0x4d2c6dfc, 0x5ac42aed), new Int_64(0x53380d13, 0x9d95b3df),
+ new Int_64(0x650a7354, 0x8baf63de), new Int_64(0x766a0abb, 0x3c77b2a8),
+ new Int_64(0x81c2c92e, 0x47edaee6), new Int_64(0x92722c85, 0x1482353b),
+ new Int_64(0xa2bfe8a1, 0x4cf10364), new Int_64(0xa81a664b, 0xbc423001),
+ new Int_64(0xc24b8b70, 0xd0f89791), new Int_64(0xc76c51a3, 0x0654be30),
+ new Int_64(0xd192e819, 0xd6ef5218), new Int_64(0xd6990624, 0x5565a910),
+ new Int_64(0xf40e3585, 0x5771202a), new Int_64(0x106aa070, 0x32bbd1b8),
+ new Int_64(0x19a4c116, 0xb8d2d0c8), new Int_64(0x1e376c08, 0x5141ab53),
+ new Int_64(0x2748774c, 0xdf8eeb99), new Int_64(0x34b0bcb5, 0xe19b48a8),
+ new Int_64(0x391c0cb3, 0xc5c95a63), new Int_64(0x4ed8aa4a, 0xe3418acb),
+ new Int_64(0x5b9cca4f, 0x7763e373), new Int_64(0x682e6ff3, 0xd6b2b8a3),
+ new Int_64(0x748f82ee, 0x5defb2fc), new Int_64(0x78a5636f, 0x43172f60),
+ new Int_64(0x84c87814, 0xa1f0ab72), new Int_64(0x8cc70208, 0x1a6439ec),
+ new Int_64(0x90befffa, 0x23631e28), new Int_64(0xa4506ceb, 0xde82bde9),
+ new Int_64(0xbef9a3f7, 0xb2c67915), new Int_64(0xc67178f2, 0xe372532b),
+ new Int_64(0xca273ece, 0xea26619c), new Int_64(0xd186b8c7, 0x21c0c207),
+ new Int_64(0xeada7dd6, 0xcde0eb1e), new Int_64(0xf57d4f7f, 0xee6ed178),
+ new Int_64(0x06f067aa, 0x72176fba), new Int_64(0x0a637dc5, 0xa2c898a6),
+ new Int_64(0x113f9804, 0xbef90dae), new Int_64(0x1b710b35, 0x131c471b),
+ new Int_64(0x28db77f5, 0x23047d84), new Int_64(0x32caab7b, 0x40c72493),
+ new Int_64(0x3c9ebe0a, 0x15c9bebc), new Int_64(0x431d67c4, 0x9c100d4c),
+ new Int_64(0x4cc5d4be, 0xcb3e42b6), new Int_64(0x597f299c, 0xfc657e2a),
+ new Int_64(0x5fcb6fab, 0x3ad6faec), new Int_64(0x6c44198c, 0x4a475817)
+ ];
- var coreSHA2 = function (message, messageLen, variant) {
- var W = [];
- var a, b, c, d, e, f, g, h;
- var T1, T2;
- var H;
- var K = [
- new Int_64(0x428a2f98, 0xd728ae22), new Int_64(0x71374491, 0x23ef65cd), new Int_64(0xb5c0fbcf, 0xec4d3b2f), new Int_64(0xe9b5dba5, 0x8189dbbc),
- new Int_64(0x3956c25b, 0xf348b538), new Int_64(0x59f111f1, 0xb605d019), new Int_64(0x923f82a4, 0xaf194f9b), new Int_64(0xab1c5ed5, 0xda6d8118),
- new Int_64(0xd807aa98, 0xa3030242), new Int_64(0x12835b01, 0x45706fbe), new Int_64(0x243185be, 0x4ee4b28c), new Int_64(0x550c7dc3, 0xd5ffb4e2),
- new Int_64(0x72be5d74, 0xf27b896f), new Int_64(0x80deb1fe, 0x3b1696b1), new Int_64(0x9bdc06a7, 0x25c71235), new Int_64(0xc19bf174, 0xcf692694),
- new Int_64(0xe49b69c1, 0x9ef14ad2), new Int_64(0xefbe4786, 0x384f25e3), new Int_64(0x0fc19dc6, 0x8b8cd5b5), new Int_64(0x240ca1cc, 0x77ac9c65),
- new Int_64(0x2de92c6f, 0x592b0275), new Int_64(0x4a7484aa, 0x6ea6e483), new Int_64(0x5cb0a9dc, 0xbd41fbd4), new Int_64(0x76f988da, 0x831153b5),
- new Int_64(0x983e5152, 0xee66dfab), new Int_64(0xa831c66d, 0x2db43210), new Int_64(0xb00327c8, 0x98fb213f), new Int_64(0xbf597fc7, 0xbeef0ee4),
- new Int_64(0xc6e00bf3, 0x3da88fc2), new Int_64(0xd5a79147, 0x930aa725), new Int_64(0x06ca6351, 0xe003826f), new Int_64(0x14292967, 0x0a0e6e70),
- new Int_64(0x27b70a85, 0x46d22ffc), new Int_64(0x2e1b2138, 0x5c26c926), new Int_64(0x4d2c6dfc, 0x5ac42aed), new Int_64(0x53380d13, 0x9d95b3df),
- new Int_64(0x650a7354, 0x8baf63de), new Int_64(0x766a0abb, 0x3c77b2a8), new Int_64(0x81c2c92e, 0x47edaee6), new Int_64(0x92722c85, 0x1482353b),
- new Int_64(0xa2bfe8a1, 0x4cf10364), new Int_64(0xa81a664b, 0xbc423001), new Int_64(0xc24b8b70, 0xd0f89791), new Int_64(0xc76c51a3, 0x0654be30),
- new Int_64(0xd192e819, 0xd6ef5218), new Int_64(0xd6990624, 0x5565a910), new Int_64(0xf40e3585, 0x5771202a), new Int_64(0x106aa070, 0x32bbd1b8),
- new Int_64(0x19a4c116, 0xb8d2d0c8), new Int_64(0x1e376c08, 0x5141ab53), new Int_64(0x2748774c, 0xdf8eeb99), new Int_64(0x34b0bcb5, 0xe19b48a8),
- new Int_64(0x391c0cb3, 0xc5c95a63), new Int_64(0x4ed8aa4a, 0xe3418acb), new Int_64(0x5b9cca4f, 0x7763e373), new Int_64(0x682e6ff3, 0xd6b2b8a3),
- new Int_64(0x748f82ee, 0x5defb2fc), new Int_64(0x78a5636f, 0x43172f60), new Int_64(0x84c87814, 0xa1f0ab72), new Int_64(0x8cc70208, 0x1a6439ec),
- new Int_64(0x90befffa, 0x23631e28), new Int_64(0xa4506ceb, 0xde82bde9), new Int_64(0xbef9a3f7, 0xb2c67915), new Int_64(0xc67178f2, 0xe372532b),
- new Int_64(0xca273ece, 0xea26619c), new Int_64(0xd186b8c7, 0x21c0c207), new Int_64(0xeada7dd6, 0xcde0eb1e), new Int_64(0xf57d4f7f, 0xee6ed178),
- new Int_64(0x06f067aa, 0x72176fba), new Int_64(0x0a637dc5, 0xa2c898a6), new Int_64(0x113f9804, 0xbef90dae), new Int_64(0x1b710b35, 0x131c471b),
- new Int_64(0x28db77f5, 0x23047d84), new Int_64(0x32caab7b, 0x40c72493), new Int_64(0x3c9ebe0a, 0x15c9bebc), new Int_64(0x431d67c4, 0x9c100d4c),
- new Int_64(0x4cc5d4be, 0xcb3e42b6), new Int_64(0x597f299c, 0xfc657e2a), new Int_64(0x5fcb6fab, 0x3ad6faec), new Int_64(0x6c44198c, 0x4a475817)
- ];
-
- if (variant === "SHA-384") {
- H = [
- new Int_64(0xcbbb9d5d, 0xc1059ed8), new Int_64(0x0629a292a, 0x367cd507), new Int_64(0x9159015a, 0x3070dd17), new Int_64(0x152fecd8, 0xf70e5939),
- new Int_64(0x67332667, 0xffc00b31), new Int_64(0x98eb44a87, 0x68581511), new Int_64(0xdb0c2e0d, 0x64f98fa7), new Int_64(0x47b5481d, 0xbefa4fa4)
+ if (variant === "SHA-384")
+ {
+ H = [
+ new Int_64(0xcbbb9d5d, 0xc1059ed8), new Int_64(0x0629a292a, 0x367cd507),
+ new Int_64(0x9159015a, 0x3070dd17), new Int_64(0x0152fecd8, 0xf70e5939),
+ new Int_64(0x67332667, 0xffc00b31), new Int_64(0x98eb44a87, 0x68581511),
+ new Int_64(0xdb0c2e0d, 0x64f98fa7), new Int_64(0x047b5481d, 0xbefa4fa4)
];
- } else {
- H = [
- new Int_64(0x6a09e667, 0xf3bcc908), new Int_64(0xbb67ae85, 0x84caa73b), new Int_64(0x3c6ef372, 0xfe94f82b), new Int_64(0xa54ff53a, 0x5f1d36f1),
- new Int_64(0x510e527f, 0xade682d1), new Int_64(0x9b05688c, 0x2b3e6c1f), new Int_64(0x1f83d9ab, 0xfb41bd6b), new Int_64(0x5be0cd19, 0x137e2179)
+ }
+ else
+ {
+ H = [
+ new Int_64(0x6a09e667, 0xf3bcc908), new Int_64(0xbb67ae85, 0x84caa73b),
+ new Int_64(0x3c6ef372, 0xfe94f82b), new Int_64(0xa54ff53a, 0x5f1d36f1),
+ new Int_64(0x510e527f, 0xade682d1), new Int_64(0x9b05688c, 0x2b3e6c1f),
+ new Int_64(0x1f83d9ab, 0xfb41bd6b), new Int_64(0x5be0cd19, 0x137e2179)
];
+ }
}
message[messageLen >> 5] |= 0x80 << (24 - messageLen % 32);
- message[((messageLen + 1 + 128 >> 10) << 5) + 31] = messageLen;
+ message[lengthPosition] = messageLen;
- var appendedMessageLength = message.length;
+ appendedMessageLength = message.length;
- for (var i = 0; i < appendedMessageLength; i += 32) {
+ for (i = 0; i < appendedMessageLength; i += 32)
+ {
a = H[0];
b = H[1];
c = H[2];
@@ -278,11 +334,19 @@ function jsSHA(srcString, inputFormat) {
g = H[6];
h = H[7];
- for (var t = 0; t < 80; t++) {
- if (t < 16) {
- W[t] = new Int_64(message[t * 2 + i], message[t * 2 + i + 1]);
- } else {
- W[t] = safeAdd_4(gamma1(W[t - 2]), W[t - 7], gamma0(W[t - 15]), W[t - 16]);
+ for (t = 0; t < 80; t += 1)
+ {
+ if (t < 16)
+ {
+ W[t] = new Int_64(message[t * 2 + i],
+ message[t * 2 + i + 1]);
+ }
+ else
+ {
+ W[t] = safeAdd_4(
+ gamma1(W[t - 2]), W[t - 7],
+ gamma0(W[t - 15]), W[t - 16]
+ );
}
T1 = safeAdd_5(h, sigma1(e), ch(e, f, g), K[t], W[t]);
@@ -307,9 +371,10 @@ function jsSHA(srcString, inputFormat) {
H[7] = safeAdd_2(h, H[7]);
}
- switch (variant) {
+ switch (variant)
+ {
case "SHA-384":
- return [
+ return [
H[0].highOrder, H[0].lowOrder,
H[1].highOrder, H[1].lowOrder,
H[2].highOrder, H[2].lowOrder,
@@ -318,7 +383,7 @@ function jsSHA(srcString, inputFormat) {
H[5].highOrder, H[5].lowOrder
];
case "SHA-512":
- return [
+ return [
H[0].highOrder, H[0].lowOrder,
H[1].highOrder, H[1].lowOrder,
H[2].highOrder, H[2].lowOrder,
@@ -329,100 +394,151 @@ function jsSHA(srcString, inputFormat) {
H[7].highOrder, H[7].lowOrder
];
default:
- return [];
+ return [];
}
- };
+ },
- this.getHash = function (variant, format) {
- var formatFunc = null;
- var message = strToHash.slice();
-
- switch (format) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
- }
+ jsSHA = function (srcString, inputFormat)
+ {
- switch (variant) {
- case "SHA-384":
- if (sha384 === null) {
- sha384 = coreSHA2(message, strBinLen, variant);
- }
- return formatFunc(sha384);
- case "SHA-512":
- if (sha512 === null) {
- sha512 = coreSHA2(message, strBinLen, variant);
+ this.sha384 = null;
+ this.sha512 = null;
+
+ this.strBinLen = null;
+ this.strToHash = null;
+
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (srcString.length % 2))
+ {
+ return "TEXT MUST BE IN BYTE INCREMENTS";
}
- return formatFunc(sha512);
- default:
- return "HASH NOT RECOGNIZED";
+ this.strBinLen = srcString.length * 4;
+ this.strToHash = hex2binb(srcString);
}
- };
-
- this.getHMAC = function (key, inputFormat, variant, outputFormat) {
- var formatFunc = null;
- var keyToUse = null;
- var keyWithIPad = [];
- var keyWithOPad = [];
- var retVal = null;
- var keyBinLen = null;
- var hashBitSize = null;
-
- switch (outputFormat) {
- case "HEX":
- formatFunc = binb2hex;
- break;
- case "B64":
- formatFunc = binb2b64;
- break;
- default:
- return "FORMAT NOT RECOGNIZED";
+ else if (("ASCII" === inputFormat) ||
+ ('undefined' === typeof(inputFormat)))
+ {
+ this.strBinLen = srcString.length * charSize;
+ this.strToHash = str2binb(srcString);
}
-
- switch (variant) {
- case "SHA-384":
- hashBitSize = 384;
- break;
- case "SHA-512":
- hashBitSize = 512;
- break;
- default:
- return "HASH NOT RECOGNIZED";
+ else
+ {
+ return "UNKNOWN TEXT INPUT TYPE";
}
+ };
- if ("HEX" === inputFormat) {
- if (0 !== (key.length % 2)) {
- return "KEY MUST BE IN BYTE INCREMENTS";
+ jsSHA.prototype = {
+ getHash : function (variant, format)
+ {
+ var formatFunc = null, message = this.strToHash.slice();
+
+ switch (format)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
}
- keyToUse = hex2binb(key);
- keyBinLen = key.length * 4;
- } else if ("ASCII" === inputFormat) {
- keyToUse = str2binb(key);
- keyBinLen = key.length * jsSHA.charSize;
- } else {
- return "UNKNOWN KEY INPUT TYPE";
- }
- if (1024 < keyBinLen) {
- keyToUse = coreSHA2(keyToUse, keyBinLen, variant);
- keyToUse[31] &= 0xFFFFFF00;
- } else if (1024 > keyBinLen) {
- keyToUse[31] &= 0xFFFFFF00;
- }
+ switch (variant)
+ {
+ case "SHA-384":
+ if (null === this.sha384)
+ {
+ this.sha384 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha384);
+ case "SHA-512":
+ if (null === this.sha512)
+ {
+ this.sha512 = coreSHA2(message, this.strBinLen, variant);
+ }
+ return formatFunc(this.sha512);
+ default:
+ return "HASH NOT RECOGNIZED";
+ }
+ },
- for (var i = 0; i <= 31; i++) {
- keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
- keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
- }
+ getHMAC : function (key, inputFormat, variant, outputFormat)
+ {
+ var formatFunc, keyToUse, i, retVal, keyBinLen, hashBitSize,
+ keyWithIPad = [], keyWithOPad = [];
+
+ switch (outputFormat)
+ {
+ case "HEX":
+ formatFunc = binb2hex;
+ break;
+ case "B64":
+ formatFunc = binb2b64;
+ break;
+ default:
+ return "FORMAT NOT RECOGNIZED";
+ }
- retVal = coreSHA2(keyWithIPad.concat(strToHash), 1024 + strBinLen, variant);
- retVal = coreSHA2(keyWithOPad.concat(retVal), 1024 + hashBitSize, variant);
+ switch (variant)
+ {
+ case "SHA-384":
+ hashBitSize = 384;
+ break;
+ case "SHA-512":
+ hashBitSize = 512;
+ break;
+ default:
+ return "HASH NOT RECOGNIZED";
+ }
- return (formatFunc(retVal));
+ if ("HEX" === inputFormat)
+ {
+ if (0 !== (key.length % 2))
+ {
+ return "KEY MUST BE IN BYTE INCREMENTS";
+ }
+ keyToUse = hex2binb(key);
+ keyBinLen = key.length * 4;
+ }
+ else if ("ASCII" === inputFormat)
+ {
+ keyToUse = str2binb(key);
+ keyBinLen = key.length * charSize;
+ }
+ else
+ {
+ return "UNKNOWN KEY INPUT TYPE";
+ }
+
+ if (128 < (keyBinLen / 8))
+ {
+ keyToUse = coreSHA2(keyToUse, keyBinLen, variant);
+ keyToUse[31] &= 0xFFFFFF00;
+ }
+ else if (128 > (keyBinLen / 8))
+ {
+ keyToUse[31] &= 0xFFFFFF00;
+ }
+
+ for (i = 0; i <= 31; i += 1)
+ {
+ keyWithIPad[i] = keyToUse[i] ^ 0x36363636;
+ keyWithOPad[i] = keyToUse[i] ^ 0x5C5C5C5C;
+ }
+
+ retVal = coreSHA2(
+ keyWithIPad.concat(this.strToHash),
+ 1024 + this.strBinLen, variant);
+ retVal = coreSHA2(
+ keyWithOPad.concat(retVal),
+ 1024 + hashBitSize, variant);
+
+ return (formatFunc(retVal));
+ }
};
-}
+
+ window.jsSHA = jsSHA;
+}());
+
diff --git a/test/test.html b/test/test.html
index 2124d7f..2688988 100644
--- a/test/test.html
+++ b/test/test.html
@@ -1,519 +1,519 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
- <head>
- <title>jsSHA (http://jssha.sourceforge.net/) - Test</title>
- <script type="text/javascript" src="../src/sha.js"></script>
- <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
- <style type="text/css">
- label
- {
- width: 235px;
- display: block;
- float: left;
- text-align: right;
- padding-right: 10px;
- }
-
- .correct
- {
- color: #00FF00;
- background-color: #FFFFFF;
- }
-
- .incorrect
- {
- color: #FF0000;
- background-color: #FFFFFF;
- }
- </style>
- <script type="text/javascript">
- function calcHashes()
- {
- calcHash("sha1-short", "SHA-1");
- calcHash("sha1-long", "SHA-1");
- calcHash("sha224-short", "SHA-224");
- calcHash("sha224-long", "SHA-224");
- calcHash("sha256-short", "SHA-256");
- calcHash("sha256-long", "SHA-256");
- calcHash("sha384-short", "SHA-384");
- calcHash("sha384-long", "SHA-384");
- calcHash("sha512-long", "SHA-512");
- calcHash("sha512-short", "SHA-512");
- calcHMAC('hmac-sha1-short', "ASCII", "ASCII", "SHA-1");
- calcHMAC('hmac-sha1-med', "ASCII", "HEX", "SHA-1");
- calcHMAC('hmac-sha1-large', "HEX", "HEX", "SHA-1");
- calcHMAC('hmac-sha224-short', "ASCII", "ASCII", "SHA-224");
- calcHMAC('hmac-sha224-med', "ASCII", "HEX", "SHA-224");
- calcHMAC('hmac-sha224-large', "HEX", "HEX", "SHA-224");
- calcHMAC('hmac-sha256-short', "ASCII", "ASCII", "SHA-256");
- calcHMAC('hmac-sha256-med', "ASCII", "HEX", "SHA-256");
- calcHMAC('hmac-sha256-large', "HEX", "HEX", "SHA-256");
- calcHMAC('hmac-sha384-short', "ASCII", "ASCII", "SHA-384");
- calcHMAC('hmac-sha384-med', "ASCII", "HEX", "SHA-384");
- calcHMAC('hmac-sha384-large', "HEX", "HEX", "SHA-384");
- calcHMAC('hmac-sha512-short', "ASCII", "ASCII", "SHA-512");
- calcHMAC('hmac-sha512-med', "ASCII", "HEX", "SHA-512");
- calcHMAC('hmac-sha512-large', "HEX", "HEX", "SHA-512");
- }
-
- function calcHash(fieldGroupName, variant)
- {
- var tmp = document.getElementById(fieldGroupName+"-ascii-comp");
-
- var shaObj = new jsSHA(document.getElementById(fieldGroupName+"-ascii-input").value, "ASCII");
-
- document.getElementById(fieldGroupName+"-ascii-result").value = shaObj.getHash(variant, "HEX");
- if (document.getElementById(fieldGroupName+"-ascii-result").value == document.getElementById(fieldGroupName+"-correct").value)
- {
- tmp.className = "correct";
- tmp.innerHTML = "Match!";
- } else {
- tmp.className = "incorrect";
- tmp.innerHTML = "Mismatch!";
- }
-
- tmp = document.getElementById(fieldGroupName+"-hex-comp");
-
- shaObj = new jsSHA(document.getElementById(fieldGroupName+"-hex-input").value, "HEX");
-
- document.getElementById(fieldGroupName+"-hex-result").value = shaObj.getHash(variant, "HEX");
- if (document.getElementById(fieldGroupName+"-hex-result").value == document.getElementById(fieldGroupName+"-correct").value)
- {
- tmp.className = "correct";
- tmp.innerHTML = "Match!";
- } else {
- tmp.className = "incorrect";
- tmp.innerHTML = "Mismatch!";
- }
- }
-
- function calcHMAC(fieldGroupName, textFormat, keyFormat, variant)
- {
- var tmp = document.getElementById(fieldGroupName+"-comp");
-
- var shaObj = new jsSHA(document.getElementById(fieldGroupName+"-text").value, textFormat);
-
- document.getElementById(fieldGroupName+"-result").value = shaObj.getHMAC(document.getElementById(fieldGroupName+"-key").value, keyFormat, variant, "HEX");
- if (document.getElementById(fieldGroupName+"-result").value == document.getElementById(fieldGroupName+"-correct").value)
- {
- tmp.className = "correct";
- tmp.innerHTML = "Match!";
- } else {
- tmp.className = "incorrect";
- tmp.innerHTML = "Mismatch!";
- }
- }
-
- </script>
- </head>
- <body onload="calcHashes()">
- <h1><a href="http://jssha.sourceforge.net/">jsSHA</a> Hash Test Page</h1>
- <p>
- The short/long inputs as well as their correct hashes are supplied by the FIPS 180-2 specification; it can be found at <a href="http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf">http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf</a>. The short/medium/large inputs for HMAC and their corresponding correct hashes (at least for SHA-1) can be found at <a href="http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf">http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf</a>.
- </p>
-
- <p>
- <span style="font-weight: bold">Instructions:</span> By default, this page should load 10 of the 15 test vectors given by the FIPS 180-2 specification and 3 of the 4 test vectors given by the FIPS 198a specification. You may also change any of the input values and then click off the input box to have the hash update.
- </p>
- <form method="get" action="test.html" onsubmit="return false">
- <fieldset>
- <legend>SHA-1 Tests</legend>
- <div>
- <label for="sha1-short-ascii-input">SHA-1 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha1-short-ascii-input" onchange="calcHash('sha1-short', 'SHA-1')" />
- </div>
- <div>
- <label for="sha1-short-ascii-result">SHA-1 Med ASCII Result:</label><input type="text" size="50" disabled="disabled" id="sha1-short-ascii-result" />
- <span id="sha1-short-ascii-comp"></span>
- </div>
- <div>
- <label for="sha1-short-hex-input">SHA-1 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha1-short-hex-input" onchange="calcHash('sha1-short', 'SHA-1')" />
- </div>
- <div>
- <label for="sha1-short-hex-result">SHA-1 Med Hex Result:</label><input type="text" size="50" disabled="disabled" id="sha1-short-hex-result" />
- <span id="sha1-short-hex-comp"></span>
- </div>
- <div>
- <label for="sha1-short-correct">SHA-1 Med Correct:</label><input type="text" size="50" value="a9993e364706816aba3e25717850c26c9cd0d89d" disabled="disabled" id="sha1-short-correct" />
- </div>
- <div>
- <label for="sha1-long-ascii-input">SHA-1 Long ASCII Input:</label><input type="text" size="60" value="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" id="sha1-long-ascii-input" onchange="calcHash('sha1-long', 'SHA-1')" />
- </div>
- <div>
- <label for="sha1-long-ascii-result">SHA-1 Long ASCII Result:</label><input type="text" size="50" disabled="disabled" id="sha1-long-ascii-result" />
- <span id="sha1-long-ascii-comp"></span>
- </div>
- <div>
- <label for="sha1-long-hex-input">SHA-1 Long Hex Input:</label><input type="text" size="140" value="6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071" id="sha1-long-hex-input" onchange="calcHash('sha1-long', 'SHA-1')" />
- </div>
- <div>
- <label for="sha1-long-hex-result">SHA-1 Long Hex Result:</label><input type="text" size="50" disabled="disabled" id="sha1-long-hex-result" />
- <span id="sha1-long-hex-comp"></span>
- </div>
- <div>
- <label for="sha1-long-correct">SHA-1 Long Correct:</label><input type="text" size="50" value="84983e441c3bd26ebaae4aa1f95129e5e54670f1" disabled="disabled" id="sha1-long-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>SHA-224 Tests</legend>
- <div>
- <label for="sha224-short-ascii-input">SHA-224 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha224-short-ascii-input" onchange="calcHash('sha224-short', 'SHA-224')" />
- </div>
- <div>
- <label for="sha224-short-ascii-result">SHA-224 Med ASCII Result:</label><input type="text" size="65" disabled="disabled" id="sha224-short-ascii-result" />
- <span id="sha224-short-ascii-comp"></span>
- </div>
- <div>
- <label for="sha224-short-hex-input">SHA-224 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha224-short-hex-input" onchange="calcHash('sha224-short', 'SHA-224')" />
- </div>
- <div>
- <label for="sha224-short-hex-result">SHA-224 Med Hex Result:</label><input type="text" size="65" disabled="disabled" id="sha224-short-hex-result" />
- <span id="sha224-short-hex-comp"></span>
- </div>
- <div>
- <label for="sha224-short-correct">SHA-224 Med Correct:</label><input type="text" size="65" value="23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" disabled="disabled" id="sha224-short-correct" />
- </div>
- <div>
- <label for="sha224-long-ascii-input">SHA-224 Long ASCII Input:</label><input type="text" size="60" value="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" id="sha224-long-ascii-input" onchange="calcHash('sha224-long', 'SHA-224')" />
- </div>
- <div>
- <label for="sha224-long-ascii-result">SHA-224 Long ASCII Result:</label><input type="text" size="65" disabled="disabled" id="sha224-long-ascii-result" />
- <span id="sha224-long-ascii-comp"></span>
- </div>
- <div>
- <label for="sha224-long-hex-input">SHA-224 Long Hex Input:</label><input type="text" size="140" value="6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071" id="sha224-long-hex-input" onchange="calcHash('sha224-long', 'SHA-224')" />
- </div>
- <div>
- <label for="sha224-long-hex-result">SHA-224 Long Hex Result:</label><input type="text" size="65" disabled="disabled" id="sha224-long-hex-result" />
- <span id="sha224-long-hex-comp"></span>
- </div>
- <div>
- <label for="sha224-long-correct">SHA-224 Long Correct:</label><input type="text" size="65" value="75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" disabled="disabled" id="sha224-long-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>SHA-256 Tests</legend>
- <div>
- <label for="sha256-short-ascii-input">SHA-256 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha256-short-ascii-input" onchange="calcHash('sha256-short', 'SHA-256')" />
- </div>
- <div>
- <label for="sha256-short-ascii-result">SHA-256 Med ASCII Result:</label><input type="text" size="75" disabled="disabled" id="sha256-short-ascii-result" />
- <span id="sha256-short-ascii-comp"></span>
- </div>
- <div>
- <label for="sha256-short-hex-input">SHA-256 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha256-short-hex-input" onchange="calcHash('sha256-short', 'SHA-256')" />
- </div>
- <div>
- <label for="sha256-short-hex-result">SHA-256 Med Hex Result:</label><input type="text" size="75" disabled="disabled" id="sha256-short-hex-result" />
- <span id="sha256-short-hex-comp"></span>
- </div>
- <div>
- <label for="sha256-short-correct">SHA-256 Med Correct:</label><input type="text" size="75" value="ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" disabled="disabled" id="sha256-short-correct" />
- </div>
- <div>
- <label for="sha256-long-ascii-input">SHA-256 Long ASCII Input:</label><input type="text" size="60" value="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" id="sha256-long-ascii-input" onchange="calcHash('sha256-long', 'SHA-256')" />
- </div>
- <div>
- <label for="sha256-long-ascii-result">SHA-256 Long ASCII Result:</label><input type="text" size="75" disabled="disabled" id="sha256-long-ascii-result" />
- <span id="sha256-long-ascii-comp"></span>
- </div>
- <div>
- <label for="sha256-long-hex-input">SHA-256 Long Hex Input:</label><input type="text" size="140" value="6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071" id="sha256-long-hex-input" onchange="calcHash('sha256-long', 'SHA-256')" />
- </div>
- <div>
- <label for="sha256-long-hex-result">SHA-256 Long Hex Result:</label><input type="text" size="75" disabled="disabled" id="sha256-long-hex-result" />
- <span id="sha256-long-hex-comp"></span>
- </div>
- <div>
- <label for="sha256-long-correct">SHA-256 Long Correct:</label><input type="text" size="75" value="248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" disabled="disabled" id="sha256-long-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>SHA-384 Tests</legend>
- <div>
- <label for="sha384-short-ascii-input">SHA-384 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha384-short-ascii-input" onchange="calcHash('sha384-short', 'SHA-384')" />
- </div>
- <div>
- <label for="sha384-short-ascii-result">SHA-384 Med ASCII Result:</label><input type="text" size="115" disabled="disabled" id="sha384-short-ascii-result" />
- <span id="sha384-short-ascii-comp"></span>
- </div>
- <div>
- <label for="sha384-short-hex-input">SHA-384 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha384-short-hex-input" onchange="calcHash('sha384-short', 'SHA-384')" />
- </div>
- <div>
- <label for="sha384-short-hex-result">SHA-384 Med Hex Result:</label><input type="text" size="115" disabled="disabled" id="sha384-short-hex-result" />
- <span id="sha384-short-hex-comp"></span>
- </div>
- <div>
- <label for="sha384-short-correct">SHA-384 Med Correct:</label><input type="text" size="115" value="cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" disabled="disabled" id="sha384-short-correct" />
- </div>
- <div>
- <label for="sha384-long-ascii-input">SHA-384 Long ASCII Input:</label><input type="text" size="120" value="abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" id="sha384-long-ascii-input" onchange="calcHash('sha384-long', 'SHA-384')" />
- </div>
- <div>
- <label for="sha384-long-ascii-result">SHA-384 Long ASCII Result:</label><input type="text" size="115" disabled="disabled" id="sha384-long-ascii-result" />
- <span id="sha384-long-ascii-comp"></span>
- </div>
- <div>
- <label for="sha384-long-hex-input">SHA-384 Long Hex Input:</label><input type="text" size="100" value="61626364656667686263646566676869636465666768696A6465666768696A6B65666768696A6B6C666768696A6B6C6D6768696A6B6C6D6E68696A6B6C6D6E6F696A6B6C6D6E6F706A6B6C6D6E6F70716B6C6D6E6F7071726C6D6E6F707172736D6E6F70717273746E6F707172737475" id="sha384-long-hex-input" onchange="calcHash('sha384-long', 'SHA-384')" />
- </div>
- <div>
- <label for="sha384-long-hex-result">SHA-384 Long Hex Result:</label><input type="text" size="115" disabled="disabled" id="sha384-long-hex-result" />
- <span id="sha384-long-hex-comp"></span>
- </div>
- <div>
- <label for="sha384-long-correct">SHA-384 Long Correct:</label><input type="text" size="115" value="09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039" disabled="disabled" id="sha384-long-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>SHA-512 Tests</legend>
- <div>
- <label for="sha512-short-ascii-input">SHA-512 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha512-short-ascii-input" onchange="calcHash('sha512-short', 'SHA-512')" />
- </div>
- <div>
- <label for="sha512-short-ascii-result">SHA-512 Med ASCII Result:</label><input type="text" size="150" disabled="disabled" id="sha512-short-ascii-result" />
- <span id="sha512-short-ascii-comp"></span>
- </div>
- <div>
- <label for="sha512-short-hex-input">SHA-512 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha512-short-hex-input" onchange="calcHash('sha512-short', 'SHA-512')" />
- </div>
- <div>
- <label for="sha512-short-hex-result">SHA-512 Med Hex Result:</label><input type="text" size="150" disabled="disabled" id="sha512-short-hex-result" />
- <span id="sha512-short-hex-comp"></span>
- </div>
- <div>
- <label for="sha512-short-correct">SHA-512 Med Correct:</label><input type="text" size="150" value="ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" disabled="disabled" id="sha512-short-correct" />
- </div>
- <div>
- <label for="sha512-long-ascii-input">SHA-512 Long ASCII Input:</label><input type="text" size="120" value="abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" id="sha512-long-ascii-input" onchange="calcHash('sha512-long', 'SHA-512')" />
- </div>
- <div>
- <label for="sha512-long-ascii-result">SHA-512 Long ASCII Result:</label><input type="text" size="150" disabled="disabled" id="sha512-long-ascii-result" />
- <span id="sha512-long-ascii-comp"></span>
- </div>
- <div>
- <label for="sha512-long-hex-input">SHA-512 Long Hex Input:</label><input type="text" size="100" value="61626364656667686263646566676869636465666768696A6465666768696A6B65666768696A6B6C666768696A6B6C6D6768696A6B6C6D6E68696A6B6C6D6E6F696A6B6C6D6E6F706A6B6C6D6E6F70716B6C6D6E6F7071726C6D6E6F707172736D6E6F70717273746E6F707172737475" id="sha512-long-hex-input" onchange="calcHash('sha512-long', 'SHA-512')" />
- </div>
- <div>
- <label for="sha512-long-hex-result">SHA-512 Long Hex Result:</label><input type="text" size="150" disabled="disabled" id="sha512-long-hex-result" />
- <span id="sha512-long-hex-comp"></span>
- </div>
- <div>
- <label for="sha512-long-correct">SHA-512 Long Correct:</label><input type="text" size="150" value="8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" disabled="disabled" id="sha512-long-correct" />
- </div>
- </fieldset>
- </form>
- <form method="get" action="test.html" onsubmit="return false">
- <fieldset>
- <legend>HMAC/SHA-1 Tests</legend>
-
- <div>
- <label for="hmac-sha1-short-text">HMAC/SHA-1 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha1-short-text" onchange="calcHMAC('hmac-sha1-short', 'ASCII', 'ASCII', 'SHA-1')" />
- </div>
- <div>
- <label for="hmac-sha1-short-key">HMAC/SHA-1 Short Hex Key:</label><input type="text" size="25" value="0123456789:;&lt;=>?@ABC" id="hmac-sha1-short-key" onchange="calcHMAC('hmac-sha1-short', 'ASCII', 'ASCII', 'SHA-1')" />
- </div>
- <div>
- <label for="hmac-sha1-short-result">HMAC/SHA-1 Short Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha1-short-result" />
- <span id="hmac-sha1-short-comp"></span>
- </div>
- <div>
- <label for="hmac-sha1-short-correct">HMAC/SHA-1 Short Correct:</label><input type="text" size="45" value="0922d3405faa3d194f82a45830737d5cc6c75d24" disabled="disabled" id="hmac-sha1-short-correct" />
- </div>
- <div>
- <label for="hmac-sha1-med-text">HMAC/SHA-1 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha1-med-text" onchange="calcHMAC('hmac-sha1-med', 'ASCII', 'HEX', 'SHA-1')" />
- </div>
- <div>
- <label for="hmac-sha1-med-key">HMAC/SHA-1 Med Hex Key:</label><input type="text" size="150" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha1-med-key" onchange="calcHMAC('hmac-sha1-med', 'ASCII', 'HEX', 'SHA-1')" />
- </div>
- <div>
- <label for="hmac-sha1-med-result">HMAC/SHA-1 Med Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha1-med-result" />
- <span id="hmac-sha1-med-comp"></span>
- </div>
- <div>
- <label for="hmac-sha1-med-correct">HMAC/SHA-1 Med Correct:</label><input type="text" size="45" value="4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a" disabled="disabled" id="hmac-sha1-med-correct" />
- </div>
- <div>
- <label for="hmac-sha1-large-text">HMAC/SHA-1 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha1-large-text" onchange="calcHMAC('hmac-sha1-large', 'HEX', 'HEX', 'SHA-1')" />
- </div>
- <div>
- <label for="hmac-sha1-large-key">HMAC/SHA-1 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha1-large-key" onchange="calcHMAC('hmac-sha1-large', 'HEX', 'HEX', 'SHA-1')" />
- </div>
- <div>
- <label for="hmac-sha1-large-result">HMAC/SHA-1 Large Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha1-large-result" />
- <span id="hmac-sha1-large-comp"></span>
- </div>
- <div>
- <label for="hmac-sha1-large-correct">HMAC/SHA-1 Large Correct:</label><input type="text" size="45" value="bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa" disabled="disabled" id="hmac-sha1-large-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>HMAC/SHA-224 Tests</legend>
- <div>
- <label for="hmac-sha224-short-text">HMAC/SHA-224 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha224-short-text" onchange="calcHMAC('hmac-sha224-short', 'ASCII', 'ASCII', 'SHA-224')" />
- </div>
- <div>
- <label for="hmac-sha224-short-key">HMAC/SHA-224 Short Hex Key:</label><input type="text" size="25" value="0123456789:;&lt;=>?@ABC" id="hmac-sha224-short-key" onchange="calcHMAC('hmac-sha224-short', 'ASCII', 'ASCII', 'SHA-224')" />
- </div>
- <div>
- <label for="hmac-sha224-short-result">HMAC/SHA-224 Short Hex Result:</label><input type="text" size="65" disabled="disabled" id="hmac-sha224-short-result" />
- <span id="hmac-sha224-short-comp"></span>
- </div>
- <div>
- <label for="hmac-sha224-short-correct">HMAC/SHA-224 Short Correct:</label><input type="text" size="65" value="ddef0a40cb7d50fb6ee6cea120ba26aa08f3077587b8ad1b8c8d12c7" disabled="disabled" id="hmac-sha224-short-correct" />
- </div>
- <div>
- <label for="hmac-sha224-med-text">HMAC/SHA-224 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha224-med-text" onchange="calcHMAC('hmac-sha224-med', 'ASCII', 'HEX', 'SHA-224')" />
- </div>
- <div>
- <label for="hmac-sha224-med-key">HMAC/SHA-224 Med Hex Key:</label><input type="text" size="150" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha224-med-key" onchange="calcHMAC('hmac-sha224-med', 'ASCII', 'HEX', 'SHA-224')" />
- </div>
- <div>
- <label for="hmac-sha224-med-result">HMAC/SHA-224 Med Hex Result:</label><input type="text" size="65" disabled="disabled" id="hmac-sha224-med-result" />
- <span id="hmac-sha224-med-comp"></span>
- </div>
- <div>
- <label for="hmac-sha224-med-correct">HMAC/SHA-224 Med Correct:</label><input type="text" size="65" value="a6a3e27f8b4cfaf2bd157cc5e87c5b5d7d7f22b009fa6644fbbd3813" disabled="disabled" id="hmac-sha224-med-correct" />
- </div>
- <div>
- <label for="hmac-sha224-large-text">HMAC/SHA-224 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha224-large-text" onchange="calcHMAC('hmac-sha224-large', 'HEX', 'HEX', 'SHA-224')" />
- </div>
- <div>
- <label for="hmac-sha224-large-key">HMAC/SHA-224 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha224-large-key" onchange="calcHMAC('hmac-sha224-large', 'HEX', 'HEX', 'SHA-224')" />
- </div>
- <div>
- <label for="hmac-sha224-large-result">HMAC/SHA-224 Large Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha224-large-result" />
- <span id="hmac-sha224-large-comp"></span>
- </div>
- <div>
- <label for="hmac-sha224-large-correct">HMAC/SHA-224 Large Correct:</label><input type="text" size="45" value="9c2919912e4453d727292cee4c678d3e105fe316f1195ef9cfafe9f0" disabled="disabled" id="hmac-sha224-large-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>HMAC/SHA-256 Tests</legend>
- <div>
- <label for="hmac-sha256-short-text">HMAC/SHA-256 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha256-short-text" onchange="calcHMAC('hmac-sha256-short', 'ASCII', 'ASCII', 'SHA-256')" />
- </div>
- <div>
- <label for="hmac-sha256-short-key">HMAC/SHA-256 Short Hex Key:</label><input type="text" size="25" value="0123456789:;&lt;=>?@ABC" id="hmac-sha256-short-key" onchange="calcHMAC('hmac-sha256-short', 'ASCII', 'ASCII', 'SHA-256')" />
- </div>
- <div>
- <label for="hmac-sha256-short-result">HMAC/SHA-256 Short Hex Result:</label><input type="text" size="75" disabled="disabled" id="hmac-sha256-short-result" />
- <span id="hmac-sha256-short-comp"></span>
- </div>
- <div>
- <label for="hmac-sha256-short-correct">HMAC/SHA-256 Short Correct:</label><input type="text" size="75" value="b8f20db541ea4309ca4ea9380cd0e834f71fbe9174a261380dc17eae6a3451d9" disabled="disabled" id="hmac-sha256-short-correct" />
- </div>
- <div>
- <label for="hmac-sha256-med-text">HMAC/SHA-256 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha256-med-text" onchange="calcHMAC('hmac-sha256-med', 'ASCII', 'HEX', 'SHA-256')" />
- </div>
- <div>
- <label for="hmac-sha256-med-key">HMAC/SHA-256 Med Hex Key:</label><input type="text" size="150" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha256-med-key" onchange="calcHMAC('hmac-sha256-med', 'ASCII', 'HEX', 'SHA-256')" />
- </div>
- <div>
- <label for="hmac-sha256-med-result">HMAC/SHA-256 Med Hex Result:</label><input type="text" size="75" disabled="disabled" id="hmac-sha256-med-result" />
- <span id="hmac-sha256-med-comp"></span>
- </div>
- <div>
- <label for="hmac-sha256-med-correct">HMAC/SHA-256 Med Correct:</label><input type="text" size="75" value="3519f0cddfa090f8ace819d9ae8501578c46920502c62baa47bfe6014864a93a" disabled="disabled" id="hmac-sha256-med-correct" />
- </div>
- <div>
- <label for="hmac-sha256-large-text">HMAC/SHA-256 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha256-large-text" onchange="calcHMAC('hmac-sha256-large', 'HEX', 'HEX', 'SHA-256')" />
- </div>
- <div>
- <label for="hmac-sha256-large-key">HMAC/SHA-256 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha256-large-key" onchange="calcHMAC('hmac-sha256-large', 'HEX', 'HEX', 'SHA-256')" />
- </div>
- <div>
- <label for="hmac-sha256-large-result">HMAC/SHA-256 Large Hex Result:</label><input type="text" size="75" disabled="disabled" id="hmac-sha256-large-result" />
- <span id="hmac-sha256-large-comp"></span>
- </div>
- <div>
- <label for="hmac-sha256-large-correct">HMAC/SHA-256 Large Correct:</label><input type="text" size="75" value="2d7d0d7f3e52ffe89d65c978f39d555bb48b0ba48d5b6eb404654ad1afdb4ca3" disabled="disabled" id="hmac-sha256-large-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>HMAC/SHA-384 Tests</legend>
- <div>
- <label for="hmac-sha384-short-text">HMAC/SHA-384 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha384-short-text" onchange="calcHMAC('hmac-sha384-short', 'ASCII', 'ASCII', 'SHA-384')" />
- </div>
- <div>
- <label for="hmac-sha384-short-key">HMAC/SHA-384 Short Hex Key:</label><input type="text" size="50" value="0123456789:;&lt;=>?@ABC0123456789:;&lt;=>?@ABC" id="hmac-sha384-short-key" onchange="calcHMAC('hmac-sha384-short', 'ASCII', 'ASCII', 'SHA-384')" />
- </div>
- <div>
- <label for="hmac-sha384-short-result">HMAC/SHA-384 Short Hex Result:</label><input type="text" size="115" disabled="disabled" id="hmac-sha384-short-result" />
- <span id="hmac-sha384-short-comp"></span>
- </div>
- <div>
- <label for="hmac-sha384-short-correct">HMAC/SHA-384 Short Correct:</label><input type="text" size="115" value="97ab4a9c2e17af122bb32b4b1678cff917ca700a111925f455ae25348214dcbd7d163c4a4e644e401b2f87cb1b752fc5" disabled="disabled" id="hmac-sha384-short-correct" />
- </div>
- <div>
- <label for="hmac-sha384-med-text">HMAC/SHA-384 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha384-med-text" onchange="calcHMAC('hmac-sha384-med', 'ASCII', 'HEX', 'SHA-384')" />
- </div>
- <div>
- <label for="hmac-sha384-med-key">HMAC/SHA-384 Med Hex Key:</label><input type="text" size="100" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha384-med-key" onchange="calcHMAC('hmac-sha384-med', 'ASCII', 'HEX', 'SHA-384')" />
- </div>
- <div>
- <label for="hmac-sha384-med-result">HMAC/SHA-384 Med Hex Result:</label><input type="text" size="115" disabled="disabled" id="hmac-sha384-med-result" />
- <span id="hmac-sha384-med-comp"></span>
- </div>
- <div>
- <label for="hmac-sha384-med-correct">HMAC/SHA-384 Med Correct:</label><input type="text" size="115" value="bed40c524441b2e0ebe20be79b914067a57a74adb4b008d9c2f9f944c89b0fa8ce23227002aa6c1d256ee276d697332e" disabled="disabled" id="hmac-sha384-med-correct" />
- </div>
- <div>
- <label for="hmac-sha384-large-text">HMAC/SHA-384 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha384-large-text" onchange="calcHMAC('hmac-sha384-large', 'HEX', 'HEX', 'SHA-384')" />
- </div>
- <div>
- <label for="hmac-sha384-large-key">HMAC/SHA-384 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha384-large-key" onchange="calcHMAC('hmac-sha384-large', 'HEX', 'HEX', 'SHA-384')" />
- </div>
- <div>
- <label for="hmac-sha384-large-result">HMAC/SHA-384 Large Hex Result:</label><input type="text" size="115" disabled="disabled" id="hmac-sha384-large-result" />
- <span id="hmac-sha384-large-comp"></span>
- </div>
- <div>
- <label for="hmac-sha384-large-correct">HMAC/SHA-384 Large Correct:</label><input type="text" size="115" value="96b8cfd4340494cd12bd2e4d5df413b5585020d6fa078659cdf938c35e3fcdee84af95e8e598481dc5f064126d561c31" disabled="disabled" id="hmac-sha384-large-correct" />
- </div>
- </fieldset>
- <fieldset>
- <legend>HMAC/SHA-512 Tests</legend>
- <div>
- <label for="hmac-sha512-short-text">HMAC/SHA-512 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha512-short-text" onchange="calcHMAC('hmac-sha512-short', 'ASCII', 'ASCII', 'SHA-512')" />
- </div>
- <div>
- <label for="hmac-sha512-short-key">HMAC/SHA-512 Short Hex Key:</label><input type="text" size="50" value="0123456789:;&lt;=>?@ABC0123456789:;&lt;=>?@ABC" id="hmac-sha512-short-key" onchange="calcHMAC('hmac-sha512-short', 'ASCII', 'ASCII', 'SHA-512')" />
- </div>
- <div>
- <label for="hmac-sha512-short-result">HMAC/SHA-512 Short Hex Result:</label><input type="text" size="150" disabled="disabled" id="hmac-sha512-short-result" />
- <span id="hmac-sha512-short-comp"></span>
- </div>
- <div>
- <label for="hmac-sha512-short-correct">HMAC/SHA-512 Short Correct:</label><input type="text" size="150" value="74ed1131b8e37c0e18829b7ae7d99925664cfe055c2d01fa00d0f152ac321a50f3ef1ee91a36fd6248de60ede4196a4f9e5acca4981a09a91a0745d674ca11d3" disabled="disabled" id="hmac-sha512-short-correct" />
- </div>
- <div>
- <label for="hmac-sha512-med-text">HMAC/SHA-512 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha512-med-text" onchange="calcHMAC('hmac-sha512-med', 'ASCII', 'HEX', 'SHA-512')" />
- </div>
- <div>
- <label for="hmac-sha512-med-key">HMAC/SHA-512 Med Hex Key:</label><input type="text" size="100" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha512-med-key" onchange="calcHMAC('hmac-sha512-med', 'ASCII', 'HEX', 'SHA-512')" />
- </div>
- <div>
- <label for="hmac-sha512-med-result">HMAC/SHA-512 Med Hex Result:</label><input type="text" size="150" disabled="disabled" id="hmac-sha512-med-result" />
- <span id="hmac-sha512-med-comp"></span>
- </div>
- <div>
- <label for="hmac-sha512-med-correct">HMAC/SHA-512 Med Correct:</label><input type="text" size="150" value="e3c46b747b407ae103d75d94cc2247d6fef607a019e9dca6a1183966a163eb19317e7642da27b6e6ed22fea8224c493d5f20a458f83a555b94264253ddceb242" disabled="disabled" id="hmac-sha512-med-correct" />
- </div>
- <div>
- <label for="hmac-sha512-large-text">HMAC/SHA-512 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha512-large-text" onchange="calcHMAC('hmac-sha512-large', 'HEX', 'HEX', 'SHA-512')" />
- </div>
- <div>
- <label for="hmac-sha512-large-key">HMAC/SHA-512 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha512-large-key" onchange="calcHMAC('hmac-sha512-large', 'HEX', 'HEX', 'SHA-512')" />
- </div>
- <div>
- <label for="hmac-sha512-large-result">HMAC/SHA-512 Large Hex Result:</label><input type="text" size="150" disabled="disabled" id="hmac-sha512-large-result" />
- <span id="hmac-sha512-large-comp"></span>
- </div>
- <div>
- <label for="hmac-sha512-large-correct">HMAC/SHA-512 Large Correct:</label><input type="text" size="150" value="a2a8627f166e8c52d95fbf5c55271d466d43b73696e94977d08262f021d9a916f9d10f09f40db64e038c2ed3b16fbb9e61082c9173acfa86445612ccd4d8836c" disabled="disabled" id="hmac-sha512-large-correct" />
- </div>
- </fieldset>
- </form>
- </body>
-</html>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
+ <head>
+ <title>jsSHA (http://jssha.sourceforge.net/) - Test</title>
+ <script type="text/javascript" src="../src/sha.js"></script>
+ <meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
+ <style type="text/css">
+ label
+ {
+ width: 290px;
+ display: block;
+ float: left;
+ text-align: right;
+ padding-right: 10px;
+ }
+
+ .correct
+ {
+ color: #00FF00;
+ background-color: #FFFFFF;
+ }
+
+ .incorrect
+ {
+ color: #FF0000;
+ background-color: #FFFFFF;
+ }
+ </style>
+ <script type="text/javascript">
+ function calcHashes()
+ {
+ calcHash("sha1-short", "SHA-1");
+ calcHash("sha1-long", "SHA-1");
+ calcHash("sha224-short", "SHA-224");
+ calcHash("sha224-long", "SHA-224");
+ calcHash("sha256-short", "SHA-256");
+ calcHash("sha256-long", "SHA-256");
+ calcHash("sha384-short", "SHA-384");
+ calcHash("sha384-long", "SHA-384");
+ calcHash("sha512-long", "SHA-512");
+ calcHash("sha512-short", "SHA-512");
+ calcHMAC('hmac-sha1-short', "ASCII", "ASCII", "SHA-1");
+ calcHMAC('hmac-sha1-med', "ASCII", "HEX", "SHA-1");
+ calcHMAC('hmac-sha1-large', "HEX", "HEX", "SHA-1");
+ calcHMAC('hmac-sha224-short', "ASCII", "ASCII", "SHA-224");
+ calcHMAC('hmac-sha224-med', "ASCII", "HEX", "SHA-224");
+ calcHMAC('hmac-sha224-large', "HEX", "HEX", "SHA-224");
+ calcHMAC('hmac-sha256-short', "ASCII", "ASCII", "SHA-256");
+ calcHMAC('hmac-sha256-med', "ASCII", "HEX", "SHA-256");
+ calcHMAC('hmac-sha256-large', "HEX", "HEX", "SHA-256");
+ calcHMAC('hmac-sha384-short', "ASCII", "ASCII", "SHA-384");
+ calcHMAC('hmac-sha384-med', "ASCII", "HEX", "SHA-384");
+ calcHMAC('hmac-sha384-large', "HEX", "HEX", "SHA-384");
+ calcHMAC('hmac-sha512-short', "ASCII", "ASCII", "SHA-512");
+ calcHMAC('hmac-sha512-med', "ASCII", "HEX", "SHA-512");
+ calcHMAC('hmac-sha512-large', "HEX", "HEX", "SHA-512");
+ }
+
+ function calcHash(fieldGroupName, variant)
+ {
+ var tmp = document.getElementById(fieldGroupName+"-ascii-comp");
+
+ var shaObj = new jsSHA(document.getElementById(fieldGroupName+"-ascii-input").value, "ASCII");
+
+ document.getElementById(fieldGroupName+"-ascii-result").value = shaObj.getHash(variant, "HEX");
+ if (document.getElementById(fieldGroupName+"-ascii-result").value == document.getElementById(fieldGroupName+"-correct").value)
+ {
+ tmp.className = "correct";
+ tmp.innerHTML = "Match!";
+ } else {
+ tmp.className = "incorrect";
+ tmp.innerHTML = "Mismatch!";
+ }
+
+ tmp = document.getElementById(fieldGroupName+"-hex-comp");
+
+ shaObj = new jsSHA(document.getElementById(fieldGroupName+"-hex-input").value, "HEX");
+
+ document.getElementById(fieldGroupName+"-hex-result").value = shaObj.getHash(variant, "HEX");
+ if (document.getElementById(fieldGroupName+"-hex-result").value == document.getElementById(fieldGroupName+"-correct").value)
+ {
+ tmp.className = "correct";
+ tmp.innerHTML = "Match!";
+ } else {
+ tmp.className = "incorrect";
+ tmp.innerHTML = "Mismatch!";
+ }
+ }
+
+ function calcHMAC(fieldGroupName, textFormat, keyFormat, variant)
+ {
+ var tmp = document.getElementById(fieldGroupName+"-comp");
+
+ var shaObj = new jsSHA(document.getElementById(fieldGroupName+"-text").value, textFormat);
+
+ document.getElementById(fieldGroupName+"-result").value = shaObj.getHMAC(document.getElementById(fieldGroupName+"-key").value, keyFormat, variant, "HEX");
+ if (document.getElementById(fieldGroupName+"-result").value == document.getElementById(fieldGroupName+"-correct").value)
+ {
+ tmp.className = "correct";
+ tmp.innerHTML = "Match!";
+ } else {
+ tmp.className = "incorrect";
+ tmp.innerHTML = "Mismatch!";
+ }
+ }
+
+ </script>
+ </head>
+ <body onload="calcHashes()">
+ <h1><a href="http://jssha.sourceforge.net/">jsSHA</a> Hash Test Page</h1>
+ <p>
+ The short/long inputs as well as their correct hashes are supplied by the FIPS 180-2 specification; it can be found at <a href="http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf">http://csrc.nist.gov/publications/fips/fips180-2/fips180-2withchangenotice.pdf</a>. The short/medium/large inputs for HMAC and their corresponding correct hashes (at least for SHA-1) can be found at <a href="http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf">http://csrc.nist.gov/publications/fips/fips198/fips-198a.pdf</a>.
+ </p>
+
+ <p>
+ <span style="font-weight: bold">Instructions:</span> By default, this page should load 10 of the 15 test vectors given by the FIPS 180-2 specification and 3 of the 4 test vectors given by the FIPS 198a specification. You may also change any of the input values and then click off the input box to have the hash update.
+ </p>
+ <form method="get" action="test.html" onsubmit="return false">
+ <fieldset>
+ <legend>SHA-1 Tests</legend>
+ <div>
+ <label for="sha1-short-ascii-input">SHA-1 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha1-short-ascii-input" onchange="calcHash('sha1-short', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="sha1-short-ascii-result">SHA-1 Med ASCII Result:</label><input type="text" size="50" disabled="disabled" id="sha1-short-ascii-result" />
+ <span id="sha1-short-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha1-short-hex-input">SHA-1 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha1-short-hex-input" onchange="calcHash('sha1-short', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="sha1-short-hex-result">SHA-1 Med Hex Result:</label><input type="text" size="50" disabled="disabled" id="sha1-short-hex-result" />
+ <span id="sha1-short-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha1-short-correct">SHA-1 Med Correct:</label><input type="text" size="50" value="a9993e364706816aba3e25717850c26c9cd0d89d" disabled="disabled" id="sha1-short-correct" />
+ </div>
+ <div>
+ <label for="sha1-long-ascii-input">SHA-1 Long ASCII Input:</label><input type="text" size="60" value="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" id="sha1-long-ascii-input" onchange="calcHash('sha1-long', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="sha1-long-ascii-result">SHA-1 Long ASCII Result:</label><input type="text" size="50" disabled="disabled" id="sha1-long-ascii-result" />
+ <span id="sha1-long-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha1-long-hex-input">SHA-1 Long Hex Input:</label><input type="text" size="140" value="6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071" id="sha1-long-hex-input" onchange="calcHash('sha1-long', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="sha1-long-hex-result">SHA-1 Long Hex Result:</label><input type="text" size="50" disabled="disabled" id="sha1-long-hex-result" />
+ <span id="sha1-long-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha1-long-correct">SHA-1 Long Correct:</label><input type="text" size="50" value="84983e441c3bd26ebaae4aa1f95129e5e54670f1" disabled="disabled" id="sha1-long-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>SHA-224 Tests</legend>
+ <div>
+ <label for="sha224-short-ascii-input">SHA-224 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha224-short-ascii-input" onchange="calcHash('sha224-short', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="sha224-short-ascii-result">SHA-224 Med ASCII Result:</label><input type="text" size="65" disabled="disabled" id="sha224-short-ascii-result" />
+ <span id="sha224-short-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha224-short-hex-input">SHA-224 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha224-short-hex-input" onchange="calcHash('sha224-short', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="sha224-short-hex-result">SHA-224 Med Hex Result:</label><input type="text" size="65" disabled="disabled" id="sha224-short-hex-result" />
+ <span id="sha224-short-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha224-short-correct">SHA-224 Med Correct:</label><input type="text" size="65" value="23097d223405d8228642a477bda255b32aadbce4bda0b3f7e36c9da7" disabled="disabled" id="sha224-short-correct" />
+ </div>
+ <div>
+ <label for="sha224-long-ascii-input">SHA-224 Long ASCII Input:</label><input type="text" size="60" value="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" id="sha224-long-ascii-input" onchange="calcHash('sha224-long', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="sha224-long-ascii-result">SHA-224 Long ASCII Result:</label><input type="text" size="65" disabled="disabled" id="sha224-long-ascii-result" />
+ <span id="sha224-long-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha224-long-hex-input">SHA-224 Long Hex Input:</label><input type="text" size="140" value="6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071" id="sha224-long-hex-input" onchange="calcHash('sha224-long', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="sha224-long-hex-result">SHA-224 Long Hex Result:</label><input type="text" size="65" disabled="disabled" id="sha224-long-hex-result" />
+ <span id="sha224-long-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha224-long-correct">SHA-224 Long Correct:</label><input type="text" size="65" value="75388b16512776cc5dba5da1fd890150b0c6455cb4f58b1952522525" disabled="disabled" id="sha224-long-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>SHA-256 Tests</legend>
+ <div>
+ <label for="sha256-short-ascii-input">SHA-256 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha256-short-ascii-input" onchange="calcHash('sha256-short', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="sha256-short-ascii-result">SHA-256 Med ASCII Result:</label><input type="text" size="75" disabled="disabled" id="sha256-short-ascii-result" />
+ <span id="sha256-short-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha256-short-hex-input">SHA-256 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha256-short-hex-input" onchange="calcHash('sha256-short', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="sha256-short-hex-result">SHA-256 Med Hex Result:</label><input type="text" size="75" disabled="disabled" id="sha256-short-hex-result" />
+ <span id="sha256-short-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha256-short-correct">SHA-256 Med Correct:</label><input type="text" size="75" value="ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad" disabled="disabled" id="sha256-short-correct" />
+ </div>
+ <div>
+ <label for="sha256-long-ascii-input">SHA-256 Long ASCII Input:</label><input type="text" size="60" value="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" id="sha256-long-ascii-input" onchange="calcHash('sha256-long', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="sha256-long-ascii-result">SHA-256 Long ASCII Result:</label><input type="text" size="75" disabled="disabled" id="sha256-long-ascii-result" />
+ <span id="sha256-long-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha256-long-hex-input">SHA-256 Long Hex Input:</label><input type="text" size="140" value="6162636462636465636465666465666765666768666768696768696A68696A6B696A6B6C6A6B6C6D6B6C6D6E6C6D6E6F6D6E6F706E6F7071" id="sha256-long-hex-input" onchange="calcHash('sha256-long', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="sha256-long-hex-result">SHA-256 Long Hex Result:</label><input type="text" size="75" disabled="disabled" id="sha256-long-hex-result" />
+ <span id="sha256-long-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha256-long-correct">SHA-256 Long Correct:</label><input type="text" size="75" value="248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1" disabled="disabled" id="sha256-long-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>SHA-384 Tests</legend>
+ <div>
+ <label for="sha384-short-ascii-input">SHA-384 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha384-short-ascii-input" onchange="calcHash('sha384-short', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="sha384-short-ascii-result">SHA-384 Med ASCII Result:</label><input type="text" size="115" disabled="disabled" id="sha384-short-ascii-result" />
+ <span id="sha384-short-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha384-short-hex-input">SHA-384 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha384-short-hex-input" onchange="calcHash('sha384-short', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="sha384-short-hex-result">SHA-384 Med Hex Result:</label><input type="text" size="115" disabled="disabled" id="sha384-short-hex-result" />
+ <span id="sha384-short-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha384-short-correct">SHA-384 Med Correct:</label><input type="text" size="115" value="cb00753f45a35e8bb5a03d699ac65007272c32ab0eded1631a8b605a43ff5bed8086072ba1e7cc2358baeca134c825a7" disabled="disabled" id="sha384-short-correct" />
+ </div>
+ <div>
+ <label for="sha384-long-ascii-input">SHA-384 Long ASCII Input:</label><input type="text" size="120" value="abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" id="sha384-long-ascii-input" onchange="calcHash('sha384-long', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="sha384-long-ascii-result">SHA-384 Long ASCII Result:</label><input type="text" size="115" disabled="disabled" id="sha384-long-ascii-result" />
+ <span id="sha384-long-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha384-long-hex-input">SHA-384 Long Hex Input:</label><input type="text" size="100" value="61626364656667686263646566676869636465666768696A6465666768696A6B65666768696A6B6C666768696A6B6C6D6768696A6B6C6D6E68696A6B6C6D6E6F696A6B6C6D6E6F706A6B6C6D6E6F70716B6C6D6E6F7071726C6D6E6F707172736D6E6F70717273746E6F707172737475" id="sha384-long-hex-input" onchange="calcHash('sha384-long', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="sha384-long-hex-result">SHA-384 Long Hex Result:</label><input type="text" size="115" disabled="disabled" id="sha384-long-hex-result" />
+ <span id="sha384-long-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha384-long-correct">SHA-384 Long Correct:</label><input type="text" size="115" value="09330c33f71147e83d192fc782cd1b4753111b173b3b05d22fa08086e3b0f712fcc7c71a557e2db966c3e9fa91746039" disabled="disabled" id="sha384-long-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>SHA-512 Tests</legend>
+ <div>
+ <label for="sha512-short-ascii-input">SHA-512 Med ASCII Input:</label><input type="text" size="5" value="abc" id="sha512-short-ascii-input" onchange="calcHash('sha512-short', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="sha512-short-ascii-result">SHA-512 Med ASCII Result:</label><input type="text" size="150" disabled="disabled" id="sha512-short-ascii-result" />
+ <span id="sha512-short-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha512-short-hex-input">SHA-512 Med Hex Input:</label><input type="text" size="10" value="616263" id="sha512-short-hex-input" onchange="calcHash('sha512-short', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="sha512-short-hex-result">SHA-512 Med Hex Result:</label><input type="text" size="150" disabled="disabled" id="sha512-short-hex-result" />
+ <span id="sha512-short-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha512-short-correct">SHA-512 Med Correct:</label><input type="text" size="150" value="ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f" disabled="disabled" id="sha512-short-correct" />
+ </div>
+ <div>
+ <label for="sha512-long-ascii-input">SHA-512 Long ASCII Input:</label><input type="text" size="120" value="abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu" id="sha512-long-ascii-input" onchange="calcHash('sha512-long', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="sha512-long-ascii-result">SHA-512 Long ASCII Result:</label><input type="text" size="150" disabled="disabled" id="sha512-long-ascii-result" />
+ <span id="sha512-long-ascii-comp"></span>
+ </div>
+ <div>
+ <label for="sha512-long-hex-input">SHA-512 Long Hex Input:</label><input type="text" size="100" value="61626364656667686263646566676869636465666768696A6465666768696A6B65666768696A6B6C666768696A6B6C6D6768696A6B6C6D6E68696A6B6C6D6E6F696A6B6C6D6E6F706A6B6C6D6E6F70716B6C6D6E6F7071726C6D6E6F707172736D6E6F70717273746E6F707172737475" id="sha512-long-hex-input" onchange="calcHash('sha512-long', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="sha512-long-hex-result">SHA-512 Long Hex Result:</label><input type="text" size="150" disabled="disabled" id="sha512-long-hex-result" />
+ <span id="sha512-long-hex-comp"></span>
+ </div>
+ <div>
+ <label for="sha512-long-correct">SHA-512 Long Correct:</label><input type="text" size="150" value="8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909" disabled="disabled" id="sha512-long-correct" />
+ </div>
+ </fieldset>
+ </form>
+ <form method="get" action="test.html" onsubmit="return false">
+ <fieldset>
+ <legend>HMAC/SHA-1 Tests</legend>
+
+ <div>
+ <label for="hmac-sha1-short-text">HMAC/SHA-1 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha1-short-text" onchange="calcHMAC('hmac-sha1-short', 'ASCII', 'ASCII', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="hmac-sha1-short-key">HMAC/SHA-1 Short Hex Key:</label><input type="text" size="25" value="0123456789:;&lt;=>?@ABC" id="hmac-sha1-short-key" onchange="calcHMAC('hmac-sha1-short', 'ASCII', 'ASCII', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="hmac-sha1-short-result">HMAC/SHA-1 Short Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha1-short-result" />
+ <span id="hmac-sha1-short-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha1-short-correct">HMAC/SHA-1 Short Correct:</label><input type="text" size="45" value="0922d3405faa3d194f82a45830737d5cc6c75d24" disabled="disabled" id="hmac-sha1-short-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha1-med-text">HMAC/SHA-1 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha1-med-text" onchange="calcHMAC('hmac-sha1-med', 'ASCII', 'HEX', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="hmac-sha1-med-key">HMAC/SHA-1 Med Hex Key:</label><input type="text" size="150" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha1-med-key" onchange="calcHMAC('hmac-sha1-med', 'ASCII', 'HEX', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="hmac-sha1-med-result">HMAC/SHA-1 Med Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha1-med-result" />
+ <span id="hmac-sha1-med-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha1-med-correct">HMAC/SHA-1 Med Correct:</label><input type="text" size="45" value="4f4ca3d5d68ba7cc0a1208c9c61e9c5da0403c0a" disabled="disabled" id="hmac-sha1-med-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha1-large-text">HMAC/SHA-1 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha1-large-text" onchange="calcHMAC('hmac-sha1-large', 'HEX', 'HEX', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="hmac-sha1-large-key">HMAC/SHA-1 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha1-large-key" onchange="calcHMAC('hmac-sha1-large', 'HEX', 'HEX', 'SHA-1')" />
+ </div>
+ <div>
+ <label for="hmac-sha1-large-result">HMAC/SHA-1 Large Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha1-large-result" />
+ <span id="hmac-sha1-large-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha1-large-correct">HMAC/SHA-1 Large Correct:</label><input type="text" size="45" value="bcf41eab8bb2d802f3d05caf7cb092ecf8d1a3aa" disabled="disabled" id="hmac-sha1-large-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>HMAC/SHA-224 Tests</legend>
+ <div>
+ <label for="hmac-sha224-short-text">HMAC/SHA-224 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha224-short-text" onchange="calcHMAC('hmac-sha224-short', 'ASCII', 'ASCII', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="hmac-sha224-short-key">HMAC/SHA-224 Short Hex Key:</label><input type="text" size="25" value="0123456789:;&lt;=>?@ABC" id="hmac-sha224-short-key" onchange="calcHMAC('hmac-sha224-short', 'ASCII', 'ASCII', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="hmac-sha224-short-result">HMAC/SHA-224 Short Hex Result:</label><input type="text" size="65" disabled="disabled" id="hmac-sha224-short-result" />
+ <span id="hmac-sha224-short-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha224-short-correct">HMAC/SHA-224 Short Correct:</label><input type="text" size="65" value="ddef0a40cb7d50fb6ee6cea120ba26aa08f3077587b8ad1b8c8d12c7" disabled="disabled" id="hmac-sha224-short-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha224-med-text">HMAC/SHA-224 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha224-med-text" onchange="calcHMAC('hmac-sha224-med', 'ASCII', 'HEX', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="hmac-sha224-med-key">HMAC/SHA-224 Med Hex Key:</label><input type="text" size="150" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha224-med-key" onchange="calcHMAC('hmac-sha224-med', 'ASCII', 'HEX', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="hmac-sha224-med-result">HMAC/SHA-224 Med Hex Result:</label><input type="text" size="65" disabled="disabled" id="hmac-sha224-med-result" />
+ <span id="hmac-sha224-med-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha224-med-correct">HMAC/SHA-224 Med Correct:</label><input type="text" size="65" value="a6a3e27f8b4cfaf2bd157cc5e87c5b5d7d7f22b009fa6644fbbd3813" disabled="disabled" id="hmac-sha224-med-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha224-large-text">HMAC/SHA-224 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha224-large-text" onchange="calcHMAC('hmac-sha224-large', 'HEX', 'HEX', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="hmac-sha224-large-key">HMAC/SHA-224 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha224-large-key" onchange="calcHMAC('hmac-sha224-large', 'HEX', 'HEX', 'SHA-224')" />
+ </div>
+ <div>
+ <label for="hmac-sha224-large-result">HMAC/SHA-224 Large Hex Result:</label><input type="text" size="45" disabled="disabled" id="hmac-sha224-large-result" />
+ <span id="hmac-sha224-large-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha224-large-correct">HMAC/SHA-224 Large Correct:</label><input type="text" size="45" value="9c2919912e4453d727292cee4c678d3e105fe316f1195ef9cfafe9f0" disabled="disabled" id="hmac-sha224-large-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>HMAC/SHA-256 Tests</legend>
+ <div>
+ <label for="hmac-sha256-short-text">HMAC/SHA-256 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha256-short-text" onchange="calcHMAC('hmac-sha256-short', 'ASCII', 'ASCII', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="hmac-sha256-short-key">HMAC/SHA-256 Short Hex Key:</label><input type="text" size="25" value="0123456789:;&lt;=>?@ABC" id="hmac-sha256-short-key" onchange="calcHMAC('hmac-sha256-short', 'ASCII', 'ASCII', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="hmac-sha256-short-result">HMAC/SHA-256 Short Hex Result:</label><input type="text" size="75" disabled="disabled" id="hmac-sha256-short-result" />
+ <span id="hmac-sha256-short-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha256-short-correct">HMAC/SHA-256 Short Correct:</label><input type="text" size="75" value="b8f20db541ea4309ca4ea9380cd0e834f71fbe9174a261380dc17eae6a3451d9" disabled="disabled" id="hmac-sha256-short-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha256-med-text">HMAC/SHA-256 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha256-med-text" onchange="calcHMAC('hmac-sha256-med', 'ASCII', 'HEX', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="hmac-sha256-med-key">HMAC/SHA-256 Med Hex Key:</label><input type="text" size="150" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha256-med-key" onchange="calcHMAC('hmac-sha256-med', 'ASCII', 'HEX', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="hmac-sha256-med-result">HMAC/SHA-256 Med Hex Result:</label><input type="text" size="75" disabled="disabled" id="hmac-sha256-med-result" />
+ <span id="hmac-sha256-med-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha256-med-correct">HMAC/SHA-256 Med Correct:</label><input type="text" size="75" value="3519f0cddfa090f8ace819d9ae8501578c46920502c62baa47bfe6014864a93a" disabled="disabled" id="hmac-sha256-med-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha256-large-text">HMAC/SHA-256 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha256-large-text" onchange="calcHMAC('hmac-sha256-large', 'HEX', 'HEX', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="hmac-sha256-large-key">HMAC/SHA-256 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha256-large-key" onchange="calcHMAC('hmac-sha256-large', 'HEX', 'HEX', 'SHA-256')" />
+ </div>
+ <div>
+ <label for="hmac-sha256-large-result">HMAC/SHA-256 Large Hex Result:</label><input type="text" size="75" disabled="disabled" id="hmac-sha256-large-result" />
+ <span id="hmac-sha256-large-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha256-large-correct">HMAC/SHA-256 Large Correct:</label><input type="text" size="75" value="2d7d0d7f3e52ffe89d65c978f39d555bb48b0ba48d5b6eb404654ad1afdb4ca3" disabled="disabled" id="hmac-sha256-large-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>HMAC/SHA-384 Tests</legend>
+ <div>
+ <label for="hmac-sha384-short-text">HMAC/SHA-384 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha384-short-text" onchange="calcHMAC('hmac-sha384-short', 'ASCII', 'ASCII', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="hmac-sha384-short-key">HMAC/SHA-384 Short Hex Key:</label><input type="text" size="50" value="0123456789:;&lt;=>?@ABC0123456789:;&lt;=>?@ABC" id="hmac-sha384-short-key" onchange="calcHMAC('hmac-sha384-short', 'ASCII', 'ASCII', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="hmac-sha384-short-result">HMAC/SHA-384 Short Hex Result:</label><input type="text" size="115" disabled="disabled" id="hmac-sha384-short-result" />
+ <span id="hmac-sha384-short-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha384-short-correct">HMAC/SHA-384 Short Correct:</label><input type="text" size="115" value="97ab4a9c2e17af122bb32b4b1678cff917ca700a111925f455ae25348214dcbd7d163c4a4e644e401b2f87cb1b752fc5" disabled="disabled" id="hmac-sha384-short-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha384-med-text">HMAC/SHA-384 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha384-med-text" onchange="calcHMAC('hmac-sha384-med', 'ASCII', 'HEX', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="hmac-sha384-med-key">HMAC/SHA-384 Med Hex Key:</label><input type="text" size="100" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha384-med-key" onchange="calcHMAC('hmac-sha384-med', 'ASCII', 'HEX', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="hmac-sha384-med-result">HMAC/SHA-384 Med Hex Result:</label><input type="text" size="115" disabled="disabled" id="hmac-sha384-med-result" />
+ <span id="hmac-sha384-med-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha384-med-correct">HMAC/SHA-384 Med Correct:</label><input type="text" size="115" value="bed40c524441b2e0ebe20be79b914067a57a74adb4b008d9c2f9f944c89b0fa8ce23227002aa6c1d256ee276d697332e" disabled="disabled" id="hmac-sha384-med-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha384-large-text">HMAC/SHA-384 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha384-large-text" onchange="calcHMAC('hmac-sha384-large', 'HEX', 'HEX', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="hmac-sha384-large-key">HMAC/SHA-384 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha384-large-key" onchange="calcHMAC('hmac-sha384-large', 'HEX', 'HEX', 'SHA-384')" />
+ </div>
+ <div>
+ <label for="hmac-sha384-large-result">HMAC/SHA-384 Large Hex Result:</label><input type="text" size="115" disabled="disabled" id="hmac-sha384-large-result" />
+ <span id="hmac-sha384-large-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha384-large-correct">HMAC/SHA-384 Large Correct:</label><input type="text" size="115" value="96b8cfd4340494cd12bd2e4d5df413b5585020d6fa078659cdf938c35e3fcdee84af95e8e598481dc5f064126d561c31" disabled="disabled" id="hmac-sha384-large-correct" />
+ </div>
+ </fieldset>
+ <fieldset>
+ <legend>HMAC/SHA-512 Tests</legend>
+ <div>
+ <label for="hmac-sha512-short-text">HMAC/SHA-512 Short ASCII Text:</label><input type="text" size="10" value="Sample #2" id="hmac-sha512-short-text" onchange="calcHMAC('hmac-sha512-short', 'ASCII', 'ASCII', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="hmac-sha512-short-key">HMAC/SHA-512 Short Hex Key:</label><input type="text" size="50" value="0123456789:;&lt;=>?@ABC0123456789:;&lt;=>?@ABC" id="hmac-sha512-short-key" onchange="calcHMAC('hmac-sha512-short', 'ASCII', 'ASCII', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="hmac-sha512-short-result">HMAC/SHA-512 Short Hex Result:</label><input type="text" size="150" disabled="disabled" id="hmac-sha512-short-result" />
+ <span id="hmac-sha512-short-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha512-short-correct">HMAC/SHA-512 Short Correct:</label><input type="text" size="150" value="74ed1131b8e37c0e18829b7ae7d99925664cfe055c2d01fa00d0f152ac321a50f3ef1ee91a36fd6248de60ede4196a4f9e5acca4981a09a91a0745d674ca11d3" disabled="disabled" id="hmac-sha512-short-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha512-med-text">HMAC/SHA-512 Med ASCII Text:</label><input type="text" size="10" value="Sample #1" id="hmac-sha512-med-text" onchange="calcHMAC('hmac-sha512-med', 'ASCII', 'HEX', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="hmac-sha512-med-key">HMAC/SHA-512 Med Hex Key:</label><input type="text" size="100" value="000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" id="hmac-sha512-med-key" onchange="calcHMAC('hmac-sha512-med', 'ASCII', 'HEX', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="hmac-sha512-med-result">HMAC/SHA-512 Med Hex Result:</label><input type="text" size="150" disabled="disabled" id="hmac-sha512-med-result" />
+ <span id="hmac-sha512-med-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha512-med-correct">HMAC/SHA-512 Med Correct:</label><input type="text" size="150" value="e3c46b747b407ae103d75d94cc2247d6fef607a019e9dca6a1183966a163eb19317e7642da27b6e6ed22fea8224c493d5f20a458f83a555b94264253ddceb242" disabled="disabled" id="hmac-sha512-med-correct" />
+ </div>
+ <div>
+ <label for="hmac-sha512-large-text">HMAC/SHA-512 Large Hex Text:</label><input type="text" size="20" value="53616D706C65202333" id="hmac-sha512-large-text" onchange="calcHMAC('hmac-sha512-large', 'HEX', 'HEX', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="hmac-sha512-large-key">HMAC/SHA-512 Large Hex Key:</label><input type="text" size="100" value="505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3505152535455565758595a5b5c5d5e5f606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeafb0b1b2b3" id="hmac-sha512-large-key" onchange="calcHMAC('hmac-sha512-large', 'HEX', 'HEX', 'SHA-512')" />
+ </div>
+ <div>
+ <label for="hmac-sha512-large-result">HMAC/SHA-512 Large Hex Result:</label><input type="text" size="150" disabled="disabled" id="hmac-sha512-large-result" />
+ <span id="hmac-sha512-large-comp"></span>
+ </div>
+ <div>
+ <label for="hmac-sha512-large-correct">HMAC/SHA-512 Large Correct:</label><input type="text" size="150" value="a2a8627f166e8c52d95fbf5c55271d466d43b73696e94977d08262f021d9a916f9d10f09f40db64e038c2ed3b16fbb9e61082c9173acfa86445612ccd4d8836c" disabled="disabled" id="hmac-sha512-large-correct" />
+ </div>
+ </fieldset>
+ </form>
+ </body>
+</html>