diff options
Diffstat (limited to 'src/lib/libcrypto/sha')
| -rw-r--r-- | src/lib/libcrypto/sha/Makefile | 145 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/asm/README | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/asm/sha1-586.pl | 1107 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha.c | 124 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha.h | 14 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1.c | 127 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1dgst.c | 1 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha1test.c | 178 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha256t.c | 147 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha512t.c | 184 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha_dgst.c | 74 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha_locl.h | 6 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/sha_one.c | 78 | ||||
| -rw-r--r-- | src/lib/libcrypto/sha/shatest.c | 178 |
14 files changed, 1286 insertions, 1078 deletions
diff --git a/src/lib/libcrypto/sha/Makefile b/src/lib/libcrypto/sha/Makefile new file mode 100644 index 0000000000..e6eccb05f9 --- /dev/null +++ b/src/lib/libcrypto/sha/Makefile | |||
| @@ -0,0 +1,145 @@ | |||
| 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 | MAKEFILE= Makefile | ||
| 12 | AR= ar r | ||
| 13 | |||
| 14 | SHA1_ASM_OBJ= | ||
| 15 | |||
| 16 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 17 | ASFLAGS= $(INCLUDES) $(ASFLAG) | ||
| 18 | AFLAGS= $(ASFLAGS) | ||
| 19 | |||
| 20 | GENERAL=Makefile | ||
| 21 | TEST=shatest.c sha1test.c sha256t.c sha512t.c | ||
| 22 | APPS= | ||
| 23 | |||
| 24 | LIB=$(TOP)/libcrypto.a | ||
| 25 | LIBSRC=sha_dgst.c sha1dgst.c sha_one.c sha1_one.c sha256.c sha512.c | ||
| 26 | LIBOBJ=sha_dgst.o sha1dgst.o sha_one.o sha1_one.o sha256.o sha512.o $(SHA1_ASM_OBJ) | ||
| 27 | |||
| 28 | SRC= $(LIBSRC) | ||
| 29 | |||
| 30 | EXHEADER= sha.h | ||
| 31 | HEADER= sha_locl.h $(EXHEADER) | ||
| 32 | |||
| 33 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 34 | |||
| 35 | top: | ||
| 36 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 37 | |||
| 38 | all: lib | ||
| 39 | |||
| 40 | lib: $(LIBOBJ) | ||
| 41 | $(AR) $(LIB) $(LIBOBJ) | ||
| 42 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 43 | @touch lib | ||
| 44 | |||
| 45 | sha1-586.s: asm/sha1-586.pl ../perlasm/x86asm.pl | ||
| 46 | $(PERL) asm/sha1-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@ | ||
| 47 | sha256-586.s: asm/sha256-586.pl ../perlasm/x86asm.pl | ||
| 48 | $(PERL) asm/sha256-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@ | ||
| 49 | sha512-586.s: asm/sha512-586.pl ../perlasm/x86asm.pl | ||
| 50 | $(PERL) asm/sha512-586.pl $(PERLASM_SCHEME) $(CFLAGS) $(PROCESSOR) > $@ | ||
| 51 | |||
| 52 | sha1-ia64.s: asm/sha1-ia64.pl | ||
| 53 | (cd asm; $(PERL) sha1-ia64.pl ../$@ $(CFLAGS)) | ||
| 54 | sha256-ia64.s: asm/sha512-ia64.pl | ||
| 55 | (cd asm; $(PERL) sha512-ia64.pl ../$@ $(CFLAGS)) | ||
| 56 | sha512-ia64.s: asm/sha512-ia64.pl | ||
| 57 | (cd asm; $(PERL) sha512-ia64.pl ../$@ $(CFLAGS)) | ||
| 58 | |||
| 59 | sha256-armv4.s: asm/sha256-armv4.pl | ||
| 60 | $(PERL) $< $@ | ||
| 61 | |||
| 62 | # Solaris make has to be explicitly told | ||
| 63 | sha1-x86_64.s: asm/sha1-x86_64.pl; $(PERL) asm/sha1-x86_64.pl $(PERLASM_SCHEME) > $@ | ||
| 64 | sha256-x86_64.s:asm/sha512-x86_64.pl; $(PERL) asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@ | ||
| 65 | sha512-x86_64.s:asm/sha512-x86_64.pl; $(PERL) asm/sha512-x86_64.pl $(PERLASM_SCHEME) $@ | ||
| 66 | sha1-sparcv9.s: asm/sha1-sparcv9.pl; $(PERL) asm/sha1-sparcv9.pl $@ $(CFLAGS) | ||
| 67 | sha256-sparcv9.s:asm/sha512-sparcv9.pl; $(PERL) asm/sha512-sparcv9.pl $@ $(CFLAGS) | ||
| 68 | sha512-sparcv9.s:asm/sha512-sparcv9.pl; $(PERL) asm/sha512-sparcv9.pl $@ $(CFLAGS) | ||
| 69 | |||
| 70 | sha1-ppc.s: asm/sha1-ppc.pl; $(PERL) asm/sha1-ppc.pl $(PERLASM_SCHEME) $@ | ||
| 71 | sha256-ppc.s: asm/sha512-ppc.pl; $(PERL) asm/sha512-ppc.pl $(PERLASM_SCHEME) $@ | ||
| 72 | sha512-ppc.s: asm/sha512-ppc.pl; $(PERL) asm/sha512-ppc.pl $(PERLASM_SCHEME) $@ | ||
| 73 | |||
| 74 | # GNU make "catch all" | ||
| 75 | sha1-%.s: asm/sha1-%.pl; $(PERL) $< $@ | ||
| 76 | sha256-%.s: asm/sha512-%.pl; $(PERL) $< $@ | ||
| 77 | sha512-%.s: asm/sha512-%.pl; $(PERL) $< $@ | ||
| 78 | |||
| 79 | files: | ||
| 80 | $(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO | ||
| 81 | |||
| 82 | links: | ||
| 83 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 84 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 85 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 86 | |||
| 87 | install: | ||
| 88 | @[ -n "$(INSTALLTOP)" ] # should be set by top Makefile... | ||
| 89 | @headerlist="$(EXHEADER)"; for i in $$headerlist ; \ | ||
| 90 | do \ | ||
| 91 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 92 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 93 | done; | ||
| 94 | |||
| 95 | tags: | ||
| 96 | ctags $(SRC) | ||
| 97 | |||
| 98 | tests: | ||
| 99 | |||
| 100 | lint: | ||
| 101 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 102 | |||
| 103 | depend: | ||
| 104 | @[ -n "$(MAKEDEPEND)" ] # should be set by upper Makefile... | ||
| 105 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 106 | |||
| 107 | dclean: | ||
| 108 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 109 | mv -f Makefile.new $(MAKEFILE) | ||
| 110 | |||
| 111 | clean: | ||
| 112 | rm -f *.s *.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 113 | |||
| 114 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 115 | |||
| 116 | sha1_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 117 | sha1_one.o: ../../include/openssl/opensslconf.h | ||
| 118 | sha1_one.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 119 | sha1_one.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 120 | sha1_one.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 121 | sha1_one.o: sha1_one.c | ||
| 122 | sha1dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 123 | sha1dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h | ||
| 124 | sha1dgst.o: ../md32_common.h sha1dgst.c sha_locl.h | ||
| 125 | sha256.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 126 | sha256.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 127 | sha256.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 128 | sha256.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 129 | sha256.o: ../../include/openssl/symhacks.h ../md32_common.h sha256.c | ||
| 130 | sha512.o: ../../e_os.h ../../include/openssl/bio.h | ||
| 131 | sha512.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 132 | sha512.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 133 | sha512.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 134 | sha512.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 135 | sha512.o: ../../include/openssl/safestack.h ../../include/openssl/sha.h | ||
| 136 | sha512.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 137 | sha512.o: ../cryptlib.h sha512.c | ||
| 138 | sha_dgst.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 139 | sha_dgst.o: ../../include/openssl/opensslv.h ../../include/openssl/sha.h | ||
| 140 | sha_dgst.o: ../md32_common.h sha_dgst.c sha_locl.h | ||
| 141 | sha_one.o: ../../include/openssl/crypto.h ../../include/openssl/e_os2.h | ||
| 142 | sha_one.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 143 | sha_one.o: ../../include/openssl/ossl_typ.h ../../include/openssl/safestack.h | ||
| 144 | sha_one.o: ../../include/openssl/sha.h ../../include/openssl/stack.h | ||
| 145 | sha_one.o: ../../include/openssl/symhacks.h 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 index 1084d227fe..a1f876281a 100644 --- a/src/lib/libcrypto/sha/asm/sha1-586.pl +++ b/src/lib/libcrypto/sha/asm/sha1-586.pl | |||
| @@ -12,8 +12,6 @@ | |||
| 12 | # commentary below], and in 2006 the rest was rewritten in order to | 12 | # commentary below], and in 2006 the rest was rewritten in order to |
| 13 | # gain freedom to liberate licensing terms. | 13 | # gain freedom to liberate licensing terms. |
| 14 | 14 | ||
| 15 | # January, September 2004. | ||
| 16 | # | ||
| 17 | # It was noted that Intel IA-32 C compiler generates code which | 15 | # It was noted that Intel IA-32 C compiler generates code which |
| 18 | # performs ~30% *faster* on P4 CPU than original *hand-coded* | 16 | # performs ~30% *faster* on P4 CPU than original *hand-coded* |
| 19 | # SHA1 assembler implementation. To address this problem (and | 17 | # SHA1 assembler implementation. To address this problem (and |
| @@ -33,92 +31,12 @@ | |||
| 33 | # ---------------------------------------------------------------- | 31 | # ---------------------------------------------------------------- |
| 34 | # <appro@fy.chalmers.se> | 32 | # <appro@fy.chalmers.se> |
| 35 | 33 | ||
| 36 | # August 2009. | ||
| 37 | # | ||
| 38 | # George Spelvin has tipped that F_40_59(b,c,d) can be rewritten as | ||
| 39 | # '(c&d) + (b&(c^d))', which allows to accumulate partial results | ||
| 40 | # and lighten "pressure" on scratch registers. This resulted in | ||
| 41 | # >12% performance improvement on contemporary AMD cores (with no | ||
| 42 | # degradation on other CPUs:-). Also, the code was revised to maximize | ||
| 43 | # "distance" between instructions producing input to 'lea' instruction | ||
| 44 | # and the 'lea' instruction itself, which is essential for Intel Atom | ||
| 45 | # core and resulted in ~15% improvement. | ||
| 46 | |||
| 47 | # October 2010. | ||
| 48 | # | ||
| 49 | # Add SSSE3, Supplemental[!] SSE3, implementation. The idea behind it | ||
| 50 | # is to offload message schedule denoted by Wt in NIST specification, | ||
| 51 | # or Xupdate in OpenSSL source, to SIMD unit. The idea is not novel, | ||
| 52 | # and in SSE2 context was first explored by Dean Gaudet in 2004, see | ||
| 53 | # http://arctic.org/~dean/crypto/sha1.html. Since then several things | ||
| 54 | # have changed that made it interesting again: | ||
| 55 | # | ||
| 56 | # a) XMM units became faster and wider; | ||
| 57 | # b) instruction set became more versatile; | ||
| 58 | # c) an important observation was made by Max Locktykhin, which made | ||
| 59 | # it possible to reduce amount of instructions required to perform | ||
| 60 | # the operation in question, for further details see | ||
| 61 | # http://software.intel.com/en-us/articles/improving-the-performance-of-the-secure-hash-algorithm-1/. | ||
| 62 | |||
| 63 | # April 2011. | ||
| 64 | # | ||
| 65 | # Add AVX code path, probably most controversial... The thing is that | ||
| 66 | # switch to AVX alone improves performance by as little as 4% in | ||
| 67 | # comparison to SSSE3 code path. But below result doesn't look like | ||
| 68 | # 4% improvement... Trouble is that Sandy Bridge decodes 'ro[rl]' as | ||
| 69 | # pair of µ-ops, and it's the additional µ-ops, two per round, that | ||
| 70 | # make it run slower than Core2 and Westmere. But 'sh[rl]d' is decoded | ||
| 71 | # as single µ-op by Sandy Bridge and it's replacing 'ro[rl]' with | ||
| 72 | # equivalent 'sh[rl]d' that is responsible for the impressive 5.1 | ||
| 73 | # cycles per processed byte. But 'sh[rl]d' is not something that used | ||
| 74 | # to be fast, nor does it appear to be fast in upcoming Bulldozer | ||
| 75 | # [according to its optimization manual]. Which is why AVX code path | ||
| 76 | # is guarded by *both* AVX and synthetic bit denoting Intel CPUs. | ||
| 77 | # One can argue that it's unfair to AMD, but without 'sh[rl]d' it | ||
| 78 | # makes no sense to keep the AVX code path. If somebody feels that | ||
| 79 | # strongly, it's probably more appropriate to discuss possibility of | ||
| 80 | # using vector rotate XOP on AMD... | ||
| 81 | |||
| 82 | ###################################################################### | ||
| 83 | # Current performance is summarized in following table. Numbers are | ||
| 84 | # CPU clock cycles spent to process single byte (less is better). | ||
| 85 | # | ||
| 86 | # x86 SSSE3 AVX | ||
| 87 | # Pentium 15.7 - | ||
| 88 | # PIII 11.5 - | ||
| 89 | # P4 10.6 - | ||
| 90 | # AMD K8 7.1 - | ||
| 91 | # Core2 7.3 6.1/+20% - | ||
| 92 | # Atom 12.5 9.5(*)/+32% - | ||
| 93 | # Westmere 7.3 5.6/+30% - | ||
| 94 | # Sandy Bridge 8.8 6.2/+40% 5.1(**)/+70% | ||
| 95 | # | ||
| 96 | # (*) Loop is 1056 instructions long and expected result is ~8.25. | ||
| 97 | # It remains mystery [to me] why ILP is limited to 1.7. | ||
| 98 | # | ||
| 99 | # (**) As per above comment, the result is for AVX *plus* sh[rl]d. | ||
| 100 | |||
| 101 | $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; | 34 | $0 =~ m/(.*[\/\\])[^\/\\]+$/; $dir=$1; |
| 102 | push(@INC,"${dir}","${dir}../../perlasm"); | 35 | push(@INC,"${dir}","${dir}../../perlasm"); |
| 103 | require "x86asm.pl"; | 36 | require "x86asm.pl"; |
| 104 | 37 | ||
| 105 | &asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); | 38 | &asm_init($ARGV[0],"sha1-586.pl",$ARGV[$#ARGV] eq "386"); |
| 106 | 39 | ||
| 107 | $xmm=$ymm=0; | ||
| 108 | for (@ARGV) { $xmm=1 if (/-DOPENSSL_IA32_SSE2/); } | ||
| 109 | |||
| 110 | $ymm=1 if ($xmm && | ||
| 111 | `$ENV{CC} -Wa,-v -c -o /dev/null -x assembler /dev/null 2>&1` | ||
| 112 | =~ /GNU assembler version ([2-9]\.[0-9]+)/ && | ||
| 113 | $1>=2.19); # first version supporting AVX | ||
| 114 | |||
| 115 | $ymm=1 if ($xmm && !$ymm && $ARGV[0] eq "win32n" && | ||
| 116 | `nasm -v 2>&1` =~ /NASM version ([2-9]\.[0-9]+)/ && | ||
| 117 | $1>=2.03); # first version supporting AVX | ||
| 118 | |||
| 119 | &external_label("OPENSSL_ia32cap_P") if ($xmm); | ||
| 120 | |||
| 121 | |||
| 122 | $A="eax"; | 40 | $A="eax"; |
| 123 | $B="ebx"; | 41 | $B="ebx"; |
| 124 | $C="ecx"; | 42 | $C="ecx"; |
| @@ -129,10 +47,6 @@ $tmp1="ebp"; | |||
| 129 | 47 | ||
| 130 | @V=($A,$B,$C,$D,$E,$T); | 48 | @V=($A,$B,$C,$D,$E,$T); |
| 131 | 49 | ||
| 132 | $alt=0; # 1 denotes alternative IALU implementation, which performs | ||
| 133 | # 8% *worse* on P4, same on Westmere and Atom, 2% better on | ||
| 134 | # Sandy Bridge... | ||
| 135 | |||
| 136 | sub BODY_00_15 | 50 | sub BODY_00_15 |
| 137 | { | 51 | { |
| 138 | local($n,$a,$b,$c,$d,$e,$f)=@_; | 52 | local($n,$a,$b,$c,$d,$e,$f)=@_; |
| @@ -145,18 +59,16 @@ sub BODY_00_15 | |||
| 145 | &rotl($tmp1,5); # tmp1=ROTATE(a,5) | 59 | &rotl($tmp1,5); # tmp1=ROTATE(a,5) |
| 146 | &xor($f,$d); | 60 | &xor($f,$d); |
| 147 | &add($tmp1,$e); # tmp1+=e; | 61 | &add($tmp1,$e); # tmp1+=e; |
| 148 | &mov($e,&swtmp($n%16)); # e becomes volatile and is loaded | 62 | &and($f,$b); |
| 63 | &mov($e,&swtmp($n%16)); # e becomes volatile and is loaded | ||
| 149 | # with xi, also note that e becomes | 64 | # with xi, also note that e becomes |
| 150 | # f in next round... | 65 | # f in next round... |
| 151 | &and($f,$b); | ||
| 152 | &rotr($b,2); # b=ROTATE(b,30) | ||
| 153 | &xor($f,$d); # f holds F_00_19(b,c,d) | 66 | &xor($f,$d); # f holds F_00_19(b,c,d) |
| 154 | &lea($tmp1,&DWP(0x5a827999,$tmp1,$e)); # tmp1+=K_00_19+xi | 67 | &rotr($b,2); # b=ROTATE(b,30) |
| 68 | &lea($tmp1,&DWP(0x5a827999,$tmp1,$e)); # tmp1+=K_00_19+xi | ||
| 155 | 69 | ||
| 156 | if ($n==15) { &mov($e,&swtmp(($n+1)%16));# pre-fetch f for next round | 70 | if ($n==15) { &add($f,$tmp1); } # f+=tmp1 |
| 157 | &add($f,$tmp1); } # f+=tmp1 | ||
| 158 | else { &add($tmp1,$f); } # f becomes a in next round | 71 | else { &add($tmp1,$f); } # f becomes a in next round |
| 159 | &mov($tmp1,$a) if ($alt && $n==15); | ||
| 160 | } | 72 | } |
| 161 | 73 | ||
| 162 | sub BODY_16_19 | 74 | sub BODY_16_19 |
| @@ -165,41 +77,22 @@ sub BODY_16_19 | |||
| 165 | 77 | ||
| 166 | &comment("16_19 $n"); | 78 | &comment("16_19 $n"); |
| 167 | 79 | ||
| 168 | if ($alt) { | 80 | &mov($f,&swtmp($n%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) |
| 169 | &xor($c,$d); | 81 | &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d) |
| 170 | &xor($f,&swtmp(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) | 82 | &xor($f,&swtmp(($n+2)%16)); |
| 171 | &and($tmp1,$c); # tmp1 to hold F_00_19(b,c,d), b&=c^d | 83 | &xor($tmp1,$d); |
| 172 | &xor($f,&swtmp(($n+8)%16)); | 84 | &xor($f,&swtmp(($n+8)%16)); |
| 173 | &xor($tmp1,$d); # tmp1=F_00_19(b,c,d) | 85 | &and($tmp1,$b); # tmp1 holds F_00_19(b,c,d) |
| 174 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd | 86 | &rotr($b,2); # b=ROTATE(b,30) |
| 175 | &rotl($f,1); # f=ROTATE(f,1) | ||
| 176 | &add($e,$tmp1); # e+=F_00_19(b,c,d) | ||
| 177 | &xor($c,$d); # restore $c | ||
| 178 | &mov($tmp1,$a); # b in next round | ||
| 179 | &rotr($b,$n==16?2:7); # b=ROTATE(b,30) | ||
| 180 | &mov(&swtmp($n%16),$f); # xi=f | ||
| 181 | &rotl($a,5); # ROTATE(a,5) | ||
| 182 | &lea($f,&DWP(0x5a827999,$f,$e));# f+=F_00_19(b,c,d)+e | ||
| 183 | &mov($e,&swtmp(($n+1)%16)); # pre-fetch f for next round | ||
| 184 | &add($f,$a); # f+=ROTATE(a,5) | ||
| 185 | } else { | ||
| 186 | &mov($tmp1,$c); # tmp1 to hold F_00_19(b,c,d) | ||
| 187 | &xor($f,&swtmp(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) | ||
| 188 | &xor($tmp1,$d); | ||
| 189 | &xor($f,&swtmp(($n+8)%16)); | ||
| 190 | &and($tmp1,$b); | ||
| 191 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd | 87 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd |
| 192 | &rotl($f,1); # f=ROTATE(f,1) | 88 | &rotl($f,1); # f=ROTATE(f,1) |
| 193 | &xor($tmp1,$d); # tmp1=F_00_19(b,c,d) | 89 | &xor($tmp1,$d); # tmp1=F_00_19(b,c,d) |
| 194 | &add($e,$tmp1); # e+=F_00_19(b,c,d) | 90 | &mov(&swtmp($n%16),$f); # xi=f |
| 195 | &mov($tmp1,$a); | 91 | &lea($f,&DWP(0x5a827999,$f,$e));# f+=K_00_19+e |
| 196 | &rotr($b,2); # b=ROTATE(b,30) | 92 | &mov($e,$a); # e becomes volatile |
| 197 | &mov(&swtmp($n%16),$f); # xi=f | 93 | &rotl($e,5); # e=ROTATE(a,5) |
| 198 | &rotl($tmp1,5); # ROTATE(a,5) | 94 | &add($f,$tmp1); # f+=F_00_19(b,c,d) |
| 199 | &lea($f,&DWP(0x5a827999,$f,$e));# f+=F_00_19(b,c,d)+e | 95 | &add($f,$e); # f+=ROTATE(a,5) |
| 200 | &mov($e,&swtmp(($n+1)%16)); # pre-fetch f for next round | ||
| 201 | &add($f,$tmp1); # f+=ROTATE(a,5) | ||
| 202 | } | ||
| 203 | } | 96 | } |
| 204 | 97 | ||
| 205 | sub BODY_20_39 | 98 | sub BODY_20_39 |
| @@ -209,41 +102,21 @@ sub BODY_20_39 | |||
| 209 | 102 | ||
| 210 | &comment("20_39 $n"); | 103 | &comment("20_39 $n"); |
| 211 | 104 | ||
| 212 | if ($alt) { | ||
| 213 | &xor($tmp1,$c); # tmp1 to hold F_20_39(b,c,d), b^=c | ||
| 214 | &xor($f,&swtmp(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) | ||
| 215 | &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d) | ||
| 216 | &xor($f,&swtmp(($n+8)%16)); | ||
| 217 | &add($e,$tmp1); # e+=F_20_39(b,c,d) | ||
| 218 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd | ||
| 219 | &rotl($f,1); # f=ROTATE(f,1) | ||
| 220 | &mov($tmp1,$a); # b in next round | ||
| 221 | &rotr($b,7); # b=ROTATE(b,30) | ||
| 222 | &mov(&swtmp($n%16),$f) if($n<77);# xi=f | ||
| 223 | &rotl($a,5); # ROTATE(a,5) | ||
| 224 | &xor($b,$c) if($n==39);# warm up for BODY_40_59 | ||
| 225 | &and($tmp1,$b) if($n==39); | ||
| 226 | &lea($f,&DWP($K,$f,$e)); # f+=e+K_XX_YY | ||
| 227 | &mov($e,&swtmp(($n+1)%16)) if($n<79);# pre-fetch f for next round | ||
| 228 | &add($f,$a); # f+=ROTATE(a,5) | ||
| 229 | &rotr($a,5) if ($n==79); | ||
| 230 | } else { | ||
| 231 | &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d) | 105 | &mov($tmp1,$b); # tmp1 to hold F_20_39(b,c,d) |
| 232 | &xor($f,&swtmp(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) | 106 | &mov($f,&swtmp($n%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) |
| 107 | &rotr($b,2); # b=ROTATE(b,30) | ||
| 108 | &xor($f,&swtmp(($n+2)%16)); | ||
| 233 | &xor($tmp1,$c); | 109 | &xor($tmp1,$c); |
| 234 | &xor($f,&swtmp(($n+8)%16)); | 110 | &xor($f,&swtmp(($n+8)%16)); |
| 235 | &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d) | 111 | &xor($tmp1,$d); # tmp1 holds F_20_39(b,c,d) |
| 236 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd | 112 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd |
| 237 | &rotl($f,1); # f=ROTATE(f,1) | 113 | &rotl($f,1); # f=ROTATE(f,1) |
| 238 | &add($e,$tmp1); # e+=F_20_39(b,c,d) | 114 | &add($tmp1,$e); |
| 239 | &rotr($b,2); # b=ROTATE(b,30) | 115 | &mov(&swtmp($n%16),$f); # xi=f |
| 240 | &mov($tmp1,$a); | 116 | &mov($e,$a); # e becomes volatile |
| 241 | &rotl($tmp1,5); # ROTATE(a,5) | 117 | &rotl($e,5); # e=ROTATE(a,5) |
| 242 | &mov(&swtmp($n%16),$f) if($n<77);# xi=f | 118 | &lea($f,&DWP($K,$f,$tmp1)); # f+=K_20_39+e |
| 243 | &lea($f,&DWP($K,$f,$e)); # f+=e+K_XX_YY | 119 | &add($f,$e); # f+=ROTATE(a,5) |
| 244 | &mov($e,&swtmp(($n+1)%16)) if($n<79);# pre-fetch f for next round | ||
| 245 | &add($f,$tmp1); # f+=ROTATE(a,5) | ||
| 246 | } | ||
| 247 | } | 120 | } |
| 248 | 121 | ||
| 249 | sub BODY_40_59 | 122 | sub BODY_40_59 |
| @@ -252,86 +125,41 @@ sub BODY_40_59 | |||
| 252 | 125 | ||
| 253 | &comment("40_59 $n"); | 126 | &comment("40_59 $n"); |
| 254 | 127 | ||
| 255 | if ($alt) { | 128 | &mov($f,&swtmp($n%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) |
| 256 | &add($e,$tmp1); # e+=b&(c^d) | 129 | &mov($tmp1,&swtmp(($n+2)%16)); |
| 257 | &xor($f,&swtmp(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) | 130 | &xor($f,$tmp1); |
| 258 | &mov($tmp1,$d); | 131 | &mov($tmp1,&swtmp(($n+8)%16)); |
| 259 | &xor($f,&swtmp(($n+8)%16)); | 132 | &xor($f,$tmp1); |
| 260 | &xor($c,$d); # restore $c | 133 | &mov($tmp1,&swtmp(($n+13)%16)); |
| 261 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd | 134 | &xor($f,$tmp1); # f holds xa^xb^xc^xd |
| 262 | &rotl($f,1); # f=ROTATE(f,1) | 135 | &mov($tmp1,$b); # tmp1 to hold F_40_59(b,c,d) |
| 263 | &and($tmp1,$c); | ||
| 264 | &rotr($b,7); # b=ROTATE(b,30) | ||
| 265 | &add($e,$tmp1); # e+=c&d | ||
| 266 | &mov($tmp1,$a); # b in next round | ||
| 267 | &mov(&swtmp($n%16),$f); # xi=f | ||
| 268 | &rotl($a,5); # ROTATE(a,5) | ||
| 269 | &xor($b,$c) if ($n<59); | ||
| 270 | &and($tmp1,$b) if ($n<59);# tmp1 to hold F_40_59(b,c,d) | ||
| 271 | &lea($f,&DWP(0x8f1bbcdc,$f,$e));# f+=K_40_59+e+(b&(c^d)) | ||
| 272 | &mov($e,&swtmp(($n+1)%16)); # pre-fetch f for next round | ||
| 273 | &add($f,$a); # f+=ROTATE(a,5) | ||
| 274 | } else { | ||
| 275 | &mov($tmp1,$c); # tmp1 to hold F_40_59(b,c,d) | ||
| 276 | &xor($f,&swtmp(($n+2)%16)); # f to hold Xupdate(xi,xa,xb,xc,xd) | ||
| 277 | &xor($tmp1,$d); | ||
| 278 | &xor($f,&swtmp(($n+8)%16)); | ||
| 279 | &and($tmp1,$b); | ||
| 280 | &xor($f,&swtmp(($n+13)%16)); # f holds xa^xb^xc^xd | ||
| 281 | &rotl($f,1); # f=ROTATE(f,1) | 136 | &rotl($f,1); # f=ROTATE(f,1) |
| 282 | &add($tmp1,$e); # b&(c^d)+=e | 137 | &or($tmp1,$c); |
| 138 | &mov(&swtmp($n%16),$f); # xi=f | ||
| 139 | &and($tmp1,$d); | ||
| 140 | &lea($f,&DWP(0x8f1bbcdc,$f,$e));# f+=K_40_59+e | ||
| 141 | &mov($e,$b); # e becomes volatile and is used | ||
| 142 | # to calculate F_40_59(b,c,d) | ||
| 283 | &rotr($b,2); # b=ROTATE(b,30) | 143 | &rotr($b,2); # b=ROTATE(b,30) |
| 284 | &mov($e,$a); # e becomes volatile | 144 | &and($e,$c); |
| 285 | &rotl($e,5); # ROTATE(a,5) | 145 | &or($tmp1,$e); # tmp1 holds F_40_59(b,c,d) |
| 286 | &mov(&swtmp($n%16),$f); # xi=f | 146 | &mov($e,$a); |
| 287 | &lea($f,&DWP(0x8f1bbcdc,$f,$tmp1));# f+=K_40_59+e+(b&(c^d)) | 147 | &rotl($e,5); # e=ROTATE(a,5) |
| 288 | &mov($tmp1,$c); | 148 | &add($f,$tmp1); # f+=tmp1; |
| 289 | &add($f,$e); # f+=ROTATE(a,5) | 149 | &add($f,$e); # f+=ROTATE(a,5) |
| 290 | &and($tmp1,$d); | ||
| 291 | &mov($e,&swtmp(($n+1)%16)); # pre-fetch f for next round | ||
| 292 | &add($f,$tmp1); # f+=c&d | ||
| 293 | } | ||
| 294 | } | 150 | } |
| 295 | 151 | ||
| 296 | &function_begin("sha1_block_data_order"); | 152 | &function_begin("sha1_block_data_order"); |
| 297 | if ($xmm) { | ||
| 298 | &static_label("ssse3_shortcut"); | ||
| 299 | &static_label("avx_shortcut") if ($ymm); | ||
| 300 | &static_label("K_XX_XX"); | ||
| 301 | |||
| 302 | &call (&label("pic_point")); # make it PIC! | ||
| 303 | &set_label("pic_point"); | ||
| 304 | &blindpop($tmp1); | ||
| 305 | &picmeup($T,"OPENSSL_ia32cap_P",$tmp1,&label("pic_point")); | ||
| 306 | &lea ($tmp1,&DWP(&label("K_XX_XX")."-".&label("pic_point"),$tmp1)); | ||
| 307 | |||
| 308 | &mov ($A,&DWP(0,$T)); | ||
| 309 | &mov ($D,&DWP(4,$T)); | ||
| 310 | &test ($D,1<<9); # check SSSE3 bit | ||
| 311 | &jz (&label("x86")); | ||
| 312 | &test ($A,1<<24); # check FXSR bit | ||
| 313 | &jz (&label("x86")); | ||
| 314 | if ($ymm) { | ||
| 315 | &and ($D,1<<28); # mask AVX bit | ||
| 316 | &and ($A,1<<30); # mask "Intel CPU" bit | ||
| 317 | &or ($A,$D); | ||
| 318 | &cmp ($A,1<<28|1<<30); | ||
| 319 | &je (&label("avx_shortcut")); | ||
| 320 | } | ||
| 321 | &jmp (&label("ssse3_shortcut")); | ||
| 322 | &set_label("x86",16); | ||
| 323 | } | ||
| 324 | &mov($tmp1,&wparam(0)); # SHA_CTX *c | 153 | &mov($tmp1,&wparam(0)); # SHA_CTX *c |
| 325 | &mov($T,&wparam(1)); # const void *input | 154 | &mov($T,&wparam(1)); # const void *input |
| 326 | &mov($A,&wparam(2)); # size_t num | 155 | &mov($A,&wparam(2)); # size_t num |
| 327 | &stack_push(16+3); # allocate X[16] | 156 | &stack_push(16); # allocate X[16] |
| 328 | &shl($A,6); | 157 | &shl($A,6); |
| 329 | &add($A,$T); | 158 | &add($A,$T); |
| 330 | &mov(&wparam(2),$A); # pointer beyond the end of input | 159 | &mov(&wparam(2),$A); # pointer beyond the end of input |
| 331 | &mov($E,&DWP(16,$tmp1));# pre-load E | 160 | &mov($E,&DWP(16,$tmp1));# pre-load E |
| 332 | &jmp(&label("loop")); | ||
| 333 | 161 | ||
| 334 | &set_label("loop",16); | 162 | &set_label("loop",16); |
| 335 | 163 | ||
| 336 | # copy input chunk to X, but reversing byte order! | 164 | # copy input chunk to X, but reversing byte order! |
| 337 | for ($i=0; $i<16; $i+=4) | 165 | for ($i=0; $i<16; $i+=4) |
| @@ -385,845 +213,8 @@ if ($xmm) { | |||
| 385 | &mov(&DWP(16,$tmp1),$C); | 213 | &mov(&DWP(16,$tmp1),$C); |
| 386 | &jb(&label("loop")); | 214 | &jb(&label("loop")); |
| 387 | 215 | ||
| 388 | &stack_pop(16+3); | 216 | &stack_pop(16); |
| 389 | &function_end("sha1_block_data_order"); | 217 | &function_end("sha1_block_data_order"); |
| 390 | |||
| 391 | if ($xmm) { | ||
| 392 | ###################################################################### | ||
| 393 | # The SSSE3 implementation. | ||
| 394 | # | ||
| 395 | # %xmm[0-7] are used as ring @X[] buffer containing quadruples of last | ||
| 396 | # 32 elements of the message schedule or Xupdate outputs. First 4 | ||
| 397 | # quadruples are simply byte-swapped input, next 4 are calculated | ||
| 398 | # according to method originally suggested by Dean Gaudet (modulo | ||
| 399 | # being implemented in SSSE3). Once 8 quadruples or 32 elements are | ||
| 400 | # collected, it switches to routine proposed by Max Locktyukhin. | ||
| 401 | # | ||
| 402 | # Calculations inevitably require temporary reqisters, and there are | ||
| 403 | # no %xmm registers left to spare. For this reason part of the ring | ||
| 404 | # buffer, X[2..4] to be specific, is offloaded to 3 quadriples ring | ||
| 405 | # buffer on the stack. Keep in mind that X[2] is alias X[-6], X[3] - | ||
| 406 | # X[-5], and X[4] - X[-4]... | ||
| 407 | # | ||
| 408 | # Another notable optimization is aggressive stack frame compression | ||
| 409 | # aiming to minimize amount of 9-byte instructions... | ||
| 410 | # | ||
| 411 | # Yet another notable optimization is "jumping" $B variable. It means | ||
| 412 | # that there is no register permanently allocated for $B value. This | ||
| 413 | # allowed to eliminate one instruction from body_20_39... | ||
| 414 | # | ||
| 415 | my $Xi=4; # 4xSIMD Xupdate round, start pre-seeded | ||
| 416 | my @X=map("xmm$_",(4..7,0..3)); # pre-seeded for $Xi=4 | ||
| 417 | my @V=($A,$B,$C,$D,$E); | ||
| 418 | my $j=0; # hash round | ||
| 419 | my @T=($T,$tmp1); | ||
| 420 | my $inp; | ||
| 421 | |||
| 422 | my $_rol=sub { &rol(@_) }; | ||
| 423 | my $_ror=sub { &ror(@_) }; | ||
| 424 | |||
| 425 | &function_begin("_sha1_block_data_order_ssse3"); | ||
| 426 | &call (&label("pic_point")); # make it PIC! | ||
| 427 | &set_label("pic_point"); | ||
| 428 | &blindpop($tmp1); | ||
| 429 | &lea ($tmp1,&DWP(&label("K_XX_XX")."-".&label("pic_point"),$tmp1)); | ||
| 430 | &set_label("ssse3_shortcut"); | ||
| 431 | |||
| 432 | &movdqa (@X[3],&QWP(0,$tmp1)); # K_00_19 | ||
| 433 | &movdqa (@X[4],&QWP(16,$tmp1)); # K_20_39 | ||
| 434 | &movdqa (@X[5],&QWP(32,$tmp1)); # K_40_59 | ||
| 435 | &movdqa (@X[6],&QWP(48,$tmp1)); # K_60_79 | ||
| 436 | &movdqa (@X[2],&QWP(64,$tmp1)); # pbswap mask | ||
| 437 | |||
| 438 | &mov ($E,&wparam(0)); # load argument block | ||
| 439 | &mov ($inp=@T[1],&wparam(1)); | ||
| 440 | &mov ($D,&wparam(2)); | ||
| 441 | &mov (@T[0],"esp"); | ||
| 442 | |||
| 443 | # stack frame layout | ||
| 444 | # | ||
| 445 | # +0 X[0]+K X[1]+K X[2]+K X[3]+K # XMM->IALU xfer area | ||
| 446 | # X[4]+K X[5]+K X[6]+K X[7]+K | ||
| 447 | # X[8]+K X[9]+K X[10]+K X[11]+K | ||
| 448 | # X[12]+K X[13]+K X[14]+K X[15]+K | ||
| 449 | # | ||
| 450 | # +64 X[0] X[1] X[2] X[3] # XMM->XMM backtrace area | ||
| 451 | # X[4] X[5] X[6] X[7] | ||
| 452 | # X[8] X[9] X[10] X[11] # even borrowed for K_00_19 | ||
| 453 | # | ||
| 454 | # +112 K_20_39 K_20_39 K_20_39 K_20_39 # constants | ||
| 455 | # K_40_59 K_40_59 K_40_59 K_40_59 | ||
| 456 | # K_60_79 K_60_79 K_60_79 K_60_79 | ||
| 457 | # K_00_19 K_00_19 K_00_19 K_00_19 | ||
| 458 | # pbswap mask | ||
| 459 | # | ||
| 460 | # +192 ctx # argument block | ||
| 461 | # +196 inp | ||
| 462 | # +200 end | ||
| 463 | # +204 esp | ||
| 464 | &sub ("esp",208); | ||
| 465 | &and ("esp",-64); | ||
| 466 | |||
| 467 | &movdqa (&QWP(112+0,"esp"),@X[4]); # copy constants | ||
| 468 | &movdqa (&QWP(112+16,"esp"),@X[5]); | ||
| 469 | &movdqa (&QWP(112+32,"esp"),@X[6]); | ||
| 470 | &shl ($D,6); # len*64 | ||
| 471 | &movdqa (&QWP(112+48,"esp"),@X[3]); | ||
| 472 | &add ($D,$inp); # end of input | ||
| 473 | &movdqa (&QWP(112+64,"esp"),@X[2]); | ||
| 474 | &add ($inp,64); | ||
| 475 | &mov (&DWP(192+0,"esp"),$E); # save argument block | ||
| 476 | &mov (&DWP(192+4,"esp"),$inp); | ||
| 477 | &mov (&DWP(192+8,"esp"),$D); | ||
| 478 | &mov (&DWP(192+12,"esp"),@T[0]); # save original %esp | ||
| 479 | |||
| 480 | &mov ($A,&DWP(0,$E)); # load context | ||
| 481 | &mov ($B,&DWP(4,$E)); | ||
| 482 | &mov ($C,&DWP(8,$E)); | ||
| 483 | &mov ($D,&DWP(12,$E)); | ||
| 484 | &mov ($E,&DWP(16,$E)); | ||
| 485 | &mov (@T[0],$B); # magic seed | ||
| 486 | |||
| 487 | &movdqu (@X[-4&7],&QWP(-64,$inp)); # load input to %xmm[0-3] | ||
| 488 | &movdqu (@X[-3&7],&QWP(-48,$inp)); | ||
| 489 | &movdqu (@X[-2&7],&QWP(-32,$inp)); | ||
| 490 | &movdqu (@X[-1&7],&QWP(-16,$inp)); | ||
| 491 | &pshufb (@X[-4&7],@X[2]); # byte swap | ||
| 492 | &pshufb (@X[-3&7],@X[2]); | ||
| 493 | &pshufb (@X[-2&7],@X[2]); | ||
| 494 | &movdqa (&QWP(112-16,"esp"),@X[3]); # borrow last backtrace slot | ||
| 495 | &pshufb (@X[-1&7],@X[2]); | ||
| 496 | &paddd (@X[-4&7],@X[3]); # add K_00_19 | ||
| 497 | &paddd (@X[-3&7],@X[3]); | ||
| 498 | &paddd (@X[-2&7],@X[3]); | ||
| 499 | &movdqa (&QWP(0,"esp"),@X[-4&7]); # X[]+K xfer to IALU | ||
| 500 | &psubd (@X[-4&7],@X[3]); # restore X[] | ||
| 501 | &movdqa (&QWP(0+16,"esp"),@X[-3&7]); | ||
| 502 | &psubd (@X[-3&7],@X[3]); | ||
| 503 | &movdqa (&QWP(0+32,"esp"),@X[-2&7]); | ||
| 504 | &psubd (@X[-2&7],@X[3]); | ||
| 505 | &movdqa (@X[0],@X[-3&7]); | ||
| 506 | &jmp (&label("loop")); | ||
| 507 | |||
| 508 | ###################################################################### | ||
| 509 | # SSE instruction sequence is first broken to groups of indepentent | ||
| 510 | # instructions, independent in respect to their inputs and shifter | ||
| 511 | # (not all architectures have more than one). Then IALU instructions | ||
| 512 | # are "knitted in" between the SSE groups. Distance is maintained for | ||
| 513 | # SSE latency of 2 in hope that it fits better upcoming AMD Bulldozer | ||
| 514 | # [which allegedly also implements SSSE3]... | ||
| 515 | # | ||
| 516 | # Temporary registers usage. X[2] is volatile at the entry and at the | ||
| 517 | # end is restored from backtrace ring buffer. X[3] is expected to | ||
| 518 | # contain current K_XX_XX constant and is used to caclulate X[-1]+K | ||
| 519 | # from previous round, it becomes volatile the moment the value is | ||
| 520 | # saved to stack for transfer to IALU. X[4] becomes volatile whenever | ||
| 521 | # X[-4] is accumulated and offloaded to backtrace ring buffer, at the | ||
| 522 | # end it is loaded with next K_XX_XX [which becomes X[3] in next | ||
| 523 | # round]... | ||
| 524 | # | ||
| 525 | sub Xupdate_ssse3_16_31() # recall that $Xi starts wtih 4 | ||
| 526 | { use integer; | ||
| 527 | my $body = shift; | ||
| 528 | my @insns = (&$body,&$body,&$body,&$body); # 40 instructions | ||
| 529 | my ($a,$b,$c,$d,$e); | ||
| 530 | |||
| 531 | eval(shift(@insns)); | ||
| 532 | eval(shift(@insns)); | ||
| 533 | &palignr(@X[0],@X[-4&7],8); # compose "X[-14]" in "X[0]" | ||
| 534 | &movdqa (@X[2],@X[-1&7]); | ||
| 535 | eval(shift(@insns)); | ||
| 536 | eval(shift(@insns)); | ||
| 537 | |||
| 538 | &paddd (@X[3],@X[-1&7]); | ||
| 539 | &movdqa (&QWP(64+16*(($Xi-4)%3),"esp"),@X[-4&7]);# save X[] to backtrace buffer | ||
| 540 | eval(shift(@insns)); | ||
| 541 | eval(shift(@insns)); | ||
| 542 | &psrldq (@X[2],4); # "X[-3]", 3 dwords | ||
| 543 | eval(shift(@insns)); | ||
| 544 | eval(shift(@insns)); | ||
| 545 | &pxor (@X[0],@X[-4&7]); # "X[0]"^="X[-16]" | ||
| 546 | eval(shift(@insns)); | ||
| 547 | eval(shift(@insns)); | ||
| 548 | |||
| 549 | &pxor (@X[2],@X[-2&7]); # "X[-3]"^"X[-8]" | ||
| 550 | eval(shift(@insns)); | ||
| 551 | eval(shift(@insns)); | ||
| 552 | eval(shift(@insns)); | ||
| 553 | eval(shift(@insns)); | ||
| 554 | |||
| 555 | &pxor (@X[0],@X[2]); # "X[0]"^="X[-3]"^"X[-8]" | ||
| 556 | eval(shift(@insns)); | ||
| 557 | eval(shift(@insns)); | ||
| 558 | &movdqa (&QWP(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU | ||
| 559 | eval(shift(@insns)); | ||
| 560 | eval(shift(@insns)); | ||
| 561 | |||
| 562 | &movdqa (@X[4],@X[0]); | ||
| 563 | &movdqa (@X[2],@X[0]); | ||
| 564 | eval(shift(@insns)); | ||
| 565 | eval(shift(@insns)); | ||
| 566 | eval(shift(@insns)); | ||
| 567 | eval(shift(@insns)); | ||
| 568 | |||
| 569 | &pslldq (@X[4],12); # "X[0]"<<96, extract one dword | ||
| 570 | &paddd (@X[0],@X[0]); | ||
| 571 | eval(shift(@insns)); | ||
| 572 | eval(shift(@insns)); | ||
| 573 | eval(shift(@insns)); | ||
| 574 | eval(shift(@insns)); | ||
| 575 | |||
| 576 | &psrld (@X[2],31); | ||
| 577 | eval(shift(@insns)); | ||
| 578 | eval(shift(@insns)); | ||
| 579 | &movdqa (@X[3],@X[4]); | ||
| 580 | eval(shift(@insns)); | ||
| 581 | eval(shift(@insns)); | ||
| 582 | |||
| 583 | &psrld (@X[4],30); | ||
| 584 | &por (@X[0],@X[2]); # "X[0]"<<<=1 | ||
| 585 | eval(shift(@insns)); | ||
| 586 | eval(shift(@insns)); | ||
| 587 | &movdqa (@X[2],&QWP(64+16*(($Xi-6)%3),"esp")) if ($Xi>5); # restore X[] from backtrace buffer | ||
| 588 | eval(shift(@insns)); | ||
| 589 | eval(shift(@insns)); | ||
| 590 | |||
| 591 | &pslld (@X[3],2); | ||
| 592 | &pxor (@X[0],@X[4]); | ||
| 593 | eval(shift(@insns)); | ||
| 594 | eval(shift(@insns)); | ||
| 595 | &movdqa (@X[4],&QWP(112-16+16*(($Xi)/5),"esp")); # K_XX_XX | ||
| 596 | eval(shift(@insns)); | ||
| 597 | eval(shift(@insns)); | ||
| 598 | |||
| 599 | &pxor (@X[0],@X[3]); # "X[0]"^=("X[0]"<<96)<<<2 | ||
| 600 | &movdqa (@X[1],@X[-2&7]) if ($Xi<7); | ||
| 601 | eval(shift(@insns)); | ||
| 602 | eval(shift(@insns)); | ||
| 603 | |||
| 604 | foreach (@insns) { eval; } # remaining instructions [if any] | ||
| 605 | |||
| 606 | $Xi++; push(@X,shift(@X)); # "rotate" X[] | ||
| 607 | } | ||
| 608 | |||
| 609 | sub Xupdate_ssse3_32_79() | ||
| 610 | { use integer; | ||
| 611 | my $body = shift; | ||
| 612 | my @insns = (&$body,&$body,&$body,&$body); # 32 to 48 instructions | ||
| 613 | my ($a,$b,$c,$d,$e); | ||
| 614 | |||
| 615 | &movdqa (@X[2],@X[-1&7]) if ($Xi==8); | ||
| 616 | eval(shift(@insns)); # body_20_39 | ||
| 617 | &pxor (@X[0],@X[-4&7]); # "X[0]"="X[-32]"^"X[-16]" | ||
| 618 | &palignr(@X[2],@X[-2&7],8); # compose "X[-6]" | ||
| 619 | eval(shift(@insns)); | ||
| 620 | eval(shift(@insns)); | ||
| 621 | eval(shift(@insns)); # rol | ||
| 622 | |||
| 623 | &pxor (@X[0],@X[-7&7]); # "X[0]"^="X[-28]" | ||
| 624 | &movdqa (&QWP(64+16*(($Xi-4)%3),"esp"),@X[-4&7]); # save X[] to backtrace buffer | ||
| 625 | eval(shift(@insns)); | ||
| 626 | eval(shift(@insns)); | ||
| 627 | if ($Xi%5) { | ||
| 628 | &movdqa (@X[4],@X[3]); # "perpetuate" K_XX_XX... | ||
| 629 | } else { # ... or load next one | ||
| 630 | &movdqa (@X[4],&QWP(112-16+16*($Xi/5),"esp")); | ||
| 631 | } | ||
| 632 | &paddd (@X[3],@X[-1&7]); | ||
| 633 | eval(shift(@insns)); # ror | ||
| 634 | eval(shift(@insns)); | ||
| 635 | |||
| 636 | &pxor (@X[0],@X[2]); # "X[0]"^="X[-6]" | ||
| 637 | eval(shift(@insns)); # body_20_39 | ||
| 638 | eval(shift(@insns)); | ||
| 639 | eval(shift(@insns)); | ||
| 640 | eval(shift(@insns)); # rol | ||
| 641 | |||
| 642 | &movdqa (@X[2],@X[0]); | ||
| 643 | &movdqa (&QWP(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU | ||
| 644 | eval(shift(@insns)); | ||
| 645 | eval(shift(@insns)); | ||
| 646 | eval(shift(@insns)); # ror | ||
| 647 | eval(shift(@insns)); | ||
| 648 | |||
| 649 | &pslld (@X[0],2); | ||
| 650 | eval(shift(@insns)); # body_20_39 | ||
| 651 | eval(shift(@insns)); | ||
| 652 | &psrld (@X[2],30); | ||
| 653 | eval(shift(@insns)); | ||
| 654 | eval(shift(@insns)); # rol | ||
| 655 | eval(shift(@insns)); | ||
| 656 | eval(shift(@insns)); | ||
| 657 | eval(shift(@insns)); # ror | ||
| 658 | eval(shift(@insns)); | ||
| 659 | |||
| 660 | &por (@X[0],@X[2]); # "X[0]"<<<=2 | ||
| 661 | eval(shift(@insns)); # body_20_39 | ||
| 662 | eval(shift(@insns)); | ||
| 663 | &movdqa (@X[2],&QWP(64+16*(($Xi-6)%3),"esp")) if($Xi<19); # restore X[] from backtrace buffer | ||
| 664 | eval(shift(@insns)); | ||
| 665 | eval(shift(@insns)); # rol | ||
| 666 | eval(shift(@insns)); | ||
| 667 | eval(shift(@insns)); | ||
| 668 | eval(shift(@insns)); # ror | ||
| 669 | &movdqa (@X[3],@X[0]) if ($Xi<19); | ||
| 670 | eval(shift(@insns)); | ||
| 671 | |||
| 672 | foreach (@insns) { eval; } # remaining instructions | ||
| 673 | |||
| 674 | $Xi++; push(@X,shift(@X)); # "rotate" X[] | ||
| 675 | } | ||
| 676 | |||
| 677 | sub Xuplast_ssse3_80() | ||
| 678 | { use integer; | ||
| 679 | my $body = shift; | ||
| 680 | my @insns = (&$body,&$body,&$body,&$body); # 32 instructions | ||
| 681 | my ($a,$b,$c,$d,$e); | ||
| 682 | |||
| 683 | eval(shift(@insns)); | ||
| 684 | &paddd (@X[3],@X[-1&7]); | ||
| 685 | eval(shift(@insns)); | ||
| 686 | eval(shift(@insns)); | ||
| 687 | eval(shift(@insns)); | ||
| 688 | eval(shift(@insns)); | ||
| 689 | |||
| 690 | &movdqa (&QWP(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer IALU | ||
| 691 | |||
| 692 | foreach (@insns) { eval; } # remaining instructions | ||
| 693 | |||
| 694 | &mov ($inp=@T[1],&DWP(192+4,"esp")); | ||
| 695 | &cmp ($inp,&DWP(192+8,"esp")); | ||
| 696 | &je (&label("done")); | ||
| 697 | |||
| 698 | &movdqa (@X[3],&QWP(112+48,"esp")); # K_00_19 | ||
| 699 | &movdqa (@X[2],&QWP(112+64,"esp")); # pbswap mask | ||
| 700 | &movdqu (@X[-4&7],&QWP(0,$inp)); # load input | ||
| 701 | &movdqu (@X[-3&7],&QWP(16,$inp)); | ||
| 702 | &movdqu (@X[-2&7],&QWP(32,$inp)); | ||
| 703 | &movdqu (@X[-1&7],&QWP(48,$inp)); | ||
| 704 | &add ($inp,64); | ||
| 705 | &pshufb (@X[-4&7],@X[2]); # byte swap | ||
| 706 | &mov (&DWP(192+4,"esp"),$inp); | ||
| 707 | &movdqa (&QWP(112-16,"esp"),@X[3]); # borrow last backtrace slot | ||
| 708 | |||
| 709 | $Xi=0; | ||
| 710 | } | ||
| 711 | |||
| 712 | sub Xloop_ssse3() | ||
| 713 | { use integer; | ||
| 714 | my $body = shift; | ||
| 715 | my @insns = (&$body,&$body,&$body,&$body); # 32 instructions | ||
| 716 | my ($a,$b,$c,$d,$e); | ||
| 717 | |||
| 718 | eval(shift(@insns)); | ||
| 719 | eval(shift(@insns)); | ||
| 720 | &pshufb (@X[($Xi-3)&7],@X[2]); | ||
| 721 | eval(shift(@insns)); | ||
| 722 | eval(shift(@insns)); | ||
| 723 | &paddd (@X[($Xi-4)&7],@X[3]); | ||
| 724 | eval(shift(@insns)); | ||
| 725 | eval(shift(@insns)); | ||
| 726 | eval(shift(@insns)); | ||
| 727 | eval(shift(@insns)); | ||
| 728 | &movdqa (&QWP(0+16*$Xi,"esp"),@X[($Xi-4)&7]); # X[]+K xfer to IALU | ||
| 729 | eval(shift(@insns)); | ||
| 730 | eval(shift(@insns)); | ||
| 731 | &psubd (@X[($Xi-4)&7],@X[3]); | ||
| 732 | |||
| 733 | foreach (@insns) { eval; } | ||
| 734 | $Xi++; | ||
| 735 | } | ||
| 736 | |||
| 737 | sub Xtail_ssse3() | ||
| 738 | { use integer; | ||
| 739 | my $body = shift; | ||
| 740 | my @insns = (&$body,&$body,&$body,&$body); # 32 instructions | ||
| 741 | my ($a,$b,$c,$d,$e); | ||
| 742 | |||
| 743 | foreach (@insns) { eval; } | ||
| 744 | } | ||
| 745 | |||
| 746 | sub body_00_19 () { | ||
| 747 | ( | ||
| 748 | '($a,$b,$c,$d,$e)=@V;'. | ||
| 749 | '&add ($e,&DWP(4*($j&15),"esp"));', # X[]+K xfer | ||
| 750 | '&xor ($c,$d);', | ||
| 751 | '&mov (@T[1],$a);', # $b in next round | ||
| 752 | '&$_rol ($a,5);', | ||
| 753 | '&and (@T[0],$c);', # ($b&($c^$d)) | ||
| 754 | '&xor ($c,$d);', # restore $c | ||
| 755 | '&xor (@T[0],$d);', | ||
| 756 | '&add ($e,$a);', | ||
| 757 | '&$_ror ($b,$j?7:2);', # $b>>>2 | ||
| 758 | '&add ($e,@T[0]);' .'$j++; unshift(@V,pop(@V)); unshift(@T,pop(@T));' | ||
| 759 | ); | ||
| 760 | } | ||
| 761 | |||
| 762 | sub body_20_39 () { | ||
| 763 | ( | ||
| 764 | '($a,$b,$c,$d,$e)=@V;'. | ||
| 765 | '&add ($e,&DWP(4*($j++&15),"esp"));', # X[]+K xfer | ||
| 766 | '&xor (@T[0],$d);', # ($b^$d) | ||
| 767 | '&mov (@T[1],$a);', # $b in next round | ||
| 768 | '&$_rol ($a,5);', | ||
| 769 | '&xor (@T[0],$c);', # ($b^$d^$c) | ||
| 770 | '&add ($e,$a);', | ||
| 771 | '&$_ror ($b,7);', # $b>>>2 | ||
| 772 | '&add ($e,@T[0]);' .'unshift(@V,pop(@V)); unshift(@T,pop(@T));' | ||
| 773 | ); | ||
| 774 | } | ||
| 775 | |||
| 776 | sub body_40_59 () { | ||
| 777 | ( | ||
| 778 | '($a,$b,$c,$d,$e)=@V;'. | ||
| 779 | '&mov (@T[1],$c);', | ||
| 780 | '&xor ($c,$d);', | ||
| 781 | '&add ($e,&DWP(4*($j++&15),"esp"));', # X[]+K xfer | ||
| 782 | '&and (@T[1],$d);', | ||
| 783 | '&and (@T[0],$c);', # ($b&($c^$d)) | ||
| 784 | '&$_ror ($b,7);', # $b>>>2 | ||
| 785 | '&add ($e,@T[1]);', | ||
| 786 | '&mov (@T[1],$a);', # $b in next round | ||
| 787 | '&$_rol ($a,5);', | ||
| 788 | '&add ($e,@T[0]);', | ||
| 789 | '&xor ($c,$d);', # restore $c | ||
| 790 | '&add ($e,$a);' .'unshift(@V,pop(@V)); unshift(@T,pop(@T));' | ||
| 791 | ); | ||
| 792 | } | ||
| 793 | |||
| 794 | &set_label("loop",16); | ||
| 795 | &Xupdate_ssse3_16_31(\&body_00_19); | ||
| 796 | &Xupdate_ssse3_16_31(\&body_00_19); | ||
| 797 | &Xupdate_ssse3_16_31(\&body_00_19); | ||
| 798 | &Xupdate_ssse3_16_31(\&body_00_19); | ||
| 799 | &Xupdate_ssse3_32_79(\&body_00_19); | ||
| 800 | &Xupdate_ssse3_32_79(\&body_20_39); | ||
| 801 | &Xupdate_ssse3_32_79(\&body_20_39); | ||
| 802 | &Xupdate_ssse3_32_79(\&body_20_39); | ||
| 803 | &Xupdate_ssse3_32_79(\&body_20_39); | ||
| 804 | &Xupdate_ssse3_32_79(\&body_20_39); | ||
| 805 | &Xupdate_ssse3_32_79(\&body_40_59); | ||
| 806 | &Xupdate_ssse3_32_79(\&body_40_59); | ||
| 807 | &Xupdate_ssse3_32_79(\&body_40_59); | ||
| 808 | &Xupdate_ssse3_32_79(\&body_40_59); | ||
| 809 | &Xupdate_ssse3_32_79(\&body_40_59); | ||
| 810 | &Xupdate_ssse3_32_79(\&body_20_39); | ||
| 811 | &Xuplast_ssse3_80(\&body_20_39); # can jump to "done" | ||
| 812 | |||
| 813 | $saved_j=$j; @saved_V=@V; | ||
| 814 | |||
| 815 | &Xloop_ssse3(\&body_20_39); | ||
| 816 | &Xloop_ssse3(\&body_20_39); | ||
| 817 | &Xloop_ssse3(\&body_20_39); | ||
| 818 | |||
| 819 | &mov (@T[1],&DWP(192,"esp")); # update context | ||
| 820 | &add ($A,&DWP(0,@T[1])); | ||
| 821 | &add (@T[0],&DWP(4,@T[1])); # $b | ||
| 822 | &add ($C,&DWP(8,@T[1])); | ||
| 823 | &mov (&DWP(0,@T[1]),$A); | ||
| 824 | &add ($D,&DWP(12,@T[1])); | ||
| 825 | &mov (&DWP(4,@T[1]),@T[0]); | ||
| 826 | &add ($E,&DWP(16,@T[1])); | ||
| 827 | &mov (&DWP(8,@T[1]),$C); | ||
| 828 | &mov ($B,@T[0]); | ||
| 829 | &mov (&DWP(12,@T[1]),$D); | ||
| 830 | &mov (&DWP(16,@T[1]),$E); | ||
| 831 | &movdqa (@X[0],@X[-3&7]); | ||
| 832 | |||
| 833 | &jmp (&label("loop")); | ||
| 834 | |||
| 835 | &set_label("done",16); $j=$saved_j; @V=@saved_V; | ||
| 836 | |||
| 837 | &Xtail_ssse3(\&body_20_39); | ||
| 838 | &Xtail_ssse3(\&body_20_39); | ||
| 839 | &Xtail_ssse3(\&body_20_39); | ||
| 840 | |||
| 841 | &mov (@T[1],&DWP(192,"esp")); # update context | ||
| 842 | &add ($A,&DWP(0,@T[1])); | ||
| 843 | &mov ("esp",&DWP(192+12,"esp")); # restore %esp | ||
| 844 | &add (@T[0],&DWP(4,@T[1])); # $b | ||
| 845 | &add ($C,&DWP(8,@T[1])); | ||
| 846 | &mov (&DWP(0,@T[1]),$A); | ||
| 847 | &add ($D,&DWP(12,@T[1])); | ||
| 848 | &mov (&DWP(4,@T[1]),@T[0]); | ||
| 849 | &add ($E,&DWP(16,@T[1])); | ||
| 850 | &mov (&DWP(8,@T[1]),$C); | ||
| 851 | &mov (&DWP(12,@T[1]),$D); | ||
| 852 | &mov (&DWP(16,@T[1]),$E); | ||
| 853 | |||
| 854 | &function_end("_sha1_block_data_order_ssse3"); | ||
| 855 | |||
| 856 | if ($ymm) { | ||
| 857 | my $Xi=4; # 4xSIMD Xupdate round, start pre-seeded | ||
| 858 | my @X=map("xmm$_",(4..7,0..3)); # pre-seeded for $Xi=4 | ||
| 859 | my @V=($A,$B,$C,$D,$E); | ||
| 860 | my $j=0; # hash round | ||
| 861 | my @T=($T,$tmp1); | ||
| 862 | my $inp; | ||
| 863 | |||
| 864 | my $_rol=sub { &shld(@_[0],@_) }; | ||
| 865 | my $_ror=sub { &shrd(@_[0],@_) }; | ||
| 866 | |||
| 867 | &function_begin("_sha1_block_data_order_avx"); | ||
| 868 | &call (&label("pic_point")); # make it PIC! | ||
| 869 | &set_label("pic_point"); | ||
| 870 | &blindpop($tmp1); | ||
| 871 | &lea ($tmp1,&DWP(&label("K_XX_XX")."-".&label("pic_point"),$tmp1)); | ||
| 872 | &set_label("avx_shortcut"); | ||
| 873 | &vzeroall(); | ||
| 874 | |||
| 875 | &vmovdqa(@X[3],&QWP(0,$tmp1)); # K_00_19 | ||
| 876 | &vmovdqa(@X[4],&QWP(16,$tmp1)); # K_20_39 | ||
| 877 | &vmovdqa(@X[5],&QWP(32,$tmp1)); # K_40_59 | ||
| 878 | &vmovdqa(@X[6],&QWP(48,$tmp1)); # K_60_79 | ||
| 879 | &vmovdqa(@X[2],&QWP(64,$tmp1)); # pbswap mask | ||
| 880 | |||
| 881 | &mov ($E,&wparam(0)); # load argument block | ||
| 882 | &mov ($inp=@T[1],&wparam(1)); | ||
| 883 | &mov ($D,&wparam(2)); | ||
| 884 | &mov (@T[0],"esp"); | ||
| 885 | |||
| 886 | # stack frame layout | ||
| 887 | # | ||
| 888 | # +0 X[0]+K X[1]+K X[2]+K X[3]+K # XMM->IALU xfer area | ||
| 889 | # X[4]+K X[5]+K X[6]+K X[7]+K | ||
| 890 | # X[8]+K X[9]+K X[10]+K X[11]+K | ||
| 891 | # X[12]+K X[13]+K X[14]+K X[15]+K | ||
| 892 | # | ||
| 893 | # +64 X[0] X[1] X[2] X[3] # XMM->XMM backtrace area | ||
| 894 | # X[4] X[5] X[6] X[7] | ||
| 895 | # X[8] X[9] X[10] X[11] # even borrowed for K_00_19 | ||
| 896 | # | ||
| 897 | # +112 K_20_39 K_20_39 K_20_39 K_20_39 # constants | ||
| 898 | # K_40_59 K_40_59 K_40_59 K_40_59 | ||
| 899 | # K_60_79 K_60_79 K_60_79 K_60_79 | ||
| 900 | # K_00_19 K_00_19 K_00_19 K_00_19 | ||
| 901 | # pbswap mask | ||
| 902 | # | ||
| 903 | # +192 ctx # argument block | ||
| 904 | # +196 inp | ||
| 905 | # +200 end | ||
| 906 | # +204 esp | ||
| 907 | &sub ("esp",208); | ||
| 908 | &and ("esp",-64); | ||
| 909 | |||
| 910 | &vmovdqa(&QWP(112+0,"esp"),@X[4]); # copy constants | ||
| 911 | &vmovdqa(&QWP(112+16,"esp"),@X[5]); | ||
| 912 | &vmovdqa(&QWP(112+32,"esp"),@X[6]); | ||
| 913 | &shl ($D,6); # len*64 | ||
| 914 | &vmovdqa(&QWP(112+48,"esp"),@X[3]); | ||
| 915 | &add ($D,$inp); # end of input | ||
| 916 | &vmovdqa(&QWP(112+64,"esp"),@X[2]); | ||
| 917 | &add ($inp,64); | ||
| 918 | &mov (&DWP(192+0,"esp"),$E); # save argument block | ||
| 919 | &mov (&DWP(192+4,"esp"),$inp); | ||
| 920 | &mov (&DWP(192+8,"esp"),$D); | ||
| 921 | &mov (&DWP(192+12,"esp"),@T[0]); # save original %esp | ||
| 922 | |||
| 923 | &mov ($A,&DWP(0,$E)); # load context | ||
| 924 | &mov ($B,&DWP(4,$E)); | ||
| 925 | &mov ($C,&DWP(8,$E)); | ||
| 926 | &mov ($D,&DWP(12,$E)); | ||
| 927 | &mov ($E,&DWP(16,$E)); | ||
| 928 | &mov (@T[0],$B); # magic seed | ||
| 929 | |||
| 930 | &vmovdqu(@X[-4&7],&QWP(-64,$inp)); # load input to %xmm[0-3] | ||
| 931 | &vmovdqu(@X[-3&7],&QWP(-48,$inp)); | ||
| 932 | &vmovdqu(@X[-2&7],&QWP(-32,$inp)); | ||
| 933 | &vmovdqu(@X[-1&7],&QWP(-16,$inp)); | ||
| 934 | &vpshufb(@X[-4&7],@X[-4&7],@X[2]); # byte swap | ||
| 935 | &vpshufb(@X[-3&7],@X[-3&7],@X[2]); | ||
| 936 | &vpshufb(@X[-2&7],@X[-2&7],@X[2]); | ||
| 937 | &vmovdqa(&QWP(112-16,"esp"),@X[3]); # borrow last backtrace slot | ||
| 938 | &vpshufb(@X[-1&7],@X[-1&7],@X[2]); | ||
| 939 | &vpaddd (@X[0],@X[-4&7],@X[3]); # add K_00_19 | ||
| 940 | &vpaddd (@X[1],@X[-3&7],@X[3]); | ||
| 941 | &vpaddd (@X[2],@X[-2&7],@X[3]); | ||
| 942 | &vmovdqa(&QWP(0,"esp"),@X[0]); # X[]+K xfer to IALU | ||
| 943 | &vmovdqa(&QWP(0+16,"esp"),@X[1]); | ||
| 944 | &vmovdqa(&QWP(0+32,"esp"),@X[2]); | ||
| 945 | &jmp (&label("loop")); | ||
| 946 | |||
| 947 | sub Xupdate_avx_16_31() # recall that $Xi starts wtih 4 | ||
| 948 | { use integer; | ||
| 949 | my $body = shift; | ||
| 950 | my @insns = (&$body,&$body,&$body,&$body); # 40 instructions | ||
| 951 | my ($a,$b,$c,$d,$e); | ||
| 952 | |||
| 953 | eval(shift(@insns)); | ||
| 954 | eval(shift(@insns)); | ||
| 955 | &vpalignr(@X[0],@X[-3&7],@X[-4&7],8); # compose "X[-14]" in "X[0]" | ||
| 956 | eval(shift(@insns)); | ||
| 957 | eval(shift(@insns)); | ||
| 958 | |||
| 959 | &vpaddd (@X[3],@X[3],@X[-1&7]); | ||
| 960 | &vmovdqa (&QWP(64+16*(($Xi-4)%3),"esp"),@X[-4&7]);# save X[] to backtrace buffer | ||
| 961 | eval(shift(@insns)); | ||
| 962 | eval(shift(@insns)); | ||
| 963 | &vpsrldq(@X[2],@X[-1&7],4); # "X[-3]", 3 dwords | ||
| 964 | eval(shift(@insns)); | ||
| 965 | eval(shift(@insns)); | ||
| 966 | &vpxor (@X[0],@X[0],@X[-4&7]); # "X[0]"^="X[-16]" | ||
| 967 | eval(shift(@insns)); | ||
| 968 | eval(shift(@insns)); | ||
| 969 | |||
| 970 | &vpxor (@X[2],@X[2],@X[-2&7]); # "X[-3]"^"X[-8]" | ||
| 971 | eval(shift(@insns)); | ||
| 972 | eval(shift(@insns)); | ||
| 973 | &vmovdqa (&QWP(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU | ||
| 974 | eval(shift(@insns)); | ||
| 975 | eval(shift(@insns)); | ||
| 976 | |||
| 977 | &vpxor (@X[0],@X[0],@X[2]); # "X[0]"^="X[-3]"^"X[-8]" | ||
| 978 | eval(shift(@insns)); | ||
| 979 | eval(shift(@insns)); | ||
| 980 | eval(shift(@insns)); | ||
| 981 | eval(shift(@insns)); | ||
| 982 | |||
| 983 | &vpsrld (@X[2],@X[0],31); | ||
| 984 | eval(shift(@insns)); | ||
| 985 | eval(shift(@insns)); | ||
| 986 | eval(shift(@insns)); | ||
| 987 | eval(shift(@insns)); | ||
| 988 | |||
| 989 | &vpslldq(@X[4],@X[0],12); # "X[0]"<<96, extract one dword | ||
| 990 | &vpaddd (@X[0],@X[0],@X[0]); | ||
| 991 | eval(shift(@insns)); | ||
| 992 | eval(shift(@insns)); | ||
| 993 | eval(shift(@insns)); | ||
| 994 | eval(shift(@insns)); | ||
| 995 | |||
| 996 | &vpsrld (@X[3],@X[4],30); | ||
| 997 | &vpor (@X[0],@X[0],@X[2]); # "X[0]"<<<=1 | ||
| 998 | eval(shift(@insns)); | ||
| 999 | eval(shift(@insns)); | ||
| 1000 | eval(shift(@insns)); | ||
| 1001 | eval(shift(@insns)); | ||
| 1002 | |||
| 1003 | &vpslld (@X[4],@X[4],2); | ||
| 1004 | &vmovdqa (@X[2],&QWP(64+16*(($Xi-6)%3),"esp")) if ($Xi>5); # restore X[] from backtrace buffer | ||
| 1005 | eval(shift(@insns)); | ||
| 1006 | eval(shift(@insns)); | ||
| 1007 | &vpxor (@X[0],@X[0],@X[3]); | ||
| 1008 | eval(shift(@insns)); | ||
| 1009 | eval(shift(@insns)); | ||
| 1010 | eval(shift(@insns)); | ||
| 1011 | eval(shift(@insns)); | ||
| 1012 | |||
| 1013 | &vpxor (@X[0],@X[0],@X[4]); # "X[0]"^=("X[0]"<<96)<<<2 | ||
| 1014 | eval(shift(@insns)); | ||
| 1015 | eval(shift(@insns)); | ||
| 1016 | &vmovdqa (@X[4],&QWP(112-16+16*(($Xi)/5),"esp")); # K_XX_XX | ||
| 1017 | eval(shift(@insns)); | ||
| 1018 | eval(shift(@insns)); | ||
| 1019 | |||
| 1020 | foreach (@insns) { eval; } # remaining instructions [if any] | ||
| 1021 | |||
| 1022 | $Xi++; push(@X,shift(@X)); # "rotate" X[] | ||
| 1023 | } | ||
| 1024 | |||
| 1025 | sub Xupdate_avx_32_79() | ||
| 1026 | { use integer; | ||
| 1027 | my $body = shift; | ||
| 1028 | my @insns = (&$body,&$body,&$body,&$body); # 32 to 48 instructions | ||
| 1029 | my ($a,$b,$c,$d,$e); | ||
| 1030 | |||
| 1031 | &vpalignr(@X[2],@X[-1&7],@X[-2&7],8); # compose "X[-6]" | ||
| 1032 | &vpxor (@X[0],@X[0],@X[-4&7]); # "X[0]"="X[-32]"^"X[-16]" | ||
| 1033 | eval(shift(@insns)); # body_20_39 | ||
| 1034 | eval(shift(@insns)); | ||
| 1035 | eval(shift(@insns)); | ||
| 1036 | eval(shift(@insns)); # rol | ||
| 1037 | |||
| 1038 | &vpxor (@X[0],@X[0],@X[-7&7]); # "X[0]"^="X[-28]" | ||
| 1039 | &vmovdqa (&QWP(64+16*(($Xi-4)%3),"esp"),@X[-4&7]); # save X[] to backtrace buffer | ||
| 1040 | eval(shift(@insns)); | ||
| 1041 | eval(shift(@insns)); | ||
| 1042 | if ($Xi%5) { | ||
| 1043 | &vmovdqa (@X[4],@X[3]); # "perpetuate" K_XX_XX... | ||
| 1044 | } else { # ... or load next one | ||
| 1045 | &vmovdqa (@X[4],&QWP(112-16+16*($Xi/5),"esp")); | ||
| 1046 | } | ||
| 1047 | &vpaddd (@X[3],@X[3],@X[-1&7]); | ||
| 1048 | eval(shift(@insns)); # ror | ||
| 1049 | eval(shift(@insns)); | ||
| 1050 | |||
| 1051 | &vpxor (@X[0],@X[0],@X[2]); # "X[0]"^="X[-6]" | ||
| 1052 | eval(shift(@insns)); # body_20_39 | ||
| 1053 | eval(shift(@insns)); | ||
| 1054 | eval(shift(@insns)); | ||
| 1055 | eval(shift(@insns)); # rol | ||
| 1056 | |||
| 1057 | &vpsrld (@X[2],@X[0],30); | ||
| 1058 | &vmovdqa (&QWP(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer to IALU | ||
| 1059 | eval(shift(@insns)); | ||
| 1060 | eval(shift(@insns)); | ||
| 1061 | eval(shift(@insns)); # ror | ||
| 1062 | eval(shift(@insns)); | ||
| 1063 | |||
| 1064 | &vpslld (@X[0],@X[0],2); | ||
| 1065 | eval(shift(@insns)); # body_20_39 | ||
| 1066 | eval(shift(@insns)); | ||
| 1067 | eval(shift(@insns)); | ||
| 1068 | eval(shift(@insns)); # rol | ||
| 1069 | eval(shift(@insns)); | ||
| 1070 | eval(shift(@insns)); | ||
| 1071 | eval(shift(@insns)); # ror | ||
| 1072 | eval(shift(@insns)); | ||
| 1073 | |||
| 1074 | &vpor (@X[0],@X[0],@X[2]); # "X[0]"<<<=2 | ||
| 1075 | eval(shift(@insns)); # body_20_39 | ||
| 1076 | eval(shift(@insns)); | ||
| 1077 | &vmovdqa (@X[2],&QWP(64+16*(($Xi-6)%3),"esp")) if($Xi<19); # restore X[] from backtrace buffer | ||
| 1078 | eval(shift(@insns)); | ||
| 1079 | eval(shift(@insns)); # rol | ||
| 1080 | eval(shift(@insns)); | ||
| 1081 | eval(shift(@insns)); | ||
| 1082 | eval(shift(@insns)); # ror | ||
| 1083 | eval(shift(@insns)); | ||
| 1084 | |||
| 1085 | foreach (@insns) { eval; } # remaining instructions | ||
| 1086 | |||
| 1087 | $Xi++; push(@X,shift(@X)); # "rotate" X[] | ||
| 1088 | } | ||
| 1089 | |||
| 1090 | sub Xuplast_avx_80() | ||
| 1091 | { use integer; | ||
| 1092 | my $body = shift; | ||
| 1093 | my @insns = (&$body,&$body,&$body,&$body); # 32 instructions | ||
| 1094 | my ($a,$b,$c,$d,$e); | ||
| 1095 | |||
| 1096 | eval(shift(@insns)); | ||
| 1097 | &vpaddd (@X[3],@X[3],@X[-1&7]); | ||
| 1098 | eval(shift(@insns)); | ||
| 1099 | eval(shift(@insns)); | ||
| 1100 | eval(shift(@insns)); | ||
| 1101 | eval(shift(@insns)); | ||
| 1102 | |||
| 1103 | &vmovdqa (&QWP(0+16*(($Xi-1)&3),"esp"),@X[3]); # X[]+K xfer IALU | ||
| 1104 | |||
| 1105 | foreach (@insns) { eval; } # remaining instructions | ||
| 1106 | |||
| 1107 | &mov ($inp=@T[1],&DWP(192+4,"esp")); | ||
| 1108 | &cmp ($inp,&DWP(192+8,"esp")); | ||
| 1109 | &je (&label("done")); | ||
| 1110 | |||
| 1111 | &vmovdqa(@X[3],&QWP(112+48,"esp")); # K_00_19 | ||
| 1112 | &vmovdqa(@X[2],&QWP(112+64,"esp")); # pbswap mask | ||
| 1113 | &vmovdqu(@X[-4&7],&QWP(0,$inp)); # load input | ||
| 1114 | &vmovdqu(@X[-3&7],&QWP(16,$inp)); | ||
| 1115 | &vmovdqu(@X[-2&7],&QWP(32,$inp)); | ||
| 1116 | &vmovdqu(@X[-1&7],&QWP(48,$inp)); | ||
| 1117 | &add ($inp,64); | ||
| 1118 | &vpshufb(@X[-4&7],@X[-4&7],@X[2]); # byte swap | ||
| 1119 | &mov (&DWP(192+4,"esp"),$inp); | ||
| 1120 | &vmovdqa(&QWP(112-16,"esp"),@X[3]); # borrow last backtrace slot | ||
| 1121 | |||
| 1122 | $Xi=0; | ||
| 1123 | } | ||
| 1124 | |||
| 1125 | sub Xloop_avx() | ||
| 1126 | { use integer; | ||
| 1127 | my $body = shift; | ||
| 1128 | my @insns = (&$body,&$body,&$body,&$body); # 32 instructions | ||
| 1129 | my ($a,$b,$c,$d,$e); | ||
| 1130 | |||
| 1131 | eval(shift(@insns)); | ||
| 1132 | eval(shift(@insns)); | ||
| 1133 | &vpshufb (@X[($Xi-3)&7],@X[($Xi-3)&7],@X[2]); | ||
| 1134 | eval(shift(@insns)); | ||
| 1135 | eval(shift(@insns)); | ||
| 1136 | &vpaddd (@X[$Xi&7],@X[($Xi-4)&7],@X[3]); | ||
| 1137 | eval(shift(@insns)); | ||
| 1138 | eval(shift(@insns)); | ||
| 1139 | eval(shift(@insns)); | ||
| 1140 | eval(shift(@insns)); | ||
| 1141 | &vmovdqa (&QWP(0+16*$Xi,"esp"),@X[$Xi&7]); # X[]+K xfer to IALU | ||
| 1142 | eval(shift(@insns)); | ||
| 1143 | eval(shift(@insns)); | ||
| 1144 | |||
| 1145 | foreach (@insns) { eval; } | ||
| 1146 | $Xi++; | ||
| 1147 | } | ||
| 1148 | |||
| 1149 | sub Xtail_avx() | ||
| 1150 | { use integer; | ||
| 1151 | my $body = shift; | ||
| 1152 | my @insns = (&$body,&$body,&$body,&$body); # 32 instructions | ||
| 1153 | my ($a,$b,$c,$d,$e); | ||
| 1154 | |||
| 1155 | foreach (@insns) { eval; } | ||
| 1156 | } | ||
| 1157 | |||
| 1158 | &set_label("loop",16); | ||
| 1159 | &Xupdate_avx_16_31(\&body_00_19); | ||
| 1160 | &Xupdate_avx_16_31(\&body_00_19); | ||
| 1161 | &Xupdate_avx_16_31(\&body_00_19); | ||
| 1162 | &Xupdate_avx_16_31(\&body_00_19); | ||
| 1163 | &Xupdate_avx_32_79(\&body_00_19); | ||
| 1164 | &Xupdate_avx_32_79(\&body_20_39); | ||
| 1165 | &Xupdate_avx_32_79(\&body_20_39); | ||
| 1166 | &Xupdate_avx_32_79(\&body_20_39); | ||
| 1167 | &Xupdate_avx_32_79(\&body_20_39); | ||
| 1168 | &Xupdate_avx_32_79(\&body_20_39); | ||
| 1169 | &Xupdate_avx_32_79(\&body_40_59); | ||
| 1170 | &Xupdate_avx_32_79(\&body_40_59); | ||
| 1171 | &Xupdate_avx_32_79(\&body_40_59); | ||
| 1172 | &Xupdate_avx_32_79(\&body_40_59); | ||
| 1173 | &Xupdate_avx_32_79(\&body_40_59); | ||
| 1174 | &Xupdate_avx_32_79(\&body_20_39); | ||
| 1175 | &Xuplast_avx_80(\&body_20_39); # can jump to "done" | ||
| 1176 | |||
| 1177 | $saved_j=$j; @saved_V=@V; | ||
| 1178 | |||
| 1179 | &Xloop_avx(\&body_20_39); | ||
| 1180 | &Xloop_avx(\&body_20_39); | ||
| 1181 | &Xloop_avx(\&body_20_39); | ||
| 1182 | |||
| 1183 | &mov (@T[1],&DWP(192,"esp")); # update context | ||
| 1184 | &add ($A,&DWP(0,@T[1])); | ||
| 1185 | &add (@T[0],&DWP(4,@T[1])); # $b | ||
| 1186 | &add ($C,&DWP(8,@T[1])); | ||
| 1187 | &mov (&DWP(0,@T[1]),$A); | ||
| 1188 | &add ($D,&DWP(12,@T[1])); | ||
| 1189 | &mov (&DWP(4,@T[1]),@T[0]); | ||
| 1190 | &add ($E,&DWP(16,@T[1])); | ||
| 1191 | &mov (&DWP(8,@T[1]),$C); | ||
| 1192 | &mov ($B,@T[0]); | ||
| 1193 | &mov (&DWP(12,@T[1]),$D); | ||
| 1194 | &mov (&DWP(16,@T[1]),$E); | ||
| 1195 | |||
| 1196 | &jmp (&label("loop")); | ||
| 1197 | |||
| 1198 | &set_label("done",16); $j=$saved_j; @V=@saved_V; | ||
| 1199 | |||
| 1200 | &Xtail_avx(\&body_20_39); | ||
| 1201 | &Xtail_avx(\&body_20_39); | ||
| 1202 | &Xtail_avx(\&body_20_39); | ||
| 1203 | |||
| 1204 | &vzeroall(); | ||
| 1205 | |||
| 1206 | &mov (@T[1],&DWP(192,"esp")); # update context | ||
| 1207 | &add ($A,&DWP(0,@T[1])); | ||
| 1208 | &mov ("esp",&DWP(192+12,"esp")); # restore %esp | ||
| 1209 | &add (@T[0],&DWP(4,@T[1])); # $b | ||
| 1210 | &add ($C,&DWP(8,@T[1])); | ||
| 1211 | &mov (&DWP(0,@T[1]),$A); | ||
| 1212 | &add ($D,&DWP(12,@T[1])); | ||
| 1213 | &mov (&DWP(4,@T[1]),@T[0]); | ||
| 1214 | &add ($E,&DWP(16,@T[1])); | ||
| 1215 | &mov (&DWP(8,@T[1]),$C); | ||
| 1216 | &mov (&DWP(12,@T[1]),$D); | ||
| 1217 | &mov (&DWP(16,@T[1]),$E); | ||
| 1218 | &function_end("_sha1_block_data_order_avx"); | ||
| 1219 | } | ||
| 1220 | &set_label("K_XX_XX",64); | ||
| 1221 | &data_word(0x5a827999,0x5a827999,0x5a827999,0x5a827999); # K_00_19 | ||
| 1222 | &data_word(0x6ed9eba1,0x6ed9eba1,0x6ed9eba1,0x6ed9eba1); # K_20_39 | ||
| 1223 | &data_word(0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc,0x8f1bbcdc); # K_40_59 | ||
| 1224 | &data_word(0xca62c1d6,0xca62c1d6,0xca62c1d6,0xca62c1d6); # K_60_79 | ||
| 1225 | &data_word(0x00010203,0x04050607,0x08090a0b,0x0c0d0e0f); # pbswap mask | ||
| 1226 | } | ||
| 1227 | &asciz("SHA1 block transform for x86, CRYPTOGAMS by <appro\@openssl.org>"); | 218 | &asciz("SHA1 block transform for x86, CRYPTOGAMS by <appro\@openssl.org>"); |
| 1228 | 219 | ||
| 1229 | &asm_finish(); | 220 | &asm_finish(); |
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 index 8a6bf4bbbb..16cacf9fc0 100644 --- a/src/lib/libcrypto/sha/sha.h +++ b/src/lib/libcrypto/sha/sha.h | |||
| @@ -106,9 +106,6 @@ typedef struct SHAstate_st | |||
| 106 | } SHA_CTX; | 106 | } SHA_CTX; |
| 107 | 107 | ||
| 108 | #ifndef OPENSSL_NO_SHA0 | 108 | #ifndef OPENSSL_NO_SHA0 |
| 109 | #ifdef OPENSSL_FIPS | ||
| 110 | int private_SHA_Init(SHA_CTX *c); | ||
| 111 | #endif | ||
| 112 | int SHA_Init(SHA_CTX *c); | 109 | int SHA_Init(SHA_CTX *c); |
| 113 | int SHA_Update(SHA_CTX *c, const void *data, size_t len); | 110 | int SHA_Update(SHA_CTX *c, const void *data, size_t len); |
| 114 | int SHA_Final(unsigned char *md, SHA_CTX *c); | 111 | int SHA_Final(unsigned char *md, SHA_CTX *c); |
| @@ -116,9 +113,6 @@ unsigned char *SHA(const unsigned char *d, size_t n, unsigned char *md); | |||
| 116 | void SHA_Transform(SHA_CTX *c, const unsigned char *data); | 113 | void SHA_Transform(SHA_CTX *c, const unsigned char *data); |
| 117 | #endif | 114 | #endif |
| 118 | #ifndef OPENSSL_NO_SHA1 | 115 | #ifndef OPENSSL_NO_SHA1 |
| 119 | #ifdef OPENSSL_FIPS | ||
| 120 | int private_SHA1_Init(SHA_CTX *c); | ||
| 121 | #endif | ||
| 122 | int SHA1_Init(SHA_CTX *c); | 116 | int SHA1_Init(SHA_CTX *c); |
| 123 | int SHA1_Update(SHA_CTX *c, const void *data, size_t len); | 117 | int SHA1_Update(SHA_CTX *c, const void *data, size_t len); |
| 124 | int SHA1_Final(unsigned char *md, SHA_CTX *c); | 118 | int SHA1_Final(unsigned char *md, SHA_CTX *c); |
| @@ -141,10 +135,6 @@ typedef struct SHA256state_st | |||
| 141 | } SHA256_CTX; | 135 | } SHA256_CTX; |
| 142 | 136 | ||
| 143 | #ifndef OPENSSL_NO_SHA256 | 137 | #ifndef OPENSSL_NO_SHA256 |
| 144 | #ifdef OPENSSL_FIPS | ||
| 145 | int private_SHA224_Init(SHA256_CTX *c); | ||
| 146 | int private_SHA256_Init(SHA256_CTX *c); | ||
| 147 | #endif | ||
| 148 | int SHA224_Init(SHA256_CTX *c); | 138 | int SHA224_Init(SHA256_CTX *c); |
| 149 | int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); | 139 | int SHA224_Update(SHA256_CTX *c, const void *data, size_t len); |
| 150 | int SHA224_Final(unsigned char *md, SHA256_CTX *c); | 140 | int SHA224_Final(unsigned char *md, SHA256_CTX *c); |
| @@ -192,10 +182,6 @@ typedef struct SHA512state_st | |||
| 192 | #endif | 182 | #endif |
| 193 | 183 | ||
| 194 | #ifndef OPENSSL_NO_SHA512 | 184 | #ifndef OPENSSL_NO_SHA512 |
| 195 | #ifdef OPENSSL_FIPS | ||
| 196 | int private_SHA384_Init(SHA512_CTX *c); | ||
| 197 | int private_SHA512_Init(SHA512_CTX *c); | ||
| 198 | #endif | ||
| 199 | int SHA384_Init(SHA512_CTX *c); | 185 | int SHA384_Init(SHA512_CTX *c); |
| 200 | int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); | 186 | int SHA384_Update(SHA512_CTX *c, const void *data, size_t len); |
| 201 | int SHA384_Final(unsigned char *md, SHA512_CTX *c); | 187 | int SHA384_Final(unsigned char *md, SHA512_CTX *c); |
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/sha1dgst.c b/src/lib/libcrypto/sha/sha1dgst.c index 81219af088..50d1925cde 100644 --- a/src/lib/libcrypto/sha/sha1dgst.c +++ b/src/lib/libcrypto/sha/sha1dgst.c | |||
| @@ -57,7 +57,6 @@ | |||
| 57 | */ | 57 | */ |
| 58 | 58 | ||
| 59 | #include <openssl/opensslconf.h> | 59 | #include <openssl/opensslconf.h> |
| 60 | #include <openssl/crypto.h> | ||
| 61 | #if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA) | 60 | #if !defined(OPENSSL_NO_SHA1) && !defined(OPENSSL_NO_SHA) |
| 62 | 61 | ||
| 63 | #undef SHA_0 | 62 | #undef SHA_0 |
diff --git a/src/lib/libcrypto/sha/sha1test.c b/src/lib/libcrypto/sha/sha1test.c new file mode 100644 index 0000000000..6feb3964c7 --- /dev/null +++ b/src/lib/libcrypto/sha/sha1test.c | |||
| @@ -0,0 +1,178 @@ | |||
| 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 | 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=test; | ||
| 122 | R=ret; | ||
| 123 | i=1; | ||
| 124 | while (*P != NULL) | ||
| 125 | { | ||
| 126 | EVP_Digest(*P,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 | |||
| 161 | #ifdef OPENSSL_SYS_NETWARE | ||
| 162 | if (err) printf("ERROR: %d\n", err); | ||
| 163 | #endif | ||
| 164 | EXIT(err); | ||
| 165 | EVP_MD_CTX_cleanup(&c); | ||
| 166 | return(0); | ||
| 167 | } | ||
| 168 | |||
| 169 | static char *pt(unsigned char *md) | ||
| 170 | { | ||
| 171 | int i; | ||
| 172 | static char buf[80]; | ||
| 173 | |||
| 174 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 175 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
| 176 | return(buf); | ||
| 177 | } | ||
| 178 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha256t.c b/src/lib/libcrypto/sha/sha256t.c new file mode 100644 index 0000000000..6b4a3bd001 --- /dev/null +++ b/src/lib/libcrypto/sha/sha256t.c | |||
| @@ -0,0 +1,147 @@ | |||
| 1 | /* crypto/sha/sha256t.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 4 | * ==================================================================== | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include <openssl/sha.h> | ||
| 11 | #include <openssl/evp.h> | ||
| 12 | |||
| 13 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA256) | ||
| 14 | int main(int argc, char *argv[]) | ||
| 15 | { | ||
| 16 | printf("No SHA256 support\n"); | ||
| 17 | return(0); | ||
| 18 | } | ||
| 19 | #else | ||
| 20 | |||
| 21 | unsigned char app_b1[SHA256_DIGEST_LENGTH] = { | ||
| 22 | 0xba,0x78,0x16,0xbf,0x8f,0x01,0xcf,0xea, | ||
| 23 | 0x41,0x41,0x40,0xde,0x5d,0xae,0x22,0x23, | ||
| 24 | 0xb0,0x03,0x61,0xa3,0x96,0x17,0x7a,0x9c, | ||
| 25 | 0xb4,0x10,0xff,0x61,0xf2,0x00,0x15,0xad }; | ||
| 26 | |||
| 27 | unsigned char app_b2[SHA256_DIGEST_LENGTH] = { | ||
| 28 | 0x24,0x8d,0x6a,0x61,0xd2,0x06,0x38,0xb8, | ||
| 29 | 0xe5,0xc0,0x26,0x93,0x0c,0x3e,0x60,0x39, | ||
| 30 | 0xa3,0x3c,0xe4,0x59,0x64,0xff,0x21,0x67, | ||
| 31 | 0xf6,0xec,0xed,0xd4,0x19,0xdb,0x06,0xc1 }; | ||
| 32 | |||
| 33 | unsigned char app_b3[SHA256_DIGEST_LENGTH] = { | ||
| 34 | 0xcd,0xc7,0x6e,0x5c,0x99,0x14,0xfb,0x92, | ||
| 35 | 0x81,0xa1,0xc7,0xe2,0x84,0xd7,0x3e,0x67, | ||
| 36 | 0xf1,0x80,0x9a,0x48,0xa4,0x97,0x20,0x0e, | ||
| 37 | 0x04,0x6d,0x39,0xcc,0xc7,0x11,0x2c,0xd0 }; | ||
| 38 | |||
| 39 | unsigned char addenum_1[SHA224_DIGEST_LENGTH] = { | ||
| 40 | 0x23,0x09,0x7d,0x22,0x34,0x05,0xd8,0x22, | ||
| 41 | 0x86,0x42,0xa4,0x77,0xbd,0xa2,0x55,0xb3, | ||
| 42 | 0x2a,0xad,0xbc,0xe4,0xbd,0xa0,0xb3,0xf7, | ||
| 43 | 0xe3,0x6c,0x9d,0xa7 }; | ||
| 44 | |||
| 45 | unsigned char addenum_2[SHA224_DIGEST_LENGTH] = { | ||
| 46 | 0x75,0x38,0x8b,0x16,0x51,0x27,0x76,0xcc, | ||
| 47 | 0x5d,0xba,0x5d,0xa1,0xfd,0x89,0x01,0x50, | ||
| 48 | 0xb0,0xc6,0x45,0x5c,0xb4,0xf5,0x8b,0x19, | ||
| 49 | 0x52,0x52,0x25,0x25 }; | ||
| 50 | |||
| 51 | unsigned char addenum_3[SHA224_DIGEST_LENGTH] = { | ||
| 52 | 0x20,0x79,0x46,0x55,0x98,0x0c,0x91,0xd8, | ||
| 53 | 0xbb,0xb4,0xc1,0xea,0x97,0x61,0x8a,0x4b, | ||
| 54 | 0xf0,0x3f,0x42,0x58,0x19,0x48,0xb2,0xee, | ||
| 55 | 0x4e,0xe7,0xad,0x67 }; | ||
| 56 | |||
| 57 | int main (int argc,char **argv) | ||
| 58 | { unsigned char md[SHA256_DIGEST_LENGTH]; | ||
| 59 | int i; | ||
| 60 | EVP_MD_CTX evp; | ||
| 61 | |||
| 62 | fprintf(stdout,"Testing SHA-256 "); | ||
| 63 | |||
| 64 | EVP_Digest ("abc",3,md,NULL,EVP_sha256(),NULL); | ||
| 65 | if (memcmp(md,app_b1,sizeof(app_b1))) | ||
| 66 | { fflush(stdout); | ||
| 67 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 68 | return 1; | ||
| 69 | } | ||
| 70 | else | ||
| 71 | fprintf(stdout,"."); fflush(stdout); | ||
| 72 | |||
| 73 | EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk" | ||
| 74 | "ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha256(),NULL); | ||
| 75 | if (memcmp(md,app_b2,sizeof(app_b2))) | ||
| 76 | { fflush(stdout); | ||
| 77 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 78 | return 1; | ||
| 79 | } | ||
| 80 | else | ||
| 81 | fprintf(stdout,"."); fflush(stdout); | ||
| 82 | |||
| 83 | EVP_MD_CTX_init (&evp); | ||
| 84 | EVP_DigestInit_ex (&evp,EVP_sha256(),NULL); | ||
| 85 | for (i=0;i<1000000;i+=160) | ||
| 86 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 87 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 88 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 89 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 90 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 91 | (1000000-i)<160?1000000-i:160); | ||
| 92 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 93 | EVP_MD_CTX_cleanup (&evp); | ||
| 94 | |||
| 95 | if (memcmp(md,app_b3,sizeof(app_b3))) | ||
| 96 | { fflush(stdout); | ||
| 97 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 98 | return 1; | ||
| 99 | } | ||
| 100 | else | ||
| 101 | fprintf(stdout,"."); fflush(stdout); | ||
| 102 | |||
| 103 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 104 | |||
| 105 | fprintf(stdout,"Testing SHA-224 "); | ||
| 106 | |||
| 107 | EVP_Digest ("abc",3,md,NULL,EVP_sha224(),NULL); | ||
| 108 | if (memcmp(md,addenum_1,sizeof(addenum_1))) | ||
| 109 | { fflush(stdout); | ||
| 110 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 111 | return 1; | ||
| 112 | } | ||
| 113 | else | ||
| 114 | fprintf(stdout,"."); fflush(stdout); | ||
| 115 | |||
| 116 | EVP_Digest ("abcdbcde""cdefdefg""efghfghi""ghijhijk" | ||
| 117 | "ijkljklm""klmnlmno""mnopnopq",56,md,NULL,EVP_sha224(),NULL); | ||
| 118 | if (memcmp(md,addenum_2,sizeof(addenum_2))) | ||
| 119 | { fflush(stdout); | ||
| 120 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 121 | return 1; | ||
| 122 | } | ||
| 123 | else | ||
| 124 | fprintf(stdout,"."); fflush(stdout); | ||
| 125 | |||
| 126 | EVP_MD_CTX_init (&evp); | ||
| 127 | EVP_DigestInit_ex (&evp,EVP_sha224(),NULL); | ||
| 128 | for (i=0;i<1000000;i+=64) | ||
| 129 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 130 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 131 | (1000000-i)<64?1000000-i:64); | ||
| 132 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 133 | EVP_MD_CTX_cleanup (&evp); | ||
| 134 | |||
| 135 | if (memcmp(md,addenum_3,sizeof(addenum_3))) | ||
| 136 | { fflush(stdout); | ||
| 137 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 138 | return 1; | ||
| 139 | } | ||
| 140 | else | ||
| 141 | fprintf(stdout,"."); fflush(stdout); | ||
| 142 | |||
| 143 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 144 | |||
| 145 | return 0; | ||
| 146 | } | ||
| 147 | #endif | ||
diff --git a/src/lib/libcrypto/sha/sha512t.c b/src/lib/libcrypto/sha/sha512t.c new file mode 100644 index 0000000000..210041d435 --- /dev/null +++ b/src/lib/libcrypto/sha/sha512t.c | |||
| @@ -0,0 +1,184 @@ | |||
| 1 | /* crypto/sha/sha512t.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 2004 The OpenSSL Project. All rights reserved. | ||
| 4 | * ==================================================================== | ||
| 5 | */ | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include <openssl/sha.h> | ||
| 11 | #include <openssl/evp.h> | ||
| 12 | #include <openssl/crypto.h> | ||
| 13 | |||
| 14 | #if defined(OPENSSL_NO_SHA) || defined(OPENSSL_NO_SHA512) | ||
| 15 | int main(int argc, char *argv[]) | ||
| 16 | { | ||
| 17 | printf("No SHA512 support\n"); | ||
| 18 | return(0); | ||
| 19 | } | ||
| 20 | #else | ||
| 21 | |||
| 22 | unsigned char app_c1[SHA512_DIGEST_LENGTH] = { | ||
| 23 | 0xdd,0xaf,0x35,0xa1,0x93,0x61,0x7a,0xba, | ||
| 24 | 0xcc,0x41,0x73,0x49,0xae,0x20,0x41,0x31, | ||
| 25 | 0x12,0xe6,0xfa,0x4e,0x89,0xa9,0x7e,0xa2, | ||
| 26 | 0x0a,0x9e,0xee,0xe6,0x4b,0x55,0xd3,0x9a, | ||
| 27 | 0x21,0x92,0x99,0x2a,0x27,0x4f,0xc1,0xa8, | ||
| 28 | 0x36,0xba,0x3c,0x23,0xa3,0xfe,0xeb,0xbd, | ||
| 29 | 0x45,0x4d,0x44,0x23,0x64,0x3c,0xe8,0x0e, | ||
| 30 | 0x2a,0x9a,0xc9,0x4f,0xa5,0x4c,0xa4,0x9f }; | ||
| 31 | |||
| 32 | unsigned char app_c2[SHA512_DIGEST_LENGTH] = { | ||
| 33 | 0x8e,0x95,0x9b,0x75,0xda,0xe3,0x13,0xda, | ||
| 34 | 0x8c,0xf4,0xf7,0x28,0x14,0xfc,0x14,0x3f, | ||
| 35 | 0x8f,0x77,0x79,0xc6,0xeb,0x9f,0x7f,0xa1, | ||
| 36 | 0x72,0x99,0xae,0xad,0xb6,0x88,0x90,0x18, | ||
| 37 | 0x50,0x1d,0x28,0x9e,0x49,0x00,0xf7,0xe4, | ||
| 38 | 0x33,0x1b,0x99,0xde,0xc4,0xb5,0x43,0x3a, | ||
| 39 | 0xc7,0xd3,0x29,0xee,0xb6,0xdd,0x26,0x54, | ||
| 40 | 0x5e,0x96,0xe5,0x5b,0x87,0x4b,0xe9,0x09 }; | ||
| 41 | |||
| 42 | unsigned char app_c3[SHA512_DIGEST_LENGTH] = { | ||
| 43 | 0xe7,0x18,0x48,0x3d,0x0c,0xe7,0x69,0x64, | ||
| 44 | 0x4e,0x2e,0x42,0xc7,0xbc,0x15,0xb4,0x63, | ||
| 45 | 0x8e,0x1f,0x98,0xb1,0x3b,0x20,0x44,0x28, | ||
| 46 | 0x56,0x32,0xa8,0x03,0xaf,0xa9,0x73,0xeb, | ||
| 47 | 0xde,0x0f,0xf2,0x44,0x87,0x7e,0xa6,0x0a, | ||
| 48 | 0x4c,0xb0,0x43,0x2c,0xe5,0x77,0xc3,0x1b, | ||
| 49 | 0xeb,0x00,0x9c,0x5c,0x2c,0x49,0xaa,0x2e, | ||
| 50 | 0x4e,0xad,0xb2,0x17,0xad,0x8c,0xc0,0x9b }; | ||
| 51 | |||
| 52 | unsigned char app_d1[SHA384_DIGEST_LENGTH] = { | ||
| 53 | 0xcb,0x00,0x75,0x3f,0x45,0xa3,0x5e,0x8b, | ||
| 54 | 0xb5,0xa0,0x3d,0x69,0x9a,0xc6,0x50,0x07, | ||
| 55 | 0x27,0x2c,0x32,0xab,0x0e,0xde,0xd1,0x63, | ||
| 56 | 0x1a,0x8b,0x60,0x5a,0x43,0xff,0x5b,0xed, | ||
| 57 | 0x80,0x86,0x07,0x2b,0xa1,0xe7,0xcc,0x23, | ||
| 58 | 0x58,0xba,0xec,0xa1,0x34,0xc8,0x25,0xa7 }; | ||
| 59 | |||
| 60 | unsigned char app_d2[SHA384_DIGEST_LENGTH] = { | ||
| 61 | 0x09,0x33,0x0c,0x33,0xf7,0x11,0x47,0xe8, | ||
| 62 | 0x3d,0x19,0x2f,0xc7,0x82,0xcd,0x1b,0x47, | ||
| 63 | 0x53,0x11,0x1b,0x17,0x3b,0x3b,0x05,0xd2, | ||
| 64 | 0x2f,0xa0,0x80,0x86,0xe3,0xb0,0xf7,0x12, | ||
| 65 | 0xfc,0xc7,0xc7,0x1a,0x55,0x7e,0x2d,0xb9, | ||
| 66 | 0x66,0xc3,0xe9,0xfa,0x91,0x74,0x60,0x39 }; | ||
| 67 | |||
| 68 | unsigned char app_d3[SHA384_DIGEST_LENGTH] = { | ||
| 69 | 0x9d,0x0e,0x18,0x09,0x71,0x64,0x74,0xcb, | ||
| 70 | 0x08,0x6e,0x83,0x4e,0x31,0x0a,0x4a,0x1c, | ||
| 71 | 0xed,0x14,0x9e,0x9c,0x00,0xf2,0x48,0x52, | ||
| 72 | 0x79,0x72,0xce,0xc5,0x70,0x4c,0x2a,0x5b, | ||
| 73 | 0x07,0xb8,0xb3,0xdc,0x38,0xec,0xc4,0xeb, | ||
| 74 | 0xae,0x97,0xdd,0xd8,0x7f,0x3d,0x89,0x85 }; | ||
| 75 | |||
| 76 | int main (int argc,char **argv) | ||
| 77 | { unsigned char md[SHA512_DIGEST_LENGTH]; | ||
| 78 | int i; | ||
| 79 | EVP_MD_CTX evp; | ||
| 80 | |||
| 81 | #ifdef OPENSSL_IA32_SSE2 | ||
| 82 | /* Alternative to this is to call OpenSSL_add_all_algorithms... | ||
| 83 | * The below code is retained exclusively for debugging purposes. */ | ||
| 84 | { char *env; | ||
| 85 | |||
| 86 | if ((env=getenv("OPENSSL_ia32cap"))) | ||
| 87 | OPENSSL_ia32cap = strtoul (env,NULL,0); | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | fprintf(stdout,"Testing SHA-512 "); | ||
| 92 | |||
| 93 | EVP_Digest ("abc",3,md,NULL,EVP_sha512(),NULL); | ||
| 94 | if (memcmp(md,app_c1,sizeof(app_c1))) | ||
| 95 | { fflush(stdout); | ||
| 96 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 97 | return 1; | ||
| 98 | } | ||
| 99 | else | ||
| 100 | fprintf(stdout,"."); fflush(stdout); | ||
| 101 | |||
| 102 | EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk" | ||
| 103 | "efghijkl""fghijklm""ghijklmn""hijklmno" | ||
| 104 | "ijklmnop""jklmnopq""klmnopqr""lmnopqrs" | ||
| 105 | "mnopqrst""nopqrstu",112,md,NULL,EVP_sha512(),NULL); | ||
| 106 | if (memcmp(md,app_c2,sizeof(app_c2))) | ||
| 107 | { fflush(stdout); | ||
| 108 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 109 | return 1; | ||
| 110 | } | ||
| 111 | else | ||
| 112 | fprintf(stdout,"."); fflush(stdout); | ||
| 113 | |||
| 114 | EVP_MD_CTX_init (&evp); | ||
| 115 | EVP_DigestInit_ex (&evp,EVP_sha512(),NULL); | ||
| 116 | for (i=0;i<1000000;i+=288) | ||
| 117 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 118 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 119 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 120 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 121 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 122 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 123 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 124 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 125 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 126 | (1000000-i)<288?1000000-i:288); | ||
| 127 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 128 | EVP_MD_CTX_cleanup (&evp); | ||
| 129 | |||
| 130 | if (memcmp(md,app_c3,sizeof(app_c3))) | ||
| 131 | { fflush(stdout); | ||
| 132 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 133 | return 1; | ||
| 134 | } | ||
| 135 | else | ||
| 136 | fprintf(stdout,"."); fflush(stdout); | ||
| 137 | |||
| 138 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 139 | |||
| 140 | fprintf(stdout,"Testing SHA-384 "); | ||
| 141 | |||
| 142 | EVP_Digest ("abc",3,md,NULL,EVP_sha384(),NULL); | ||
| 143 | if (memcmp(md,app_d1,sizeof(app_d1))) | ||
| 144 | { fflush(stdout); | ||
| 145 | fprintf(stderr,"\nTEST 1 of 3 failed.\n"); | ||
| 146 | return 1; | ||
| 147 | } | ||
| 148 | else | ||
| 149 | fprintf(stdout,"."); fflush(stdout); | ||
| 150 | |||
| 151 | EVP_Digest ("abcdefgh""bcdefghi""cdefghij""defghijk" | ||
| 152 | "efghijkl""fghijklm""ghijklmn""hijklmno" | ||
| 153 | "ijklmnop""jklmnopq""klmnopqr""lmnopqrs" | ||
| 154 | "mnopqrst""nopqrstu",112,md,NULL,EVP_sha384(),NULL); | ||
| 155 | if (memcmp(md,app_d2,sizeof(app_d2))) | ||
| 156 | { fflush(stdout); | ||
| 157 | fprintf(stderr,"\nTEST 2 of 3 failed.\n"); | ||
| 158 | return 1; | ||
| 159 | } | ||
| 160 | else | ||
| 161 | fprintf(stdout,"."); fflush(stdout); | ||
| 162 | |||
| 163 | EVP_MD_CTX_init (&evp); | ||
| 164 | EVP_DigestInit_ex (&evp,EVP_sha384(),NULL); | ||
| 165 | for (i=0;i<1000000;i+=64) | ||
| 166 | EVP_DigestUpdate (&evp, "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa" | ||
| 167 | "aaaaaaaa""aaaaaaaa""aaaaaaaa""aaaaaaaa", | ||
| 168 | (1000000-i)<64?1000000-i:64); | ||
| 169 | EVP_DigestFinal_ex (&evp,md,NULL); | ||
| 170 | EVP_MD_CTX_cleanup (&evp); | ||
| 171 | |||
| 172 | if (memcmp(md,app_d3,sizeof(app_d3))) | ||
| 173 | { fflush(stdout); | ||
| 174 | fprintf(stderr,"\nTEST 3 of 3 failed.\n"); | ||
| 175 | return 1; | ||
| 176 | } | ||
| 177 | else | ||
| 178 | fprintf(stdout,"."); fflush(stdout); | ||
| 179 | |||
| 180 | fprintf(stdout," passed.\n"); fflush(stdout); | ||
| 181 | |||
| 182 | return 0; | ||
| 183 | } | ||
| 184 | #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..70eb56032c --- /dev/null +++ b/src/lib/libcrypto/sha/sha_dgst.c | |||
| @@ -0,0 +1,74 @@ | |||
| 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 | #include <openssl/opensslconf.h> | ||
| 60 | #if !defined(OPENSSL_NO_SHA0) && !defined(OPENSSL_NO_SHA) | ||
| 61 | |||
| 62 | #undef SHA_1 | ||
| 63 | #define SHA_0 | ||
| 64 | |||
| 65 | #include <openssl/opensslv.h> | ||
| 66 | |||
| 67 | const char SHA_version[]="SHA" OPENSSL_VERSION_PTEXT; | ||
| 68 | |||
| 69 | /* The implementation is in ../md32_common.h */ | ||
| 70 | |||
| 71 | #include "sha_locl.h" | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
diff --git a/src/lib/libcrypto/sha/sha_locl.h b/src/lib/libcrypto/sha/sha_locl.h index 7a0c3ca8d8..672c26eee1 100644 --- a/src/lib/libcrypto/sha/sha_locl.h +++ b/src/lib/libcrypto/sha/sha_locl.h | |||
| @@ -122,11 +122,7 @@ void sha1_block_data_order (SHA_CTX *c, const void *p,size_t num); | |||
| 122 | #define INIT_DATA_h3 0x10325476UL | 122 | #define INIT_DATA_h3 0x10325476UL |
| 123 | #define INIT_DATA_h4 0xc3d2e1f0UL | 123 | #define INIT_DATA_h4 0xc3d2e1f0UL |
| 124 | 124 | ||
| 125 | #ifdef SHA_0 | 125 | int HASH_INIT (SHA_CTX *c) |
| 126 | fips_md_init(SHA) | ||
| 127 | #else | ||
| 128 | fips_md_init_ctx(SHA1, SHA) | ||
| 129 | #endif | ||
| 130 | { | 126 | { |
| 131 | memset (c,0,sizeof(*c)); | 127 | memset (c,0,sizeof(*c)); |
| 132 | c->h0=INIT_DATA_h0; | 128 | c->h0=INIT_DATA_h0; |
diff --git a/src/lib/libcrypto/sha/sha_one.c b/src/lib/libcrypto/sha/sha_one.c new file mode 100644 index 0000000000..3bae623ce8 --- /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, size_t 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..27614646d1 --- /dev/null +++ b/src/lib/libcrypto/sha/shatest.c | |||
| @@ -0,0 +1,178 @@ | |||
| 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 | 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=test; | ||
| 122 | R=ret; | ||
| 123 | i=1; | ||
| 124 | while (*P != NULL) | ||
| 125 | { | ||
| 126 | EVP_Digest(*P,strlen(*P),md,NULL,EVP_sha(), NULL); | ||
| 127 | p=pt(md); | ||
| 128 | if (strcmp(p,*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 | |||
| 161 | #ifdef OPENSSL_SYS_NETWARE | ||
| 162 | if (err) printf("ERROR: %d\n", err); | ||
| 163 | #endif | ||
| 164 | EVP_MD_CTX_cleanup(&c); | ||
| 165 | EXIT(err); | ||
| 166 | return(0); | ||
| 167 | } | ||
| 168 | |||
| 169 | static char *pt(unsigned char *md) | ||
| 170 | { | ||
| 171 | int i; | ||
| 172 | static char buf[80]; | ||
| 173 | |||
| 174 | for (i=0; i<SHA_DIGEST_LENGTH; i++) | ||
| 175 | sprintf(&(buf[i*2]),"%02x",md[i]); | ||
| 176 | return(buf); | ||
| 177 | } | ||
| 178 | #endif | ||
