diff options
author | lloyd <[email protected]> | 2006-08-12 17:56:23 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2006-08-12 17:56:23 +0000 |
commit | 81ae351be2dd83ebd301427b7111b875caa7704e (patch) | |
tree | 95bf0b163eb06f9be5023bc0cdb3c9c1ec9e7d7d /modules | |
parent | d93e78a86529d11e1a4239d302c343675ed0435e (diff) |
Implement the first set of rounds of SHA-1 in assembly
Diffstat (limited to 'modules')
-rw-r--r-- | modules/sha_x86/sha160.cpp | 26 | ||||
-rw-r--r-- | modules/sha_x86/sha1core.S | 64 |
2 files changed, 85 insertions, 5 deletions
diff --git a/modules/sha_x86/sha160.cpp b/modules/sha_x86/sha160.cpp index be8b7f695..fce5c9d04 100644 --- a/modules/sha_x86/sha160.cpp +++ b/modules/sha_x86/sha160.cpp @@ -56,25 +56,41 @@ extern "C" void sha160_core(u32bit[5], const byte[64], u32bit[80]); void SHA_160::hash(const byte input[]) { #if 1 - sha160_core(digest, input, W); + u32bit digestX[5]; + for(int j = 0; j != 5; j++) + digestX[j] = digest[j]; + + sha160_core(digestX, input, W); + + u32bit A = digestX[0], B = digestX[1], C = digestX[2], + D = digestX[3], E = digestX[4]; + #else for(u32bit j = 0; j != 16; ++j) W[j] = make_u32bit(input[4*j], input[4*j+1], input[4*j+2], input[4*j+3]); for(u32bit j = 16; j != 80; ++j) W[j] = rotate_left((W[j-3] ^ W[j-8] ^ W[j-14] ^ W[j-16]), 1); -#endif u32bit A = digest[0], B = digest[1], C = digest[2], D = digest[3], E = digest[4]; +#endif - 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(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]); - F1(B,C,D,E,A,W[ 9]); F1(A,B,C,D,E,W[10]); F1(E,A,B,C,D,W[11]); + F1(B,C,D,E,A,W[ 9]); + + F1(A,B,C,D,E,W[10]); F1(E,A,B,C,D,W[11]); F1(D,E,A,B,C,W[12]); F1(C,D,E,A,B,W[13]); F1(B,C,D,E,A,W[14]); + F1(A,B,C,D,E,W[15]); F1(E,A,B,C,D,W[16]); F1(D,E,A,B,C,W[17]); F1(C,D,E,A,B,W[18]); F1(B,C,D,E,A,W[19]); + */ F2(A,B,C,D,E,W[20]); F2(E,A,B,C,D,W[21]); F2(D,E,A,B,C,W[22]); F2(C,D,E,A,B,W[23]); F2(B,C,D,E,A,W[24]); F2(A,B,C,D,E,W[25]); diff --git a/modules/sha_x86/sha1core.S b/modules/sha_x86/sha1core.S index 38d8525db..5a09cb00d 100644 --- a/modules/sha_x86/sha1core.S +++ b/modules/sha_x86/sha1core.S @@ -28,6 +28,7 @@ sha160_core: leal 64(%edi), %edx + .p2align 4,,7 // here esi == 16 .EXPANSION_LOOP: movl -32(%edx), %eax @@ -42,6 +43,69 @@ sha160_core: cmpl $80, %esi jne .EXPANSION_LOOP + // here: edi = W + + movl 20(%esp), %ebp + movl 0(%ebp), %eax + movl 4(%ebp), %ebx + movl 8(%ebp), %ecx + movl 12(%ebp), %edx + movl 16(%ebp), %esi + +#define MAGIC1 $0x5A827999 + +#define FUNC1(B, C, D, TEMP) \ + movl C, TEMP ; \ + xorl D, TEMP ; \ + andl B, TEMP ; \ + xorl D, TEMP + +#define FUNC2(B, C, D, TEMP) \ + movl B, TEMP ; \ + xorl C, TEMP ; \ + xorl D, TEMP + +#define F(A, B, C, D, E, TEMP, MSG, MAGIC, FUNC) \ + FUNC(B, C, D, TEMP) ; \ + addl MSG, E ; \ + addl TEMP, E ; \ + addl MAGIC, E ; \ + roll $5, A ; \ + addl A, E ; \ + rorl $5, A ; \ + roll $30, B + + F(%eax, %ebx, %ecx, %edx, %esi, %ebp, 0(%edi), MAGIC1, FUNC1) + F(%esi, %eax, %ebx, %ecx, %edx, %ebp, 4(%edi), MAGIC1, FUNC1) + F(%edx, %esi, %eax, %ebx, %ecx, %ebp, 8(%edi), MAGIC1, FUNC1) + F(%ecx, %edx, %esi, %eax, %ebx, %ebp, 12(%edi), MAGIC1, FUNC1) + F(%ebx, %ecx, %edx, %esi, %eax, %ebp, 16(%edi), MAGIC1, FUNC1) + + F(%eax, %ebx, %ecx, %edx, %esi, %ebp, 20(%edi), MAGIC1, FUNC1) + F(%esi, %eax, %ebx, %ecx, %edx, %ebp, 24(%edi), MAGIC1, FUNC1) + F(%edx, %esi, %eax, %ebx, %ecx, %ebp, 28(%edi), MAGIC1, FUNC1) + F(%ecx, %edx, %esi, %eax, %ebx, %ebp, 32(%edi), MAGIC1, FUNC1) + F(%ebx, %ecx, %edx, %esi, %eax, %ebp, 36(%edi), MAGIC1, FUNC1) + + F(%eax, %ebx, %ecx, %edx, %esi, %ebp, 40(%edi), MAGIC1, FUNC1) + F(%esi, %eax, %ebx, %ecx, %edx, %ebp, 44(%edi), MAGIC1, FUNC1) + F(%edx, %esi, %eax, %ebx, %ecx, %ebp, 48(%edi), MAGIC1, FUNC1) + F(%ecx, %edx, %esi, %eax, %ebx, %ebp, 52(%edi), MAGIC1, FUNC1) + F(%ebx, %ecx, %edx, %esi, %eax, %ebp, 56(%edi), MAGIC1, FUNC1) + + F(%eax, %ebx, %ecx, %edx, %esi, %ebp, 60(%edi), MAGIC1, FUNC1) + F(%esi, %eax, %ebx, %ecx, %edx, %ebp, 64(%edi), MAGIC1, FUNC1) + F(%edx, %esi, %eax, %ebx, %ecx, %ebp, 68(%edi), MAGIC1, FUNC1) + F(%ecx, %edx, %esi, %eax, %ebx, %ebp, 72(%edi), MAGIC1, FUNC1) + F(%ebx, %ecx, %edx, %esi, %eax, %ebp, 76(%edi), MAGIC1, FUNC1) + + movl 20(%esp), %ebp + movl %eax, 0(%ebp) + movl %ebx, 4(%ebp) + movl %ecx, 8(%ebp) + movl %edx, 12(%ebp) + movl %esi, 16(%ebp) + popl %ebx popl %esi popl %edi |