From c5f17d45c1866ad7c65bcec66be03212ec5cc3ae Mon Sep 17 00:00:00 2001 From: Andy Polyakov Date: Tue, 17 Oct 2006 16:13:18 +0000 Subject: [PATCH] Further synchronizations with md32_common.h update, consistent naming for low-level SHA block routines. --- crypto/sha/asm/sha1-586.pl | 4 +- crypto/sha/asm/sha1-ia64.pl | 10 ++-- crypto/sha/asm/sha1-ppc.pl | 4 +- crypto/sha/asm/sha1-x86_64.pl | 6 ++- crypto/sha/asm/sha512-ia64.pl | 4 +- crypto/sha/asm/sha512-ppc.pl | 4 +- crypto/sha/asm/sha512-x86_64.pl | 29 ++---------- crypto/sha/sha1s.cpp | 82 --------------------------------- crypto/sha/sha256.c | 14 +++--- crypto/sha/sha512.c | 18 ++++---- crypto/sha/sha_locl.h | 30 ++++-------- 11 files changed, 45 insertions(+), 160 deletions(-) delete mode 100644 crypto/sha/sha1s.cpp diff --git a/crypto/sha/asm/sha1-586.pl b/crypto/sha/asm/sha1-586.pl index 10c7d43641..0b1e1731cb 100644 --- a/crypto/sha/asm/sha1-586.pl +++ b/crypto/sha/asm/sha1-586.pl @@ -149,7 +149,7 @@ sub BODY_40_59 &add($f,$e); # f+=ROTATE(a,5) } -&function_begin("sha1_block_asm_data_order",16); +&function_begin("sha1_block_data_order",16); &mov($tmp1,&wparam(0)); # SHA_CTX *c &mov($T,&wparam(1)); # const void *input &mov($A,&wparam(2)); # size_t num @@ -214,7 +214,7 @@ sub BODY_40_59 &jb(&label("loop")); &stack_pop(16); -&function_end("sha1_block_asm_data_order"); +&function_end("sha1_block_data_order"); &asciz("SHA1 block transform for x86, CRYPTOGAMS by "); &asm_finish(); diff --git a/crypto/sha/asm/sha1-ia64.pl b/crypto/sha/asm/sha1-ia64.pl index 9e2f73560f..242cadcc52 100644 --- a/crypto/sha/asm/sha1-ia64.pl +++ b/crypto/sha/asm/sha1-ia64.pl @@ -239,11 +239,11 @@ tmp3=r11; ctx=r32; // in0 inp=r33; // in1 -// void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num); -.global sha1_block_asm_data_order# -.proc sha1_block_asm_data_order# +// void sha1_block_data_order(SHA_CTX *c,const void *p,size_t num); +.global sha1_block_data_order# +.proc sha1_block_data_order# .align 32 -sha1_block_asm_data_order: +sha1_block_data_order: .prologue { .mmi; alloc tmp1=ar.pfs,3,15,0,0 $ADDP tmp0=4,ctx @@ -306,7 +306,7 @@ $code.=<<___; { .mib; st4 [ctx]=$h4,-16 mov pr=r2,0x1ffff br.ret.sptk.many b0 };; -.endp sha1_block_asm_data_order# +.endp sha1_block_data_order# ___ print $code; diff --git a/crypto/sha/asm/sha1-ppc.pl b/crypto/sha/asm/sha1-ppc.pl index 5c5c7d87ec..fbd051652c 100755 --- a/crypto/sha/asm/sha1-ppc.pl +++ b/crypto/sha/asm/sha1-ppc.pl @@ -158,9 +158,9 @@ ___ $code=<<___; .text -.globl .sha1_block_asm_data_order +.globl .sha1_block_data_order .align 4 -.sha1_block_asm_data_order: +.sha1_block_data_order: mflr r0 $STU $sp,`-($FRAME+64)`($sp) $PUSH r0,`$FRAME-$SIZE_T*18`($sp) diff --git a/crypto/sha/asm/sha1-x86_64.pl b/crypto/sha/asm/sha1-x86_64.pl index 857db2d671..f3cb1347fb 100755 --- a/crypto/sha/asm/sha1-x86_64.pl +++ b/crypto/sha/asm/sha1-x86_64.pl @@ -158,6 +158,8 @@ $code.=<<___ if ($i<79); rol \$30,$b add $t0,$f rol \$1,$xi +___ +$code.=<<___ if ($i<76); mov $xi,`4*($j%16)`(%rsp) ___ $code.=<<___ if ($i==79); @@ -200,7 +202,7 @@ ___ $code=".text\n"; -&PROLOGUE("sha1_block_asm_data_order"); +&PROLOGUE("sha1_block_data_order"); $code.=".align 4\n.Lloop:\n"; for($i=0;$i<20;$i++) { &BODY_00_19($i,@V); unshift(@V,pop(@V)); } for(;$i<40;$i++) { &BODY_20_39($i,@V); unshift(@V,pop(@V)); } @@ -227,7 +229,7 @@ $code.=<<___; sub \$1,$num jnz .Lloop ___ -&EPILOGUE("sha1_block_asm_data_order"); +&EPILOGUE("sha1_block_data_order"); $code.=<<___; .asciz "SHA1 block transform for x86_64, CRYPTOGAMS by " ___ diff --git a/crypto/sha/asm/sha512-ia64.pl b/crypto/sha/asm/sha512-ia64.pl index 628e33e426..bba7f6bb15 100755 --- a/crypto/sha/asm/sha512-ia64.pl +++ b/crypto/sha/asm/sha512-ia64.pl @@ -71,7 +71,7 @@ if ($output =~ /512.*\.[s|asm]/) { $ADD="add"; $SHRU="shr.u"; $TABLE="K512"; - $func="sha512_block"; + $func="sha512_block_data_order"; @Sigma0=(28,34,39); @Sigma1=(14,18,41); @sigma0=(1, 8, 7); @@ -85,7 +85,7 @@ if ($output =~ /512.*\.[s|asm]/) { $ADD="padd4"; $SHRU="pshr4.u"; $TABLE="K256"; - $func="sha256_block"; + $func="sha256_block_data_order"; @Sigma0=( 2,13,22); @Sigma1=( 6,11,25); @sigma0=( 7,18, 3); diff --git a/crypto/sha/asm/sha512-ppc.pl b/crypto/sha/asm/sha512-ppc.pl index b866f93eef..877d172215 100755 --- a/crypto/sha/asm/sha512-ppc.pl +++ b/crypto/sha/asm/sha512-ppc.pl @@ -41,7 +41,7 @@ if ($output =~ /64/) { die "can't call ../perlasm/ppc-xlate.pl: $!"; if ($output =~ /512/) { - $func="sha512_block"; + $func="sha512_block_data_order"; $SZ=8; @Sigma0=(28,34,39); @Sigma1=(14,18,41); @@ -53,7 +53,7 @@ if ($output =~ /512/) { $ROR="rotrdi"; $SHR="srdi"; } else { - $func="sha256_block"; + $func="sha256_block_data_order"; $SZ=4; @Sigma0=( 2,13,22); @Sigma1=( 6,11,25); diff --git a/crypto/sha/asm/sha512-x86_64.pl b/crypto/sha/asm/sha512-x86_64.pl index 38157b610c..4cf5c623d6 100755 --- a/crypto/sha/asm/sha512-x86_64.pl +++ b/crypto/sha/asm/sha512-x86_64.pl @@ -44,7 +44,7 @@ $output=shift; open STDOUT,"| $^X ../perlasm/x86_64-xlate.pl $output"; if ($output =~ /512/) { - $func="sha512_block"; + $func="sha512_block_data_order"; $TABLE="K512"; $SZ=8; @ROT=($A,$B,$C,$D,$E,$F,$G,$H)=("%rax","%rbx","%rcx","%rdx", @@ -56,7 +56,7 @@ if ($output =~ /512/) { @sigma1=(19,61, 6); $rounds=80; } else { - $func="sha256_block"; + $func="sha256_block_data_order"; $TABLE="K256"; $SZ=4; @ROT=($A,$B,$C,$D,$E,$F,$G,$H)=("%eax","%ebx","%ecx","%edx", @@ -77,9 +77,8 @@ $Tbl="%rbp"; $_ctx="16*$SZ+0*8(%rsp)"; $_inp="16*$SZ+1*8(%rsp)"; $_end="16*$SZ+2*8(%rsp)"; -$_ord="16*$SZ+3*8(%rsp)"; -$_rsp="16*$SZ+4*8(%rsp)"; -$framesz="16*$SZ+5*8"; +$_rsp="16*$SZ+3*8(%rsp)"; +$framesz="16*$SZ+4*8"; sub ROUND_00_15() @@ -189,7 +188,6 @@ $func: mov $ctx,$_ctx # save ctx, 1st arg mov $inp,$_inp # save inp, 2nd arh mov %rdx,$_end # save end pointer, "3rd" arg - mov %ecx,$_ord # save host, 4th arg mov %rbp,$_rsp # save copy of %rsp .picmeup $Tbl @@ -209,25 +207,6 @@ $func: .Lloop: xor $round,$round ___ -if ($SZ==4) { -$code.=<<___; - cmpl \$0,$_ord - je .Ldata_order -.align 16 -.Lhost_order: -___ - - for($i=0;$i<16;$i++) { - $code.=" mov $SZ*$i($inp),$T1\n"; - &ROUND_00_15($i,@ROT); - unshift(@ROT,pop(@ROT)); - } -$code.=<<___; - jmp .Lrounds_16_xx -.align 16 -.Ldata_order: -___ -} # 256 for($i=0;$i<16;$i++) { $code.=" mov $SZ*$i($inp),$T1\n"; $code.=" bswap $T1\n"; diff --git a/crypto/sha/sha1s.cpp b/crypto/sha/sha1s.cpp deleted file mode 100644 index af23d1e0f2..0000000000 --- a/crypto/sha/sha1s.cpp +++ /dev/null @@ -1,82 +0,0 @@ -// -// gettsc.inl -// -// gives access to the Pentium's (secret) cycle counter -// -// This software was written by Leonard Janke (janke@unixg.ubc.ca) -// in 1996-7 and is entered, by him, into the public domain. - -#if defined(__WATCOMC__) -void GetTSC(unsigned long&); -#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; -#elif defined(__GNUC__) -inline -void GetTSC(unsigned long& tsc) -{ - asm volatile(".byte 15, 49\n\t" - : "=eax" (tsc) - : - : "%edx", "%eax"); -} -#elif defined(_MSC_VER) -inline -void GetTSC(unsigned long& tsc) -{ - unsigned long a; - __asm _emit 0fh - __asm _emit 31h - __asm mov a, eax; - tsc=a; -} -#endif - -#include -#include -#include - -#define sha1_block_x86 sha1_block_asm_data_order -extern "C" { -void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); -} - -void main(int argc,char *argv[]) - { - unsigned char buffer[64*256]; - SHA_CTX ctx; - unsigned long s1,s2,e1,e2; - unsigned char k[16]; - unsigned long data[2]; - unsigned char iv[8]; - int i,num=0,numm; - int j=0; - - if (argc >= 2) - num=atoi(argv[1]); - - if (num == 0) num=16; - if (num > 250) num=16; - numm=num+2; -#if 0 - num*=64; - numm*=64; -#endif - - for (j=0; j<6; j++) - { - for (i=0; i<10; i++) /**/ - { - sha1_block_x86(&ctx,buffer,numm); - GetTSC(s1); - sha1_block_x86(&ctx,buffer,numm); - GetTSC(e1); - GetTSC(s2); - sha1_block_x86(&ctx,buffer,num); - GetTSC(e2); - sha1_block_x86(&ctx,buffer,num); - } - - printf("sha1 (%d bytes) %d %d (%.2f)\n",num*64, - e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); - } - } - diff --git a/crypto/sha/sha256.c b/crypto/sha/sha256.c index f83e5afe71..9b69ff38d2 100644 --- a/crypto/sha/sha256.c +++ b/crypto/sha/sha256.c @@ -107,13 +107,14 @@ int SHA224_Final (unsigned char *md, SHA256_CTX *c) #define HASH_TRANSFORM SHA256_Transform #define HASH_FINAL SHA256_Final #define HASH_BLOCK_DATA_ORDER sha256_block_data_order +#ifndef SHA256_ASM +static +#endif void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num); #include "md32_common.h" -#ifdef SHA256_ASM -void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host); -#else +#ifndef SHA256_ASM static const SHA_LONG K256[64] = { 0x428a2f98UL,0x71374491UL,0xb5c0fbcfUL,0xe9b5dba5UL, 0x3956c25bUL,0x59f111f1UL,0x923f82a4UL,0xab1c5ed5UL, @@ -147,7 +148,7 @@ static const SHA_LONG K256[64] = { #ifdef OPENSSL_SMALL_FOOTPRINT -static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host) +static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num) { unsigned MD32_REG_T a,b,c,d,e,f,g,h,s0,s1,T1,T2; SHA_LONG X[16],l; @@ -199,7 +200,7 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host) T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \ ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0) -static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host) +static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num) { unsigned MD32_REG_T a,b,c,d,e,f,g,h,s0,s1,T1; SHA_LONG X[16]; @@ -278,7 +279,4 @@ static void sha256_block (SHA256_CTX *ctx, const void *in, size_t num, int host) #endif #endif /* SHA256_ASM */ -void HASH_BLOCK_DATA_ORDER (SHA256_CTX *ctx, const void *in, size_t num) -{ sha256_block (ctx,in,num,0); } - #endif /* OPENSSL_NO_SHA256 */ diff --git a/crypto/sha/sha512.c b/crypto/sha/sha512.c index dba4c49c0b..e7a7e5dea8 100644 --- a/crypto/sha/sha512.c +++ b/crypto/sha/sha512.c @@ -89,7 +89,7 @@ int SHA512_Init (SHA512_CTX *c) #ifndef SHA512_ASM static #endif -void sha512_block (SHA512_CTX *ctx, const void *in, size_t num); +void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num); int SHA512_Final (unsigned char *md, SHA512_CTX *c) { @@ -100,7 +100,7 @@ int SHA512_Final (unsigned char *md, SHA512_CTX *c) n++; if (n > (sizeof(c->u)-16)) memset (p+n,0,sizeof(c->u)-n), n=0, - sha512_block (c,p,1); + sha512_block_data_order (c,p,1); memset (p+n,0,sizeof(c->u)-16-n); #ifdef B_ENDIAN @@ -125,7 +125,7 @@ int SHA512_Final (unsigned char *md, SHA512_CTX *c) p[sizeof(c->u)-16] = (unsigned char)(c->Nh>>56); #endif - sha512_block (c,p,1); + sha512_block_data_order (c,p,1); if (md==0) return 0; @@ -197,7 +197,7 @@ int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len) else { memcpy (p+c->num,data,n), c->num = 0; len-=n, data+=n; - sha512_block (c,p,1); + sha512_block_data_order (c,p,1); } } @@ -207,12 +207,12 @@ int SHA512_Update (SHA512_CTX *c, const void *_data, size_t len) if ((size_t)data%sizeof(c->u.d[0]) != 0) while (len >= sizeof(c->u)) memcpy (p,data,sizeof(c->u)), - sha512_block (c,p,1), + sha512_block_data_order (c,p,1), len -= sizeof(c->u), data += sizeof(c->u); else #endif - sha512_block (c,data,len/sizeof(c->u)), + sha512_block_data_order (c,data,len/sizeof(c->u)), data += len, len %= sizeof(c->u), data -= len; @@ -227,7 +227,7 @@ int SHA384_Update (SHA512_CTX *c, const void *data, size_t len) { return SHA512_Update (c,data,len); } void SHA512_Transform (SHA512_CTX *c, const unsigned char *data) -{ sha512_block (c,data,1); } +{ sha512_block_data_order (c,data,1); } unsigned char *SHA384(const unsigned char *d, size_t n, unsigned char *md) { @@ -392,7 +392,7 @@ static const SHA_LONG64 K512[80] = { #ifdef OPENSSL_SMALL_FOOTPRINT -static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num) +static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num) { const SHA_LONG64 *W=in; SHA_LONG64 a,b,c,d,e,f,g,h,s0,s1,T1,T2; @@ -453,7 +453,7 @@ static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num) T1 = X[(i)&0x0f] += s0 + s1 + X[(i+9)&0x0f]; \ ROUND_00_15(i,a,b,c,d,e,f,g,h); } while (0) -static void sha512_block (SHA512_CTX *ctx, const void *in, size_t num) +static void sha512_block_data_order (SHA512_CTX *ctx, const void *in, size_t num) { const SHA_LONG64 *W=in; SHA_LONG64 a,b,c,d,e,f,g,h,s0,s1,T1; diff --git a/crypto/sha/sha_locl.h b/crypto/sha/sha_locl.h index d482ba12a0..247d4df6f5 100644 --- a/crypto/sha/sha_locl.h +++ b/crypto/sha/sha_locl.h @@ -85,7 +85,7 @@ # define HASH_BLOCK_DATA_ORDER sha_block_data_order # define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id)) - void sha_block_data_order (SHA_CTX *c, const void *p,size_t num); +static void sha_block_data_order (SHA_CTX *c, const void *p,size_t num); #elif defined(SHA_1) @@ -105,22 +105,10 @@ ) # endif -# ifdef SHA1_ASM -# if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) \ - || defined(__x86_64) || defined(__x86_64__) || defined(_M_AMD64) || defined(_M_X64) -# define sha1_block_data_order sha1_block_asm_data_order -# define DONT_IMPLEMENT_BLOCK_DATA_ORDER -# elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) -# define sha1_block_data_order sha1_block_asm_data_order -# define DONT_IMPLEMENT_BLOCK_DATA_ORDER -# elif defined(_ARCH_PPC) || defined(_ARCH_PPC64) || \ - defined(__ppc) || defined(__ppc__) || defined(__powerpc) || \ - defined(__ppc64) || defined(__ppc64__) || defined(__powerpc64) -# define sha1_block_data_order sha1_block_asm_data_order -# define DONT_IMPLEMENT_BLOCK_DATA_ORDER -# endif -# endif - void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num); +#ifndef SHA1_ASM +static +#endif +void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num); #else # error "Either SHA_0 or SHA_1 must be defined." @@ -216,8 +204,8 @@ int HASH_INIT (SHA_CTX *c) # define X(i) XX[i] #endif -#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER -void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) +#if !defined(SHA_1) || !defined(SHA1_ASM) +static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) { const unsigned char *data=p; register unsigned MD32_REG_T A,B,C,D,E,T,l; @@ -416,8 +404,8 @@ void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) E=D, D=C, C=ROTATE(B,30), B=A; \ A=ROTATE(A,5)+T+xa; } while(0) -#ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER -void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) +#if !defined(SHA_1) || !defined(SHA1_ASM) +static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num) { const unsigned char *data=p; register unsigned MD32_REG_T A,B,C,D,E,T,l; -- 2.34.1