Re: [PATCH 6/12] random pt4: Replace SHA with faster version

From: Denis Vlasenko
Date: Tue Jan 25 2005 - 16:27:50 EST


On Friday 21 January 2005 23:41, Matt Mackall wrote:
> - * @W: 80 words of workspace
> + * @W: 80 words of workspace, caller should clear

Why?

> *
> * This function generates a SHA1 digest for a single. 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.
> */
> -void sha_transform(__u32 *digest, const char *data, __u32 *W)
> +void sha_transform(__u32 *digest, const char *in, __u32 *W)
> {
> - __u32 A, B, C, D, E;
> - __u32 TEMP;
> - int i;
> + __u32 a, b, c, d, e, t, i;
>
> - memset(W, 0, sizeof(W));
> for (i = 0; i < 16; i++)
> - W[i] = be32_to_cpu(((const __u32 *)data)[i]);
> - /*
> - * Do the preliminary expansion of 16 to 80 words. Doing it
> - * out-of-line line this is faster than doing it in-line on
> - * register-starved machines like the x86, and not really any
> - * slower on real processors.
> - */
> - for (i = 0; i < 64; i++) {
> - TEMP = W[i] ^ W[i+2] ^ W[i+8] ^ W[i+13];
> - W[i+16] = rol32(TEMP, 1);
> + W[i] = be32_to_cpu(((const __u32 *)in)[i]);
> +
> + for (i = 0; i < 64; i++)
> + W[i+16] = rol32(W[i+13] ^ W[i+8] ^ W[i+2] ^ W[i], 1);
--
vda

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/