package/network/services/ead/src/sha1.c
/**
 * sha_transform - single block SHA1 transform
 *
 * @digest: 160 bit digest to update
 * @data:   512 bits of data to hash
 * @W:      80 words of workspace (see note)
 *
 * This function generates a SHA1 digest for a single 512-bit block.
 * Be warned, it does not handle padding and message digest, do not
 * confuse it with the full FIPS 180-1 digest algorithm for variable
 * length messages.
 *
 * Note: If the hash is security sensitive, the caller should be sure
 * to clear the workspace. This is left to the caller to avoid
 * unnecessary clears between chained hashing operations.
 */
single block SHA1 transform
@digest: 160 bit digest to update
@data:   512 bits of data to hash
@W:      80 words of workspace

This function generates a SHA1 digest for a single 512-bit block.
Be warned, it does not handle padding and message digest, do not
confuse it with the full FIPS 180-1 digest algorithm for variable
length messages.

If the hash is security sensitive, the caller should be sure
to clear the workspace. This is left to the caller to avoid
unnecessary clears between chained hashing operations.
single block SHA1 transform @digest : 160 bit digest to update @data : 512 bits of data to hash @W : 80 words of workspace This function generates a SHA1 digest for a single 512 - bit block . Be warned it does not handle padding and message digest do not confuse it with the full FIPS 180 - 1 digest algorithm for variable length messages . If the hash is security sensitive the caller should be sure to clear the workspace . This is left to the caller to avoid unnecessary clears between chained hashing operations .
static void sha_transform(uint32_t *digest, const unsigned char *in, uint32_t *W)
{
	uint32_t a, b, c, d, e, t, i;
	for (i = 0; i < 16; i++) {
		int ofs = 4 * i;
		W[i] =
			(in[ofs+0] << 24) |
			(in[ofs+1] << 16) |
			(in[ofs+2] << 8) |
			 in[ofs+3];
	}
	for (i = 0; i < 64; i++)
		W[i+16] = rol32(W[i+13] ^ W[i+8] ^ W[i+2] ^ W[i], 1);
	a = digest[0];
	b = digest[1];
	c = digest[2];
	d = digest[3];
	e = digest[4];
	for (i = 0; i < 20; i++) {
		t = f1(b, c, d) + K1 + rol32(a, 5) + e + W[i];
		e = d; d = c; c = rol32(b, 30); b = a; a = t;
	}
	for (; i < 40; i ++) {
		t = f2(b, c, d) + K2 + rol32(a, 5) + e + W[i];
		e = d; d = c; c = rol32(b, 30); b = a; a = t;
	}
	for (; i < 60; i ++) {
		t = f3(b, c, d) + K3 + rol32(a, 5) + e + W[i];
		e = d; d = c; c = rol32(b, 30); b = a; a = t;
	}
	for (; i < 80; i ++) {
		t = f2(b, c, d) + K4 + rol32(a, 5) + e + W[i];
		e = d; d = c; c = rol32(b, 30); b = a; a = t;
	}
	digest[0] += a;
	digest[1] += b;
	digest[2] += c;
	digest[3] += d;
	digest[4] += e;
}
static void sha_transform ( uint32_t * digest , const unsigned char * in , uint32_t * W ) { uint32_t a , b , c , d , e , t , i ; for ( i = 0 ; i < 16 ; i ++ ) { int ofs = 4 * i ; W [ i ] = ( in [ ofs + 0 ] << 24 ) | ( in [ ofs + 1 ] << 16 ) | ( in [ ofs + 2 ] << 8 ) | in [ ofs + 3 ] ; } for ( i = 0 ; i < 64 ; i ++ ) W [ i + 16 ] = rol32 ( W [ i + 13 ] ^ W [ i + 8 ] ^ W [ i + 2 ] ^ W [ i ] , 1 ) ; a = digest [ 0 ] ; b = digest [ 1 ] ; c = digest [ 2 ] ; d = digest [ 3 ] ; e = digest [ 4 ] ; for ( i = 0 ; i < 20 ; i ++ ) { t = f1 ( b , c , d ) + K1 + rol32 ( a , 5 ) + e + W [ i ] ; e = d ; d = c ; c = rol32 ( b , 30 ) ; b = a ; a = t ; } for ( ; i < 40 ; i ++ ) { t = f2 ( b , c , d ) + K2 + rol32 ( a , 5 ) + e + W [ i ] ; e = d ; d = c ; c = rol32 ( b , 30 ) ; b = a ; a = t ; } for ( ; i < 60 ; i ++ ) { t = f3 ( b , c , d ) + K3 + rol32 ( a , 5 ) + e + W [ i ] ; e = d ; d = c ; c = rol32 ( b , 30 ) ; b = a ; a = t ; } for ( ; i < 80 ; i ++ ) { t = f2 ( b , c , d ) + K4 + rol32 ( a , 5 ) + e + W [ i ] ; e = d ; d = c ; c = rol32 ( b , 30 ) ; b = a ; a = t ; } digest [ 0 ] += a ; digest [ 1 ] += b ; digest [ 2 ] += c ; digest [ 3 ] += d ; digest [ 4 ] += e ; }
sha_transform - single block SHA1 transform
 @digest: 160 bit digest to update
 @data:   512 bits of data to hash
 @W:      80 words of workspace (see note)
sha_transform - single block SHA1 transform @digest : 160 bit digest to update @data : 512 bits of data to hash @W : 80 words of workspace ( see note )
/* word load/store may be unaligned here, so use bytes instead */