diff options
Diffstat (limited to 'src/lib/libcrypto/md5')
| -rw-r--r-- | src/lib/libcrypto/md5/Makefile.ssl | 135 | ||||
| -rw-r--r-- | src/lib/libcrypto/md5/asm/md5-586.pl | 306 | ||||
| -rw-r--r-- | src/lib/libcrypto/md5/md5.h | 114 | ||||
| -rw-r--r-- | src/lib/libcrypto/md5/md5_dgst.c | 320 | ||||
| -rw-r--r-- | src/lib/libcrypto/md5/md5_locl.h | 172 | ||||
| -rw-r--r-- | src/lib/libcrypto/md5/md5_one.c | 95 |
6 files changed, 1142 insertions, 0 deletions
diff --git a/src/lib/libcrypto/md5/Makefile.ssl b/src/lib/libcrypto/md5/Makefile.ssl new file mode 100644 index 0000000000..a7a92e9588 --- /dev/null +++ b/src/lib/libcrypto/md5/Makefile.ssl | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | # | ||
| 2 | # SSLeay/crypto/md5/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= md5 | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | CPP= $(CC) -E | ||
| 9 | INCLUDES= | ||
| 10 | CFLAG=-g | ||
| 11 | INSTALL_PREFIX= | ||
| 12 | OPENSSLDIR= /usr/local/ssl | ||
| 13 | INSTALLTOP=/usr/local/ssl | ||
| 14 | MAKE= make -f Makefile.ssl | ||
| 15 | MAKEDEPPROG= makedepend | ||
| 16 | MAKEDEPEND= $(TOP)/util/domd $(TOP) -MD $(MAKEDEPPROG) | ||
| 17 | MAKEFILE= Makefile.ssl | ||
| 18 | AR= ar r | ||
| 19 | |||
| 20 | MD5_ASM_OBJ= | ||
| 21 | |||
| 22 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 23 | |||
| 24 | # We let the C compiler driver to take care of .s files. This is done in | ||
| 25 | # order to be excused from maintaining a separate set of architecture | ||
| 26 | # dependent assembler flags. E.g. if you throw -mcpu=ultrasparc at SPARC | ||
| 27 | # gcc, then the driver will automatically translate it to -xarch=v8plus | ||
| 28 | # and pass it down to assembler. | ||
| 29 | AS=$(CC) -c | ||
| 30 | ASFLAGS=$(CFLAGS) | ||
| 31 | |||
| 32 | GENERAL=Makefile | ||
| 33 | TEST=md5test.c | ||
| 34 | APPS= | ||
| 35 | |||
| 36 | LIB=$(TOP)/libcrypto.a | ||
| 37 | LIBSRC=md5_dgst.c md5_one.c | ||
| 38 | LIBOBJ=md5_dgst.o md5_one.o $(MD5_ASM_OBJ) | ||
| 39 | |||
| 40 | SRC= $(LIBSRC) | ||
| 41 | |||
| 42 | EXHEADER= md5.h | ||
| 43 | HEADER= md5_locl.h $(EXHEADER) | ||
| 44 | |||
| 45 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 46 | |||
| 47 | top: | ||
| 48 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 49 | |||
| 50 | all: lib | ||
| 51 | |||
| 52 | lib: $(LIBOBJ) | ||
| 53 | $(AR) $(LIB) $(LIBOBJ) | ||
| 54 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 55 | @touch lib | ||
| 56 | |||
| 57 | # elf | ||
| 58 | asm/mx86-elf.o: asm/mx86unix.cpp | ||
| 59 | $(CPP) -DELF -x c asm/mx86unix.cpp | as -o asm/mx86-elf.o | ||
| 60 | |||
| 61 | # solaris | ||
| 62 | asm/mx86-sol.o: asm/mx86unix.cpp | ||
| 63 | $(CC) -E -DSOL asm/mx86unix.cpp | sed 's/^#.*//' > asm/mx86-sol.s | ||
| 64 | as -o asm/mx86-sol.o asm/mx86-sol.s | ||
| 65 | rm -f asm/mx86-sol.s | ||
| 66 | |||
| 67 | # a.out | ||
| 68 | asm/mx86-out.o: asm/mx86unix.cpp | ||
| 69 | $(CPP) -DOUT asm/mx86unix.cpp | as -o asm/mx86-out.o | ||
| 70 | |||
| 71 | # bsdi | ||
| 72 | asm/mx86bsdi.o: asm/mx86unix.cpp | ||
| 73 | $(CPP) -DBSDI asm/mx86unix.cpp | sed 's/ :/:/' | as -o asm/mx86bsdi.o | ||
| 74 | |||
| 75 | asm/mx86unix.cpp: asm/md5-586.pl ../perlasm/x86asm.pl | ||
| 76 | (cd asm; $(PERL) md5-586.pl cpp >mx86unix.cpp) | ||
| 77 | |||
| 78 | asm/md5-sparcv8plus.o: asm/md5-sparcv9.S | ||
| 79 | $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \ | ||
| 80 | -o asm/md5-sparcv8plus.o asm/md5-sparcv9.S | ||
| 81 | |||
| 82 | # Old GNU assembler doesn't understand V9 instructions, so we | ||
| 83 | # hire /usr/ccs/bin/as to do the job. Note that option is called | ||
| 84 | # *-gcc27, but even gcc 2>=8 users may experience similar problem | ||
| 85 | # if they didn't bother to upgrade GNU assembler. Such users should | ||
| 86 | # not choose this option, but be adviced to *remove* GNU assembler | ||
| 87 | # or upgrade it. | ||
| 88 | asm/md5-sparcv8plus-gcc27.o: asm/md5-sparcv9.S | ||
| 89 | $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -E asm/md5-sparcv9.S | \ | ||
| 90 | /usr/ccs/bin/as -xarch=v8plus - -o asm/md5-sparcv8plus-gcc27.o | ||
| 91 | |||
| 92 | asm/md5-sparcv9.o: asm/md5-sparcv9.S | ||
| 93 | $(CC) $(ASFLAGS) -DMD5_BLOCK_DATA_ORDER -c \ | ||
| 94 | -o asm/md5-sparcv9.o asm/md5-sparcv9.S | ||
| 95 | |||
| 96 | files: | ||
| 97 | $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO | ||
| 98 | |||
| 99 | links: | ||
| 100 | @sh $(TOP)/util/point.sh Makefile.ssl Makefile | ||
| 101 | @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) | ||
| 102 | @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) | ||
| 103 | @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) | ||
| 104 | |||
| 105 | install: | ||
| 106 | @for i in $(EXHEADER) ; \ | ||
| 107 | do \ | ||
| 108 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 109 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 110 | done; | ||
| 111 | |||
| 112 | tags: | ||
| 113 | ctags $(SRC) | ||
| 114 | |||
| 115 | tests: | ||
| 116 | |||
| 117 | lint: | ||
| 118 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 119 | |||
| 120 | depend: | ||
| 121 | $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) | ||
| 122 | |||
| 123 | dclean: | ||
| 124 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 125 | mv -f Makefile.new $(MAKEFILE) | ||
| 126 | |||
| 127 | clean: | ||
| 128 | rm -f asm/mx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff | ||
| 129 | |||
| 130 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 131 | |||
| 132 | md5_dgst.o: ../../include/openssl/md5.h ../../include/openssl/opensslconf.h | ||
| 133 | md5_dgst.o: ../../include/openssl/opensslv.h ../md32_common.h md5_dgst.c | ||
| 134 | md5_dgst.o: md5_locl.h | ||
| 135 | md5_one.o: ../../include/openssl/md5.h md5_one.c | ||
diff --git a/src/lib/libcrypto/md5/asm/md5-586.pl b/src/lib/libcrypto/md5/asm/md5-586.pl new file mode 100644 index 0000000000..5fc6a205ce --- /dev/null +++ b/src/lib/libcrypto/md5/asm/md5-586.pl | |||
| @@ -0,0 +1,306 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | # Normal is the | ||
| 4 | # md5_block_x86(MD5_CTX *c, ULONG *X); | ||
| 5 | # version, non-normal is the | ||
| 6 | # md5_block_x86(MD5_CTX *c, ULONG *X,int blocks); | ||
| 7 | |||
| 8 | $normal=0; | ||
| 9 | |||
| 10 | push(@INC,"perlasm","../../perlasm"); | ||
| 11 | require "x86asm.pl"; | ||
| 12 | |||
| 13 | &asm_init($ARGV[0],$0); | ||
| 14 | |||
| 15 | $A="eax"; | ||
| 16 | $B="ebx"; | ||
| 17 | $C="ecx"; | ||
| 18 | $D="edx"; | ||
| 19 | $tmp1="edi"; | ||
| 20 | $tmp2="ebp"; | ||
| 21 | $X="esi"; | ||
| 22 | |||
| 23 | # What we need to load into $tmp for the next round | ||
| 24 | %Ltmp1=("R0",&Np($C), "R1",&Np($C), "R2",&Np($C), "R3",&Np($D)); | ||
| 25 | @xo=( | ||
| 26 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, # R0 | ||
| 27 | 1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12, # R1 | ||
| 28 | 5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2, # R2 | ||
| 29 | 0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9, # R3 | ||
| 30 | ); | ||
| 31 | |||
| 32 | &md5_block("md5_block_asm_host_order"); | ||
| 33 | &asm_finish(); | ||
| 34 | |||
| 35 | sub Np | ||
| 36 | { | ||
| 37 | local($p)=@_; | ||
| 38 | local(%n)=($A,$D,$B,$A,$C,$B,$D,$C); | ||
| 39 | return($n{$p}); | ||
| 40 | } | ||
| 41 | |||
| 42 | sub R0 | ||
| 43 | { | ||
| 44 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 45 | |||
| 46 | &mov($tmp1,$C) if $pos < 0; | ||
| 47 | &mov($tmp2,&DWP($xo[$ki]*4,$K,"",0)) if $pos < 0; # very first one | ||
| 48 | |||
| 49 | # body proper | ||
| 50 | |||
| 51 | &comment("R0 $ki"); | ||
| 52 | &xor($tmp1,$d); # F function - part 2 | ||
| 53 | |||
| 54 | &and($tmp1,$b); # F function - part 3 | ||
| 55 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 56 | |||
| 57 | &xor($tmp1,$d); # F function - part 4 | ||
| 58 | |||
| 59 | &add($a,$tmp1); | ||
| 60 | &mov($tmp1,&Np($c)) if $pos < 1; # next tmp1 for R0 | ||
| 61 | &mov($tmp1,&Np($c)) if $pos == 1; # next tmp1 for R1 | ||
| 62 | |||
| 63 | &rotl($a,$s); | ||
| 64 | |||
| 65 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
| 66 | |||
| 67 | &add($a,$b); | ||
| 68 | } | ||
| 69 | |||
| 70 | sub R1 | ||
| 71 | { | ||
| 72 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 73 | |||
| 74 | &comment("R1 $ki"); | ||
| 75 | |||
| 76 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 77 | |||
| 78 | &xor($tmp1,$b); # G function - part 2 | ||
| 79 | &and($tmp1,$d); # G function - part 3 | ||
| 80 | |||
| 81 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
| 82 | &xor($tmp1,$c); # G function - part 4 | ||
| 83 | |||
| 84 | &add($a,$tmp1); | ||
| 85 | &mov($tmp1,&Np($c)) if $pos < 1; # G function - part 1 | ||
| 86 | &mov($tmp1,&Np($c)) if $pos == 1; # G function - part 1 | ||
| 87 | |||
| 88 | &rotl($a,$s); | ||
| 89 | |||
| 90 | &add($a,$b); | ||
| 91 | } | ||
| 92 | |||
| 93 | sub R2 | ||
| 94 | { | ||
| 95 | local($n,$pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 96 | # This one is different, only 3 logical operations | ||
| 97 | |||
| 98 | if (($n & 1) == 0) | ||
| 99 | { | ||
| 100 | &comment("R2 $ki"); | ||
| 101 | # make sure to do 'D' first, not 'B', else we clash with | ||
| 102 | # the last add from the previous round. | ||
| 103 | |||
| 104 | &xor($tmp1,$d); # H function - part 2 | ||
| 105 | |||
| 106 | &xor($tmp1,$b); # H function - part 3 | ||
| 107 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 108 | |||
| 109 | &add($a,$tmp1); | ||
| 110 | |||
| 111 | &rotl($a,$s); | ||
| 112 | |||
| 113 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)); | ||
| 114 | &mov($tmp1,&Np($c)); | ||
| 115 | } | ||
| 116 | else | ||
| 117 | { | ||
| 118 | &comment("R2 $ki"); | ||
| 119 | # make sure to do 'D' first, not 'B', else we clash with | ||
| 120 | # the last add from the previous round. | ||
| 121 | |||
| 122 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 123 | |||
| 124 | &add($b,$c); # MOVED FORWARD | ||
| 125 | &xor($tmp1,$d); # H function - part 2 | ||
| 126 | |||
| 127 | &xor($tmp1,$b); # H function - part 3 | ||
| 128 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if ($pos != 2); | ||
| 129 | |||
| 130 | &add($a,$tmp1); | ||
| 131 | &mov($tmp1,&Np($c)) if $pos < 1; # H function - part 1 | ||
| 132 | &mov($tmp1,-1) if $pos == 1; # I function - part 1 | ||
| 133 | |||
| 134 | &rotl($a,$s); | ||
| 135 | |||
| 136 | &add($a,$b); | ||
| 137 | } | ||
| 138 | } | ||
| 139 | |||
| 140 | sub R3 | ||
| 141 | { | ||
| 142 | local($pos,$a,$b,$c,$d,$K,$ki,$s,$t)=@_; | ||
| 143 | |||
| 144 | &comment("R3 $ki"); | ||
| 145 | |||
| 146 | # ¬($tmp1) | ||
| 147 | &xor($tmp1,$d) if $pos < 0; # I function - part 2 | ||
| 148 | |||
| 149 | &or($tmp1,$b); # I function - part 3 | ||
| 150 | &lea($a,&DWP($t,$a,$tmp2,1)); | ||
| 151 | |||
| 152 | &xor($tmp1,$c); # I function - part 4 | ||
| 153 | &mov($tmp2,&DWP($xo[$ki+1]*4,$K,"",0)) if $pos != 2; # load X/k value | ||
| 154 | &mov($tmp2,&wparam(0)) if $pos == 2; | ||
| 155 | |||
| 156 | &add($a,$tmp1); | ||
| 157 | &mov($tmp1,-1) if $pos < 1; # H function - part 1 | ||
| 158 | &add($K,64) if $pos >=1 && !$normal; | ||
| 159 | |||
| 160 | &rotl($a,$s); | ||
| 161 | |||
| 162 | &xor($tmp1,&Np($d)) if $pos <= 0; # I function - part = first time | ||
| 163 | &mov($tmp1,&DWP( 0,$tmp2,"",0)) if $pos > 0; | ||
| 164 | &add($a,$b); | ||
| 165 | } | ||
| 166 | |||
| 167 | |||
| 168 | sub md5_block | ||
| 169 | { | ||
| 170 | local($name)=@_; | ||
| 171 | |||
| 172 | &function_begin_B($name,"",3); | ||
| 173 | |||
| 174 | # parameter 1 is the MD5_CTX structure. | ||
| 175 | # A 0 | ||
| 176 | # B 4 | ||
| 177 | # C 8 | ||
| 178 | # D 12 | ||
| 179 | |||
| 180 | &push("esi"); | ||
| 181 | &push("edi"); | ||
| 182 | &mov($tmp1, &wparam(0)); # edi | ||
| 183 | &mov($X, &wparam(1)); # esi | ||
| 184 | &mov($C, &wparam(2)); | ||
| 185 | &push("ebp"); | ||
| 186 | &shl($C, 6); | ||
| 187 | &push("ebx"); | ||
| 188 | &add($C, $X); # offset we end at | ||
| 189 | &sub($C, 64); | ||
| 190 | &mov($A, &DWP( 0,$tmp1,"",0)); | ||
| 191 | &push($C); # Put on the TOS | ||
| 192 | &mov($B, &DWP( 4,$tmp1,"",0)); | ||
| 193 | &mov($C, &DWP( 8,$tmp1,"",0)); | ||
| 194 | &mov($D, &DWP(12,$tmp1,"",0)); | ||
| 195 | |||
| 196 | &set_label("start") unless $normal; | ||
| 197 | &comment(""); | ||
| 198 | &comment("R0 section"); | ||
| 199 | |||
| 200 | &R0(-2,$A,$B,$C,$D,$X, 0, 7,0xd76aa478); | ||
| 201 | &R0( 0,$D,$A,$B,$C,$X, 1,12,0xe8c7b756); | ||
| 202 | &R0( 0,$C,$D,$A,$B,$X, 2,17,0x242070db); | ||
| 203 | &R0( 0,$B,$C,$D,$A,$X, 3,22,0xc1bdceee); | ||
| 204 | &R0( 0,$A,$B,$C,$D,$X, 4, 7,0xf57c0faf); | ||
| 205 | &R0( 0,$D,$A,$B,$C,$X, 5,12,0x4787c62a); | ||
| 206 | &R0( 0,$C,$D,$A,$B,$X, 6,17,0xa8304613); | ||
| 207 | &R0( 0,$B,$C,$D,$A,$X, 7,22,0xfd469501); | ||
| 208 | &R0( 0,$A,$B,$C,$D,$X, 8, 7,0x698098d8); | ||
| 209 | &R0( 0,$D,$A,$B,$C,$X, 9,12,0x8b44f7af); | ||
| 210 | &R0( 0,$C,$D,$A,$B,$X,10,17,0xffff5bb1); | ||
| 211 | &R0( 0,$B,$C,$D,$A,$X,11,22,0x895cd7be); | ||
| 212 | &R0( 0,$A,$B,$C,$D,$X,12, 7,0x6b901122); | ||
| 213 | &R0( 0,$D,$A,$B,$C,$X,13,12,0xfd987193); | ||
| 214 | &R0( 0,$C,$D,$A,$B,$X,14,17,0xa679438e); | ||
| 215 | &R0( 1,$B,$C,$D,$A,$X,15,22,0x49b40821); | ||
| 216 | |||
| 217 | &comment(""); | ||
| 218 | &comment("R1 section"); | ||
| 219 | &R1(-1,$A,$B,$C,$D,$X,16, 5,0xf61e2562); | ||
| 220 | &R1( 0,$D,$A,$B,$C,$X,17, 9,0xc040b340); | ||
| 221 | &R1( 0,$C,$D,$A,$B,$X,18,14,0x265e5a51); | ||
| 222 | &R1( 0,$B,$C,$D,$A,$X,19,20,0xe9b6c7aa); | ||
| 223 | &R1( 0,$A,$B,$C,$D,$X,20, 5,0xd62f105d); | ||
| 224 | &R1( 0,$D,$A,$B,$C,$X,21, 9,0x02441453); | ||
| 225 | &R1( 0,$C,$D,$A,$B,$X,22,14,0xd8a1e681); | ||
| 226 | &R1( 0,$B,$C,$D,$A,$X,23,20,0xe7d3fbc8); | ||
| 227 | &R1( 0,$A,$B,$C,$D,$X,24, 5,0x21e1cde6); | ||
| 228 | &R1( 0,$D,$A,$B,$C,$X,25, 9,0xc33707d6); | ||
| 229 | &R1( 0,$C,$D,$A,$B,$X,26,14,0xf4d50d87); | ||
| 230 | &R1( 0,$B,$C,$D,$A,$X,27,20,0x455a14ed); | ||
| 231 | &R1( 0,$A,$B,$C,$D,$X,28, 5,0xa9e3e905); | ||
| 232 | &R1( 0,$D,$A,$B,$C,$X,29, 9,0xfcefa3f8); | ||
| 233 | &R1( 0,$C,$D,$A,$B,$X,30,14,0x676f02d9); | ||
| 234 | &R1( 1,$B,$C,$D,$A,$X,31,20,0x8d2a4c8a); | ||
| 235 | |||
| 236 | &comment(""); | ||
| 237 | &comment("R2 section"); | ||
| 238 | &R2( 0,-1,$A,$B,$C,$D,$X,32, 4,0xfffa3942); | ||
| 239 | &R2( 1, 0,$D,$A,$B,$C,$X,33,11,0x8771f681); | ||
| 240 | &R2( 2, 0,$C,$D,$A,$B,$X,34,16,0x6d9d6122); | ||
| 241 | &R2( 3, 0,$B,$C,$D,$A,$X,35,23,0xfde5380c); | ||
| 242 | &R2( 4, 0,$A,$B,$C,$D,$X,36, 4,0xa4beea44); | ||
| 243 | &R2( 5, 0,$D,$A,$B,$C,$X,37,11,0x4bdecfa9); | ||
| 244 | &R2( 6, 0,$C,$D,$A,$B,$X,38,16,0xf6bb4b60); | ||
| 245 | &R2( 7, 0,$B,$C,$D,$A,$X,39,23,0xbebfbc70); | ||
| 246 | &R2( 8, 0,$A,$B,$C,$D,$X,40, 4,0x289b7ec6); | ||
| 247 | &R2( 9, 0,$D,$A,$B,$C,$X,41,11,0xeaa127fa); | ||
| 248 | &R2(10, 0,$C,$D,$A,$B,$X,42,16,0xd4ef3085); | ||
| 249 | &R2(11, 0,$B,$C,$D,$A,$X,43,23,0x04881d05); | ||
| 250 | &R2(12, 0,$A,$B,$C,$D,$X,44, 4,0xd9d4d039); | ||
| 251 | &R2(13, 0,$D,$A,$B,$C,$X,45,11,0xe6db99e5); | ||
| 252 | &R2(14, 0,$C,$D,$A,$B,$X,46,16,0x1fa27cf8); | ||
| 253 | &R2(15, 1,$B,$C,$D,$A,$X,47,23,0xc4ac5665); | ||
| 254 | |||
| 255 | &comment(""); | ||
| 256 | &comment("R3 section"); | ||
| 257 | &R3(-1,$A,$B,$C,$D,$X,48, 6,0xf4292244); | ||
| 258 | &R3( 0,$D,$A,$B,$C,$X,49,10,0x432aff97); | ||
| 259 | &R3( 0,$C,$D,$A,$B,$X,50,15,0xab9423a7); | ||
| 260 | &R3( 0,$B,$C,$D,$A,$X,51,21,0xfc93a039); | ||
| 261 | &R3( 0,$A,$B,$C,$D,$X,52, 6,0x655b59c3); | ||
| 262 | &R3( 0,$D,$A,$B,$C,$X,53,10,0x8f0ccc92); | ||
| 263 | &R3( 0,$C,$D,$A,$B,$X,54,15,0xffeff47d); | ||
| 264 | &R3( 0,$B,$C,$D,$A,$X,55,21,0x85845dd1); | ||
| 265 | &R3( 0,$A,$B,$C,$D,$X,56, 6,0x6fa87e4f); | ||
| 266 | &R3( 0,$D,$A,$B,$C,$X,57,10,0xfe2ce6e0); | ||
| 267 | &R3( 0,$C,$D,$A,$B,$X,58,15,0xa3014314); | ||
| 268 | &R3( 0,$B,$C,$D,$A,$X,59,21,0x4e0811a1); | ||
| 269 | &R3( 0,$A,$B,$C,$D,$X,60, 6,0xf7537e82); | ||
| 270 | &R3( 0,$D,$A,$B,$C,$X,61,10,0xbd3af235); | ||
| 271 | &R3( 0,$C,$D,$A,$B,$X,62,15,0x2ad7d2bb); | ||
| 272 | &R3( 2,$B,$C,$D,$A,$X,63,21,0xeb86d391); | ||
| 273 | |||
| 274 | # &mov($tmp2,&wparam(0)); # done in the last R3 | ||
| 275 | # &mov($tmp1, &DWP( 0,$tmp2,"",0)); # done is the last R3 | ||
| 276 | |||
| 277 | &add($A,$tmp1); | ||
| 278 | &mov($tmp1, &DWP( 4,$tmp2,"",0)); | ||
| 279 | |||
| 280 | &add($B,$tmp1); | ||
| 281 | &mov($tmp1, &DWP( 8,$tmp2,"",0)); | ||
| 282 | |||
| 283 | &add($C,$tmp1); | ||
| 284 | &mov($tmp1, &DWP(12,$tmp2,"",0)); | ||
| 285 | |||
| 286 | &add($D,$tmp1); | ||
| 287 | &mov(&DWP( 0,$tmp2,"",0),$A); | ||
| 288 | |||
| 289 | &mov(&DWP( 4,$tmp2,"",0),$B); | ||
| 290 | &mov($tmp1,&swtmp(0)) unless $normal; | ||
| 291 | |||
| 292 | &mov(&DWP( 8,$tmp2,"",0),$C); | ||
| 293 | &mov(&DWP(12,$tmp2,"",0),$D); | ||
| 294 | |||
| 295 | &cmp($tmp1,$X) unless $normal; # check count | ||
| 296 | &jge(&label("start")) unless $normal; | ||
| 297 | |||
| 298 | &pop("eax"); # pop the temp variable off the stack | ||
| 299 | &pop("ebx"); | ||
| 300 | &pop("ebp"); | ||
| 301 | &pop("edi"); | ||
| 302 | &pop("esi"); | ||
| 303 | &ret(); | ||
| 304 | &function_end_B($name); | ||
| 305 | } | ||
| 306 | |||
diff --git a/src/lib/libcrypto/md5/md5.h b/src/lib/libcrypto/md5/md5.h new file mode 100644 index 0000000000..52cb753e6a --- /dev/null +++ b/src/lib/libcrypto/md5/md5.h | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | /* crypto/md5/md5.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #ifndef HEADER_MD5_H | ||
| 60 | #define HEADER_MD5_H | ||
| 61 | |||
| 62 | #ifdef __cplusplus | ||
| 63 | extern "C" { | ||
| 64 | #endif | ||
| 65 | |||
| 66 | #ifdef OPENSSL_NO_MD5 | ||
| 67 | #error MD5 is disabled. | ||
| 68 | #endif | ||
| 69 | |||
| 70 | /* | ||
| 71 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 72 | * ! MD5_LONG has to be at least 32 bits wide. If it's wider, then ! | ||
| 73 | * ! MD5_LONG_LOG2 has to be defined along. ! | ||
| 74 | * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
| 75 | */ | ||
| 76 | |||
| 77 | #if defined(OPENSSL_SYS_WIN16) || defined(__LP32__) | ||
| 78 | #define MD5_LONG unsigned long | ||
| 79 | #elif defined(OENSSL_SYS_CRAY) || defined(__ILP64__) | ||
| 80 | #define MD5_LONG unsigned long | ||
| 81 | #define MD5_LONG_LOG2 3 | ||
| 82 | /* | ||
| 83 | * _CRAY note. I could declare short, but I have no idea what impact | ||
| 84 | * does it have on performance on none-T3E machines. I could declare | ||
| 85 | * int, but at least on C90 sizeof(int) can be chosen at compile time. | ||
| 86 | * So I've chosen long... | ||
| 87 | * <appro@fy.chalmers.se> | ||
| 88 | */ | ||
| 89 | #else | ||
| 90 | #define MD5_LONG unsigned int | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #define MD5_CBLOCK 64 | ||
| 94 | #define MD5_LBLOCK (MD5_CBLOCK/4) | ||
| 95 | #define MD5_DIGEST_LENGTH 16 | ||
| 96 | |||
| 97 | typedef struct MD5state_st | ||
| 98 | { | ||
| 99 | MD5_LONG A,B,C,D; | ||
| 100 | MD5_LONG Nl,Nh; | ||
| 101 | MD5_LONG data[MD5_LBLOCK]; | ||
| 102 | int num; | ||
| 103 | } MD5_CTX; | ||
| 104 | |||
| 105 | int MD5_Init(MD5_CTX *c); | ||
| 106 | int MD5_Update(MD5_CTX *c, const void *data, unsigned long len); | ||
| 107 | int MD5_Final(unsigned char *md, MD5_CTX *c); | ||
| 108 | unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md); | ||
| 109 | void MD5_Transform(MD5_CTX *c, const unsigned char *b); | ||
| 110 | #ifdef __cplusplus | ||
| 111 | } | ||
| 112 | #endif | ||
| 113 | |||
| 114 | #endif | ||
diff --git a/src/lib/libcrypto/md5/md5_dgst.c b/src/lib/libcrypto/md5/md5_dgst.c new file mode 100644 index 0000000000..c38a3f021e --- /dev/null +++ b/src/lib/libcrypto/md5/md5_dgst.c | |||
| @@ -0,0 +1,320 @@ | |||
| 1 | /* crypto/md5/md5_dgst.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 "md5_locl.h" | ||
| 61 | #include <openssl/opensslv.h> | ||
| 62 | |||
| 63 | const char *MD5_version="MD5" OPENSSL_VERSION_PTEXT; | ||
| 64 | |||
| 65 | /* Implemented from RFC1321 The MD5 Message-Digest Algorithm | ||
| 66 | */ | ||
| 67 | |||
| 68 | #define INIT_DATA_A (unsigned long)0x67452301L | ||
| 69 | #define INIT_DATA_B (unsigned long)0xefcdab89L | ||
| 70 | #define INIT_DATA_C (unsigned long)0x98badcfeL | ||
| 71 | #define INIT_DATA_D (unsigned long)0x10325476L | ||
| 72 | |||
| 73 | int MD5_Init(MD5_CTX *c) | ||
| 74 | { | ||
| 75 | c->A=INIT_DATA_A; | ||
| 76 | c->B=INIT_DATA_B; | ||
| 77 | c->C=INIT_DATA_C; | ||
| 78 | c->D=INIT_DATA_D; | ||
| 79 | c->Nl=0; | ||
| 80 | c->Nh=0; | ||
| 81 | c->num=0; | ||
| 82 | return 1; | ||
| 83 | } | ||
| 84 | |||
| 85 | #ifndef md5_block_host_order | ||
| 86 | void md5_block_host_order (MD5_CTX *c, const void *data, int num) | ||
| 87 | { | ||
| 88 | const MD5_LONG *X=data; | ||
| 89 | register unsigned long A,B,C,D; | ||
| 90 | /* | ||
| 91 | * In case you wonder why A-D are declared as long and not | ||
| 92 | * as MD5_LONG. Doing so results in slight performance | ||
| 93 | * boost on LP64 architectures. The catch is we don't | ||
| 94 | * really care if 32 MSBs of a 64-bit register get polluted | ||
| 95 | * with eventual overflows as we *save* only 32 LSBs in | ||
| 96 | * *either* case. Now declaring 'em long excuses the compiler | ||
| 97 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
| 98 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
| 99 | * Well, to be honest it should say that this *prevents* | ||
| 100 | * performance degradation. | ||
| 101 | * | ||
| 102 | * <appro@fy.chalmers.se> | ||
| 103 | */ | ||
| 104 | |||
| 105 | A=c->A; | ||
| 106 | B=c->B; | ||
| 107 | C=c->C; | ||
| 108 | D=c->D; | ||
| 109 | |||
| 110 | for (;num--;X+=HASH_LBLOCK) | ||
| 111 | { | ||
| 112 | /* Round 0 */ | ||
| 113 | R0(A,B,C,D,X[ 0], 7,0xd76aa478L); | ||
| 114 | R0(D,A,B,C,X[ 1],12,0xe8c7b756L); | ||
| 115 | R0(C,D,A,B,X[ 2],17,0x242070dbL); | ||
| 116 | R0(B,C,D,A,X[ 3],22,0xc1bdceeeL); | ||
| 117 | R0(A,B,C,D,X[ 4], 7,0xf57c0fafL); | ||
| 118 | R0(D,A,B,C,X[ 5],12,0x4787c62aL); | ||
| 119 | R0(C,D,A,B,X[ 6],17,0xa8304613L); | ||
| 120 | R0(B,C,D,A,X[ 7],22,0xfd469501L); | ||
| 121 | R0(A,B,C,D,X[ 8], 7,0x698098d8L); | ||
| 122 | R0(D,A,B,C,X[ 9],12,0x8b44f7afL); | ||
| 123 | R0(C,D,A,B,X[10],17,0xffff5bb1L); | ||
| 124 | R0(B,C,D,A,X[11],22,0x895cd7beL); | ||
| 125 | R0(A,B,C,D,X[12], 7,0x6b901122L); | ||
| 126 | R0(D,A,B,C,X[13],12,0xfd987193L); | ||
| 127 | R0(C,D,A,B,X[14],17,0xa679438eL); | ||
| 128 | R0(B,C,D,A,X[15],22,0x49b40821L); | ||
| 129 | /* Round 1 */ | ||
| 130 | R1(A,B,C,D,X[ 1], 5,0xf61e2562L); | ||
| 131 | R1(D,A,B,C,X[ 6], 9,0xc040b340L); | ||
| 132 | R1(C,D,A,B,X[11],14,0x265e5a51L); | ||
| 133 | R1(B,C,D,A,X[ 0],20,0xe9b6c7aaL); | ||
| 134 | R1(A,B,C,D,X[ 5], 5,0xd62f105dL); | ||
| 135 | R1(D,A,B,C,X[10], 9,0x02441453L); | ||
| 136 | R1(C,D,A,B,X[15],14,0xd8a1e681L); | ||
| 137 | R1(B,C,D,A,X[ 4],20,0xe7d3fbc8L); | ||
| 138 | R1(A,B,C,D,X[ 9], 5,0x21e1cde6L); | ||
| 139 | R1(D,A,B,C,X[14], 9,0xc33707d6L); | ||
| 140 | R1(C,D,A,B,X[ 3],14,0xf4d50d87L); | ||
| 141 | R1(B,C,D,A,X[ 8],20,0x455a14edL); | ||
| 142 | R1(A,B,C,D,X[13], 5,0xa9e3e905L); | ||
| 143 | R1(D,A,B,C,X[ 2], 9,0xfcefa3f8L); | ||
| 144 | R1(C,D,A,B,X[ 7],14,0x676f02d9L); | ||
| 145 | R1(B,C,D,A,X[12],20,0x8d2a4c8aL); | ||
| 146 | /* Round 2 */ | ||
| 147 | R2(A,B,C,D,X[ 5], 4,0xfffa3942L); | ||
| 148 | R2(D,A,B,C,X[ 8],11,0x8771f681L); | ||
| 149 | R2(C,D,A,B,X[11],16,0x6d9d6122L); | ||
| 150 | R2(B,C,D,A,X[14],23,0xfde5380cL); | ||
| 151 | R2(A,B,C,D,X[ 1], 4,0xa4beea44L); | ||
| 152 | R2(D,A,B,C,X[ 4],11,0x4bdecfa9L); | ||
| 153 | R2(C,D,A,B,X[ 7],16,0xf6bb4b60L); | ||
| 154 | R2(B,C,D,A,X[10],23,0xbebfbc70L); | ||
| 155 | R2(A,B,C,D,X[13], 4,0x289b7ec6L); | ||
| 156 | R2(D,A,B,C,X[ 0],11,0xeaa127faL); | ||
| 157 | R2(C,D,A,B,X[ 3],16,0xd4ef3085L); | ||
| 158 | R2(B,C,D,A,X[ 6],23,0x04881d05L); | ||
| 159 | R2(A,B,C,D,X[ 9], 4,0xd9d4d039L); | ||
| 160 | R2(D,A,B,C,X[12],11,0xe6db99e5L); | ||
| 161 | R2(C,D,A,B,X[15],16,0x1fa27cf8L); | ||
| 162 | R2(B,C,D,A,X[ 2],23,0xc4ac5665L); | ||
| 163 | /* Round 3 */ | ||
| 164 | R3(A,B,C,D,X[ 0], 6,0xf4292244L); | ||
| 165 | R3(D,A,B,C,X[ 7],10,0x432aff97L); | ||
| 166 | R3(C,D,A,B,X[14],15,0xab9423a7L); | ||
| 167 | R3(B,C,D,A,X[ 5],21,0xfc93a039L); | ||
| 168 | R3(A,B,C,D,X[12], 6,0x655b59c3L); | ||
| 169 | R3(D,A,B,C,X[ 3],10,0x8f0ccc92L); | ||
| 170 | R3(C,D,A,B,X[10],15,0xffeff47dL); | ||
| 171 | R3(B,C,D,A,X[ 1],21,0x85845dd1L); | ||
| 172 | R3(A,B,C,D,X[ 8], 6,0x6fa87e4fL); | ||
| 173 | R3(D,A,B,C,X[15],10,0xfe2ce6e0L); | ||
| 174 | R3(C,D,A,B,X[ 6],15,0xa3014314L); | ||
| 175 | R3(B,C,D,A,X[13],21,0x4e0811a1L); | ||
| 176 | R3(A,B,C,D,X[ 4], 6,0xf7537e82L); | ||
| 177 | R3(D,A,B,C,X[11],10,0xbd3af235L); | ||
| 178 | R3(C,D,A,B,X[ 2],15,0x2ad7d2bbL); | ||
| 179 | R3(B,C,D,A,X[ 9],21,0xeb86d391L); | ||
| 180 | |||
| 181 | A = c->A += A; | ||
| 182 | B = c->B += B; | ||
| 183 | C = c->C += C; | ||
| 184 | D = c->D += D; | ||
| 185 | } | ||
| 186 | } | ||
| 187 | #endif | ||
| 188 | |||
| 189 | #ifndef md5_block_data_order | ||
| 190 | #ifdef X | ||
| 191 | #undef X | ||
| 192 | #endif | ||
| 193 | void md5_block_data_order (MD5_CTX *c, const void *data_, int num) | ||
| 194 | { | ||
| 195 | const unsigned char *data=data_; | ||
| 196 | register unsigned long A,B,C,D,l; | ||
| 197 | /* | ||
| 198 | * In case you wonder why A-D are declared as long and not | ||
| 199 | * as MD5_LONG. Doing so results in slight performance | ||
| 200 | * boost on LP64 architectures. The catch is we don't | ||
| 201 | * really care if 32 MSBs of a 64-bit register get polluted | ||
| 202 | * with eventual overflows as we *save* only 32 LSBs in | ||
| 203 | * *either* case. Now declaring 'em long excuses the compiler | ||
| 204 | * from keeping 32 MSBs zeroed resulting in 13% performance | ||
| 205 | * improvement under SPARC Solaris7/64 and 5% under AlphaLinux. | ||
| 206 | * Well, to be honest it should say that this *prevents* | ||
| 207 | * performance degradation. | ||
| 208 | * | ||
| 209 | * <appro@fy.chalmers.se> | ||
| 210 | */ | ||
| 211 | #ifndef MD32_XARRAY | ||
| 212 | /* See comment in crypto/sha/sha_locl.h for details. */ | ||
| 213 | unsigned long XX0, XX1, XX2, XX3, XX4, XX5, XX6, XX7, | ||
| 214 | XX8, XX9,XX10,XX11,XX12,XX13,XX14,XX15; | ||
| 215 | # define X(i) XX##i | ||
| 216 | #else | ||
| 217 | MD5_LONG XX[MD5_LBLOCK]; | ||
| 218 | # define X(i) XX[i] | ||
| 219 | #endif | ||
| 220 | |||
| 221 | A=c->A; | ||
| 222 | B=c->B; | ||
| 223 | C=c->C; | ||
| 224 | D=c->D; | ||
| 225 | |||
| 226 | for (;num--;) | ||
| 227 | { | ||
| 228 | HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l; | ||
| 229 | /* Round 0 */ | ||
| 230 | R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l; | ||
| 231 | R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l; | ||
| 232 | R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l; | ||
| 233 | R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l; | ||
| 234 | R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l; | ||
| 235 | R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l; | ||
| 236 | R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l; | ||
| 237 | R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l; | ||
| 238 | R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l; | ||
| 239 | R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l; | ||
| 240 | R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l; | ||
| 241 | R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l; | ||
| 242 | R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l; | ||
| 243 | R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l; | ||
| 244 | R0(C,D,A,B,X(14),17,0xa679438eL); | ||
| 245 | R0(B,C,D,A,X(15),22,0x49b40821L); | ||
| 246 | /* Round 1 */ | ||
| 247 | R1(A,B,C,D,X( 1), 5,0xf61e2562L); | ||
| 248 | R1(D,A,B,C,X( 6), 9,0xc040b340L); | ||
| 249 | R1(C,D,A,B,X(11),14,0x265e5a51L); | ||
| 250 | R1(B,C,D,A,X( 0),20,0xe9b6c7aaL); | ||
| 251 | R1(A,B,C,D,X( 5), 5,0xd62f105dL); | ||
| 252 | R1(D,A,B,C,X(10), 9,0x02441453L); | ||
| 253 | R1(C,D,A,B,X(15),14,0xd8a1e681L); | ||
| 254 | R1(B,C,D,A,X( 4),20,0xe7d3fbc8L); | ||
| 255 | R1(A,B,C,D,X( 9), 5,0x21e1cde6L); | ||
| 256 | R1(D,A,B,C,X(14), 9,0xc33707d6L); | ||
| 257 | R1(C,D,A,B,X( 3),14,0xf4d50d87L); | ||
| 258 | R1(B,C,D,A,X( 8),20,0x455a14edL); | ||
| 259 | R1(A,B,C,D,X(13), 5,0xa9e3e905L); | ||
| 260 | R1(D,A,B,C,X( 2), 9,0xfcefa3f8L); | ||
| 261 | R1(C,D,A,B,X( 7),14,0x676f02d9L); | ||
| 262 | R1(B,C,D,A,X(12),20,0x8d2a4c8aL); | ||
| 263 | /* Round 2 */ | ||
| 264 | R2(A,B,C,D,X( 5), 4,0xfffa3942L); | ||
| 265 | R2(D,A,B,C,X( 8),11,0x8771f681L); | ||
| 266 | R2(C,D,A,B,X(11),16,0x6d9d6122L); | ||
| 267 | R2(B,C,D,A,X(14),23,0xfde5380cL); | ||
| 268 | R2(A,B,C,D,X( 1), 4,0xa4beea44L); | ||
| 269 | R2(D,A,B,C,X( 4),11,0x4bdecfa9L); | ||
| 270 | R2(C,D,A,B,X( 7),16,0xf6bb4b60L); | ||
| 271 | R2(B,C,D,A,X(10),23,0xbebfbc70L); | ||
| 272 | R2(A,B,C,D,X(13), 4,0x289b7ec6L); | ||
| 273 | R2(D,A,B,C,X( 0),11,0xeaa127faL); | ||
| 274 | R2(C,D,A,B,X( 3),16,0xd4ef3085L); | ||
| 275 | R2(B,C,D,A,X( 6),23,0x04881d05L); | ||
| 276 | R2(A,B,C,D,X( 9), 4,0xd9d4d039L); | ||
| 277 | R2(D,A,B,C,X(12),11,0xe6db99e5L); | ||
| 278 | R2(C,D,A,B,X(15),16,0x1fa27cf8L); | ||
| 279 | R2(B,C,D,A,X( 2),23,0xc4ac5665L); | ||
| 280 | /* Round 3 */ | ||
| 281 | R3(A,B,C,D,X( 0), 6,0xf4292244L); | ||
| 282 | R3(D,A,B,C,X( 7),10,0x432aff97L); | ||
| 283 | R3(C,D,A,B,X(14),15,0xab9423a7L); | ||
| 284 | R3(B,C,D,A,X( 5),21,0xfc93a039L); | ||
| 285 | R3(A,B,C,D,X(12), 6,0x655b59c3L); | ||
| 286 | R3(D,A,B,C,X( 3),10,0x8f0ccc92L); | ||
| 287 | R3(C,D,A,B,X(10),15,0xffeff47dL); | ||
| 288 | R3(B,C,D,A,X( 1),21,0x85845dd1L); | ||
| 289 | R3(A,B,C,D,X( 8), 6,0x6fa87e4fL); | ||
| 290 | R3(D,A,B,C,X(15),10,0xfe2ce6e0L); | ||
| 291 | R3(C,D,A,B,X( 6),15,0xa3014314L); | ||
| 292 | R3(B,C,D,A,X(13),21,0x4e0811a1L); | ||
| 293 | R3(A,B,C,D,X( 4), 6,0xf7537e82L); | ||
| 294 | R3(D,A,B,C,X(11),10,0xbd3af235L); | ||
| 295 | R3(C,D,A,B,X( 2),15,0x2ad7d2bbL); | ||
| 296 | R3(B,C,D,A,X( 9),21,0xeb86d391L); | ||
| 297 | |||
| 298 | A = c->A += A; | ||
| 299 | B = c->B += B; | ||
| 300 | C = c->C += C; | ||
| 301 | D = c->D += D; | ||
| 302 | } | ||
| 303 | } | ||
| 304 | #endif | ||
| 305 | |||
| 306 | #ifdef undef | ||
| 307 | int printit(unsigned long *l) | ||
| 308 | { | ||
| 309 | int i,ii; | ||
| 310 | |||
| 311 | for (i=0; i<2; i++) | ||
| 312 | { | ||
| 313 | for (ii=0; ii<8; ii++) | ||
| 314 | { | ||
| 315 | fprintf(stderr,"%08lx ",l[i*8+ii]); | ||
| 316 | } | ||
| 317 | fprintf(stderr,"\n"); | ||
| 318 | } | ||
| 319 | } | ||
| 320 | #endif | ||
diff --git a/src/lib/libcrypto/md5/md5_locl.h b/src/lib/libcrypto/md5/md5_locl.h new file mode 100644 index 0000000000..34c5257306 --- /dev/null +++ b/src/lib/libcrypto/md5/md5_locl.h | |||
| @@ -0,0 +1,172 @@ | |||
| 1 | /* crypto/md5/md5_locl.h */ | ||
| 2 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * This package is an SSL implementation written | ||
| 6 | * by Eric Young (eay@cryptsoft.com). | ||
| 7 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 8 | * | ||
| 9 | * This library is free for commercial and non-commercial use as long as | ||
| 10 | * the following conditions are aheared to. The following conditions | ||
| 11 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 12 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 13 | * included with this distribution is covered by the same copyright terms | ||
| 14 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 15 | * | ||
| 16 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 17 | * the code are not to be removed. | ||
| 18 | * If this package is used in a product, Eric Young should be given attribution | ||
| 19 | * as the author of the parts of the library used. | ||
| 20 | * This can be in the form of a textual message at program startup or | ||
| 21 | * in documentation (online or textual) provided with the package. | ||
| 22 | * | ||
| 23 | * Redistribution and use in source and binary forms, with or without | ||
| 24 | * modification, are permitted provided that the following conditions | ||
| 25 | * are met: | ||
| 26 | * 1. Redistributions of source code must retain the copyright | ||
| 27 | * notice, this list of conditions and the following disclaimer. | ||
| 28 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer in the | ||
| 30 | * documentation and/or other materials provided with the distribution. | ||
| 31 | * 3. All advertising materials mentioning features or use of this software | ||
| 32 | * must display the following acknowledgement: | ||
| 33 | * "This product includes cryptographic software written by | ||
| 34 | * Eric Young (eay@cryptsoft.com)" | ||
| 35 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 36 | * being used are not cryptographic related :-). | ||
| 37 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 38 | * the apps directory (application code) you must include an acknowledgement: | ||
| 39 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 40 | * | ||
| 41 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 42 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 43 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 44 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 45 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 46 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 47 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 49 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 50 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 51 | * SUCH DAMAGE. | ||
| 52 | * | ||
| 53 | * The licence and distribution terms for any publically available version or | ||
| 54 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 55 | * copied and put under another distribution licence | ||
| 56 | * [including the GNU Public Licence.] | ||
| 57 | */ | ||
| 58 | |||
| 59 | #include <stdlib.h> | ||
| 60 | #include <string.h> | ||
| 61 | #include <openssl/opensslconf.h> | ||
| 62 | #include <openssl/md5.h> | ||
| 63 | |||
| 64 | #ifndef MD5_LONG_LOG2 | ||
| 65 | #define MD5_LONG_LOG2 2 /* default to 32 bits */ | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifdef MD5_ASM | ||
| 69 | # if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) | ||
| 70 | # define md5_block_host_order md5_block_asm_host_order | ||
| 71 | # elif defined(__sparc) && defined(OPENSSL_SYS_ULTRASPARC) | ||
| 72 | void md5_block_asm_data_order_aligned (MD5_CTX *c, const MD5_LONG *p,int num); | ||
| 73 | # define HASH_BLOCK_DATA_ORDER_ALIGNED md5_block_asm_data_order_aligned | ||
| 74 | # endif | ||
| 75 | #endif | ||
| 76 | |||
| 77 | void md5_block_host_order (MD5_CTX *c, const void *p,int num); | ||
| 78 | void md5_block_data_order (MD5_CTX *c, const void *p,int num); | ||
| 79 | |||
| 80 | #if defined(__i386) || defined(__i386__) || defined(_M_IX86) || defined(__INTEL__) | ||
| 81 | /* | ||
| 82 | * *_block_host_order is expected to handle aligned data while | ||
| 83 | * *_block_data_order - unaligned. As algorithm and host (x86) | ||
| 84 | * are in this case of the same "endianness" these two are | ||
| 85 | * otherwise indistinguishable. But normally you don't want to | ||
| 86 | * call the same function because unaligned access in places | ||
| 87 | * where alignment is expected is usually a "Bad Thing". Indeed, | ||
| 88 | * on RISCs you get punished with BUS ERROR signal or *severe* | ||
| 89 | * performance degradation. Intel CPUs are in turn perfectly | ||
| 90 | * capable of loading unaligned data without such drastic side | ||
| 91 | * effect. Yes, they say it's slower than aligned load, but no | ||
| 92 | * exception is generated and therefore performance degradation | ||
| 93 | * is *incomparable* with RISCs. What we should weight here is | ||
| 94 | * costs of unaligned access against costs of aligning data. | ||
| 95 | * According to my measurements allowing unaligned access results | ||
| 96 | * in ~9% performance improvement on Pentium II operating at | ||
| 97 | * 266MHz. I won't be surprised if the difference will be higher | ||
| 98 | * on faster systems:-) | ||
| 99 | * | ||
| 100 | * <appro@fy.chalmers.se> | ||
| 101 | */ | ||
| 102 | #define md5_block_data_order md5_block_host_order | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #define DATA_ORDER_IS_LITTLE_ENDIAN | ||
| 106 | |||
| 107 | #define HASH_LONG MD5_LONG | ||
| 108 | #define HASH_LONG_LOG2 MD5_LONG_LOG2 | ||
| 109 | #define HASH_CTX MD5_CTX | ||
| 110 | #define HASH_CBLOCK MD5_CBLOCK | ||
| 111 | #define HASH_LBLOCK MD5_LBLOCK | ||
| 112 | #define HASH_UPDATE MD5_Update | ||
| 113 | #define HASH_TRANSFORM MD5_Transform | ||
| 114 | #define HASH_FINAL MD5_Final | ||
| 115 | #define HASH_MAKE_STRING(c,s) do { \ | ||
| 116 | unsigned long ll; \ | ||
| 117 | ll=(c)->A; HOST_l2c(ll,(s)); \ | ||
| 118 | ll=(c)->B; HOST_l2c(ll,(s)); \ | ||
| 119 | ll=(c)->C; HOST_l2c(ll,(s)); \ | ||
| 120 | ll=(c)->D; HOST_l2c(ll,(s)); \ | ||
| 121 | } while (0) | ||
| 122 | #define HASH_BLOCK_HOST_ORDER md5_block_host_order | ||
| 123 | #if !defined(L_ENDIAN) || defined(md5_block_data_order) | ||
| 124 | #define HASH_BLOCK_DATA_ORDER md5_block_data_order | ||
| 125 | /* | ||
| 126 | * Little-endians (Intel and Alpha) feel better without this. | ||
| 127 | * It looks like memcpy does better job than generic | ||
| 128 | * md5_block_data_order on copying-n-aligning input data. | ||
| 129 | * But frankly speaking I didn't expect such result on Alpha. | ||
| 130 | * On the other hand I've got this with egcs-1.0.2 and if | ||
| 131 | * program is compiled with another (better?) compiler it | ||
| 132 | * might turn out other way around. | ||
| 133 | * | ||
| 134 | * <appro@fy.chalmers.se> | ||
| 135 | */ | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #include "md32_common.h" | ||
| 139 | |||
| 140 | /* | ||
| 141 | #define F(x,y,z) (((x) & (y)) | ((~(x)) & (z))) | ||
| 142 | #define G(x,y,z) (((x) & (z)) | ((y) & (~(z)))) | ||
| 143 | */ | ||
| 144 | |||
| 145 | /* As pointed out by Wei Dai <weidai@eskimo.com>, the above can be | ||
| 146 | * simplified to the code below. Wei attributes these optimizations | ||
| 147 | * to Peter Gutmann's SHS code, and he attributes it to Rich Schroeppel. | ||
| 148 | */ | ||
| 149 | #define F(b,c,d) ((((c) ^ (d)) & (b)) ^ (d)) | ||
| 150 | #define G(b,c,d) ((((b) ^ (c)) & (d)) ^ (c)) | ||
| 151 | #define H(b,c,d) ((b) ^ (c) ^ (d)) | ||
| 152 | #define I(b,c,d) (((~(d)) | (b)) ^ (c)) | ||
| 153 | |||
| 154 | #define R0(a,b,c,d,k,s,t) { \ | ||
| 155 | a+=((k)+(t)+F((b),(c),(d))); \ | ||
| 156 | a=ROTATE(a,s); \ | ||
| 157 | a+=b; };\ | ||
| 158 | |||
| 159 | #define R1(a,b,c,d,k,s,t) { \ | ||
| 160 | a+=((k)+(t)+G((b),(c),(d))); \ | ||
| 161 | a=ROTATE(a,s); \ | ||
| 162 | a+=b; }; | ||
| 163 | |||
| 164 | #define R2(a,b,c,d,k,s,t) { \ | ||
| 165 | a+=((k)+(t)+H((b),(c),(d))); \ | ||
| 166 | a=ROTATE(a,s); \ | ||
| 167 | a+=b; }; | ||
| 168 | |||
| 169 | #define R3(a,b,c,d,k,s,t) { \ | ||
| 170 | a+=((k)+(t)+I((b),(c),(d))); \ | ||
| 171 | a=ROTATE(a,s); \ | ||
| 172 | a+=b; }; | ||
diff --git a/src/lib/libcrypto/md5/md5_one.c b/src/lib/libcrypto/md5/md5_one.c new file mode 100644 index 0000000000..b89dec850d --- /dev/null +++ b/src/lib/libcrypto/md5/md5_one.c | |||
| @@ -0,0 +1,95 @@ | |||
| 1 | /* crypto/md5/md5_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/md5.h> | ||
| 62 | |||
| 63 | #ifdef CHARSET_EBCDIC | ||
| 64 | #include <openssl/ebcdic.h> | ||
| 65 | #endif | ||
| 66 | |||
| 67 | unsigned char *MD5(const unsigned char *d, unsigned long n, unsigned char *md) | ||
| 68 | { | ||
| 69 | MD5_CTX c; | ||
| 70 | static unsigned char m[MD5_DIGEST_LENGTH]; | ||
| 71 | |||
| 72 | if (md == NULL) md=m; | ||
| 73 | MD5_Init(&c); | ||
| 74 | #ifndef CHARSET_EBCDIC | ||
| 75 | MD5_Update(&c,d,n); | ||
| 76 | #else | ||
| 77 | { | ||
| 78 | char temp[1024]; | ||
| 79 | unsigned long chunk; | ||
| 80 | |||
| 81 | while (n > 0) | ||
| 82 | { | ||
| 83 | chunk = (n > sizeof(temp)) ? sizeof(temp) : n; | ||
| 84 | ebcdic2ascii(temp, d, chunk); | ||
| 85 | MD5_Update(&c,temp,chunk); | ||
| 86 | n -= chunk; | ||
| 87 | d += chunk; | ||
| 88 | } | ||
| 89 | } | ||
| 90 | #endif | ||
| 91 | MD5_Final(md,&c); | ||
| 92 | memset(&c,0,sizeof(c)); /* security consideration */ | ||
| 93 | return(md); | ||
| 94 | } | ||
| 95 | |||
