src/sha_dev.js
function getNewState(variant)
	{
		var retVal = [], H_trunc, H_full, i;

		if (("SHA-1" === variant) && ((1 & SUPPORTED_ALGS) !== 0))
		{
			retVal = [
				0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
			];
		}
		else if ((variant.lastIndexOf("SHA-", 0) === 0) && ((6 & SUPPORTED_ALGS) !== 0))
		{
			H_trunc = [
				0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
				0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
			];
			H_full = [
				0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
				0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
			];

			switch (variant)
			{
			case "SHA-224":
				retVal = H_trunc;
				break;
			case "SHA-256":
				retVal = H_full;
				break;
			case "SHA-384":
				retVal = [
					new Int_64(0xcbbb9d5d, H_trunc[0]),
					new Int_64(0x0629a292a, H_trunc[1]),
					new Int_64(0x9159015a, H_trunc[2]),
					new Int_64(0x0152fecd8, H_trunc[3]),
					new Int_64(0x67332667, H_trunc[4]),
					new Int_64(0x98eb44a87, H_trunc[5]),
					new Int_64(0xdb0c2e0d, H_trunc[6]),
					new Int_64(0x047b5481d, H_trunc[7])
				];
				break;
			case "SHA-512":
				retVal = [
					new Int_64(H_full[0], 0xf3bcc908),
					new Int_64(H_full[1], 0x84caa73b),
					new Int_64(H_full[2], 0xfe94f82b),
					new Int_64(H_full[3], 0x5f1d36f1),
					new Int_64(H_full[4], 0xade682d1),
					new Int_64(H_full[5], 0x2b3e6c1f),
					new Int_64(H_full[6], 0xfb41bd6b),
					new Int_64(H_full[7], 0x137e2179)
				];
				break;
			default:
				throw new Error("Unknown SHA variant");
			}
		}
		else if (((variant.lastIndexOf("SHA3-", 0) === 0) || (variant.lastIndexOf("SHAKE", 0) === 0)) &&
			((8 & SUPPORTED_ALGS) !== 0))
		{
			for (i = 0; i < 5; i += 1)
			{
				retVal[i] = [new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0)];
			}
		}
		else
		{
			throw new Error("No SHA variants supported");
		}

		return retVal;
	}
function getNewState(variant)
	{
		var retVal = [], H_trunc, H_full, i;

		if (("SHA-1" === variant) && ((1 & SUPPORTED_ALGS) !== 0))
		{
			retVal = [
				0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0
			];
		}
		else if ((variant.lastIndexOf("SHA-", 0) === 0) && ((6 & SUPPORTED_ALGS) !== 0))
		{
			H_trunc = [
				0xc1059ed8, 0x367cd507, 0x3070dd17, 0xf70e5939,
				0xffc00b31, 0x68581511, 0x64f98fa7, 0xbefa4fa4
			];
			H_full = [
				0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A,
				0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19
			];

			switch (variant)
			{
			case "SHA-224":
				retVal = H_trunc;
				break;
			case "SHA-256":
				retVal = H_full;
				break;
			case "SHA-384":
				retVal = [
					new Int_64(0xcbbb9d5d, H_trunc[0]),
					new Int_64(0x0629a292a, H_trunc[1]),
					new Int_64(0x9159015a, H_trunc[2]),
					new Int_64(0x0152fecd8, H_trunc[3]),
					new Int_64(0x67332667, H_trunc[4]),
					new Int_64(0x98eb44a87, H_trunc[5]),
					new Int_64(0xdb0c2e0d, H_trunc[6]),
					new Int_64(0x047b5481d, H_trunc[7])
				];
				break;
			case "SHA-512":
				retVal = [
					new Int_64(H_full[0], 0xf3bcc908),
					new Int_64(H_full[1], 0x84caa73b),
					new Int_64(H_full[2], 0xfe94f82b),
					new Int_64(H_full[3], 0x5f1d36f1),
					new Int_64(H_full[4], 0xade682d1),
					new Int_64(H_full[5], 0x2b3e6c1f),
					new Int_64(H_full[6], 0xfb41bd6b),
					new Int_64(H_full[7], 0x137e2179)
				];
				break;
			default:
				throw new Error("Unknown SHA variant");
			}
		}
		else if (((variant.lastIndexOf("SHA3-", 0) === 0) || (variant.lastIndexOf("SHAKE", 0) === 0)) &&
			((8 & SUPPORTED_ALGS) !== 0))
		{
			for (i = 0; i < 5; i += 1)
			{
				retVal[i] = [new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0), new Int_64(0, 0)];
			}
		}
		else
		{
			throw new Error("No SHA variants supported");
		}

		return retVal;
	}
function getNewState ( variant ) { var retVal = [ ] , H_trunc , H_full , i ; if ( ( "SHA-1" === variant ) && ( ( 1 & SUPPORTED_ALGS ) !== 0 ) ) { retVal = [ 0x67452301 , 0xefcdab89 , 0x98badcfe , 0x10325476 , 0xc3d2e1f0 ] ; } else if ( ( variant . lastIndexOf ( "SHA-" , 0 ) === 0 ) && ( ( 6 & SUPPORTED_ALGS ) !== 0 ) ) { H_trunc = [ 0xc1059ed8 , 0x367cd507 , 0x3070dd17 , 0xf70e5939 , 0xffc00b31 , 0x68581511 , 0x64f98fa7 , 0xbefa4fa4 ] ; H_full = [ 0x6A09E667 , 0xBB67AE85 , 0x3C6EF372 , 0xA54FF53A , 0x510E527F , 0x9B05688C , 0x1F83D9AB , 0x5BE0CD19 ] ; switch ( variant ) { case "SHA-224" : retVal = H_trunc ; break ; case "SHA-256" : retVal = H_full ; break ; case "SHA-384" : retVal = [ new Int_64 ( 0xcbbb9d5d , H_trunc [ 0 ] ) , new Int_64 ( 0x0629a292a , H_trunc [ 1 ] ) , new Int_64 ( 0x9159015a , H_trunc [ 2 ] ) , new Int_64 ( 0x0152fecd8 , H_trunc [ 3 ] ) , new Int_64 ( 0x67332667 , H_trunc [ 4 ] ) , new Int_64 ( 0x98eb44a87 , H_trunc [ 5 ] ) , new Int_64 ( 0xdb0c2e0d , H_trunc [ 6 ] ) , new Int_64 ( 0x047b5481d , H_trunc [ 7 ] ) ] ; break ; case "SHA-512" : retVal = [ new Int_64 ( H_full [ 0 ] , 0xf3bcc908 ) , new Int_64 ( H_full [ 1 ] , 0x84caa73b ) , new Int_64 ( H_full [ 2 ] , 0xfe94f82b ) , new Int_64 ( H_full [ 3 ] , 0x5f1d36f1 ) , new Int_64 ( H_full [ 4 ] , 0xade682d1 ) , new Int_64 ( H_full [ 5 ] , 0x2b3e6c1f ) , new Int_64 ( H_full [ 6 ] , 0xfb41bd6b ) , new Int_64 ( H_full [ 7 ] , 0x137e2179 ) ] ; break ; default : throw new Error ( "Unknown SHA variant" ) ; } } else if ( ( ( variant . lastIndexOf ( "SHA3-" , 0 ) === 0 ) || ( variant . lastIndexOf ( "SHAKE" , 0 ) === 0 ) ) && ( ( 8 & SUPPORTED_ALGS ) !== 0 ) ) { for ( i = 0 ; i < 5 ; i += 1 ) { retVal [ i ] = [ new Int_64 ( 0 , 0 ) , new Int_64 ( 0 , 0 ) , new Int_64 ( 0 , 0 ) , new Int_64 ( 0 , 0 ) , new Int_64 ( 0 , 0 ) ] ; } } else { throw new Error ( "No SHA variants supported" ) ; } return retVal ; }
Gets the state values for the specified SHA variant

@param {string} variant The SHA variant
@return {Array<number|Int_64|Array<null>>} The initial state values
Gets the state values for the specified SHA variant