Refactor src/crypto/hash/*.js to use import & export
This commit is contained in:
parent
19a97bf117
commit
3aed324d51
|
@ -8,13 +8,14 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var sha = require('./sha.js'),
|
import sha from './sha.js';
|
||||||
asmCrypto = require('asmcrypto-lite'),
|
import asmCrypto from 'asmcrypto-lite';
|
||||||
Rusha = require('rusha'),
|
import Rusha from 'rusha';
|
||||||
rusha = new Rusha(),
|
import md5 from './md5.js';
|
||||||
md5 = require('./md5.js'),
|
import ripemd from './ripe-md.js';
|
||||||
ripemd = require('./ripe-md.js'),
|
import util from '../../util.js';
|
||||||
util = require('../../util.js'),
|
|
||||||
|
const rusha = new Rusha(),
|
||||||
nodeCrypto = util.getNodeCrypto(),
|
nodeCrypto = util.getNodeCrypto(),
|
||||||
Buffer = util.getNodeBuffer();
|
Buffer = util.getNodeBuffer();
|
||||||
|
|
||||||
|
|
|
@ -19,17 +19,17 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var util = require('../../util.js');
|
import util from '../../util.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MD5 hash
|
* MD5 hash
|
||||||
* @param {String} entree string to hash
|
* @param {String} entree string to hash
|
||||||
*/
|
*/
|
||||||
module.exports = function (entree) {
|
export default function(entree) {
|
||||||
var hex = md5(util.Uint8Array2str(entree));
|
var hex = md5(util.Uint8Array2str(entree));
|
||||||
var bin = util.str2Uint8Array(util.hex2bin(hex));
|
var bin = util.str2Uint8Array(util.hex2bin(hex));
|
||||||
return bin;
|
return bin;
|
||||||
};
|
}
|
||||||
|
|
||||||
function md5cycle(x, k) {
|
function md5cycle(x, k) {
|
||||||
var a = x[0],
|
var a = x[0],
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
* @module crypto/hash/ripe-md
|
* @module crypto/hash/ripe-md
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var util = require('../../util.js');
|
import util from '../../util.js';
|
||||||
|
|
||||||
var RMDsize = 160;
|
var RMDsize = 160;
|
||||||
var X = [];
|
var X = [];
|
||||||
|
@ -289,7 +289,7 @@ function RMD(message) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function RMDstring(message) {
|
export default function RMDstring(message) {
|
||||||
var hashcode = RMD(util.Uint8Array2str(message));
|
var hashcode = RMD(util.Uint8Array2str(message));
|
||||||
var retString = "";
|
var retString = "";
|
||||||
|
|
||||||
|
@ -299,5 +299,3 @@ function RMDstring(message) {
|
||||||
|
|
||||||
return util.str2Uint8Array(retString);
|
return util.str2Uint8Array(retString);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = RMDstring;
|
|
||||||
|
|
|
@ -19,12 +19,11 @@
|
||||||
* 1 = SHA-1, 2 = SHA-224/SHA-256, 4 = SHA-384/SHA-512
|
* 1 = SHA-1, 2 = SHA-224/SHA-256, 4 = SHA-384/SHA-512
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
var SUPPORTED_ALGS = 4 | 2 | 1;
|
var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
|
|
||||||
(function (global)
|
/**
|
||||||
{
|
|
||||||
"use strict";
|
|
||||||
/**
|
|
||||||
* Int_64 is a object for 2 32-bit numbers emulating a 64-bit number
|
* Int_64 is a object for 2 32-bit numbers emulating a 64-bit number
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -33,13 +32,13 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} msint_32 The most significant 32-bits of a 64-bit number
|
* @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
|
* @param {number} lsint_32 The least significant 32-bits of a 64-bit number
|
||||||
*/
|
*/
|
||||||
function Int_64(msint_32, lsint_32)
|
function Int_64(msint_32, lsint_32)
|
||||||
{
|
{
|
||||||
this.highOrder = msint_32;
|
this.highOrder = msint_32;
|
||||||
this.lowOrder = lsint_32;
|
this.lowOrder = lsint_32;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string to an array of big-endian words
|
* Convert a string to an array of big-endian words
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -50,8 +49,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* "value" contains the output number array and "binLen" is the binary
|
* "value" contains the output number array and "binLen" is the binary
|
||||||
* length of "value"
|
* length of "value"
|
||||||
*/
|
*/
|
||||||
function str2binb(str, utfType)
|
function str2binb(str, utfType)
|
||||||
{
|
{
|
||||||
var bin = [], codePnt, binArr = [], byteCnt = 0, i, j, offset;
|
var bin = [], codePnt, binArr = [], byteCnt = 0, i, j, offset;
|
||||||
|
|
||||||
if ("UTF8" === utfType)
|
if ("UTF8" === utfType)
|
||||||
|
@ -123,9 +122,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return {"value" : bin, "binLen" : byteCnt * 8};
|
return {"value" : bin, "binLen" : byteCnt * 8};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a hex string to an array of big-endian words
|
* Convert a hex string to an array of big-endian words
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -134,8 +133,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* "value" contains the output number array and "binLen" is the binary
|
* "value" contains the output number array and "binLen" is the binary
|
||||||
* length of "value"
|
* length of "value"
|
||||||
*/
|
*/
|
||||||
function hex2binb(str)
|
function hex2binb(str)
|
||||||
{
|
{
|
||||||
var bin = [], length = str.length, i, num, offset;
|
var bin = [], length = str.length, i, num, offset;
|
||||||
|
|
||||||
if (0 !== (length % 2))
|
if (0 !== (length % 2))
|
||||||
|
@ -162,9 +161,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"value" : bin, "binLen" : length * 4};
|
return {"value" : bin, "binLen" : length * 4};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a string of raw bytes to an array of big-endian words
|
* Convert a string of raw bytes to an array of big-endian words
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -173,8 +172,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* "value" contains the output number array and "binLen" is the binary
|
* "value" contains the output number array and "binLen" is the binary
|
||||||
* length of "value"
|
* length of "value"
|
||||||
*/
|
*/
|
||||||
function bytes2binb(str)
|
function bytes2binb(str)
|
||||||
{
|
{
|
||||||
var bin = [], codePnt, i, offset;
|
var bin = [], codePnt, i, offset;
|
||||||
|
|
||||||
for (i = 0; i < str.length; i += 1)
|
for (i = 0; i < str.length; i += 1)
|
||||||
|
@ -190,9 +189,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"value" : bin, "binLen" : str.length * 8};
|
return {"value" : bin, "binLen" : str.length * 8};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a Uint8Array of raw bytes to an array of big-endian 32-bit words
|
* Convert a Uint8Array of raw bytes to an array of big-endian 32-bit words
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -201,8 +200,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* "value" contains the output array and "binLen" is the binary
|
* "value" contains the output array and "binLen" is the binary
|
||||||
* length of "value"
|
* length of "value"
|
||||||
*/
|
*/
|
||||||
function typed2binb(array)
|
function typed2binb(array)
|
||||||
{
|
{
|
||||||
|
|
||||||
var bin = [], octet, i, offset;
|
var bin = [], octet, i, offset;
|
||||||
|
|
||||||
|
@ -219,9 +218,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"value" : bin, "binLen" : array.length * 8};
|
return {"value" : bin, "binLen" : array.length * 8};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert a base-64 string to an array of big-endian words
|
* Convert a base-64 string to an array of big-endian words
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -230,8 +229,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* "value" contains the output number array and "binLen" is the binary
|
* "value" contains the output number array and "binLen" is the binary
|
||||||
* length of "value"
|
* length of "value"
|
||||||
*/
|
*/
|
||||||
function b642binb(str)
|
function b642binb(str)
|
||||||
{
|
{
|
||||||
var retVal = [], byteCnt = 0, index, i, j, tmpInt, strPart, firstEqual, offset,
|
var retVal = [], byteCnt = 0, index, i, j, tmpInt, strPart, firstEqual, offset,
|
||||||
b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
|
@ -271,9 +270,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"value" : retVal, "binLen" : byteCnt * 8};
|
return {"value" : retVal, "binLen" : byteCnt * 8};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of big-endian words to a hex string.
|
* Convert an array of big-endian words to a hex string.
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -284,8 +283,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @return {string} Hexidecimal representation of the parameter in string
|
* @return {string} Hexidecimal representation of the parameter in string
|
||||||
* form
|
* form
|
||||||
*/
|
*/
|
||||||
function binb2hex(binarray, formatOpts)
|
function binb2hex(binarray, formatOpts)
|
||||||
{
|
{
|
||||||
var hex_tab = "0123456789abcdef", str = "",
|
var hex_tab = "0123456789abcdef", str = "",
|
||||||
length = binarray.length * 4, i, srcByte;
|
length = binarray.length * 4, i, srcByte;
|
||||||
|
|
||||||
|
@ -298,9 +297,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (formatOpts["outputUpper"]) ? str.toUpperCase() : str;
|
return (formatOpts["outputUpper"]) ? str.toUpperCase() : str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of big-endian words to a base-64 string
|
* Convert an array of big-endian words to a base-64 string
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -311,8 +310,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @return {string} Base-64 encoded representation of the parameter in
|
* @return {string} Base-64 encoded representation of the parameter in
|
||||||
* string form
|
* string form
|
||||||
*/
|
*/
|
||||||
function binb2b64(binarray, formatOpts)
|
function binb2b64(binarray, formatOpts)
|
||||||
{
|
{
|
||||||
var str = "", length = binarray.length * 4, i, j, triplet, offset, int1, int2,
|
var str = "", length = binarray.length * 4, i, j, triplet, offset, int1, int2,
|
||||||
b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
||||||
|
|
||||||
|
@ -338,9 +337,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of big-endian words to raw bytes string
|
* Convert an array of big-endian words to raw bytes string
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -350,8 +349,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @return {string} Raw bytes representation of the parameter in string
|
* @return {string} Raw bytes representation of the parameter in string
|
||||||
* form
|
* form
|
||||||
*/
|
*/
|
||||||
function binb2bytes(binarray, formatOpts)
|
function binb2bytes(binarray, formatOpts)
|
||||||
{
|
{
|
||||||
var str = "", length = binarray.length * 4, i, srcByte;
|
var str = "", length = binarray.length * 4, i, srcByte;
|
||||||
|
|
||||||
for (i = 0; i < length; i += 1)
|
for (i = 0; i < length; i += 1)
|
||||||
|
@ -361,9 +360,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert an array of big-endian words to raw bytes Uint8Array
|
* Convert an array of big-endian words to raw bytes Uint8Array
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -372,8 +371,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {!Object} formatOpts Unused Hash list
|
* @param {!Object} formatOpts Unused Hash list
|
||||||
* @return {Uint8Array} Raw bytes representation of the parameter
|
* @return {Uint8Array} Raw bytes representation of the parameter
|
||||||
*/
|
*/
|
||||||
function binb2typed(binarray, formatOpts)
|
function binb2typed(binarray, formatOpts)
|
||||||
{
|
{
|
||||||
var length = binarray.length * 4;
|
var length = binarray.length * 4;
|
||||||
var arr = new Uint8Array(length), i;
|
var arr = new Uint8Array(length), i;
|
||||||
|
|
||||||
|
@ -383,9 +382,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate hash list containing output formatting options, ensuring
|
* Validate hash list containing output formatting options, ensuring
|
||||||
* presence of every option or adding the default value
|
* presence of every option or adding the default value
|
||||||
*
|
*
|
||||||
|
@ -395,8 +394,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @return {{outputUpper : boolean, b64Pad : string}} Validated hash list
|
* @return {{outputUpper : boolean, b64Pad : string}} Validated hash list
|
||||||
* containing output formatting options
|
* containing output formatting options
|
||||||
*/
|
*/
|
||||||
function getOutputOpts(outputOpts)
|
function getOutputOpts(outputOpts)
|
||||||
{
|
{
|
||||||
var retVal = {"outputUpper" : false, "b64Pad" : "="};
|
var retVal = {"outputUpper" : false, "b64Pad" : "="};
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -425,9 +424,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of circular rotate left
|
* The 32-bit implementation of circular rotate left
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -435,12 +434,12 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} n The number of bits to shift
|
* @param {number} n The number of bits to shift
|
||||||
* @return {number} The x shifted circularly by n bits
|
* @return {number} The x shifted circularly by n bits
|
||||||
*/
|
*/
|
||||||
function rotl_32(x, n)
|
function rotl_32(x, n)
|
||||||
{
|
{
|
||||||
return (x << n) | (x >>> (32 - n));
|
return (x << n) | (x >>> (32 - n));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of circular rotate right
|
* The 32-bit implementation of circular rotate right
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -448,12 +447,12 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} n The number of bits to shift
|
* @param {number} n The number of bits to shift
|
||||||
* @return {number} The x shifted circularly by n bits
|
* @return {number} The x shifted circularly by n bits
|
||||||
*/
|
*/
|
||||||
function rotr_32(x, n)
|
function rotr_32(x, n)
|
||||||
{
|
{
|
||||||
return (x >>> n) | (x << (32 - n));
|
return (x >>> n) | (x << (32 - n));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of circular rotate right
|
* The 64-bit implementation of circular rotate right
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -461,8 +460,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} n The number of bits to shift
|
* @param {number} n The number of bits to shift
|
||||||
* @return {Int_64} The x shifted circularly by n bits
|
* @return {Int_64} The x shifted circularly by n bits
|
||||||
*/
|
*/
|
||||||
function rotr_64(x, n)
|
function rotr_64(x, n)
|
||||||
{
|
{
|
||||||
var retVal = null, tmp = new Int_64(x.highOrder, x.lowOrder);
|
var retVal = null, tmp = new Int_64(x.highOrder, x.lowOrder);
|
||||||
|
|
||||||
if (32 >= n)
|
if (32 >= n)
|
||||||
|
@ -481,9 +480,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of shift right
|
* The 32-bit implementation of shift right
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -491,12 +490,12 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} n The number of bits to shift
|
* @param {number} n The number of bits to shift
|
||||||
* @return {number} The x shifted by n bits
|
* @return {number} The x shifted by n bits
|
||||||
*/
|
*/
|
||||||
function shr_32(x, n)
|
function shr_32(x, n)
|
||||||
{
|
{
|
||||||
return x >>> n;
|
return x >>> n;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of shift right
|
* The 64-bit implementation of shift right
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -504,8 +503,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} n The number of bits to shift
|
* @param {number} n The number of bits to shift
|
||||||
* @return {Int_64} The x shifted by n bits
|
* @return {Int_64} The x shifted by n bits
|
||||||
*/
|
*/
|
||||||
function shr_64(x, n)
|
function shr_64(x, n)
|
||||||
{
|
{
|
||||||
var retVal = null;
|
var retVal = null;
|
||||||
|
|
||||||
if (32 >= n)
|
if (32 >= n)
|
||||||
|
@ -524,9 +523,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of the NIST specified Parity function
|
* The 32-bit implementation of the NIST specified Parity function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -535,12 +534,12 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} z The third 32-bit integer argument
|
* @param {number} z The third 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function parity_32(x, y, z)
|
function parity_32(x, y, z)
|
||||||
{
|
{
|
||||||
return x ^ y ^ z;
|
return x ^ y ^ z;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of the NIST specified Ch function
|
* The 32-bit implementation of the NIST specified Ch function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -549,12 +548,12 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} z The third 32-bit integer argument
|
* @param {number} z The third 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function ch_32(x, y, z)
|
function ch_32(x, y, z)
|
||||||
{
|
{
|
||||||
return (x & y) ^ (~x & z);
|
return (x & y) ^ (~x & z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of the NIST specified Ch function
|
* The 64-bit implementation of the NIST specified Ch function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -563,15 +562,15 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {Int_64} z The third 64-bit integer argument
|
* @param {Int_64} z The third 64-bit integer argument
|
||||||
* @return {Int_64} The NIST specified output of the function
|
* @return {Int_64} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function ch_64(x, y, z)
|
function ch_64(x, y, z)
|
||||||
{
|
{
|
||||||
return new Int_64(
|
return new Int_64(
|
||||||
(x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),
|
(x.highOrder & y.highOrder) ^ (~x.highOrder & z.highOrder),
|
||||||
(x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)
|
(x.lowOrder & y.lowOrder) ^ (~x.lowOrder & z.lowOrder)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of the NIST specified Maj function
|
* The 32-bit implementation of the NIST specified Maj function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -580,12 +579,12 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} z The third 32-bit integer argument
|
* @param {number} z The third 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function maj_32(x, y, z)
|
function maj_32(x, y, z)
|
||||||
{
|
{
|
||||||
return (x & y) ^ (x & z) ^ (y & z);
|
return (x & y) ^ (x & z) ^ (y & z);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of the NIST specified Maj function
|
* The 64-bit implementation of the NIST specified Maj function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -594,8 +593,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {Int_64} z The third 64-bit integer argument
|
* @param {Int_64} z The third 64-bit integer argument
|
||||||
* @return {Int_64} The NIST specified output of the function
|
* @return {Int_64} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function maj_64(x, y, z)
|
function maj_64(x, y, z)
|
||||||
{
|
{
|
||||||
return new Int_64(
|
return new Int_64(
|
||||||
(x.highOrder & y.highOrder) ^
|
(x.highOrder & y.highOrder) ^
|
||||||
(x.highOrder & z.highOrder) ^
|
(x.highOrder & z.highOrder) ^
|
||||||
|
@ -604,116 +603,116 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
(x.lowOrder & z.lowOrder) ^
|
(x.lowOrder & z.lowOrder) ^
|
||||||
(y.lowOrder & z.lowOrder)
|
(y.lowOrder & z.lowOrder)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of the NIST specified Sigma0 function
|
* The 32-bit implementation of the NIST specified Sigma0 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {number} x The 32-bit integer argument
|
* @param {number} x The 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function sigma0_32(x)
|
function sigma0_32(x)
|
||||||
{
|
{
|
||||||
return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22);
|
return rotr_32(x, 2) ^ rotr_32(x, 13) ^ rotr_32(x, 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of the NIST specified Sigma0 function
|
* The 64-bit implementation of the NIST specified Sigma0 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Int_64} x The 64-bit integer argument
|
* @param {Int_64} x The 64-bit integer argument
|
||||||
* @return {Int_64} The NIST specified output of the function
|
* @return {Int_64} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function sigma0_64(x)
|
function sigma0_64(x)
|
||||||
{
|
{
|
||||||
var rotr28 = rotr_64(x, 28), rotr34 = rotr_64(x, 34),
|
var rotr28 = rotr_64(x, 28), rotr34 = rotr_64(x, 34),
|
||||||
rotr39 = rotr_64(x, 39);
|
rotr39 = rotr_64(x, 39);
|
||||||
|
|
||||||
return new Int_64(
|
return new Int_64(
|
||||||
rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
|
rotr28.highOrder ^ rotr34.highOrder ^ rotr39.highOrder,
|
||||||
rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder);
|
rotr28.lowOrder ^ rotr34.lowOrder ^ rotr39.lowOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of the NIST specified Sigma1 function
|
* The 32-bit implementation of the NIST specified Sigma1 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {number} x The 32-bit integer argument
|
* @param {number} x The 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function sigma1_32(x)
|
function sigma1_32(x)
|
||||||
{
|
{
|
||||||
return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25);
|
return rotr_32(x, 6) ^ rotr_32(x, 11) ^ rotr_32(x, 25);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of the NIST specified Sigma1 function
|
* The 64-bit implementation of the NIST specified Sigma1 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Int_64} x The 64-bit integer argument
|
* @param {Int_64} x The 64-bit integer argument
|
||||||
* @return {Int_64} The NIST specified output of the function
|
* @return {Int_64} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function sigma1_64(x)
|
function sigma1_64(x)
|
||||||
{
|
{
|
||||||
var rotr14 = rotr_64(x, 14), rotr18 = rotr_64(x, 18),
|
var rotr14 = rotr_64(x, 14), rotr18 = rotr_64(x, 18),
|
||||||
rotr41 = rotr_64(x, 41);
|
rotr41 = rotr_64(x, 41);
|
||||||
|
|
||||||
return new Int_64(
|
return new Int_64(
|
||||||
rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,
|
rotr14.highOrder ^ rotr18.highOrder ^ rotr41.highOrder,
|
||||||
rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder);
|
rotr14.lowOrder ^ rotr18.lowOrder ^ rotr41.lowOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 32-bit implementation of the NIST specified Gamma0 function
|
* The 32-bit implementation of the NIST specified Gamma0 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {number} x The 32-bit integer argument
|
* @param {number} x The 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function gamma0_32(x)
|
function gamma0_32(x)
|
||||||
{
|
{
|
||||||
return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3);
|
return rotr_32(x, 7) ^ rotr_32(x, 18) ^ shr_32(x, 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of the NIST specified Gamma0 function
|
* The 64-bit implementation of the NIST specified Gamma0 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Int_64} x The 64-bit integer argument
|
* @param {Int_64} x The 64-bit integer argument
|
||||||
* @return {Int_64} The NIST specified output of the function
|
* @return {Int_64} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function gamma0_64(x)
|
function gamma0_64(x)
|
||||||
{
|
{
|
||||||
var rotr1 = rotr_64(x, 1), rotr8 = rotr_64(x, 8), shr7 = shr_64(x, 7);
|
var rotr1 = rotr_64(x, 1), rotr8 = rotr_64(x, 8), shr7 = shr_64(x, 7);
|
||||||
|
|
||||||
return new Int_64(
|
return new Int_64(
|
||||||
rotr1.highOrder ^ rotr8.highOrder ^ shr7.highOrder,
|
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
|
* The 32-bit implementation of the NIST specified Gamma1 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {number} x The 32-bit integer argument
|
* @param {number} x The 32-bit integer argument
|
||||||
* @return {number} The NIST specified output of the function
|
* @return {number} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function gamma1_32(x)
|
function gamma1_32(x)
|
||||||
{
|
{
|
||||||
return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10);
|
return rotr_32(x, 17) ^ rotr_32(x, 19) ^ shr_32(x, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The 64-bit implementation of the NIST specified Gamma1 function
|
* The 64-bit implementation of the NIST specified Gamma1 function
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
* @param {Int_64} x The 64-bit integer argument
|
* @param {Int_64} x The 64-bit integer argument
|
||||||
* @return {Int_64} The NIST specified output of the function
|
* @return {Int_64} The NIST specified output of the function
|
||||||
*/
|
*/
|
||||||
function gamma1_64(x)
|
function gamma1_64(x)
|
||||||
{
|
{
|
||||||
var rotr19 = rotr_64(x, 19), rotr61 = rotr_64(x, 61),
|
var rotr19 = rotr_64(x, 19), rotr61 = rotr_64(x, 61),
|
||||||
shr6 = shr_64(x, 6);
|
shr6 = shr_64(x, 6);
|
||||||
|
|
||||||
|
@ -721,9 +720,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
rotr19.highOrder ^ rotr61.highOrder ^ shr6.highOrder,
|
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
|
* Add two 32-bit integers, wrapping at 2^32. This uses 16-bit operations
|
||||||
* internally to work around bugs in some JS interpreters.
|
* internally to work around bugs in some JS interpreters.
|
||||||
*
|
*
|
||||||
|
@ -732,15 +731,15 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} b The second 32-bit integer argument to be added
|
* @param {number} b The second 32-bit integer argument to be added
|
||||||
* @return {number} The sum of a + b
|
* @return {number} The sum of a + b
|
||||||
*/
|
*/
|
||||||
function safeAdd_32_2(a, b)
|
function safeAdd_32_2(a, b)
|
||||||
{
|
{
|
||||||
var lsw = (a & 0xFFFF) + (b & 0xFFFF),
|
var lsw = (a & 0xFFFF) + (b & 0xFFFF),
|
||||||
msw = (a >>> 16) + (b >>> 16) + (lsw >>> 16);
|
msw = (a >>> 16) + (b >>> 16) + (lsw >>> 16);
|
||||||
|
|
||||||
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add four 32-bit integers, wrapping at 2^32. This uses 16-bit operations
|
* Add four 32-bit integers, wrapping at 2^32. This uses 16-bit operations
|
||||||
* internally to work around bugs in some JS interpreters.
|
* internally to work around bugs in some JS interpreters.
|
||||||
*
|
*
|
||||||
|
@ -751,16 +750,16 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} d The fourth 32-bit integer argument to be added
|
* @param {number} d The fourth 32-bit integer argument to be added
|
||||||
* @return {number} The sum of a + b + c + d
|
* @return {number} The sum of a + b + c + d
|
||||||
*/
|
*/
|
||||||
function safeAdd_32_4(a, b, c, d)
|
function safeAdd_32_4(a, b, c, d)
|
||||||
{
|
{
|
||||||
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF),
|
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF),
|
||||||
msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
|
msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
|
||||||
(lsw >>> 16);
|
(lsw >>> 16);
|
||||||
|
|
||||||
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add five 32-bit integers, wrapping at 2^32. This uses 16-bit operations
|
* Add five 32-bit integers, wrapping at 2^32. This uses 16-bit operations
|
||||||
* internally to work around bugs in some JS interpreters.
|
* internally to work around bugs in some JS interpreters.
|
||||||
*
|
*
|
||||||
|
@ -772,17 +771,17 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {number} e The fifth 32-bit integer argument to be added
|
* @param {number} e The fifth 32-bit integer argument to be added
|
||||||
* @return {number} The sum of a + b + c + d + e
|
* @return {number} The sum of a + b + c + d + e
|
||||||
*/
|
*/
|
||||||
function safeAdd_32_5(a, b, c, d, e)
|
function safeAdd_32_5(a, b, c, d, e)
|
||||||
{
|
{
|
||||||
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) +
|
var lsw = (a & 0xFFFF) + (b & 0xFFFF) + (c & 0xFFFF) + (d & 0xFFFF) +
|
||||||
(e & 0xFFFF),
|
(e & 0xFFFF),
|
||||||
msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
|
msw = (a >>> 16) + (b >>> 16) + (c >>> 16) + (d >>> 16) +
|
||||||
(e >>> 16) + (lsw >>> 16);
|
(e >>> 16) + (lsw >>> 16);
|
||||||
|
|
||||||
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
return ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add two 64-bit integers, wrapping at 2^64. This uses 16-bit operations
|
* Add two 64-bit integers, wrapping at 2^64. This uses 16-bit operations
|
||||||
* internally to work around bugs in some JS interpreters.
|
* internally to work around bugs in some JS interpreters.
|
||||||
*
|
*
|
||||||
|
@ -791,8 +790,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {Int_64} y The second 64-bit integer argument to be added
|
* @param {Int_64} y The second 64-bit integer argument to be added
|
||||||
* @return {Int_64} The sum of x + y
|
* @return {Int_64} The sum of x + y
|
||||||
*/
|
*/
|
||||||
function safeAdd_64_2(x, y)
|
function safeAdd_64_2(x, y)
|
||||||
{
|
{
|
||||||
var lsw, msw, lowOrder, highOrder;
|
var lsw, msw, lowOrder, highOrder;
|
||||||
|
|
||||||
lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
|
lsw = (x.lowOrder & 0xFFFF) + (y.lowOrder & 0xFFFF);
|
||||||
|
@ -804,9 +803,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
||||||
|
|
||||||
return new Int_64(highOrder, lowOrder);
|
return new Int_64(highOrder, lowOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add four 64-bit integers, wrapping at 2^64. This uses 16-bit operations
|
* Add four 64-bit integers, wrapping at 2^64. This uses 16-bit operations
|
||||||
* internally to work around bugs in some JS interpreters.
|
* internally to work around bugs in some JS interpreters.
|
||||||
*
|
*
|
||||||
|
@ -817,8 +816,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {Int_64} d The fouth 64-bit integer argument to be added
|
* @param {Int_64} d The fouth 64-bit integer argument to be added
|
||||||
* @return {Int_64} The sum of a + b + c + d
|
* @return {Int_64} The sum of a + b + c + d
|
||||||
*/
|
*/
|
||||||
function safeAdd_64_4(a, b, c, d)
|
function safeAdd_64_4(a, b, c, d)
|
||||||
{
|
{
|
||||||
var lsw, msw, lowOrder, highOrder;
|
var lsw, msw, lowOrder, highOrder;
|
||||||
|
|
||||||
lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
|
lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
|
||||||
|
@ -834,9 +833,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
||||||
|
|
||||||
return new Int_64(highOrder, lowOrder);
|
return new Int_64(highOrder, lowOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add five 64-bit integers, wrapping at 2^64. This uses 16-bit operations
|
* Add five 64-bit integers, wrapping at 2^64. This uses 16-bit operations
|
||||||
* internally to work around bugs in some JS interpreters.
|
* internally to work around bugs in some JS interpreters.
|
||||||
*
|
*
|
||||||
|
@ -848,8 +847,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {Int_64} e The fouth 64-bit integer argument to be added
|
* @param {Int_64} e The fouth 64-bit integer argument to be added
|
||||||
* @return {Int_64} The sum of a + b + c + d + e
|
* @return {Int_64} The sum of a + b + c + d + e
|
||||||
*/
|
*/
|
||||||
function safeAdd_64_5(a, b, c, d, e)
|
function safeAdd_64_5(a, b, c, d, e)
|
||||||
{
|
{
|
||||||
var lsw, msw, lowOrder, highOrder;
|
var lsw, msw, lowOrder, highOrder;
|
||||||
|
|
||||||
lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
|
lsw = (a.lowOrder & 0xFFFF) + (b.lowOrder & 0xFFFF) +
|
||||||
|
@ -869,9 +868,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
highOrder = ((msw & 0xFFFF) << 16) | (lsw & 0xFFFF);
|
||||||
|
|
||||||
return new Int_64(highOrder, lowOrder);
|
return new Int_64(highOrder, lowOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the SHA-1 hash of the string set at instantiation
|
* Calculates the SHA-1 hash of the string set at instantiation
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -881,8 +880,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @return {Array.<number>} The array of integers representing the SHA-1
|
* @return {Array.<number>} The array of integers representing the SHA-1
|
||||||
* hash of message
|
* hash of message
|
||||||
*/
|
*/
|
||||||
function coreSHA1(message, messageLen)
|
function coreSHA1(message, messageLen)
|
||||||
{
|
{
|
||||||
var W = [], a, b, c, d, e, T, ch = ch_32, parity = parity_32,
|
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,
|
maj = maj_32, rotl = rotl_32, safeAdd_2 = safeAdd_32_2, i, t,
|
||||||
safeAdd_5 = safeAdd_32_5, appendedMessageLength, offset,
|
safeAdd_5 = safeAdd_32_5, appendedMessageLength, offset,
|
||||||
|
@ -953,9 +952,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return H;
|
return H;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculates the desired SHA-2 hash of the string set at instantiation
|
* Calculates the desired SHA-2 hash of the string set at instantiation
|
||||||
*
|
*
|
||||||
* @private
|
* @private
|
||||||
|
@ -966,8 +965,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @return {Array.<number>} The array of integers representing the SHA-2
|
* @return {Array.<number>} The array of integers representing the SHA-2
|
||||||
* hash of message
|
* hash of message
|
||||||
*/
|
*/
|
||||||
function coreSHA2(message, messageLen, variant)
|
function coreSHA2(message, messageLen, variant)
|
||||||
{
|
{
|
||||||
var a, b, c, d, e, f, g, h, T1, T2, H, numRounds, lengthPosition, i, t,
|
var a, b, c, d, e, f, g, h, T1, T2, H, numRounds, lengthPosition, i, t,
|
||||||
binaryStringInc, binaryStringMult, safeAdd_2, safeAdd_4, safeAdd_5,
|
binaryStringInc, binaryStringMult, safeAdd_2, safeAdd_4, safeAdd_5,
|
||||||
gamma0, gamma1, sigma0, sigma1, ch, maj, Int, W = [], int1, int2, offset,
|
gamma0, gamma1, sigma0, sigma1, ch, maj, Int, W = [], int1, int2, offset,
|
||||||
|
@ -1220,9 +1219,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* jsSHA is the workhorse of the library. Instantiate it with the string to
|
* jsSHA is the workhorse of the library. Instantiate it with the string to
|
||||||
* be hashed as the parameter
|
* be hashed as the parameter
|
||||||
*
|
*
|
||||||
|
@ -1234,8 +1233,8 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
* @param {string=} encoding The text encoding to use to encode the source
|
* @param {string=} encoding The text encoding to use to encode the source
|
||||||
* string
|
* string
|
||||||
*/
|
*/
|
||||||
var jsSHA = function(srcString, inputFormat, encoding)
|
var jsSHA = function(srcString, inputFormat, encoding)
|
||||||
{
|
{
|
||||||
var strBinLen = 0, strToHash = [0], utfType = '', srcConvertRet = null;
|
var strBinLen = 0, strToHash = [0], utfType = '', srcConvertRet = null;
|
||||||
|
|
||||||
utfType = encoding || "UTF8";
|
utfType = encoding || "UTF8";
|
||||||
|
@ -1573,9 +1572,9 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
|
|
||||||
return formatFunc(retVal, getOutputOpts(outputFormatOpts));
|
return formatFunc(retVal, getOutputOpts(outputFormatOpts));
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = {
|
export default {
|
||||||
/** SHA1 hash */
|
/** SHA1 hash */
|
||||||
sha1: function(str) {
|
sha1: function(str) {
|
||||||
var shaObj = new jsSHA(str, "TYPED", "UTF8");
|
var shaObj = new jsSHA(str, "TYPED", "UTF8");
|
||||||
|
@ -1602,5 +1601,4 @@ var SUPPORTED_ALGS = 4 | 2 | 1;
|
||||||
var shaObj = new jsSHA(str, "TYPED", "UTF8");
|
var shaObj = new jsSHA(str, "TYPED", "UTF8");
|
||||||
return shaObj.getHash("SHA-512", "TYPED");
|
return shaObj.getHash("SHA-512", "TYPED");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}(this));
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user