aboutsummaryrefslogtreecommitdiffstats
path: root/src/hash/sha1
diff options
context:
space:
mode:
authorlloyd <[email protected]>2008-11-23 03:38:03 +0000
committerlloyd <[email protected]>2008-11-23 03:38:03 +0000
commita3b7eb7194b2d181a21c73f0b201de3d9a8d2785 (patch)
tree345be60212e71b6419d118abf2e4c084fcad8187 /src/hash/sha1
parent6cebada1115c54036f8e364ee6ca598af5996758 (diff)
Do a minor optimization in some of the compression functions, loading
the registers only once and carrying the values over between loop iterations.
Diffstat (limited to 'src/hash/sha1')
-rw-r--r--src/hash/sha1/sha160.cpp13
1 files changed, 8 insertions, 5 deletions
diff --git a/src/hash/sha1/sha160.cpp b/src/hash/sha1/sha160.cpp
index 302151921..231dbeb12 100644
--- a/src/hash/sha1/sha160.cpp
+++ b/src/hash/sha1/sha160.cpp
@@ -54,6 +54,9 @@ inline void F4(u32bit A, u32bit& B, u32bit C, u32bit D, u32bit& E, u32bit msg)
*************************************************/
void SHA_160::compress_n(const byte input[], u32bit blocks)
{
+ u32bit A = digest[0], B = digest[1], C = digest[2],
+ D = digest[3], E = digest[4];
+
for(u32bit i = 0; i != blocks; ++i)
{
for(u32bit j = 0; j != 16; j += 4)
@@ -73,9 +76,6 @@ void SHA_160::compress_n(const byte input[], u32bit blocks)
W[j+3] = rotate_left((W[j ] ^ W[j-5] ^ W[j-11] ^ W[j-13]), 1);
}
- u32bit A = digest[0], B = digest[1], C = digest[2],
- D = digest[3], E = digest[4];
-
F1(A,B,C,D,E,W[ 0]); F1(E,A,B,C,D,W[ 1]); F1(D,E,A,B,C,W[ 2]);
F1(C,D,E,A,B,W[ 3]); F1(B,C,D,E,A,W[ 4]); F1(A,B,C,D,E,W[ 5]);
F1(E,A,B,C,D,W[ 6]); F1(D,E,A,B,C,W[ 7]); F1(C,D,E,A,B,W[ 8]);
@@ -108,8 +108,11 @@ void SHA_160::compress_n(const byte input[], u32bit blocks)
F4(A,B,C,D,E,W[75]); F4(E,A,B,C,D,W[76]); F4(D,E,A,B,C,W[77]);
F4(C,D,E,A,B,W[78]); F4(B,C,D,E,A,W[79]);
- digest[0] += A; digest[1] += B; digest[2] += C;
- digest[3] += D; digest[4] += E;
+ A = (digest[0] += A);
+ B = (digest[1] += B);
+ C = (digest[2] += C);
+ D = (digest[3] += D);
+ E = (digest[4] += E);
}
}