diff options
Diffstat (limited to 'src/lib/libcrypto/sha')
| -rw-r--r-- | src/lib/libcrypto/sha/Makefile | 127 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/asm/README | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/asm/sha1-586.pl | 425 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/asm/sha1-ia64.pl | 549 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha.c | 124 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha.h | 128 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1.c | 127 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1_one.c | 78 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1dgst.c | 81 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1s.cpp | 82 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1test.c | 174 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha_dgst.c | 73 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha_locl.h | 481 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha_one.c | 78 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/shatest.c | 174 |
15 files changed, 2702 insertions, 0 deletions
diff --git a/src/lib/libcrypto/sha/Makefile b/src/lib/libcrypto/sha/Makefile new file mode 100644 index 0000000000..46103bbc83 --- /dev/null +++ b/src/lib/libcrypto/sha/Makefile | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | # | ||
| 2 | # OpenSSL/crypto/sha/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= sha | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | CPP= $(CC) -E | ||
| 9 | INCLUDES= | ||
| 10 | CFLAG=-g | ||
| 11 | INSTALL_PREFIX= | ||
| 12 | OPENSSLDIR= /usr/local/ssl | ||
| 13 | INSTALLTOP=/usr/local/ssl | ||
| 14 | MAKEDEPPROG= makedepend | ||
| 15 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 16 | MAKEFILE= Makefile | ||
| 17 | AR= ar r | ||
| 18 | |||
| 19 | SHA1_ASM_OBJ= | ||
| 20 | |||
| 21 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 22 | ASFLAGS= $(INCLUDES) $(ASFLAG) | ||
| 23 | |||
| 24 | GENERAL=Makefile | ||
| 25 | TEST=shatest.c sha1test.c | ||
| 26 | APPS= | ||
| 27 | |||
| 28 | LIB=$(TOP)/libcrypto.a | ||
| 29 | LIBSRC=sha_dgst.c sha1dgst.c sha_one.c sha1_one.c | ||
| 30 | LIBOBJ=sha_dgst.o sha1dgst.o sha_one.o sha1_one.o $(SHA1_ASM_OBJ) | ||
| 31 | |||
| 32 | SRC= $(LIBSRC) | ||
| 33 | |||
| 34 | EXHEADER= sha.h | ||
| 35 | HEADER= sha_locl.h $(EXHEADER) | ||
| 36 | |||
| 37 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 38 | |||
| 39 | top: | ||
| 40 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 41 | |||
| 42 | all: lib | ||
| 43 | |||
| 44 | lib: $(LIBOBJ) | ||
| 45 | $(AR) $(LIB) $(LIBOBJ) | ||
| 46 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 47 | @touch lib | ||
| 48 | |||
| 49 | # elf | ||
| 50 | asm/sx86-elf.s: asm/sha1-586.pl ../perlasm/x86asm.pl | ||
| 51 | (cd asm; $(PERL) sha1-586.pl elf $(CFLAGS) $(PROCESSOR) > sx86-elf.s) | ||
| 52 | |||
| 53 | # a.out | ||
| 54 | asm/sx86-out.o: asm/sx86unix.cpp | ||
| 55 | $(CPP) -DOUT asm/sx86unix.cpp | as -o asm/sx86-out.o | ||
| 56 | |||
| 57 | # bsdi | ||
| 58 | asm/sx86bsdi.o: asm/sx86unix.cpp | ||
| 59 | $(CPP) -DBSDI asm/sx86unix.cpp | sed 's/ :/:/' | as -o asm/sx86bsdi.o | ||
| 60 | |||
| 61 | asm/sx86unix.cpp: asm/sha1-586.pl ../perlasm/x86asm.pl | ||
| 62 | (cd asm; $(PERL) sha1-586.pl cpp $(PROCESSOR) >sx86unix.cpp) | ||
| 63 | |||
| 64 | asm/sha1-ia64.s: asm/sha1-ia64.pl | ||
| 65 | (cd asm; $(PERL) sha1-ia64.pl $(CFLAGS) ) > $@ | ||
| 66 | |||
| 67 | files: | ||
| 68 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 69 | |||
| 70 | links: | ||
| 71 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 72 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 73 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 74 | |||
| 75 | install: | ||
| 76 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 77 | do \ | ||
| 78 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 79 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 80 | done; | ||
| 81 | |||
| 82 | tags: | ||
| 83 | ctags $(SRC) | ||
| 84 | |||
| 85 | tests: | ||
| 86 | |||
| 87 | lint: | ||
| 88 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 89 | |||
| 90 | depend: | ||
| 91 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 92 | |||
| 93 | dclean: | ||
| 94 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 95 | mv -f Makefile.new $(MAKEFILE) | ||
| 96 | |||
| 97 | clean: | ||
| 98 | rm -f asm/sx86unix.cpp asm/*-elf.* *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff asm/*.o | ||
| 99 | |||
| 100 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 101 | |||
| 102 | sha1_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 103 | sha1_one.o: ../../include/openssl/opensslconf.h | ||
| 104 | sha1_one.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 105 | sha1_one.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 106 | sha1_one.o: ../../include/openssl/symhacks.h sha1_one.c | ||
| 107 | sha1dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 108 | sha1dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 109 | sha1dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h | ||
| 110 | sha1dgst.o: ../../include/openssl/opensslconf.h | ||
| 111 | sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 112 | sha1dgst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 113 | sha1dgst.o: ../../include/openssl/symhacks.h ../md32_common.h sha1dgst.c | ||
| 114 | sha1dgst.o: sha_locl.h | ||
| 115 | sha_dgst.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 116 | sha_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 117 | sha_dgst.o: ../../include/openssl/fips.h ../../include/openssl/lhash.h | ||
| 118 | sha_dgst.o: ../../include/openssl/opensslconf.h | ||
| 119 | sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 120 | sha_dgst.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 121 | sha_dgst.o: ../../include/openssl/symhacks.h ../md32_common.h sha_dgst.c | ||
| 122 | sha_dgst.o: sha_locl.h | ||
| 123 | sha_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 124 | sha_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 125 | sha_one.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 126 | sha_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 127 | sha_one.o: sha_one.c | ||
diff --git a/src/lib/libcrypto/sha/asm/README b/src/lib/libcrypto/sha/asm/README new file mode 100644 index 0000000000..b7e755765f --- /dev/null +++ b/src/lib/libcrypto/sha/asm/README | |||
| @@ -0,0 +1 @@ | |||
| C2.pl works | |||
diff --git a/src/lib/libcrypto/sha/asm/sha1-586.pl b/src/lib/libcrypto/sha/asm/sha1-586.pl new file mode 100644 index 0000000000..041acc0348 --- /dev/null +++ b/src/lib/libcrypto/sha/asm/sha1-586.pl | |||
| @@ -0,0 +1,425 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | # It was noted that Intel IA-32 C compiler generates code which | ||
| 4 | # performs ~30% *faster* on P4 CPU than original *hand-coded* | ||
| 5 | # SHA1 assembler implementation. To address this problem (and | ||
| 6 | # prove that humans are still better than machines:-), the | ||
| 7 | # original code was overhauled, which resulted in following | ||
| 8 | # performance changes: | ||
| 9 | # | ||
| 10 | # compared with original compared with Intel cc | ||
| 11 | # assembler impl. generated code | ||
| 12 | # Pentium -25% +37% | ||
| 13 | # PIII/AMD +8% +16% | ||
| 14 | # P4 +85%(!) +45% | ||
| 15 | # | ||
| 16 | # As you can see Pentium came out as looser:-( Yet I reckoned that | ||
| 17 | # improvement on P4 outweights the loss and incorporate this | ||
| 18 | # re-tuned code to 0.9.7 and later. | ||
| 19 | # ---------------------------------------------------------------- | ||
| 20 | # Those who for any particular reason absolutely must score on | ||
| 21 | # Pentium can replace this module with one from 0.9.6 distribution. | ||
| 22 | # This "offer" shall be revoked the moment programming interface to | ||
| 23 | # this module is changed, in which case this paragraph should be | ||
| 24 | # removed. | ||
| 25 | # ---------------------------------------------------------------- | ||
| 26 | # <appro@fy.chalmers.se> | ||
| 27 | |||
| 28 | $normal=0; | ||
| 29 | |||
| 30 | push(@INC,"perlasm","../../perlasm"); | ||
| 31 | require "x86asm.pl"; | ||
| 32 | |||
| 33 | &asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); | ||
| 34 | |||
| 35 | $A="eax"; | ||
| 36 | $B="ecx"; | ||
| 37 | $C="ebx"; | ||
| 38 | $D="edx"; | ||
| 39 | $E="edi"; | ||
| 40 | $T="esi"; | ||
| 41 | $tmp1="ebp"; | ||
| 42 | |||
| 43 | $off=9*4; | ||
| 44 | |||
| 45 | @K=(0x5a827999,0x6ed9eba1,0x8f1bbcdc,0xca62c1d6); | ||
| 46 | |||
| 47 | &sha1_block_data("sha1_block_asm_data_order"); | ||
| 48 | |||
| 49 | &asm_finish(); | ||
| 50 | |||
| 51 | sub Nn | ||
| 52 | { | ||
| 53 | local($p)=@_; | ||
| 54 | local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E); | ||
| 55 | return($n{$p}); | ||
| 56 | } | ||
| 57 | |||
| 58 | sub Np | ||
| 59 | { | ||
| 60 | local($p)=@_; | ||
| 61 | local(%n)=($A,$T,$B,$A,$C,$B,$D,$C,$E,$D,$T,$E); | ||
| 62 | local(%n)=($A,$B,$B,$C,$C,$D,$D,$E,$E,$T,$T,$A); | ||
| 63 | return($n{$p}); | ||
| 64 | } | ||
| 65 | |||
| 66 | sub Na | ||
| 67 | { | ||
| 68 | local($n)=@_; | ||
| 69 | return( (($n )&0x0f), | ||
| 70 | (($n+ 2)&0x0f), | ||
| 71 | (($n+ 8)&0x0f), | ||
| 72 | (($n+13)&0x0f), | ||
| 73 | (($n+ 1)&0x0f)); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub X_expand | ||
| 77 | { | ||
| 78 | local($in)=@_; | ||
| 79 | |||
| 80 | &comment("First, load the words onto the stack in network byte order"); | ||
| 81 | for ($i=0; $i<16; $i+=2) | ||
| 82 | { | ||
| 83 | &mov($A,&DWP(($i+0)*4,$in,"",0));# unless $i == 0; | ||
| 84 | &mov($B,&DWP(($i+1)*4,$in,"",0)); | ||
| 85 | &bswap($A); | ||
| 86 | &bswap($B); | ||
| 87 | &mov(&swtmp($i+0),$A); | ||
| 88 | &mov(&swtmp($i+1),$B); | ||
| 89 | } | ||
| 90 | |||
| 91 | &comment("We now have the X array on the stack"); | ||
| 92 | &comment("starting at sp-4"); | ||
| 93 | } | ||
| 94 | |||
| 95 | # Rules of engagement | ||
| 96 | # F is always trashable at the start, the running total. | ||
| 97 | # E becomes the next F so it can be trashed after it has been 'accumulated' | ||
| 98 | # F becomes A in the next round. We don't need to access it much. | ||
| 99 | # During the X update part, the result ends up in $X[$n0]. | ||
| 100 | |||
| 101 | sub BODY_00_15 | ||
| 102 | { | ||
| 103 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 104 | |||
| 105 | &comment("00_15 $n"); | ||
| 106 | |||
| 107 | &mov($tmp1,$a); | ||
| 108 | &mov($f,$c); # f to hold F_00_19(b,c,d) | ||
| 109 | &rotl($tmp1,5); # tmp1=ROTATE(a,5) | ||
| 110 | &xor($f,$d); | ||
| 111 | &and($f,$b); | ||
| 112 | &rotr($b,2); # b=ROTATE(b,30) | ||
| 113 | &add($tmp1,$e); # tmp1+=e; | ||
| 114 | &mov($e,&swtmp($n)); # e becomes volatile and | ||
| 115 | # is loaded with xi | ||
| 116 | &xor($f,$d); # f holds F_00_19(b,c,d) | ||
| 117 | &lea($tmp1,&DWP($K,$tmp1,$e,1));# tmp1+=K_00_19+xi | ||
| 118 | |||
| 119 | &add($f,$tmp1); # f+=tmp1 | ||
| 120 | } | ||
| 121 | |||
| 122 | sub BODY_16_19 | ||
| 123 | { | ||
| 124 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 125 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 126 | |||
| 127 | &comment("16_19 $n"); | ||
| 128 | |||
| 129 | &mov($f,&swtmp($n1)); # f to hold Xupdate(xi,xa,xb,xc,xd) | ||
| 130 | &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d) | ||
| 131 | &xor($f,&swtmp($n0)); | ||
| 132 | &xor($tmp1,$d); | ||
| 133 | &xor($f,&swtmp($n2)); | ||
| 134 | &and($tmp1,$b); # tmp1 holds F_00_19(b,c,d) | ||
| 135 | &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd | ||
| 136 | &rotr($b,2); # b=ROTATE(b,30) | ||
| 137 | &xor($tmp1,$d); # tmp1=F_00_19(b,c,d) | ||
| 138 | &rotl($f,1); # f=ROATE(f,1) | ||
| 139 | &mov(&swtmp($n0),$f); # xi=f | ||
| 140 | &lea($f,&DWP($K,$f,$e,1)); # f+=K_00_19+e | ||
| 141 | &mov($e,$a); # e becomes volatile | ||
| 142 | &add($f,$tmp1); # f+=F_00_19(b,c,d) | ||
| 143 | &rotl($e,5); # e=ROTATE(a,5) | ||
| 144 | &add($f,$e); # f+=ROTATE(a,5) | ||
| 145 | } | ||
| 146 | |||
| 147 | sub BODY_20_39 | ||
| 148 | { | ||
| 149 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 150 | |||
| 151 | &comment("20_39 $n"); | ||
| 152 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 153 | |||
| 154 | &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd) | ||
| 155 | &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d) | ||
| 156 | &xor($f,&swtmp($n1)); | ||
| 157 | &rotr($b,2); # b=ROTATE(b,30) | ||
| 158 | &xor($f,&swtmp($n2)); | ||
| 159 | &xor($tmp1,$c); | ||
| 160 | &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd | ||
| 161 | &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d) | ||
| 162 | &rotl($f,1); # f=ROTATE(f,1) | ||
| 163 | &mov(&swtmp($n0),$f); # xi=f | ||
| 164 | &lea($f,&DWP($K,$f,$e,1)); # f+=K_20_39+e | ||
| 165 | &mov($e,$a); # e becomes volatile | ||
| 166 | &rotl($e,5); # e=ROTATE(a,5) | ||
| 167 | &add($f,$tmp1); # f+=F_20_39(b,c,d) | ||
| 168 | &add($f,$e); # f+=ROTATE(a,5) | ||
| 169 | } | ||
| 170 | |||
| 171 | sub BODY_40_59 | ||
| 172 | { | ||
| 173 | local($pos,$K,$X,$n,$a,$b,$c,$d,$e,$f)=@_; | ||
| 174 | |||
| 175 | &comment("40_59 $n"); | ||
| 176 | local($n0,$n1,$n2,$n3,$np)=&Na($n); | ||
| 177 | |||
| 178 | &mov($f,&swtmp($n0)); # f to hold Xupdate(xi,xa,xb,xc,xd) | ||
| 179 | &mov($tmp1,$b); # tmp1 to hold F_40_59(b,c,d) | ||
| 180 | &xor($f,&swtmp($n1)); | ||
| 181 | &or($tmp1,$c); | ||
| 182 | &xor($f,&swtmp($n2)); | ||
| 183 | &and($tmp1,$d); | ||
| 184 | &xor($f,&swtmp($n3)); # f holds xa^xb^xc^xd | ||
| 185 | &rotl($f,1); # f=ROTATE(f,1) | ||
| 186 | &mov(&swtmp($n0),$f); # xi=f | ||
| 187 | &lea($f,&DWP($K,$f,$e,1)); # f+=K_40_59+e | ||
| 188 | &mov($e,$b); # e becomes volatile and is used | ||
| 189 | # to calculate F_40_59(b,c,d) | ||
| 190 | &rotr($b,2); # b=ROTATE(b,30) | ||
| 191 | &and($e,$c); | ||
| 192 | &or($tmp1,$e); # tmp1 holds F_40_59(b,c,d) | ||
| 193 | &mov($e,$a); | ||
| 194 | &rotl($e,5); # e=ROTATE(a,5) | ||
| 195 | &add($tmp1,$e); # tmp1+=ROTATE(a,5) | ||
| 196 | &add($f,$tmp1); # f+=tmp1; | ||
| 197 | } | ||
| 198 | |||
| 199 | sub BODY_60_79 | ||
| 200 | { | ||
| 201 | &BODY_20_39(@_); | ||
| 202 | } | ||
| 203 | |||
| 204 | sub sha1_block_host | ||
| 205 | { | ||
| 206 | local($name, $sclabel)=@_; | ||
| 207 | |||
| 208 | &function_begin_B($name,""); | ||
| 209 | |||
| 210 | # parameter 1 is the MD5_CTX structure. | ||
| 211 | # A 0 | ||
| 212 | # B 4 | ||
| 213 | # C 8 | ||
| 214 | # D 12 | ||
| 215 | # E 16 | ||
| 216 | |||
| 217 | &mov("ecx", &wparam(2)); | ||
| 218 | &push("esi"); | ||
| 219 | &shl("ecx",6); | ||
| 220 | &mov("esi", &wparam(1)); | ||
| 221 | &push("ebp"); | ||
| 222 | &add("ecx","esi"); # offset to leave on | ||
| 223 | &push("ebx"); | ||
| 224 | &mov("ebp", &wparam(0)); | ||
| 225 | &push("edi"); | ||
| 226 | &mov($D, &DWP(12,"ebp","",0)); | ||
| 227 | &stack_push(18+9); | ||
| 228 | &mov($E, &DWP(16,"ebp","",0)); | ||
| 229 | &mov($C, &DWP( 8,"ebp","",0)); | ||
| 230 | &mov(&swtmp(17),"ecx"); | ||
| 231 | |||
| 232 | &comment("First we need to setup the X array"); | ||
| 233 | |||
| 234 | for ($i=0; $i<16; $i+=2) | ||
| 235 | { | ||
| 236 | &mov($A,&DWP(($i+0)*4,"esi","",0));# unless $i == 0; | ||
| 237 | &mov($B,&DWP(($i+1)*4,"esi","",0)); | ||
| 238 | &mov(&swtmp($i+0),$A); | ||
| 239 | &mov(&swtmp($i+1),$B); | ||
| 240 | } | ||
| 241 | &jmp($sclabel); | ||
| 242 | &function_end_B($name); | ||
| 243 | } | ||
| 244 | |||
| 245 | |||
| 246 | sub sha1_block_data | ||
| 247 | { | ||
| 248 | local($name)=@_; | ||
| 249 | |||
| 250 | &function_begin_B($name,""); | ||
| 251 | |||
| 252 | # parameter 1 is the MD5_CTX structure. | ||
| 253 | # A 0 | ||
| 254 | # B 4 | ||
| 255 | # C 8 | ||
| 256 | # D 12 | ||
| 257 | # E 16 | ||
| 258 | |||
| 259 | &mov("ecx", &wparam(2)); | ||
| 260 | &push("esi"); | ||
| 261 | &shl("ecx",6); | ||
| 262 | &mov("esi", &wparam(1)); | ||
| 263 | &push("ebp"); | ||
| 264 | &add("ecx","esi"); # offset to leave on | ||
| 265 | &push("ebx"); | ||
| 266 | &mov("ebp", &wparam(0)); | ||
| 267 | &push("edi"); | ||
| 268 | &mov($D, &DWP(12,"ebp","",0)); | ||
| 269 | &stack_push(18+9); | ||
| 270 | &mov($E, &DWP(16,"ebp","",0)); | ||
| 271 | &mov($C, &DWP( 8,"ebp","",0)); | ||
| 272 | &mov(&swtmp(17),"ecx"); | ||
| 273 | |||
| 274 | &comment("First we need to setup the X array"); | ||
| 275 | |||
| 276 | &set_label("start") unless $normal; | ||
| 277 | |||
| 278 | &X_expand("esi"); | ||
| 279 | &mov(&wparam(1),"esi"); | ||
| 280 | |||
| 281 | &set_label("shortcut", 0, 1); | ||
| 282 | &comment(""); | ||
| 283 | &comment("Start processing"); | ||
| 284 | |||
| 285 | # odd start | ||
| 286 | &mov($A, &DWP( 0,"ebp","",0)); | ||
| 287 | &mov($B, &DWP( 4,"ebp","",0)); | ||
| 288 | $X="esp"; | ||
| 289 | &BODY_00_15(-2,$K[0],$X, 0,$A,$B,$C,$D,$E,$T); | ||
| 290 | &BODY_00_15( 0,$K[0],$X, 1,$T,$A,$B,$C,$D,$E); | ||
| 291 | &BODY_00_15( 0,$K[0],$X, 2,$E,$T,$A,$B,$C,$D); | ||
| 292 | &BODY_00_15( 0,$K[0],$X, 3,$D,$E,$T,$A,$B,$C); | ||
| 293 | &BODY_00_15( 0,$K[0],$X, 4,$C,$D,$E,$T,$A,$B); | ||
| 294 | &BODY_00_15( 0,$K[0],$X, 5,$B,$C,$D,$E,$T,$A); | ||
| 295 | &BODY_00_15( 0,$K[0],$X, 6,$A,$B,$C,$D,$E,$T); | ||
| 296 | &BODY_00_15( 0,$K[0],$X, 7,$T,$A,$B,$C,$D,$E); | ||
| 297 | &BODY_00_15( 0,$K[0],$X, 8,$E,$T,$A,$B,$C,$D); | ||
| 298 | &BODY_00_15( 0,$K[0],$X, 9,$D,$E,$T,$A,$B,$C); | ||
| 299 | &BODY_00_15( 0,$K[0],$X,10,$C,$D,$E,$T,$A,$B); | ||
| 300 | &BODY_00_15( 0,$K[0],$X,11,$B,$C,$D,$E,$T,$A); | ||
| 301 | &BODY_00_15( 0,$K[0],$X,12,$A,$B,$C,$D,$E,$T); | ||
| 302 | &BODY_00_15( 0,$K[0],$X,13,$T,$A,$B,$C,$D,$E); | ||
| 303 | &BODY_00_15( 0,$K[0],$X,14,$E,$T,$A,$B,$C,$D); | ||
| 304 | &BODY_00_15( 1,$K[0],$X,15,$D,$E,$T,$A,$B,$C); | ||
| 305 | &BODY_16_19(-1,$K[0],$X,16,$C,$D,$E,$T,$A,$B); | ||
| 306 | &BODY_16_19( 0,$K[0],$X,17,$B,$C,$D,$E,$T,$A); | ||
| 307 | &BODY_16_19( 0,$K[0],$X,18,$A,$B,$C,$D,$E,$T); | ||
| 308 | &BODY_16_19( 1,$K[0],$X,19,$T,$A,$B,$C,$D,$E); | ||
| 309 | |||
| 310 | &BODY_20_39(-1,$K[1],$X,20,$E,$T,$A,$B,$C,$D); | ||
| 311 | &BODY_20_39( 0,$K[1],$X,21,$D,$E,$T,$A,$B,$C); | ||
| 312 | &BODY_20_39( 0,$K[1],$X,22,$C,$D,$E,$T,$A,$B); | ||
| 313 | &BODY_20_39( 0,$K[1],$X,23,$B,$C,$D,$E,$T,$A); | ||
| 314 | &BODY_20_39( 0,$K[1],$X,24,$A,$B,$C,$D,$E,$T); | ||
| 315 | &BODY_20_39( 0,$K[1],$X,25,$T,$A,$B,$C,$D,$E); | ||
| 316 | &BODY_20_39( 0,$K[1],$X,26,$E,$T,$A,$B,$C,$D); | ||
| 317 | &BODY_20_39( 0,$K[1],$X,27,$D,$E,$T,$A,$B,$C); | ||
| 318 | &BODY_20_39( 0,$K[1],$X,28,$C,$D,$E,$T,$A,$B); | ||
| 319 | &BODY_20_39( 0,$K[1],$X,29,$B,$C,$D,$E,$T,$A); | ||
| 320 | &BODY_20_39( 0,$K[1],$X,30,$A,$B,$C,$D,$E,$T); | ||
| 321 | &BODY_20_39( 0,$K[1],$X,31,$T,$A,$B,$C,$D,$E); | ||
| 322 | &BODY_20_39( 0,$K[1],$X,32,$E,$T,$A,$B,$C,$D); | ||
| 323 | &BODY_20_39( 0,$K[1],$X,33,$D,$E,$T,$A,$B,$C); | ||
| 324 | &BODY_20_39( 0,$K[1],$X,34,$C,$D,$E,$T,$A,$B); | ||
| 325 | &BODY_20_39( 0,$K[1],$X,35,$B,$C,$D,$E,$T,$A); | ||
| 326 | &BODY_20_39( 0,$K[1],$X,36,$A,$B,$C,$D,$E,$T); | ||
| 327 | &BODY_20_39( 0,$K[1],$X,37,$T,$A,$B,$C,$D,$E); | ||
| 328 | &BODY_20_39( 0,$K[1],$X,38,$E,$T,$A,$B,$C,$D); | ||
| 329 | &BODY_20_39( 1,$K[1],$X,39,$D,$E,$T,$A,$B,$C); | ||
| 330 | |||
| 331 | &BODY_40_59(-1,$K[2],$X,40,$C,$D,$E,$T,$A,$B); | ||
| 332 | &BODY_40_59( 0,$K[2],$X,41,$B,$C,$D,$E,$T,$A); | ||
| 333 | &BODY_40_59( 0,$K[2],$X,42,$A,$B,$C,$D,$E,$T); | ||
| 334 | &BODY_40_59( 0,$K[2],$X,43,$T,$A,$B,$C,$D,$E); | ||
| 335 | &BODY_40_59( 0,$K[2],$X,44,$E,$T,$A,$B,$C,$D); | ||
| 336 | &BODY_40_59( 0,$K[2],$X,45,$D,$E,$T,$A,$B,$C); | ||
| 337 | &BODY_40_59( 0,$K[2],$X,46,$C,$D,$E,$T,$A,$B); | ||
| 338 | &BODY_40_59( 0,$K[2],$X,47,$B,$C,$D,$E,$T,$A); | ||
| 339 | &BODY_40_59( 0,$K[2],$X,48,$A,$B,$C,$D,$E,$T); | ||
| 340 | &BODY_40_59( 0,$K[2],$X,49,$T,$A,$B,$C,$D,$E); | ||
| 341 | &BODY_40_59( 0,$K[2],$X,50,$E,$T,$A,$B,$C,$D); | ||
| 342 | &BODY_40_59( 0,$K[2],$X,51,$D,$E,$T,$A,$B,$C); | ||
| 343 | &BODY_40_59( 0,$K[2],$X,52,$C,$D,$E,$T,$A,$B); | ||
| 344 | &BODY_40_59( 0,$K[2],$X,53,$B,$C,$D,$E,$T,$A); | ||
| 345 | &BODY_40_59( 0,$K[2],$X,54,$A,$B,$C,$D,$E,$T); | ||
| 346 | &BODY_40_59( 0,$K[2],$X,55,$T,$A,$B,$C,$D,$E); | ||
| 347 | &BODY_40_59( 0,$K[2],$X,56,$E,$T,$A,$B,$C,$D); | ||
| 348 | &BODY_40_59( 0,$K[2],$X,57,$D,$E,$T,$A,$B,$C); | ||
| 349 | &BODY_40_59( 0,$K[2],$X,58,$C,$D,$E,$T,$A,$B); | ||
| 350 | &BODY_40_59( 1,$K[2],$X,59,$B,$C,$D,$E,$T,$A); | ||
| 351 | |||
| 352 | &BODY_60_79(-1,$K[3],$X,60,$A,$B,$C,$D,$E,$T); | ||
| 353 | &BODY_60_79( 0,$K[3],$X,61,$T,$A,$B,$C,$D,$E); | ||
| 354 | &BODY_60_79( 0,$K[3],$X,62,$E,$T,$A,$B,$C,$D); | ||
| 355 | &BODY_60_79( 0,$K[3],$X,63,$D,$E,$T,$A,$B,$C); | ||
| 356 | &BODY_60_79( 0,$K[3],$X,64,$C,$D,$E,$T,$A,$B); | ||
| 357 | &BODY_60_79( 0,$K[3],$X,65,$B,$C,$D,$E,$T,$A); | ||
| 358 | &BODY_60_79( 0,$K[3],$X,66,$A,$B,$C,$D,$E,$T); | ||
| 359 | &BODY_60_79( 0,$K[3],$X,67,$T,$A,$B,$C,$D,$E); | ||
| 360 | &BODY_60_79( 0,$K[3],$X,68,$E,$T,$A,$B,$C,$D); | ||
| 361 | &BODY_60_79( 0,$K[3],$X,69,$D,$E,$T,$A,$B,$C); | ||
| 362 | &BODY_60_79( 0,$K[3],$X,70,$C,$D,$E,$T,$A,$B); | ||
| 363 | &BODY_60_79( 0,$K[3],$X,71,$B,$C,$D,$E,$T,$A); | ||
| 364 | &BODY_60_79( 0,$K[3],$X,72,$A,$B,$C,$D,$E,$T); | ||
| 365 | &BODY_60_79( 0,$K[3],$X,73,$T,$A,$B,$C,$D,$E); | ||
| 366 | &BODY_60_79( 0,$K[3],$X,74,$E,$T,$A,$B,$C,$D); | ||
| 367 | &BODY_60_79( 0,$K[3],$X,75,$D,$E,$T,$A,$B,$C); | ||
| 368 | &BODY_60_79( 0,$K[3],$X,76,$C,$D,$E,$T,$A,$B); | ||
| 369 | &BODY_60_79( 0,$K[3],$X,77,$B,$C,$D,$E,$T,$A); | ||
| 370 | &BODY_60_79( 0,$K[3],$X,78,$A,$B,$C,$D,$E,$T); | ||
| 371 | &BODY_60_79( 2,$K[3],$X,79,$T,$A,$B,$C,$D,$E); | ||
| 372 | |||
| 373 | &comment("End processing"); | ||
| 374 | &comment(""); | ||
| 375 | # D is the tmp value | ||
| 376 | |||
| 377 | # E -> A | ||
| 378 | # T -> B | ||
| 379 | # A -> C | ||
| 380 | # B -> D | ||
| 381 | # C -> E | ||
| 382 | # D -> T | ||
| 383 | |||
| 384 | &mov($tmp1,&wparam(0)); | ||
| 385 | |||
| 386 | &mov($D, &DWP(12,$tmp1,"",0)); | ||
| 387 | &add($D,$B); | ||
| 388 | &mov($B, &DWP( 4,$tmp1,"",0)); | ||
| 389 | &add($B,$T); | ||
| 390 | &mov($T, $A); | ||
| 391 | &mov($A, &DWP( 0,$tmp1,"",0)); | ||
| 392 | &mov(&DWP(12,$tmp1,"",0),$D); | ||
| 393 | |||
| 394 | &add($A,$E); | ||
| 395 | &mov($E, &DWP(16,$tmp1,"",0)); | ||
| 396 | &add($E,$C); | ||
| 397 | &mov($C, &DWP( 8,$tmp1,"",0)); | ||
| 398 | &add($C,$T); | ||
| 399 | |||
| 400 | &mov(&DWP( 0,$tmp1,"",0),$A); | ||
| 401 | &mov("esi",&wparam(1)); | ||
| 402 | &mov(&DWP( 8,$tmp1,"",0),$C); | ||
| 403 | &add("esi",64); | ||
| 404 | &mov("eax",&swtmp(17)); | ||
| 405 | &mov(&DWP(16,$tmp1,"",0),$E); | ||
| 406 | &cmp("esi","eax"); | ||
| 407 | &mov(&DWP( 4,$tmp1,"",0),$B); | ||
| 408 | &jb(&label("start")); | ||
| 409 | |||
| 410 | &stack_pop(18+9); | ||
| 411 | &pop("edi"); | ||
| 412 | &pop("ebx"); | ||
| 413 | &pop("ebp"); | ||
| 414 | &pop("esi"); | ||
| 415 | &ret(); | ||
| 416 | |||
| 417 | # keep a note of shortcut label so it can be used outside | ||
| 418 | # block. | ||
| 419 | my $sclabel = &label("shortcut"); | ||
| 420 | |||
| 421 | &function_end_B($name); | ||
| 422 | # Putting this here avoids problems with MASM in debugging mode | ||
| 423 | &sha1_block_host("sha1_block_asm_host_order", $sclabel); | ||
| 424 | } | ||
| 425 | |||
diff --git a/src/lib/libcrypto/sha/asm/sha1-ia64.pl b/src/lib/libcrypto/sha/asm/sha1-ia64.pl new file mode 100644 index 0000000000..cb9dfad124 --- /dev/null +++ b/src/lib/libcrypto/sha/asm/sha1-ia64.pl | |||
| @@ -0,0 +1,549 @@ | |||
| 1 | #!/usr/bin/env perl | ||
| 2 | # | ||
| 3 | # ==================================================================== | ||
| 4 | # Written by Andy Polyakov <appro@fy.chalmers.se> for the OpenSSL | ||
| 5 | # project. Rights for redistribution and usage in source and binary | ||
| 6 | # forms are granted according to the OpenSSL license. | ||
| 7 | # ==================================================================== | ||
| 8 | # | ||
| 9 | # Eternal question is what's wrong with compiler generated code? The | ||
| 10 | # trick is that it's possible to reduce the number of shifts required | ||
| 11 | # to perform rotations by maintaining copy of 32-bit value in upper | ||
| 12 | # bits of 64-bit register. Just follow mux2 and shrp instructions... | ||
| 13 | # Performance under big-endian OS such as HP-UX is 179MBps*1GHz, which | ||
| 14 | # is >50% better than HP C and >2x better than gcc. As of this moment | ||
| 15 | # performance under little-endian OS such as Linux and Windows will be | ||
| 16 | # a bit lower, because data has to be picked in reverse byte-order. | ||
| 17 | # It's possible to resolve this issue by implementing third function, | ||
| 18 | # sha1_block_asm_data_order_aligned, which would temporarily flip | ||
| 19 | # BE field in User Mask register... | ||
| 20 | |||
| 21 | $code=<<___; | ||
| 22 | .ident \"sha1-ia64.s, version 1.0\" | ||
| 23 | .ident \"IA-64 ISA artwork by Andy Polyakov <appro\@fy.chalmers.se>\" | ||
| 24 | .explicit | ||
| 25 | |||
| 26 | ___ | ||
| 27 | |||
| 28 | |||
| 29 | if ($^O eq "hpux") { | ||
| 30 | $ADDP="addp4"; | ||
| 31 | for (@ARGV) { $ADDP="add" if (/[\+DD|\-mlp]64/); } | ||
| 32 | } else { $ADDP="add"; } | ||
| 33 | for (@ARGV) { $big_endian=1 if (/\-DB_ENDIAN/); | ||
| 34 | $big_endian=0 if (/\-DL_ENDIAN/); } | ||
| 35 | if (!defined($big_endian)) | ||
| 36 | { $big_endian=(unpack('L',pack('N',1))==1); } | ||
| 37 | |||
| 38 | #$human=1; | ||
| 39 | if ($human) { # useful for visual code auditing... | ||
| 40 | ($A,$B,$C,$D,$E,$T) = ("A","B","C","D","E","T"); | ||
| 41 | ($h0,$h1,$h2,$h3,$h4) = ("h0","h1","h2","h3","h4"); | ||
| 42 | ($K_00_19, $K_20_39, $K_40_59, $K_60_79) = | ||
| 43 | ( "K_00_19","K_20_39","K_40_59","K_60_79" ); | ||
| 44 | @X= ( "X0", "X1", "X2", "X3", "X4", "X5", "X6", "X7", | ||
| 45 | "X8", "X9","X10","X11","X12","X13","X14","X15" ); | ||
| 46 | } | ||
| 47 | else { | ||
| 48 | ($A,$B,$C,$D,$E,$T) = ("loc0","loc1","loc2","loc3","loc4","loc5"); | ||
| 49 | ($h0,$h1,$h2,$h3,$h4) = ("loc6","loc7","loc8","loc9","loc10"); | ||
| 50 | ($K_00_19, $K_20_39, $K_40_59, $K_60_79) = | ||
| 51 | ( "r14", "r15", "loc11", "loc12" ); | ||
| 52 | @X= ( "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23", | ||
| 53 | "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31" ); | ||
| 54 | } | ||
| 55 | |||
| 56 | sub BODY_00_15 { | ||
| 57 | local *code=shift; | ||
| 58 | local ($i,$a,$b,$c,$d,$e,$f,$unaligned)=@_; | ||
| 59 | |||
| 60 | if ($unaligned) { | ||
| 61 | $code.=<<___; | ||
| 62 | { .mmi; ld1 tmp0=[inp],2 // MSB | ||
| 63 | ld1 tmp1=[tmp3],2 };; | ||
| 64 | { .mmi; ld1 tmp2=[inp],2 | ||
| 65 | ld1 $X[$i&0xf]=[tmp3],2 // LSB | ||
| 66 | dep tmp1=tmp0,tmp1,8,8 };; | ||
| 67 | { .mii; cmp.ne p16,p0=r0,r0 // no misaligned prefetch | ||
| 68 | dep $X[$i&0xf]=tmp2,$X[$i&0xf],8,8;; | ||
| 69 | dep $X[$i&0xf]=tmp1,$X[$i&0xf],16,16 };; | ||
| 70 | { .mmi; nop.m 0 | ||
| 71 | ___ | ||
| 72 | } | ||
| 73 | elsif ($i<15) { | ||
| 74 | $code.=<<___; | ||
| 75 | { .mmi; ld4 $X[($i+1)&0xf]=[inp],4 // prefetch | ||
| 76 | ___ | ||
| 77 | } | ||
| 78 | else { | ||
| 79 | $code.=<<___; | ||
| 80 | { .mmi; nop.m 0 | ||
| 81 | ___ | ||
| 82 | } | ||
| 83 | if ($i<15) { | ||
| 84 | $code.=<<___; | ||
| 85 | and tmp0=$c,$b | ||
| 86 | dep.z tmp5=$a,5,27 } // a<<5 | ||
| 87 | { .mmi; andcm tmp1=$d,$b | ||
| 88 | add tmp4=$e,$K_00_19 };; | ||
| 89 | { .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d) | ||
| 90 | add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19 | ||
| 91 | extr.u tmp1=$a,27,5 };; // a>>27 | ||
| 92 | { .mib; add $f=$f,tmp0 // f+=F_00_19(b,c,d) | ||
| 93 | shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) | ||
| 94 | { .mib; or tmp1=tmp1,tmp5 // ROTATE(a,5) | ||
| 95 | mux2 tmp6=$a,0x44 };; // see b in next iteration | ||
| 96 | { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5) | ||
| 97 | mux2 $X[$i&0xf]=$X[$i&0xf],0x44 | ||
| 98 | nop.i 0 };; | ||
| 99 | |||
| 100 | ___ | ||
| 101 | } | ||
| 102 | else { | ||
| 103 | $code.=<<___; | ||
| 104 | and tmp0=$c,$b | ||
| 105 | dep.z tmp5=$a,5,27 } // a<<5 ;;? | ||
| 106 | { .mmi; andcm tmp1=$d,$b | ||
| 107 | add tmp4=$e,$K_00_19 };; | ||
| 108 | { .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d) | ||
| 109 | add $f=tmp4,$X[$i&0xf] // f=xi+e+K_00_19 | ||
| 110 | extr.u tmp1=$a,27,5 } // a>>27 | ||
| 111 | { .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1 | ||
| 112 | xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1 | ||
| 113 | nop.i 0 };; | ||
| 114 | { .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d) | ||
| 115 | xor tmp2=tmp2,tmp3 // +1 | ||
| 116 | shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) | ||
| 117 | { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5) | ||
| 118 | mux2 tmp6=$a,0x44 };; // see b in next iteration | ||
| 119 | { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5) | ||
| 120 | shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1) | ||
| 121 | mux2 $X[$i&0xf]=$X[$i&0xf],0x44 };; | ||
| 122 | |||
| 123 | ___ | ||
| 124 | } | ||
| 125 | } | ||
| 126 | |||
| 127 | sub BODY_16_19 { | ||
| 128 | local *code=shift; | ||
| 129 | local ($i,$a,$b,$c,$d,$e,$f)=@_; | ||
| 130 | |||
| 131 | $code.=<<___; | ||
| 132 | { .mmi; mov $X[$i&0xf]=$f // Xupdate | ||
| 133 | and tmp0=$c,$b | ||
| 134 | dep.z tmp5=$a,5,27 } // a<<5 | ||
| 135 | { .mmi; andcm tmp1=$d,$b | ||
| 136 | add tmp4=$e,$K_00_19 };; | ||
| 137 | { .mmi; or tmp0=tmp0,tmp1 // F_00_19(b,c,d)=(b&c)|(~b&d) | ||
| 138 | add $f=$f,tmp4 // f+=e+K_00_19 | ||
| 139 | extr.u tmp1=$a,27,5 } // a>>27 | ||
| 140 | { .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1 | ||
| 141 | xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1 | ||
| 142 | nop.i 0 };; | ||
| 143 | { .mmi; add $f=$f,tmp0 // f+=F_00_19(b,c,d) | ||
| 144 | xor tmp2=tmp2,tmp3 // +1 | ||
| 145 | shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) | ||
| 146 | { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5) | ||
| 147 | mux2 tmp6=$a,0x44 };; // see b in next iteration | ||
| 148 | { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5) | ||
| 149 | shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1) | ||
| 150 | nop.i 0 };; | ||
| 151 | |||
| 152 | ___ | ||
| 153 | } | ||
| 154 | |||
| 155 | sub BODY_20_39 { | ||
| 156 | local *code=shift; | ||
| 157 | local ($i,$a,$b,$c,$d,$e,$f,$Konst)=@_; | ||
| 158 | $Konst = $K_20_39 if (!defined($Konst)); | ||
| 159 | |||
| 160 | if ($i<79) { | ||
| 161 | $code.=<<___; | ||
| 162 | { .mib; mov $X[$i&0xf]=$f // Xupdate | ||
| 163 | dep.z tmp5=$a,5,27 } // a<<5 | ||
| 164 | { .mib; xor tmp0=$c,$b | ||
| 165 | add tmp4=$e,$Konst };; | ||
| 166 | { .mmi; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d | ||
| 167 | add $f=$f,tmp4 // f+=e+K_20_39 | ||
| 168 | extr.u tmp1=$a,27,5 } // a>>27 | ||
| 169 | { .mmi; xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1 | ||
| 170 | xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1 | ||
| 171 | nop.i 0 };; | ||
| 172 | { .mmi; add $f=$f,tmp0 // f+=F_20_39(b,c,d) | ||
| 173 | xor tmp2=tmp2,tmp3 // +1 | ||
| 174 | shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) | ||
| 175 | { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5) | ||
| 176 | mux2 tmp6=$a,0x44 };; // see b in next iteration | ||
| 177 | { .mii; add $f=$f,tmp1 // f+=ROTATE(a,5) | ||
| 178 | shrp $e=tmp2,tmp2,31 // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1) | ||
| 179 | nop.i 0 };; | ||
| 180 | |||
| 181 | ___ | ||
| 182 | } | ||
| 183 | else { | ||
| 184 | $code.=<<___; | ||
| 185 | { .mib; mov $X[$i&0xf]=$f // Xupdate | ||
| 186 | dep.z tmp5=$a,5,27 } // a<<5 | ||
| 187 | { .mib; xor tmp0=$c,$b | ||
| 188 | add tmp4=$e,$Konst };; | ||
| 189 | { .mib; xor tmp0=tmp0,$d // F_20_39(b,c,d)=b^c^d | ||
| 190 | extr.u tmp1=$a,27,5 } // a>>27 | ||
| 191 | { .mib; add $f=$f,tmp4 // f+=e+K_20_39 | ||
| 192 | add $h1=$h1,$a };; // wrap up | ||
| 193 | { .mmi; | ||
| 194 | (p16) ld4.s $X[0]=[inp],4 // non-faulting prefetch | ||
| 195 | add $f=$f,tmp0 // f+=F_20_39(b,c,d) | ||
| 196 | shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) ;;? | ||
| 197 | { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5) | ||
| 198 | add $h3=$h3,$c };; // wrap up | ||
| 199 | { .mib; add tmp3=1,inp // used in unaligned codepath | ||
| 200 | add $f=$f,tmp1 } // f+=ROTATE(a,5) | ||
| 201 | { .mib; add $h2=$h2,$b // wrap up | ||
| 202 | add $h4=$h4,$d };; // wrap up | ||
| 203 | |||
| 204 | ___ | ||
| 205 | } | ||
| 206 | } | ||
| 207 | |||
| 208 | sub BODY_40_59 { | ||
| 209 | local *code=shift; | ||
| 210 | local ($i,$a,$b,$c,$d,$e,$f)=@_; | ||
| 211 | |||
| 212 | $code.=<<___; | ||
| 213 | { .mmi; mov $X[$i&0xf]=$f // Xupdate | ||
| 214 | and tmp0=$c,$b | ||
| 215 | dep.z tmp5=$a,5,27 } // a<<5 | ||
| 216 | { .mmi; and tmp1=$d,$b | ||
| 217 | add tmp4=$e,$K_40_59 };; | ||
| 218 | { .mmi; or tmp0=tmp0,tmp1 // (b&c)|(b&d) | ||
| 219 | add $f=$f,tmp4 // f+=e+K_40_59 | ||
| 220 | extr.u tmp1=$a,27,5 } // a>>27 | ||
| 221 | { .mmi; and tmp4=$c,$d | ||
| 222 | xor tmp2=$X[($i+0+1)&0xf],$X[($i+2+1)&0xf] // +1 | ||
| 223 | xor tmp3=$X[($i+8+1)&0xf],$X[($i+13+1)&0xf] // +1 | ||
| 224 | };; | ||
| 225 | { .mmi; or tmp1=tmp1,tmp5 // ROTATE(a,5) | ||
| 226 | xor tmp2=tmp2,tmp3 // +1 | ||
| 227 | shrp $b=tmp6,tmp6,2 } // b=ROTATE(b,30) | ||
| 228 | { .mmi; or tmp0=tmp0,tmp4 // F_40_59(b,c,d)=(b&c)|(b&d)|(c&d) | ||
| 229 | mux2 tmp6=$a,0x44 };; // see b in next iteration | ||
| 230 | { .mii; add $f=$f,tmp0 // f+=F_40_59(b,c,d) | ||
| 231 | shrp $e=tmp2,tmp2,31;; // f+1=ROTATE(x[0]^x[2]^x[8]^x[13],1) | ||
| 232 | add $f=$f,tmp1 };; // f+=ROTATE(a,5) | ||
| 233 | |||
| 234 | ___ | ||
| 235 | } | ||
| 236 | sub BODY_60_79 { &BODY_20_39(@_,$K_60_79); } | ||
| 237 | |||
| 238 | $code.=<<___; | ||
| 239 | .text | ||
| 240 | |||
| 241 | tmp0=r8; | ||
| 242 | tmp1=r9; | ||
| 243 | tmp2=r10; | ||
| 244 | tmp3=r11; | ||
| 245 | ctx=r32; // in0 | ||
| 246 | inp=r33; // in1 | ||
| 247 | |||
| 248 | // void sha1_block_asm_host_order(SHA_CTX *c,const void *p,size_t num); | ||
| 249 | .global sha1_block_asm_host_order# | ||
| 250 | .proc sha1_block_asm_host_order# | ||
| 251 | .align 32 | ||
| 252 | sha1_block_asm_host_order: | ||
| 253 | .prologue | ||
| 254 | .fframe 0 | ||
| 255 | .save ar.pfs,r0 | ||
| 256 | .save ar.lc,r3 | ||
| 257 | { .mmi; alloc tmp1=ar.pfs,3,15,0,0 | ||
| 258 | $ADDP tmp0=4,ctx | ||
| 259 | mov r3=ar.lc } | ||
| 260 | { .mmi; $ADDP ctx=0,ctx | ||
| 261 | $ADDP inp=0,inp | ||
| 262 | mov r2=pr };; | ||
| 263 | tmp4=in2; | ||
| 264 | tmp5=loc13; | ||
| 265 | tmp6=loc14; | ||
| 266 | .body | ||
| 267 | { .mlx; ld4 $h0=[ctx],8 | ||
| 268 | movl $K_00_19=0x5a827999 } | ||
| 269 | { .mlx; ld4 $h1=[tmp0],8 | ||
| 270 | movl $K_20_39=0x6ed9eba1 };; | ||
| 271 | { .mlx; ld4 $h2=[ctx],8 | ||
| 272 | movl $K_40_59=0x8f1bbcdc } | ||
| 273 | { .mlx; ld4 $h3=[tmp0] | ||
| 274 | movl $K_60_79=0xca62c1d6 };; | ||
| 275 | { .mmi; ld4 $h4=[ctx],-16 | ||
| 276 | add in2=-1,in2 // adjust num for ar.lc | ||
| 277 | mov ar.ec=1 };; | ||
| 278 | { .mmi; ld4 $X[0]=[inp],4 // prefetch | ||
| 279 | cmp.ne p16,p0=r0,in2 // prefecth at loop end | ||
| 280 | mov ar.lc=in2 };; // brp.loop.imp: too far | ||
| 281 | |||
| 282 | .Lhtop: | ||
| 283 | { .mmi; mov $A=$h0 | ||
| 284 | mov $B=$h1 | ||
| 285 | mux2 tmp6=$h1,0x44 } | ||
| 286 | { .mmi; mov $C=$h2 | ||
| 287 | mov $D=$h3 | ||
| 288 | mov $E=$h4 };; | ||
| 289 | |||
| 290 | ___ | ||
| 291 | |||
| 292 | &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T); | ||
| 293 | &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E); | ||
| 294 | &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D); | ||
| 295 | &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C); | ||
| 296 | &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B); | ||
| 297 | &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A); | ||
| 298 | &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T); | ||
| 299 | &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E); | ||
| 300 | &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D); | ||
| 301 | &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C); | ||
| 302 | &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B); | ||
| 303 | &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A); | ||
| 304 | &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T); | ||
| 305 | &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E); | ||
| 306 | &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D); | ||
| 307 | &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C); | ||
| 308 | |||
| 309 | &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B); | ||
| 310 | &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A); | ||
| 311 | &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T); | ||
| 312 | &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E); | ||
| 313 | |||
| 314 | &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D); | ||
| 315 | &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C); | ||
| 316 | &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B); | ||
| 317 | &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A); | ||
| 318 | &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T); | ||
| 319 | &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E); | ||
| 320 | &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D); | ||
| 321 | &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C); | ||
| 322 | &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B); | ||
| 323 | &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A); | ||
| 324 | &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T); | ||
| 325 | &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E); | ||
| 326 | &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D); | ||
| 327 | &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C); | ||
| 328 | &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B); | ||
| 329 | &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A); | ||
| 330 | &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T); | ||
| 331 | &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E); | ||
| 332 | &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D); | ||
| 333 | &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C); | ||
| 334 | |||
| 335 | &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B); | ||
| 336 | &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A); | ||
| 337 | &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T); | ||
| 338 | &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E); | ||
| 339 | &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D); | ||
| 340 | &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C); | ||
| 341 | &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B); | ||
| 342 | &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A); | ||
| 343 | &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T); | ||
| 344 | &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E); | ||
| 345 | &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D); | ||
| 346 | &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C); | ||
| 347 | &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B); | ||
| 348 | &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A); | ||
| 349 | &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T); | ||
| 350 | &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E); | ||
| 351 | &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D); | ||
| 352 | &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C); | ||
| 353 | &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B); | ||
| 354 | &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A); | ||
| 355 | |||
| 356 | &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T); | ||
| 357 | &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E); | ||
| 358 | &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D); | ||
| 359 | &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C); | ||
| 360 | &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B); | ||
| 361 | &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A); | ||
| 362 | &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T); | ||
| 363 | &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E); | ||
| 364 | &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D); | ||
| 365 | &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C); | ||
| 366 | &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B); | ||
| 367 | &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A); | ||
| 368 | &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T); | ||
| 369 | &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E); | ||
| 370 | &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D); | ||
| 371 | &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C); | ||
| 372 | &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B); | ||
| 373 | &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A); | ||
| 374 | &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T); | ||
| 375 | &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E); | ||
| 376 | |||
| 377 | $code.=<<___; | ||
| 378 | { .mmb; add $h0=$h0,$E | ||
| 379 | nop.m 0 | ||
| 380 | br.ctop.dptk.many .Lhtop };; | ||
| 381 | .Lhend: | ||
| 382 | { .mmi; add tmp0=4,ctx | ||
| 383 | mov ar.lc=r3 };; | ||
| 384 | { .mmi; st4 [ctx]=$h0,8 | ||
| 385 | st4 [tmp0]=$h1,8 };; | ||
| 386 | { .mmi; st4 [ctx]=$h2,8 | ||
| 387 | st4 [tmp0]=$h3 };; | ||
| 388 | { .mib; st4 [ctx]=$h4,-16 | ||
| 389 | mov pr=r2,0x1ffff | ||
| 390 | br.ret.sptk.many b0 };; | ||
| 391 | .endp sha1_block_asm_host_order# | ||
| 392 | ___ | ||
| 393 | |||
| 394 | |||
| 395 | $code.=<<___; | ||
| 396 | // void sha1_block_asm_data_order(SHA_CTX *c,const void *p,size_t num); | ||
| 397 | .global sha1_block_asm_data_order# | ||
| 398 | .proc sha1_block_asm_data_order# | ||
| 399 | .align 32 | ||
| 400 | sha1_block_asm_data_order: | ||
| 401 | ___ | ||
| 402 | $code.=<<___ if ($big_endian); | ||
| 403 | { .mmi; and r2=3,inp };; | ||
| 404 | { .mib; cmp.eq p6,p0=r0,r2 | ||
| 405 | (p6) br.dptk.many sha1_block_asm_host_order };; | ||
| 406 | ___ | ||
| 407 | $code.=<<___; | ||
| 408 | .prologue | ||
| 409 | .fframe 0 | ||
| 410 | .save ar.pfs,r0 | ||
| 411 | .save ar.lc,r3 | ||
| 412 | { .mmi; alloc tmp1=ar.pfs,3,15,0,0 | ||
| 413 | $ADDP tmp0=4,ctx | ||
| 414 | mov r3=ar.lc } | ||
| 415 | { .mmi; $ADDP ctx=0,ctx | ||
| 416 | $ADDP inp=0,inp | ||
| 417 | mov r2=pr };; | ||
| 418 | tmp4=in2; | ||
| 419 | tmp5=loc13; | ||
| 420 | tmp6=loc14; | ||
| 421 | .body | ||
| 422 | { .mlx; ld4 $h0=[ctx],8 | ||
| 423 | movl $K_00_19=0x5a827999 } | ||
| 424 | { .mlx; ld4 $h1=[tmp0],8 | ||
| 425 | movl $K_20_39=0x6ed9eba1 };; | ||
| 426 | { .mlx; ld4 $h2=[ctx],8 | ||
| 427 | movl $K_40_59=0x8f1bbcdc } | ||
| 428 | { .mlx; ld4 $h3=[tmp0] | ||
| 429 | movl $K_60_79=0xca62c1d6 };; | ||
| 430 | { .mmi; ld4 $h4=[ctx],-16 | ||
| 431 | add in2=-1,in2 // adjust num for ar.lc | ||
| 432 | mov ar.ec=1 };; | ||
| 433 | { .mmi; nop.m 0 | ||
| 434 | add tmp3=1,inp | ||
| 435 | mov ar.lc=in2 };; // brp.loop.imp: too far | ||
| 436 | |||
| 437 | .Ldtop: | ||
| 438 | { .mmi; mov $A=$h0 | ||
| 439 | mov $B=$h1 | ||
| 440 | mux2 tmp6=$h1,0x44 } | ||
| 441 | { .mmi; mov $C=$h2 | ||
| 442 | mov $D=$h3 | ||
| 443 | mov $E=$h4 };; | ||
| 444 | |||
| 445 | ___ | ||
| 446 | |||
| 447 | &BODY_00_15(\$code, 0,$A,$B,$C,$D,$E,$T,1); | ||
| 448 | &BODY_00_15(\$code, 1,$T,$A,$B,$C,$D,$E,1); | ||
| 449 | &BODY_00_15(\$code, 2,$E,$T,$A,$B,$C,$D,1); | ||
| 450 | &BODY_00_15(\$code, 3,$D,$E,$T,$A,$B,$C,1); | ||
| 451 | &BODY_00_15(\$code, 4,$C,$D,$E,$T,$A,$B,1); | ||
| 452 | &BODY_00_15(\$code, 5,$B,$C,$D,$E,$T,$A,1); | ||
| 453 | &BODY_00_15(\$code, 6,$A,$B,$C,$D,$E,$T,1); | ||
| 454 | &BODY_00_15(\$code, 7,$T,$A,$B,$C,$D,$E,1); | ||
| 455 | &BODY_00_15(\$code, 8,$E,$T,$A,$B,$C,$D,1); | ||
| 456 | &BODY_00_15(\$code, 9,$D,$E,$T,$A,$B,$C,1); | ||
| 457 | &BODY_00_15(\$code,10,$C,$D,$E,$T,$A,$B,1); | ||
| 458 | &BODY_00_15(\$code,11,$B,$C,$D,$E,$T,$A,1); | ||
| 459 | &BODY_00_15(\$code,12,$A,$B,$C,$D,$E,$T,1); | ||
| 460 | &BODY_00_15(\$code,13,$T,$A,$B,$C,$D,$E,1); | ||
| 461 | &BODY_00_15(\$code,14,$E,$T,$A,$B,$C,$D,1); | ||
| 462 | &BODY_00_15(\$code,15,$D,$E,$T,$A,$B,$C,1); | ||
| 463 | |||
| 464 | &BODY_16_19(\$code,16,$C,$D,$E,$T,$A,$B); | ||
| 465 | &BODY_16_19(\$code,17,$B,$C,$D,$E,$T,$A); | ||
| 466 | &BODY_16_19(\$code,18,$A,$B,$C,$D,$E,$T); | ||
| 467 | &BODY_16_19(\$code,19,$T,$A,$B,$C,$D,$E); | ||
| 468 | |||
| 469 | &BODY_20_39(\$code,20,$E,$T,$A,$B,$C,$D); | ||
| 470 | &BODY_20_39(\$code,21,$D,$E,$T,$A,$B,$C); | ||
| 471 | &BODY_20_39(\$code,22,$C,$D,$E,$T,$A,$B); | ||
| 472 | &BODY_20_39(\$code,23,$B,$C,$D,$E,$T,$A); | ||
| 473 | &BODY_20_39(\$code,24,$A,$B,$C,$D,$E,$T); | ||
| 474 | &BODY_20_39(\$code,25,$T,$A,$B,$C,$D,$E); | ||
| 475 | &BODY_20_39(\$code,26,$E,$T,$A,$B,$C,$D); | ||
| 476 | &BODY_20_39(\$code,27,$D,$E,$T,$A,$B,$C); | ||
| 477 | &BODY_20_39(\$code,28,$C,$D,$E,$T,$A,$B); | ||
| 478 | &BODY_20_39(\$code,29,$B,$C,$D,$E,$T,$A); | ||
| 479 | &BODY_20_39(\$code,30,$A,$B,$C,$D,$E,$T); | ||
| 480 | &BODY_20_39(\$code,31,$T,$A,$B,$C,$D,$E); | ||
| 481 | &BODY_20_39(\$code,32,$E,$T,$A,$B,$C,$D); | ||
| 482 | &BODY_20_39(\$code,33,$D,$E,$T,$A,$B,$C); | ||
| 483 | &BODY_20_39(\$code,34,$C,$D,$E,$T,$A,$B); | ||
| 484 | &BODY_20_39(\$code,35,$B,$C,$D,$E,$T,$A); | ||
| 485 | &BODY_20_39(\$code,36,$A,$B,$C,$D,$E,$T); | ||
| 486 | &BODY_20_39(\$code,37,$T,$A,$B,$C,$D,$E); | ||
| 487 | &BODY_20_39(\$code,38,$E,$T,$A,$B,$C,$D); | ||
| 488 | &BODY_20_39(\$code,39,$D,$E,$T,$A,$B,$C); | ||
| 489 | |||
| 490 | &BODY_40_59(\$code,40,$C,$D,$E,$T,$A,$B); | ||
| 491 | &BODY_40_59(\$code,41,$B,$C,$D,$E,$T,$A); | ||
| 492 | &BODY_40_59(\$code,42,$A,$B,$C,$D,$E,$T); | ||
| 493 | &BODY_40_59(\$code,43,$T,$A,$B,$C,$D,$E); | ||
| 494 | &BODY_40_59(\$code,44,$E,$T,$A,$B,$C,$D); | ||
| 495 | &BODY_40_59(\$code,45,$D,$E,$T,$A,$B,$C); | ||
| 496 | &BODY_40_59(\$code,46,$C,$D,$E,$T,$A,$B); | ||
| 497 | &BODY_40_59(\$code,47,$B,$C,$D,$E,$T,$A); | ||
| 498 | &BODY_40_59(\$code,48,$A,$B,$C,$D,$E,$T); | ||
| 499 | &BODY_40_59(\$code,49,$T,$A,$B,$C,$D,$E); | ||
| 500 | &BODY_40_59(\$code,50,$E,$T,$A,$B,$C,$D); | ||
| 501 | &BODY_40_59(\$code,51,$D,$E,$T,$A,$B,$C); | ||
| 502 | &BODY_40_59(\$code,52,$C,$D,$E,$T,$A,$B); | ||
| 503 | &BODY_40_59(\$code,53,$B,$C,$D,$E,$T,$A); | ||
| 504 | &BODY_40_59(\$code,54,$A,$B,$C,$D,$E,$T); | ||
| 505 | &BODY_40_59(\$code,55,$T,$A,$B,$C,$D,$E); | ||
| 506 | &BODY_40_59(\$code,56,$E,$T,$A,$B,$C,$D); | ||
| 507 | &BODY_40_59(\$code,57,$D,$E,$T,$A,$B,$C); | ||
| 508 | &BODY_40_59(\$code,58,$C,$D,$E,$T,$A,$B); | ||
| 509 | &BODY_40_59(\$code,59,$B,$C,$D,$E,$T,$A); | ||
| 510 | |||
| 511 | &BODY_60_79(\$code,60,$A,$B,$C,$D,$E,$T); | ||
| 512 | &BODY_60_79(\$code,61,$T,$A,$B,$C,$D,$E); | ||
| 513 | &BODY_60_79(\$code,62,$E,$T,$A,$B,$C,$D); | ||
| 514 | &BODY_60_79(\$code,63,$D,$E,$T,$A,$B,$C); | ||
| 515 | &BODY_60_79(\$code,64,$C,$D,$E,$T,$A,$B); | ||
| 516 | &BODY_60_79(\$code,65,$B,$C,$D,$E,$T,$A); | ||
| 517 | &BODY_60_79(\$code,66,$A,$B,$C,$D,$E,$T); | ||
| 518 | &BODY_60_79(\$code,67,$T,$A,$B,$C,$D,$E); | ||
| 519 | &BODY_60_79(\$code,68,$E,$T,$A,$B,$C,$D); | ||
| 520 | &BODY_60_79(\$code,69,$D,$E,$T,$A,$B,$C); | ||
| 521 | &BODY_60_79(\$code,70,$C,$D,$E,$T,$A,$B); | ||
| 522 | &BODY_60_79(\$code,71,$B,$C,$D,$E,$T,$A); | ||
| 523 | &BODY_60_79(\$code,72,$A,$B,$C,$D,$E,$T); | ||
| 524 | &BODY_60_79(\$code,73,$T,$A,$B,$C,$D,$E); | ||
| 525 | &BODY_60_79(\$code,74,$E,$T,$A,$B,$C,$D); | ||
| 526 | &BODY_60_79(\$code,75,$D,$E,$T,$A,$B,$C); | ||
| 527 | &BODY_60_79(\$code,76,$C,$D,$E,$T,$A,$B); | ||
| 528 | &BODY_60_79(\$code,77,$B,$C,$D,$E,$T,$A); | ||
| 529 | &BODY_60_79(\$code,78,$A,$B,$C,$D,$E,$T); | ||
| 530 | &BODY_60_79(\$code,79,$T,$A,$B,$C,$D,$E); | ||
| 531 | |||
| 532 | $code.=<<___; | ||
| 533 | { .mmb; add $h0=$h0,$E | ||
| 534 | nop.m 0 | ||
| 535 | br.ctop.dptk.many .Ldtop };; | ||
| 536 | .Ldend: | ||
| 537 | { .mmi; add tmp0=4,ctx | ||
| 538 | mov ar.lc=r3 };; | ||
| 539 | { .mmi; st4 [ctx]=$h0,8 | ||
| 540 | st4 [tmp0]=$h1,8 };; | ||
| 541 | { .mmi; st4 [ctx]=$h2,8 | ||
| 542 | st4 [tmp0]=$h3 };; | ||
| 543 | { .mib; st4 [ctx]=$h4,-16 | ||
| 544 | mov pr=r2,0x1ffff | ||
| 545 | br.ret.sptk.many b0 };; | ||
| 546 | .endp sha1_block_asm_data_order# | ||
| 547 | ___ | ||
| 548 | |||
| 549 | print $code; | ||
diff --git a/src/lib/libcrypto/sha/sha.c b/src/lib/libcrypto/sha/sha.c new file mode 100644 index 0000000000..42126551d1 --- /dev/null +++ b/src/lib/libcrypto/sha/sha.c | |||
| @@ -0,0 +1,124 @@ | |||
| 1 | /* crypto/sha/sha.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <openssl/sha.h> | ||
| 62 | |||
| 63 | #define BUFSIZE 1024*16 | ||
| 64 | |||
| 65 | void do_fp(FILE *f); | ||
| 66 | void pt(unsigned char *md); | ||
| 67 | int read(int, void *, unsigned int); | ||
| 68 | int main(int argc, char **argv) | ||
| 69 | { | ||
| 70 | int i,err=0; | ||
| 71 | FILE *IN; | ||
| 72 | |||
| 73 | if (argc == 1) | ||
| 74 | { | ||
| 75 | do_fp(stdin); | ||
| 76 | } | ||
| 77 | else | ||
| 78 | { | ||
| 79 | for (i=1; i<argc; i++) | ||
| 80 | { | ||
| 81 | IN=fopen(argv[i],"r"); | ||
| 82 | if (IN == NULL) | ||
| 83 | { | ||
| 84 | perror(argv[i]); | ||
| 85 | err++; | ||
| 86 | continue; | ||
| 87 | } | ||
| 88 | printf("SHA(%s)= ",argv[i]); | ||
| 89 | do_fp(IN); | ||
| 90 | fclose(IN); | ||
| 91 | } | ||
| 92 | } | ||
| 93 | exit(err); | ||
| 94 | } | ||
| 95 | |||
| 96 | void do_fp(FILE *f) | ||
| 97 | { | ||
| 98 | SHA_CTX c; | ||
| 99 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 100 | int fd; | ||
| 101 | int i; | ||
| 102 | unsigned char buf[BUFSIZE]; | ||
| 103 | |||
| 104 | fd=fileno(f); | ||
| 105 | SHA_Init(&c); | ||
| 106 | for (;;) | ||
| 107 | { | ||
| 108 | i=read(fd,buf,BUFSIZE); | ||
| 109 | if (i <= 0) break; | ||
| 110 | SHA_Update(&c,buf,(unsigned long)i); | ||
| 111 | } | ||
| 112 | SHA_Final(&(md[0]),&c); | ||
| 113 | pt(md); | ||
| 114 | } | ||
| 115 | |||
| 116 | void pt(unsigned char *md) | ||
| 117 | { | ||
| 118 | int i; | ||
| 119 | |||
| 120 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 121 | printf("%02x",md[i]); | ||
| 122 | printf("\n"); | ||
| 123 | } | ||
| 124 | |||
diff --git a/src/lib/libcrypto/sha/sha.h b/src/lib/libcrypto/sha/sha.h new file mode 100644 index 0000000000..79c07b0fd1 --- /dev/null +++ b/src/lib/libcrypto/sha/sha.h | |||
| @@ -0,0 +1,128 @@ | |||
| 1 | /* crypto/sha/sha.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_SHA_H | ||
| 60 | #define HEADER_SHA_H | ||
| 61 | |||
| 62 | #include <openssl/e_os2.h> | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | extern "C" { | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #if defined(OPENSSL_NO_SHA) || (defined(OPENSSL_NO_SHA0) && defined(OPENSSL_NO_SHA1)) | ||
| 69 | #error SHA is disabled. | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #if defined(OPENSSL_FIPS) | ||
| 73 | #define FIPS_SHA_SIZE_T unsigned long | ||
| 74 | #endif | ||
| 75 | |||
| 76 | /* | ||
| 77 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 78 | * ! SHA_LONG has to be at least 32 bits wide. If it's wider, then ! | ||
| 79 | * ! SHA_LONG_LOG2 has to be defined along. ! | ||
| 80 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 81 | */ | ||
| 82 | |||
| 83 | #if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) | ||
| 84 | #define SHA_LONG unsigned long | ||
| 85 | #elif defined(OPENSSL_SYS_CRAY) || defined(__ILP64__) | ||
| 86 | #define SHA_LONG unsigned long | ||
| 87 | #define SHA_LONG_LOG2 3 | ||
| 88 | #else | ||
| 89 | #define SHA_LONG unsigned int | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #define SHA_LBLOCK 16 | ||
| 93 | #define SHA_CBLOCK (SHA_LBLOCK*4) /* SHA treats input data as a | ||
| 94 | * contiguous array of 32 bit | ||
| 95 | * wide big-endian values. */ | ||
| 96 | #define SHA_LAST_BLOCK (SHA_CBLOCK-8) | ||
| 97 | #define SHA_DIGEST_LENGTH 20 | ||
| 98 | |||
| 99 | typedef struct SHAstate_st | ||
| 100 | { | ||
| 101 | SHA_LONG h0,h1,h2,h3,h4; | ||
| 102 | SHA_LONG Nl,Nh; | ||
| 103 | SHA_LONG data[SHA_LBLOCK]; | ||
| 104 | int num; | ||
| 105 | } SHA_CTX; | ||
| 106 | |||
| 107 | #ifndef OPENSSL_NO_SHA0 | ||
| 108 | #ifdef OPENSSL_FIPS | ||
| 109 | int private_SHA_Init(SHA_CTX *c); | ||
| 110 | #endif | ||
| 111 | int SHA_Init(SHA_CTX *c); | ||
| 112 | int SHA_Update(SHA_CTX *c, const void *data, unsigned long len); | ||
| 113 | int SHA_Final(unsigned char *md, SHA_CTX *c); | ||
| 114 | unsigned char *SHA(const unsigned char *d, unsigned long n,unsigned char *md); | ||
| 115 | void SHA_Transform(SHA_CTX *c, const unsigned char *data); | ||
| 116 | #endif | ||
| 117 | #ifndef OPENSSL_NO_SHA1 | ||
| 118 | int SHA1_Init(SHA_CTX *c); | ||
| 119 | int SHA1_Update(SHA_CTX *c, const void *data, unsigned long len); | ||
| 120 | int SHA1_Final(unsigned char *md, SHA_CTX *c); | ||
| 121 | unsigned char *SHA1(const unsigned char *d, unsigned long n,unsigned char *md); | ||
| 122 | void SHA1_Transform(SHA_CTX *c, const unsigned char *data); | ||
| 123 | #endif | ||
| 124 | #ifdef __cplusplus | ||
| 125 | } | ||
| 126 | #endif | ||
| 127 | |||
| 128 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha1.c b/src/lib/libcrypto/sha/sha1.c new file mode 100644 index 0000000000..d350c88ee4 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1.c | |||
| @@ -0,0 +1,127 @@ | |||
| 1 | /* crypto/sha/sha1.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <stdlib.h> | ||
| 61 | #include <openssl/sha.h> | ||
| 62 | |||
| 63 | #define BUFSIZE 1024*16 | ||
| 64 | |||
| 65 | void do_fp(FILE *f); | ||
| 66 | void pt(unsigned char *md); | ||
| 67 | #ifndef _OSD_POSIX | ||
| 68 | int read(int, void *, unsigned int); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | int main(int argc, char **argv) | ||
| 72 | { | ||
| 73 | int i,err=0; | ||
| 74 | FILE *IN; | ||
| 75 | |||
| 76 | if (argc == 1) | ||
| 77 | { | ||
| 78 | do_fp(stdin); | ||
| 79 | } | ||
| 80 | else | ||
| 81 | { | ||
| 82 | for (i=1; i<argc; i++) | ||
| 83 | { | ||
| 84 | IN=fopen(argv[i],"r"); | ||
| 85 | if (IN == NULL) | ||
| 86 | { | ||
| 87 | perror(argv[i]); | ||
| 88 | err++; | ||
| 89 | continue; | ||
| 90 | } | ||
| 91 | printf("SHA1(%s)= ",argv[i]); | ||
| 92 | do_fp(IN); | ||
| 93 | fclose(IN); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | exit(err); | ||
| 97 | } | ||
| 98 | |||
| 99 | void do_fp(FILE *f) | ||
| 100 | { | ||
| 101 | SHA_CTX c; | ||
| 102 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 103 | int fd; | ||
| 104 | int i; | ||
| 105 | unsigned char buf[BUFSIZE]; | ||
| 106 | |||
| 107 | fd=fileno(f); | ||
| 108 | SHA1_Init(&c); | ||
| 109 | for (;;) | ||
| 110 | { | ||
| 111 | i=read(fd,buf,BUFSIZE); | ||
| 112 | if (i <= 0) break; | ||
| 113 | SHA1_Update(&c,buf,(unsigned long)i); | ||
| 114 | } | ||
| 115 | SHA1_Final(&(md[0]),&c); | ||
| 116 | pt(md); | ||
| 117 | } | ||
| 118 | |||
| 119 | void pt(unsigned char *md) | ||
| 120 | { | ||
| 121 | int i; | ||
| 122 | |||
| 123 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 124 | printf("%02x",md[i]); | ||
| 125 | printf("\n"); | ||
| 126 | } | ||
| 127 | |||
diff --git a/src/lib/libcrypto/sha/sha1_one.c b/src/lib/libcrypto/sha/sha1_one.c new file mode 100644 index 0000000000..f4694b701b --- /dev/null +++ b/src/lib/libcrypto/sha/sha1_one.c | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /* crypto/sha/sha1_one.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <openssl/sha.h> | ||
| 62 | #include <openssl/crypto.h> | ||
| 63 | |||
| 64 | #if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_FIPS) | ||
| 65 | unsigned char *SHA1(const unsigned char *d, unsigned long n, unsigned char *md) | ||
| 66 | { | ||
| 67 | SHA_CTX c; | ||
| 68 | static unsigned char m[SHA_DIGEST_LENGTH]; | ||
| 69 | |||
| 70 | if (md == NULL) md=m; | ||
| 71 | if (!SHA1_Init(&c)) | ||
| 72 | return NULL; | ||
| 73 | SHA1_Update(&c,d,n); | ||
| 74 | SHA1_Final(md,&c); | ||
| 75 | OPENSSL_cleanse(&c,sizeof(c)); | ||
| 76 | return(md); | ||
| 77 | } | ||
| 78 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c new file mode 100644 index 0000000000..1e2009b760 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1dgst.c | |||
| @@ -0,0 +1,81 @@ | |||
| 1 | /* crypto/sha/sha1dgst.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA) | ||
| 60 | |||
| 61 | #undef SHA_0 | ||
| 62 | #define SHA_1 | ||
| 63 | |||
| 64 | #include <openssl/opensslv.h> | ||
| 65 | #include <openssl/opensslconf.h> | ||
| 66 | |||
| 67 | #ifndef OPENSSL_FIPS | ||
| 68 | const char *SHA1_version="SHA1" OPENSSL_VERSION_PTEXT; | ||
| 69 | |||
| 70 | /* The implementation is in ../md32_common.h */ | ||
| 71 | |||
| 72 | #include "sha_locl.h" | ||
| 73 | |||
| 74 | #else /* ndef OPENSSL_FIPS */ | ||
| 75 | |||
| 76 | static void *dummy=&dummy; | ||
| 77 | |||
| 78 | #endif /* ndef OPENSSL_FIPS */ | ||
| 79 | |||
| 80 | #endif | ||
| 81 | |||
diff --git a/src/lib/libcrypto/sha/sha1s.cpp b/src/lib/libcrypto/sha/sha1s.cpp new file mode 100644 index 0000000000..af23d1e0f2 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1s.cpp | |||
| @@ -0,0 +1,82 @@ | |||
| 1 | // | ||
| 2 | // gettsc.inl | ||
| 3 | // | ||
| 4 | // gives access to the Pentium's (secret) cycle counter | ||
| 5 | // | ||
| 6 | // This software was written by Leonard Janke (janke@unixg.ubc.ca) | ||
| 7 | // in 1996-7 and is entered, by him, into the public domain. | ||
| 8 | |||
| 9 | #if defined(__WATCOMC__) | ||
| 10 | void GetTSC(unsigned long&); | ||
| 11 | #pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax]; | ||
| 12 | #elif defined(__GNUC__) | ||
| 13 | inline | ||
| 14 | void GetTSC(unsigned long& tsc) | ||
| 15 | { | ||
| 16 | asm volatile(".byte 15, 49\n\t" | ||
| 17 | : "=eax" (tsc) | ||
| 18 | : | ||
| 19 | : "%edx", "%eax"); | ||
| 20 | } | ||
| 21 | #elif defined(_MSC_VER) | ||
| 22 | inline | ||
| 23 | void GetTSC(unsigned long& tsc) | ||
| 24 | { | ||
| 25 | unsigned long a; | ||
| 26 | __asm _emit 0fh | ||
| 27 | __asm _emit 31h | ||
| 28 | __asm mov a, eax; | ||
| 29 | tsc=a; | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #include <stdio.h> | ||
| 34 | #include <stdlib.h> | ||
| 35 | #include <openssl/sha.h> | ||
| 36 | |||
| 37 | #define sha1_block_x86 sha1_block_asm_data_order | ||
| 38 | extern "C" { | ||
| 39 | void sha1_block_x86(SHA_CTX *ctx, unsigned char *buffer,int num); | ||
| 40 | } | ||
| 41 | |||
| 42 | void main(int argc,char *argv[]) | ||
| 43 | { | ||
| 44 | unsigned char buffer[64*256]; | ||
| 45 | SHA_CTX ctx; | ||
| 46 | unsigned long s1,s2,e1,e2; | ||
| 47 | unsigned char k[16]; | ||
| 48 | unsigned long data[2]; | ||
| 49 | unsigned char iv[8]; | ||
| 50 | int i,num=0,numm; | ||
| 51 | int j=0; | ||
| 52 | |||
| 53 | if (argc >= 2) | ||
| 54 | num=atoi(argv[1]); | ||
| 55 | |||
| 56 | if (num == 0) num=16; | ||
| 57 | if (num > 250) num=16; | ||
| 58 | numm=num+2; | ||
| 59 | #if 0 | ||
| 60 | num*=64; | ||
| 61 | numm*=64; | ||
| 62 | #endif | ||
| 63 | |||
| 64 | for (j=0; j<6; j++) | ||
| 65 | { | ||
| 66 | for (i=0; i<10; i++) /**/ | ||
| 67 | { | ||
| 68 | sha1_block_x86(&ctx,buffer,numm); | ||
| 69 | GetTSC(s1); | ||
| 70 | sha1_block_x86(&ctx,buffer,numm); | ||
| 71 | GetTSC(e1); | ||
| 72 | GetTSC(s2); | ||
| 73 | sha1_block_x86(&ctx,buffer,num); | ||
| 74 | GetTSC(e2); | ||
| 75 | sha1_block_x86(&ctx,buffer,num); | ||
| 76 | } | ||
| 77 | |||
| 78 | printf("sha1 (%d bytes) %d %d (%.2f)\n",num*64, | ||
| 79 | e1-s1,e2-s2,(double)((e1-s1)-(e2-s2))/2); | ||
| 80 | } | ||
| 81 | } | ||
| 82 | |||
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c new file mode 100644 index 0000000000..4f2e4ada2d --- /dev/null +++ b/src/lib/libcrypto/sha/sha1test.c | |||
| @@ -0,0 +1,174 @@ | |||
| 1 | /* crypto/sha/sha1test.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include "../e_os.h" | ||
| 64 | |||
| 65 | #ifdef OPENSSL_NO_SHA | ||
| 66 | int main(int argc, char *argv[]) | ||
| 67 | { | ||
| 68 | printf("No SHA support\n"); | ||
| 69 | return(0); | ||
| 70 | } | ||
| 71 | #else | ||
| 72 | #include <openssl/evp.h> | ||
| 73 | #include <openssl/sha.h> | ||
| 74 | |||
| 75 | #ifdef CHARSET_EBCDIC | ||
| 76 | #include <openssl/ebcdic.h> | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #undef SHA_0 /* FIPS 180 */ | ||
| 80 | #define SHA_1 /* FIPS 180-1 */ | ||
| 81 | |||
| 82 | static char *test[]={ | ||
| 83 | "abc", | ||
| 84 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
| 85 | NULL, | ||
| 86 | }; | ||
| 87 | |||
| 88 | #ifdef SHA_0 | ||
| 89 | static char *ret[]={ | ||
| 90 | "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", | ||
| 91 | "d2516ee1acfa5baf33dfc1c471e438449ef134c8", | ||
| 92 | }; | ||
| 93 | static char *bigret= | ||
| 94 | "3232affa48628a26653b5aaa44541fd90d690603"; | ||
| 95 | #endif | ||
| 96 | #ifdef SHA_1 | ||
| 97 | static char *ret[]={ | ||
| 98 | "a9993e364706816aba3e25717850c26c9cd0d89d", | ||
| 99 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | ||
| 100 | }; | ||
| 101 | static char *bigret= | ||
| 102 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | ||
| 103 | #endif | ||
| 104 | |||
| 105 | static char *pt(unsigned char *md); | ||
| 106 | int main(int argc, char *argv[]) | ||
| 107 | { | ||
| 108 | int i,err=0; | ||
| 109 | unsigned char **P,**R; | ||
| 110 | static unsigned char buf[1000]; | ||
| 111 | char *p,*r; | ||
| 112 | EVP_MD_CTX c; | ||
| 113 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 114 | |||
| 115 | #ifdef CHARSET_EBCDIC | ||
| 116 | ebcdic2ascii(test[0], test[0], strlen(test[0])); | ||
| 117 | ebcdic2ascii(test[1], test[1], strlen(test[1])); | ||
| 118 | #endif | ||
| 119 | |||
| 120 | EVP_MD_CTX_init(&c); | ||
| 121 | P=(unsigned char **)test; | ||
| 122 | R=(unsigned char **)ret; | ||
| 123 | i=1; | ||
| 124 | while (*P != NULL) | ||
| 125 | { | ||
| 126 | EVP_Digest(*P,(unsigned long)strlen((char *)*P),md,NULL,EVP_sha1(), NULL); | ||
| 127 | p=pt(md); | ||
| 128 | if (strcmp(p,(char *)*R) != 0) | ||
| 129 | { | ||
| 130 | printf("error calculating SHA1 on '%s'\n",*P); | ||
| 131 | printf("got %s instead of %s\n",p,*R); | ||
| 132 | err++; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | printf("test %d ok\n",i); | ||
| 136 | i++; | ||
| 137 | R++; | ||
| 138 | P++; | ||
| 139 | } | ||
| 140 | |||
| 141 | memset(buf,'a',1000); | ||
| 142 | #ifdef CHARSET_EBCDIC | ||
| 143 | ebcdic2ascii(buf, buf, 1000); | ||
| 144 | #endif /*CHARSET_EBCDIC*/ | ||
| 145 | EVP_DigestInit_ex(&c,EVP_sha1(), NULL); | ||
| 146 | for (i=0; i<1000; i++) | ||
| 147 | EVP_DigestUpdate(&c,buf,1000); | ||
| 148 | EVP_DigestFinal_ex(&c,md,NULL); | ||
| 149 | p=pt(md); | ||
| 150 | |||
| 151 | r=bigret; | ||
| 152 | if (strcmp(p,r) != 0) | ||
| 153 | { | ||
| 154 | printf("error calculating SHA1 on 'a' * 1000\n"); | ||
| 155 | printf("got %s instead of %s\n",p,r); | ||
| 156 | err++; | ||
| 157 | } | ||
| 158 | else | ||
| 159 | printf("test 3 ok\n"); | ||
| 160 | EXIT(err); | ||
| 161 | EVP_MD_CTX_cleanup(&c); | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | |||
| 165 | static char *pt(unsigned char *md) | ||
| 166 | { | ||
| 167 | int i; | ||
| 168 | static char buf[80]; | ||
| 169 | |||
| 170 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 171 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
| 172 | return(buf); | ||
| 173 | } | ||
| 174 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha_dgst.c b/src/lib/libcrypto/sha/sha_dgst.c new file mode 100644 index 0000000000..5a4b3ab204 --- /dev/null +++ b/src/lib/libcrypto/sha/sha_dgst.c | |||
| @@ -0,0 +1,73 @@ | |||
| 1 | /* crypto/sha/sha1dgst.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #if !defined(OPENSSL_NO_SHA0) && !defined(OPENSSL_NO_SHA) | ||
| 60 | |||
| 61 | #undef SHA_1 | ||
| 62 | #define SHA_0 | ||
| 63 | |||
| 64 | #include <openssl/opensslv.h> | ||
| 65 | |||
| 66 | const char *SHA_version="SHA" OPENSSL_VERSION_PTEXT; | ||
| 67 | |||
| 68 | /* The implementation is in ../md32_common.h */ | ||
| 69 | |||
| 70 | #include "sha_locl.h" | ||
| 71 | |||
| 72 | #endif | ||
| 73 | |||
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h new file mode 100644 index 0000000000..a3623f72da --- /dev/null +++ b/src/lib/libcrypto/sha/sha_locl.h | |||
| @@ -0,0 +1,481 @@ | |||
| 1 | /* crypto/sha/sha_locl.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdlib.h> | ||
| 60 | #include <string.h> | ||
| 61 | |||
| 62 | #include <openssl/opensslconf.h> | ||
| 63 | #include <openssl/sha.h> | ||
| 64 | |||
| 65 | #ifndef SHA_LONG_LOG2 | ||
| 66 | #define SHA_LONG_LOG2 2 /* default to 32 bits */ | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #define DATA_ORDER_IS_BIG_ENDIAN | ||
| 70 | |||
| 71 | #define HASH_LONG SHA_LONG | ||
| 72 | #define HASH_LONG_LOG2 SHA_LONG_LOG2 | ||
| 73 | #define HASH_CTX SHA_CTX | ||
| 74 | #define HASH_CBLOCK SHA_CBLOCK | ||
| 75 | #define HASH_LBLOCK SHA_LBLOCK | ||
| 76 | #define HASH_MAKE_STRING(c,s) do { \ | ||
| 77 | unsigned long ll; \ | ||
| 78 | ll=(c)->h0; HOST_l2c(ll,(s)); \ | ||
| 79 | ll=(c)->h1; HOST_l2c(ll,(s)); \ | ||
| 80 | ll=(c)->h2; HOST_l2c(ll,(s)); \ | ||
| 81 | ll=(c)->h3; HOST_l2c(ll,(s)); \ | ||
| 82 | ll=(c)->h4; HOST_l2c(ll,(s)); \ | ||
| 83 | } while (0) | ||
| 84 | |||
| 85 | #if defined(SHA_0) | ||
| 86 | |||
| 87 | # define HASH_UPDATE SHA_Update | ||
| 88 | # define HASH_TRANSFORM SHA_Transform | ||
| 89 | # define HASH_FINAL SHA_Final | ||
| 90 | # define HASH_INIT SHA_Init | ||
| 91 | # define HASH_BLOCK_HOST_ORDER sha_block_host_order | ||
| 92 | # define HASH_BLOCK_DATA_ORDER sha_block_data_order | ||
| 93 | # define Xupdate(a,ix,ia,ib,ic,id) (ix=(a)=(ia^ib^ic^id)) | ||
| 94 | |||
| 95 | void sha_block_host_order (SHA_CTX *c, const void *p,int num); | ||
| 96 | void sha_block_data_order (SHA_CTX *c, const void *p,int num); | ||
| 97 | |||
| 98 | #elif defined(SHA_1) | ||
| 99 | |||
| 100 | # define HASH_UPDATE SHA1_Update | ||
| 101 | # define HASH_TRANSFORM SHA1_Transform | ||
| 102 | # define HASH_FINAL SHA1_Final | ||
| 103 | # define HASH_INIT SHA1_Init | ||
| 104 | # define HASH_BLOCK_HOST_ORDER sha1_block_host_order | ||
| 105 | # define HASH_BLOCK_DATA_ORDER sha1_block_data_order | ||
| 106 | # if defined(__MWERKS__) && defined(__MC68K__) | ||
| 107 | /* Metrowerks for Motorola fails otherwise:-( <appro@fy.chalmers.se> */ | ||
| 108 | # define Xupdate(a,ix,ia,ib,ic,id) do { (a)=(ia^ib^ic^id); \ | ||
| 109 | ix=(a)=ROTATE((a),1); \ | ||
| 110 | } while (0) | ||
| 111 | # else | ||
| 112 | # define Xupdate(a,ix,ia,ib,ic,id) ( (a)=(ia^ib^ic^id), \ | ||
| 113 | ix=(a)=ROTATE((a),1) \ | ||
| 114 | ) | ||
| 115 | # endif | ||
| 116 | |||
| 117 | # ifdef SHA1_ASM | ||
| 118 | # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) | ||
| 119 | # define sha1_block_host_order sha1_block_asm_host_order | ||
| 120 | # define DONT_IMPLEMENT_BLOCK_HOST_ORDER | ||
| 121 | # define sha1_block_data_order sha1_block_asm_data_order | ||
| 122 | # define DONT_IMPLEMENT_BLOCK_DATA_ORDER | ||
| 123 | # define HASH_BLOCK_DATA_ORDER_ALIGNED sha1_block_asm_data_order | ||
| 124 | # elif defined(__ia64) || defined(__ia64__) || defined(_M_IA64) | ||
| 125 | # define sha1_block_host_order sha1_block_asm_host_order | ||
| 126 | # define DONT_IMPLEMENT_BLOCK_HOST_ORDER | ||
| 127 | # define sha1_block_data_order sha1_block_asm_data_order | ||
| 128 | # define DONT_IMPLEMENT_BLOCK_DATA_ORDER | ||
| 129 | # endif | ||
| 130 | # endif | ||
| 131 | void sha1_block_host_order (SHA_CTX *c, const void *p,int num); | ||
| 132 | void sha1_block_data_order (SHA_CTX *c, const void *p,int num); | ||
| 133 | |||
| 134 | #else | ||
| 135 | # error "Either SHA_0 or SHA_1 must be defined." | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #include "md32_common.h" | ||
| 139 | |||
| 140 | #define INIT_DATA_h0 0x67452301UL | ||
| 141 | #define INIT_DATA_h1 0xefcdab89UL | ||
| 142 | #define INIT_DATA_h2 0x98badcfeUL | ||
| 143 | #define INIT_DATA_h3 0x10325476UL | ||
| 144 | #define INIT_DATA_h4 0xc3d2e1f0UL | ||
| 145 | |||
| 146 | #if defined(SHA_0) && defined(OPENSSL_FIPS) | ||
| 147 | FIPS_NON_FIPS_MD_Init(SHA) | ||
| 148 | #else | ||
| 149 | int HASH_INIT (SHA_CTX *c) | ||
| 150 | #endif | ||
| 151 | { | ||
| 152 | c->h0=INIT_DATA_h0; | ||
| 153 | c->h1=INIT_DATA_h1; | ||
| 154 | c->h2=INIT_DATA_h2; | ||
| 155 | c->h3=INIT_DATA_h3; | ||
| 156 | c->h4=INIT_DATA_h4; | ||
| 157 | c->Nl=0; | ||
| 158 | c->Nh=0; | ||
| 159 | c->num=0; | ||
| 160 | return 1; | ||
| 161 | } | ||
| 162 | |||
| 163 | #define K_00_19 0x5a827999UL | ||
| 164 | #define K_20_39 0x6ed9eba1UL | ||
| 165 | #define K_40_59 0x8f1bbcdcUL | ||
| 166 | #define K_60_79 0xca62c1d6UL | ||
| 167 | |||
| 168 | /* As pointed out by Wei Dai <weidai@eskimo.com>, F() below can be | ||
| 169 | * simplified to the code in F_00_19. Wei attributes these optimisations | ||
| 170 | * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. | ||
| 171 | * #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) | ||
| 172 | * I've just become aware of another tweak to be made, again from Wei Dai, | ||
| 173 | * in F_40_59, (x&a)|(y&a) -> (x|y)&a | ||
| 174 | */ | ||
| 175 | #define F_00_19(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) | ||
| 176 | #define F_20_39(b,c,d) ((b) ^ (c) ^ (d)) | ||
| 177 | #define F_40_59(b,c,d) (((b) & (c)) | (((b)|(c)) & (d))) | ||
| 178 | #define F_60_79(b,c,d) F_20_39(b,c,d) | ||
| 179 | |||
| 180 | #define BODY_00_15(i,a,b,c,d,e,f,xi) \ | ||
| 181 | (f)=xi+(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ | ||
| 182 | (b)=ROTATE((b),30); | ||
| 183 | |||
| 184 | #define BODY_16_19(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \ | ||
| 185 | Xupdate(f,xi,xa,xb,xc,xd); \ | ||
| 186 | (f)+=(e)+K_00_19+ROTATE((a),5)+F_00_19((b),(c),(d)); \ | ||
| 187 | (b)=ROTATE((b),30); | ||
| 188 | |||
| 189 | #define BODY_20_31(i,a,b,c,d,e,f,xi,xa,xb,xc,xd) \ | ||
| 190 | Xupdate(f,xi,xa,xb,xc,xd); \ | ||
| 191 | (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ | ||
| 192 | (b)=ROTATE((b),30); | ||
| 193 | |||
| 194 | #define BODY_32_39(i,a,b,c,d,e,f,xa,xb,xc,xd) \ | ||
| 195 | Xupdate(f,xa,xa,xb,xc,xd); \ | ||
| 196 | (f)+=(e)+K_20_39+ROTATE((a),5)+F_20_39((b),(c),(d)); \ | ||
| 197 | (b)=ROTATE((b),30); | ||
| 198 | |||
| 199 | #define BODY_40_59(i,a,b,c,d,e,f,xa,xb,xc,xd) \ | ||
| 200 | Xupdate(f,xa,xa,xb,xc,xd); \ | ||
| 201 | (f)+=(e)+K_40_59+ROTATE((a),5)+F_40_59((b),(c),(d)); \ | ||
| 202 | (b)=ROTATE((b),30); | ||
| 203 | |||
| 204 | #define BODY_60_79(i,a,b,c,d,e,f,xa,xb,xc,xd) \ | ||
| 205 | Xupdate(f,xa,xa,xb,xc,xd); \ | ||
| 206 | (f)=xa+(e)+K_60_79+ROTATE((a),5)+F_60_79((b),(c),(d)); \ | ||
| 207 | (b)=ROTATE((b),30); | ||
| 208 | |||
| 209 | #ifdef X | ||
| 210 | #undef X | ||
| 211 | #endif | ||
| 212 | #ifndef MD32_XARRAY | ||
| 213 | /* | ||
| 214 | * Originally X was an array. As it's automatic it's natural | ||
| 215 | * to expect RISC compiler to accomodate at least part of it in | ||
| 216 | * the register bank, isn't it? Unfortunately not all compilers | ||
| 217 | * "find" this expectation reasonable:-( On order to make such | ||
| 218 | * compilers generate better code I replace X[] with a bunch of | ||
| 219 | * X0, X1, etc. See the function body below... | ||
| 220 | * <appro@fy.chalmers.se> | ||
| 221 | */ | ||
| 222 | # define X(i) XX##i | ||
| 223 | #else | ||
| 224 | /* | ||
| 225 | * However! Some compilers (most notably HP C) get overwhelmed by | ||
| 226 | * that many local variables so that we have to have the way to | ||
| 227 | * fall down to the original behavior. | ||
| 228 | */ | ||
| 229 | # define X(i) XX[i] | ||
| 230 | #endif | ||
| 231 | |||
| 232 | #ifndef DONT_IMPLEMENT_BLOCK_HOST_ORDER | ||
| 233 | void HASH_BLOCK_HOST_ORDER (SHA_CTX *c, const void *d, int num) | ||
| 234 | { | ||
| 235 | const SHA_LONG *W=d; | ||
| 236 | register unsigned MD32_REG_T A,B,C,D,E,T; | ||
| 237 | #ifndef MD32_XARRAY | ||
| 238 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | ||
| 239 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | ||
| 240 | #else | ||
| 241 | SHA_LONG XX[16]; | ||
| 242 | #endif | ||
| 243 | |||
| 244 | A=c->h0; | ||
| 245 | B=c->h1; | ||
| 246 | C=c->h2; | ||
| 247 | D=c->h3; | ||
| 248 | E=c->h4; | ||
| 249 | |||
| 250 | for (;;) | ||
| 251 | { | ||
| 252 | BODY_00_15( 0,A,B,C,D,E,T,W[ 0]); | ||
| 253 | BODY_00_15( 1,T,A,B,C,D,E,W[ 1]); | ||
| 254 | BODY_00_15( 2,E,T,A,B,C,D,W[ 2]); | ||
| 255 | BODY_00_15( 3,D,E,T,A,B,C,W[ 3]); | ||
| 256 | BODY_00_15( 4,C,D,E,T,A,B,W[ 4]); | ||
| 257 | BODY_00_15( 5,B,C,D,E,T,A,W[ 5]); | ||
| 258 | BODY_00_15( 6,A,B,C,D,E,T,W[ 6]); | ||
| 259 | BODY_00_15( 7,T,A,B,C,D,E,W[ 7]); | ||
| 260 | BODY_00_15( 8,E,T,A,B,C,D,W[ 8]); | ||
| 261 | BODY_00_15( 9,D,E,T,A,B,C,W[ 9]); | ||
| 262 | BODY_00_15(10,C,D,E,T,A,B,W[10]); | ||
| 263 | BODY_00_15(11,B,C,D,E,T,A,W[11]); | ||
| 264 | BODY_00_15(12,A,B,C,D,E,T,W[12]); | ||
| 265 | BODY_00_15(13,T,A,B,C,D,E,W[13]); | ||
| 266 | BODY_00_15(14,E,T,A,B,C,D,W[14]); | ||
| 267 | BODY_00_15(15,D,E,T,A,B,C,W[15]); | ||
| 268 | |||
| 269 | BODY_16_19(16,C,D,E,T,A,B,X( 0),W[ 0],W[ 2],W[ 8],W[13]); | ||
| 270 | BODY_16_19(17,B,C,D,E,T,A,X( 1),W[ 1],W[ 3],W[ 9],W[14]); | ||
| 271 | BODY_16_19(18,A,B,C,D,E,T,X( 2),W[ 2],W[ 4],W[10],W[15]); | ||
| 272 | BODY_16_19(19,T,A,B,C,D,E,X( 3),W[ 3],W[ 5],W[11],X( 0)); | ||
| 273 | |||
| 274 | BODY_20_31(20,E,T,A,B,C,D,X( 4),W[ 4],W[ 6],W[12],X( 1)); | ||
| 275 | BODY_20_31(21,D,E,T,A,B,C,X( 5),W[ 5],W[ 7],W[13],X( 2)); | ||
| 276 | BODY_20_31(22,C,D,E,T,A,B,X( 6),W[ 6],W[ 8],W[14],X( 3)); | ||
| 277 | BODY_20_31(23,B,C,D,E,T,A,X( 7),W[ 7],W[ 9],W[15],X( 4)); | ||
| 278 | BODY_20_31(24,A,B,C,D,E,T,X( 8),W[ 8],W[10],X( 0),X( 5)); | ||
| 279 | BODY_20_31(25,T,A,B,C,D,E,X( 9),W[ 9],W[11],X( 1),X( 6)); | ||
| 280 | BODY_20_31(26,E,T,A,B,C,D,X(10),W[10],W[12],X( 2),X( 7)); | ||
| 281 | BODY_20_31(27,D,E,T,A,B,C,X(11),W[11],W[13],X( 3),X( 8)); | ||
| 282 | BODY_20_31(28,C,D,E,T,A,B,X(12),W[12],W[14],X( 4),X( 9)); | ||
| 283 | BODY_20_31(29,B,C,D,E,T,A,X(13),W[13],W[15],X( 5),X(10)); | ||
| 284 | BODY_20_31(30,A,B,C,D,E,T,X(14),W[14],X( 0),X( 6),X(11)); | ||
| 285 | BODY_20_31(31,T,A,B,C,D,E,X(15),W[15],X( 1),X( 7),X(12)); | ||
| 286 | |||
| 287 | BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13)); | ||
| 288 | BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14)); | ||
| 289 | BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15)); | ||
| 290 | BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0)); | ||
| 291 | BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1)); | ||
| 292 | BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2)); | ||
| 293 | BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3)); | ||
| 294 | BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4)); | ||
| 295 | |||
| 296 | BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5)); | ||
| 297 | BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6)); | ||
| 298 | BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7)); | ||
| 299 | BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8)); | ||
| 300 | BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9)); | ||
| 301 | BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10)); | ||
| 302 | BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11)); | ||
| 303 | BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12)); | ||
| 304 | BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13)); | ||
| 305 | BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14)); | ||
| 306 | BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15)); | ||
| 307 | BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0)); | ||
| 308 | BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1)); | ||
| 309 | BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2)); | ||
| 310 | BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3)); | ||
| 311 | BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4)); | ||
| 312 | BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5)); | ||
| 313 | BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6)); | ||
| 314 | BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7)); | ||
| 315 | BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8)); | ||
| 316 | |||
| 317 | BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9)); | ||
| 318 | BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10)); | ||
| 319 | BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11)); | ||
| 320 | BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12)); | ||
| 321 | BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13)); | ||
| 322 | BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14)); | ||
| 323 | BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15)); | ||
| 324 | BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0)); | ||
| 325 | BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1)); | ||
| 326 | BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2)); | ||
| 327 | BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3)); | ||
| 328 | BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4)); | ||
| 329 | BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5)); | ||
| 330 | BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6)); | ||
| 331 | BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7)); | ||
| 332 | BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8)); | ||
| 333 | BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9)); | ||
| 334 | BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10)); | ||
| 335 | BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11)); | ||
| 336 | BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12)); | ||
| 337 | |||
| 338 | c->h0=(c->h0+E)&0xffffffffL; | ||
| 339 | c->h1=(c->h1+T)&0xffffffffL; | ||
| 340 | c->h2=(c->h2+A)&0xffffffffL; | ||
| 341 | c->h3=(c->h3+B)&0xffffffffL; | ||
| 342 | c->h4=(c->h4+C)&0xffffffffL; | ||
| 343 | |||
| 344 | if (--num <= 0) break; | ||
| 345 | |||
| 346 | A=c->h0; | ||
| 347 | B=c->h1; | ||
| 348 | C=c->h2; | ||
| 349 | D=c->h3; | ||
| 350 | E=c->h4; | ||
| 351 | |||
| 352 | W+=SHA_LBLOCK; | ||
| 353 | } | ||
| 354 | } | ||
| 355 | #endif | ||
| 356 | |||
| 357 | #ifndef DONT_IMPLEMENT_BLOCK_DATA_ORDER | ||
| 358 | void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, int num) | ||
| 359 | { | ||
| 360 | const unsigned char *data=p; | ||
| 361 | register unsigned MD32_REG_T A,B,C,D,E,T,l; | ||
| 362 | #ifndef MD32_XARRAY | ||
| 363 | unsigned MD32_REG_T XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | ||
| 364 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | ||
| 365 | #else | ||
| 366 | SHA_LONG XX[16]; | ||
| 367 | #endif | ||
| 368 | |||
| 369 | A=c->h0; | ||
| 370 | B=c->h1; | ||
| 371 | C=c->h2; | ||
| 372 | D=c->h3; | ||
| 373 | E=c->h4; | ||
| 374 | |||
| 375 | for (;;) | ||
| 376 | { | ||
| 377 | |||
| 378 | HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l; | ||
| 379 | BODY_00_15( 0,A,B,C,D,E,T,X( 0)); HOST_c2l(data,l); X( 2)=l; | ||
| 380 | BODY_00_15( 1,T,A,B,C,D,E,X( 1)); HOST_c2l(data,l); X( 3)=l; | ||
| 381 | BODY_00_15( 2,E,T,A,B,C,D,X( 2)); HOST_c2l(data,l); X( 4)=l; | ||
| 382 | BODY_00_15( 3,D,E,T,A,B,C,X( 3)); HOST_c2l(data,l); X( 5)=l; | ||
| 383 | BODY_00_15( 4,C,D,E,T,A,B,X( 4)); HOST_c2l(data,l); X( 6)=l; | ||
| 384 | BODY_00_15( 5,B,C,D,E,T,A,X( 5)); HOST_c2l(data,l); X( 7)=l; | ||
| 385 | BODY_00_15( 6,A,B,C,D,E,T,X( 6)); HOST_c2l(data,l); X( 8)=l; | ||
| 386 | BODY_00_15( 7,T,A,B,C,D,E,X( 7)); HOST_c2l(data,l); X( 9)=l; | ||
| 387 | BODY_00_15( 8,E,T,A,B,C,D,X( 8)); HOST_c2l(data,l); X(10)=l; | ||
| 388 | BODY_00_15( 9,D,E,T,A,B,C,X( 9)); HOST_c2l(data,l); X(11)=l; | ||
| 389 | BODY_00_15(10,C,D,E,T,A,B,X(10)); HOST_c2l(data,l); X(12)=l; | ||
| 390 | BODY_00_15(11,B,C,D,E,T,A,X(11)); HOST_c2l(data,l); X(13)=l; | ||
| 391 | BODY_00_15(12,A,B,C,D,E,T,X(12)); HOST_c2l(data,l); X(14)=l; | ||
| 392 | BODY_00_15(13,T,A,B,C,D,E,X(13)); HOST_c2l(data,l); X(15)=l; | ||
| 393 | BODY_00_15(14,E,T,A,B,C,D,X(14)); | ||
| 394 | BODY_00_15(15,D,E,T,A,B,C,X(15)); | ||
| 395 | |||
| 396 | BODY_16_19(16,C,D,E,T,A,B,X( 0),X( 0),X( 2),X( 8),X(13)); | ||
| 397 | BODY_16_19(17,B,C,D,E,T,A,X( 1),X( 1),X( 3),X( 9),X(14)); | ||
| 398 | BODY_16_19(18,A,B,C,D,E,T,X( 2),X( 2),X( 4),X(10),X(15)); | ||
| 399 | BODY_16_19(19,T,A,B,C,D,E,X( 3),X( 3),X( 5),X(11),X( 0)); | ||
| 400 | |||
| 401 | BODY_20_31(20,E,T,A,B,C,D,X( 4),X( 4),X( 6),X(12),X( 1)); | ||
| 402 | BODY_20_31(21,D,E,T,A,B,C,X( 5),X( 5),X( 7),X(13),X( 2)); | ||
| 403 | BODY_20_31(22,C,D,E,T,A,B,X( 6),X( 6),X( 8),X(14),X( 3)); | ||
| 404 | BODY_20_31(23,B,C,D,E,T,A,X( 7),X( 7),X( 9),X(15),X( 4)); | ||
| 405 | BODY_20_31(24,A,B,C,D,E,T,X( 8),X( 8),X(10),X( 0),X( 5)); | ||
| 406 | BODY_20_31(25,T,A,B,C,D,E,X( 9),X( 9),X(11),X( 1),X( 6)); | ||
| 407 | BODY_20_31(26,E,T,A,B,C,D,X(10),X(10),X(12),X( 2),X( 7)); | ||
| 408 | BODY_20_31(27,D,E,T,A,B,C,X(11),X(11),X(13),X( 3),X( 8)); | ||
| 409 | BODY_20_31(28,C,D,E,T,A,B,X(12),X(12),X(14),X( 4),X( 9)); | ||
| 410 | BODY_20_31(29,B,C,D,E,T,A,X(13),X(13),X(15),X( 5),X(10)); | ||
| 411 | BODY_20_31(30,A,B,C,D,E,T,X(14),X(14),X( 0),X( 6),X(11)); | ||
| 412 | BODY_20_31(31,T,A,B,C,D,E,X(15),X(15),X( 1),X( 7),X(12)); | ||
| 413 | |||
| 414 | BODY_32_39(32,E,T,A,B,C,D,X( 0),X( 2),X( 8),X(13)); | ||
| 415 | BODY_32_39(33,D,E,T,A,B,C,X( 1),X( 3),X( 9),X(14)); | ||
| 416 | BODY_32_39(34,C,D,E,T,A,B,X( 2),X( 4),X(10),X(15)); | ||
| 417 | BODY_32_39(35,B,C,D,E,T,A,X( 3),X( 5),X(11),X( 0)); | ||
| 418 | BODY_32_39(36,A,B,C,D,E,T,X( 4),X( 6),X(12),X( 1)); | ||
| 419 | BODY_32_39(37,T,A,B,C,D,E,X( 5),X( 7),X(13),X( 2)); | ||
| 420 | BODY_32_39(38,E,T,A,B,C,D,X( 6),X( 8),X(14),X( 3)); | ||
| 421 | BODY_32_39(39,D,E,T,A,B,C,X( 7),X( 9),X(15),X( 4)); | ||
| 422 | |||
| 423 | BODY_40_59(40,C,D,E,T,A,B,X( 8),X(10),X( 0),X( 5)); | ||
| 424 | BODY_40_59(41,B,C,D,E,T,A,X( 9),X(11),X( 1),X( 6)); | ||
| 425 | BODY_40_59(42,A,B,C,D,E,T,X(10),X(12),X( 2),X( 7)); | ||
| 426 | BODY_40_59(43,T,A,B,C,D,E,X(11),X(13),X( 3),X( 8)); | ||
| 427 | BODY_40_59(44,E,T,A,B,C,D,X(12),X(14),X( 4),X( 9)); | ||
| 428 | BODY_40_59(45,D,E,T,A,B,C,X(13),X(15),X( 5),X(10)); | ||
| 429 | BODY_40_59(46,C,D,E,T,A,B,X(14),X( 0),X( 6),X(11)); | ||
| 430 | BODY_40_59(47,B,C,D,E,T,A,X(15),X( 1),X( 7),X(12)); | ||
| 431 | BODY_40_59(48,A,B,C,D,E,T,X( 0),X( 2),X( 8),X(13)); | ||
| 432 | BODY_40_59(49,T,A,B,C,D,E,X( 1),X( 3),X( 9),X(14)); | ||
| 433 | BODY_40_59(50,E,T,A,B,C,D,X( 2),X( 4),X(10),X(15)); | ||
| 434 | BODY_40_59(51,D,E,T,A,B,C,X( 3),X( 5),X(11),X( 0)); | ||
| 435 | BODY_40_59(52,C,D,E,T,A,B,X( 4),X( 6),X(12),X( 1)); | ||
| 436 | BODY_40_59(53,B,C,D,E,T,A,X( 5),X( 7),X(13),X( 2)); | ||
| 437 | BODY_40_59(54,A,B,C,D,E,T,X( 6),X( 8),X(14),X( 3)); | ||
| 438 | BODY_40_59(55,T,A,B,C,D,E,X( 7),X( 9),X(15),X( 4)); | ||
| 439 | BODY_40_59(56,E,T,A,B,C,D,X( 8),X(10),X( 0),X( 5)); | ||
| 440 | BODY_40_59(57,D,E,T,A,B,C,X( 9),X(11),X( 1),X( 6)); | ||
| 441 | BODY_40_59(58,C,D,E,T,A,B,X(10),X(12),X( 2),X( 7)); | ||
| 442 | BODY_40_59(59,B,C,D,E,T,A,X(11),X(13),X( 3),X( 8)); | ||
| 443 | |||
| 444 | BODY_60_79(60,A,B,C,D,E,T,X(12),X(14),X( 4),X( 9)); | ||
| 445 | BODY_60_79(61,T,A,B,C,D,E,X(13),X(15),X( 5),X(10)); | ||
| 446 | BODY_60_79(62,E,T,A,B,C,D,X(14),X( 0),X( 6),X(11)); | ||
| 447 | BODY_60_79(63,D,E,T,A,B,C,X(15),X( 1),X( 7),X(12)); | ||
| 448 | BODY_60_79(64,C,D,E,T,A,B,X( 0),X( 2),X( 8),X(13)); | ||
| 449 | BODY_60_79(65,B,C,D,E,T,A,X( 1),X( 3),X( 9),X(14)); | ||
| 450 | BODY_60_79(66,A,B,C,D,E,T,X( 2),X( 4),X(10),X(15)); | ||
| 451 | BODY_60_79(67,T,A,B,C,D,E,X( 3),X( 5),X(11),X( 0)); | ||
| 452 | BODY_60_79(68,E,T,A,B,C,D,X( 4),X( 6),X(12),X( 1)); | ||
| 453 | BODY_60_79(69,D,E,T,A,B,C,X( 5),X( 7),X(13),X( 2)); | ||
| 454 | BODY_60_79(70,C,D,E,T,A,B,X( 6),X( 8),X(14),X( 3)); | ||
| 455 | BODY_60_79(71,B,C,D,E,T,A,X( 7),X( 9),X(15),X( 4)); | ||
| 456 | BODY_60_79(72,A,B,C,D,E,T,X( 8),X(10),X( 0),X( 5)); | ||
| 457 | BODY_60_79(73,T,A,B,C,D,E,X( 9),X(11),X( 1),X( 6)); | ||
| 458 | BODY_60_79(74,E,T,A,B,C,D,X(10),X(12),X( 2),X( 7)); | ||
| 459 | BODY_60_79(75,D,E,T,A,B,C,X(11),X(13),X( 3),X( 8)); | ||
| 460 | BODY_60_79(76,C,D,E,T,A,B,X(12),X(14),X( 4),X( 9)); | ||
| 461 | BODY_60_79(77,B,C,D,E,T,A,X(13),X(15),X( 5),X(10)); | ||
| 462 | BODY_60_79(78,A,B,C,D,E,T,X(14),X( 0),X( 6),X(11)); | ||
| 463 | BODY_60_79(79,T,A,B,C,D,E,X(15),X( 1),X( 7),X(12)); | ||
| 464 | |||
| 465 | c->h0=(c->h0+E)&0xffffffffL; | ||
| 466 | c->h1=(c->h1+T)&0xffffffffL; | ||
| 467 | c->h2=(c->h2+A)&0xffffffffL; | ||
| 468 | c->h3=(c->h3+B)&0xffffffffL; | ||
| 469 | c->h4=(c->h4+C)&0xffffffffL; | ||
| 470 | |||
| 471 | if (--num <= 0) break; | ||
| 472 | |||
| 473 | A=c->h0; | ||
| 474 | B=c->h1; | ||
| 475 | C=c->h2; | ||
| 476 | D=c->h3; | ||
| 477 | E=c->h4; | ||
| 478 | |||
| 479 | } | ||
| 480 | } | ||
| 481 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c new file mode 100644 index 0000000000..d4f4d344df --- /dev/null +++ b/src/lib/libcrypto/sha/sha_one.c | |||
| @@ -0,0 +1,78 @@ | |||
| 1 | /* crypto/sha/sha_one.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <openssl/sha.h> | ||
| 62 | #include <openssl/crypto.h> | ||
| 63 | |||
| 64 | #ifndef OPENSSL_NO_SHA0 | ||
| 65 | unsigned char *SHA(const unsigned char *d, unsigned long n, unsigned char *md) | ||
| 66 | { | ||
| 67 | SHA_CTX c; | ||
| 68 | static unsigned char m[SHA_DIGEST_LENGTH]; | ||
| 69 | |||
| 70 | if (md == NULL) md=m; | ||
| 71 | if (!SHA_Init(&c)) | ||
| 72 | return NULL; | ||
| 73 | SHA_Update(&c,d,n); | ||
| 74 | SHA_Final(md,&c); | ||
| 75 | OPENSSL_cleanse(&c,sizeof(c)); | ||
| 76 | return(md); | ||
| 77 | } | ||
| 78 | #endif | ||
diff --git a/src/lib/libcrypto/sha/shatest.c b/src/lib/libcrypto/sha/shatest.c new file mode 100644 index 0000000000..ff702aa53e --- /dev/null +++ b/src/lib/libcrypto/sha/shatest.c | |||
| @@ -0,0 +1,174 @@ | |||
| 1 | /* crypto/sha/shatest.c */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdio.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <stdlib.h> | ||
| 62 | |||
| 63 | #include "../e_os.h" | ||
| 64 | |||
| 65 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA0) | ||
| 66 | int main(int argc, char *argv[]) | ||
| 67 | { | ||
| 68 | printf("No SHA0 support\n"); | ||
| 69 | return(0); | ||
| 70 | } | ||
| 71 | #else | ||
| 72 | #include <openssl/evp.h> | ||
| 73 | #include <openssl/sha.h> | ||
| 74 | |||
| 75 | #ifdef CHARSET_EBCDIC | ||
| 76 | #include <openssl/ebcdic.h> | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #define SHA_0 /* FIPS 180 */ | ||
| 80 | #undef SHA_1 /* FIPS 180-1 */ | ||
| 81 | |||
| 82 | static char *test[]={ | ||
| 83 | "abc", | ||
| 84 | "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", | ||
| 85 | NULL, | ||
| 86 | }; | ||
| 87 | |||
| 88 | #ifdef SHA_0 | ||
| 89 | static char *ret[]={ | ||
| 90 | "0164b8a914cd2a5e74c4f7ff082c4d97f1edf880", | ||
| 91 | "d2516ee1acfa5baf33dfc1c471e438449ef134c8", | ||
| 92 | }; | ||
| 93 | static char *bigret= | ||
| 94 | "3232affa48628a26653b5aaa44541fd90d690603"; | ||
| 95 | #endif | ||
| 96 | #ifdef SHA_1 | ||
| 97 | static char *ret[]={ | ||
| 98 | "a9993e364706816aba3e25717850c26c9cd0d89d", | ||
| 99 | "84983e441c3bd26ebaae4aa1f95129e5e54670f1", | ||
| 100 | }; | ||
| 101 | static char *bigret= | ||
| 102 | "34aa973cd4c4daa4f61eeb2bdbad27316534016f"; | ||
| 103 | #endif | ||
| 104 | |||
| 105 | static char *pt(unsigned char *md); | ||
| 106 | int main(int argc, char *argv[]) | ||
| 107 | { | ||
| 108 | int i,err=0; | ||
| 109 | unsigned char **P,**R; | ||
| 110 | static unsigned char buf[1000]; | ||
| 111 | char *p,*r; | ||
| 112 | EVP_MD_CTX c; | ||
| 113 | unsigned char md[SHA_DIGEST_LENGTH]; | ||
| 114 | |||
| 115 | #ifdef CHARSET_EBCDIC | ||
| 116 | ebcdic2ascii(test[0], test[0], strlen(test[0])); | ||
| 117 | ebcdic2ascii(test[1], test[1], strlen(test[1])); | ||
| 118 | #endif | ||
| 119 | |||
| 120 | EVP_MD_CTX_init(&c); | ||
| 121 | P=(unsigned char **)test; | ||
| 122 | R=(unsigned char **)ret; | ||
| 123 | i=1; | ||
| 124 | while (*P != NULL) | ||
| 125 | { | ||
| 126 | EVP_Digest(*P,(unsigned long)strlen((char *)*P),md,NULL,EVP_sha(), NULL); | ||
| 127 | p=pt(md); | ||
| 128 | if (strcmp(p,(char *)*R) != 0) | ||
| 129 | { | ||
| 130 | printf("error calculating SHA on '%s'\n",*P); | ||
| 131 | printf("got %s instead of %s\n",p,*R); | ||
| 132 | err++; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | printf("test %d ok\n",i); | ||
| 136 | i++; | ||
| 137 | R++; | ||
| 138 | P++; | ||
| 139 | } | ||
| 140 | |||
| 141 | memset(buf,'a',1000); | ||
| 142 | #ifdef CHARSET_EBCDIC | ||
| 143 | ebcdic2ascii(buf, buf, 1000); | ||
| 144 | #endif /*CHARSET_EBCDIC*/ | ||
| 145 | EVP_DigestInit_ex(&c,EVP_sha(), NULL); | ||
| 146 | for (i=0; i<1000; i++) | ||
| 147 | EVP_DigestUpdate(&c,buf,1000); | ||
| 148 | EVP_DigestFinal_ex(&c,md,NULL); | ||
| 149 | p=pt(md); | ||
| 150 | |||
| 151 | r=bigret; | ||
| 152 | if (strcmp(p,r) != 0) | ||
| 153 | { | ||
| 154 | printf("error calculating SHA on '%s'\n",p); | ||
| 155 | printf("got %s instead of %s\n",p,r); | ||
| 156 | err++; | ||
| 157 | } | ||
| 158 | else | ||
| 159 | printf("test 3 ok\n"); | ||
| 160 | EVP_MD_CTX_cleanup(&c); | ||
| 161 | EXIT(err); | ||
| 162 | return(0); | ||
| 163 | } | ||
| 164 | |||
| 165 | static char *pt(unsigned char *md) | ||
| 166 | { | ||
| 167 | int i; | ||
| 168 | static char buf[80]; | ||
| 169 | |||
| 170 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 171 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
| 172 | return(buf); | ||
| 173 | } | ||
| 174 | #endif | ||
