src/sha_dev.js
function b642packed(str, existingPacked, existingPackedLen, bigEndianMod)
	{
		var packed, byteCnt = 0, index, i, j, tmpInt, strPart, firstEqual,
			b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
			existingByteLen, intOffset, byteOffset, shiftModifier;

		if (-1 === str.search(/^[a-zA-Z0-9=+\/]+$/))
		{
			throw new Error("Invalid character in base-64 string");
		}

		firstEqual = str.indexOf("=");
		str = str.replace(/\=/g, "");
		if ((-1 !== firstEqual) && (firstEqual < str.length))
		{
			throw new Error("Invalid '=' found in base-64 string");
		}

		packed = existingPacked || [0];
		existingPackedLen = existingPackedLen || 0;
		existingByteLen = existingPackedLen >>> 3;
		shiftModifier = (bigEndianMod === -1) ? 3 : 0;

		for (i = 0; i < str.length; i += 4)
		{
			strPart = str.substr(i, 4);
			tmpInt = 0;

			for (j = 0; j < strPart.length; j += 1)
			{
				index = b64Tab.indexOf(strPart[j]);
				tmpInt |= index << (18 - (6 * j));
			}

			for (j = 0; j < strPart.length - 1; j += 1)
			{
				byteOffset = byteCnt + existingByteLen;
				intOffset = byteOffset >>> 2;
				while (packed.length <= intOffset)
				{
					packed.push(0);
				}
				packed[intOffset] |= ((tmpInt >>> (16 - (j * 8))) & 0xFF) <<
					(8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));
				byteCnt += 1;
			}
		}

		return {"value" : packed, "binLen" : byteCnt * 8 + existingPackedLen};
	}
function b642packed(str, existingPacked, existingPackedLen, bigEndianMod)
	{
		var packed, byteCnt = 0, index, i, j, tmpInt, strPart, firstEqual,
			b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
			existingByteLen, intOffset, byteOffset, shiftModifier;

		if (-1 === str.search(/^[a-zA-Z0-9=+\/]+$/))
		{
			throw new Error("Invalid character in base-64 string");
		}

		firstEqual = str.indexOf("=");
		str = str.replace(/\=/g, "");
		if ((-1 !== firstEqual) && (firstEqual < str.length))
		{
			throw new Error("Invalid '=' found in base-64 string");
		}

		packed = existingPacked || [0];
		existingPackedLen = existingPackedLen || 0;
		existingByteLen = existingPackedLen >>> 3;
		shiftModifier = (bigEndianMod === -1) ? 3 : 0;

		for (i = 0; i < str.length; i += 4)
		{
			strPart = str.substr(i, 4);
			tmpInt = 0;

			for (j = 0; j < strPart.length; j += 1)
			{
				index = b64Tab.indexOf(strPart[j]);
				tmpInt |= index << (18 - (6 * j));
			}

			for (j = 0; j < strPart.length - 1; j += 1)
			{
				byteOffset = byteCnt + existingByteLen;
				intOffset = byteOffset >>> 2;
				while (packed.length <= intOffset)
				{
					packed.push(0);
				}
				packed[intOffset] |= ((tmpInt >>> (16 - (j * 8))) & 0xFF) <<
					(8 * (shiftModifier + bigEndianMod * (byteOffset % 4)));
				byteCnt += 1;
			}
		}

		return {"value" : packed, "binLen" : byteCnt * 8 + existingPackedLen};
	}
function b642packed ( str , existingPacked , existingPackedLen , bigEndianMod ) { var packed , byteCnt = 0 , index , i , j , tmpInt , strPart , firstEqual , b64Tab = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/" , existingByteLen , intOffset , byteOffset , shiftModifier ; if ( - 1 === str . search ( / ^[a-zA-Z0-9=+\/]+$ / ) ) { throw new Error ( "Invalid character in base-64 string" ) ; } firstEqual = str . indexOf ( "=" ) ; str = str . replace ( / \= / g , "" ) ; if ( ( - 1 !== firstEqual ) && ( firstEqual < str . length ) ) { throw new Error ( "Invalid '=' found in base-64 string" ) ; } packed = existingPacked || [ 0 ] ; existingPackedLen = existingPackedLen || 0 ; existingByteLen = existingPackedLen >>> 3 ; shiftModifier = ( bigEndianMod === - 1 ) ? 3 : 0 ; for ( i = 0 ; i < str . length ; i += 4 ) { strPart = str . substr ( i , 4 ) ; tmpInt = 0 ; for ( j = 0 ; j < strPart . length ; j += 1 ) { index = b64Tab . indexOf ( strPart [ j ] ) ; tmpInt |= index << ( 18 - ( 6 * j ) ) ; } for ( j = 0 ; j < strPart . length - 1 ; j += 1 ) { byteOffset = byteCnt + existingByteLen ; intOffset = byteOffset >>> 2 ; while ( packed . length <= intOffset ) { packed . push ( 0 ) ; } packed [ intOffset ] |= ( ( tmpInt >>> ( 16 - ( j * 8 ) ) ) & 0xFF ) << ( 8 * ( shiftModifier + bigEndianMod * ( byteOffset % 4 ) ) ) ; byteCnt += 1 ; } } return { "value" : packed , "binLen" : byteCnt * 8 + existingPackedLen } ; }
Convert a base-64 string to an array of big-endian words

@private
@param {string} str String to be converted to binary representation
@param {Array<number>} existingPacked A packed int array of bytes to
append the results to
@param {number} existingPackedLen The number of bits in the existingPacked
array
@param {number} bigEndianMod Modifier for whether hash function is
big or small endian
@return {{value : Array<number>, binLen : number}} Hash list where
"value" contains the output number array and "binLen" is the binary
length of "value"
Convert a base - 64 string to an array of big - endian words