diff options
Diffstat (limited to 'src/lib/libcrypto/des')
34 files changed, 7667 insertions, 4 deletions
diff --git a/src/lib/libcrypto/des/COPYRIGHT b/src/lib/libcrypto/des/COPYRIGHT new file mode 100644 index 0000000000..5469e1e469 --- /dev/null +++ b/src/lib/libcrypto/des/COPYRIGHT | |||
| @@ -0,0 +1,50 @@ | |||
| 1 | Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com) | ||
| 2 | All rights reserved. | ||
| 3 | |||
| 4 | This package is an DES implementation written by Eric Young (eay@cryptsoft.com). | ||
| 5 | The implementation was written so as to conform with MIT's libdes. | ||
| 6 | |||
| 7 | This library is free for commercial and non-commercial use as long as | ||
| 8 | the following conditions are aheared to. The following conditions | ||
| 9 | apply to all code found in this distribution. | ||
| 10 | |||
| 11 | Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 12 | the code are not to be removed. | ||
| 13 | If this package is used in a product, Eric Young should be given attribution | ||
| 14 | as the author of that the SSL library. This can be in the form of a textual | ||
| 15 | message at program startup or in documentation (online or textual) provided | ||
| 16 | with the package. | ||
| 17 | |||
| 18 | Redistribution and use in source and binary forms, with or without | ||
| 19 | modification, are permitted provided that the following conditions | ||
| 20 | are met: | ||
| 21 | 1. Redistributions of source code must retain the copyright | ||
| 22 | notice, this list of conditions and the following disclaimer. | ||
| 23 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 24 | notice, this list of conditions and the following disclaimer in the | ||
| 25 | documentation and/or other materials provided with the distribution. | ||
| 26 | 3. All advertising materials mentioning features or use of this software | ||
| 27 | must display the following acknowledgement: | ||
| 28 | This product includes software developed by Eric Young (eay@cryptsoft.com) | ||
| 29 | |||
| 30 | THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 31 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 32 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 33 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 34 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 35 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 36 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 37 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 38 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 39 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 40 | SUCH DAMAGE. | ||
| 41 | |||
| 42 | The license and distribution terms for any publically available version or | ||
| 43 | derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 44 | copied and put under another distrubution license | ||
| 45 | [including the GNU Public License.] | ||
| 46 | |||
| 47 | The reason behind this being stated in this direct manner is past | ||
| 48 | experience in code simply being copied and the attribution removed | ||
| 49 | from it and then being distributed as part of other packages. This | ||
| 50 | implementation was a non-trivial and unpaid effort. | ||
diff --git a/src/lib/libcrypto/des/Makefile.ssl b/src/lib/libcrypto/des/Makefile.ssl new file mode 100644 index 0000000000..0d9ba2b42f --- /dev/null +++ b/src/lib/libcrypto/des/Makefile.ssl | |||
| @@ -0,0 +1,316 @@ | |||
| 1 | # | ||
| 2 | # SSLeay/crypto/des/Makefile | ||
| 3 | # | ||
| 4 | |||
| 5 | DIR= des | ||
| 6 | TOP= ../.. | ||
| 7 | CC= cc | ||
| 8 | CPP= $(CC) -E | ||
| 9 | INCLUDES=-I$(TOP) -I../../include | ||
| 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 | RANLIB= ranlib | ||
| 20 | DES_ENC= des_enc.o fcrypt_b.o | ||
| 21 | # or use | ||
| 22 | #DES_ENC= dx86-elf.o yx86-elf.o | ||
| 23 | |||
| 24 | CFLAGS= $(INCLUDES) $(CFLAG) | ||
| 25 | ASFLAGS= $(INCLUDES) $(ASFLAG) | ||
| 26 | |||
| 27 | GENERAL=Makefile | ||
| 28 | TEST=destest.c | ||
| 29 | APPS= | ||
| 30 | |||
| 31 | LIB=$(TOP)/libcrypto.a | ||
| 32 | LIBSRC= cbc_cksm.c cbc_enc.c cfb64enc.c cfb_enc.c \ | ||
| 33 | ecb3_enc.c ecb_enc.c enc_read.c enc_writ.c \ | ||
| 34 | fcrypt.c ofb64enc.c ofb_enc.c pcbc_enc.c \ | ||
| 35 | qud_cksm.c rand_key.c rpc_enc.c set_key.c \ | ||
| 36 | des_enc.c fcrypt_b.c \ | ||
| 37 | xcbc_enc.c \ | ||
| 38 | str2key.c cfb64ede.c ofb64ede.c ede_cbcm_enc.c des_old.c des_old2.c \ | ||
| 39 | read2pwd.c | ||
| 40 | |||
| 41 | LIBOBJ= set_key.o ecb_enc.o cbc_enc.o \ | ||
| 42 | ecb3_enc.o cfb64enc.o cfb64ede.o cfb_enc.o ofb64ede.o \ | ||
| 43 | enc_read.o enc_writ.o ofb64enc.o \ | ||
| 44 | ofb_enc.o str2key.o pcbc_enc.o qud_cksm.o rand_key.o \ | ||
| 45 | ${DES_ENC} \ | ||
| 46 | fcrypt.o xcbc_enc.o rpc_enc.o cbc_cksm.o \ | ||
| 47 | ede_cbcm_enc.o des_old.o des_old2.o read2pwd.o | ||
| 48 | |||
| 49 | SRC= $(LIBSRC) | ||
| 50 | |||
| 51 | EXHEADER= des.h des_old.h | ||
| 52 | HEADER= des_locl.h rpc_des.h spr.h des_ver.h $(EXHEADER) | ||
| 53 | |||
| 54 | ALL= $(GENERAL) $(SRC) $(HEADER) | ||
| 55 | |||
| 56 | top: | ||
| 57 | (cd ../..; $(MAKE) DIRS=crypto SDIRS=$(DIR) sub_all) | ||
| 58 | |||
| 59 | all: lib | ||
| 60 | |||
| 61 | lib: $(LIBOBJ) | ||
| 62 | $(AR) $(LIB) $(LIBOBJ) | ||
| 63 | $(RANLIB) $(LIB) || echo Never mind. | ||
| 64 | @touch lib | ||
| 65 | |||
| 66 | des: des.o cbc3_enc.o lib | ||
| 67 | $(CC) $(CFLAGS) -o des des.o cbc3_enc.o $(LIB) | ||
| 68 | |||
| 69 | # elf | ||
| 70 | asm/dx86-elf.s: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl | ||
| 71 | (cd asm; $(PERL) des-586.pl elf $(CFLAGS) > dx86-elf.s) | ||
| 72 | |||
| 73 | asm/yx86-elf.s: asm/crypt586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl | ||
| 74 | (cd asm; $(PERL) crypt586.pl elf $(CFLAGS) > yx86-elf.s) | ||
| 75 | |||
| 76 | # a.out | ||
| 77 | asm/dx86-out.o: asm/dx86unix.cpp | ||
| 78 | $(CPP) -DOUT asm/dx86unix.cpp | as -o asm/dx86-out.o | ||
| 79 | |||
| 80 | asm/yx86-out.o: asm/yx86unix.cpp | ||
| 81 | $(CPP) -DOUT asm/yx86unix.cpp | as -o asm/yx86-out.o | ||
| 82 | |||
| 83 | # bsdi | ||
| 84 | asm/dx86bsdi.o: asm/dx86unix.cpp | ||
| 85 | $(CPP) -DBSDI asm/dx86unix.cpp | sed 's/ :/:/' | as -o asm/dx86bsdi.o | ||
| 86 | |||
| 87 | asm/yx86bsdi.o: asm/yx86unix.cpp | ||
| 88 | $(CPP) -DBSDI asm/yx86unix.cpp | sed 's/ :/:/' | as -o asm/yx86bsdi.o | ||
| 89 | |||
| 90 | asm/dx86unix.cpp: asm/des-586.pl ../perlasm/x86asm.pl ../perlasm/cbc.pl | ||
| 91 | (cd asm; $(PERL) des-586.pl cpp >dx86unix.cpp) | ||
| 92 | |||
| 93 | asm/yx86unix.cpp: asm/crypt586.pl ../perlasm/x86asm.pl | ||
| 94 | (cd asm; $(PERL) crypt586.pl cpp >yx86unix.cpp) | ||
| 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: installs | ||
| 106 | |||
| 107 | installs: | ||
| 108 | @for i in $(EXHEADER) ; \ | ||
| 109 | do \ | ||
| 110 | (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ | ||
| 111 | chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ | ||
| 112 | done; | ||
| 113 | |||
| 114 | tags: | ||
| 115 | ctags $(SRC) | ||
| 116 | |||
| 117 | tests: | ||
| 118 | |||
| 119 | lint: | ||
| 120 | lint -DLINT $(INCLUDES) $(SRC)>fluff | ||
| 121 | |||
| 122 | depend: | ||
| 123 | $(MAKEDEPEND) -- $(CFLAG) $(INCLUDES) $(DEPFLAG) -- $(PROGS) $(LIBSRC) | ||
| 124 | |||
| 125 | dclean: | ||
| 126 | $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new | ||
| 127 | mv -f Makefile.new $(MAKEFILE) | ||
| 128 | |||
| 129 | clean: | ||
| 130 | rm -f asm/dx86unix.cpp asm/yx86unix.cpp asm/*-elf.* *.o asm/*.o *.obj des lib tags core .pure .nfs* *.old *.bak fluff | ||
| 131 | |||
| 132 | # DO NOT DELETE THIS LINE -- make depend depends on it. | ||
| 133 | |||
| 134 | cbc_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 135 | cbc_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 136 | cbc_cksm.o: ../../include/openssl/opensslconf.h | ||
| 137 | cbc_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 138 | cbc_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 139 | cbc_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 140 | cbc_cksm.o: cbc_cksm.c des_locl.h | ||
| 141 | cbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 142 | cbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 143 | cbc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 144 | cbc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 145 | cbc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 146 | cbc_enc.o: ../../include/openssl/ui_compat.h cbc_enc.c des_locl.h ncbc_enc.c | ||
| 147 | cfb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 148 | cfb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 149 | cfb64ede.o: ../../include/openssl/opensslconf.h | ||
| 150 | cfb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 151 | cfb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 152 | cfb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 153 | cfb64ede.o: cfb64ede.c des_locl.h | ||
| 154 | cfb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 155 | cfb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 156 | cfb64enc.o: ../../include/openssl/opensslconf.h | ||
| 157 | cfb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 158 | cfb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 159 | cfb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 160 | cfb64enc.o: cfb64enc.c des_locl.h | ||
| 161 | cfb_enc.o: ../../e_os.h ../../include/openssl/crypto.h | ||
| 162 | cfb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 163 | cfb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 164 | cfb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 165 | cfb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 166 | cfb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 167 | cfb_enc.o: cfb_enc.c des_locl.h | ||
| 168 | des_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 169 | des_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 170 | des_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 171 | des_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 172 | des_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 173 | des_enc.o: ../../include/openssl/ui_compat.h des_enc.c des_locl.h ncbc_enc.c | ||
| 174 | des_old.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 175 | des_old.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 176 | des_old.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 177 | des_old.o: ../../include/openssl/ossl_typ.h ../../include/openssl/rand.h | ||
| 178 | des_old.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 179 | des_old.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 180 | des_old.o: ../../include/openssl/ui_compat.h des_old.c | ||
| 181 | des_old2.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 182 | des_old2.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 183 | des_old2.o: ../../include/openssl/opensslconf.h | ||
| 184 | des_old2.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 185 | des_old2.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
| 186 | des_old2.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 187 | des_old2.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 188 | des_old2.o: des_old2.c | ||
| 189 | ecb3_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 190 | ecb3_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 191 | ecb3_enc.o: ../../include/openssl/opensslconf.h | ||
| 192 | ecb3_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 193 | ecb3_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 194 | ecb3_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 195 | ecb3_enc.o: des_locl.h ecb3_enc.c | ||
| 196 | ecb_enc.o: ../../include/openssl/bio.h ../../include/openssl/crypto.h | ||
| 197 | ecb_enc.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 198 | ecb_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h | ||
| 199 | ecb_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 200 | ecb_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 201 | ecb_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 202 | ecb_enc.o: des_locl.h des_ver.h ecb_enc.c spr.h | ||
| 203 | ede_cbcm_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 204 | ede_cbcm_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 205 | ede_cbcm_enc.o: ../../include/openssl/opensslconf.h | ||
| 206 | ede_cbcm_enc.o: ../../include/openssl/opensslv.h | ||
| 207 | ede_cbcm_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 208 | ede_cbcm_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 209 | ede_cbcm_enc.o: ../../include/openssl/ui_compat.h des_locl.h ede_cbcm_enc.c | ||
| 210 | enc_read.o: ../../e_os.h ../../include/openssl/bio.h | ||
| 211 | enc_read.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 212 | enc_read.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 213 | enc_read.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 214 | enc_read.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 215 | enc_read.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 216 | enc_read.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 217 | enc_read.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 218 | enc_read.o: ../cryptlib.h des_locl.h enc_read.c | ||
| 219 | enc_writ.o: ../../e_os.h ../../include/openssl/bio.h | ||
| 220 | enc_writ.o: ../../include/openssl/buffer.h ../../include/openssl/crypto.h | ||
| 221 | enc_writ.o: ../../include/openssl/des.h ../../include/openssl/des_old.h | ||
| 222 | enc_writ.o: ../../include/openssl/e_os2.h ../../include/openssl/err.h | ||
| 223 | enc_writ.o: ../../include/openssl/lhash.h ../../include/openssl/opensslconf.h | ||
| 224 | enc_writ.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 225 | enc_writ.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
| 226 | enc_writ.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 227 | enc_writ.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 228 | enc_writ.o: ../cryptlib.h des_locl.h enc_writ.c | ||
| 229 | fcrypt.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 230 | fcrypt.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 231 | fcrypt.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 232 | fcrypt.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 233 | fcrypt.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 234 | fcrypt.o: ../../include/openssl/ui_compat.h des_locl.h fcrypt.c | ||
| 235 | fcrypt_b.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 236 | fcrypt_b.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 237 | fcrypt_b.o: ../../include/openssl/opensslconf.h | ||
| 238 | fcrypt_b.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 239 | fcrypt_b.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 240 | fcrypt_b.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 241 | fcrypt_b.o: des_locl.h fcrypt_b.c | ||
| 242 | ofb64ede.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 243 | ofb64ede.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 244 | ofb64ede.o: ../../include/openssl/opensslconf.h | ||
| 245 | ofb64ede.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 246 | ofb64ede.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 247 | ofb64ede.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 248 | ofb64ede.o: des_locl.h ofb64ede.c | ||
| 249 | ofb64enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 250 | ofb64enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 251 | ofb64enc.o: ../../include/openssl/opensslconf.h | ||
| 252 | ofb64enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 253 | ofb64enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 254 | ofb64enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 255 | ofb64enc.o: des_locl.h ofb64enc.c | ||
| 256 | ofb_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 257 | ofb_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 258 | ofb_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 259 | ofb_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 260 | ofb_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 261 | ofb_enc.o: ../../include/openssl/ui_compat.h des_locl.h ofb_enc.c | ||
| 262 | pcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 263 | pcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 264 | pcbc_enc.o: ../../include/openssl/opensslconf.h | ||
| 265 | pcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 266 | pcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 267 | pcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 268 | pcbc_enc.o: des_locl.h pcbc_enc.c | ||
| 269 | qud_cksm.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 270 | qud_cksm.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 271 | qud_cksm.o: ../../include/openssl/opensslconf.h | ||
| 272 | qud_cksm.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 273 | qud_cksm.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 274 | qud_cksm.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 275 | qud_cksm.o: des_locl.h qud_cksm.c | ||
| 276 | rand_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 277 | rand_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 278 | rand_key.o: ../../include/openssl/opensslconf.h | ||
| 279 | rand_key.o: ../../include/openssl/opensslv.h ../../include/openssl/ossl_typ.h | ||
| 280 | rand_key.o: ../../include/openssl/rand.h ../../include/openssl/safestack.h | ||
| 281 | rand_key.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 282 | rand_key.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 283 | rand_key.o: rand_key.c | ||
| 284 | read2pwd.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 285 | read2pwd.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 286 | read2pwd.o: ../../include/openssl/opensslconf.h | ||
| 287 | read2pwd.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 288 | read2pwd.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 289 | read2pwd.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 290 | read2pwd.o: read2pwd.c | ||
| 291 | rpc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 292 | rpc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 293 | rpc_enc.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 294 | rpc_enc.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 295 | rpc_enc.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 296 | rpc_enc.o: ../../include/openssl/ui_compat.h des_locl.h des_ver.h rpc_des.h | ||
| 297 | rpc_enc.o: rpc_enc.c | ||
| 298 | set_key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 299 | set_key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 300 | set_key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 301 | set_key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 302 | set_key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 303 | set_key.o: ../../include/openssl/ui_compat.h des_locl.h set_key.c | ||
| 304 | str2key.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 305 | str2key.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 306 | str2key.o: ../../include/openssl/opensslconf.h ../../include/openssl/opensslv.h | ||
| 307 | str2key.o: ../../include/openssl/safestack.h ../../include/openssl/stack.h | ||
| 308 | str2key.o: ../../include/openssl/symhacks.h ../../include/openssl/ui.h | ||
| 309 | str2key.o: ../../include/openssl/ui_compat.h des_locl.h str2key.c | ||
| 310 | xcbc_enc.o: ../../include/openssl/crypto.h ../../include/openssl/des.h | ||
| 311 | xcbc_enc.o: ../../include/openssl/des_old.h ../../include/openssl/e_os2.h | ||
| 312 | xcbc_enc.o: ../../include/openssl/opensslconf.h | ||
| 313 | xcbc_enc.o: ../../include/openssl/opensslv.h ../../include/openssl/safestack.h | ||
| 314 | xcbc_enc.o: ../../include/openssl/stack.h ../../include/openssl/symhacks.h | ||
| 315 | xcbc_enc.o: ../../include/openssl/ui.h ../../include/openssl/ui_compat.h | ||
| 316 | xcbc_enc.o: des_locl.h xcbc_enc.c | ||
diff --git a/src/lib/libcrypto/des/asm/crypt586.pl b/src/lib/libcrypto/des/asm/crypt586.pl new file mode 100644 index 0000000000..1d04ed6def --- /dev/null +++ b/src/lib/libcrypto/des/asm/crypt586.pl | |||
| @@ -0,0 +1,208 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # | ||
| 3 | # The inner loop instruction sequence and the IP/FP modifications are from | ||
| 4 | # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> | ||
| 5 | # I've added the stuff needed for crypt() but I've not worried about making | ||
| 6 | # things perfect. | ||
| 7 | # | ||
| 8 | |||
| 9 | push(@INC,"perlasm","../../perlasm"); | ||
| 10 | require "x86asm.pl"; | ||
| 11 | |||
| 12 | &asm_init($ARGV[0],"crypt586.pl"); | ||
| 13 | |||
| 14 | $L="edi"; | ||
| 15 | $R="esi"; | ||
| 16 | |||
| 17 | &external_label("DES_SPtrans"); | ||
| 18 | &fcrypt_body("fcrypt_body"); | ||
| 19 | &asm_finish(); | ||
| 20 | |||
| 21 | sub fcrypt_body | ||
| 22 | { | ||
| 23 | local($name,$do_ip)=@_; | ||
| 24 | |||
| 25 | &function_begin($name,"EXTRN _DES_SPtrans:DWORD"); | ||
| 26 | |||
| 27 | &comment(""); | ||
| 28 | &comment("Load the 2 words"); | ||
| 29 | $trans="ebp"; | ||
| 30 | |||
| 31 | &xor( $L, $L); | ||
| 32 | &xor( $R, $R); | ||
| 33 | |||
| 34 | # PIC-ification:-) | ||
| 35 | &picmeup("edx","DES_SPtrans"); | ||
| 36 | #if ($cpp) { &picmeup("edx","DES_SPtrans"); } | ||
| 37 | #else { &lea("edx",&DWP("DES_SPtrans")); } | ||
| 38 | &push("edx"); # becomes &swtmp(1) | ||
| 39 | # | ||
| 40 | &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT | ||
| 41 | |||
| 42 | &push(&DWC(25)); # add a variable | ||
| 43 | |||
| 44 | &set_label("start"); | ||
| 45 | for ($i=0; $i<16; $i+=2) | ||
| 46 | { | ||
| 47 | &comment(""); | ||
| 48 | &comment("Round $i"); | ||
| 49 | &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); | ||
| 50 | |||
| 51 | &comment(""); | ||
| 52 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 53 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx"); | ||
| 54 | } | ||
| 55 | &mov("ebx", &swtmp(0)); | ||
| 56 | &mov("eax", $L); | ||
| 57 | &dec("ebx"); | ||
| 58 | &mov($L, $R); | ||
| 59 | &mov($R, "eax"); | ||
| 60 | &mov(&swtmp(0), "ebx"); | ||
| 61 | &jnz(&label("start")); | ||
| 62 | |||
| 63 | &comment(""); | ||
| 64 | &comment("FP"); | ||
| 65 | &mov("edx",&wparam(0)); | ||
| 66 | |||
| 67 | &FP_new($R,$L,"eax",3); | ||
| 68 | &mov(&DWP(0,"edx","",0),"eax"); | ||
| 69 | &mov(&DWP(4,"edx","",0),$L); | ||
| 70 | |||
| 71 | &add("esp",8); # remove variables | ||
| 72 | |||
| 73 | &function_end($name); | ||
| 74 | } | ||
| 75 | |||
| 76 | sub D_ENCRYPT | ||
| 77 | { | ||
| 78 | local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; | ||
| 79 | |||
| 80 | &mov( $u, &wparam(2)); # 2 | ||
| 81 | &mov( $t, $R); | ||
| 82 | &shr( $t, 16); # 1 | ||
| 83 | &mov( $tmp2, &wparam(3)); # 2 | ||
| 84 | &xor( $t, $R); # 1 | ||
| 85 | |||
| 86 | &and( $u, $t); # 2 | ||
| 87 | &and( $t, $tmp2); # 2 | ||
| 88 | |||
| 89 | &mov( $tmp1, $u); | ||
| 90 | &shl( $tmp1, 16); # 1 | ||
| 91 | &mov( $tmp2, $t); | ||
| 92 | &shl( $tmp2, 16); # 1 | ||
| 93 | &xor( $u, $tmp1); # 2 | ||
| 94 | &xor( $t, $tmp2); # 2 | ||
| 95 | &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2 | ||
| 96 | &xor( $u, $tmp1); | ||
| 97 | &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2 | ||
| 98 | &xor( $u, $R); | ||
| 99 | &xor( $t, $R); | ||
| 100 | &xor( $t, $tmp2); | ||
| 101 | |||
| 102 | &and( $u, "0xfcfcfcfc" ); # 2 | ||
| 103 | &xor( $tmp1, $tmp1); # 1 | ||
| 104 | &and( $t, "0xcfcfcfcf" ); # 2 | ||
| 105 | &xor( $tmp2, $tmp2); | ||
| 106 | &movb( &LB($tmp1), &LB($u) ); | ||
| 107 | &movb( &LB($tmp2), &HB($u) ); | ||
| 108 | &rotr( $t, 4 ); | ||
| 109 | &mov( $trans, &swtmp(1)); | ||
| 110 | &xor( $L, &DWP(" ",$trans,$tmp1,0)); | ||
| 111 | &movb( &LB($tmp1), &LB($t) ); | ||
| 112 | &xor( $L, &DWP("0x200",$trans,$tmp2,0)); | ||
| 113 | &movb( &LB($tmp2), &HB($t) ); | ||
| 114 | &shr( $u, 16); | ||
| 115 | &xor( $L, &DWP("0x100",$trans,$tmp1,0)); | ||
| 116 | &movb( &LB($tmp1), &HB($u) ); | ||
| 117 | &shr( $t, 16); | ||
| 118 | &xor( $L, &DWP("0x300",$trans,$tmp2,0)); | ||
| 119 | &movb( &LB($tmp2), &HB($t) ); | ||
| 120 | &and( $u, "0xff" ); | ||
| 121 | &and( $t, "0xff" ); | ||
| 122 | &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0)); | ||
| 123 | &xor( $L, $tmp1); | ||
| 124 | &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0)); | ||
| 125 | &xor( $L, $tmp1); | ||
| 126 | &mov( $tmp1, &DWP("0x400",$trans,$u,0)); | ||
| 127 | &xor( $L, $tmp1); | ||
| 128 | &mov( $tmp1, &DWP("0x500",$trans,$t,0)); | ||
| 129 | &xor( $L, $tmp1); | ||
| 130 | &mov( $trans, &wparam(1)); | ||
| 131 | } | ||
| 132 | |||
| 133 | sub n2a | ||
| 134 | { | ||
| 135 | sprintf("%d",$_[0]); | ||
| 136 | } | ||
| 137 | |||
| 138 | # now has a side affect of rotating $a by $shift | ||
| 139 | sub R_PERM_OP | ||
| 140 | { | ||
| 141 | local($a,$b,$tt,$shift,$mask,$last)=@_; | ||
| 142 | |||
| 143 | &rotl( $a, $shift ) if ($shift != 0); | ||
| 144 | &mov( $tt, $a ); | ||
| 145 | &xor( $a, $b ); | ||
| 146 | &and( $a, $mask ); | ||
| 147 | if ($notlast eq $b) | ||
| 148 | { | ||
| 149 | &xor( $b, $a ); | ||
| 150 | &xor( $tt, $a ); | ||
| 151 | } | ||
| 152 | else | ||
| 153 | { | ||
| 154 | &xor( $tt, $a ); | ||
| 155 | &xor( $b, $a ); | ||
| 156 | } | ||
| 157 | &comment(""); | ||
| 158 | } | ||
| 159 | |||
| 160 | sub IP_new | ||
| 161 | { | ||
| 162 | local($l,$r,$tt,$lr)=@_; | ||
| 163 | |||
| 164 | &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l); | ||
| 165 | &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l); | ||
| 166 | &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r); | ||
| 167 | &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r); | ||
| 168 | &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r); | ||
| 169 | |||
| 170 | if ($lr != 3) | ||
| 171 | { | ||
| 172 | if (($lr-3) < 0) | ||
| 173 | { &rotr($tt, 3-$lr); } | ||
| 174 | else { &rotl($tt, $lr-3); } | ||
| 175 | } | ||
| 176 | if ($lr != 2) | ||
| 177 | { | ||
| 178 | if (($lr-2) < 0) | ||
| 179 | { &rotr($r, 2-$lr); } | ||
| 180 | else { &rotl($r, $lr-2); } | ||
| 181 | } | ||
| 182 | } | ||
| 183 | |||
| 184 | sub FP_new | ||
| 185 | { | ||
| 186 | local($l,$r,$tt,$lr)=@_; | ||
| 187 | |||
| 188 | if ($lr != 2) | ||
| 189 | { | ||
| 190 | if (($lr-2) < 0) | ||
| 191 | { &rotl($r, 2-$lr); } | ||
| 192 | else { &rotr($r, $lr-2); } | ||
| 193 | } | ||
| 194 | if ($lr != 3) | ||
| 195 | { | ||
| 196 | if (($lr-3) < 0) | ||
| 197 | { &rotl($l, 3-$lr); } | ||
| 198 | else { &rotr($l, $lr-3); } | ||
| 199 | } | ||
| 200 | |||
| 201 | &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r); | ||
| 202 | &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r); | ||
| 203 | &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l); | ||
| 204 | &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l); | ||
| 205 | &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r); | ||
| 206 | &rotr($tt , 4); | ||
| 207 | } | ||
| 208 | |||
diff --git a/src/lib/libcrypto/des/asm/des-586.pl b/src/lib/libcrypto/des/asm/des-586.pl new file mode 100644 index 0000000000..60d577cc8d --- /dev/null +++ b/src/lib/libcrypto/des/asm/des-586.pl | |||
| @@ -0,0 +1,255 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | # | ||
| 3 | # The inner loop instruction sequence and the IP/FP modifications are from | ||
| 4 | # Svend Olaf Mikkelsen <svolaf@inet.uni-c.dk> | ||
| 5 | # | ||
| 6 | |||
| 7 | push(@INC,"perlasm","../../perlasm"); | ||
| 8 | require "x86asm.pl"; | ||
| 9 | require "cbc.pl"; | ||
| 10 | require "desboth.pl"; | ||
| 11 | |||
| 12 | # base code is in microsft | ||
| 13 | # op dest, source | ||
| 14 | # format. | ||
| 15 | # | ||
| 16 | |||
| 17 | &asm_init($ARGV[0],"des-586.pl"); | ||
| 18 | |||
| 19 | $L="edi"; | ||
| 20 | $R="esi"; | ||
| 21 | |||
| 22 | &external_label("DES_SPtrans"); | ||
| 23 | &DES_encrypt("DES_encrypt1",1); | ||
| 24 | &DES_encrypt("DES_encrypt2",0); | ||
| 25 | |||
| 26 | if (!$main'openbsd) | ||
| 27 | { | ||
| 28 | &DES_encrypt3("DES_encrypt3",1); | ||
| 29 | &DES_encrypt3("DES_decrypt3",0); | ||
| 30 | &cbc("DES_ncbc_encrypt","DES_encrypt1","DES_encrypt1",0,4,5,3,5,-1); | ||
| 31 | &cbc("DES_ede3_cbc_encrypt","DES_encrypt3","DES_decrypt3",0,6,7,3,4,5); | ||
| 32 | } | ||
| 33 | |||
| 34 | &asm_finish(); | ||
| 35 | |||
| 36 | sub DES_encrypt | ||
| 37 | { | ||
| 38 | local($name,$do_ip)=@_; | ||
| 39 | |||
| 40 | &function_begin_B($name,"EXTRN _DES_SPtrans:DWORD"); | ||
| 41 | |||
| 42 | &push("esi"); | ||
| 43 | &push("edi"); | ||
| 44 | |||
| 45 | &comment(""); | ||
| 46 | &comment("Load the 2 words"); | ||
| 47 | $trans="ebp"; | ||
| 48 | |||
| 49 | if ($do_ip) | ||
| 50 | { | ||
| 51 | &mov($R,&wparam(0)); | ||
| 52 | &xor( "ecx", "ecx" ); | ||
| 53 | |||
| 54 | &push("ebx"); | ||
| 55 | &push("ebp"); | ||
| 56 | |||
| 57 | &mov("eax",&DWP(0,$R,"",0)); | ||
| 58 | &mov("ebx",&wparam(2)); # get encrypt flag | ||
| 59 | &mov($L,&DWP(4,$R,"",0)); | ||
| 60 | &comment(""); | ||
| 61 | &comment("IP"); | ||
| 62 | &IP_new("eax",$L,$R,3); | ||
| 63 | } | ||
| 64 | else | ||
| 65 | { | ||
| 66 | &mov("eax",&wparam(0)); | ||
| 67 | &xor( "ecx", "ecx" ); | ||
| 68 | |||
| 69 | &push("ebx"); | ||
| 70 | &push("ebp"); | ||
| 71 | |||
| 72 | &mov($R,&DWP(0,"eax","",0)); | ||
| 73 | &mov("ebx",&wparam(2)); # get encrypt flag | ||
| 74 | &rotl($R,3); | ||
| 75 | &mov($L,&DWP(4,"eax","",0)); | ||
| 76 | &rotl($L,3); | ||
| 77 | } | ||
| 78 | |||
| 79 | # PIC-ification:-) | ||
| 80 | &picmeup($trans,"DES_SPtrans"); | ||
| 81 | #if ($cpp) { &picmeup($trans,"DES_SPtrans"); } | ||
| 82 | #else { &lea($trans,&DWP("DES_SPtrans")); } | ||
| 83 | |||
| 84 | &mov( "ecx", &wparam(1) ); | ||
| 85 | &cmp("ebx","0"); | ||
| 86 | &je(&label("start_decrypt")); | ||
| 87 | |||
| 88 | for ($i=0; $i<16; $i+=2) | ||
| 89 | { | ||
| 90 | &comment(""); | ||
| 91 | &comment("Round $i"); | ||
| 92 | &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); | ||
| 93 | |||
| 94 | &comment(""); | ||
| 95 | &comment("Round ".sprintf("%d",$i+1)); | ||
| 96 | &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx"); | ||
| 97 | } | ||
| 98 | &jmp(&label("end")); | ||
| 99 | |||
| 100 | &set_label("start_decrypt"); | ||
| 101 | |||
| 102 | for ($i=15; $i>0; $i-=2) | ||
| 103 | { | ||
| 104 | &comment(""); | ||
| 105 | &comment("Round $i"); | ||
| 106 | &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); | ||
| 107 | &comment(""); | ||
| 108 | &comment("Round ".sprintf("%d",$i-1)); | ||
| 109 | &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx"); | ||
| 110 | } | ||
| 111 | |||
| 112 | &set_label("end"); | ||
| 113 | |||
| 114 | if ($do_ip) | ||
| 115 | { | ||
| 116 | &comment(""); | ||
| 117 | &comment("FP"); | ||
| 118 | &mov("edx",&wparam(0)); | ||
| 119 | &FP_new($L,$R,"eax",3); | ||
| 120 | |||
| 121 | &mov(&DWP(0,"edx","",0),"eax"); | ||
| 122 | &mov(&DWP(4,"edx","",0),$R); | ||
| 123 | } | ||
| 124 | else | ||
| 125 | { | ||
| 126 | &comment(""); | ||
| 127 | &comment("Fixup"); | ||
| 128 | &rotr($L,3); # r | ||
| 129 | &mov("eax",&wparam(0)); | ||
| 130 | &rotr($R,3); # l | ||
| 131 | &mov(&DWP(0,"eax","",0),$L); | ||
| 132 | &mov(&DWP(4,"eax","",0),$R); | ||
| 133 | } | ||
| 134 | |||
| 135 | &pop("ebp"); | ||
| 136 | &pop("ebx"); | ||
| 137 | &pop("edi"); | ||
| 138 | &pop("esi"); | ||
| 139 | &ret(); | ||
| 140 | |||
| 141 | &function_end_B($name); | ||
| 142 | } | ||
| 143 | |||
| 144 | sub D_ENCRYPT | ||
| 145 | { | ||
| 146 | local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; | ||
| 147 | |||
| 148 | &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0)); | ||
| 149 | &xor( $tmp1, $tmp1); | ||
| 150 | &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0)); | ||
| 151 | &xor( $u, $R); | ||
| 152 | &xor( $tmp2, $tmp2); | ||
| 153 | &xor( $t, $R); | ||
| 154 | &and( $u, "0xfcfcfcfc" ); | ||
| 155 | &and( $t, "0xcfcfcfcf" ); | ||
| 156 | &movb( &LB($tmp1), &LB($u) ); | ||
| 157 | &movb( &LB($tmp2), &HB($u) ); | ||
| 158 | &rotr( $t, 4 ); | ||
| 159 | &xor( $L, &DWP(" ",$trans,$tmp1,0)); | ||
| 160 | &movb( &LB($tmp1), &LB($t) ); | ||
| 161 | &xor( $L, &DWP("0x200",$trans,$tmp2,0)); | ||
| 162 | &movb( &LB($tmp2), &HB($t) ); | ||
| 163 | &shr( $u, 16); | ||
| 164 | &xor( $L, &DWP("0x100",$trans,$tmp1,0)); | ||
| 165 | &movb( &LB($tmp1), &HB($u) ); | ||
| 166 | &shr( $t, 16); | ||
| 167 | &xor( $L, &DWP("0x300",$trans,$tmp2,0)); | ||
| 168 | &movb( &LB($tmp2), &HB($t) ); | ||
| 169 | &and( $u, "0xff" ); | ||
| 170 | &and( $t, "0xff" ); | ||
| 171 | &xor( $L, &DWP("0x600",$trans,$tmp1,0)); | ||
| 172 | &xor( $L, &DWP("0x700",$trans,$tmp2,0)); | ||
| 173 | &mov( $tmp2, &wparam(1) ); | ||
| 174 | &xor( $L, &DWP("0x400",$trans,$u,0)); | ||
| 175 | &xor( $L, &DWP("0x500",$trans,$t,0)); | ||
| 176 | } | ||
| 177 | |||
| 178 | sub n2a | ||
| 179 | { | ||
| 180 | sprintf("%d",$_[0]); | ||
| 181 | } | ||
| 182 | |||
| 183 | # now has a side affect of rotating $a by $shift | ||
| 184 | sub R_PERM_OP | ||
| 185 | { | ||
| 186 | local($a,$b,$tt,$shift,$mask,$last)=@_; | ||
| 187 | |||
| 188 | &rotl( $a, $shift ) if ($shift != 0); | ||
| 189 | &mov( $tt, $a ); | ||
| 190 | &xor( $a, $b ); | ||
| 191 | &and( $a, $mask ); | ||
| 192 | # This can never succeed, and besides it is difficult to see what the | ||
| 193 | # idea was - Ben 13 Feb 99 | ||
| 194 | if (!$last eq $b) | ||
| 195 | { | ||
| 196 | &xor( $b, $a ); | ||
| 197 | &xor( $tt, $a ); | ||
| 198 | } | ||
| 199 | else | ||
| 200 | { | ||
| 201 | &xor( $tt, $a ); | ||
| 202 | &xor( $b, $a ); | ||
| 203 | } | ||
| 204 | &comment(""); | ||
| 205 | } | ||
| 206 | |||
| 207 | sub IP_new | ||
| 208 | { | ||
| 209 | local($l,$r,$tt,$lr)=@_; | ||
| 210 | |||
| 211 | &R_PERM_OP($l,$r,$tt, 4,"0xf0f0f0f0",$l); | ||
| 212 | &R_PERM_OP($r,$tt,$l,20,"0xfff0000f",$l); | ||
| 213 | &R_PERM_OP($l,$tt,$r,14,"0x33333333",$r); | ||
| 214 | &R_PERM_OP($tt,$r,$l,22,"0x03fc03fc",$r); | ||
| 215 | &R_PERM_OP($l,$r,$tt, 9,"0xaaaaaaaa",$r); | ||
| 216 | |||
| 217 | if ($lr != 3) | ||
| 218 | { | ||
| 219 | if (($lr-3) < 0) | ||
| 220 | { &rotr($tt, 3-$lr); } | ||
| 221 | else { &rotl($tt, $lr-3); } | ||
| 222 | } | ||
| 223 | if ($lr != 2) | ||
| 224 | { | ||
| 225 | if (($lr-2) < 0) | ||
| 226 | { &rotr($r, 2-$lr); } | ||
| 227 | else { &rotl($r, $lr-2); } | ||
| 228 | } | ||
| 229 | } | ||
| 230 | |||
| 231 | sub FP_new | ||
| 232 | { | ||
| 233 | local($l,$r,$tt,$lr)=@_; | ||
| 234 | |||
| 235 | if ($lr != 2) | ||
| 236 | { | ||
| 237 | if (($lr-2) < 0) | ||
| 238 | { &rotl($r, 2-$lr); } | ||
| 239 | else { &rotr($r, $lr-2); } | ||
| 240 | } | ||
| 241 | if ($lr != 3) | ||
| 242 | { | ||
| 243 | if (($lr-3) < 0) | ||
| 244 | { &rotl($l, 3-$lr); } | ||
| 245 | else { &rotr($l, $lr-3); } | ||
| 246 | } | ||
| 247 | |||
| 248 | &R_PERM_OP($l,$r,$tt, 0,"0xaaaaaaaa",$r); | ||
| 249 | &R_PERM_OP($tt,$r,$l,23,"0x03fc03fc",$r); | ||
| 250 | &R_PERM_OP($l,$r,$tt,10,"0x33333333",$l); | ||
| 251 | &R_PERM_OP($r,$tt,$l,18,"0xfff0000f",$l); | ||
| 252 | &R_PERM_OP($l,$tt,$r,12,"0xf0f0f0f0",$r); | ||
| 253 | &rotr($tt , 4); | ||
| 254 | } | ||
| 255 | |||
diff --git a/src/lib/libcrypto/des/asm/des_enc.m4 b/src/lib/libcrypto/des/asm/des_enc.m4 new file mode 100644 index 0000000000..f5b1928f99 --- /dev/null +++ b/src/lib/libcrypto/des/asm/des_enc.m4 | |||
| @@ -0,0 +1,1980 @@ | |||
| 1 | ! des_enc.m4 | ||
| 2 | ! des_enc.S (generated from des_enc.m4) | ||
| 3 | ! | ||
| 4 | ! UltraSPARC assembler version of the LibDES/SSLeay/OpenSSL des_enc.c file. | ||
| 5 | ! | ||
| 6 | ! Version 1.0. 32-bit version. | ||
| 7 | ! | ||
| 8 | ! June 8, 2000. | ||
| 9 | ! | ||
| 10 | ! Version 2.0. 32/64-bit, PIC-ification, blended CPU adaptation | ||
| 11 | ! by Andy Polyakov. | ||
| 12 | ! | ||
| 13 | ! January 1, 2003. | ||
| 14 | ! | ||
| 15 | ! Assembler version: Copyright Svend Olaf Mikkelsen. | ||
| 16 | ! | ||
| 17 | ! Original C code: Copyright Eric A. Young. | ||
| 18 | ! | ||
| 19 | ! This code can be freely used by LibDES/SSLeay/OpenSSL users. | ||
| 20 | ! | ||
| 21 | ! The LibDES/SSLeay/OpenSSL copyright notices must be respected. | ||
| 22 | ! | ||
| 23 | ! This version can be redistributed. | ||
| 24 | ! | ||
| 25 | ! To expand the m4 macros: m4 -B 8192 des_enc.m4 > des_enc.S | ||
| 26 | ! | ||
| 27 | ! Global registers 1 to 5 are used. This is the same as done by the | ||
| 28 | ! cc compiler. The UltraSPARC load/store little endian feature is used. | ||
| 29 | ! | ||
| 30 | ! Instruction grouping often refers to one CPU cycle. | ||
| 31 | ! | ||
| 32 | ! Assemble through gcc: gcc -c -mcpu=ultrasparc -o des_enc.o des_enc.S | ||
| 33 | ! | ||
| 34 | ! Assemble through cc: cc -c -xarch=v8plusa -o des_enc.o des_enc.S | ||
| 35 | ! | ||
| 36 | ! Performance improvement according to './apps/openssl speed des' | ||
| 37 | ! | ||
| 38 | ! 32-bit build: | ||
| 39 | ! 23% faster than cc-5.2 -xarch=v8plus -xO5 | ||
| 40 | ! 115% faster than gcc-3.2.1 -m32 -mcpu=ultrasparc -O5 | ||
| 41 | ! 64-bit build: | ||
| 42 | ! 50% faster than cc-5.2 -xarch=v9 -xO5 | ||
| 43 | ! 100% faster than gcc-3.2.1 -m64 -mcpu=ultrasparc -O5 | ||
| 44 | ! | ||
| 45 | |||
| 46 | .ident "des_enc.m4 2.1" | ||
| 47 | |||
| 48 | #if defined(__SUNPRO_C) && defined(__sparcv9) | ||
| 49 | # define ABI64 /* They've said -xarch=v9 at command line */ | ||
| 50 | #elif defined(__GNUC__) && defined(__arch64__) | ||
| 51 | # define ABI64 /* They've said -m64 at command line */ | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #ifdef ABI64 | ||
| 55 | .register %g2,#scratch | ||
| 56 | .register %g3,#scratch | ||
| 57 | # define FRAME -192 | ||
| 58 | # define BIAS 2047 | ||
| 59 | # define LDPTR ldx | ||
| 60 | # define STPTR stx | ||
| 61 | # define ARG0 128 | ||
| 62 | # define ARGSZ 8 | ||
| 63 | # ifndef OPENSSL_SYSNAME_ULTRASPARC | ||
| 64 | # define OPENSSL_SYSNAME_ULTRASPARC | ||
| 65 | # endif | ||
| 66 | #else | ||
| 67 | # define FRAME -96 | ||
| 68 | # define BIAS 0 | ||
| 69 | # define LDPTR ld | ||
| 70 | # define STPTR st | ||
| 71 | # define ARG0 68 | ||
| 72 | # define ARGSZ 4 | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #define LOOPS 7 | ||
| 76 | |||
| 77 | #define global0 %g0 | ||
| 78 | #define global1 %g1 | ||
| 79 | #define global2 %g2 | ||
| 80 | #define global3 %g3 | ||
| 81 | #define global4 %g4 | ||
| 82 | #define global5 %g5 | ||
| 83 | |||
| 84 | #define local0 %l0 | ||
| 85 | #define local1 %l1 | ||
| 86 | #define local2 %l2 | ||
| 87 | #define local3 %l3 | ||
| 88 | #define local4 %l4 | ||
| 89 | #define local5 %l5 | ||
| 90 | #define local7 %l6 | ||
| 91 | #define local6 %l7 | ||
| 92 | |||
| 93 | #define in0 %i0 | ||
| 94 | #define in1 %i1 | ||
| 95 | #define in2 %i2 | ||
| 96 | #define in3 %i3 | ||
| 97 | #define in4 %i4 | ||
| 98 | #define in5 %i5 | ||
| 99 | #define in6 %i6 | ||
| 100 | #define in7 %i7 | ||
| 101 | |||
| 102 | #define out0 %o0 | ||
| 103 | #define out1 %o1 | ||
| 104 | #define out2 %o2 | ||
| 105 | #define out3 %o3 | ||
| 106 | #define out4 %o4 | ||
| 107 | #define out5 %o5 | ||
| 108 | #define out6 %o6 | ||
| 109 | #define out7 %o7 | ||
| 110 | |||
| 111 | #define stub stb | ||
| 112 | |||
| 113 | changequote({,}) | ||
| 114 | |||
| 115 | |||
| 116 | ! Macro definitions: | ||
| 117 | |||
| 118 | |||
| 119 | ! {ip_macro} | ||
| 120 | ! | ||
| 121 | ! The logic used in initial and final permutations is the same as in | ||
| 122 | ! the C code. The permutations are done with a clever shift, xor, and | ||
| 123 | ! technique. | ||
| 124 | ! | ||
| 125 | ! The macro also loads address sbox 1 to 5 to global 1 to 5, address | ||
| 126 | ! sbox 6 to local6, and addres sbox 8 to out3. | ||
| 127 | ! | ||
| 128 | ! Rotates the halfs 3 left to bring the sbox bits in convenient positions. | ||
| 129 | ! | ||
| 130 | ! Loads key first round from address in parameter 5 to out0, out1. | ||
| 131 | ! | ||
| 132 | ! After the the original LibDES initial permutation, the resulting left | ||
| 133 | ! is in the variable initially used for right and vice versa. The macro | ||
| 134 | ! implements the possibility to keep the halfs in the original registers. | ||
| 135 | ! | ||
| 136 | ! parameter 1 left | ||
| 137 | ! parameter 2 right | ||
| 138 | ! parameter 3 result left (modify in first round) | ||
| 139 | ! parameter 4 result right (use in first round) | ||
| 140 | ! parameter 5 key address | ||
| 141 | ! parameter 6 1/2 for include encryption/decryption | ||
| 142 | ! parameter 7 1 for move in1 to in3 | ||
| 143 | ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 | ||
| 144 | ! parameter 9 1 for load ks3 and ks2 to in4 and in3 | ||
| 145 | |||
| 146 | define(ip_macro, { | ||
| 147 | |||
| 148 | ! {ip_macro} | ||
| 149 | ! $1 $2 $4 $3 $5 $6 $7 $8 $9 | ||
| 150 | |||
| 151 | ld [out2+256], local1 | ||
| 152 | srl $2, 4, local4 | ||
| 153 | |||
| 154 | xor local4, $1, local4 | ||
| 155 | ifelse($7,1,{mov in1, in3},{nop}) | ||
| 156 | |||
| 157 | ld [out2+260], local2 | ||
| 158 | and local4, local1, local4 | ||
| 159 | ifelse($8,1,{mov in3, in4},{}) | ||
| 160 | ifelse($8,2,{mov in4, in3},{}) | ||
| 161 | |||
| 162 | ld [out2+280], out4 ! loop counter | ||
| 163 | sll local4, 4, local1 | ||
| 164 | xor $1, local4, $1 | ||
| 165 | |||
| 166 | ld [out2+264], local3 | ||
| 167 | srl $1, 16, local4 | ||
| 168 | xor $2, local1, $2 | ||
| 169 | |||
| 170 | ifelse($9,1,{LDPTR KS3, in4},{}) | ||
| 171 | xor local4, $2, local4 | ||
| 172 | nop !sethi %hi(DES_SPtrans), global1 ! sbox addr | ||
| 173 | |||
| 174 | ifelse($9,1,{LDPTR KS2, in3},{}) | ||
| 175 | and local4, local2, local4 | ||
| 176 | nop !or global1, %lo(DES_SPtrans), global1 ! sbox addr | ||
| 177 | |||
| 178 | sll local4, 16, local1 | ||
| 179 | xor $2, local4, $2 | ||
| 180 | |||
| 181 | srl $2, 2, local4 | ||
| 182 | xor $1, local1, $1 | ||
| 183 | |||
| 184 | sethi %hi(16711680), local5 | ||
| 185 | xor local4, $1, local4 | ||
| 186 | |||
| 187 | and local4, local3, local4 | ||
| 188 | or local5, 255, local5 | ||
| 189 | |||
| 190 | sll local4, 2, local2 | ||
| 191 | xor $1, local4, $1 | ||
| 192 | |||
| 193 | srl $1, 8, local4 | ||
| 194 | xor $2, local2, $2 | ||
| 195 | |||
| 196 | xor local4, $2, local4 | ||
| 197 | add global1, 768, global4 | ||
| 198 | |||
| 199 | and local4, local5, local4 | ||
| 200 | add global1, 1024, global5 | ||
| 201 | |||
| 202 | ld [out2+272], local7 | ||
| 203 | sll local4, 8, local1 | ||
| 204 | xor $2, local4, $2 | ||
| 205 | |||
| 206 | srl $2, 1, local4 | ||
| 207 | xor $1, local1, $1 | ||
| 208 | |||
| 209 | ld [$5], out0 ! key 7531 | ||
| 210 | xor local4, $1, local4 | ||
| 211 | add global1, 256, global2 | ||
| 212 | |||
| 213 | ld [$5+4], out1 ! key 8642 | ||
| 214 | and local4, local7, local4 | ||
| 215 | add global1, 512, global3 | ||
| 216 | |||
| 217 | sll local4, 1, local1 | ||
| 218 | xor $1, local4, $1 | ||
| 219 | |||
| 220 | sll $1, 3, local3 | ||
| 221 | xor $2, local1, $2 | ||
| 222 | |||
| 223 | sll $2, 3, local2 | ||
| 224 | add global1, 1280, local6 ! address sbox 8 | ||
| 225 | |||
| 226 | srl $1, 29, local4 | ||
| 227 | add global1, 1792, out3 ! address sbox 8 | ||
| 228 | |||
| 229 | srl $2, 29, local1 | ||
| 230 | or local4, local3, $4 | ||
| 231 | |||
| 232 | or local2, local1, $3 | ||
| 233 | |||
| 234 | ifelse($6, 1, { | ||
| 235 | |||
| 236 | ld [out2+284], local5 ! 0x0000FC00 used in the rounds | ||
| 237 | or local2, local1, $3 | ||
| 238 | xor $4, out0, local1 | ||
| 239 | |||
| 240 | call .des_enc.1 | ||
| 241 | and local1, 252, local1 | ||
| 242 | |||
| 243 | },{}) | ||
| 244 | |||
| 245 | ifelse($6, 2, { | ||
| 246 | |||
| 247 | ld [out2+284], local5 ! 0x0000FC00 used in the rounds | ||
| 248 | or local2, local1, $3 | ||
| 249 | xor $4, out0, local1 | ||
| 250 | |||
| 251 | call .des_dec.1 | ||
| 252 | and local1, 252, local1 | ||
| 253 | |||
| 254 | },{}) | ||
| 255 | }) | ||
| 256 | |||
| 257 | |||
| 258 | ! {rounds_macro} | ||
| 259 | ! | ||
| 260 | ! The logic used in the DES rounds is the same as in the C code, | ||
| 261 | ! except that calculations for sbox 1 and sbox 5 begin before | ||
| 262 | ! the previous round is finished. | ||
| 263 | ! | ||
| 264 | ! In each round one half (work) is modified based on key and the | ||
| 265 | ! other half (use). | ||
| 266 | ! | ||
| 267 | ! In this version we do two rounds in a loop repeated 7 times | ||
| 268 | ! and two rounds seperately. | ||
| 269 | ! | ||
| 270 | ! One half has the bits for the sboxes in the following positions: | ||
| 271 | ! | ||
| 272 | ! 777777xx555555xx333333xx111111xx | ||
| 273 | ! | ||
| 274 | ! 88xx666666xx444444xx222222xx8888 | ||
| 275 | ! | ||
| 276 | ! The bits for each sbox are xor-ed with the key bits for that box. | ||
| 277 | ! The above xx bits are cleared, and the result used for lookup in | ||
| 278 | ! the sbox table. Each sbox entry contains the 4 output bits permuted | ||
| 279 | ! into 32 bits according to the P permutation. | ||
| 280 | ! | ||
| 281 | ! In the description of DES, left and right are switched after | ||
| 282 | ! each round, except after last round. In this code the original | ||
| 283 | ! left and right are kept in the same register in all rounds, meaning | ||
| 284 | ! that after the 16 rounds the result for right is in the register | ||
| 285 | ! originally used for left. | ||
| 286 | ! | ||
| 287 | ! parameter 1 first work (left in first round) | ||
| 288 | ! parameter 2 first use (right in first round) | ||
| 289 | ! parameter 3 enc/dec 1/-1 | ||
| 290 | ! parameter 4 loop label | ||
| 291 | ! parameter 5 key address register | ||
| 292 | ! parameter 6 optional address for key next encryption/decryption | ||
| 293 | ! parameter 7 not empty for include retl | ||
| 294 | ! | ||
| 295 | ! also compares in2 to 8 | ||
| 296 | |||
| 297 | define(rounds_macro, { | ||
| 298 | |||
| 299 | ! {rounds_macro} | ||
| 300 | ! $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
| 301 | |||
| 302 | xor $2, out0, local1 | ||
| 303 | |||
| 304 | ld [out2+284], local5 ! 0x0000FC00 | ||
| 305 | ba $4 | ||
| 306 | and local1, 252, local1 | ||
| 307 | |||
| 308 | .align 32 | ||
| 309 | |||
| 310 | $4: | ||
| 311 | ! local6 is address sbox 6 | ||
| 312 | ! out3 is address sbox 8 | ||
| 313 | ! out4 is loop counter | ||
| 314 | |||
| 315 | ld [global1+local1], local1 | ||
| 316 | xor $2, out1, out1 ! 8642 | ||
| 317 | xor $2, out0, out0 ! 7531 | ||
| 318 | fmovs %f0, %f0 ! fxor used for alignment | ||
| 319 | |||
| 320 | srl out1, 4, local0 ! rotate 4 right | ||
| 321 | and out0, local5, local3 ! 3 | ||
| 322 | fmovs %f0, %f0 | ||
| 323 | |||
| 324 | ld [$5+$3*8], local7 ! key 7531 next round | ||
| 325 | srl local3, 8, local3 ! 3 | ||
| 326 | and local0, 252, local2 ! 2 | ||
| 327 | fmovs %f0, %f0 | ||
| 328 | |||
| 329 | ld [global3+local3],local3 ! 3 | ||
| 330 | sll out1, 28, out1 ! rotate | ||
| 331 | xor $1, local1, $1 ! 1 finished, local1 now sbox 7 | ||
| 332 | |||
| 333 | ld [global2+local2], local2 ! 2 | ||
| 334 | srl out0, 24, local1 ! 7 | ||
| 335 | or out1, local0, out1 ! rotate | ||
| 336 | |||
| 337 | ldub [out2+local1], local1 ! 7 (and 0xFC) | ||
| 338 | srl out1, 24, local0 ! 8 | ||
| 339 | and out1, local5, local4 ! 4 | ||
| 340 | |||
| 341 | ldub [out2+local0], local0 ! 8 (and 0xFC) | ||
| 342 | srl local4, 8, local4 ! 4 | ||
| 343 | xor $1, local2, $1 ! 2 finished local2 now sbox 6 | ||
| 344 | |||
| 345 | ld [global4+local4],local4 ! 4 | ||
| 346 | srl out1, 16, local2 ! 6 | ||
| 347 | xor $1, local3, $1 ! 3 finished local3 now sbox 5 | ||
| 348 | |||
| 349 | ld [out3+local0],local0 ! 8 | ||
| 350 | and local2, 252, local2 ! 6 | ||
| 351 | add global1, 1536, local5 ! address sbox 7 | ||
| 352 | |||
| 353 | ld [local6+local2], local2 ! 6 | ||
| 354 | srl out0, 16, local3 ! 5 | ||
| 355 | xor $1, local4, $1 ! 4 finished | ||
| 356 | |||
| 357 | ld [local5+local1],local1 ! 7 | ||
| 358 | and local3, 252, local3 ! 5 | ||
| 359 | xor $1, local0, $1 ! 8 finished | ||
| 360 | |||
| 361 | ld [global5+local3],local3 ! 5 | ||
| 362 | xor $1, local2, $1 ! 6 finished | ||
| 363 | subcc out4, 1, out4 | ||
| 364 | |||
| 365 | ld [$5+$3*8+4], out0 ! key 8642 next round | ||
| 366 | xor $1, local7, local2 ! sbox 5 next round | ||
| 367 | xor $1, local1, $1 ! 7 finished | ||
| 368 | |||
| 369 | srl local2, 16, local2 ! sbox 5 next round | ||
| 370 | xor $1, local3, $1 ! 5 finished | ||
| 371 | |||
| 372 | ld [$5+$3*16+4], out1 ! key 8642 next round again | ||
| 373 | and local2, 252, local2 ! sbox5 next round | ||
| 374 | ! next round | ||
| 375 | xor $1, local7, local7 ! 7531 | ||
| 376 | |||
| 377 | ld [global5+local2], local2 ! 5 | ||
| 378 | srl local7, 24, local3 ! 7 | ||
| 379 | xor $1, out0, out0 ! 8642 | ||
| 380 | |||
| 381 | ldub [out2+local3], local3 ! 7 (and 0xFC) | ||
| 382 | srl out0, 4, local0 ! rotate 4 right | ||
| 383 | and local7, 252, local1 ! 1 | ||
| 384 | |||
| 385 | sll out0, 28, out0 ! rotate | ||
| 386 | xor $2, local2, $2 ! 5 finished local2 used | ||
| 387 | |||
| 388 | srl local0, 8, local4 ! 4 | ||
| 389 | and local0, 252, local2 ! 2 | ||
| 390 | ld [local5+local3], local3 ! 7 | ||
| 391 | |||
| 392 | srl local0, 16, local5 ! 6 | ||
| 393 | or out0, local0, out0 ! rotate | ||
| 394 | ld [global2+local2], local2 ! 2 | ||
| 395 | |||
| 396 | srl out0, 24, local0 | ||
| 397 | ld [$5+$3*16], out0 ! key 7531 next round | ||
| 398 | and local4, 252, local4 ! 4 | ||
| 399 | |||
| 400 | and local5, 252, local5 ! 6 | ||
| 401 | ld [global4+local4], local4 ! 4 | ||
| 402 | xor $2, local3, $2 ! 7 finished local3 used | ||
| 403 | |||
| 404 | and local0, 252, local0 ! 8 | ||
| 405 | ld [local6+local5], local5 ! 6 | ||
| 406 | xor $2, local2, $2 ! 2 finished local2 now sbox 3 | ||
| 407 | |||
| 408 | srl local7, 8, local2 ! 3 start | ||
| 409 | ld [out3+local0], local0 ! 8 | ||
| 410 | xor $2, local4, $2 ! 4 finished | ||
| 411 | |||
| 412 | and local2, 252, local2 ! 3 | ||
| 413 | ld [global1+local1], local1 ! 1 | ||
| 414 | xor $2, local5, $2 ! 6 finished local5 used | ||
| 415 | |||
| 416 | ld [global3+local2], local2 ! 3 | ||
| 417 | xor $2, local0, $2 ! 8 finished | ||
| 418 | add $5, $3*16, $5 ! enc add 8, dec add -8 to key pointer | ||
| 419 | |||
| 420 | ld [out2+284], local5 ! 0x0000FC00 | ||
| 421 | xor $2, out0, local4 ! sbox 1 next round | ||
| 422 | xor $2, local1, $2 ! 1 finished | ||
| 423 | |||
| 424 | xor $2, local2, $2 ! 3 finished | ||
| 425 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 426 | bne,pt %icc, $4 | ||
| 427 | #else | ||
| 428 | bne $4 | ||
| 429 | #endif | ||
| 430 | and local4, 252, local1 ! sbox 1 next round | ||
| 431 | |||
| 432 | ! two rounds more: | ||
| 433 | |||
| 434 | ld [global1+local1], local1 | ||
| 435 | xor $2, out1, out1 | ||
| 436 | xor $2, out0, out0 | ||
| 437 | |||
| 438 | srl out1, 4, local0 ! rotate | ||
| 439 | and out0, local5, local3 | ||
| 440 | |||
| 441 | ld [$5+$3*8], local7 ! key 7531 | ||
| 442 | srl local3, 8, local3 | ||
| 443 | and local0, 252, local2 | ||
| 444 | |||
| 445 | ld [global3+local3],local3 | ||
| 446 | sll out1, 28, out1 ! rotate | ||
| 447 | xor $1, local1, $1 ! 1 finished, local1 now sbox 7 | ||
| 448 | |||
| 449 | ld [global2+local2], local2 | ||
| 450 | srl out0, 24, local1 | ||
| 451 | or out1, local0, out1 ! rotate | ||
| 452 | |||
| 453 | ldub [out2+local1], local1 | ||
| 454 | srl out1, 24, local0 | ||
| 455 | and out1, local5, local4 | ||
| 456 | |||
| 457 | ldub [out2+local0], local0 | ||
| 458 | srl local4, 8, local4 | ||
| 459 | xor $1, local2, $1 ! 2 finished local2 now sbox 6 | ||
| 460 | |||
| 461 | ld [global4+local4],local4 | ||
| 462 | srl out1, 16, local2 | ||
| 463 | xor $1, local3, $1 ! 3 finished local3 now sbox 5 | ||
| 464 | |||
| 465 | ld [out3+local0],local0 | ||
| 466 | and local2, 252, local2 | ||
| 467 | add global1, 1536, local5 ! address sbox 7 | ||
| 468 | |||
| 469 | ld [local6+local2], local2 | ||
| 470 | srl out0, 16, local3 | ||
| 471 | xor $1, local4, $1 ! 4 finished | ||
| 472 | |||
| 473 | ld [local5+local1],local1 | ||
| 474 | and local3, 252, local3 | ||
| 475 | xor $1, local0, $1 | ||
| 476 | |||
| 477 | ld [global5+local3],local3 | ||
| 478 | xor $1, local2, $1 ! 6 finished | ||
| 479 | cmp in2, 8 | ||
| 480 | |||
| 481 | ifelse($6,{}, {}, {ld [out2+280], out4}) ! loop counter | ||
| 482 | xor $1, local7, local2 ! sbox 5 next round | ||
| 483 | xor $1, local1, $1 ! 7 finished | ||
| 484 | |||
| 485 | ld [$5+$3*8+4], out0 | ||
| 486 | srl local2, 16, local2 ! sbox 5 next round | ||
| 487 | xor $1, local3, $1 ! 5 finished | ||
| 488 | |||
| 489 | and local2, 252, local2 | ||
| 490 | ! next round (two rounds more) | ||
| 491 | xor $1, local7, local7 ! 7531 | ||
| 492 | |||
| 493 | ld [global5+local2], local2 | ||
| 494 | srl local7, 24, local3 | ||
| 495 | xor $1, out0, out0 ! 8642 | ||
| 496 | |||
| 497 | ldub [out2+local3], local3 | ||
| 498 | srl out0, 4, local0 ! rotate | ||
| 499 | and local7, 252, local1 | ||
| 500 | |||
| 501 | sll out0, 28, out0 ! rotate | ||
| 502 | xor $2, local2, $2 ! 5 finished local2 used | ||
| 503 | |||
| 504 | srl local0, 8, local4 | ||
| 505 | and local0, 252, local2 | ||
| 506 | ld [local5+local3], local3 | ||
| 507 | |||
| 508 | srl local0, 16, local5 | ||
| 509 | or out0, local0, out0 ! rotate | ||
| 510 | ld [global2+local2], local2 | ||
| 511 | |||
| 512 | srl out0, 24, local0 | ||
| 513 | ifelse($6,{}, {}, {ld [$6], out0}) ! key next encryption/decryption | ||
| 514 | and local4, 252, local4 | ||
| 515 | |||
| 516 | and local5, 252, local5 | ||
| 517 | ld [global4+local4], local4 | ||
| 518 | xor $2, local3, $2 ! 7 finished local3 used | ||
| 519 | |||
| 520 | and local0, 252, local0 | ||
| 521 | ld [local6+local5], local5 | ||
| 522 | xor $2, local2, $2 ! 2 finished local2 now sbox 3 | ||
| 523 | |||
| 524 | srl local7, 8, local2 ! 3 start | ||
| 525 | ld [out3+local0], local0 | ||
| 526 | xor $2, local4, $2 | ||
| 527 | |||
| 528 | and local2, 252, local2 | ||
| 529 | ld [global1+local1], local1 | ||
| 530 | xor $2, local5, $2 ! 6 finished local5 used | ||
| 531 | |||
| 532 | ld [global3+local2], local2 | ||
| 533 | srl $1, 3, local3 | ||
| 534 | xor $2, local0, $2 | ||
| 535 | |||
| 536 | ifelse($6,{}, {}, {ld [$6+4], out1}) ! key next encryption/decryption | ||
| 537 | sll $1, 29, local4 | ||
| 538 | xor $2, local1, $2 | ||
| 539 | |||
| 540 | ifelse($7,{}, {}, {retl}) | ||
| 541 | xor $2, local2, $2 | ||
| 542 | }) | ||
| 543 | |||
| 544 | |||
| 545 | ! {fp_macro} | ||
| 546 | ! | ||
| 547 | ! parameter 1 right (original left) | ||
| 548 | ! parameter 2 left (original right) | ||
| 549 | ! parameter 3 1 for optional store to [in0] | ||
| 550 | ! parameter 4 1 for load input/output address to local5/7 | ||
| 551 | ! | ||
| 552 | ! The final permutation logic switches the halfes, meaning that | ||
| 553 | ! left and right ends up the the registers originally used. | ||
| 554 | |||
| 555 | define(fp_macro, { | ||
| 556 | |||
| 557 | ! {fp_macro} | ||
| 558 | ! $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
| 559 | |||
| 560 | ! initially undo the rotate 3 left done after initial permutation | ||
| 561 | ! original left is received shifted 3 right and 29 left in local3/4 | ||
| 562 | |||
| 563 | sll $2, 29, local1 | ||
| 564 | or local3, local4, $1 | ||
| 565 | |||
| 566 | srl $2, 3, $2 | ||
| 567 | sethi %hi(0x55555555), local2 | ||
| 568 | |||
| 569 | or $2, local1, $2 | ||
| 570 | or local2, %lo(0x55555555), local2 | ||
| 571 | |||
| 572 | srl $2, 1, local3 | ||
| 573 | sethi %hi(0x00ff00ff), local1 | ||
| 574 | xor local3, $1, local3 | ||
| 575 | or local1, %lo(0x00ff00ff), local1 | ||
| 576 | and local3, local2, local3 | ||
| 577 | sethi %hi(0x33333333), local4 | ||
| 578 | sll local3, 1, local2 | ||
| 579 | |||
| 580 | xor $1, local3, $1 | ||
| 581 | |||
| 582 | srl $1, 8, local3 | ||
| 583 | xor $2, local2, $2 | ||
| 584 | xor local3, $2, local3 | ||
| 585 | or local4, %lo(0x33333333), local4 | ||
| 586 | and local3, local1, local3 | ||
| 587 | sethi %hi(0x0000ffff), local1 | ||
| 588 | sll local3, 8, local2 | ||
| 589 | |||
| 590 | xor $2, local3, $2 | ||
| 591 | |||
| 592 | srl $2, 2, local3 | ||
| 593 | xor $1, local2, $1 | ||
| 594 | xor local3, $1, local3 | ||
| 595 | or local1, %lo(0x0000ffff), local1 | ||
| 596 | and local3, local4, local3 | ||
| 597 | sethi %hi(0x0f0f0f0f), local4 | ||
| 598 | sll local3, 2, local2 | ||
| 599 | |||
| 600 | ifelse($4,1, {LDPTR INPUT, local5}) | ||
| 601 | xor $1, local3, $1 | ||
| 602 | |||
| 603 | ifelse($4,1, {LDPTR OUTPUT, local7}) | ||
| 604 | srl $1, 16, local3 | ||
| 605 | xor $2, local2, $2 | ||
| 606 | xor local3, $2, local3 | ||
| 607 | or local4, %lo(0x0f0f0f0f), local4 | ||
| 608 | and local3, local1, local3 | ||
| 609 | sll local3, 16, local2 | ||
| 610 | |||
| 611 | xor $2, local3, local1 | ||
| 612 | |||
| 613 | srl local1, 4, local3 | ||
| 614 | xor $1, local2, $1 | ||
| 615 | xor local3, $1, local3 | ||
| 616 | and local3, local4, local3 | ||
| 617 | sll local3, 4, local2 | ||
| 618 | |||
| 619 | xor $1, local3, $1 | ||
| 620 | |||
| 621 | ! optional store: | ||
| 622 | |||
| 623 | ifelse($3,1, {st $1, [in0]}) | ||
| 624 | |||
| 625 | xor local1, local2, $2 | ||
| 626 | |||
| 627 | ifelse($3,1, {st $2, [in0+4]}) | ||
| 628 | |||
| 629 | }) | ||
| 630 | |||
| 631 | |||
| 632 | ! {fp_ip_macro} | ||
| 633 | ! | ||
| 634 | ! Does initial permutation for next block mixed with | ||
| 635 | ! final permutation for current block. | ||
| 636 | ! | ||
| 637 | ! parameter 1 original left | ||
| 638 | ! parameter 2 original right | ||
| 639 | ! parameter 3 left ip | ||
| 640 | ! parameter 4 right ip | ||
| 641 | ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4 | ||
| 642 | ! 2: mov in4 to in3 | ||
| 643 | ! | ||
| 644 | ! also adds -8 to length in2 and loads loop counter to out4 | ||
| 645 | |||
| 646 | define(fp_ip_macro, { | ||
| 647 | |||
| 648 | ! {fp_ip_macro} | ||
| 649 | ! $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
| 650 | |||
| 651 | define({temp1},{out4}) | ||
| 652 | define({temp2},{local3}) | ||
| 653 | |||
| 654 | define({ip1},{local1}) | ||
| 655 | define({ip2},{local2}) | ||
| 656 | define({ip4},{local4}) | ||
| 657 | define({ip5},{local5}) | ||
| 658 | |||
| 659 | ! $1 in local3, local4 | ||
| 660 | |||
| 661 | ld [out2+256], ip1 | ||
| 662 | sll out5, 29, temp1 | ||
| 663 | or local3, local4, $1 | ||
| 664 | |||
| 665 | srl out5, 3, $2 | ||
| 666 | ifelse($5,2,{mov in4, in3}) | ||
| 667 | |||
| 668 | ld [out2+272], ip5 | ||
| 669 | srl $4, 4, local0 | ||
| 670 | or $2, temp1, $2 | ||
| 671 | |||
| 672 | srl $2, 1, temp1 | ||
| 673 | xor temp1, $1, temp1 | ||
| 674 | |||
| 675 | and temp1, ip5, temp1 | ||
| 676 | xor local0, $3, local0 | ||
| 677 | |||
| 678 | sll temp1, 1, temp2 | ||
| 679 | xor $1, temp1, $1 | ||
| 680 | |||
| 681 | and local0, ip1, local0 | ||
| 682 | add in2, -8, in2 | ||
| 683 | |||
| 684 | sll local0, 4, local7 | ||
| 685 | xor $3, local0, $3 | ||
| 686 | |||
| 687 | ld [out2+268], ip4 | ||
| 688 | srl $1, 8, temp1 | ||
| 689 | xor $2, temp2, $2 | ||
| 690 | ld [out2+260], ip2 | ||
| 691 | srl $3, 16, local0 | ||
| 692 | xor $4, local7, $4 | ||
| 693 | xor temp1, $2, temp1 | ||
| 694 | xor local0, $4, local0 | ||
| 695 | and temp1, ip4, temp1 | ||
| 696 | and local0, ip2, local0 | ||
| 697 | sll temp1, 8, temp2 | ||
| 698 | xor $2, temp1, $2 | ||
| 699 | sll local0, 16, local7 | ||
| 700 | xor $4, local0, $4 | ||
| 701 | |||
| 702 | srl $2, 2, temp1 | ||
| 703 | xor $1, temp2, $1 | ||
| 704 | |||
| 705 | ld [out2+264], temp2 ! ip3 | ||
| 706 | srl $4, 2, local0 | ||
| 707 | xor $3, local7, $3 | ||
| 708 | xor temp1, $1, temp1 | ||
| 709 | xor local0, $3, local0 | ||
| 710 | and temp1, temp2, temp1 | ||
| 711 | and local0, temp2, local0 | ||
| 712 | sll temp1, 2, temp2 | ||
| 713 | xor $1, temp1, $1 | ||
| 714 | sll local0, 2, local7 | ||
| 715 | xor $3, local0, $3 | ||
| 716 | |||
| 717 | srl $1, 16, temp1 | ||
| 718 | xor $2, temp2, $2 | ||
| 719 | srl $3, 8, local0 | ||
| 720 | xor $4, local7, $4 | ||
| 721 | xor temp1, $2, temp1 | ||
| 722 | xor local0, $4, local0 | ||
| 723 | and temp1, ip2, temp1 | ||
| 724 | and local0, ip4, local0 | ||
| 725 | sll temp1, 16, temp2 | ||
| 726 | xor $2, temp1, local4 | ||
| 727 | sll local0, 8, local7 | ||
| 728 | xor $4, local0, $4 | ||
| 729 | |||
| 730 | srl $4, 1, local0 | ||
| 731 | xor $3, local7, $3 | ||
| 732 | |||
| 733 | srl local4, 4, temp1 | ||
| 734 | xor local0, $3, local0 | ||
| 735 | |||
| 736 | xor $1, temp2, $1 | ||
| 737 | and local0, ip5, local0 | ||
| 738 | |||
| 739 | sll local0, 1, local7 | ||
| 740 | xor temp1, $1, temp1 | ||
| 741 | |||
| 742 | xor $3, local0, $3 | ||
| 743 | xor $4, local7, $4 | ||
| 744 | |||
| 745 | sll $3, 3, local5 | ||
| 746 | and temp1, ip1, temp1 | ||
| 747 | |||
| 748 | sll temp1, 4, temp2 | ||
| 749 | xor $1, temp1, $1 | ||
| 750 | |||
| 751 | ifelse($5,1,{LDPTR KS2, in4}) | ||
| 752 | sll $4, 3, local2 | ||
| 753 | xor local4, temp2, $2 | ||
| 754 | |||
| 755 | ! reload since used as temporar: | ||
| 756 | |||
| 757 | ld [out2+280], out4 ! loop counter | ||
| 758 | |||
| 759 | srl $3, 29, local0 | ||
| 760 | ifelse($5,1,{add in4, 120, in4}) | ||
| 761 | |||
| 762 | ifelse($5,1,{LDPTR KS1, in3}) | ||
| 763 | srl $4, 29, local7 | ||
| 764 | |||
| 765 | or local0, local5, $4 | ||
| 766 | or local2, local7, $3 | ||
| 767 | |||
| 768 | }) | ||
| 769 | |||
| 770 | |||
| 771 | |||
| 772 | ! {load_little_endian} | ||
| 773 | ! | ||
| 774 | ! parameter 1 address | ||
| 775 | ! parameter 2 destination left | ||
| 776 | ! parameter 3 destination right | ||
| 777 | ! parameter 4 temporar | ||
| 778 | ! parameter 5 label | ||
| 779 | |||
| 780 | define(load_little_endian, { | ||
| 781 | |||
| 782 | ! {load_little_endian} | ||
| 783 | ! $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
| 784 | |||
| 785 | ! first in memory to rightmost in register | ||
| 786 | |||
| 787 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 788 | andcc $1, 3, global0 | ||
| 789 | bne,pn %icc, $5 | ||
| 790 | nop | ||
| 791 | |||
| 792 | lda [$1] 0x88, $2 | ||
| 793 | add $1, 4, $4 | ||
| 794 | |||
| 795 | ba,pt %icc, $5a | ||
| 796 | lda [$4] 0x88, $3 | ||
| 797 | #endif | ||
| 798 | |||
| 799 | $5: | ||
| 800 | ldub [$1+3], $2 | ||
| 801 | |||
| 802 | ldub [$1+2], $4 | ||
| 803 | sll $2, 8, $2 | ||
| 804 | or $2, $4, $2 | ||
| 805 | |||
| 806 | ldub [$1+1], $4 | ||
| 807 | sll $2, 8, $2 | ||
| 808 | or $2, $4, $2 | ||
| 809 | |||
| 810 | ldub [$1+0], $4 | ||
| 811 | sll $2, 8, $2 | ||
| 812 | or $2, $4, $2 | ||
| 813 | |||
| 814 | |||
| 815 | ldub [$1+3+4], $3 | ||
| 816 | |||
| 817 | ldub [$1+2+4], $4 | ||
| 818 | sll $3, 8, $3 | ||
| 819 | or $3, $4, $3 | ||
| 820 | |||
| 821 | ldub [$1+1+4], $4 | ||
| 822 | sll $3, 8, $3 | ||
| 823 | or $3, $4, $3 | ||
| 824 | |||
| 825 | ldub [$1+0+4], $4 | ||
| 826 | sll $3, 8, $3 | ||
| 827 | or $3, $4, $3 | ||
| 828 | $5a: | ||
| 829 | |||
| 830 | }) | ||
| 831 | |||
| 832 | |||
| 833 | ! {load_little_endian_inc} | ||
| 834 | ! | ||
| 835 | ! parameter 1 address | ||
| 836 | ! parameter 2 destination left | ||
| 837 | ! parameter 3 destination right | ||
| 838 | ! parameter 4 temporar | ||
| 839 | ! parameter 4 label | ||
| 840 | ! | ||
| 841 | ! adds 8 to address | ||
| 842 | |||
| 843 | define(load_little_endian_inc, { | ||
| 844 | |||
| 845 | ! {load_little_endian_inc} | ||
| 846 | ! $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
| 847 | |||
| 848 | ! first in memory to rightmost in register | ||
| 849 | |||
| 850 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 851 | andcc $1, 3, global0 | ||
| 852 | bne,pn %icc, $5 | ||
| 853 | nop | ||
| 854 | |||
| 855 | lda [$1] 0x88, $2 | ||
| 856 | add $1, 4, $1 | ||
| 857 | |||
| 858 | lda [$1] 0x88, $3 | ||
| 859 | ba,pt %icc, $5a | ||
| 860 | add $1, 4, $1 | ||
| 861 | #endif | ||
| 862 | |||
| 863 | $5: | ||
| 864 | ldub [$1+3], $2 | ||
| 865 | |||
| 866 | ldub [$1+2], $4 | ||
| 867 | sll $2, 8, $2 | ||
| 868 | or $2, $4, $2 | ||
| 869 | |||
| 870 | ldub [$1+1], $4 | ||
| 871 | sll $2, 8, $2 | ||
| 872 | or $2, $4, $2 | ||
| 873 | |||
| 874 | ldub [$1+0], $4 | ||
| 875 | sll $2, 8, $2 | ||
| 876 | or $2, $4, $2 | ||
| 877 | |||
| 878 | ldub [$1+3+4], $3 | ||
| 879 | add $1, 8, $1 | ||
| 880 | |||
| 881 | ldub [$1+2+4-8], $4 | ||
| 882 | sll $3, 8, $3 | ||
| 883 | or $3, $4, $3 | ||
| 884 | |||
| 885 | ldub [$1+1+4-8], $4 | ||
| 886 | sll $3, 8, $3 | ||
| 887 | or $3, $4, $3 | ||
| 888 | |||
| 889 | ldub [$1+0+4-8], $4 | ||
| 890 | sll $3, 8, $3 | ||
| 891 | or $3, $4, $3 | ||
| 892 | $5a: | ||
| 893 | |||
| 894 | }) | ||
| 895 | |||
| 896 | |||
| 897 | ! {load_n_bytes} | ||
| 898 | ! | ||
| 899 | ! Loads 1 to 7 bytes little endian | ||
| 900 | ! Remaining bytes are zeroed. | ||
| 901 | ! | ||
| 902 | ! parameter 1 address | ||
| 903 | ! parameter 2 length | ||
| 904 | ! parameter 3 destination register left | ||
| 905 | ! parameter 4 destination register right | ||
| 906 | ! parameter 5 temp | ||
| 907 | ! parameter 6 temp2 | ||
| 908 | ! parameter 7 label | ||
| 909 | ! parameter 8 return label | ||
| 910 | |||
| 911 | define(load_n_bytes, { | ||
| 912 | |||
| 913 | ! {load_n_bytes} | ||
| 914 | ! $1 $2 $5 $6 $7 $8 $7 $8 $9 | ||
| 915 | |||
| 916 | $7.0: call .+8 | ||
| 917 | sll $2, 2, $6 | ||
| 918 | |||
| 919 | add %o7,$7.jmp.table-$7.0,$5 | ||
| 920 | |||
| 921 | add $5, $6, $5 | ||
| 922 | mov 0, $4 | ||
| 923 | |||
| 924 | ld [$5], $5 | ||
| 925 | |||
| 926 | jmp %o7+$5 | ||
| 927 | mov 0, $3 | ||
| 928 | |||
| 929 | $7.7: | ||
| 930 | ldub [$1+6], $5 | ||
| 931 | sll $5, 16, $5 | ||
| 932 | or $3, $5, $3 | ||
| 933 | $7.6: | ||
| 934 | ldub [$1+5], $5 | ||
| 935 | sll $5, 8, $5 | ||
| 936 | or $3, $5, $3 | ||
| 937 | $7.5: | ||
| 938 | ldub [$1+4], $5 | ||
| 939 | or $3, $5, $3 | ||
| 940 | $7.4: | ||
| 941 | ldub [$1+3], $5 | ||
| 942 | sll $5, 24, $5 | ||
| 943 | or $4, $5, $4 | ||
| 944 | $7.3: | ||
| 945 | ldub [$1+2], $5 | ||
| 946 | sll $5, 16, $5 | ||
| 947 | or $4, $5, $4 | ||
| 948 | $7.2: | ||
| 949 | ldub [$1+1], $5 | ||
| 950 | sll $5, 8, $5 | ||
| 951 | or $4, $5, $4 | ||
| 952 | $7.1: | ||
| 953 | ldub [$1+0], $5 | ||
| 954 | ba $8 | ||
| 955 | or $4, $5, $4 | ||
| 956 | |||
| 957 | .align 4 | ||
| 958 | |||
| 959 | $7.jmp.table: | ||
| 960 | .word 0 | ||
| 961 | .word $7.1-$7.0 | ||
| 962 | .word $7.2-$7.0 | ||
| 963 | .word $7.3-$7.0 | ||
| 964 | .word $7.4-$7.0 | ||
| 965 | .word $7.5-$7.0 | ||
| 966 | .word $7.6-$7.0 | ||
| 967 | .word $7.7-$7.0 | ||
| 968 | }) | ||
| 969 | |||
| 970 | |||
| 971 | ! {store_little_endian} | ||
| 972 | ! | ||
| 973 | ! parameter 1 address | ||
| 974 | ! parameter 2 source left | ||
| 975 | ! parameter 3 source right | ||
| 976 | ! parameter 4 temporar | ||
| 977 | |||
| 978 | define(store_little_endian, { | ||
| 979 | |||
| 980 | ! {store_little_endian} | ||
| 981 | ! $1 $2 $3 $4 $5 $6 $7 $8 $9 | ||
| 982 | |||
| 983 | ! rightmost in register to first in memory | ||
| 984 | |||
| 985 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 986 | andcc $1, 3, global0 | ||
| 987 | bne,pn %icc, $5 | ||
| 988 | nop | ||
| 989 | |||
| 990 | sta $2, [$1] 0x88 | ||
| 991 | add $1, 4, $4 | ||
| 992 | |||
| 993 | ba,pt %icc, $5a | ||
| 994 | sta $3, [$4] 0x88 | ||
| 995 | #endif | ||
| 996 | |||
| 997 | $5: | ||
| 998 | and $2, 255, $4 | ||
| 999 | stub $4, [$1+0] | ||
| 1000 | |||
| 1001 | srl $2, 8, $4 | ||
| 1002 | and $4, 255, $4 | ||
| 1003 | stub $4, [$1+1] | ||
| 1004 | |||
| 1005 | srl $2, 16, $4 | ||
| 1006 | and $4, 255, $4 | ||
| 1007 | stub $4, [$1+2] | ||
| 1008 | |||
| 1009 | srl $2, 24, $4 | ||
| 1010 | stub $4, [$1+3] | ||
| 1011 | |||
| 1012 | |||
| 1013 | and $3, 255, $4 | ||
| 1014 | stub $4, [$1+0+4] | ||
| 1015 | |||
| 1016 | srl $3, 8, $4 | ||
| 1017 | and $4, 255, $4 | ||
| 1018 | stub $4, [$1+1+4] | ||
| 1019 | |||
| 1020 | srl $3, 16, $4 | ||
| 1021 | and $4, 255, $4 | ||
| 1022 | stub $4, [$1+2+4] | ||
| 1023 | |||
| 1024 | srl $3, 24, $4 | ||
| 1025 | stub $4, [$1+3+4] | ||
| 1026 | |||
| 1027 | $5a: | ||
| 1028 | |||
| 1029 | }) | ||
| 1030 | |||
| 1031 | |||
| 1032 | ! {store_n_bytes} | ||
| 1033 | ! | ||
| 1034 | ! Stores 1 to 7 bytes little endian | ||
| 1035 | ! | ||
| 1036 | ! parameter 1 address | ||
| 1037 | ! parameter 2 length | ||
| 1038 | ! parameter 3 source register left | ||
| 1039 | ! parameter 4 source register right | ||
| 1040 | ! parameter 5 temp | ||
| 1041 | ! parameter 6 temp2 | ||
| 1042 | ! parameter 7 label | ||
| 1043 | ! parameter 8 return label | ||
| 1044 | |||
| 1045 | define(store_n_bytes, { | ||
| 1046 | |||
| 1047 | ! {store_n_bytes} | ||
| 1048 | ! $1 $2 $5 $6 $7 $8 $7 $8 $9 | ||
| 1049 | |||
| 1050 | $7.0: call .+8 | ||
| 1051 | sll $2, 2, $6 | ||
| 1052 | |||
| 1053 | add %o7,$7.jmp.table-$7.0,$5 | ||
| 1054 | |||
| 1055 | add $5, $6, $5 | ||
| 1056 | |||
| 1057 | ld [$5], $5 | ||
| 1058 | |||
| 1059 | jmp %o7+$5 | ||
| 1060 | nop | ||
| 1061 | |||
| 1062 | $7.7: | ||
| 1063 | srl $3, 16, $5 | ||
| 1064 | and $5, 0xff, $5 | ||
| 1065 | stub $5, [$1+6] | ||
| 1066 | $7.6: | ||
| 1067 | srl $3, 8, $5 | ||
| 1068 | and $5, 0xff, $5 | ||
| 1069 | stub $5, [$1+5] | ||
| 1070 | $7.5: | ||
| 1071 | and $3, 0xff, $5 | ||
| 1072 | stub $5, [$1+4] | ||
| 1073 | $7.4: | ||
| 1074 | srl $4, 24, $5 | ||
| 1075 | stub $5, [$1+3] | ||
| 1076 | $7.3: | ||
| 1077 | srl $4, 16, $5 | ||
| 1078 | and $5, 0xff, $5 | ||
| 1079 | stub $5, [$1+2] | ||
| 1080 | $7.2: | ||
| 1081 | srl $4, 8, $5 | ||
| 1082 | and $5, 0xff, $5 | ||
| 1083 | stub $5, [$1+1] | ||
| 1084 | $7.1: | ||
| 1085 | and $4, 0xff, $5 | ||
| 1086 | |||
| 1087 | |||
| 1088 | ba $8 | ||
| 1089 | stub $5, [$1] | ||
| 1090 | |||
| 1091 | .align 4 | ||
| 1092 | |||
| 1093 | $7.jmp.table: | ||
| 1094 | |||
| 1095 | .word 0 | ||
| 1096 | .word $7.1-$7.0 | ||
| 1097 | .word $7.2-$7.0 | ||
| 1098 | .word $7.3-$7.0 | ||
| 1099 | .word $7.4-$7.0 | ||
| 1100 | .word $7.5-$7.0 | ||
| 1101 | .word $7.6-$7.0 | ||
| 1102 | .word $7.7-$7.0 | ||
| 1103 | }) | ||
| 1104 | |||
| 1105 | |||
| 1106 | define(testvalue,{1}) | ||
| 1107 | |||
| 1108 | define(register_init, { | ||
| 1109 | |||
| 1110 | ! For test purposes: | ||
| 1111 | |||
| 1112 | sethi %hi(testvalue), local0 | ||
| 1113 | or local0, %lo(testvalue), local0 | ||
| 1114 | |||
| 1115 | ifelse($1,{},{}, {mov local0, $1}) | ||
| 1116 | ifelse($2,{},{}, {mov local0, $2}) | ||
| 1117 | ifelse($3,{},{}, {mov local0, $3}) | ||
| 1118 | ifelse($4,{},{}, {mov local0, $4}) | ||
| 1119 | ifelse($5,{},{}, {mov local0, $5}) | ||
| 1120 | ifelse($6,{},{}, {mov local0, $6}) | ||
| 1121 | ifelse($7,{},{}, {mov local0, $7}) | ||
| 1122 | ifelse($8,{},{}, {mov local0, $8}) | ||
| 1123 | |||
| 1124 | mov local0, local1 | ||
| 1125 | mov local0, local2 | ||
| 1126 | mov local0, local3 | ||
| 1127 | mov local0, local4 | ||
| 1128 | mov local0, local5 | ||
| 1129 | mov local0, local7 | ||
| 1130 | mov local0, local6 | ||
| 1131 | mov local0, out0 | ||
| 1132 | mov local0, out1 | ||
| 1133 | mov local0, out2 | ||
| 1134 | mov local0, out3 | ||
| 1135 | mov local0, out4 | ||
| 1136 | mov local0, out5 | ||
| 1137 | mov local0, global1 | ||
| 1138 | mov local0, global2 | ||
| 1139 | mov local0, global3 | ||
| 1140 | mov local0, global4 | ||
| 1141 | mov local0, global5 | ||
| 1142 | |||
| 1143 | }) | ||
| 1144 | |||
| 1145 | .section ".text" | ||
| 1146 | |||
| 1147 | .align 32 | ||
| 1148 | |||
| 1149 | .des_enc: | ||
| 1150 | |||
| 1151 | ! key address in3 | ||
| 1152 | ! loads key next encryption/decryption first round from [in4] | ||
| 1153 | |||
| 1154 | rounds_macro(in5, out5, 1, .des_enc.1, in3, in4, retl) | ||
| 1155 | |||
| 1156 | |||
| 1157 | .align 32 | ||
| 1158 | |||
| 1159 | .des_dec: | ||
| 1160 | |||
| 1161 | ! implemented with out5 as first parameter to avoid | ||
| 1162 | ! register exchange in ede modes | ||
| 1163 | |||
| 1164 | ! key address in4 | ||
| 1165 | ! loads key next encryption/decryption first round from [in3] | ||
| 1166 | |||
| 1167 | rounds_macro(out5, in5, -1, .des_dec.1, in4, in3, retl) | ||
| 1168 | |||
| 1169 | |||
| 1170 | |||
| 1171 | ! void DES_encrypt1(data, ks, enc) | ||
| 1172 | ! ******************************* | ||
| 1173 | |||
| 1174 | .align 32 | ||
| 1175 | .global DES_encrypt1 | ||
| 1176 | .type DES_encrypt1,#function | ||
| 1177 | |||
| 1178 | DES_encrypt1: | ||
| 1179 | |||
| 1180 | save %sp, FRAME, %sp | ||
| 1181 | |||
| 1182 | call .PIC.me.up | ||
| 1183 | mov .PIC.me.up-(.-4),out0 | ||
| 1184 | |||
| 1185 | ld [in0], in5 ! left | ||
| 1186 | cmp in2, 0 ! enc | ||
| 1187 | |||
| 1188 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1189 | be,pn %icc, .encrypt.dec ! enc/dec | ||
| 1190 | #else | ||
| 1191 | be .encrypt.dec | ||
| 1192 | #endif | ||
| 1193 | ld [in0+4], out5 ! right | ||
| 1194 | |||
| 1195 | ! parameter 6 1/2 for include encryption/decryption | ||
| 1196 | ! parameter 7 1 for move in1 to in3 | ||
| 1197 | ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 | ||
| 1198 | |||
| 1199 | ip_macro(in5, out5, in5, out5, in3, 0, 1, 1) | ||
| 1200 | |||
| 1201 | rounds_macro(in5, out5, 1, .des_encrypt1.1, in3, in4) ! in4 not used | ||
| 1202 | |||
| 1203 | fp_macro(in5, out5, 1) ! 1 for store to [in0] | ||
| 1204 | |||
| 1205 | ret | ||
| 1206 | restore | ||
| 1207 | |||
| 1208 | .encrypt.dec: | ||
| 1209 | |||
| 1210 | add in1, 120, in3 ! use last subkey for first round | ||
| 1211 | |||
| 1212 | ! parameter 6 1/2 for include encryption/decryption | ||
| 1213 | ! parameter 7 1 for move in1 to in3 | ||
| 1214 | ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 | ||
| 1215 | |||
| 1216 | ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include dec, ks in4 | ||
| 1217 | |||
| 1218 | fp_macro(out5, in5, 1) ! 1 for store to [in0] | ||
| 1219 | |||
| 1220 | ret | ||
| 1221 | restore | ||
| 1222 | |||
| 1223 | .DES_encrypt1.end: | ||
| 1224 | .size DES_encrypt1,.DES_encrypt1.end-DES_encrypt1 | ||
| 1225 | |||
| 1226 | |||
| 1227 | ! void DES_encrypt2(data, ks, enc) | ||
| 1228 | !********************************* | ||
| 1229 | |||
| 1230 | ! encrypts/decrypts without initial/final permutation | ||
| 1231 | |||
| 1232 | .align 32 | ||
| 1233 | .global DES_encrypt2 | ||
| 1234 | .type DES_encrypt2,#function | ||
| 1235 | |||
| 1236 | DES_encrypt2: | ||
| 1237 | |||
| 1238 | save %sp, FRAME, %sp | ||
| 1239 | |||
| 1240 | call .PIC.me.up | ||
| 1241 | mov .PIC.me.up-(.-4),out0 | ||
| 1242 | |||
| 1243 | ! Set sbox address 1 to 6 and rotate halfs 3 left | ||
| 1244 | ! Errors caught by destest? Yes. Still? *NO* | ||
| 1245 | |||
| 1246 | !sethi %hi(DES_SPtrans), global1 ! address sbox 1 | ||
| 1247 | |||
| 1248 | !or global1, %lo(DES_SPtrans), global1 ! sbox 1 | ||
| 1249 | |||
| 1250 | add global1, 256, global2 ! sbox 2 | ||
| 1251 | add global1, 512, global3 ! sbox 3 | ||
| 1252 | |||
| 1253 | ld [in0], out5 ! right | ||
| 1254 | add global1, 768, global4 ! sbox 4 | ||
| 1255 | add global1, 1024, global5 ! sbox 5 | ||
| 1256 | |||
| 1257 | ld [in0+4], in5 ! left | ||
| 1258 | add global1, 1280, local6 ! sbox 6 | ||
| 1259 | add global1, 1792, out3 ! sbox 8 | ||
| 1260 | |||
| 1261 | ! rotate | ||
| 1262 | |||
| 1263 | sll in5, 3, local5 | ||
| 1264 | mov in1, in3 ! key address to in3 | ||
| 1265 | |||
| 1266 | sll out5, 3, local7 | ||
| 1267 | srl in5, 29, in5 | ||
| 1268 | |||
| 1269 | srl out5, 29, out5 | ||
| 1270 | add in5, local5, in5 | ||
| 1271 | |||
| 1272 | add out5, local7, out5 | ||
| 1273 | cmp in2, 0 | ||
| 1274 | |||
| 1275 | ! we use our own stackframe | ||
| 1276 | |||
| 1277 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1278 | be,pn %icc, .encrypt2.dec ! decryption | ||
| 1279 | #else | ||
| 1280 | be .encrypt2.dec | ||
| 1281 | #endif | ||
| 1282 | STPTR in0, [%sp+BIAS+ARG0+0*ARGSZ] | ||
| 1283 | |||
| 1284 | ld [in3], out0 ! key 7531 first round | ||
| 1285 | mov LOOPS, out4 ! loop counter | ||
| 1286 | |||
| 1287 | ld [in3+4], out1 ! key 8642 first round | ||
| 1288 | sethi %hi(0x0000FC00), local5 | ||
| 1289 | |||
| 1290 | call .des_enc | ||
| 1291 | mov in3, in4 | ||
| 1292 | |||
| 1293 | ! rotate | ||
| 1294 | sll in5, 29, in0 | ||
| 1295 | srl in5, 3, in5 | ||
| 1296 | sll out5, 29, in1 | ||
| 1297 | add in5, in0, in5 | ||
| 1298 | srl out5, 3, out5 | ||
| 1299 | LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0 | ||
| 1300 | add out5, in1, out5 | ||
| 1301 | st in5, [in0] | ||
| 1302 | st out5, [in0+4] | ||
| 1303 | |||
| 1304 | ret | ||
| 1305 | restore | ||
| 1306 | |||
| 1307 | |||
| 1308 | .encrypt2.dec: | ||
| 1309 | |||
| 1310 | add in3, 120, in4 | ||
| 1311 | |||
| 1312 | ld [in4], out0 ! key 7531 first round | ||
| 1313 | mov LOOPS, out4 ! loop counter | ||
| 1314 | |||
| 1315 | ld [in4+4], out1 ! key 8642 first round | ||
| 1316 | sethi %hi(0x0000FC00), local5 | ||
| 1317 | |||
| 1318 | mov in5, local1 ! left expected in out5 | ||
| 1319 | mov out5, in5 | ||
| 1320 | |||
| 1321 | call .des_dec | ||
| 1322 | mov local1, out5 | ||
| 1323 | |||
| 1324 | .encrypt2.finish: | ||
| 1325 | |||
| 1326 | ! rotate | ||
| 1327 | sll in5, 29, in0 | ||
| 1328 | srl in5, 3, in5 | ||
| 1329 | sll out5, 29, in1 | ||
| 1330 | add in5, in0, in5 | ||
| 1331 | srl out5, 3, out5 | ||
| 1332 | LDPTR [%sp+BIAS+ARG0+0*ARGSZ], in0 | ||
| 1333 | add out5, in1, out5 | ||
| 1334 | st out5, [in0] | ||
| 1335 | st in5, [in0+4] | ||
| 1336 | |||
| 1337 | ret | ||
| 1338 | restore | ||
| 1339 | |||
| 1340 | .DES_encrypt2.end: | ||
| 1341 | .size DES_encrypt2, .DES_encrypt2.end-DES_encrypt2 | ||
| 1342 | |||
| 1343 | |||
| 1344 | ! void DES_encrypt3(data, ks1, ks2, ks3) | ||
| 1345 | ! ************************************** | ||
| 1346 | |||
| 1347 | .align 32 | ||
| 1348 | .global DES_encrypt3 | ||
| 1349 | .type DES_encrypt3,#function | ||
| 1350 | |||
| 1351 | DES_encrypt3: | ||
| 1352 | |||
| 1353 | save %sp, FRAME, %sp | ||
| 1354 | |||
| 1355 | call .PIC.me.up | ||
| 1356 | mov .PIC.me.up-(.-4),out0 | ||
| 1357 | |||
| 1358 | ld [in0], in5 ! left | ||
| 1359 | add in2, 120, in4 ! ks2 | ||
| 1360 | |||
| 1361 | ld [in0+4], out5 ! right | ||
| 1362 | mov in3, in2 ! save ks3 | ||
| 1363 | |||
| 1364 | ! parameter 6 1/2 for include encryption/decryption | ||
| 1365 | ! parameter 7 1 for mov in1 to in3 | ||
| 1366 | ! parameter 8 1 for mov in3 to in4 | ||
| 1367 | ! parameter 9 1 for load ks3 and ks2 to in4 and in3 | ||
| 1368 | |||
| 1369 | ip_macro(in5, out5, in5, out5, in3, 1, 1, 0, 0) | ||
| 1370 | |||
| 1371 | call .des_dec | ||
| 1372 | mov in2, in3 ! preload ks3 | ||
| 1373 | |||
| 1374 | call .des_enc | ||
| 1375 | nop | ||
| 1376 | |||
| 1377 | fp_macro(in5, out5, 1) | ||
| 1378 | |||
| 1379 | ret | ||
| 1380 | restore | ||
| 1381 | |||
| 1382 | .DES_encrypt3.end: | ||
| 1383 | .size DES_encrypt3,.DES_encrypt3.end-DES_encrypt3 | ||
| 1384 | |||
| 1385 | |||
| 1386 | ! void DES_decrypt3(data, ks1, ks2, ks3) | ||
| 1387 | ! ************************************** | ||
| 1388 | |||
| 1389 | .align 32 | ||
| 1390 | .global DES_decrypt3 | ||
| 1391 | .type DES_decrypt3,#function | ||
| 1392 | |||
| 1393 | DES_decrypt3: | ||
| 1394 | |||
| 1395 | save %sp, FRAME, %sp | ||
| 1396 | |||
| 1397 | call .PIC.me.up | ||
| 1398 | mov .PIC.me.up-(.-4),out0 | ||
| 1399 | |||
| 1400 | ld [in0], in5 ! left | ||
| 1401 | add in3, 120, in4 ! ks3 | ||
| 1402 | |||
| 1403 | ld [in0+4], out5 ! right | ||
| 1404 | mov in2, in3 ! ks2 | ||
| 1405 | |||
| 1406 | ! parameter 6 1/2 for include encryption/decryption | ||
| 1407 | ! parameter 7 1 for mov in1 to in3 | ||
| 1408 | ! parameter 8 1 for mov in3 to in4 | ||
| 1409 | ! parameter 9 1 for load ks3 and ks2 to in4 and in3 | ||
| 1410 | |||
| 1411 | ip_macro(in5, out5, out5, in5, in4, 2, 0, 0, 0) | ||
| 1412 | |||
| 1413 | call .des_enc | ||
| 1414 | add in1, 120, in4 ! preload ks1 | ||
| 1415 | |||
| 1416 | call .des_dec | ||
| 1417 | nop | ||
| 1418 | |||
| 1419 | fp_macro(out5, in5, 1) | ||
| 1420 | |||
| 1421 | ret | ||
| 1422 | restore | ||
| 1423 | |||
| 1424 | .DES_decrypt3.end: | ||
| 1425 | .size DES_decrypt3,.DES_decrypt3.end-DES_decrypt3 | ||
| 1426 | |||
| 1427 | .align 256 | ||
| 1428 | .type .des_and,#object | ||
| 1429 | .size .des_and,284 | ||
| 1430 | |||
| 1431 | .des_and: | ||
| 1432 | |||
| 1433 | ! This table is used for AND 0xFC when it is known that register | ||
| 1434 | ! bits 8-31 are zero. Makes it possible to do three arithmetic | ||
| 1435 | ! operations in one cycle. | ||
| 1436 | |||
| 1437 | .byte 0, 0, 0, 0, 4, 4, 4, 4 | ||
| 1438 | .byte 8, 8, 8, 8, 12, 12, 12, 12 | ||
| 1439 | .byte 16, 16, 16, 16, 20, 20, 20, 20 | ||
| 1440 | .byte 24, 24, 24, 24, 28, 28, 28, 28 | ||
| 1441 | .byte 32, 32, 32, 32, 36, 36, 36, 36 | ||
| 1442 | .byte 40, 40, 40, 40, 44, 44, 44, 44 | ||
| 1443 | .byte 48, 48, 48, 48, 52, 52, 52, 52 | ||
| 1444 | .byte 56, 56, 56, 56, 60, 60, 60, 60 | ||
| 1445 | .byte 64, 64, 64, 64, 68, 68, 68, 68 | ||
| 1446 | .byte 72, 72, 72, 72, 76, 76, 76, 76 | ||
| 1447 | .byte 80, 80, 80, 80, 84, 84, 84, 84 | ||
| 1448 | .byte 88, 88, 88, 88, 92, 92, 92, 92 | ||
| 1449 | .byte 96, 96, 96, 96, 100, 100, 100, 100 | ||
| 1450 | .byte 104, 104, 104, 104, 108, 108, 108, 108 | ||
| 1451 | .byte 112, 112, 112, 112, 116, 116, 116, 116 | ||
| 1452 | .byte 120, 120, 120, 120, 124, 124, 124, 124 | ||
| 1453 | .byte 128, 128, 128, 128, 132, 132, 132, 132 | ||
| 1454 | .byte 136, 136, 136, 136, 140, 140, 140, 140 | ||
| 1455 | .byte 144, 144, 144, 144, 148, 148, 148, 148 | ||
| 1456 | .byte 152, 152, 152, 152, 156, 156, 156, 156 | ||
| 1457 | .byte 160, 160, 160, 160, 164, 164, 164, 164 | ||
| 1458 | .byte 168, 168, 168, 168, 172, 172, 172, 172 | ||
| 1459 | .byte 176, 176, 176, 176, 180, 180, 180, 180 | ||
| 1460 | .byte 184, 184, 184, 184, 188, 188, 188, 188 | ||
| 1461 | .byte 192, 192, 192, 192, 196, 196, 196, 196 | ||
| 1462 | .byte 200, 200, 200, 200, 204, 204, 204, 204 | ||
| 1463 | .byte 208, 208, 208, 208, 212, 212, 212, 212 | ||
| 1464 | .byte 216, 216, 216, 216, 220, 220, 220, 220 | ||
| 1465 | .byte 224, 224, 224, 224, 228, 228, 228, 228 | ||
| 1466 | .byte 232, 232, 232, 232, 236, 236, 236, 236 | ||
| 1467 | .byte 240, 240, 240, 240, 244, 244, 244, 244 | ||
| 1468 | .byte 248, 248, 248, 248, 252, 252, 252, 252 | ||
| 1469 | |||
| 1470 | ! 5 numbers for initil/final permutation | ||
| 1471 | |||
| 1472 | .word 0x0f0f0f0f ! offset 256 | ||
| 1473 | .word 0x0000ffff ! 260 | ||
| 1474 | .word 0x33333333 ! 264 | ||
| 1475 | .word 0x00ff00ff ! 268 | ||
| 1476 | .word 0x55555555 ! 272 | ||
| 1477 | |||
| 1478 | .word 0 ! 276 | ||
| 1479 | .word LOOPS ! 280 | ||
| 1480 | .word 0x0000FC00 ! 284 | ||
| 1481 | .PIC.DES_SPtrans: | ||
| 1482 | .word %r_disp32(DES_SPtrans) | ||
| 1483 | |||
| 1484 | ! input: out0 offset between .PIC.me.up and caller | ||
| 1485 | ! output: out0 pointer to .PIC.me.up | ||
| 1486 | ! out2 pointer to .des_and | ||
| 1487 | ! global1 pointer to DES_SPtrans | ||
| 1488 | .align 32 | ||
| 1489 | .PIC.me.up: | ||
| 1490 | add out0,%o7,out0 ! pointer to .PIC.me.up | ||
| 1491 | #if 1 | ||
| 1492 | ld [out0+(.PIC.DES_SPtrans-.PIC.me.up)],global1 | ||
| 1493 | add global1,(.PIC.DES_SPtrans-.PIC.me.up),global1 | ||
| 1494 | add global1,out0,global1 | ||
| 1495 | #else | ||
| 1496 | # ifdef OPENSSL_PIC | ||
| 1497 | ! In case anybody wonders why this code is same for both ABI. | ||
| 1498 | ! To start with it is not. Do note LDPTR below. But of course | ||
| 1499 | ! you must be wondering why the rest of it does not contain | ||
| 1500 | ! things like %hh, %hm and %lm. Well, those are needed only | ||
| 1501 | ! if OpenSSL library *itself* will become larger than 4GB, | ||
| 1502 | ! which is not going to happen any time soon. | ||
| 1503 | sethi %hi(DES_SPtrans),global1 | ||
| 1504 | or global1,%lo(DES_SPtrans),global1 | ||
| 1505 | sethi %hi(_GLOBAL_OFFSET_TABLE_-(.PIC.me.up-.)),out2 | ||
| 1506 | add global1,out0,global1 | ||
| 1507 | add out2,%lo(_GLOBAL_OFFSET_TABLE_-(.PIC.me.up-.)),out2 | ||
| 1508 | LDPTR [out2+global1],global1 | ||
| 1509 | # elif 0 | ||
| 1510 | setn DES_SPtrans,out2,global1 ! synthetic instruction ! | ||
| 1511 | # elif defined(ABI64) | ||
| 1512 | sethi %hh(DES_SPtrans),out2 | ||
| 1513 | or out2,%hm(DES_SPtrans),out2 | ||
| 1514 | sethi %lm(DES_SPtrans),global1 | ||
| 1515 | or global1,%lo(DES_SPtrans),global1 | ||
| 1516 | sllx out2,32,out2 | ||
| 1517 | or out2,global1,global1 | ||
| 1518 | # else | ||
| 1519 | sethi %hi(DES_SPtrans),global1 | ||
| 1520 | or global1,%lo(DES_SPtrans),global1 | ||
| 1521 | # endif | ||
| 1522 | #endif | ||
| 1523 | retl | ||
| 1524 | add out0,.des_and-.PIC.me.up,out2 | ||
| 1525 | |||
| 1526 | ! void DES_ncbc_encrypt(input, output, length, schedule, ivec, enc) | ||
| 1527 | ! ***************************************************************** | ||
| 1528 | |||
| 1529 | |||
| 1530 | .align 32 | ||
| 1531 | .global DES_ncbc_encrypt | ||
| 1532 | .type DES_ncbc_encrypt,#function | ||
| 1533 | |||
| 1534 | DES_ncbc_encrypt: | ||
| 1535 | |||
| 1536 | save %sp, FRAME, %sp | ||
| 1537 | |||
| 1538 | define({INPUT}, { [%sp+BIAS+ARG0+0*ARGSZ] }) | ||
| 1539 | define({OUTPUT}, { [%sp+BIAS+ARG0+1*ARGSZ] }) | ||
| 1540 | define({IVEC}, { [%sp+BIAS+ARG0+4*ARGSZ] }) | ||
| 1541 | |||
| 1542 | call .PIC.me.up | ||
| 1543 | mov .PIC.me.up-(.-4),out0 | ||
| 1544 | |||
| 1545 | cmp in5, 0 ! enc | ||
| 1546 | |||
| 1547 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1548 | be,pn %icc, .ncbc.dec | ||
| 1549 | #else | ||
| 1550 | be .ncbc.dec | ||
| 1551 | #endif | ||
| 1552 | STPTR in4, IVEC | ||
| 1553 | |||
| 1554 | ! addr left right temp label | ||
| 1555 | load_little_endian(in4, in5, out5, local3, .LLE1) ! iv | ||
| 1556 | |||
| 1557 | addcc in2, -8, in2 ! bytes missing when first block done | ||
| 1558 | |||
| 1559 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1560 | bl,pn %icc, .ncbc.enc.seven.or.less | ||
| 1561 | #else | ||
| 1562 | bl .ncbc.enc.seven.or.less | ||
| 1563 | #endif | ||
| 1564 | mov in3, in4 ! schedule | ||
| 1565 | |||
| 1566 | .ncbc.enc.next.block: | ||
| 1567 | |||
| 1568 | load_little_endian(in0, out4, global4, local3, .LLE2) ! block | ||
| 1569 | |||
| 1570 | .ncbc.enc.next.block_1: | ||
| 1571 | |||
| 1572 | xor in5, out4, in5 ! iv xor | ||
| 1573 | xor out5, global4, out5 ! iv xor | ||
| 1574 | |||
| 1575 | ! parameter 8 1 for move in3 to in4, 2 for move in4 to in3 | ||
| 1576 | ip_macro(in5, out5, in5, out5, in3, 0, 0, 2) | ||
| 1577 | |||
| 1578 | .ncbc.enc.next.block_2: | ||
| 1579 | |||
| 1580 | !// call .des_enc ! compares in2 to 8 | ||
| 1581 | ! rounds inlined for alignment purposes | ||
| 1582 | |||
| 1583 | add global1, 768, global4 ! address sbox 4 since register used below | ||
| 1584 | |||
| 1585 | rounds_macro(in5, out5, 1, .ncbc.enc.1, in3, in4) ! include encryption ks in3 | ||
| 1586 | |||
| 1587 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1588 | bl,pn %icc, .ncbc.enc.next.block_fp | ||
| 1589 | #else | ||
| 1590 | bl .ncbc.enc.next.block_fp | ||
| 1591 | #endif | ||
| 1592 | add in0, 8, in0 ! input address | ||
| 1593 | |||
| 1594 | ! If 8 or more bytes are to be encrypted after this block, | ||
| 1595 | ! we combine final permutation for this block with initial | ||
| 1596 | ! permutation for next block. Load next block: | ||
| 1597 | |||
| 1598 | load_little_endian(in0, global3, global4, local5, .LLE12) | ||
| 1599 | |||
| 1600 | ! parameter 1 original left | ||
| 1601 | ! parameter 2 original right | ||
| 1602 | ! parameter 3 left ip | ||
| 1603 | ! parameter 4 right ip | ||
| 1604 | ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4 | ||
| 1605 | ! 2: mov in4 to in3 | ||
| 1606 | ! | ||
| 1607 | ! also adds -8 to length in2 and loads loop counter to out4 | ||
| 1608 | |||
| 1609 | fp_ip_macro(out0, out1, global3, global4, 2) | ||
| 1610 | |||
| 1611 | store_little_endian(in1, out0, out1, local3, .SLE10) ! block | ||
| 1612 | |||
| 1613 | ld [in3], out0 ! key 7531 first round next block | ||
| 1614 | mov in5, local1 | ||
| 1615 | xor global3, out5, in5 ! iv xor next block | ||
| 1616 | |||
| 1617 | ld [in3+4], out1 ! key 8642 | ||
| 1618 | add global1, 512, global3 ! address sbox 3 since register used | ||
| 1619 | xor global4, local1, out5 ! iv xor next block | ||
| 1620 | |||
| 1621 | ba .ncbc.enc.next.block_2 | ||
| 1622 | add in1, 8, in1 ! output adress | ||
| 1623 | |||
| 1624 | .ncbc.enc.next.block_fp: | ||
| 1625 | |||
| 1626 | fp_macro(in5, out5) | ||
| 1627 | |||
| 1628 | store_little_endian(in1, in5, out5, local3, .SLE1) ! block | ||
| 1629 | |||
| 1630 | addcc in2, -8, in2 ! bytes missing when next block done | ||
| 1631 | |||
| 1632 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1633 | bpos,pt %icc, .ncbc.enc.next.block ! also jumps if 0 | ||
| 1634 | #else | ||
| 1635 | bpos .ncbc.enc.next.block | ||
| 1636 | #endif | ||
| 1637 | add in1, 8, in1 | ||
| 1638 | |||
| 1639 | .ncbc.enc.seven.or.less: | ||
| 1640 | |||
| 1641 | cmp in2, -8 | ||
| 1642 | |||
| 1643 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1644 | ble,pt %icc, .ncbc.enc.finish | ||
| 1645 | #else | ||
| 1646 | ble .ncbc.enc.finish | ||
| 1647 | #endif | ||
| 1648 | nop | ||
| 1649 | |||
| 1650 | add in2, 8, local1 ! bytes to load | ||
| 1651 | |||
| 1652 | ! addr, length, dest left, dest right, temp, temp2, label, ret label | ||
| 1653 | load_n_bytes(in0, local1, global4, out4, local2, local3, .LNB1, .ncbc.enc.next.block_1) | ||
| 1654 | |||
| 1655 | ! Loads 1 to 7 bytes little endian to global4, out4 | ||
| 1656 | |||
| 1657 | |||
| 1658 | .ncbc.enc.finish: | ||
| 1659 | |||
| 1660 | LDPTR IVEC, local4 | ||
| 1661 | store_little_endian(local4, in5, out5, local5, .SLE2) ! ivec | ||
| 1662 | |||
| 1663 | ret | ||
| 1664 | restore | ||
| 1665 | |||
| 1666 | |||
| 1667 | .ncbc.dec: | ||
| 1668 | |||
| 1669 | STPTR in0, INPUT | ||
| 1670 | cmp in2, 0 ! length | ||
| 1671 | add in3, 120, in3 | ||
| 1672 | |||
| 1673 | LDPTR IVEC, local7 ! ivec | ||
| 1674 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1675 | ble,pn %icc, .ncbc.dec.finish | ||
| 1676 | #else | ||
| 1677 | ble .ncbc.dec.finish | ||
| 1678 | #endif | ||
| 1679 | mov in3, in4 ! schedule | ||
| 1680 | |||
| 1681 | STPTR in1, OUTPUT | ||
| 1682 | mov in0, local5 ! input | ||
| 1683 | |||
| 1684 | load_little_endian(local7, in0, in1, local3, .LLE3) ! ivec | ||
| 1685 | |||
| 1686 | .ncbc.dec.next.block: | ||
| 1687 | |||
| 1688 | load_little_endian(local5, in5, out5, local3, .LLE4) ! block | ||
| 1689 | |||
| 1690 | ! parameter 6 1/2 for include encryption/decryption | ||
| 1691 | ! parameter 7 1 for mov in1 to in3 | ||
| 1692 | ! parameter 8 1 for mov in3 to in4 | ||
| 1693 | |||
| 1694 | ip_macro(in5, out5, out5, in5, in4, 2, 0, 1) ! include decryprion ks in4 | ||
| 1695 | |||
| 1696 | fp_macro(out5, in5, 0, 1) ! 1 for input and output address to local5/7 | ||
| 1697 | |||
| 1698 | ! in2 is bytes left to be stored | ||
| 1699 | ! in2 is compared to 8 in the rounds | ||
| 1700 | |||
| 1701 | xor out5, in0, out4 ! iv xor | ||
| 1702 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1703 | bl,pn %icc, .ncbc.dec.seven.or.less | ||
| 1704 | #else | ||
| 1705 | bl .ncbc.dec.seven.or.less | ||
| 1706 | #endif | ||
| 1707 | xor in5, in1, global4 ! iv xor | ||
| 1708 | |||
| 1709 | ! Load ivec next block now, since input and output address might be the same. | ||
| 1710 | |||
| 1711 | load_little_endian_inc(local5, in0, in1, local3, .LLE5) ! iv | ||
| 1712 | |||
| 1713 | store_little_endian(local7, out4, global4, local3, .SLE3) | ||
| 1714 | |||
| 1715 | STPTR local5, INPUT | ||
| 1716 | add local7, 8, local7 | ||
| 1717 | addcc in2, -8, in2 | ||
| 1718 | |||
| 1719 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1720 | bg,pt %icc, .ncbc.dec.next.block | ||
| 1721 | #else | ||
| 1722 | bg .ncbc.dec.next.block | ||
| 1723 | #endif | ||
| 1724 | STPTR local7, OUTPUT | ||
| 1725 | |||
| 1726 | |||
| 1727 | .ncbc.dec.store.iv: | ||
| 1728 | |||
| 1729 | LDPTR IVEC, local4 ! ivec | ||
| 1730 | store_little_endian(local4, in0, in1, local5, .SLE4) | ||
| 1731 | |||
| 1732 | .ncbc.dec.finish: | ||
| 1733 | |||
| 1734 | ret | ||
| 1735 | restore | ||
| 1736 | |||
| 1737 | .ncbc.dec.seven.or.less: | ||
| 1738 | |||
| 1739 | load_little_endian_inc(local5, in0, in1, local3, .LLE13) ! ivec | ||
| 1740 | |||
| 1741 | store_n_bytes(local7, in2, global4, out4, local3, local4, .SNB1, .ncbc.dec.store.iv) | ||
| 1742 | |||
| 1743 | |||
| 1744 | .DES_ncbc_encrypt.end: | ||
| 1745 | .size DES_ncbc_encrypt, .DES_ncbc_encrypt.end-DES_ncbc_encrypt | ||
| 1746 | |||
| 1747 | |||
| 1748 | ! void DES_ede3_cbc_encrypt(input, output, lenght, ks1, ks2, ks3, ivec, enc) | ||
| 1749 | ! ************************************************************************** | ||
| 1750 | |||
| 1751 | |||
| 1752 | .align 32 | ||
| 1753 | .global DES_ede3_cbc_encrypt | ||
| 1754 | .type DES_ede3_cbc_encrypt,#function | ||
| 1755 | |||
| 1756 | DES_ede3_cbc_encrypt: | ||
| 1757 | |||
| 1758 | save %sp, FRAME, %sp | ||
| 1759 | |||
| 1760 | define({KS1}, { [%sp+BIAS+ARG0+3*ARGSZ] }) | ||
| 1761 | define({KS2}, { [%sp+BIAS+ARG0+4*ARGSZ] }) | ||
| 1762 | define({KS3}, { [%sp+BIAS+ARG0+5*ARGSZ] }) | ||
| 1763 | |||
| 1764 | call .PIC.me.up | ||
| 1765 | mov .PIC.me.up-(.-4),out0 | ||
| 1766 | |||
| 1767 | LDPTR [%fp+BIAS+ARG0+7*ARGSZ], local3 ! enc | ||
| 1768 | LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec | ||
| 1769 | cmp local3, 0 ! enc | ||
| 1770 | |||
| 1771 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1772 | be,pn %icc, .ede3.dec | ||
| 1773 | #else | ||
| 1774 | be .ede3.dec | ||
| 1775 | #endif | ||
| 1776 | STPTR in4, KS2 | ||
| 1777 | |||
| 1778 | STPTR in5, KS3 | ||
| 1779 | |||
| 1780 | load_little_endian(local4, in5, out5, local3, .LLE6) ! ivec | ||
| 1781 | |||
| 1782 | addcc in2, -8, in2 ! bytes missing after next block | ||
| 1783 | |||
| 1784 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1785 | bl,pn %icc, .ede3.enc.seven.or.less | ||
| 1786 | #else | ||
| 1787 | bl .ede3.enc.seven.or.less | ||
| 1788 | #endif | ||
| 1789 | STPTR in3, KS1 | ||
| 1790 | |||
| 1791 | .ede3.enc.next.block: | ||
| 1792 | |||
| 1793 | load_little_endian(in0, out4, global4, local3, .LLE7) | ||
| 1794 | |||
| 1795 | .ede3.enc.next.block_1: | ||
| 1796 | |||
| 1797 | LDPTR KS2, in4 | ||
| 1798 | xor in5, out4, in5 ! iv xor | ||
| 1799 | xor out5, global4, out5 ! iv xor | ||
| 1800 | |||
| 1801 | LDPTR KS1, in3 | ||
| 1802 | add in4, 120, in4 ! for decryption we use last subkey first | ||
| 1803 | nop | ||
| 1804 | |||
| 1805 | ip_macro(in5, out5, in5, out5, in3) | ||
| 1806 | |||
| 1807 | .ede3.enc.next.block_2: | ||
| 1808 | |||
| 1809 | call .des_enc ! ks1 in3 | ||
| 1810 | nop | ||
| 1811 | |||
| 1812 | call .des_dec ! ks2 in4 | ||
| 1813 | LDPTR KS3, in3 | ||
| 1814 | |||
| 1815 | call .des_enc ! ks3 in3 compares in2 to 8 | ||
| 1816 | nop | ||
| 1817 | |||
| 1818 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1819 | bl,pn %icc, .ede3.enc.next.block_fp | ||
| 1820 | #else | ||
| 1821 | bl .ede3.enc.next.block_fp | ||
| 1822 | #endif | ||
| 1823 | add in0, 8, in0 | ||
| 1824 | |||
| 1825 | ! If 8 or more bytes are to be encrypted after this block, | ||
| 1826 | ! we combine final permutation for this block with initial | ||
| 1827 | ! permutation for next block. Load next block: | ||
| 1828 | |||
| 1829 | load_little_endian(in0, global3, global4, local5, .LLE11) | ||
| 1830 | |||
| 1831 | ! parameter 1 original left | ||
| 1832 | ! parameter 2 original right | ||
| 1833 | ! parameter 3 left ip | ||
| 1834 | ! parameter 4 right ip | ||
| 1835 | ! parameter 5 1: load ks1/ks2 to in3/in4, add 120 to in4 | ||
| 1836 | ! 2: mov in4 to in3 | ||
| 1837 | ! | ||
| 1838 | ! also adds -8 to length in2 and loads loop counter to out4 | ||
| 1839 | |||
| 1840 | fp_ip_macro(out0, out1, global3, global4, 1) | ||
| 1841 | |||
| 1842 | store_little_endian(in1, out0, out1, local3, .SLE9) ! block | ||
| 1843 | |||
| 1844 | mov in5, local1 | ||
| 1845 | xor global3, out5, in5 ! iv xor next block | ||
| 1846 | |||
| 1847 | ld [in3], out0 ! key 7531 | ||
| 1848 | add global1, 512, global3 ! address sbox 3 | ||
| 1849 | xor global4, local1, out5 ! iv xor next block | ||
| 1850 | |||
| 1851 | ld [in3+4], out1 ! key 8642 | ||
| 1852 | add global1, 768, global4 ! address sbox 4 | ||
| 1853 | ba .ede3.enc.next.block_2 | ||
| 1854 | add in1, 8, in1 | ||
| 1855 | |||
| 1856 | .ede3.enc.next.block_fp: | ||
| 1857 | |||
| 1858 | fp_macro(in5, out5) | ||
| 1859 | |||
| 1860 | store_little_endian(in1, in5, out5, local3, .SLE5) ! block | ||
| 1861 | |||
| 1862 | addcc in2, -8, in2 ! bytes missing when next block done | ||
| 1863 | |||
| 1864 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1865 | bpos,pt %icc, .ede3.enc.next.block | ||
| 1866 | #else | ||
| 1867 | bpos .ede3.enc.next.block | ||
| 1868 | #endif | ||
| 1869 | add in1, 8, in1 | ||
| 1870 | |||
| 1871 | .ede3.enc.seven.or.less: | ||
| 1872 | |||
| 1873 | cmp in2, -8 | ||
| 1874 | |||
| 1875 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1876 | ble,pt %icc, .ede3.enc.finish | ||
| 1877 | #else | ||
| 1878 | ble .ede3.enc.finish | ||
| 1879 | #endif | ||
| 1880 | nop | ||
| 1881 | |||
| 1882 | add in2, 8, local1 ! bytes to load | ||
| 1883 | |||
| 1884 | ! addr, length, dest left, dest right, temp, temp2, label, ret label | ||
| 1885 | load_n_bytes(in0, local1, global4, out4, local2, local3, .LNB2, .ede3.enc.next.block_1) | ||
| 1886 | |||
| 1887 | .ede3.enc.finish: | ||
| 1888 | |||
| 1889 | LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec | ||
| 1890 | store_little_endian(local4, in5, out5, local5, .SLE6) ! ivec | ||
| 1891 | |||
| 1892 | ret | ||
| 1893 | restore | ||
| 1894 | |||
| 1895 | .ede3.dec: | ||
| 1896 | |||
| 1897 | STPTR in0, INPUT | ||
| 1898 | add in5, 120, in5 | ||
| 1899 | |||
| 1900 | STPTR in1, OUTPUT | ||
| 1901 | mov in0, local5 | ||
| 1902 | add in3, 120, in3 | ||
| 1903 | |||
| 1904 | STPTR in3, KS1 | ||
| 1905 | cmp in2, 0 | ||
| 1906 | |||
| 1907 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1908 | ble %icc, .ede3.dec.finish | ||
| 1909 | #else | ||
| 1910 | ble .ede3.dec.finish | ||
| 1911 | #endif | ||
| 1912 | STPTR in5, KS3 | ||
| 1913 | |||
| 1914 | LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local7 ! iv | ||
| 1915 | load_little_endian(local7, in0, in1, local3, .LLE8) | ||
| 1916 | |||
| 1917 | .ede3.dec.next.block: | ||
| 1918 | |||
| 1919 | load_little_endian(local5, in5, out5, local3, .LLE9) | ||
| 1920 | |||
| 1921 | ! parameter 6 1/2 for include encryption/decryption | ||
| 1922 | ! parameter 7 1 for mov in1 to in3 | ||
| 1923 | ! parameter 8 1 for mov in3 to in4 | ||
| 1924 | ! parameter 9 1 for load ks3 and ks2 to in4 and in3 | ||
| 1925 | |||
| 1926 | ip_macro(in5, out5, out5, in5, in4, 2, 0, 0, 1) ! inc .des_dec ks3 in4 | ||
| 1927 | |||
| 1928 | call .des_enc ! ks2 in3 | ||
| 1929 | LDPTR KS1, in4 | ||
| 1930 | |||
| 1931 | call .des_dec ! ks1 in4 | ||
| 1932 | nop | ||
| 1933 | |||
| 1934 | fp_macro(out5, in5, 0, 1) ! 1 for input and output address local5/7 | ||
| 1935 | |||
| 1936 | ! in2 is bytes left to be stored | ||
| 1937 | ! in2 is compared to 8 in the rounds | ||
| 1938 | |||
| 1939 | xor out5, in0, out4 | ||
| 1940 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1941 | bl,pn %icc, .ede3.dec.seven.or.less | ||
| 1942 | #else | ||
| 1943 | bl .ede3.dec.seven.or.less | ||
| 1944 | #endif | ||
| 1945 | xor in5, in1, global4 | ||
| 1946 | |||
| 1947 | load_little_endian_inc(local5, in0, in1, local3, .LLE10) ! iv next block | ||
| 1948 | |||
| 1949 | store_little_endian(local7, out4, global4, local3, .SLE7) ! block | ||
| 1950 | |||
| 1951 | STPTR local5, INPUT | ||
| 1952 | addcc in2, -8, in2 | ||
| 1953 | add local7, 8, local7 | ||
| 1954 | |||
| 1955 | #ifdef OPENSSL_SYSNAME_ULTRASPARC | ||
| 1956 | bg,pt %icc, .ede3.dec.next.block | ||
| 1957 | #else | ||
| 1958 | bg .ede3.dec.next.block | ||
| 1959 | #endif | ||
| 1960 | STPTR local7, OUTPUT | ||
| 1961 | |||
| 1962 | .ede3.dec.store.iv: | ||
| 1963 | |||
| 1964 | LDPTR [%fp+BIAS+ARG0+6*ARGSZ], local4 ! ivec | ||
| 1965 | store_little_endian(local4, in0, in1, local5, .SLE8) ! ivec | ||
| 1966 | |||
| 1967 | .ede3.dec.finish: | ||
| 1968 | |||
| 1969 | ret | ||
| 1970 | restore | ||
| 1971 | |||
| 1972 | .ede3.dec.seven.or.less: | ||
| 1973 | |||
| 1974 | load_little_endian_inc(local5, in0, in1, local3, .LLE14) ! iv | ||
| 1975 | |||
| 1976 | store_n_bytes(local7, in2, global4, out4, local3, local4, .SNB2, .ede3.dec.store.iv) | ||
| 1977 | |||
| 1978 | |||
| 1979 | .DES_ede3_cbc_encrypt.end: | ||
| 1980 | .size DES_ede3_cbc_encrypt,.DES_ede3_cbc_encrypt.end-DES_ede3_cbc_encrypt | ||
diff --git a/src/lib/libcrypto/des/asm/desboth.pl b/src/lib/libcrypto/des/asm/desboth.pl new file mode 100644 index 0000000000..eec00886e4 --- /dev/null +++ b/src/lib/libcrypto/des/asm/desboth.pl | |||
| @@ -0,0 +1,79 @@ | |||
| 1 | #!/usr/local/bin/perl | ||
| 2 | |||
| 3 | $L="edi"; | ||
| 4 | $R="esi"; | ||
| 5 | |||
| 6 | sub DES_encrypt3 | ||
| 7 | { | ||
| 8 | local($name,$enc)=@_; | ||
| 9 | |||
| 10 | &function_begin_B($name,""); | ||
| 11 | &push("ebx"); | ||
| 12 | &mov("ebx",&wparam(0)); | ||
| 13 | |||
| 14 | &push("ebp"); | ||
| 15 | &push("esi"); | ||
| 16 | |||
| 17 | &push("edi"); | ||
| 18 | |||
| 19 | &comment(""); | ||
| 20 | &comment("Load the data words"); | ||
| 21 | &mov($L,&DWP(0,"ebx","",0)); | ||
| 22 | &mov($R,&DWP(4,"ebx","",0)); | ||
| 23 | &stack_push(3); | ||
| 24 | |||
| 25 | &comment(""); | ||
| 26 | &comment("IP"); | ||
| 27 | &IP_new($L,$R,"edx",0); | ||
| 28 | |||
| 29 | # put them back | ||
| 30 | |||
| 31 | if ($enc) | ||
| 32 | { | ||
| 33 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 34 | &mov("eax",&wparam(1)); | ||
| 35 | &mov(&DWP(0,"ebx","",0),"edx"); | ||
| 36 | &mov("edi",&wparam(2)); | ||
| 37 | &mov("esi",&wparam(3)); | ||
| 38 | } | ||
| 39 | else | ||
| 40 | { | ||
| 41 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 42 | &mov("esi",&wparam(1)); | ||
| 43 | &mov(&DWP(0,"ebx","",0),"edx"); | ||
| 44 | &mov("edi",&wparam(2)); | ||
| 45 | &mov("eax",&wparam(3)); | ||
| 46 | } | ||
| 47 | &mov(&swtmp(2), (DWC(($enc)?"1":"0"))); | ||
| 48 | &mov(&swtmp(1), "eax"); | ||
| 49 | &mov(&swtmp(0), "ebx"); | ||
| 50 | &call("DES_encrypt2"); | ||
| 51 | &mov(&swtmp(2), (DWC(($enc)?"0":"1"))); | ||
| 52 | &mov(&swtmp(1), "edi"); | ||
| 53 | &mov(&swtmp(0), "ebx"); | ||
| 54 | &call("DES_encrypt2"); | ||
| 55 | &mov(&swtmp(2), (DWC(($enc)?"1":"0"))); | ||
| 56 | &mov(&swtmp(1), "esi"); | ||
| 57 | &mov(&swtmp(0), "ebx"); | ||
| 58 | &call("DES_encrypt2"); | ||
| 59 | |||
| 60 | &stack_pop(3); | ||
| 61 | &mov($L,&DWP(0,"ebx","",0)); | ||
| 62 | &mov($R,&DWP(4,"ebx","",0)); | ||
| 63 | |||
| 64 | &comment(""); | ||
| 65 | &comment("FP"); | ||
| 66 | &FP_new($L,$R,"eax",0); | ||
| 67 | |||
| 68 | &mov(&DWP(0,"ebx","",0),"eax"); | ||
| 69 | &mov(&DWP(4,"ebx","",0),$R); | ||
| 70 | |||
| 71 | &pop("edi"); | ||
| 72 | &pop("esi"); | ||
| 73 | &pop("ebp"); | ||
| 74 | &pop("ebx"); | ||
| 75 | &ret(); | ||
| 76 | &function_end_B($name); | ||
| 77 | } | ||
| 78 | |||
| 79 | |||
diff --git a/src/lib/libcrypto/des/cbc_cksm.c b/src/lib/libcrypto/des/cbc_cksm.c new file mode 100644 index 0000000000..09a7ba56aa --- /dev/null +++ b/src/lib/libcrypto/des/cbc_cksm.c | |||
| @@ -0,0 +1,106 @@ | |||
| 1 | /* crypto/des/cbc_cksm.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 "des_locl.h" | ||
| 60 | |||
| 61 | DES_LONG DES_cbc_cksum(const unsigned char *in, DES_cblock *output, | ||
| 62 | long length, DES_key_schedule *schedule, | ||
| 63 | const_DES_cblock *ivec) | ||
| 64 | { | ||
| 65 | register DES_LONG tout0,tout1,tin0,tin1; | ||
| 66 | register long l=length; | ||
| 67 | DES_LONG tin[2]; | ||
| 68 | unsigned char *out = &(*output)[0]; | ||
| 69 | const unsigned char *iv = &(*ivec)[0]; | ||
| 70 | |||
| 71 | c2l(iv,tout0); | ||
| 72 | c2l(iv,tout1); | ||
| 73 | for (; l>0; l-=8) | ||
| 74 | { | ||
| 75 | if (l >= 8) | ||
| 76 | { | ||
| 77 | c2l(in,tin0); | ||
| 78 | c2l(in,tin1); | ||
| 79 | } | ||
| 80 | else | ||
| 81 | c2ln(in,tin0,tin1,l); | ||
| 82 | |||
| 83 | tin0^=tout0; tin[0]=tin0; | ||
| 84 | tin1^=tout1; tin[1]=tin1; | ||
| 85 | DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 86 | /* fix 15/10/91 eay - thanks to keithr@sco.COM */ | ||
| 87 | tout0=tin[0]; | ||
| 88 | tout1=tin[1]; | ||
| 89 | } | ||
| 90 | if (out != NULL) | ||
| 91 | { | ||
| 92 | l2c(tout0,out); | ||
| 93 | l2c(tout1,out); | ||
| 94 | } | ||
| 95 | tout0=tin0=tin1=tin[0]=tin[1]=0; | ||
| 96 | /* | ||
| 97 | Transform the data in tout1 so that it will | ||
| 98 | match the return value that the MIT Kerberos | ||
| 99 | mit_des_cbc_cksum API returns. | ||
| 100 | */ | ||
| 101 | tout1 = ((tout1 >> 24L) & 0x000000FF) | ||
| 102 | | ((tout1 >> 8L) & 0x0000FF00) | ||
| 103 | | ((tout1 << 8L) & 0x00FF0000) | ||
| 104 | | ((tout1 << 24L) & 0xFF000000); | ||
| 105 | return(tout1); | ||
| 106 | } | ||
diff --git a/src/lib/libcrypto/des/cbc_enc.c b/src/lib/libcrypto/des/cbc_enc.c new file mode 100644 index 0000000000..677903ae4e --- /dev/null +++ b/src/lib/libcrypto/des/cbc_enc.c | |||
| @@ -0,0 +1,61 @@ | |||
| 1 | /* crypto/des/cbc_enc.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 | #define CBC_ENC_C__DONT_UPDATE_IV | ||
| 60 | |||
| 61 | #include "ncbc_enc.c" /* des_cbc_encrypt */ | ||
diff --git a/src/lib/libcrypto/des/cfb64ede.c b/src/lib/libcrypto/des/cfb64ede.c new file mode 100644 index 0000000000..de34ecceb9 --- /dev/null +++ b/src/lib/libcrypto/des/cfb64ede.c | |||
| @@ -0,0 +1,254 @@ | |||
| 1 | /* crypto/des/cfb64ede.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 "des_locl.h" | ||
| 60 | #include "e_os.h" | ||
| 61 | |||
| 62 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 63 | * used. The extra state information to record how much of the | ||
| 64 | * 64bit block we have used is contained in *num; | ||
| 65 | */ | ||
| 66 | |||
| 67 | void DES_ede3_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 68 | long length, DES_key_schedule *ks1, | ||
| 69 | DES_key_schedule *ks2, DES_key_schedule *ks3, | ||
| 70 | DES_cblock *ivec, int *num, int enc) | ||
| 71 | { | ||
| 72 | register DES_LONG v0,v1; | ||
| 73 | register long l=length; | ||
| 74 | register int n= *num; | ||
| 75 | DES_LONG ti[2]; | ||
| 76 | unsigned char *iv,c,cc; | ||
| 77 | |||
| 78 | iv=&(*ivec)[0]; | ||
| 79 | if (enc) | ||
| 80 | { | ||
| 81 | while (l--) | ||
| 82 | { | ||
| 83 | if (n == 0) | ||
| 84 | { | ||
| 85 | c2l(iv,v0); | ||
| 86 | c2l(iv,v1); | ||
| 87 | |||
| 88 | ti[0]=v0; | ||
| 89 | ti[1]=v1; | ||
| 90 | DES_encrypt3(ti,ks1,ks2,ks3); | ||
| 91 | v0=ti[0]; | ||
| 92 | v1=ti[1]; | ||
| 93 | |||
| 94 | iv = &(*ivec)[0]; | ||
| 95 | l2c(v0,iv); | ||
| 96 | l2c(v1,iv); | ||
| 97 | iv = &(*ivec)[0]; | ||
| 98 | } | ||
| 99 | c= *(in++)^iv[n]; | ||
| 100 | *(out++)=c; | ||
| 101 | iv[n]=c; | ||
| 102 | n=(n+1)&0x07; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | else | ||
| 106 | { | ||
| 107 | while (l--) | ||
| 108 | { | ||
| 109 | if (n == 0) | ||
| 110 | { | ||
| 111 | c2l(iv,v0); | ||
| 112 | c2l(iv,v1); | ||
| 113 | |||
| 114 | ti[0]=v0; | ||
| 115 | ti[1]=v1; | ||
| 116 | DES_encrypt3(ti,ks1,ks2,ks3); | ||
| 117 | v0=ti[0]; | ||
| 118 | v1=ti[1]; | ||
| 119 | |||
| 120 | iv = &(*ivec)[0]; | ||
| 121 | l2c(v0,iv); | ||
| 122 | l2c(v1,iv); | ||
| 123 | iv = &(*ivec)[0]; | ||
| 124 | } | ||
| 125 | cc= *(in++); | ||
| 126 | c=iv[n]; | ||
| 127 | iv[n]=cc; | ||
| 128 | *(out++)=c^cc; | ||
| 129 | n=(n+1)&0x07; | ||
| 130 | } | ||
| 131 | } | ||
| 132 | v0=v1=ti[0]=ti[1]=c=cc=0; | ||
| 133 | *num=n; | ||
| 134 | } | ||
| 135 | |||
| 136 | #ifdef undef /* MACRO */ | ||
| 137 | void DES_ede2_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, | ||
| 138 | DES_key_schedule ks1, DES_key_schedule ks2, DES_cblock (*ivec), | ||
| 139 | int *num, int enc) | ||
| 140 | { | ||
| 141 | DES_ede3_cfb64_encrypt(in,out,length,ks1,ks2,ks1,ivec,num,enc); | ||
| 142 | } | ||
| 143 | #endif | ||
| 144 | |||
| 145 | /* This is compatible with the single key CFB-r for DES, even thought that's | ||
| 146 | * not what EVP needs. | ||
| 147 | */ | ||
| 148 | |||
| 149 | void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, | ||
| 150 | int numbits,long length,DES_key_schedule *ks1, | ||
| 151 | DES_key_schedule *ks2,DES_key_schedule *ks3, | ||
| 152 | DES_cblock *ivec,int enc) | ||
| 153 | { | ||
| 154 | register DES_LONG d0,d1,v0,v1; | ||
| 155 | register unsigned long l=length,n=((unsigned int)numbits+7)/8; | ||
| 156 | register int num=numbits,i; | ||
| 157 | DES_LONG ti[2]; | ||
| 158 | unsigned char *iv; | ||
| 159 | unsigned char ovec[16]; | ||
| 160 | |||
| 161 | if (num > 64) return; | ||
| 162 | iv = &(*ivec)[0]; | ||
| 163 | c2l(iv,v0); | ||
| 164 | c2l(iv,v1); | ||
| 165 | if (enc) | ||
| 166 | { | ||
| 167 | while (l >= n) | ||
| 168 | { | ||
| 169 | l-=n; | ||
| 170 | ti[0]=v0; | ||
| 171 | ti[1]=v1; | ||
| 172 | DES_encrypt3(ti,ks1,ks2,ks3); | ||
| 173 | c2ln(in,d0,d1,n); | ||
| 174 | in+=n; | ||
| 175 | d0^=ti[0]; | ||
| 176 | d1^=ti[1]; | ||
| 177 | l2cn(d0,d1,out,n); | ||
| 178 | out+=n; | ||
| 179 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 180 | * l<<32 are bad under gcc :-( */ | ||
| 181 | if (num == 32) | ||
| 182 | { v0=v1; v1=d0; } | ||
| 183 | else if (num == 64) | ||
| 184 | { v0=d0; v1=d1; } | ||
| 185 | else | ||
| 186 | { | ||
| 187 | iv=&ovec[0]; | ||
| 188 | l2c(v0,iv); | ||
| 189 | l2c(v1,iv); | ||
| 190 | l2c(d0,iv); | ||
| 191 | l2c(d1,iv); | ||
| 192 | /* shift ovec left most of the bits... */ | ||
| 193 | memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); | ||
| 194 | /* now the remaining bits */ | ||
| 195 | if(num%8 != 0) | ||
| 196 | for(i=0 ; i < 8 ; ++i) | ||
| 197 | { | ||
| 198 | ovec[i]<<=num%8; | ||
| 199 | ovec[i]|=ovec[i+1]>>(8-num%8); | ||
| 200 | } | ||
| 201 | iv=&ovec[0]; | ||
| 202 | c2l(iv,v0); | ||
| 203 | c2l(iv,v1); | ||
| 204 | } | ||
| 205 | } | ||
| 206 | } | ||
| 207 | else | ||
| 208 | { | ||
| 209 | while (l >= n) | ||
| 210 | { | ||
| 211 | l-=n; | ||
| 212 | ti[0]=v0; | ||
| 213 | ti[1]=v1; | ||
| 214 | DES_encrypt3(ti,ks1,ks2,ks3); | ||
| 215 | c2ln(in,d0,d1,n); | ||
| 216 | in+=n; | ||
| 217 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 218 | * l<<32 are bad under gcc :-( */ | ||
| 219 | if (num == 32) | ||
| 220 | { v0=v1; v1=d0; } | ||
| 221 | else if (num == 64) | ||
| 222 | { v0=d0; v1=d1; } | ||
| 223 | else | ||
| 224 | { | ||
| 225 | iv=&ovec[0]; | ||
| 226 | l2c(v0,iv); | ||
| 227 | l2c(v1,iv); | ||
| 228 | l2c(d0,iv); | ||
| 229 | l2c(d1,iv); | ||
| 230 | /* shift ovec left most of the bits... */ | ||
| 231 | memmove(ovec,ovec+num/8,8+(num%8 ? 1 : 0)); | ||
| 232 | /* now the remaining bits */ | ||
| 233 | if(num%8 != 0) | ||
| 234 | for(i=0 ; i < 8 ; ++i) | ||
| 235 | { | ||
| 236 | ovec[i]<<=num%8; | ||
| 237 | ovec[i]|=ovec[i+1]>>(8-num%8); | ||
| 238 | } | ||
| 239 | iv=&ovec[0]; | ||
| 240 | c2l(iv,v0); | ||
| 241 | c2l(iv,v1); | ||
| 242 | } | ||
| 243 | d0^=ti[0]; | ||
| 244 | d1^=ti[1]; | ||
| 245 | l2cn(d0,d1,out,n); | ||
| 246 | out+=n; | ||
| 247 | } | ||
| 248 | } | ||
| 249 | iv = &(*ivec)[0]; | ||
| 250 | l2c(v0,iv); | ||
| 251 | l2c(v1,iv); | ||
| 252 | v0=v1=d0=d1=ti[0]=ti[1]=0; | ||
| 253 | } | ||
| 254 | |||
diff --git a/src/lib/libcrypto/des/cfb64enc.c b/src/lib/libcrypto/des/cfb64enc.c new file mode 100644 index 0000000000..5ec8683e40 --- /dev/null +++ b/src/lib/libcrypto/des/cfb64enc.c | |||
| @@ -0,0 +1,121 @@ | |||
| 1 | /* crypto/des/cfb64enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit cfb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | |||
| 66 | void DES_cfb64_encrypt(const unsigned char *in, unsigned char *out, | ||
| 67 | long length, DES_key_schedule *schedule, | ||
| 68 | DES_cblock *ivec, int *num, int enc) | ||
| 69 | { | ||
| 70 | register DES_LONG v0,v1; | ||
| 71 | register long l=length; | ||
| 72 | register int n= *num; | ||
| 73 | DES_LONG ti[2]; | ||
| 74 | unsigned char *iv,c,cc; | ||
| 75 | |||
| 76 | iv = &(*ivec)[0]; | ||
| 77 | if (enc) | ||
| 78 | { | ||
| 79 | while (l--) | ||
| 80 | { | ||
| 81 | if (n == 0) | ||
| 82 | { | ||
| 83 | c2l(iv,v0); ti[0]=v0; | ||
| 84 | c2l(iv,v1); ti[1]=v1; | ||
| 85 | DES_encrypt1(ti,schedule,DES_ENCRYPT); | ||
| 86 | iv = &(*ivec)[0]; | ||
| 87 | v0=ti[0]; l2c(v0,iv); | ||
| 88 | v0=ti[1]; l2c(v0,iv); | ||
| 89 | iv = &(*ivec)[0]; | ||
| 90 | } | ||
| 91 | c= *(in++)^iv[n]; | ||
| 92 | *(out++)=c; | ||
| 93 | iv[n]=c; | ||
| 94 | n=(n+1)&0x07; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | else | ||
| 98 | { | ||
| 99 | while (l--) | ||
| 100 | { | ||
| 101 | if (n == 0) | ||
| 102 | { | ||
| 103 | c2l(iv,v0); ti[0]=v0; | ||
| 104 | c2l(iv,v1); ti[1]=v1; | ||
| 105 | DES_encrypt1(ti,schedule,DES_ENCRYPT); | ||
| 106 | iv = &(*ivec)[0]; | ||
| 107 | v0=ti[0]; l2c(v0,iv); | ||
| 108 | v0=ti[1]; l2c(v0,iv); | ||
| 109 | iv = &(*ivec)[0]; | ||
| 110 | } | ||
| 111 | cc= *(in++); | ||
| 112 | c=iv[n]; | ||
| 113 | iv[n]=cc; | ||
| 114 | *(out++)=c^cc; | ||
| 115 | n=(n+1)&0x07; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | v0=v1=ti[0]=ti[1]=c=cc=0; | ||
| 119 | *num=n; | ||
| 120 | } | ||
| 121 | |||
diff --git a/src/lib/libcrypto/des/cfb_enc.c b/src/lib/libcrypto/des/cfb_enc.c new file mode 100644 index 0000000000..720f29a28e --- /dev/null +++ b/src/lib/libcrypto/des/cfb_enc.c | |||
| @@ -0,0 +1,195 @@ | |||
| 1 | /* crypto/des/cfb_enc.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 "e_os.h" | ||
| 60 | #include "des_locl.h" | ||
| 61 | #include <assert.h> | ||
| 62 | |||
| 63 | /* The input and output are loaded in multiples of 8 bits. | ||
| 64 | * What this means is that if you hame numbits=12 and length=2 | ||
| 65 | * the first 12 bits will be retrieved from the first byte and half | ||
| 66 | * the second. The second 12 bits will come from the 3rd and half the 4th | ||
| 67 | * byte. | ||
| 68 | */ | ||
| 69 | /* Until Aug 1 2003 this function did not correctly implement CFB-r, so it | ||
| 70 | * will not be compatible with any encryption prior to that date. Ben. */ | ||
| 71 | void DES_cfb_encrypt(const unsigned char *in, unsigned char *out, int numbits, | ||
| 72 | long length, DES_key_schedule *schedule, DES_cblock *ivec, | ||
| 73 | int enc) | ||
| 74 | { | ||
| 75 | register DES_LONG d0,d1,v0,v1; | ||
| 76 | register unsigned long l=length; | ||
| 77 | register int num=numbits/8,n=(numbits+7)/8,i,rem=numbits%8; | ||
| 78 | DES_LONG ti[2]; | ||
| 79 | unsigned char *iv; | ||
| 80 | #ifndef L_ENDIAN | ||
| 81 | unsigned char ovec[16]; | ||
| 82 | #else | ||
| 83 | unsigned int sh[4]; | ||
| 84 | unsigned char *ovec=(unsigned char *)sh; | ||
| 85 | |||
| 86 | /* I kind of count that compiler optimizes away this assertioni,*/ | ||
| 87 | assert (sizeof(sh[0])==4); /* as this holds true for all, */ | ||
| 88 | /* but 16-bit platforms... */ | ||
| 89 | |||
| 90 | #endif | ||
| 91 | |||
| 92 | if (numbits<=0 || numbits > 64) return; | ||
| 93 | iv = &(*ivec)[0]; | ||
| 94 | c2l(iv,v0); | ||
| 95 | c2l(iv,v1); | ||
| 96 | if (enc) | ||
| 97 | { | ||
| 98 | while (l >= (unsigned long)n) | ||
| 99 | { | ||
| 100 | l-=n; | ||
| 101 | ti[0]=v0; | ||
| 102 | ti[1]=v1; | ||
| 103 | DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 104 | c2ln(in,d0,d1,n); | ||
| 105 | in+=n; | ||
| 106 | d0^=ti[0]; | ||
| 107 | d1^=ti[1]; | ||
| 108 | l2cn(d0,d1,out,n); | ||
| 109 | out+=n; | ||
| 110 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 111 | * l<<32 are bad under gcc :-( */ | ||
| 112 | if (numbits == 32) | ||
| 113 | { v0=v1; v1=d0; } | ||
| 114 | else if (numbits == 64) | ||
| 115 | { v0=d0; v1=d1; } | ||
| 116 | else | ||
| 117 | { | ||
| 118 | #ifndef L_ENDIAN | ||
| 119 | iv=&ovec[0]; | ||
| 120 | l2c(v0,iv); | ||
| 121 | l2c(v1,iv); | ||
| 122 | l2c(d0,iv); | ||
| 123 | l2c(d1,iv); | ||
| 124 | #else | ||
| 125 | sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; | ||
| 126 | #endif | ||
| 127 | if (rem==0) | ||
| 128 | memmove(ovec,ovec+num,8); | ||
| 129 | else | ||
| 130 | for(i=0 ; i < 8 ; ++i) | ||
| 131 | ovec[i]=ovec[i+num]<<rem | | ||
| 132 | ovec[i+num+1]>>(8-rem); | ||
| 133 | #ifdef L_ENDIAN | ||
| 134 | v0=sh[0], v1=sh[1]; | ||
| 135 | #else | ||
| 136 | iv=&ovec[0]; | ||
| 137 | c2l(iv,v0); | ||
| 138 | c2l(iv,v1); | ||
| 139 | #endif | ||
| 140 | } | ||
| 141 | } | ||
| 142 | } | ||
| 143 | else | ||
| 144 | { | ||
| 145 | while (l >= (unsigned long)n) | ||
| 146 | { | ||
| 147 | l-=n; | ||
| 148 | ti[0]=v0; | ||
| 149 | ti[1]=v1; | ||
| 150 | DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 151 | c2ln(in,d0,d1,n); | ||
| 152 | in+=n; | ||
| 153 | /* 30-08-94 - eay - changed because l>>32 and | ||
| 154 | * l<<32 are bad under gcc :-( */ | ||
| 155 | if (numbits == 32) | ||
| 156 | { v0=v1; v1=d0; } | ||
| 157 | else if (numbits == 64) | ||
| 158 | { v0=d0; v1=d1; } | ||
| 159 | else | ||
| 160 | { | ||
| 161 | #ifndef L_ENDIAN | ||
| 162 | iv=&ovec[0]; | ||
| 163 | l2c(v0,iv); | ||
| 164 | l2c(v1,iv); | ||
| 165 | l2c(d0,iv); | ||
| 166 | l2c(d1,iv); | ||
| 167 | #else | ||
| 168 | sh[0]=v0, sh[1]=v1, sh[2]=d0, sh[3]=d1; | ||
| 169 | #endif | ||
| 170 | if (rem==0) | ||
| 171 | memmove(ovec,ovec+num,8); | ||
| 172 | else | ||
| 173 | for(i=0 ; i < 8 ; ++i) | ||
| 174 | ovec[i]=ovec[i+num]<<rem | | ||
| 175 | ovec[i+num+1]>>(8-rem); | ||
| 176 | #ifdef L_ENDIAN | ||
| 177 | v0=sh[0], v1=sh[1]; | ||
| 178 | #else | ||
| 179 | iv=&ovec[0]; | ||
| 180 | c2l(iv,v0); | ||
| 181 | c2l(iv,v1); | ||
| 182 | #endif | ||
| 183 | } | ||
| 184 | d0^=ti[0]; | ||
| 185 | d1^=ti[1]; | ||
| 186 | l2cn(d0,d1,out,n); | ||
| 187 | out+=n; | ||
| 188 | } | ||
| 189 | } | ||
| 190 | iv = &(*ivec)[0]; | ||
| 191 | l2c(v0,iv); | ||
| 192 | l2c(v1,iv); | ||
| 193 | v0=v1=d0=d1=ti[0]=ti[1]=0; | ||
| 194 | } | ||
| 195 | |||
diff --git a/src/lib/libcrypto/des/des.h b/src/lib/libcrypto/des/des.h new file mode 100644 index 0000000000..7318593699 --- /dev/null +++ b/src/lib/libcrypto/des/des.h | |||
| @@ -0,0 +1,247 @@ | |||
| 1 | /* crypto/des/des.h */ | ||
| 2 | /* Copyright (C) 1995-1997 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_DES_H | ||
| 60 | #define HEADER_DES_H | ||
| 61 | |||
| 62 | #include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, | ||
| 63 | DES_LONG (via openssl/opensslconf.h */ | ||
| 64 | |||
| 65 | #ifdef OPENSSL_NO_DES | ||
| 66 | #error DES is disabled. | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | ||
| 70 | # undef OPENSSL_EXTERN | ||
| 71 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #define des_SPtrans DES_SPtrans | ||
| 75 | |||
| 76 | #ifdef __cplusplus | ||
| 77 | extern "C" { | ||
| 78 | #endif | ||
| 79 | |||
| 80 | typedef unsigned char DES_cblock[8]; | ||
| 81 | typedef /* const */ unsigned char const_DES_cblock[8]; | ||
| 82 | /* With "const", gcc 2.8.1 on Solaris thinks that DES_cblock * | ||
| 83 | * and const_DES_cblock * are incompatible pointer types. */ | ||
| 84 | |||
| 85 | typedef struct DES_ks | ||
| 86 | { | ||
| 87 | union | ||
| 88 | { | ||
| 89 | DES_cblock cblock; | ||
| 90 | /* make sure things are correct size on machines with | ||
| 91 | * 8 byte longs */ | ||
| 92 | DES_LONG deslong[2]; | ||
| 93 | } ks[16]; | ||
| 94 | } DES_key_schedule; | ||
| 95 | |||
| 96 | #ifndef OPENSSL_DISABLE_OLD_DES_SUPPORT | ||
| 97 | # ifndef OPENSSL_ENABLE_OLD_DES_SUPPORT | ||
| 98 | # define OPENSSL_ENABLE_OLD_DES_SUPPORT | ||
| 99 | # endif | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #ifdef OPENSSL_ENABLE_OLD_DES_SUPPORT | ||
| 103 | # include <openssl/des_old.h> | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #define DES_KEY_SZ (sizeof(DES_cblock)) | ||
| 107 | #define DES_SCHEDULE_SZ (sizeof(DES_key_schedule)) | ||
| 108 | |||
| 109 | #define DES_ENCRYPT 1 | ||
| 110 | #define DES_DECRYPT 0 | ||
| 111 | |||
| 112 | #define DES_CBC_MODE 0 | ||
| 113 | #define DES_PCBC_MODE 1 | ||
| 114 | |||
| 115 | #define DES_ecb2_encrypt(i,o,k1,k2,e) \ | ||
| 116 | DES_ecb3_encrypt((i),(o),(k1),(k2),(k1),(e)) | ||
| 117 | |||
| 118 | #define DES_ede2_cbc_encrypt(i,o,l,k1,k2,iv,e) \ | ||
| 119 | DES_ede3_cbc_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(e)) | ||
| 120 | |||
| 121 | #define DES_ede2_cfb64_encrypt(i,o,l,k1,k2,iv,n,e) \ | ||
| 122 | DES_ede3_cfb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n),(e)) | ||
| 123 | |||
| 124 | #define DES_ede2_ofb64_encrypt(i,o,l,k1,k2,iv,n) \ | ||
| 125 | DES_ede3_ofb64_encrypt((i),(o),(l),(k1),(k2),(k1),(iv),(n)) | ||
| 126 | |||
| 127 | OPENSSL_DECLARE_GLOBAL(int,DES_check_key); /* defaults to false */ | ||
| 128 | #define DES_check_key OPENSSL_GLOBAL_REF(DES_check_key) | ||
| 129 | OPENSSL_DECLARE_GLOBAL(int,DES_rw_mode); /* defaults to DES_PCBC_MODE */ | ||
| 130 | #define DES_rw_mode OPENSSL_GLOBAL_REF(DES_rw_mode) | ||
| 131 | |||
| 132 | const char *DES_options(void); | ||
| 133 | void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, | ||
| 134 | DES_key_schedule *ks1,DES_key_schedule *ks2, | ||
| 135 | DES_key_schedule *ks3, int enc); | ||
| 136 | DES_LONG DES_cbc_cksum(const unsigned char *input,DES_cblock *output, | ||
| 137 | long length,DES_key_schedule *schedule, | ||
| 138 | const_DES_cblock *ivec); | ||
| 139 | /* DES_cbc_encrypt does not update the IV! Use DES_ncbc_encrypt instead. */ | ||
| 140 | void DES_cbc_encrypt(const unsigned char *input,unsigned char *output, | ||
| 141 | long length,DES_key_schedule *schedule,DES_cblock *ivec, | ||
| 142 | int enc); | ||
| 143 | void DES_ncbc_encrypt(const unsigned char *input,unsigned char *output, | ||
| 144 | long length,DES_key_schedule *schedule,DES_cblock *ivec, | ||
| 145 | int enc); | ||
| 146 | void DES_xcbc_encrypt(const unsigned char *input,unsigned char *output, | ||
| 147 | long length,DES_key_schedule *schedule,DES_cblock *ivec, | ||
| 148 | const_DES_cblock *inw,const_DES_cblock *outw,int enc); | ||
| 149 | void DES_cfb_encrypt(const unsigned char *in,unsigned char *out,int numbits, | ||
| 150 | long length,DES_key_schedule *schedule,DES_cblock *ivec, | ||
| 151 | int enc); | ||
| 152 | void DES_ecb_encrypt(const_DES_cblock *input,DES_cblock *output, | ||
| 153 | DES_key_schedule *ks,int enc); | ||
| 154 | |||
| 155 | /* This is the DES encryption function that gets called by just about | ||
| 156 | every other DES routine in the library. You should not use this | ||
| 157 | function except to implement 'modes' of DES. I say this because the | ||
| 158 | functions that call this routine do the conversion from 'char *' to | ||
| 159 | long, and this needs to be done to make sure 'non-aligned' memory | ||
| 160 | access do not occur. The characters are loaded 'little endian'. | ||
| 161 | Data is a pointer to 2 unsigned long's and ks is the | ||
| 162 | DES_key_schedule to use. enc, is non zero specifies encryption, | ||
| 163 | zero if decryption. */ | ||
| 164 | void DES_encrypt1(DES_LONG *data,DES_key_schedule *ks, int enc); | ||
| 165 | |||
| 166 | /* This functions is the same as DES_encrypt1() except that the DES | ||
| 167 | initial permutation (IP) and final permutation (FP) have been left | ||
| 168 | out. As for DES_encrypt1(), you should not use this function. | ||
| 169 | It is used by the routines in the library that implement triple DES. | ||
| 170 | IP() DES_encrypt2() DES_encrypt2() DES_encrypt2() FP() is the same | ||
| 171 | as DES_encrypt1() DES_encrypt1() DES_encrypt1() except faster :-). */ | ||
| 172 | void DES_encrypt2(DES_LONG *data,DES_key_schedule *ks, int enc); | ||
| 173 | |||
| 174 | void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, | ||
| 175 | DES_key_schedule *ks2, DES_key_schedule *ks3); | ||
| 176 | void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, | ||
| 177 | DES_key_schedule *ks2, DES_key_schedule *ks3); | ||
| 178 | void DES_ede3_cbc_encrypt(const unsigned char *input,unsigned char *output, | ||
| 179 | long length, | ||
| 180 | DES_key_schedule *ks1,DES_key_schedule *ks2, | ||
| 181 | DES_key_schedule *ks3,DES_cblock *ivec,int enc); | ||
| 182 | void DES_ede3_cbcm_encrypt(const unsigned char *in,unsigned char *out, | ||
| 183 | long length, | ||
| 184 | DES_key_schedule *ks1,DES_key_schedule *ks2, | ||
| 185 | DES_key_schedule *ks3, | ||
| 186 | DES_cblock *ivec1,DES_cblock *ivec2, | ||
| 187 | int enc); | ||
| 188 | void DES_ede3_cfb64_encrypt(const unsigned char *in,unsigned char *out, | ||
| 189 | long length,DES_key_schedule *ks1, | ||
| 190 | DES_key_schedule *ks2,DES_key_schedule *ks3, | ||
| 191 | DES_cblock *ivec,int *num,int enc); | ||
| 192 | void DES_ede3_cfb_encrypt(const unsigned char *in,unsigned char *out, | ||
| 193 | int numbits,long length,DES_key_schedule *ks1, | ||
| 194 | DES_key_schedule *ks2,DES_key_schedule *ks3, | ||
| 195 | DES_cblock *ivec,int enc); | ||
| 196 | void DES_ede3_ofb64_encrypt(const unsigned char *in,unsigned char *out, | ||
| 197 | long length,DES_key_schedule *ks1, | ||
| 198 | DES_key_schedule *ks2,DES_key_schedule *ks3, | ||
| 199 | DES_cblock *ivec,int *num); | ||
| 200 | #if 0 | ||
| 201 | void DES_xwhite_in2out(const_DES_cblock *DES_key,const_DES_cblock *in_white, | ||
| 202 | DES_cblock *out_white); | ||
| 203 | #endif | ||
| 204 | |||
| 205 | int DES_enc_read(int fd,void *buf,int len,DES_key_schedule *sched, | ||
| 206 | DES_cblock *iv); | ||
| 207 | int DES_enc_write(int fd,const void *buf,int len,DES_key_schedule *sched, | ||
| 208 | DES_cblock *iv); | ||
| 209 | char *DES_fcrypt(const char *buf,const char *salt, char *ret); | ||
| 210 | char *DES_crypt(const char *buf,const char *salt); | ||
| 211 | void DES_ofb_encrypt(const unsigned char *in,unsigned char *out,int numbits, | ||
| 212 | long length,DES_key_schedule *schedule,DES_cblock *ivec); | ||
| 213 | void DES_pcbc_encrypt(const unsigned char *input,unsigned char *output, | ||
| 214 | long length,DES_key_schedule *schedule,DES_cblock *ivec, | ||
| 215 | int enc); | ||
| 216 | DES_LONG DES_quad_cksum(const unsigned char *input,DES_cblock output[], | ||
| 217 | long length,int out_count,DES_cblock *seed); | ||
| 218 | int DES_random_key(DES_cblock *ret); | ||
| 219 | void DES_set_odd_parity(DES_cblock *key); | ||
| 220 | int DES_check_key_parity(const_DES_cblock *key); | ||
| 221 | int DES_is_weak_key(const_DES_cblock *key); | ||
| 222 | /* DES_set_key (= set_key = DES_key_sched = key_sched) calls | ||
| 223 | * DES_set_key_checked if global variable DES_check_key is set, | ||
| 224 | * DES_set_key_unchecked otherwise. */ | ||
| 225 | int DES_set_key(const_DES_cblock *key,DES_key_schedule *schedule); | ||
| 226 | int DES_key_sched(const_DES_cblock *key,DES_key_schedule *schedule); | ||
| 227 | int DES_set_key_checked(const_DES_cblock *key,DES_key_schedule *schedule); | ||
| 228 | void DES_set_key_unchecked(const_DES_cblock *key,DES_key_schedule *schedule); | ||
| 229 | void DES_string_to_key(const char *str,DES_cblock *key); | ||
| 230 | void DES_string_to_2keys(const char *str,DES_cblock *key1,DES_cblock *key2); | ||
| 231 | void DES_cfb64_encrypt(const unsigned char *in,unsigned char *out,long length, | ||
| 232 | DES_key_schedule *schedule,DES_cblock *ivec,int *num, | ||
| 233 | int enc); | ||
| 234 | void DES_ofb64_encrypt(const unsigned char *in,unsigned char *out,long length, | ||
| 235 | DES_key_schedule *schedule,DES_cblock *ivec,int *num); | ||
| 236 | |||
| 237 | int DES_read_password(DES_cblock *key, const char *prompt, int verify); | ||
| 238 | int DES_read_2passwords(DES_cblock *key1, DES_cblock *key2, const char *prompt, | ||
| 239 | int verify); | ||
| 240 | |||
| 241 | #define DES_fixup_key_parity DES_set_odd_parity | ||
| 242 | |||
| 243 | #ifdef __cplusplus | ||
| 244 | } | ||
| 245 | #endif | ||
| 246 | |||
| 247 | #endif | ||
diff --git a/src/lib/libcrypto/des/des_enc.c b/src/lib/libcrypto/des/des_enc.c new file mode 100644 index 0000000000..0fe4e0b2ad --- /dev/null +++ b/src/lib/libcrypto/des/des_enc.c | |||
| @@ -0,0 +1,411 @@ | |||
| 1 | /* crypto/des/des_enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | #ifndef OPENBSD_DES_ASM | ||
| 62 | |||
| 63 | void DES_encrypt1(DES_LONG *data, DES_key_schedule *ks, int enc) | ||
| 64 | { | ||
| 65 | register DES_LONG l,r,t,u; | ||
| 66 | #ifdef DES_PTR | ||
| 67 | register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; | ||
| 68 | #endif | ||
| 69 | #ifndef DES_UNROLL | ||
| 70 | register int i; | ||
| 71 | #endif | ||
| 72 | register DES_LONG *s; | ||
| 73 | |||
| 74 | r=data[0]; | ||
| 75 | l=data[1]; | ||
| 76 | |||
| 77 | IP(r,l); | ||
| 78 | /* Things have been modified so that the initial rotate is | ||
| 79 | * done outside the loop. This required the | ||
| 80 | * DES_SPtrans values in sp.h to be rotated 1 bit to the right. | ||
| 81 | * One perl script later and things have a 5% speed up on a sparc2. | ||
| 82 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
| 83 | * for pointing this out. */ | ||
| 84 | /* clear the top bits on machines with 8byte longs */ | ||
| 85 | /* shift left by 2 */ | ||
| 86 | r=ROTATE(r,29)&0xffffffffL; | ||
| 87 | l=ROTATE(l,29)&0xffffffffL; | ||
| 88 | |||
| 89 | s=ks->ks->deslong; | ||
| 90 | /* I don't know if it is worth the effort of loop unrolling the | ||
| 91 | * inner loop */ | ||
| 92 | if (enc) | ||
| 93 | { | ||
| 94 | #ifdef DES_UNROLL | ||
| 95 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 96 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 97 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 98 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 99 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 100 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 101 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 102 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 103 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 104 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 105 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 106 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 107 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 108 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 109 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 110 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 111 | #else | ||
| 112 | for (i=0; i<32; i+=8) | ||
| 113 | { | ||
| 114 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 115 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 116 | D_ENCRYPT(l,r,i+4); /* 3 */ | ||
| 117 | D_ENCRYPT(r,l,i+6); /* 4 */ | ||
| 118 | } | ||
| 119 | #endif | ||
| 120 | } | ||
| 121 | else | ||
| 122 | { | ||
| 123 | #ifdef DES_UNROLL | ||
| 124 | D_ENCRYPT(l,r,30); /* 16 */ | ||
| 125 | D_ENCRYPT(r,l,28); /* 15 */ | ||
| 126 | D_ENCRYPT(l,r,26); /* 14 */ | ||
| 127 | D_ENCRYPT(r,l,24); /* 13 */ | ||
| 128 | D_ENCRYPT(l,r,22); /* 12 */ | ||
| 129 | D_ENCRYPT(r,l,20); /* 11 */ | ||
| 130 | D_ENCRYPT(l,r,18); /* 10 */ | ||
| 131 | D_ENCRYPT(r,l,16); /* 9 */ | ||
| 132 | D_ENCRYPT(l,r,14); /* 8 */ | ||
| 133 | D_ENCRYPT(r,l,12); /* 7 */ | ||
| 134 | D_ENCRYPT(l,r,10); /* 6 */ | ||
| 135 | D_ENCRYPT(r,l, 8); /* 5 */ | ||
| 136 | D_ENCRYPT(l,r, 6); /* 4 */ | ||
| 137 | D_ENCRYPT(r,l, 4); /* 3 */ | ||
| 138 | D_ENCRYPT(l,r, 2); /* 2 */ | ||
| 139 | D_ENCRYPT(r,l, 0); /* 1 */ | ||
| 140 | #else | ||
| 141 | for (i=30; i>0; i-=8) | ||
| 142 | { | ||
| 143 | D_ENCRYPT(l,r,i-0); /* 16 */ | ||
| 144 | D_ENCRYPT(r,l,i-2); /* 15 */ | ||
| 145 | D_ENCRYPT(l,r,i-4); /* 14 */ | ||
| 146 | D_ENCRYPT(r,l,i-6); /* 13 */ | ||
| 147 | } | ||
| 148 | #endif | ||
| 149 | } | ||
| 150 | |||
| 151 | /* rotate and clear the top bits on machines with 8byte longs */ | ||
| 152 | l=ROTATE(l,3)&0xffffffffL; | ||
| 153 | r=ROTATE(r,3)&0xffffffffL; | ||
| 154 | |||
| 155 | FP(r,l); | ||
| 156 | data[0]=l; | ||
| 157 | data[1]=r; | ||
| 158 | l=r=t=u=0; | ||
| 159 | } | ||
| 160 | |||
| 161 | void DES_encrypt2(DES_LONG *data, DES_key_schedule *ks, int enc) | ||
| 162 | { | ||
| 163 | register DES_LONG l,r,t,u; | ||
| 164 | #ifdef DES_PTR | ||
| 165 | register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; | ||
| 166 | #endif | ||
| 167 | #ifndef DES_UNROLL | ||
| 168 | register int i; | ||
| 169 | #endif | ||
| 170 | register DES_LONG *s; | ||
| 171 | |||
| 172 | r=data[0]; | ||
| 173 | l=data[1]; | ||
| 174 | |||
| 175 | /* Things have been modified so that the initial rotate is | ||
| 176 | * done outside the loop. This required the | ||
| 177 | * DES_SPtrans values in sp.h to be rotated 1 bit to the right. | ||
| 178 | * One perl script later and things have a 5% speed up on a sparc2. | ||
| 179 | * Thanks to Richard Outerbridge <71755.204@CompuServe.COM> | ||
| 180 | * for pointing this out. */ | ||
| 181 | /* clear the top bits on machines with 8byte longs */ | ||
| 182 | r=ROTATE(r,29)&0xffffffffL; | ||
| 183 | l=ROTATE(l,29)&0xffffffffL; | ||
| 184 | |||
| 185 | s=ks->ks->deslong; | ||
| 186 | /* I don't know if it is worth the effort of loop unrolling the | ||
| 187 | * inner loop */ | ||
| 188 | if (enc) | ||
| 189 | { | ||
| 190 | #ifdef DES_UNROLL | ||
| 191 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 192 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 193 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 194 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 195 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 196 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 197 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 198 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 199 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 200 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 201 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 202 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 203 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 204 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 205 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 206 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 207 | #else | ||
| 208 | for (i=0; i<32; i+=8) | ||
| 209 | { | ||
| 210 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 211 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 212 | D_ENCRYPT(l,r,i+4); /* 3 */ | ||
| 213 | D_ENCRYPT(r,l,i+6); /* 4 */ | ||
| 214 | } | ||
| 215 | #endif | ||
| 216 | } | ||
| 217 | else | ||
| 218 | { | ||
| 219 | #ifdef DES_UNROLL | ||
| 220 | D_ENCRYPT(l,r,30); /* 16 */ | ||
| 221 | D_ENCRYPT(r,l,28); /* 15 */ | ||
| 222 | D_ENCRYPT(l,r,26); /* 14 */ | ||
| 223 | D_ENCRYPT(r,l,24); /* 13 */ | ||
| 224 | D_ENCRYPT(l,r,22); /* 12 */ | ||
| 225 | D_ENCRYPT(r,l,20); /* 11 */ | ||
| 226 | D_ENCRYPT(l,r,18); /* 10 */ | ||
| 227 | D_ENCRYPT(r,l,16); /* 9 */ | ||
| 228 | D_ENCRYPT(l,r,14); /* 8 */ | ||
| 229 | D_ENCRYPT(r,l,12); /* 7 */ | ||
| 230 | D_ENCRYPT(l,r,10); /* 6 */ | ||
| 231 | D_ENCRYPT(r,l, 8); /* 5 */ | ||
| 232 | D_ENCRYPT(l,r, 6); /* 4 */ | ||
| 233 | D_ENCRYPT(r,l, 4); /* 3 */ | ||
| 234 | D_ENCRYPT(l,r, 2); /* 2 */ | ||
| 235 | D_ENCRYPT(r,l, 0); /* 1 */ | ||
| 236 | #else | ||
| 237 | for (i=30; i>0; i-=8) | ||
| 238 | { | ||
| 239 | D_ENCRYPT(l,r,i-0); /* 16 */ | ||
| 240 | D_ENCRYPT(r,l,i-2); /* 15 */ | ||
| 241 | D_ENCRYPT(l,r,i-4); /* 14 */ | ||
| 242 | D_ENCRYPT(r,l,i-6); /* 13 */ | ||
| 243 | } | ||
| 244 | #endif | ||
| 245 | } | ||
| 246 | /* rotate and clear the top bits on machines with 8byte longs */ | ||
| 247 | data[0]=ROTATE(l,3)&0xffffffffL; | ||
| 248 | data[1]=ROTATE(r,3)&0xffffffffL; | ||
| 249 | l=r=t=u=0; | ||
| 250 | } | ||
| 251 | |||
| 252 | #endif /* OPENBSD_DES_ASM */ | ||
| 253 | |||
| 254 | void DES_encrypt3(DES_LONG *data, DES_key_schedule *ks1, | ||
| 255 | DES_key_schedule *ks2, DES_key_schedule *ks3) | ||
| 256 | { | ||
| 257 | register DES_LONG l,r; | ||
| 258 | |||
| 259 | l=data[0]; | ||
| 260 | r=data[1]; | ||
| 261 | IP(l,r); | ||
| 262 | data[0]=l; | ||
| 263 | data[1]=r; | ||
| 264 | DES_encrypt2((DES_LONG *)data,ks1,DES_ENCRYPT); | ||
| 265 | DES_encrypt2((DES_LONG *)data,ks2,DES_DECRYPT); | ||
| 266 | DES_encrypt2((DES_LONG *)data,ks3,DES_ENCRYPT); | ||
| 267 | l=data[0]; | ||
| 268 | r=data[1]; | ||
| 269 | FP(r,l); | ||
| 270 | data[0]=l; | ||
| 271 | data[1]=r; | ||
| 272 | } | ||
| 273 | |||
| 274 | void DES_decrypt3(DES_LONG *data, DES_key_schedule *ks1, | ||
| 275 | DES_key_schedule *ks2, DES_key_schedule *ks3) | ||
| 276 | { | ||
| 277 | register DES_LONG l,r; | ||
| 278 | |||
| 279 | l=data[0]; | ||
| 280 | r=data[1]; | ||
| 281 | IP(l,r); | ||
| 282 | data[0]=l; | ||
| 283 | data[1]=r; | ||
| 284 | DES_encrypt2((DES_LONG *)data,ks3,DES_DECRYPT); | ||
| 285 | DES_encrypt2((DES_LONG *)data,ks2,DES_ENCRYPT); | ||
| 286 | DES_encrypt2((DES_LONG *)data,ks1,DES_DECRYPT); | ||
| 287 | l=data[0]; | ||
| 288 | r=data[1]; | ||
| 289 | FP(r,l); | ||
| 290 | data[0]=l; | ||
| 291 | data[1]=r; | ||
| 292 | } | ||
| 293 | |||
| 294 | #ifndef DES_DEFAULT_OPTIONS | ||
| 295 | |||
| 296 | #undef CBC_ENC_C__DONT_UPDATE_IV | ||
| 297 | #include "ncbc_enc.c" /* DES_ncbc_encrypt */ | ||
| 298 | |||
| 299 | void DES_ede3_cbc_encrypt(const unsigned char *input, unsigned char *output, | ||
| 300 | long length, DES_key_schedule *ks1, | ||
| 301 | DES_key_schedule *ks2, DES_key_schedule *ks3, | ||
| 302 | DES_cblock *ivec, int enc) | ||
| 303 | { | ||
| 304 | register DES_LONG tin0,tin1; | ||
| 305 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 306 | register const unsigned char *in; | ||
| 307 | unsigned char *out; | ||
| 308 | register long l=length; | ||
| 309 | DES_LONG tin[2]; | ||
| 310 | unsigned char *iv; | ||
| 311 | |||
| 312 | in=input; | ||
| 313 | out=output; | ||
| 314 | iv = &(*ivec)[0]; | ||
| 315 | |||
| 316 | if (enc) | ||
| 317 | { | ||
| 318 | c2l(iv,tout0); | ||
| 319 | c2l(iv,tout1); | ||
| 320 | for (l-=8; l>=0; l-=8) | ||
| 321 | { | ||
| 322 | c2l(in,tin0); | ||
| 323 | c2l(in,tin1); | ||
| 324 | tin0^=tout0; | ||
| 325 | tin1^=tout1; | ||
| 326 | |||
| 327 | tin[0]=tin0; | ||
| 328 | tin[1]=tin1; | ||
| 329 | DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 330 | tout0=tin[0]; | ||
| 331 | tout1=tin[1]; | ||
| 332 | |||
| 333 | l2c(tout0,out); | ||
| 334 | l2c(tout1,out); | ||
| 335 | } | ||
| 336 | if (l != -8) | ||
| 337 | { | ||
| 338 | c2ln(in,tin0,tin1,l+8); | ||
| 339 | tin0^=tout0; | ||
| 340 | tin1^=tout1; | ||
| 341 | |||
| 342 | tin[0]=tin0; | ||
| 343 | tin[1]=tin1; | ||
| 344 | DES_encrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 345 | tout0=tin[0]; | ||
| 346 | tout1=tin[1]; | ||
| 347 | |||
| 348 | l2c(tout0,out); | ||
| 349 | l2c(tout1,out); | ||
| 350 | } | ||
| 351 | iv = &(*ivec)[0]; | ||
| 352 | l2c(tout0,iv); | ||
| 353 | l2c(tout1,iv); | ||
| 354 | } | ||
| 355 | else | ||
| 356 | { | ||
| 357 | register DES_LONG t0,t1; | ||
| 358 | |||
| 359 | c2l(iv,xor0); | ||
| 360 | c2l(iv,xor1); | ||
| 361 | for (l-=8; l>=0; l-=8) | ||
| 362 | { | ||
| 363 | c2l(in,tin0); | ||
| 364 | c2l(in,tin1); | ||
| 365 | |||
| 366 | t0=tin0; | ||
| 367 | t1=tin1; | ||
| 368 | |||
| 369 | tin[0]=tin0; | ||
| 370 | tin[1]=tin1; | ||
| 371 | DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 372 | tout0=tin[0]; | ||
| 373 | tout1=tin[1]; | ||
| 374 | |||
| 375 | tout0^=xor0; | ||
| 376 | tout1^=xor1; | ||
| 377 | l2c(tout0,out); | ||
| 378 | l2c(tout1,out); | ||
| 379 | xor0=t0; | ||
| 380 | xor1=t1; | ||
| 381 | } | ||
| 382 | if (l != -8) | ||
| 383 | { | ||
| 384 | c2l(in,tin0); | ||
| 385 | c2l(in,tin1); | ||
| 386 | |||
| 387 | t0=tin0; | ||
| 388 | t1=tin1; | ||
| 389 | |||
| 390 | tin[0]=tin0; | ||
| 391 | tin[1]=tin1; | ||
| 392 | DES_decrypt3((DES_LONG *)tin,ks1,ks2,ks3); | ||
| 393 | tout0=tin[0]; | ||
| 394 | tout1=tin[1]; | ||
| 395 | |||
| 396 | tout0^=xor0; | ||
| 397 | tout1^=xor1; | ||
| 398 | l2cn(tout0,tout1,out,l+8); | ||
| 399 | xor0=t0; | ||
| 400 | xor1=t1; | ||
| 401 | } | ||
| 402 | |||
| 403 | iv = &(*ivec)[0]; | ||
| 404 | l2c(xor0,iv); | ||
| 405 | l2c(xor1,iv); | ||
| 406 | } | ||
| 407 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 408 | tin[0]=tin[1]=0; | ||
| 409 | } | ||
| 410 | |||
| 411 | #endif /* DES_DEFAULT_OPTIONS */ | ||
diff --git a/src/lib/libcrypto/des/des_locl.h b/src/lib/libcrypto/des/des_locl.h new file mode 100644 index 0000000000..4b9ecff233 --- /dev/null +++ b/src/lib/libcrypto/des/des_locl.h | |||
| @@ -0,0 +1,428 @@ | |||
| 1 | /* crypto/des/des_locl.h */ | ||
| 2 | /* Copyright (C) 1995-1997 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_DES_LOCL_H | ||
| 60 | #define HEADER_DES_LOCL_H | ||
| 61 | |||
| 62 | #include <openssl/e_os2.h> | ||
| 63 | |||
| 64 | #if defined(OPENSSL_SYS_WIN32) || defined(OPENSSL_SYS_WIN16) | ||
| 65 | #ifndef OPENSSL_SYS_MSDOS | ||
| 66 | #define OPENSSL_SYS_MSDOS | ||
| 67 | #endif | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #include <stdio.h> | ||
| 71 | #include <stdlib.h> | ||
| 72 | |||
| 73 | #ifndef OPENSSL_SYS_MSDOS | ||
| 74 | #if !defined(OPENSSL_SYS_VMS) || defined(__DECC) | ||
| 75 | #ifdef OPENSSL_UNISTD | ||
| 76 | # include OPENSSL_UNISTD | ||
| 77 | #else | ||
| 78 | # include <unistd.h> | ||
| 79 | #endif | ||
| 80 | #include <math.h> | ||
| 81 | #endif | ||
| 82 | #endif | ||
| 83 | #include <openssl/des.h> | ||
| 84 | |||
| 85 | #ifdef OPENSSL_SYS_MSDOS /* Visual C++ 2.1 (Windows NT/95) */ | ||
| 86 | #include <stdlib.h> | ||
| 87 | #include <errno.h> | ||
| 88 | #include <time.h> | ||
| 89 | #include <io.h> | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #if defined(__STDC__) || defined(OPENSSL_SYS_VMS) || defined(M_XENIX) || defined(OPENSSL_SYS_MSDOS) | ||
| 93 | #include <string.h> | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #ifdef OPENSSL_BUILD_SHLIBCRYPTO | ||
| 97 | # undef OPENSSL_EXTERN | ||
| 98 | # define OPENSSL_EXTERN OPENSSL_EXPORT | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #define ITERATIONS 16 | ||
| 102 | #define HALF_ITERATIONS 8 | ||
| 103 | |||
| 104 | /* used in des_read and des_write */ | ||
| 105 | #define MAXWRITE (1024*16) | ||
| 106 | #define BSIZE (MAXWRITE+4) | ||
| 107 | |||
| 108 | #define c2l(c,l) (l =((DES_LONG)(*((c)++))) , \ | ||
| 109 | l|=((DES_LONG)(*((c)++)))<< 8L, \ | ||
| 110 | l|=((DES_LONG)(*((c)++)))<<16L, \ | ||
| 111 | l|=((DES_LONG)(*((c)++)))<<24L) | ||
| 112 | |||
| 113 | /* NOTE - c is not incremented as per c2l */ | ||
| 114 | #define c2ln(c,l1,l2,n) { \ | ||
| 115 | c+=n; \ | ||
| 116 | l1=l2=0; \ | ||
| 117 | switch (n) { \ | ||
| 118 | case 8: l2 =((DES_LONG)(*(--(c))))<<24L; \ | ||
| 119 | case 7: l2|=((DES_LONG)(*(--(c))))<<16L; \ | ||
| 120 | case 6: l2|=((DES_LONG)(*(--(c))))<< 8L; \ | ||
| 121 | case 5: l2|=((DES_LONG)(*(--(c)))); \ | ||
| 122 | case 4: l1 =((DES_LONG)(*(--(c))))<<24L; \ | ||
| 123 | case 3: l1|=((DES_LONG)(*(--(c))))<<16L; \ | ||
| 124 | case 2: l1|=((DES_LONG)(*(--(c))))<< 8L; \ | ||
| 125 | case 1: l1|=((DES_LONG)(*(--(c)))); \ | ||
| 126 | } \ | ||
| 127 | } | ||
| 128 | |||
| 129 | #define l2c(l,c) (*((c)++)=(unsigned char)(((l) )&0xff), \ | ||
| 130 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 131 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 132 | *((c)++)=(unsigned char)(((l)>>24L)&0xff)) | ||
| 133 | |||
| 134 | /* replacements for htonl and ntohl since I have no idea what to do | ||
| 135 | * when faced with machines with 8 byte longs. */ | ||
| 136 | #define HDRSIZE 4 | ||
| 137 | |||
| 138 | #define n2l(c,l) (l =((DES_LONG)(*((c)++)))<<24L, \ | ||
| 139 | l|=((DES_LONG)(*((c)++)))<<16L, \ | ||
| 140 | l|=((DES_LONG)(*((c)++)))<< 8L, \ | ||
| 141 | l|=((DES_LONG)(*((c)++)))) | ||
| 142 | |||
| 143 | #define l2n(l,c) (*((c)++)=(unsigned char)(((l)>>24L)&0xff), \ | ||
| 144 | *((c)++)=(unsigned char)(((l)>>16L)&0xff), \ | ||
| 145 | *((c)++)=(unsigned char)(((l)>> 8L)&0xff), \ | ||
| 146 | *((c)++)=(unsigned char)(((l) )&0xff)) | ||
| 147 | |||
| 148 | /* NOTE - c is not incremented as per l2c */ | ||
| 149 | #define l2cn(l1,l2,c,n) { \ | ||
| 150 | c+=n; \ | ||
| 151 | switch (n) { \ | ||
| 152 | case 8: *(--(c))=(unsigned char)(((l2)>>24L)&0xff); \ | ||
| 153 | case 7: *(--(c))=(unsigned char)(((l2)>>16L)&0xff); \ | ||
| 154 | case 6: *(--(c))=(unsigned char)(((l2)>> 8L)&0xff); \ | ||
| 155 | case 5: *(--(c))=(unsigned char)(((l2) )&0xff); \ | ||
| 156 | case 4: *(--(c))=(unsigned char)(((l1)>>24L)&0xff); \ | ||
| 157 | case 3: *(--(c))=(unsigned char)(((l1)>>16L)&0xff); \ | ||
| 158 | case 2: *(--(c))=(unsigned char)(((l1)>> 8L)&0xff); \ | ||
| 159 | case 1: *(--(c))=(unsigned char)(((l1) )&0xff); \ | ||
| 160 | } \ | ||
| 161 | } | ||
| 162 | |||
| 163 | #if (defined(OPENSSL_SYS_WIN32) && defined(_MSC_VER)) || defined(__ICC) | ||
| 164 | #define ROTATE(a,n) (_lrotr(a,n)) | ||
| 165 | #elif defined(__GNUC__) && __GNUC__>=2 && !defined(__STRICT_ANSI__) && !defined(OPENSSL_NO_ASM) && !defined(OPENSSL_NO_INLINE_ASM) && !defined(PEDANTIC) | ||
| 166 | # if defined(__i386) || defined(__i386__) || defined(__x86_64) || defined(__x86_64__) | ||
| 167 | # define ROTATE(a,n) ({ register unsigned int ret; \ | ||
| 168 | asm ("rorl %1,%0" \ | ||
| 169 | : "=r"(ret) \ | ||
| 170 | : "I"(n),"0"(a) \ | ||
| 171 | : "cc"); \ | ||
| 172 | ret; \ | ||
| 173 | }) | ||
| 174 | # endif | ||
| 175 | #endif | ||
| 176 | #ifndef ROTATE | ||
| 177 | #define ROTATE(a,n) (((a)>>(n))+((a)<<(32-(n)))) | ||
| 178 | #endif | ||
| 179 | |||
| 180 | /* Don't worry about the LOAD_DATA() stuff, that is used by | ||
| 181 | * fcrypt() to add it's little bit to the front */ | ||
| 182 | |||
| 183 | #ifdef DES_FCRYPT | ||
| 184 | |||
| 185 | #define LOAD_DATA_tmp(R,S,u,t,E0,E1) \ | ||
| 186 | { DES_LONG tmp; LOAD_DATA(R,S,u,t,E0,E1,tmp); } | ||
| 187 | |||
| 188 | #define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ | ||
| 189 | t=R^(R>>16L); \ | ||
| 190 | u=t&E0; t&=E1; \ | ||
| 191 | tmp=(u<<16); u^=R^s[S ]; u^=tmp; \ | ||
| 192 | tmp=(t<<16); t^=R^s[S+1]; t^=tmp | ||
| 193 | #else | ||
| 194 | #define LOAD_DATA_tmp(a,b,c,d,e,f) LOAD_DATA(a,b,c,d,e,f,g) | ||
| 195 | #define LOAD_DATA(R,S,u,t,E0,E1,tmp) \ | ||
| 196 | u=R^s[S ]; \ | ||
| 197 | t=R^s[S+1] | ||
| 198 | #endif | ||
| 199 | |||
| 200 | /* The changes to this macro may help or hinder, depending on the | ||
| 201 | * compiler and the architecture. gcc2 always seems to do well :-). | ||
| 202 | * Inspired by Dana How <how@isl.stanford.edu> | ||
| 203 | * DO NOT use the alternative version on machines with 8 byte longs. | ||
| 204 | * It does not seem to work on the Alpha, even when DES_LONG is 4 | ||
| 205 | * bytes, probably an issue of accessing non-word aligned objects :-( */ | ||
| 206 | #ifdef DES_PTR | ||
| 207 | |||
| 208 | /* It recently occurred to me that 0^0^0^0^0^0^0 == 0, so there | ||
| 209 | * is no reason to not xor all the sub items together. This potentially | ||
| 210 | * saves a register since things can be xored directly into L */ | ||
| 211 | |||
| 212 | #if defined(DES_RISC1) || defined(DES_RISC2) | ||
| 213 | #ifdef DES_RISC1 | ||
| 214 | #define D_ENCRYPT(LL,R,S) { \ | ||
| 215 | unsigned int u1,u2,u3; \ | ||
| 216 | LOAD_DATA(R,S,u,t,E0,E1,u1); \ | ||
| 217 | u2=(int)u>>8L; \ | ||
| 218 | u1=(int)u&0xfc; \ | ||
| 219 | u2&=0xfc; \ | ||
| 220 | t=ROTATE(t,4); \ | ||
| 221 | u>>=16L; \ | ||
| 222 | LL^= *(const DES_LONG *)(des_SP +u1); \ | ||
| 223 | LL^= *(const DES_LONG *)(des_SP+0x200+u2); \ | ||
| 224 | u3=(int)(u>>8L); \ | ||
| 225 | u1=(int)u&0xfc; \ | ||
| 226 | u3&=0xfc; \ | ||
| 227 | LL^= *(const DES_LONG *)(des_SP+0x400+u1); \ | ||
| 228 | LL^= *(const DES_LONG *)(des_SP+0x600+u3); \ | ||
| 229 | u2=(int)t>>8L; \ | ||
| 230 | u1=(int)t&0xfc; \ | ||
| 231 | u2&=0xfc; \ | ||
| 232 | t>>=16L; \ | ||
| 233 | LL^= *(const DES_LONG *)(des_SP+0x100+u1); \ | ||
| 234 | LL^= *(const DES_LONG *)(des_SP+0x300+u2); \ | ||
| 235 | u3=(int)t>>8L; \ | ||
| 236 | u1=(int)t&0xfc; \ | ||
| 237 | u3&=0xfc; \ | ||
| 238 | LL^= *(const DES_LONG *)(des_SP+0x500+u1); \ | ||
| 239 | LL^= *(const DES_LONG *)(des_SP+0x700+u3); } | ||
| 240 | #endif | ||
| 241 | #ifdef DES_RISC2 | ||
| 242 | #define D_ENCRYPT(LL,R,S) { \ | ||
| 243 | unsigned int u1,u2,s1,s2; \ | ||
| 244 | LOAD_DATA(R,S,u,t,E0,E1,u1); \ | ||
| 245 | u2=(int)u>>8L; \ | ||
| 246 | u1=(int)u&0xfc; \ | ||
| 247 | u2&=0xfc; \ | ||
| 248 | t=ROTATE(t,4); \ | ||
| 249 | LL^= *(const DES_LONG *)(des_SP +u1); \ | ||
| 250 | LL^= *(const DES_LONG *)(des_SP+0x200+u2); \ | ||
| 251 | s1=(int)(u>>16L); \ | ||
| 252 | s2=(int)(u>>24L); \ | ||
| 253 | s1&=0xfc; \ | ||
| 254 | s2&=0xfc; \ | ||
| 255 | LL^= *(const DES_LONG *)(des_SP+0x400+s1); \ | ||
| 256 | LL^= *(const DES_LONG *)(des_SP+0x600+s2); \ | ||
| 257 | u2=(int)t>>8L; \ | ||
| 258 | u1=(int)t&0xfc; \ | ||
| 259 | u2&=0xfc; \ | ||
| 260 | LL^= *(const DES_LONG *)(des_SP+0x100+u1); \ | ||
| 261 | LL^= *(const DES_LONG *)(des_SP+0x300+u2); \ | ||
| 262 | s1=(int)(t>>16L); \ | ||
| 263 | s2=(int)(t>>24L); \ | ||
| 264 | s1&=0xfc; \ | ||
| 265 | s2&=0xfc; \ | ||
| 266 | LL^= *(const DES_LONG *)(des_SP+0x500+s1); \ | ||
| 267 | LL^= *(const DES_LONG *)(des_SP+0x700+s2); } | ||
| 268 | #endif | ||
| 269 | #else | ||
| 270 | #define D_ENCRYPT(LL,R,S) { \ | ||
| 271 | LOAD_DATA_tmp(R,S,u,t,E0,E1); \ | ||
| 272 | t=ROTATE(t,4); \ | ||
| 273 | LL^= \ | ||
| 274 | *(const DES_LONG *)(des_SP +((u )&0xfc))^ \ | ||
| 275 | *(const DES_LONG *)(des_SP+0x200+((u>> 8L)&0xfc))^ \ | ||
| 276 | *(const DES_LONG *)(des_SP+0x400+((u>>16L)&0xfc))^ \ | ||
| 277 | *(const DES_LONG *)(des_SP+0x600+((u>>24L)&0xfc))^ \ | ||
| 278 | *(const DES_LONG *)(des_SP+0x100+((t )&0xfc))^ \ | ||
| 279 | *(const DES_LONG *)(des_SP+0x300+((t>> 8L)&0xfc))^ \ | ||
| 280 | *(const DES_LONG *)(des_SP+0x500+((t>>16L)&0xfc))^ \ | ||
| 281 | *(const DES_LONG *)(des_SP+0x700+((t>>24L)&0xfc)); } | ||
| 282 | #endif | ||
| 283 | |||
| 284 | #else /* original version */ | ||
| 285 | |||
| 286 | #if defined(DES_RISC1) || defined(DES_RISC2) | ||
| 287 | #ifdef DES_RISC1 | ||
| 288 | #define D_ENCRYPT(LL,R,S) {\ | ||
| 289 | unsigned int u1,u2,u3; \ | ||
| 290 | LOAD_DATA(R,S,u,t,E0,E1,u1); \ | ||
| 291 | u>>=2L; \ | ||
| 292 | t=ROTATE(t,6); \ | ||
| 293 | u2=(int)u>>8L; \ | ||
| 294 | u1=(int)u&0x3f; \ | ||
| 295 | u2&=0x3f; \ | ||
| 296 | u>>=16L; \ | ||
| 297 | LL^=DES_SPtrans[0][u1]; \ | ||
| 298 | LL^=DES_SPtrans[2][u2]; \ | ||
| 299 | u3=(int)u>>8L; \ | ||
| 300 | u1=(int)u&0x3f; \ | ||
| 301 | u3&=0x3f; \ | ||
| 302 | LL^=DES_SPtrans[4][u1]; \ | ||
| 303 | LL^=DES_SPtrans[6][u3]; \ | ||
| 304 | u2=(int)t>>8L; \ | ||
| 305 | u1=(int)t&0x3f; \ | ||
| 306 | u2&=0x3f; \ | ||
| 307 | t>>=16L; \ | ||
| 308 | LL^=DES_SPtrans[1][u1]; \ | ||
| 309 | LL^=DES_SPtrans[3][u2]; \ | ||
| 310 | u3=(int)t>>8L; \ | ||
| 311 | u1=(int)t&0x3f; \ | ||
| 312 | u3&=0x3f; \ | ||
| 313 | LL^=DES_SPtrans[5][u1]; \ | ||
| 314 | LL^=DES_SPtrans[7][u3]; } | ||
| 315 | #endif | ||
| 316 | #ifdef DES_RISC2 | ||
| 317 | #define D_ENCRYPT(LL,R,S) {\ | ||
| 318 | unsigned int u1,u2,s1,s2; \ | ||
| 319 | LOAD_DATA(R,S,u,t,E0,E1,u1); \ | ||
| 320 | u>>=2L; \ | ||
| 321 | t=ROTATE(t,6); \ | ||
| 322 | u2=(int)u>>8L; \ | ||
| 323 | u1=(int)u&0x3f; \ | ||
| 324 | u2&=0x3f; \ | ||
| 325 | LL^=DES_SPtrans[0][u1]; \ | ||
| 326 | LL^=DES_SPtrans[2][u2]; \ | ||
| 327 | s1=(int)u>>16L; \ | ||
| 328 | s2=(int)u>>24L; \ | ||
| 329 | s1&=0x3f; \ | ||
| 330 | s2&=0x3f; \ | ||
| 331 | LL^=DES_SPtrans[4][s1]; \ | ||
| 332 | LL^=DES_SPtrans[6][s2]; \ | ||
| 333 | u2=(int)t>>8L; \ | ||
| 334 | u1=(int)t&0x3f; \ | ||
| 335 | u2&=0x3f; \ | ||
| 336 | LL^=DES_SPtrans[1][u1]; \ | ||
| 337 | LL^=DES_SPtrans[3][u2]; \ | ||
| 338 | s1=(int)t>>16; \ | ||
| 339 | s2=(int)t>>24L; \ | ||
| 340 | s1&=0x3f; \ | ||
| 341 | s2&=0x3f; \ | ||
| 342 | LL^=DES_SPtrans[5][s1]; \ | ||
| 343 | LL^=DES_SPtrans[7][s2]; } | ||
| 344 | #endif | ||
| 345 | |||
| 346 | #else | ||
| 347 | |||
| 348 | #define D_ENCRYPT(LL,R,S) {\ | ||
| 349 | LOAD_DATA_tmp(R,S,u,t,E0,E1); \ | ||
| 350 | t=ROTATE(t,4); \ | ||
| 351 | LL^=\ | ||
| 352 | DES_SPtrans[0][(u>> 2L)&0x3f]^ \ | ||
| 353 | DES_SPtrans[2][(u>>10L)&0x3f]^ \ | ||
| 354 | DES_SPtrans[4][(u>>18L)&0x3f]^ \ | ||
| 355 | DES_SPtrans[6][(u>>26L)&0x3f]^ \ | ||
| 356 | DES_SPtrans[1][(t>> 2L)&0x3f]^ \ | ||
| 357 | DES_SPtrans[3][(t>>10L)&0x3f]^ \ | ||
| 358 | DES_SPtrans[5][(t>>18L)&0x3f]^ \ | ||
| 359 | DES_SPtrans[7][(t>>26L)&0x3f]; } | ||
| 360 | #endif | ||
| 361 | #endif | ||
| 362 | |||
| 363 | /* IP and FP | ||
| 364 | * The problem is more of a geometric problem that random bit fiddling. | ||
| 365 | 0 1 2 3 4 5 6 7 62 54 46 38 30 22 14 6 | ||
| 366 | 8 9 10 11 12 13 14 15 60 52 44 36 28 20 12 4 | ||
| 367 | 16 17 18 19 20 21 22 23 58 50 42 34 26 18 10 2 | ||
| 368 | 24 25 26 27 28 29 30 31 to 56 48 40 32 24 16 8 0 | ||
| 369 | |||
| 370 | 32 33 34 35 36 37 38 39 63 55 47 39 31 23 15 7 | ||
| 371 | 40 41 42 43 44 45 46 47 61 53 45 37 29 21 13 5 | ||
| 372 | 48 49 50 51 52 53 54 55 59 51 43 35 27 19 11 3 | ||
| 373 | 56 57 58 59 60 61 62 63 57 49 41 33 25 17 9 1 | ||
| 374 | |||
| 375 | The output has been subject to swaps of the form | ||
| 376 | 0 1 -> 3 1 but the odd and even bits have been put into | ||
| 377 | 2 3 2 0 | ||
| 378 | different words. The main trick is to remember that | ||
| 379 | t=((l>>size)^r)&(mask); | ||
| 380 | r^=t; | ||
| 381 | l^=(t<<size); | ||
| 382 | can be used to swap and move bits between words. | ||
| 383 | |||
| 384 | So l = 0 1 2 3 r = 16 17 18 19 | ||
| 385 | 4 5 6 7 20 21 22 23 | ||
| 386 | 8 9 10 11 24 25 26 27 | ||
| 387 | 12 13 14 15 28 29 30 31 | ||
| 388 | becomes (for size == 2 and mask == 0x3333) | ||
| 389 | t = 2^16 3^17 -- -- l = 0 1 16 17 r = 2 3 18 19 | ||
| 390 | 6^20 7^21 -- -- 4 5 20 21 6 7 22 23 | ||
| 391 | 10^24 11^25 -- -- 8 9 24 25 10 11 24 25 | ||
| 392 | 14^28 15^29 -- -- 12 13 28 29 14 15 28 29 | ||
| 393 | |||
| 394 | Thanks for hints from Richard Outerbridge - he told me IP&FP | ||
| 395 | could be done in 15 xor, 10 shifts and 5 ands. | ||
| 396 | When I finally started to think of the problem in 2D | ||
| 397 | I first got ~42 operations without xors. When I remembered | ||
| 398 | how to use xors :-) I got it to its final state. | ||
| 399 | */ | ||
| 400 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 401 | (b)^=(t),\ | ||
| 402 | (a)^=((t)<<(n))) | ||
| 403 | |||
| 404 | #define IP(l,r) \ | ||
| 405 | { \ | ||
| 406 | register DES_LONG tt; \ | ||
| 407 | PERM_OP(r,l,tt, 4,0x0f0f0f0fL); \ | ||
| 408 | PERM_OP(l,r,tt,16,0x0000ffffL); \ | ||
| 409 | PERM_OP(r,l,tt, 2,0x33333333L); \ | ||
| 410 | PERM_OP(l,r,tt, 8,0x00ff00ffL); \ | ||
| 411 | PERM_OP(r,l,tt, 1,0x55555555L); \ | ||
| 412 | } | ||
| 413 | |||
| 414 | #define FP(l,r) \ | ||
| 415 | { \ | ||
| 416 | register DES_LONG tt; \ | ||
| 417 | PERM_OP(l,r,tt, 1,0x55555555L); \ | ||
| 418 | PERM_OP(r,l,tt, 8,0x00ff00ffL); \ | ||
| 419 | PERM_OP(l,r,tt, 2,0x33333333L); \ | ||
| 420 | PERM_OP(r,l,tt,16,0x0000ffffL); \ | ||
| 421 | PERM_OP(l,r,tt, 4,0x0f0f0f0fL); \ | ||
| 422 | } | ||
| 423 | |||
| 424 | extern const DES_LONG DES_SPtrans[8][64]; | ||
| 425 | |||
| 426 | void fcrypt_body(DES_LONG *out,DES_key_schedule *ks, | ||
| 427 | DES_LONG Eswap0, DES_LONG Eswap1); | ||
| 428 | #endif | ||
diff --git a/src/lib/libcrypto/des/des_old.h b/src/lib/libcrypto/des/des_old.h index 2b2c372354..8665ba4e7e 100644 --- a/src/lib/libcrypto/des/des_old.h +++ b/src/lib/libcrypto/des/des_old.h | |||
| @@ -88,8 +88,8 @@ | |||
| 88 | * | 88 | * |
| 89 | */ | 89 | */ |
| 90 | 90 | ||
| 91 | #ifndef HEADER_DES_H | 91 | #ifndef HEADER_DES_OLD_H |
| 92 | #define HEADER_DES_H | 92 | #define HEADER_DES_OLD_H |
| 93 | 93 | ||
| 94 | #include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */ | 94 | #include <openssl/e_os2.h> /* OPENSSL_EXTERN, OPENSSL_NO_DES, DES_LONG */ |
| 95 | 95 | ||
| @@ -97,7 +97,7 @@ | |||
| 97 | #error DES is disabled. | 97 | #error DES is disabled. |
| 98 | #endif | 98 | #endif |
| 99 | 99 | ||
| 100 | #ifndef HEADER_NEW_DES_H | 100 | #ifndef HEADER_DES_H |
| 101 | #error You must include des.h, not des_old.h directly. | 101 | #error You must include des.h, not des_old.h directly. |
| 102 | #endif | 102 | #endif |
| 103 | 103 | ||
diff --git a/src/lib/libcrypto/des/ecb3_enc.c b/src/lib/libcrypto/des/ecb3_enc.c new file mode 100644 index 0000000000..c3437bc606 --- /dev/null +++ b/src/lib/libcrypto/des/ecb3_enc.c | |||
| @@ -0,0 +1,83 @@ | |||
| 1 | /* crypto/des/ecb3_enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | void DES_ecb3_encrypt(const_DES_cblock *input, DES_cblock *output, | ||
| 62 | DES_key_schedule *ks1, DES_key_schedule *ks2, | ||
| 63 | DES_key_schedule *ks3, | ||
| 64 | int enc) | ||
| 65 | { | ||
| 66 | register DES_LONG l0,l1; | ||
| 67 | DES_LONG ll[2]; | ||
| 68 | const unsigned char *in = &(*input)[0]; | ||
| 69 | unsigned char *out = &(*output)[0]; | ||
| 70 | |||
| 71 | c2l(in,l0); | ||
| 72 | c2l(in,l1); | ||
| 73 | ll[0]=l0; | ||
| 74 | ll[1]=l1; | ||
| 75 | if (enc) | ||
| 76 | DES_encrypt3(ll,ks1,ks2,ks3); | ||
| 77 | else | ||
| 78 | DES_decrypt3(ll,ks1,ks2,ks3); | ||
| 79 | l0=ll[0]; | ||
| 80 | l1=ll[1]; | ||
| 81 | l2c(l0,out); | ||
| 82 | l2c(l1,out); | ||
| 83 | } | ||
diff --git a/src/lib/libcrypto/des/ecb_enc.c b/src/lib/libcrypto/des/ecb_enc.c new file mode 100644 index 0000000000..00d5b91e8c --- /dev/null +++ b/src/lib/libcrypto/des/ecb_enc.c | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | /* crypto/des/ecb_enc.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 "des_locl.h" | ||
| 60 | #include "des_ver.h" | ||
| 61 | #include "spr.h" | ||
| 62 | #include <openssl/opensslv.h> | ||
| 63 | #include <openssl/bio.h> | ||
| 64 | |||
| 65 | OPENSSL_GLOBAL const char libdes_version[]="libdes" OPENSSL_VERSION_PTEXT; | ||
| 66 | OPENSSL_GLOBAL const char DES_version[]="DES" OPENSSL_VERSION_PTEXT; | ||
| 67 | |||
| 68 | const char *DES_options(void) | ||
| 69 | { | ||
| 70 | static int init=1; | ||
| 71 | static char buf[32]; | ||
| 72 | |||
| 73 | if (init) | ||
| 74 | { | ||
| 75 | const char *ptr,*unroll,*risc,*size; | ||
| 76 | |||
| 77 | #ifdef DES_PTR | ||
| 78 | ptr="ptr"; | ||
| 79 | #else | ||
| 80 | ptr="idx"; | ||
| 81 | #endif | ||
| 82 | #if defined(DES_RISC1) || defined(DES_RISC2) | ||
| 83 | #ifdef DES_RISC1 | ||
| 84 | risc="risc1"; | ||
| 85 | #endif | ||
| 86 | #ifdef DES_RISC2 | ||
| 87 | risc="risc2"; | ||
| 88 | #endif | ||
| 89 | #else | ||
| 90 | risc="cisc"; | ||
| 91 | #endif | ||
| 92 | #ifdef DES_UNROLL | ||
| 93 | unroll="16"; | ||
| 94 | #else | ||
| 95 | unroll="4"; | ||
| 96 | #endif | ||
| 97 | if (sizeof(DES_LONG) != sizeof(long)) | ||
| 98 | size="int"; | ||
| 99 | else | ||
| 100 | size="long"; | ||
| 101 | BIO_snprintf(buf,sizeof buf,"des(%s,%s,%s,%s)",ptr,risc,unroll, | ||
| 102 | size); | ||
| 103 | init=0; | ||
| 104 | } | ||
| 105 | return(buf); | ||
| 106 | } | ||
| 107 | |||
| 108 | |||
| 109 | void DES_ecb_encrypt(const_DES_cblock *input, DES_cblock *output, | ||
| 110 | DES_key_schedule *ks, int enc) | ||
| 111 | { | ||
| 112 | register DES_LONG l; | ||
| 113 | DES_LONG ll[2]; | ||
| 114 | const unsigned char *in = &(*input)[0]; | ||
| 115 | unsigned char *out = &(*output)[0]; | ||
| 116 | |||
| 117 | c2l(in,l); ll[0]=l; | ||
| 118 | c2l(in,l); ll[1]=l; | ||
| 119 | DES_encrypt1(ll,ks,enc); | ||
| 120 | l=ll[0]; l2c(l,out); | ||
| 121 | l=ll[1]; l2c(l,out); | ||
| 122 | l=ll[0]=ll[1]=0; | ||
| 123 | } | ||
diff --git a/src/lib/libcrypto/des/ede_cbcm_enc.c b/src/lib/libcrypto/des/ede_cbcm_enc.c new file mode 100644 index 0000000000..adfcb75cf3 --- /dev/null +++ b/src/lib/libcrypto/des/ede_cbcm_enc.c | |||
| @@ -0,0 +1,199 @@ | |||
| 1 | /* ede_cbcm_enc.c */ | ||
| 2 | /* Written by Ben Laurie <ben@algroup.co.uk> for the OpenSSL | ||
| 3 | * project 13 Feb 1999. | ||
| 4 | */ | ||
| 5 | /* ==================================================================== | ||
| 6 | * Copyright (c) 1999 The OpenSSL Project. All rights reserved. | ||
| 7 | * | ||
| 8 | * Redistribution and use in source and binary forms, with or without | ||
| 9 | * modification, are permitted provided that the following conditions | ||
| 10 | * are met: | ||
| 11 | * | ||
| 12 | * 1. Redistributions of source code must retain the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer. | ||
| 14 | * | ||
| 15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 16 | * notice, this list of conditions and the following disclaimer in | ||
| 17 | * the documentation and/or other materials provided with the | ||
| 18 | * distribution. | ||
| 19 | * | ||
| 20 | * 3. All advertising materials mentioning features or use of this | ||
| 21 | * software must display the following acknowledgment: | ||
| 22 | * "This product includes software developed by the OpenSSL Project | ||
| 23 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
| 24 | * | ||
| 25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 26 | * endorse or promote products derived from this software without | ||
| 27 | * prior written permission. For written permission, please contact | ||
| 28 | * licensing@OpenSSL.org. | ||
| 29 | * | ||
| 30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 31 | * nor may "OpenSSL" appear in their names without prior written | ||
| 32 | * permission of the OpenSSL Project. | ||
| 33 | * | ||
| 34 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 35 | * acknowledgment: | ||
| 36 | * "This product includes software developed by the OpenSSL Project | ||
| 37 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
| 38 | * | ||
| 39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 51 | * ==================================================================== | ||
| 52 | * | ||
| 53 | * This product includes cryptographic software written by Eric Young | ||
| 54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 55 | * Hudson (tjh@cryptsoft.com). | ||
| 56 | * | ||
| 57 | */ | ||
| 58 | |||
| 59 | /* | ||
| 60 | |||
| 61 | This is an implementation of Triple DES Cipher Block Chaining with Output | ||
| 62 | Feedback Masking, by Coppersmith, Johnson and Matyas, (IBM and Certicom). | ||
| 63 | |||
| 64 | Note that there is a known attack on this by Biham and Knudsen but it takes | ||
| 65 | a lot of work: | ||
| 66 | |||
| 67 | http://www.cs.technion.ac.il/users/wwwb/cgi-bin/tr-get.cgi/1998/CS/CS0928.ps.gz | ||
| 68 | |||
| 69 | */ | ||
| 70 | |||
| 71 | #include <openssl/opensslconf.h> /* To see if OPENSSL_NO_DESCBCM is defined */ | ||
| 72 | |||
| 73 | #ifndef OPENSSL_NO_DESCBCM | ||
| 74 | #include "des_locl.h" | ||
| 75 | |||
| 76 | void DES_ede3_cbcm_encrypt(const unsigned char *in, unsigned char *out, | ||
| 77 | long length, DES_key_schedule *ks1, DES_key_schedule *ks2, | ||
| 78 | DES_key_schedule *ks3, DES_cblock *ivec1, DES_cblock *ivec2, | ||
| 79 | int enc) | ||
| 80 | { | ||
| 81 | register DES_LONG tin0,tin1; | ||
| 82 | register DES_LONG tout0,tout1,xor0,xor1,m0,m1; | ||
| 83 | register long l=length; | ||
| 84 | DES_LONG tin[2]; | ||
| 85 | unsigned char *iv1,*iv2; | ||
| 86 | |||
| 87 | iv1 = &(*ivec1)[0]; | ||
| 88 | iv2 = &(*ivec2)[0]; | ||
| 89 | |||
| 90 | if (enc) | ||
| 91 | { | ||
| 92 | c2l(iv1,m0); | ||
| 93 | c2l(iv1,m1); | ||
| 94 | c2l(iv2,tout0); | ||
| 95 | c2l(iv2,tout1); | ||
| 96 | for (l-=8; l>=-7; l-=8) | ||
| 97 | { | ||
| 98 | tin[0]=m0; | ||
| 99 | tin[1]=m1; | ||
| 100 | DES_encrypt1(tin,ks3,1); | ||
| 101 | m0=tin[0]; | ||
| 102 | m1=tin[1]; | ||
| 103 | |||
| 104 | if(l < 0) | ||
| 105 | { | ||
| 106 | c2ln(in,tin0,tin1,l+8); | ||
| 107 | } | ||
| 108 | else | ||
| 109 | { | ||
| 110 | c2l(in,tin0); | ||
| 111 | c2l(in,tin1); | ||
| 112 | } | ||
| 113 | tin0^=tout0; | ||
| 114 | tin1^=tout1; | ||
| 115 | |||
| 116 | tin[0]=tin0; | ||
| 117 | tin[1]=tin1; | ||
| 118 | DES_encrypt1(tin,ks1,1); | ||
| 119 | tin[0]^=m0; | ||
| 120 | tin[1]^=m1; | ||
| 121 | DES_encrypt1(tin,ks2,0); | ||
| 122 | tin[0]^=m0; | ||
| 123 | tin[1]^=m1; | ||
| 124 | DES_encrypt1(tin,ks1,1); | ||
| 125 | tout0=tin[0]; | ||
| 126 | tout1=tin[1]; | ||
| 127 | |||
| 128 | l2c(tout0,out); | ||
| 129 | l2c(tout1,out); | ||
| 130 | } | ||
| 131 | iv1=&(*ivec1)[0]; | ||
| 132 | l2c(m0,iv1); | ||
| 133 | l2c(m1,iv1); | ||
| 134 | |||
| 135 | iv2=&(*ivec2)[0]; | ||
| 136 | l2c(tout0,iv2); | ||
| 137 | l2c(tout1,iv2); | ||
| 138 | } | ||
| 139 | else | ||
| 140 | { | ||
| 141 | register DES_LONG t0,t1; | ||
| 142 | |||
| 143 | c2l(iv1,m0); | ||
| 144 | c2l(iv1,m1); | ||
| 145 | c2l(iv2,xor0); | ||
| 146 | c2l(iv2,xor1); | ||
| 147 | for (l-=8; l>=-7; l-=8) | ||
| 148 | { | ||
| 149 | tin[0]=m0; | ||
| 150 | tin[1]=m1; | ||
| 151 | DES_encrypt1(tin,ks3,1); | ||
| 152 | m0=tin[0]; | ||
| 153 | m1=tin[1]; | ||
| 154 | |||
| 155 | c2l(in,tin0); | ||
| 156 | c2l(in,tin1); | ||
| 157 | |||
| 158 | t0=tin0; | ||
| 159 | t1=tin1; | ||
| 160 | |||
| 161 | tin[0]=tin0; | ||
| 162 | tin[1]=tin1; | ||
| 163 | DES_encrypt1(tin,ks1,0); | ||
| 164 | tin[0]^=m0; | ||
| 165 | tin[1]^=m1; | ||
| 166 | DES_encrypt1(tin,ks2,1); | ||
| 167 | tin[0]^=m0; | ||
| 168 | tin[1]^=m1; | ||
| 169 | DES_encrypt1(tin,ks1,0); | ||
| 170 | tout0=tin[0]; | ||
| 171 | tout1=tin[1]; | ||
| 172 | |||
| 173 | tout0^=xor0; | ||
| 174 | tout1^=xor1; | ||
| 175 | if(l < 0) | ||
| 176 | { | ||
| 177 | l2cn(tout0,tout1,out,l+8); | ||
| 178 | } | ||
| 179 | else | ||
| 180 | { | ||
| 181 | l2c(tout0,out); | ||
| 182 | l2c(tout1,out); | ||
| 183 | } | ||
| 184 | xor0=t0; | ||
| 185 | xor1=t1; | ||
| 186 | } | ||
| 187 | |||
| 188 | iv1=&(*ivec1)[0]; | ||
| 189 | l2c(m0,iv1); | ||
| 190 | l2c(m1,iv1); | ||
| 191 | |||
| 192 | iv2=&(*ivec2)[0]; | ||
| 193 | l2c(xor0,iv2); | ||
| 194 | l2c(xor1,iv2); | ||
| 195 | } | ||
| 196 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 197 | tin[0]=tin[1]=0; | ||
| 198 | } | ||
| 199 | #endif | ||
diff --git a/src/lib/libcrypto/des/enc_read.c b/src/lib/libcrypto/des/enc_read.c new file mode 100644 index 0000000000..c70fb686b8 --- /dev/null +++ b/src/lib/libcrypto/des/enc_read.c | |||
| @@ -0,0 +1,228 @@ | |||
| 1 | /* crypto/des/enc_read.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 <errno.h> | ||
| 61 | #include "cryptlib.h" | ||
| 62 | #include "des_locl.h" | ||
| 63 | |||
| 64 | /* This has some uglies in it but it works - even over sockets. */ | ||
| 65 | /*extern int errno;*/ | ||
| 66 | OPENSSL_IMPLEMENT_GLOBAL(int,DES_rw_mode)=DES_PCBC_MODE; | ||
| 67 | |||
| 68 | |||
| 69 | /* | ||
| 70 | * WARNINGS: | ||
| 71 | * | ||
| 72 | * - The data format used by DES_enc_write() and DES_enc_read() | ||
| 73 | * has a cryptographic weakness: When asked to write more | ||
| 74 | * than MAXWRITE bytes, DES_enc_write will split the data | ||
| 75 | * into several chunks that are all encrypted | ||
| 76 | * using the same IV. So don't use these functions unless you | ||
| 77 | * are sure you know what you do (in which case you might | ||
| 78 | * not want to use them anyway). | ||
| 79 | * | ||
| 80 | * - This code cannot handle non-blocking sockets. | ||
| 81 | * | ||
| 82 | * - This function uses an internal state and thus cannot be | ||
| 83 | * used on multiple files. | ||
| 84 | */ | ||
| 85 | |||
| 86 | |||
| 87 | int DES_enc_read(int fd, void *buf, int len, DES_key_schedule *sched, | ||
| 88 | DES_cblock *iv) | ||
| 89 | { | ||
| 90 | /* data to be unencrypted */ | ||
| 91 | int net_num=0; | ||
| 92 | static unsigned char *net=NULL; | ||
| 93 | /* extra unencrypted data | ||
| 94 | * for when a block of 100 comes in but is des_read one byte at | ||
| 95 | * a time. */ | ||
| 96 | static unsigned char *unnet=NULL; | ||
| 97 | static int unnet_start=0; | ||
| 98 | static int unnet_left=0; | ||
| 99 | static unsigned char *tmpbuf=NULL; | ||
| 100 | int i; | ||
| 101 | long num=0,rnum; | ||
| 102 | unsigned char *p; | ||
| 103 | |||
| 104 | if (tmpbuf == NULL) | ||
| 105 | { | ||
| 106 | tmpbuf=OPENSSL_malloc(BSIZE); | ||
| 107 | if (tmpbuf == NULL) return(-1); | ||
| 108 | } | ||
| 109 | if (net == NULL) | ||
| 110 | { | ||
| 111 | net=OPENSSL_malloc(BSIZE); | ||
| 112 | if (net == NULL) return(-1); | ||
| 113 | } | ||
| 114 | if (unnet == NULL) | ||
| 115 | { | ||
| 116 | unnet=OPENSSL_malloc(BSIZE); | ||
| 117 | if (unnet == NULL) return(-1); | ||
| 118 | } | ||
| 119 | /* left over data from last decrypt */ | ||
| 120 | if (unnet_left != 0) | ||
| 121 | { | ||
| 122 | if (unnet_left < len) | ||
| 123 | { | ||
| 124 | /* we still still need more data but will return | ||
| 125 | * with the number of bytes we have - should always | ||
| 126 | * check the return value */ | ||
| 127 | memcpy(buf,&(unnet[unnet_start]), | ||
| 128 | unnet_left); | ||
| 129 | /* eay 26/08/92 I had the next 2 lines | ||
| 130 | * reversed :-( */ | ||
| 131 | i=unnet_left; | ||
| 132 | unnet_start=unnet_left=0; | ||
| 133 | } | ||
| 134 | else | ||
| 135 | { | ||
| 136 | memcpy(buf,&(unnet[unnet_start]),len); | ||
| 137 | unnet_start+=len; | ||
| 138 | unnet_left-=len; | ||
| 139 | i=len; | ||
| 140 | } | ||
| 141 | return(i); | ||
| 142 | } | ||
| 143 | |||
| 144 | /* We need to get more data. */ | ||
| 145 | if (len > MAXWRITE) len=MAXWRITE; | ||
| 146 | |||
| 147 | /* first - get the length */ | ||
| 148 | while (net_num < HDRSIZE) | ||
| 149 | { | ||
| 150 | i=read(fd,(void *)&(net[net_num]),HDRSIZE-net_num); | ||
| 151 | #ifdef EINTR | ||
| 152 | if ((i == -1) && (errno == EINTR)) continue; | ||
| 153 | #endif | ||
| 154 | if (i <= 0) return(0); | ||
| 155 | net_num+=i; | ||
| 156 | } | ||
| 157 | |||
| 158 | /* we now have at net_num bytes in net */ | ||
| 159 | p=net; | ||
| 160 | /* num=0; */ | ||
| 161 | n2l(p,num); | ||
| 162 | /* num should be rounded up to the next group of eight | ||
| 163 | * we make sure that we have read a multiple of 8 bytes from the net. | ||
| 164 | */ | ||
| 165 | if ((num > MAXWRITE) || (num < 0)) /* error */ | ||
| 166 | return(-1); | ||
| 167 | rnum=(num < 8)?8:((num+7)/8*8); | ||
| 168 | |||
| 169 | net_num=0; | ||
| 170 | while (net_num < rnum) | ||
| 171 | { | ||
| 172 | i=read(fd,(void *)&(net[net_num]),rnum-net_num); | ||
| 173 | #ifdef EINTR | ||
| 174 | if ((i == -1) && (errno == EINTR)) continue; | ||
| 175 | #endif | ||
| 176 | if (i <= 0) return(0); | ||
| 177 | net_num+=i; | ||
| 178 | } | ||
| 179 | |||
| 180 | /* Check if there will be data left over. */ | ||
| 181 | if (len < num) | ||
| 182 | { | ||
| 183 | if (DES_rw_mode & DES_PCBC_MODE) | ||
| 184 | DES_pcbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); | ||
| 185 | else | ||
| 186 | DES_cbc_encrypt(net,unnet,num,sched,iv,DES_DECRYPT); | ||
| 187 | memcpy(buf,unnet,len); | ||
| 188 | unnet_start=len; | ||
| 189 | unnet_left=num-len; | ||
| 190 | |||
| 191 | /* The following line is done because we return num | ||
| 192 | * as the number of bytes read. */ | ||
| 193 | num=len; | ||
| 194 | } | ||
| 195 | else | ||
| 196 | { | ||
| 197 | /* >output is a multiple of 8 byes, if len < rnum | ||
| 198 | * >we must be careful. The user must be aware that this | ||
| 199 | * >routine will write more bytes than he asked for. | ||
| 200 | * >The length of the buffer must be correct. | ||
| 201 | * FIXED - Should be ok now 18-9-90 - eay */ | ||
| 202 | if (len < rnum) | ||
| 203 | { | ||
| 204 | |||
| 205 | if (DES_rw_mode & DES_PCBC_MODE) | ||
| 206 | DES_pcbc_encrypt(net,tmpbuf,num,sched,iv, | ||
| 207 | DES_DECRYPT); | ||
| 208 | else | ||
| 209 | DES_cbc_encrypt(net,tmpbuf,num,sched,iv, | ||
| 210 | DES_DECRYPT); | ||
| 211 | |||
| 212 | /* eay 26/08/92 fix a bug that returned more | ||
| 213 | * bytes than you asked for (returned len bytes :-( */ | ||
| 214 | memcpy(buf,tmpbuf,num); | ||
| 215 | } | ||
| 216 | else | ||
| 217 | { | ||
| 218 | if (DES_rw_mode & DES_PCBC_MODE) | ||
| 219 | DES_pcbc_encrypt(net,buf,num,sched,iv, | ||
| 220 | DES_DECRYPT); | ||
| 221 | else | ||
| 222 | DES_cbc_encrypt(net,buf,num,sched,iv, | ||
| 223 | DES_DECRYPT); | ||
| 224 | } | ||
| 225 | } | ||
| 226 | return num; | ||
| 227 | } | ||
| 228 | |||
diff --git a/src/lib/libcrypto/des/enc_writ.c b/src/lib/libcrypto/des/enc_writ.c new file mode 100644 index 0000000000..af5b8c2349 --- /dev/null +++ b/src/lib/libcrypto/des/enc_writ.c | |||
| @@ -0,0 +1,171 @@ | |||
| 1 | /* crypto/des/enc_writ.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 <errno.h> | ||
| 60 | #include <time.h> | ||
| 61 | #include <stdio.h> | ||
| 62 | #include "cryptlib.h" | ||
| 63 | #include "des_locl.h" | ||
| 64 | #include <openssl/rand.h> | ||
| 65 | |||
| 66 | /* | ||
| 67 | * WARNINGS: | ||
| 68 | * | ||
| 69 | * - The data format used by DES_enc_write() and DES_enc_read() | ||
| 70 | * has a cryptographic weakness: When asked to write more | ||
| 71 | * than MAXWRITE bytes, DES_enc_write will split the data | ||
| 72 | * into several chunks that are all encrypted | ||
| 73 | * using the same IV. So don't use these functions unless you | ||
| 74 | * are sure you know what you do (in which case you might | ||
| 75 | * not want to use them anyway). | ||
| 76 | * | ||
| 77 | * - This code cannot handle non-blocking sockets. | ||
| 78 | */ | ||
| 79 | |||
| 80 | int DES_enc_write(int fd, const void *_buf, int len, | ||
| 81 | DES_key_schedule *sched, DES_cblock *iv) | ||
| 82 | { | ||
| 83 | #ifdef _LIBC | ||
| 84 | extern unsigned long time(); | ||
| 85 | extern int write(); | ||
| 86 | #endif | ||
| 87 | const unsigned char *buf=_buf; | ||
| 88 | long rnum; | ||
| 89 | int i,j,k,outnum; | ||
| 90 | static unsigned char *outbuf=NULL; | ||
| 91 | unsigned char shortbuf[8]; | ||
| 92 | unsigned char *p; | ||
| 93 | const unsigned char *cp; | ||
| 94 | static int start=1; | ||
| 95 | |||
| 96 | if (outbuf == NULL) | ||
| 97 | { | ||
| 98 | outbuf=OPENSSL_malloc(BSIZE+HDRSIZE); | ||
| 99 | if (outbuf == NULL) return(-1); | ||
| 100 | } | ||
| 101 | /* If we are sending less than 8 bytes, the same char will look | ||
| 102 | * the same if we don't pad it out with random bytes */ | ||
| 103 | if (start) | ||
| 104 | { | ||
| 105 | start=0; | ||
| 106 | } | ||
| 107 | |||
| 108 | /* lets recurse if we want to send the data in small chunks */ | ||
| 109 | if (len > MAXWRITE) | ||
| 110 | { | ||
| 111 | j=0; | ||
| 112 | for (i=0; i<len; i+=k) | ||
| 113 | { | ||
| 114 | k=DES_enc_write(fd,&(buf[i]), | ||
| 115 | ((len-i) > MAXWRITE)?MAXWRITE:(len-i),sched,iv); | ||
| 116 | if (k < 0) | ||
| 117 | return(k); | ||
| 118 | else | ||
| 119 | j+=k; | ||
| 120 | } | ||
| 121 | return(j); | ||
| 122 | } | ||
| 123 | |||
| 124 | /* write length first */ | ||
| 125 | p=outbuf; | ||
| 126 | l2n(len,p); | ||
| 127 | |||
| 128 | /* pad short strings */ | ||
| 129 | if (len < 8) | ||
| 130 | { | ||
| 131 | cp=shortbuf; | ||
| 132 | memcpy(shortbuf,buf,len); | ||
| 133 | RAND_pseudo_bytes(shortbuf+len, 8-len); | ||
| 134 | rnum=8; | ||
| 135 | } | ||
| 136 | else | ||
| 137 | { | ||
| 138 | cp=buf; | ||
| 139 | rnum=((len+7)/8*8); /* round up to nearest eight */ | ||
| 140 | } | ||
| 141 | |||
| 142 | if (DES_rw_mode & DES_PCBC_MODE) | ||
| 143 | DES_pcbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, | ||
| 144 | DES_ENCRYPT); | ||
| 145 | else | ||
| 146 | DES_cbc_encrypt(cp,&(outbuf[HDRSIZE]),(len<8)?8:len,sched,iv, | ||
| 147 | DES_ENCRYPT); | ||
| 148 | |||
| 149 | /* output */ | ||
| 150 | outnum=rnum+HDRSIZE; | ||
| 151 | |||
| 152 | for (j=0; j<outnum; j+=i) | ||
| 153 | { | ||
| 154 | /* eay 26/08/92 I was not doing writing from where we | ||
| 155 | * got up to. */ | ||
| 156 | i=write(fd,(void *)&(outbuf[j]),outnum-j); | ||
| 157 | if (i == -1) | ||
| 158 | { | ||
| 159 | #ifdef EINTR | ||
| 160 | if (errno == EINTR) | ||
| 161 | i=0; | ||
| 162 | else | ||
| 163 | #endif | ||
| 164 | /* This is really a bad error - very bad | ||
| 165 | * It will stuff-up both ends. */ | ||
| 166 | return(-1); | ||
| 167 | } | ||
| 168 | } | ||
| 169 | |||
| 170 | return(len); | ||
| 171 | } | ||
diff --git a/src/lib/libcrypto/des/fcrypt.c b/src/lib/libcrypto/des/fcrypt.c new file mode 100644 index 0000000000..ccbdff250f --- /dev/null +++ b/src/lib/libcrypto/des/fcrypt.c | |||
| @@ -0,0 +1,170 @@ | |||
| 1 | /* NOCW */ | ||
| 2 | #include <stdio.h> | ||
| 3 | #ifdef _OSD_POSIX | ||
| 4 | #ifndef CHARSET_EBCDIC | ||
| 5 | #define CHARSET_EBCDIC 1 | ||
| 6 | #endif | ||
| 7 | #endif | ||
| 8 | #ifdef CHARSET_EBCDIC | ||
| 9 | #include <openssl/ebcdic.h> | ||
| 10 | #endif | ||
| 11 | |||
| 12 | /* This version of crypt has been developed from my MIT compatible | ||
| 13 | * DES library. | ||
| 14 | * Eric Young (eay@cryptsoft.com) | ||
| 15 | */ | ||
| 16 | |||
| 17 | /* Modification by Jens Kupferschmidt (Cu) | ||
| 18 | * I have included directive PARA for shared memory computers. | ||
| 19 | * I have included a directive LONGCRYPT to using this routine to cipher | ||
| 20 | * passwords with more then 8 bytes like HP-UX 10.x it used. The MAXPLEN | ||
| 21 | * definition is the maximum of length of password and can changed. I have | ||
| 22 | * defined 24. | ||
| 23 | */ | ||
| 24 | |||
| 25 | #include "des_locl.h" | ||
| 26 | |||
| 27 | /* Added more values to handle illegal salt values the way normal | ||
| 28 | * crypt() implementations do. The patch was sent by | ||
| 29 | * Bjorn Gronvall <bg@sics.se> | ||
| 30 | */ | ||
| 31 | static unsigned const char con_salt[128]={ | ||
| 32 | 0xD2,0xD3,0xD4,0xD5,0xD6,0xD7,0xD8,0xD9, | ||
| 33 | 0xDA,0xDB,0xDC,0xDD,0xDE,0xDF,0xE0,0xE1, | ||
| 34 | 0xE2,0xE3,0xE4,0xE5,0xE6,0xE7,0xE8,0xE9, | ||
| 35 | 0xEA,0xEB,0xEC,0xED,0xEE,0xEF,0xF0,0xF1, | ||
| 36 | 0xF2,0xF3,0xF4,0xF5,0xF6,0xF7,0xF8,0xF9, | ||
| 37 | 0xFA,0xFB,0xFC,0xFD,0xFE,0xFF,0x00,0x01, | ||
| 38 | 0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09, | ||
| 39 | 0x0A,0x0B,0x05,0x06,0x07,0x08,0x09,0x0A, | ||
| 40 | 0x0B,0x0C,0x0D,0x0E,0x0F,0x10,0x11,0x12, | ||
| 41 | 0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A, | ||
| 42 | 0x1B,0x1C,0x1D,0x1E,0x1F,0x20,0x21,0x22, | ||
| 43 | 0x23,0x24,0x25,0x20,0x21,0x22,0x23,0x24, | ||
| 44 | 0x25,0x26,0x27,0x28,0x29,0x2A,0x2B,0x2C, | ||
| 45 | 0x2D,0x2E,0x2F,0x30,0x31,0x32,0x33,0x34, | ||
| 46 | 0x35,0x36,0x37,0x38,0x39,0x3A,0x3B,0x3C, | ||
| 47 | 0x3D,0x3E,0x3F,0x40,0x41,0x42,0x43,0x44, | ||
| 48 | }; | ||
| 49 | |||
| 50 | static unsigned const char cov_2char[64]={ | ||
| 51 | 0x2E,0x2F,0x30,0x31,0x32,0x33,0x34,0x35, | ||
| 52 | 0x36,0x37,0x38,0x39,0x41,0x42,0x43,0x44, | ||
| 53 | 0x45,0x46,0x47,0x48,0x49,0x4A,0x4B,0x4C, | ||
| 54 | 0x4D,0x4E,0x4F,0x50,0x51,0x52,0x53,0x54, | ||
| 55 | 0x55,0x56,0x57,0x58,0x59,0x5A,0x61,0x62, | ||
| 56 | 0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6A, | ||
| 57 | 0x6B,0x6C,0x6D,0x6E,0x6F,0x70,0x71,0x72, | ||
| 58 | 0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7A | ||
| 59 | }; | ||
| 60 | |||
| 61 | char *DES_crypt(const char *buf, const char *salt) | ||
| 62 | { | ||
| 63 | static char buff[14]; | ||
| 64 | |||
| 65 | #ifndef CHARSET_EBCDIC | ||
| 66 | return(DES_fcrypt(buf,salt,buff)); | ||
| 67 | #else | ||
| 68 | char e_salt[2+1]; | ||
| 69 | char e_buf[32+1]; /* replace 32 by 8 ? */ | ||
| 70 | char *ret; | ||
| 71 | |||
| 72 | /* Copy at most 2 chars of salt */ | ||
| 73 | if ((e_salt[0] = salt[0]) != '\0') | ||
| 74 | e_salt[1] = salt[1]; | ||
| 75 | |||
| 76 | /* Copy at most 32 chars of password */ | ||
| 77 | strncpy (e_buf, buf, sizeof(e_buf)); | ||
| 78 | |||
| 79 | /* Make sure we have a delimiter */ | ||
| 80 | e_salt[sizeof(e_salt)-1] = e_buf[sizeof(e_buf)-1] = '\0'; | ||
| 81 | |||
| 82 | /* Convert the e_salt to ASCII, as that's what DES_fcrypt works on */ | ||
| 83 | ebcdic2ascii(e_salt, e_salt, sizeof e_salt); | ||
| 84 | |||
| 85 | /* Convert the cleartext password to ASCII */ | ||
| 86 | ebcdic2ascii(e_buf, e_buf, sizeof e_buf); | ||
| 87 | |||
| 88 | /* Encrypt it (from/to ASCII) */ | ||
| 89 | ret = DES_fcrypt(e_buf,e_salt,buff); | ||
| 90 | |||
| 91 | /* Convert the result back to EBCDIC */ | ||
| 92 | ascii2ebcdic(ret, ret, strlen(ret)); | ||
| 93 | |||
| 94 | return ret; | ||
| 95 | #endif | ||
| 96 | } | ||
| 97 | |||
| 98 | |||
| 99 | char *DES_fcrypt(const char *buf, const char *salt, char *ret) | ||
| 100 | { | ||
| 101 | unsigned int i,j,x,y; | ||
| 102 | DES_LONG Eswap0,Eswap1; | ||
| 103 | DES_LONG out[2],ll; | ||
| 104 | DES_cblock key; | ||
| 105 | DES_key_schedule ks; | ||
| 106 | unsigned char bb[9]; | ||
| 107 | unsigned char *b=bb; | ||
| 108 | unsigned char c,u; | ||
| 109 | |||
| 110 | /* eay 25/08/92 | ||
| 111 | * If you call crypt("pwd","*") as often happens when you | ||
| 112 | * have * as the pwd field in /etc/passwd, the function | ||
| 113 | * returns *\0XXXXXXXXX | ||
| 114 | * The \0 makes the string look like * so the pwd "*" would | ||
| 115 | * crypt to "*". This was found when replacing the crypt in | ||
| 116 | * our shared libraries. People found that the disabled | ||
| 117 | * accounts effectively had no passwd :-(. */ | ||
| 118 | #ifndef CHARSET_EBCDIC | ||
| 119 | x=ret[0]=((salt[0] == '\0')?'A':salt[0]); | ||
| 120 | Eswap0=con_salt[x]<<2; | ||
| 121 | x=ret[1]=((salt[1] == '\0')?'A':salt[1]); | ||
| 122 | Eswap1=con_salt[x]<<6; | ||
| 123 | #else | ||
| 124 | x=ret[0]=((salt[0] == '\0')?os_toascii['A']:salt[0]); | ||
| 125 | Eswap0=con_salt[x]<<2; | ||
| 126 | x=ret[1]=((salt[1] == '\0')?os_toascii['A']:salt[1]); | ||
| 127 | Eswap1=con_salt[x]<<6; | ||
| 128 | #endif | ||
| 129 | |||
| 130 | /* EAY | ||
| 131 | r=strlen(buf); | ||
| 132 | r=(r+7)/8; | ||
| 133 | */ | ||
| 134 | for (i=0; i<8; i++) | ||
| 135 | { | ||
| 136 | c= *(buf++); | ||
| 137 | if (!c) break; | ||
| 138 | key[i]=(c<<1); | ||
| 139 | } | ||
| 140 | for (; i<8; i++) | ||
| 141 | key[i]=0; | ||
| 142 | |||
| 143 | DES_set_key_unchecked(&key,&ks); | ||
| 144 | fcrypt_body(&(out[0]),&ks,Eswap0,Eswap1); | ||
| 145 | |||
| 146 | ll=out[0]; l2c(ll,b); | ||
| 147 | ll=out[1]; l2c(ll,b); | ||
| 148 | y=0; | ||
| 149 | u=0x80; | ||
| 150 | bb[8]=0; | ||
| 151 | for (i=2; i<13; i++) | ||
| 152 | { | ||
| 153 | c=0; | ||
| 154 | for (j=0; j<6; j++) | ||
| 155 | { | ||
| 156 | c<<=1; | ||
| 157 | if (bb[y] & u) c|=1; | ||
| 158 | u>>=1; | ||
| 159 | if (!u) | ||
| 160 | { | ||
| 161 | y++; | ||
| 162 | u=0x80; | ||
| 163 | } | ||
| 164 | } | ||
| 165 | ret[i]=cov_2char[c]; | ||
| 166 | } | ||
| 167 | ret[13]='\0'; | ||
| 168 | return(ret); | ||
| 169 | } | ||
| 170 | |||
diff --git a/src/lib/libcrypto/des/fcrypt_b.c b/src/lib/libcrypto/des/fcrypt_b.c new file mode 100644 index 0000000000..c56b461e91 --- /dev/null +++ b/src/lib/libcrypto/des/fcrypt_b.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | /* crypto/des/fcrypt_b.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 | |||
| 61 | /* This version of crypt has been developed from my MIT compatible | ||
| 62 | * DES library. | ||
| 63 | * The library is available at pub/Crypto/DES at ftp.psy.uq.oz.au | ||
| 64 | * Eric Young (eay@cryptsoft.com) | ||
| 65 | */ | ||
| 66 | |||
| 67 | #define DES_FCRYPT | ||
| 68 | #include "des_locl.h" | ||
| 69 | #undef DES_FCRYPT | ||
| 70 | |||
| 71 | #ifndef OPENBSD_DES_ASM | ||
| 72 | |||
| 73 | #undef PERM_OP | ||
| 74 | #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 75 | (b)^=(t),\ | ||
| 76 | (a)^=((t)<<(n))) | ||
| 77 | |||
| 78 | #undef HPERM_OP | ||
| 79 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | ||
| 80 | (a)=(a)^(t)^(t>>(16-(n))))\ | ||
| 81 | |||
| 82 | void fcrypt_body(DES_LONG *out, DES_key_schedule *ks, DES_LONG Eswap0, | ||
| 83 | DES_LONG Eswap1) | ||
| 84 | { | ||
| 85 | register DES_LONG l,r,t,u; | ||
| 86 | #ifdef DES_PTR | ||
| 87 | register const unsigned char *des_SP=(const unsigned char *)DES_SPtrans; | ||
| 88 | #endif | ||
| 89 | register DES_LONG *s; | ||
| 90 | register int j; | ||
| 91 | register DES_LONG E0,E1; | ||
| 92 | |||
| 93 | l=0; | ||
| 94 | r=0; | ||
| 95 | |||
| 96 | s=(DES_LONG *)ks; | ||
| 97 | E0=Eswap0; | ||
| 98 | E1=Eswap1; | ||
| 99 | |||
| 100 | for (j=0; j<25; j++) | ||
| 101 | { | ||
| 102 | #ifndef DES_UNROLL | ||
| 103 | register int i; | ||
| 104 | |||
| 105 | for (i=0; i<32; i+=8) | ||
| 106 | { | ||
| 107 | D_ENCRYPT(l,r,i+0); /* 1 */ | ||
| 108 | D_ENCRYPT(r,l,i+2); /* 2 */ | ||
| 109 | D_ENCRYPT(l,r,i+4); /* 1 */ | ||
| 110 | D_ENCRYPT(r,l,i+6); /* 2 */ | ||
| 111 | } | ||
| 112 | #else | ||
| 113 | D_ENCRYPT(l,r, 0); /* 1 */ | ||
| 114 | D_ENCRYPT(r,l, 2); /* 2 */ | ||
| 115 | D_ENCRYPT(l,r, 4); /* 3 */ | ||
| 116 | D_ENCRYPT(r,l, 6); /* 4 */ | ||
| 117 | D_ENCRYPT(l,r, 8); /* 5 */ | ||
| 118 | D_ENCRYPT(r,l,10); /* 6 */ | ||
| 119 | D_ENCRYPT(l,r,12); /* 7 */ | ||
| 120 | D_ENCRYPT(r,l,14); /* 8 */ | ||
| 121 | D_ENCRYPT(l,r,16); /* 9 */ | ||
| 122 | D_ENCRYPT(r,l,18); /* 10 */ | ||
| 123 | D_ENCRYPT(l,r,20); /* 11 */ | ||
| 124 | D_ENCRYPT(r,l,22); /* 12 */ | ||
| 125 | D_ENCRYPT(l,r,24); /* 13 */ | ||
| 126 | D_ENCRYPT(r,l,26); /* 14 */ | ||
| 127 | D_ENCRYPT(l,r,28); /* 15 */ | ||
| 128 | D_ENCRYPT(r,l,30); /* 16 */ | ||
| 129 | #endif | ||
| 130 | |||
| 131 | t=l; | ||
| 132 | l=r; | ||
| 133 | r=t; | ||
| 134 | } | ||
| 135 | l=ROTATE(l,3)&0xffffffffL; | ||
| 136 | r=ROTATE(r,3)&0xffffffffL; | ||
| 137 | |||
| 138 | PERM_OP(l,r,t, 1,0x55555555L); | ||
| 139 | PERM_OP(r,l,t, 8,0x00ff00ffL); | ||
| 140 | PERM_OP(l,r,t, 2,0x33333333L); | ||
| 141 | PERM_OP(r,l,t,16,0x0000ffffL); | ||
| 142 | PERM_OP(l,r,t, 4,0x0f0f0f0fL); | ||
| 143 | |||
| 144 | out[0]=r; | ||
| 145 | out[1]=l; | ||
| 146 | } | ||
| 147 | |||
| 148 | #endif /* OPENBSD_DES_ASM */ | ||
diff --git a/src/lib/libcrypto/des/ncbc_enc.c b/src/lib/libcrypto/des/ncbc_enc.c new file mode 100644 index 0000000000..fda23d522f --- /dev/null +++ b/src/lib/libcrypto/des/ncbc_enc.c | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | /* crypto/des/ncbc_enc.c */ | ||
| 2 | /* | ||
| 3 | * #included by: | ||
| 4 | * cbc_enc.c (DES_cbc_encrypt) | ||
| 5 | * des_enc.c (DES_ncbc_encrypt) | ||
| 6 | */ | ||
| 7 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) | ||
| 8 | * All rights reserved. | ||
| 9 | * | ||
| 10 | * This package is an SSL implementation written | ||
| 11 | * by Eric Young (eay@cryptsoft.com). | ||
| 12 | * The implementation was written so as to conform with Netscapes SSL. | ||
| 13 | * | ||
| 14 | * This library is free for commercial and non-commercial use as long as | ||
| 15 | * the following conditions are aheared to. The following conditions | ||
| 16 | * apply to all code found in this distribution, be it the RC4, RSA, | ||
| 17 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation | ||
| 18 | * included with this distribution is covered by the same copyright terms | ||
| 19 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). | ||
| 20 | * | ||
| 21 | * Copyright remains Eric Young's, and as such any Copyright notices in | ||
| 22 | * the code are not to be removed. | ||
| 23 | * If this package is used in a product, Eric Young should be given attribution | ||
| 24 | * as the author of the parts of the library used. | ||
| 25 | * This can be in the form of a textual message at program startup or | ||
| 26 | * in documentation (online or textual) provided with the package. | ||
| 27 | * | ||
| 28 | * Redistribution and use in source and binary forms, with or without | ||
| 29 | * modification, are permitted provided that the following conditions | ||
| 30 | * are met: | ||
| 31 | * 1. Redistributions of source code must retain the copyright | ||
| 32 | * notice, this list of conditions and the following disclaimer. | ||
| 33 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 34 | * notice, this list of conditions and the following disclaimer in the | ||
| 35 | * documentation and/or other materials provided with the distribution. | ||
| 36 | * 3. All advertising materials mentioning features or use of this software | ||
| 37 | * must display the following acknowledgement: | ||
| 38 | * "This product includes cryptographic software written by | ||
| 39 | * Eric Young (eay@cryptsoft.com)" | ||
| 40 | * The word 'cryptographic' can be left out if the rouines from the library | ||
| 41 | * being used are not cryptographic related :-). | ||
| 42 | * 4. If you include any Windows specific code (or a derivative thereof) from | ||
| 43 | * the apps directory (application code) you must include an acknowledgement: | ||
| 44 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" | ||
| 45 | * | ||
| 46 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND | ||
| 47 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 48 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 49 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 50 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 51 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 52 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 53 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 54 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 55 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 56 | * SUCH DAMAGE. | ||
| 57 | * | ||
| 58 | * The licence and distribution terms for any publically available version or | ||
| 59 | * derivative of this code cannot be changed. i.e. this code cannot simply be | ||
| 60 | * copied and put under another distribution licence | ||
| 61 | * [including the GNU Public Licence.] | ||
| 62 | */ | ||
| 63 | |||
| 64 | #include "des_locl.h" | ||
| 65 | |||
| 66 | #ifdef CBC_ENC_C__DONT_UPDATE_IV | ||
| 67 | void DES_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
| 68 | DES_key_schedule *_schedule, DES_cblock *ivec, int enc) | ||
| 69 | #else | ||
| 70 | void DES_ncbc_encrypt(const unsigned char *in, unsigned char *out, long length, | ||
| 71 | DES_key_schedule *_schedule, DES_cblock *ivec, int enc) | ||
| 72 | #endif | ||
| 73 | { | ||
| 74 | register DES_LONG tin0,tin1; | ||
| 75 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 76 | register long l=length; | ||
| 77 | DES_LONG tin[2]; | ||
| 78 | unsigned char *iv; | ||
| 79 | |||
| 80 | iv = &(*ivec)[0]; | ||
| 81 | |||
| 82 | if (enc) | ||
| 83 | { | ||
| 84 | c2l(iv,tout0); | ||
| 85 | c2l(iv,tout1); | ||
| 86 | for (l-=8; l>=0; l-=8) | ||
| 87 | { | ||
| 88 | c2l(in,tin0); | ||
| 89 | c2l(in,tin1); | ||
| 90 | tin0^=tout0; tin[0]=tin0; | ||
| 91 | tin1^=tout1; tin[1]=tin1; | ||
| 92 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT); | ||
| 93 | tout0=tin[0]; l2c(tout0,out); | ||
| 94 | tout1=tin[1]; l2c(tout1,out); | ||
| 95 | } | ||
| 96 | if (l != -8) | ||
| 97 | { | ||
| 98 | c2ln(in,tin0,tin1,l+8); | ||
| 99 | tin0^=tout0; tin[0]=tin0; | ||
| 100 | tin1^=tout1; tin[1]=tin1; | ||
| 101 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_ENCRYPT); | ||
| 102 | tout0=tin[0]; l2c(tout0,out); | ||
| 103 | tout1=tin[1]; l2c(tout1,out); | ||
| 104 | } | ||
| 105 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | ||
| 106 | iv = &(*ivec)[0]; | ||
| 107 | l2c(tout0,iv); | ||
| 108 | l2c(tout1,iv); | ||
| 109 | #endif | ||
| 110 | } | ||
| 111 | else | ||
| 112 | { | ||
| 113 | c2l(iv,xor0); | ||
| 114 | c2l(iv,xor1); | ||
| 115 | for (l-=8; l>=0; l-=8) | ||
| 116 | { | ||
| 117 | c2l(in,tin0); tin[0]=tin0; | ||
| 118 | c2l(in,tin1); tin[1]=tin1; | ||
| 119 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT); | ||
| 120 | tout0=tin[0]^xor0; | ||
| 121 | tout1=tin[1]^xor1; | ||
| 122 | l2c(tout0,out); | ||
| 123 | l2c(tout1,out); | ||
| 124 | xor0=tin0; | ||
| 125 | xor1=tin1; | ||
| 126 | } | ||
| 127 | if (l != -8) | ||
| 128 | { | ||
| 129 | c2l(in,tin0); tin[0]=tin0; | ||
| 130 | c2l(in,tin1); tin[1]=tin1; | ||
| 131 | DES_encrypt1((DES_LONG *)tin,_schedule,DES_DECRYPT); | ||
| 132 | tout0=tin[0]^xor0; | ||
| 133 | tout1=tin[1]^xor1; | ||
| 134 | l2cn(tout0,tout1,out,l+8); | ||
| 135 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | ||
| 136 | xor0=tin0; | ||
| 137 | xor1=tin1; | ||
| 138 | #endif | ||
| 139 | } | ||
| 140 | #ifndef CBC_ENC_C__DONT_UPDATE_IV | ||
| 141 | iv = &(*ivec)[0]; | ||
| 142 | l2c(xor0,iv); | ||
| 143 | l2c(xor1,iv); | ||
| 144 | #endif | ||
| 145 | } | ||
| 146 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 147 | tin[0]=tin[1]=0; | ||
| 148 | } | ||
diff --git a/src/lib/libcrypto/des/ofb64ede.c b/src/lib/libcrypto/des/ofb64ede.c new file mode 100644 index 0000000000..26bbf9a6a7 --- /dev/null +++ b/src/lib/libcrypto/des/ofb64ede.c | |||
| @@ -0,0 +1,125 @@ | |||
| 1 | /* crypto/des/ofb64ede.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | void DES_ede3_ofb64_encrypt(register const unsigned char *in, | ||
| 66 | register unsigned char *out, long length, | ||
| 67 | DES_key_schedule *k1, DES_key_schedule *k2, | ||
| 68 | DES_key_schedule *k3, DES_cblock *ivec, | ||
| 69 | int *num) | ||
| 70 | { | ||
| 71 | register DES_LONG v0,v1; | ||
| 72 | register int n= *num; | ||
| 73 | register long l=length; | ||
| 74 | DES_cblock d; | ||
| 75 | register char *dp; | ||
| 76 | DES_LONG ti[2]; | ||
| 77 | unsigned char *iv; | ||
| 78 | int save=0; | ||
| 79 | |||
| 80 | iv = &(*ivec)[0]; | ||
| 81 | c2l(iv,v0); | ||
| 82 | c2l(iv,v1); | ||
| 83 | ti[0]=v0; | ||
| 84 | ti[1]=v1; | ||
| 85 | dp=(char *)d; | ||
| 86 | l2c(v0,dp); | ||
| 87 | l2c(v1,dp); | ||
| 88 | while (l--) | ||
| 89 | { | ||
| 90 | if (n == 0) | ||
| 91 | { | ||
| 92 | /* ti[0]=v0; */ | ||
| 93 | /* ti[1]=v1; */ | ||
| 94 | DES_encrypt3(ti,k1,k2,k3); | ||
| 95 | v0=ti[0]; | ||
| 96 | v1=ti[1]; | ||
| 97 | |||
| 98 | dp=(char *)d; | ||
| 99 | l2c(v0,dp); | ||
| 100 | l2c(v1,dp); | ||
| 101 | save++; | ||
| 102 | } | ||
| 103 | *(out++)= *(in++)^d[n]; | ||
| 104 | n=(n+1)&0x07; | ||
| 105 | } | ||
| 106 | if (save) | ||
| 107 | { | ||
| 108 | /* v0=ti[0]; | ||
| 109 | v1=ti[1];*/ | ||
| 110 | iv = &(*ivec)[0]; | ||
| 111 | l2c(v0,iv); | ||
| 112 | l2c(v1,iv); | ||
| 113 | } | ||
| 114 | v0=v1=ti[0]=ti[1]=0; | ||
| 115 | *num=n; | ||
| 116 | } | ||
| 117 | |||
| 118 | #ifdef undef /* MACRO */ | ||
| 119 | void DES_ede2_ofb64_encrypt(register unsigned char *in, | ||
| 120 | register unsigned char *out, long length, DES_key_schedule k1, | ||
| 121 | DES_key_schedule k2, DES_cblock (*ivec), int *num) | ||
| 122 | { | ||
| 123 | DES_ede3_ofb64_encrypt(in, out, length, k1,k2,k1, ivec, num); | ||
| 124 | } | ||
| 125 | #endif | ||
diff --git a/src/lib/libcrypto/des/ofb64enc.c b/src/lib/libcrypto/des/ofb64enc.c new file mode 100644 index 0000000000..8ca3d49dea --- /dev/null +++ b/src/lib/libcrypto/des/ofb64enc.c | |||
| @@ -0,0 +1,110 @@ | |||
| 1 | /* crypto/des/ofb64enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output encrypted as though 64bit ofb mode is being | ||
| 62 | * used. The extra state information to record how much of the | ||
| 63 | * 64bit block we have used is contained in *num; | ||
| 64 | */ | ||
| 65 | void DES_ofb64_encrypt(register const unsigned char *in, | ||
| 66 | register unsigned char *out, long length, | ||
| 67 | DES_key_schedule *schedule, DES_cblock *ivec, int *num) | ||
| 68 | { | ||
| 69 | register DES_LONG v0,v1,t; | ||
| 70 | register int n= *num; | ||
| 71 | register long l=length; | ||
| 72 | DES_cblock d; | ||
| 73 | register unsigned char *dp; | ||
| 74 | DES_LONG ti[2]; | ||
| 75 | unsigned char *iv; | ||
| 76 | int save=0; | ||
| 77 | |||
| 78 | iv = &(*ivec)[0]; | ||
| 79 | c2l(iv,v0); | ||
| 80 | c2l(iv,v1); | ||
| 81 | ti[0]=v0; | ||
| 82 | ti[1]=v1; | ||
| 83 | dp=d; | ||
| 84 | l2c(v0,dp); | ||
| 85 | l2c(v1,dp); | ||
| 86 | while (l--) | ||
| 87 | { | ||
| 88 | if (n == 0) | ||
| 89 | { | ||
| 90 | DES_encrypt1(ti,schedule,DES_ENCRYPT); | ||
| 91 | dp=d; | ||
| 92 | t=ti[0]; l2c(t,dp); | ||
| 93 | t=ti[1]; l2c(t,dp); | ||
| 94 | save++; | ||
| 95 | } | ||
| 96 | *(out++)= *(in++)^d[n]; | ||
| 97 | n=(n+1)&0x07; | ||
| 98 | } | ||
| 99 | if (save) | ||
| 100 | { | ||
| 101 | v0=ti[0]; | ||
| 102 | v1=ti[1]; | ||
| 103 | iv = &(*ivec)[0]; | ||
| 104 | l2c(v0,iv); | ||
| 105 | l2c(v1,iv); | ||
| 106 | } | ||
| 107 | t=v0=v1=ti[0]=ti[1]=0; | ||
| 108 | *num=n; | ||
| 109 | } | ||
| 110 | |||
diff --git a/src/lib/libcrypto/des/ofb_enc.c b/src/lib/libcrypto/des/ofb_enc.c new file mode 100644 index 0000000000..e887a3c6f4 --- /dev/null +++ b/src/lib/libcrypto/des/ofb_enc.c | |||
| @@ -0,0 +1,135 @@ | |||
| 1 | /* crypto/des/ofb_enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* The input and output are loaded in multiples of 8 bits. | ||
| 62 | * What this means is that if you hame numbits=12 and length=2 | ||
| 63 | * the first 12 bits will be retrieved from the first byte and half | ||
| 64 | * the second. The second 12 bits will come from the 3rd and half the 4th | ||
| 65 | * byte. | ||
| 66 | */ | ||
| 67 | void DES_ofb_encrypt(const unsigned char *in, unsigned char *out, int numbits, | ||
| 68 | long length, DES_key_schedule *schedule, | ||
| 69 | DES_cblock *ivec) | ||
| 70 | { | ||
| 71 | register DES_LONG d0,d1,vv0,vv1,v0,v1,n=(numbits+7)/8; | ||
| 72 | register DES_LONG mask0,mask1; | ||
| 73 | register long l=length; | ||
| 74 | register int num=numbits; | ||
| 75 | DES_LONG ti[2]; | ||
| 76 | unsigned char *iv; | ||
| 77 | |||
| 78 | if (num > 64) return; | ||
| 79 | if (num > 32) | ||
| 80 | { | ||
| 81 | mask0=0xffffffffL; | ||
| 82 | if (num >= 64) | ||
| 83 | mask1=mask0; | ||
| 84 | else | ||
| 85 | mask1=(1L<<(num-32))-1; | ||
| 86 | } | ||
| 87 | else | ||
| 88 | { | ||
| 89 | if (num == 32) | ||
| 90 | mask0=0xffffffffL; | ||
| 91 | else | ||
| 92 | mask0=(1L<<num)-1; | ||
| 93 | mask1=0x00000000L; | ||
| 94 | } | ||
| 95 | |||
| 96 | iv = &(*ivec)[0]; | ||
| 97 | c2l(iv,v0); | ||
| 98 | c2l(iv,v1); | ||
| 99 | ti[0]=v0; | ||
| 100 | ti[1]=v1; | ||
| 101 | while (l-- > 0) | ||
| 102 | { | ||
| 103 | ti[0]=v0; | ||
| 104 | ti[1]=v1; | ||
| 105 | DES_encrypt1((DES_LONG *)ti,schedule,DES_ENCRYPT); | ||
| 106 | vv0=ti[0]; | ||
| 107 | vv1=ti[1]; | ||
| 108 | c2ln(in,d0,d1,n); | ||
| 109 | in+=n; | ||
| 110 | d0=(d0^vv0)&mask0; | ||
| 111 | d1=(d1^vv1)&mask1; | ||
| 112 | l2cn(d0,d1,out,n); | ||
| 113 | out+=n; | ||
| 114 | |||
| 115 | if (num == 32) | ||
| 116 | { v0=v1; v1=vv0; } | ||
| 117 | else if (num == 64) | ||
| 118 | { v0=vv0; v1=vv1; } | ||
| 119 | else if (num > 32) /* && num != 64 */ | ||
| 120 | { | ||
| 121 | v0=((v1>>(num-32))|(vv0<<(64-num)))&0xffffffffL; | ||
| 122 | v1=((vv0>>(num-32))|(vv1<<(64-num)))&0xffffffffL; | ||
| 123 | } | ||
| 124 | else /* num < 32 */ | ||
| 125 | { | ||
| 126 | v0=((v0>>num)|(v1<<(32-num)))&0xffffffffL; | ||
| 127 | v1=((v1>>num)|(vv0<<(32-num)))&0xffffffffL; | ||
| 128 | } | ||
| 129 | } | ||
| 130 | iv = &(*ivec)[0]; | ||
| 131 | l2c(v0,iv); | ||
| 132 | l2c(v1,iv); | ||
| 133 | v0=v1=d0=d1=ti[0]=ti[1]=vv0=vv1=0; | ||
| 134 | } | ||
| 135 | |||
diff --git a/src/lib/libcrypto/des/pcbc_enc.c b/src/lib/libcrypto/des/pcbc_enc.c new file mode 100644 index 0000000000..17a40f9520 --- /dev/null +++ b/src/lib/libcrypto/des/pcbc_enc.c | |||
| @@ -0,0 +1,123 @@ | |||
| 1 | /* crypto/des/pcbc_enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | void DES_pcbc_encrypt(const unsigned char *input, unsigned char *output, | ||
| 62 | long length, DES_key_schedule *schedule, | ||
| 63 | DES_cblock *ivec, int enc) | ||
| 64 | { | ||
| 65 | register DES_LONG sin0,sin1,xor0,xor1,tout0,tout1; | ||
| 66 | DES_LONG tin[2]; | ||
| 67 | const unsigned char *in; | ||
| 68 | unsigned char *out,*iv; | ||
| 69 | |||
| 70 | in=input; | ||
| 71 | out=output; | ||
| 72 | iv = &(*ivec)[0]; | ||
| 73 | |||
| 74 | if (enc) | ||
| 75 | { | ||
| 76 | c2l(iv,xor0); | ||
| 77 | c2l(iv,xor1); | ||
| 78 | for (; length>0; length-=8) | ||
| 79 | { | ||
| 80 | if (length >= 8) | ||
| 81 | { | ||
| 82 | c2l(in,sin0); | ||
| 83 | c2l(in,sin1); | ||
| 84 | } | ||
| 85 | else | ||
| 86 | c2ln(in,sin0,sin1,length); | ||
| 87 | tin[0]=sin0^xor0; | ||
| 88 | tin[1]=sin1^xor1; | ||
| 89 | DES_encrypt1((DES_LONG *)tin,schedule,DES_ENCRYPT); | ||
| 90 | tout0=tin[0]; | ||
| 91 | tout1=tin[1]; | ||
| 92 | xor0=sin0^tout0; | ||
| 93 | xor1=sin1^tout1; | ||
| 94 | l2c(tout0,out); | ||
| 95 | l2c(tout1,out); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | else | ||
| 99 | { | ||
| 100 | c2l(iv,xor0); c2l(iv,xor1); | ||
| 101 | for (; length>0; length-=8) | ||
| 102 | { | ||
| 103 | c2l(in,sin0); | ||
| 104 | c2l(in,sin1); | ||
| 105 | tin[0]=sin0; | ||
| 106 | tin[1]=sin1; | ||
| 107 | DES_encrypt1((DES_LONG *)tin,schedule,DES_DECRYPT); | ||
| 108 | tout0=tin[0]^xor0; | ||
| 109 | tout1=tin[1]^xor1; | ||
| 110 | if (length >= 8) | ||
| 111 | { | ||
| 112 | l2c(tout0,out); | ||
| 113 | l2c(tout1,out); | ||
| 114 | } | ||
| 115 | else | ||
| 116 | l2cn(tout0,tout1,out,length); | ||
| 117 | xor0=tout0^sin0; | ||
| 118 | xor1=tout1^sin1; | ||
| 119 | } | ||
| 120 | } | ||
| 121 | tin[0]=tin[1]=0; | ||
| 122 | sin0=sin1=xor0=xor1=tout0=tout1=0; | ||
| 123 | } | ||
diff --git a/src/lib/libcrypto/des/qud_cksm.c b/src/lib/libcrypto/des/qud_cksm.c new file mode 100644 index 0000000000..dac201227e --- /dev/null +++ b/src/lib/libcrypto/des/qud_cksm.c | |||
| @@ -0,0 +1,139 @@ | |||
| 1 | /* crypto/des/qud_cksm.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 | /* From "Message Authentication" R.R. Jueneman, S.M. Matyas, C.H. Meyer | ||
| 60 | * IEEE Communications Magazine Sept 1985 Vol. 23 No. 9 p 29-40 | ||
| 61 | * This module in only based on the code in this paper and is | ||
| 62 | * almost definitely not the same as the MIT implementation. | ||
| 63 | */ | ||
| 64 | #include "des_locl.h" | ||
| 65 | |||
| 66 | /* bug fix for dos - 7/6/91 - Larry hughes@logos.ucs.indiana.edu */ | ||
| 67 | #define Q_B0(a) (((DES_LONG)(a))) | ||
| 68 | #define Q_B1(a) (((DES_LONG)(a))<<8) | ||
| 69 | #define Q_B2(a) (((DES_LONG)(a))<<16) | ||
| 70 | #define Q_B3(a) (((DES_LONG)(a))<<24) | ||
| 71 | |||
| 72 | /* used to scramble things a bit */ | ||
| 73 | /* Got the value MIT uses via brute force :-) 2/10/90 eay */ | ||
| 74 | #define NOISE ((DES_LONG)83653421L) | ||
| 75 | |||
| 76 | DES_LONG DES_quad_cksum(const unsigned char *input, DES_cblock output[], | ||
| 77 | long length, int out_count, DES_cblock *seed) | ||
| 78 | { | ||
| 79 | DES_LONG z0,z1,t0,t1; | ||
| 80 | int i; | ||
| 81 | long l; | ||
| 82 | const unsigned char *cp; | ||
| 83 | #ifdef _CRAY | ||
| 84 | struct lp_st { int a:32; int b:32; } *lp; | ||
| 85 | #else | ||
| 86 | DES_LONG *lp; | ||
| 87 | #endif | ||
| 88 | |||
| 89 | if (out_count < 1) out_count=1; | ||
| 90 | #ifdef _CRAY | ||
| 91 | lp = (struct lp_st *) &(output[0])[0]; | ||
| 92 | #else | ||
| 93 | lp = (DES_LONG *) &(output[0])[0]; | ||
| 94 | #endif | ||
| 95 | |||
| 96 | z0=Q_B0((*seed)[0])|Q_B1((*seed)[1])|Q_B2((*seed)[2])|Q_B3((*seed)[3]); | ||
| 97 | z1=Q_B0((*seed)[4])|Q_B1((*seed)[5])|Q_B2((*seed)[6])|Q_B3((*seed)[7]); | ||
| 98 | |||
| 99 | for (i=0; ((i<4)&&(i<out_count)); i++) | ||
| 100 | { | ||
| 101 | cp=input; | ||
| 102 | l=length; | ||
| 103 | while (l > 0) | ||
| 104 | { | ||
| 105 | if (l > 1) | ||
| 106 | { | ||
| 107 | t0= (DES_LONG)(*(cp++)); | ||
| 108 | t0|=(DES_LONG)Q_B1(*(cp++)); | ||
| 109 | l--; | ||
| 110 | } | ||
| 111 | else | ||
| 112 | t0= (DES_LONG)(*(cp++)); | ||
| 113 | l--; | ||
| 114 | /* add */ | ||
| 115 | t0+=z0; | ||
| 116 | t0&=0xffffffffL; | ||
| 117 | t1=z1; | ||
| 118 | /* square, well sort of square */ | ||
| 119 | z0=((((t0*t0)&0xffffffffL)+((t1*t1)&0xffffffffL)) | ||
| 120 | &0xffffffffL)%0x7fffffffL; | ||
| 121 | z1=((t0*((t1+NOISE)&0xffffffffL))&0xffffffffL)%0x7fffffffL; | ||
| 122 | } | ||
| 123 | if (lp != NULL) | ||
| 124 | { | ||
| 125 | /* The MIT library assumes that the checksum is | ||
| 126 | * composed of 2*out_count 32 bit ints */ | ||
| 127 | #ifdef _CRAY | ||
| 128 | (*lp).a = z0; | ||
| 129 | (*lp).b = z1; | ||
| 130 | lp++; | ||
| 131 | #else | ||
| 132 | *lp++ = z0; | ||
| 133 | *lp++ = z1; | ||
| 134 | #endif | ||
| 135 | } | ||
| 136 | } | ||
| 137 | return(z0); | ||
| 138 | } | ||
| 139 | |||
diff --git a/src/lib/libcrypto/des/rand_key.c b/src/lib/libcrypto/des/rand_key.c new file mode 100644 index 0000000000..2398165568 --- /dev/null +++ b/src/lib/libcrypto/des/rand_key.c | |||
| @@ -0,0 +1,68 @@ | |||
| 1 | /* crypto/des/rand_key.c */ | ||
| 2 | /* ==================================================================== | ||
| 3 | * Copyright (c) 1998-2000 The OpenSSL Project. All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in | ||
| 14 | * the documentation and/or other materials provided with the | ||
| 15 | * distribution. | ||
| 16 | * | ||
| 17 | * 3. All advertising materials mentioning features or use of this | ||
| 18 | * software must display the following acknowledgment: | ||
| 19 | * "This product includes software developed by the OpenSSL Project | ||
| 20 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
| 21 | * | ||
| 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
| 23 | * endorse or promote products derived from this software without | ||
| 24 | * prior written permission. For written permission, please contact | ||
| 25 | * openssl-core@openssl.org. | ||
| 26 | * | ||
| 27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
| 28 | * nor may "OpenSSL" appear in their names without prior written | ||
| 29 | * permission of the OpenSSL Project. | ||
| 30 | * | ||
| 31 | * 6. Redistributions of any form whatsoever must retain the following | ||
| 32 | * acknowledgment: | ||
| 33 | * "This product includes software developed by the OpenSSL Project | ||
| 34 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
| 35 | * | ||
| 36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
| 37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
| 39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
| 40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
| 43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
| 45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
| 47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 48 | * ==================================================================== | ||
| 49 | * | ||
| 50 | * This product includes cryptographic software written by Eric Young | ||
| 51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
| 52 | * Hudson (tjh@cryptsoft.com). | ||
| 53 | * | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include <openssl/des.h> | ||
| 57 | #include <openssl/rand.h> | ||
| 58 | |||
| 59 | int DES_random_key(DES_cblock *ret) | ||
| 60 | { | ||
| 61 | do | ||
| 62 | { | ||
| 63 | if (RAND_bytes((unsigned char *)ret, sizeof(DES_cblock)) != 1) | ||
| 64 | return (0); | ||
| 65 | } while (DES_is_weak_key(ret)); | ||
| 66 | DES_set_odd_parity(ret); | ||
| 67 | return (1); | ||
| 68 | } | ||
diff --git a/src/lib/libcrypto/des/set_key.c b/src/lib/libcrypto/des/set_key.c new file mode 100644 index 0000000000..a43ef3c881 --- /dev/null +++ b/src/lib/libcrypto/des/set_key.c | |||
| @@ -0,0 +1,407 @@ | |||
| 1 | /* crypto/des/set_key.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 | /* set_key.c v 1.4 eay 24/9/91 | ||
| 60 | * 1.4 Speed up by 400% :-) | ||
| 61 | * 1.3 added register declarations. | ||
| 62 | * 1.2 unrolled make_key_sched a bit more | ||
| 63 | * 1.1 added norm_expand_bits | ||
| 64 | * 1.0 First working version | ||
| 65 | */ | ||
| 66 | #include "des_locl.h" | ||
| 67 | |||
| 68 | OPENSSL_IMPLEMENT_GLOBAL(int,DES_check_key); /* defaults to false */ | ||
| 69 | |||
| 70 | static const unsigned char odd_parity[256]={ | ||
| 71 | 1, 1, 2, 2, 4, 4, 7, 7, 8, 8, 11, 11, 13, 13, 14, 14, | ||
| 72 | 16, 16, 19, 19, 21, 21, 22, 22, 25, 25, 26, 26, 28, 28, 31, 31, | ||
| 73 | 32, 32, 35, 35, 37, 37, 38, 38, 41, 41, 42, 42, 44, 44, 47, 47, | ||
| 74 | 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 59, 59, 61, 61, 62, 62, | ||
| 75 | 64, 64, 67, 67, 69, 69, 70, 70, 73, 73, 74, 74, 76, 76, 79, 79, | ||
| 76 | 81, 81, 82, 82, 84, 84, 87, 87, 88, 88, 91, 91, 93, 93, 94, 94, | ||
| 77 | 97, 97, 98, 98,100,100,103,103,104,104,107,107,109,109,110,110, | ||
| 78 | 112,112,115,115,117,117,118,118,121,121,122,122,124,124,127,127, | ||
| 79 | 128,128,131,131,133,133,134,134,137,137,138,138,140,140,143,143, | ||
| 80 | 145,145,146,146,148,148,151,151,152,152,155,155,157,157,158,158, | ||
| 81 | 161,161,162,162,164,164,167,167,168,168,171,171,173,173,174,174, | ||
| 82 | 176,176,179,179,181,181,182,182,185,185,186,186,188,188,191,191, | ||
| 83 | 193,193,194,194,196,196,199,199,200,200,203,203,205,205,206,206, | ||
| 84 | 208,208,211,211,213,213,214,214,217,217,218,218,220,220,223,223, | ||
| 85 | 224,224,227,227,229,229,230,230,233,233,234,234,236,236,239,239, | ||
| 86 | 241,241,242,242,244,244,247,247,248,248,251,251,253,253,254,254}; | ||
| 87 | |||
| 88 | void DES_set_odd_parity(DES_cblock *key) | ||
| 89 | { | ||
| 90 | unsigned int i; | ||
| 91 | |||
| 92 | for (i=0; i<DES_KEY_SZ; i++) | ||
| 93 | (*key)[i]=odd_parity[(*key)[i]]; | ||
| 94 | } | ||
| 95 | |||
| 96 | int DES_check_key_parity(const_DES_cblock *key) | ||
| 97 | { | ||
| 98 | unsigned int i; | ||
| 99 | |||
| 100 | for (i=0; i<DES_KEY_SZ; i++) | ||
| 101 | { | ||
| 102 | if ((*key)[i] != odd_parity[(*key)[i]]) | ||
| 103 | return(0); | ||
| 104 | } | ||
| 105 | return(1); | ||
| 106 | } | ||
| 107 | |||
| 108 | /* Weak and semi week keys as take from | ||
| 109 | * %A D.W. Davies | ||
| 110 | * %A W.L. Price | ||
| 111 | * %T Security for Computer Networks | ||
| 112 | * %I John Wiley & Sons | ||
| 113 | * %D 1984 | ||
| 114 | * Many thanks to smb@ulysses.att.com (Steven Bellovin) for the reference | ||
| 115 | * (and actual cblock values). | ||
| 116 | */ | ||
| 117 | #define NUM_WEAK_KEY 16 | ||
| 118 | static const DES_cblock weak_keys[NUM_WEAK_KEY]={ | ||
| 119 | /* weak keys */ | ||
| 120 | {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}, | ||
| 121 | {0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE}, | ||
| 122 | {0x1F,0x1F,0x1F,0x1F,0x0E,0x0E,0x0E,0x0E}, | ||
| 123 | {0xE0,0xE0,0xE0,0xE0,0xF1,0xF1,0xF1,0xF1}, | ||
| 124 | /* semi-weak keys */ | ||
| 125 | {0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE}, | ||
| 126 | {0xFE,0x01,0xFE,0x01,0xFE,0x01,0xFE,0x01}, | ||
| 127 | {0x1F,0xE0,0x1F,0xE0,0x0E,0xF1,0x0E,0xF1}, | ||
| 128 | {0xE0,0x1F,0xE0,0x1F,0xF1,0x0E,0xF1,0x0E}, | ||
| 129 | {0x01,0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1}, | ||
| 130 | {0xE0,0x01,0xE0,0x01,0xF1,0x01,0xF1,0x01}, | ||
| 131 | {0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E,0xFE}, | ||
| 132 | {0xFE,0x1F,0xFE,0x1F,0xFE,0x0E,0xFE,0x0E}, | ||
| 133 | {0x01,0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E}, | ||
| 134 | {0x1F,0x01,0x1F,0x01,0x0E,0x01,0x0E,0x01}, | ||
| 135 | {0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1,0xFE}, | ||
| 136 | {0xFE,0xE0,0xFE,0xE0,0xFE,0xF1,0xFE,0xF1}}; | ||
| 137 | |||
| 138 | int DES_is_weak_key(const_DES_cblock *key) | ||
| 139 | { | ||
| 140 | int i; | ||
| 141 | |||
| 142 | for (i=0; i<NUM_WEAK_KEY; i++) | ||
| 143 | /* Added == 0 to comparison, I obviously don't run | ||
| 144 | * this section very often :-(, thanks to | ||
| 145 | * engineering@MorningStar.Com for the fix | ||
| 146 | * eay 93/06/29 | ||
| 147 | * Another problem, I was comparing only the first 4 | ||
| 148 | * bytes, 97/03/18 */ | ||
| 149 | if (memcmp(weak_keys[i],key,sizeof(DES_cblock)) == 0) return(1); | ||
| 150 | return(0); | ||
| 151 | } | ||
| 152 | |||
| 153 | /* NOW DEFINED IN des_local.h | ||
| 154 | * See ecb_encrypt.c for a pseudo description of these macros. | ||
| 155 | * #define PERM_OP(a,b,t,n,m) ((t)=((((a)>>(n))^(b))&(m)),\ | ||
| 156 | * (b)^=(t),\ | ||
| 157 | * (a)=((a)^((t)<<(n)))) | ||
| 158 | */ | ||
| 159 | |||
| 160 | #define HPERM_OP(a,t,n,m) ((t)=((((a)<<(16-(n)))^(a))&(m)),\ | ||
| 161 | (a)=(a)^(t)^(t>>(16-(n)))) | ||
| 162 | |||
| 163 | static const DES_LONG des_skb[8][64]={ | ||
| 164 | { | ||
| 165 | /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ | ||
| 166 | 0x00000000L,0x00000010L,0x20000000L,0x20000010L, | ||
| 167 | 0x00010000L,0x00010010L,0x20010000L,0x20010010L, | ||
| 168 | 0x00000800L,0x00000810L,0x20000800L,0x20000810L, | ||
| 169 | 0x00010800L,0x00010810L,0x20010800L,0x20010810L, | ||
| 170 | 0x00000020L,0x00000030L,0x20000020L,0x20000030L, | ||
| 171 | 0x00010020L,0x00010030L,0x20010020L,0x20010030L, | ||
| 172 | 0x00000820L,0x00000830L,0x20000820L,0x20000830L, | ||
| 173 | 0x00010820L,0x00010830L,0x20010820L,0x20010830L, | ||
| 174 | 0x00080000L,0x00080010L,0x20080000L,0x20080010L, | ||
| 175 | 0x00090000L,0x00090010L,0x20090000L,0x20090010L, | ||
| 176 | 0x00080800L,0x00080810L,0x20080800L,0x20080810L, | ||
| 177 | 0x00090800L,0x00090810L,0x20090800L,0x20090810L, | ||
| 178 | 0x00080020L,0x00080030L,0x20080020L,0x20080030L, | ||
| 179 | 0x00090020L,0x00090030L,0x20090020L,0x20090030L, | ||
| 180 | 0x00080820L,0x00080830L,0x20080820L,0x20080830L, | ||
| 181 | 0x00090820L,0x00090830L,0x20090820L,0x20090830L, | ||
| 182 | },{ | ||
| 183 | /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */ | ||
| 184 | 0x00000000L,0x02000000L,0x00002000L,0x02002000L, | ||
| 185 | 0x00200000L,0x02200000L,0x00202000L,0x02202000L, | ||
| 186 | 0x00000004L,0x02000004L,0x00002004L,0x02002004L, | ||
| 187 | 0x00200004L,0x02200004L,0x00202004L,0x02202004L, | ||
| 188 | 0x00000400L,0x02000400L,0x00002400L,0x02002400L, | ||
| 189 | 0x00200400L,0x02200400L,0x00202400L,0x02202400L, | ||
| 190 | 0x00000404L,0x02000404L,0x00002404L,0x02002404L, | ||
| 191 | 0x00200404L,0x02200404L,0x00202404L,0x02202404L, | ||
| 192 | 0x10000000L,0x12000000L,0x10002000L,0x12002000L, | ||
| 193 | 0x10200000L,0x12200000L,0x10202000L,0x12202000L, | ||
| 194 | 0x10000004L,0x12000004L,0x10002004L,0x12002004L, | ||
| 195 | 0x10200004L,0x12200004L,0x10202004L,0x12202004L, | ||
| 196 | 0x10000400L,0x12000400L,0x10002400L,0x12002400L, | ||
| 197 | 0x10200400L,0x12200400L,0x10202400L,0x12202400L, | ||
| 198 | 0x10000404L,0x12000404L,0x10002404L,0x12002404L, | ||
| 199 | 0x10200404L,0x12200404L,0x10202404L,0x12202404L, | ||
| 200 | },{ | ||
| 201 | /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */ | ||
| 202 | 0x00000000L,0x00000001L,0x00040000L,0x00040001L, | ||
| 203 | 0x01000000L,0x01000001L,0x01040000L,0x01040001L, | ||
| 204 | 0x00000002L,0x00000003L,0x00040002L,0x00040003L, | ||
| 205 | 0x01000002L,0x01000003L,0x01040002L,0x01040003L, | ||
| 206 | 0x00000200L,0x00000201L,0x00040200L,0x00040201L, | ||
| 207 | 0x01000200L,0x01000201L,0x01040200L,0x01040201L, | ||
| 208 | 0x00000202L,0x00000203L,0x00040202L,0x00040203L, | ||
| 209 | 0x01000202L,0x01000203L,0x01040202L,0x01040203L, | ||
| 210 | 0x08000000L,0x08000001L,0x08040000L,0x08040001L, | ||
| 211 | 0x09000000L,0x09000001L,0x09040000L,0x09040001L, | ||
| 212 | 0x08000002L,0x08000003L,0x08040002L,0x08040003L, | ||
| 213 | 0x09000002L,0x09000003L,0x09040002L,0x09040003L, | ||
| 214 | 0x08000200L,0x08000201L,0x08040200L,0x08040201L, | ||
| 215 | 0x09000200L,0x09000201L,0x09040200L,0x09040201L, | ||
| 216 | 0x08000202L,0x08000203L,0x08040202L,0x08040203L, | ||
| 217 | 0x09000202L,0x09000203L,0x09040202L,0x09040203L, | ||
| 218 | },{ | ||
| 219 | /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */ | ||
| 220 | 0x00000000L,0x00100000L,0x00000100L,0x00100100L, | ||
| 221 | 0x00000008L,0x00100008L,0x00000108L,0x00100108L, | ||
| 222 | 0x00001000L,0x00101000L,0x00001100L,0x00101100L, | ||
| 223 | 0x00001008L,0x00101008L,0x00001108L,0x00101108L, | ||
| 224 | 0x04000000L,0x04100000L,0x04000100L,0x04100100L, | ||
| 225 | 0x04000008L,0x04100008L,0x04000108L,0x04100108L, | ||
| 226 | 0x04001000L,0x04101000L,0x04001100L,0x04101100L, | ||
| 227 | 0x04001008L,0x04101008L,0x04001108L,0x04101108L, | ||
| 228 | 0x00020000L,0x00120000L,0x00020100L,0x00120100L, | ||
| 229 | 0x00020008L,0x00120008L,0x00020108L,0x00120108L, | ||
| 230 | 0x00021000L,0x00121000L,0x00021100L,0x00121100L, | ||
| 231 | 0x00021008L,0x00121008L,0x00021108L,0x00121108L, | ||
| 232 | 0x04020000L,0x04120000L,0x04020100L,0x04120100L, | ||
| 233 | 0x04020008L,0x04120008L,0x04020108L,0x04120108L, | ||
| 234 | 0x04021000L,0x04121000L,0x04021100L,0x04121100L, | ||
| 235 | 0x04021008L,0x04121008L,0x04021108L,0x04121108L, | ||
| 236 | },{ | ||
| 237 | /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ | ||
| 238 | 0x00000000L,0x10000000L,0x00010000L,0x10010000L, | ||
| 239 | 0x00000004L,0x10000004L,0x00010004L,0x10010004L, | ||
| 240 | 0x20000000L,0x30000000L,0x20010000L,0x30010000L, | ||
| 241 | 0x20000004L,0x30000004L,0x20010004L,0x30010004L, | ||
| 242 | 0x00100000L,0x10100000L,0x00110000L,0x10110000L, | ||
| 243 | 0x00100004L,0x10100004L,0x00110004L,0x10110004L, | ||
| 244 | 0x20100000L,0x30100000L,0x20110000L,0x30110000L, | ||
| 245 | 0x20100004L,0x30100004L,0x20110004L,0x30110004L, | ||
| 246 | 0x00001000L,0x10001000L,0x00011000L,0x10011000L, | ||
| 247 | 0x00001004L,0x10001004L,0x00011004L,0x10011004L, | ||
| 248 | 0x20001000L,0x30001000L,0x20011000L,0x30011000L, | ||
| 249 | 0x20001004L,0x30001004L,0x20011004L,0x30011004L, | ||
| 250 | 0x00101000L,0x10101000L,0x00111000L,0x10111000L, | ||
| 251 | 0x00101004L,0x10101004L,0x00111004L,0x10111004L, | ||
| 252 | 0x20101000L,0x30101000L,0x20111000L,0x30111000L, | ||
| 253 | 0x20101004L,0x30101004L,0x20111004L,0x30111004L, | ||
| 254 | },{ | ||
| 255 | /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */ | ||
| 256 | 0x00000000L,0x08000000L,0x00000008L,0x08000008L, | ||
| 257 | 0x00000400L,0x08000400L,0x00000408L,0x08000408L, | ||
| 258 | 0x00020000L,0x08020000L,0x00020008L,0x08020008L, | ||
| 259 | 0x00020400L,0x08020400L,0x00020408L,0x08020408L, | ||
| 260 | 0x00000001L,0x08000001L,0x00000009L,0x08000009L, | ||
| 261 | 0x00000401L,0x08000401L,0x00000409L,0x08000409L, | ||
| 262 | 0x00020001L,0x08020001L,0x00020009L,0x08020009L, | ||
| 263 | 0x00020401L,0x08020401L,0x00020409L,0x08020409L, | ||
| 264 | 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L, | ||
| 265 | 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L, | ||
| 266 | 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L, | ||
| 267 | 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L, | ||
| 268 | 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L, | ||
| 269 | 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L, | ||
| 270 | 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L, | ||
| 271 | 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L, | ||
| 272 | },{ | ||
| 273 | /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */ | ||
| 274 | 0x00000000L,0x00000100L,0x00080000L,0x00080100L, | ||
| 275 | 0x01000000L,0x01000100L,0x01080000L,0x01080100L, | ||
| 276 | 0x00000010L,0x00000110L,0x00080010L,0x00080110L, | ||
| 277 | 0x01000010L,0x01000110L,0x01080010L,0x01080110L, | ||
| 278 | 0x00200000L,0x00200100L,0x00280000L,0x00280100L, | ||
| 279 | 0x01200000L,0x01200100L,0x01280000L,0x01280100L, | ||
| 280 | 0x00200010L,0x00200110L,0x00280010L,0x00280110L, | ||
| 281 | 0x01200010L,0x01200110L,0x01280010L,0x01280110L, | ||
| 282 | 0x00000200L,0x00000300L,0x00080200L,0x00080300L, | ||
| 283 | 0x01000200L,0x01000300L,0x01080200L,0x01080300L, | ||
| 284 | 0x00000210L,0x00000310L,0x00080210L,0x00080310L, | ||
| 285 | 0x01000210L,0x01000310L,0x01080210L,0x01080310L, | ||
| 286 | 0x00200200L,0x00200300L,0x00280200L,0x00280300L, | ||
| 287 | 0x01200200L,0x01200300L,0x01280200L,0x01280300L, | ||
| 288 | 0x00200210L,0x00200310L,0x00280210L,0x00280310L, | ||
| 289 | 0x01200210L,0x01200310L,0x01280210L,0x01280310L, | ||
| 290 | },{ | ||
| 291 | /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */ | ||
| 292 | 0x00000000L,0x04000000L,0x00040000L,0x04040000L, | ||
| 293 | 0x00000002L,0x04000002L,0x00040002L,0x04040002L, | ||
| 294 | 0x00002000L,0x04002000L,0x00042000L,0x04042000L, | ||
| 295 | 0x00002002L,0x04002002L,0x00042002L,0x04042002L, | ||
| 296 | 0x00000020L,0x04000020L,0x00040020L,0x04040020L, | ||
| 297 | 0x00000022L,0x04000022L,0x00040022L,0x04040022L, | ||
| 298 | 0x00002020L,0x04002020L,0x00042020L,0x04042020L, | ||
| 299 | 0x00002022L,0x04002022L,0x00042022L,0x04042022L, | ||
| 300 | 0x00000800L,0x04000800L,0x00040800L,0x04040800L, | ||
| 301 | 0x00000802L,0x04000802L,0x00040802L,0x04040802L, | ||
| 302 | 0x00002800L,0x04002800L,0x00042800L,0x04042800L, | ||
| 303 | 0x00002802L,0x04002802L,0x00042802L,0x04042802L, | ||
| 304 | 0x00000820L,0x04000820L,0x00040820L,0x04040820L, | ||
| 305 | 0x00000822L,0x04000822L,0x00040822L,0x04040822L, | ||
| 306 | 0x00002820L,0x04002820L,0x00042820L,0x04042820L, | ||
| 307 | 0x00002822L,0x04002822L,0x00042822L,0x04042822L, | ||
| 308 | }}; | ||
| 309 | |||
| 310 | int DES_set_key(const_DES_cblock *key, DES_key_schedule *schedule) | ||
| 311 | { | ||
| 312 | if (DES_check_key) | ||
| 313 | { | ||
| 314 | return DES_set_key_checked(key, schedule); | ||
| 315 | } | ||
| 316 | else | ||
| 317 | { | ||
| 318 | DES_set_key_unchecked(key, schedule); | ||
| 319 | return 0; | ||
| 320 | } | ||
| 321 | } | ||
| 322 | |||
| 323 | /* return 0 if key parity is odd (correct), | ||
| 324 | * return -1 if key parity error, | ||
| 325 | * return -2 if illegal weak key. | ||
| 326 | */ | ||
| 327 | int DES_set_key_checked(const_DES_cblock *key, DES_key_schedule *schedule) | ||
| 328 | { | ||
| 329 | if (!DES_check_key_parity(key)) | ||
| 330 | return(-1); | ||
| 331 | if (DES_is_weak_key(key)) | ||
| 332 | return(-2); | ||
| 333 | DES_set_key_unchecked(key, schedule); | ||
| 334 | return 0; | ||
| 335 | } | ||
| 336 | |||
| 337 | void DES_set_key_unchecked(const_DES_cblock *key, DES_key_schedule *schedule) | ||
| 338 | { | ||
| 339 | static int shifts2[16]={0,0,1,1,1,1,1,1,0,1,1,1,1,1,1,0}; | ||
| 340 | register DES_LONG c,d,t,s,t2; | ||
| 341 | register const unsigned char *in; | ||
| 342 | register DES_LONG *k; | ||
| 343 | register int i; | ||
| 344 | |||
| 345 | #ifdef OPENBSD_DEV_CRYPTO | ||
| 346 | memcpy(schedule->key,key,sizeof schedule->key); | ||
| 347 | schedule->session=NULL; | ||
| 348 | #endif | ||
| 349 | k = &schedule->ks->deslong[0]; | ||
| 350 | in = &(*key)[0]; | ||
| 351 | |||
| 352 | c2l(in,c); | ||
| 353 | c2l(in,d); | ||
| 354 | |||
| 355 | /* do PC1 in 47 simple operations :-) | ||
| 356 | * Thanks to John Fletcher (john_fletcher@lccmail.ocf.llnl.gov) | ||
| 357 | * for the inspiration. :-) */ | ||
| 358 | PERM_OP (d,c,t,4,0x0f0f0f0fL); | ||
| 359 | HPERM_OP(c,t,-2,0xcccc0000L); | ||
| 360 | HPERM_OP(d,t,-2,0xcccc0000L); | ||
| 361 | PERM_OP (d,c,t,1,0x55555555L); | ||
| 362 | PERM_OP (c,d,t,8,0x00ff00ffL); | ||
| 363 | PERM_OP (d,c,t,1,0x55555555L); | ||
| 364 | d= (((d&0x000000ffL)<<16L)| (d&0x0000ff00L) | | ||
| 365 | ((d&0x00ff0000L)>>16L)|((c&0xf0000000L)>>4L)); | ||
| 366 | c&=0x0fffffffL; | ||
| 367 | |||
| 368 | for (i=0; i<ITERATIONS; i++) | ||
| 369 | { | ||
| 370 | if (shifts2[i]) | ||
| 371 | { c=((c>>2L)|(c<<26L)); d=((d>>2L)|(d<<26L)); } | ||
| 372 | else | ||
| 373 | { c=((c>>1L)|(c<<27L)); d=((d>>1L)|(d<<27L)); } | ||
| 374 | c&=0x0fffffffL; | ||
| 375 | d&=0x0fffffffL; | ||
| 376 | /* could be a few less shifts but I am to lazy at this | ||
| 377 | * point in time to investigate */ | ||
| 378 | s= des_skb[0][ (c )&0x3f ]| | ||
| 379 | des_skb[1][((c>> 6L)&0x03)|((c>> 7L)&0x3c)]| | ||
| 380 | des_skb[2][((c>>13L)&0x0f)|((c>>14L)&0x30)]| | ||
| 381 | des_skb[3][((c>>20L)&0x01)|((c>>21L)&0x06) | | ||
| 382 | ((c>>22L)&0x38)]; | ||
| 383 | t= des_skb[4][ (d )&0x3f ]| | ||
| 384 | des_skb[5][((d>> 7L)&0x03)|((d>> 8L)&0x3c)]| | ||
| 385 | des_skb[6][ (d>>15L)&0x3f ]| | ||
| 386 | des_skb[7][((d>>21L)&0x0f)|((d>>22L)&0x30)]; | ||
| 387 | |||
| 388 | /* table contained 0213 4657 */ | ||
| 389 | t2=((t<<16L)|(s&0x0000ffffL))&0xffffffffL; | ||
| 390 | *(k++)=ROTATE(t2,30)&0xffffffffL; | ||
| 391 | |||
| 392 | t2=((s>>16L)|(t&0xffff0000L)); | ||
| 393 | *(k++)=ROTATE(t2,26)&0xffffffffL; | ||
| 394 | } | ||
| 395 | } | ||
| 396 | |||
| 397 | int DES_key_sched(const_DES_cblock *key, DES_key_schedule *schedule) | ||
| 398 | { | ||
| 399 | return(DES_set_key(key,schedule)); | ||
| 400 | } | ||
| 401 | /* | ||
| 402 | #undef des_fixup_key_parity | ||
| 403 | void des_fixup_key_parity(des_cblock *key) | ||
| 404 | { | ||
| 405 | des_set_odd_parity(key); | ||
| 406 | } | ||
| 407 | */ | ||
diff --git a/src/lib/libcrypto/des/spr.h b/src/lib/libcrypto/des/spr.h new file mode 100644 index 0000000000..b91936a5a5 --- /dev/null +++ b/src/lib/libcrypto/des/spr.h | |||
| @@ -0,0 +1,204 @@ | |||
| 1 | /* crypto/des/spr.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 | OPENSSL_GLOBAL const DES_LONG DES_SPtrans[8][64]={ | ||
| 60 | { | ||
| 61 | /* nibble 0 */ | ||
| 62 | 0x02080800L, 0x00080000L, 0x02000002L, 0x02080802L, | ||
| 63 | 0x02000000L, 0x00080802L, 0x00080002L, 0x02000002L, | ||
| 64 | 0x00080802L, 0x02080800L, 0x02080000L, 0x00000802L, | ||
| 65 | 0x02000802L, 0x02000000L, 0x00000000L, 0x00080002L, | ||
| 66 | 0x00080000L, 0x00000002L, 0x02000800L, 0x00080800L, | ||
| 67 | 0x02080802L, 0x02080000L, 0x00000802L, 0x02000800L, | ||
| 68 | 0x00000002L, 0x00000800L, 0x00080800L, 0x02080002L, | ||
| 69 | 0x00000800L, 0x02000802L, 0x02080002L, 0x00000000L, | ||
| 70 | 0x00000000L, 0x02080802L, 0x02000800L, 0x00080002L, | ||
| 71 | 0x02080800L, 0x00080000L, 0x00000802L, 0x02000800L, | ||
| 72 | 0x02080002L, 0x00000800L, 0x00080800L, 0x02000002L, | ||
| 73 | 0x00080802L, 0x00000002L, 0x02000002L, 0x02080000L, | ||
| 74 | 0x02080802L, 0x00080800L, 0x02080000L, 0x02000802L, | ||
| 75 | 0x02000000L, 0x00000802L, 0x00080002L, 0x00000000L, | ||
| 76 | 0x00080000L, 0x02000000L, 0x02000802L, 0x02080800L, | ||
| 77 | 0x00000002L, 0x02080002L, 0x00000800L, 0x00080802L, | ||
| 78 | },{ | ||
| 79 | /* nibble 1 */ | ||
| 80 | 0x40108010L, 0x00000000L, 0x00108000L, 0x40100000L, | ||
| 81 | 0x40000010L, 0x00008010L, 0x40008000L, 0x00108000L, | ||
| 82 | 0x00008000L, 0x40100010L, 0x00000010L, 0x40008000L, | ||
| 83 | 0x00100010L, 0x40108000L, 0x40100000L, 0x00000010L, | ||
| 84 | 0x00100000L, 0x40008010L, 0x40100010L, 0x00008000L, | ||
| 85 | 0x00108010L, 0x40000000L, 0x00000000L, 0x00100010L, | ||
| 86 | 0x40008010L, 0x00108010L, 0x40108000L, 0x40000010L, | ||
| 87 | 0x40000000L, 0x00100000L, 0x00008010L, 0x40108010L, | ||
| 88 | 0x00100010L, 0x40108000L, 0x40008000L, 0x00108010L, | ||
| 89 | 0x40108010L, 0x00100010L, 0x40000010L, 0x00000000L, | ||
| 90 | 0x40000000L, 0x00008010L, 0x00100000L, 0x40100010L, | ||
| 91 | 0x00008000L, 0x40000000L, 0x00108010L, 0x40008010L, | ||
| 92 | 0x40108000L, 0x00008000L, 0x00000000L, 0x40000010L, | ||
| 93 | 0x00000010L, 0x40108010L, 0x00108000L, 0x40100000L, | ||
| 94 | 0x40100010L, 0x00100000L, 0x00008010L, 0x40008000L, | ||
| 95 | 0x40008010L, 0x00000010L, 0x40100000L, 0x00108000L, | ||
| 96 | },{ | ||
| 97 | /* nibble 2 */ | ||
| 98 | 0x04000001L, 0x04040100L, 0x00000100L, 0x04000101L, | ||
| 99 | 0x00040001L, 0x04000000L, 0x04000101L, 0x00040100L, | ||
| 100 | 0x04000100L, 0x00040000L, 0x04040000L, 0x00000001L, | ||
| 101 | 0x04040101L, 0x00000101L, 0x00000001L, 0x04040001L, | ||
| 102 | 0x00000000L, 0x00040001L, 0x04040100L, 0x00000100L, | ||
| 103 | 0x00000101L, 0x04040101L, 0x00040000L, 0x04000001L, | ||
| 104 | 0x04040001L, 0x04000100L, 0x00040101L, 0x04040000L, | ||
| 105 | 0x00040100L, 0x00000000L, 0x04000000L, 0x00040101L, | ||
| 106 | 0x04040100L, 0x00000100L, 0x00000001L, 0x00040000L, | ||
| 107 | 0x00000101L, 0x00040001L, 0x04040000L, 0x04000101L, | ||
| 108 | 0x00000000L, 0x04040100L, 0x00040100L, 0x04040001L, | ||
| 109 | 0x00040001L, 0x04000000L, 0x04040101L, 0x00000001L, | ||
| 110 | 0x00040101L, 0x04000001L, 0x04000000L, 0x04040101L, | ||
| 111 | 0x00040000L, 0x04000100L, 0x04000101L, 0x00040100L, | ||
| 112 | 0x04000100L, 0x00000000L, 0x04040001L, 0x00000101L, | ||
| 113 | 0x04000001L, 0x00040101L, 0x00000100L, 0x04040000L, | ||
| 114 | },{ | ||
| 115 | /* nibble 3 */ | ||
| 116 | 0x00401008L, 0x10001000L, 0x00000008L, 0x10401008L, | ||
| 117 | 0x00000000L, 0x10400000L, 0x10001008L, 0x00400008L, | ||
| 118 | 0x10401000L, 0x10000008L, 0x10000000L, 0x00001008L, | ||
| 119 | 0x10000008L, 0x00401008L, 0x00400000L, 0x10000000L, | ||
| 120 | 0x10400008L, 0x00401000L, 0x00001000L, 0x00000008L, | ||
| 121 | 0x00401000L, 0x10001008L, 0x10400000L, 0x00001000L, | ||
| 122 | 0x00001008L, 0x00000000L, 0x00400008L, 0x10401000L, | ||
| 123 | 0x10001000L, 0x10400008L, 0x10401008L, 0x00400000L, | ||
| 124 | 0x10400008L, 0x00001008L, 0x00400000L, 0x10000008L, | ||
| 125 | 0x00401000L, 0x10001000L, 0x00000008L, 0x10400000L, | ||
| 126 | 0x10001008L, 0x00000000L, 0x00001000L, 0x00400008L, | ||
| 127 | 0x00000000L, 0x10400008L, 0x10401000L, 0x00001000L, | ||
| 128 | 0x10000000L, 0x10401008L, 0x00401008L, 0x00400000L, | ||
| 129 | 0x10401008L, 0x00000008L, 0x10001000L, 0x00401008L, | ||
| 130 | 0x00400008L, 0x00401000L, 0x10400000L, 0x10001008L, | ||
| 131 | 0x00001008L, 0x10000000L, 0x10000008L, 0x10401000L, | ||
| 132 | },{ | ||
| 133 | /* nibble 4 */ | ||
| 134 | 0x08000000L, 0x00010000L, 0x00000400L, 0x08010420L, | ||
| 135 | 0x08010020L, 0x08000400L, 0x00010420L, 0x08010000L, | ||
| 136 | 0x00010000L, 0x00000020L, 0x08000020L, 0x00010400L, | ||
| 137 | 0x08000420L, 0x08010020L, 0x08010400L, 0x00000000L, | ||
| 138 | 0x00010400L, 0x08000000L, 0x00010020L, 0x00000420L, | ||
| 139 | 0x08000400L, 0x00010420L, 0x00000000L, 0x08000020L, | ||
| 140 | 0x00000020L, 0x08000420L, 0x08010420L, 0x00010020L, | ||
| 141 | 0x08010000L, 0x00000400L, 0x00000420L, 0x08010400L, | ||
| 142 | 0x08010400L, 0x08000420L, 0x00010020L, 0x08010000L, | ||
| 143 | 0x00010000L, 0x00000020L, 0x08000020L, 0x08000400L, | ||
| 144 | 0x08000000L, 0x00010400L, 0x08010420L, 0x00000000L, | ||
| 145 | 0x00010420L, 0x08000000L, 0x00000400L, 0x00010020L, | ||
| 146 | 0x08000420L, 0x00000400L, 0x00000000L, 0x08010420L, | ||
| 147 | 0x08010020L, 0x08010400L, 0x00000420L, 0x00010000L, | ||
| 148 | 0x00010400L, 0x08010020L, 0x08000400L, 0x00000420L, | ||
| 149 | 0x00000020L, 0x00010420L, 0x08010000L, 0x08000020L, | ||
| 150 | },{ | ||
| 151 | /* nibble 5 */ | ||
| 152 | 0x80000040L, 0x00200040L, 0x00000000L, 0x80202000L, | ||
| 153 | 0x00200040L, 0x00002000L, 0x80002040L, 0x00200000L, | ||
| 154 | 0x00002040L, 0x80202040L, 0x00202000L, 0x80000000L, | ||
| 155 | 0x80002000L, 0x80000040L, 0x80200000L, 0x00202040L, | ||
| 156 | 0x00200000L, 0x80002040L, 0x80200040L, 0x00000000L, | ||
| 157 | 0x00002000L, 0x00000040L, 0x80202000L, 0x80200040L, | ||
| 158 | 0x80202040L, 0x80200000L, 0x80000000L, 0x00002040L, | ||
| 159 | 0x00000040L, 0x00202000L, 0x00202040L, 0x80002000L, | ||
| 160 | 0x00002040L, 0x80000000L, 0x80002000L, 0x00202040L, | ||
| 161 | 0x80202000L, 0x00200040L, 0x00000000L, 0x80002000L, | ||
| 162 | 0x80000000L, 0x00002000L, 0x80200040L, 0x00200000L, | ||
| 163 | 0x00200040L, 0x80202040L, 0x00202000L, 0x00000040L, | ||
| 164 | 0x80202040L, 0x00202000L, 0x00200000L, 0x80002040L, | ||
| 165 | 0x80000040L, 0x80200000L, 0x00202040L, 0x00000000L, | ||
| 166 | 0x00002000L, 0x80000040L, 0x80002040L, 0x80202000L, | ||
| 167 | 0x80200000L, 0x00002040L, 0x00000040L, 0x80200040L, | ||
| 168 | },{ | ||
| 169 | /* nibble 6 */ | ||
| 170 | 0x00004000L, 0x00000200L, 0x01000200L, 0x01000004L, | ||
| 171 | 0x01004204L, 0x00004004L, 0x00004200L, 0x00000000L, | ||
| 172 | 0x01000000L, 0x01000204L, 0x00000204L, 0x01004000L, | ||
| 173 | 0x00000004L, 0x01004200L, 0x01004000L, 0x00000204L, | ||
| 174 | 0x01000204L, 0x00004000L, 0x00004004L, 0x01004204L, | ||
| 175 | 0x00000000L, 0x01000200L, 0x01000004L, 0x00004200L, | ||
| 176 | 0x01004004L, 0x00004204L, 0x01004200L, 0x00000004L, | ||
| 177 | 0x00004204L, 0x01004004L, 0x00000200L, 0x01000000L, | ||
| 178 | 0x00004204L, 0x01004000L, 0x01004004L, 0x00000204L, | ||
| 179 | 0x00004000L, 0x00000200L, 0x01000000L, 0x01004004L, | ||
| 180 | 0x01000204L, 0x00004204L, 0x00004200L, 0x00000000L, | ||
| 181 | 0x00000200L, 0x01000004L, 0x00000004L, 0x01000200L, | ||
| 182 | 0x00000000L, 0x01000204L, 0x01000200L, 0x00004200L, | ||
| 183 | 0x00000204L, 0x00004000L, 0x01004204L, 0x01000000L, | ||
| 184 | 0x01004200L, 0x00000004L, 0x00004004L, 0x01004204L, | ||
| 185 | 0x01000004L, 0x01004200L, 0x01004000L, 0x00004004L, | ||
| 186 | },{ | ||
| 187 | /* nibble 7 */ | ||
| 188 | 0x20800080L, 0x20820000L, 0x00020080L, 0x00000000L, | ||
| 189 | 0x20020000L, 0x00800080L, 0x20800000L, 0x20820080L, | ||
| 190 | 0x00000080L, 0x20000000L, 0x00820000L, 0x00020080L, | ||
| 191 | 0x00820080L, 0x20020080L, 0x20000080L, 0x20800000L, | ||
| 192 | 0x00020000L, 0x00820080L, 0x00800080L, 0x20020000L, | ||
| 193 | 0x20820080L, 0x20000080L, 0x00000000L, 0x00820000L, | ||
| 194 | 0x20000000L, 0x00800000L, 0x20020080L, 0x20800080L, | ||
| 195 | 0x00800000L, 0x00020000L, 0x20820000L, 0x00000080L, | ||
| 196 | 0x00800000L, 0x00020000L, 0x20000080L, 0x20820080L, | ||
| 197 | 0x00020080L, 0x20000000L, 0x00000000L, 0x00820000L, | ||
| 198 | 0x20800080L, 0x20020080L, 0x20020000L, 0x00800080L, | ||
| 199 | 0x20820000L, 0x00000080L, 0x00800080L, 0x20020000L, | ||
| 200 | 0x20820080L, 0x00800000L, 0x20800000L, 0x20000080L, | ||
| 201 | 0x00820000L, 0x00020080L, 0x20020080L, 0x20800000L, | ||
| 202 | 0x00000080L, 0x20820000L, 0x00820080L, 0x00000000L, | ||
| 203 | 0x20000000L, 0x20800080L, 0x00020000L, 0x00820080L, | ||
| 204 | }}; | ||
diff --git a/src/lib/libcrypto/des/str2key.c b/src/lib/libcrypto/des/str2key.c new file mode 100644 index 0000000000..9c2054bda6 --- /dev/null +++ b/src/lib/libcrypto/des/str2key.c | |||
| @@ -0,0 +1,174 @@ | |||
| 1 | /* crypto/des/str2key.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 "des_locl.h" | ||
| 60 | #include <openssl/crypto.h> | ||
| 61 | |||
| 62 | void DES_string_to_key(const char *str, DES_cblock *key) | ||
| 63 | { | ||
| 64 | DES_key_schedule ks; | ||
| 65 | int i,length; | ||
| 66 | register unsigned char j; | ||
| 67 | |||
| 68 | memset(key,0,8); | ||
| 69 | length=strlen(str); | ||
| 70 | #ifdef OLD_STR_TO_KEY | ||
| 71 | for (i=0; i<length; i++) | ||
| 72 | (*key)[i%8]^=(str[i]<<1); | ||
| 73 | #else /* MIT COMPATIBLE */ | ||
| 74 | for (i=0; i<length; i++) | ||
| 75 | { | ||
| 76 | j=str[i]; | ||
| 77 | if ((i%16) < 8) | ||
| 78 | (*key)[i%8]^=(j<<1); | ||
| 79 | else | ||
| 80 | { | ||
| 81 | /* Reverse the bit order 05/05/92 eay */ | ||
| 82 | j=((j<<4)&0xf0)|((j>>4)&0x0f); | ||
| 83 | j=((j<<2)&0xcc)|((j>>2)&0x33); | ||
| 84 | j=((j<<1)&0xaa)|((j>>1)&0x55); | ||
| 85 | (*key)[7-(i%8)]^=j; | ||
| 86 | } | ||
| 87 | } | ||
| 88 | #endif | ||
| 89 | DES_set_odd_parity(key); | ||
| 90 | #ifdef EXPERIMENTAL_STR_TO_STRONG_KEY | ||
| 91 | if(DES_is_weak_key(key)) | ||
| 92 | (*key)[7] ^= 0xF0; | ||
| 93 | DES_set_key(key,&ks); | ||
| 94 | #else | ||
| 95 | DES_set_key_unchecked(key,&ks); | ||
| 96 | #endif | ||
| 97 | DES_cbc_cksum((const unsigned char*)str,key,length,&ks,key); | ||
| 98 | OPENSSL_cleanse(&ks,sizeof(ks)); | ||
| 99 | DES_set_odd_parity(key); | ||
| 100 | } | ||
| 101 | |||
| 102 | void DES_string_to_2keys(const char *str, DES_cblock *key1, DES_cblock *key2) | ||
| 103 | { | ||
| 104 | DES_key_schedule ks; | ||
| 105 | int i,length; | ||
| 106 | register unsigned char j; | ||
| 107 | |||
| 108 | memset(key1,0,8); | ||
| 109 | memset(key2,0,8); | ||
| 110 | length=strlen(str); | ||
| 111 | #ifdef OLD_STR_TO_KEY | ||
| 112 | if (length <= 8) | ||
| 113 | { | ||
| 114 | for (i=0; i<length; i++) | ||
| 115 | { | ||
| 116 | (*key2)[i]=(*key1)[i]=(str[i]<<1); | ||
| 117 | } | ||
| 118 | } | ||
| 119 | else | ||
| 120 | { | ||
| 121 | for (i=0; i<length; i++) | ||
| 122 | { | ||
| 123 | if ((i/8)&1) | ||
| 124 | (*key2)[i%8]^=(str[i]<<1); | ||
| 125 | else | ||
| 126 | (*key1)[i%8]^=(str[i]<<1); | ||
| 127 | } | ||
| 128 | } | ||
| 129 | #else /* MIT COMPATIBLE */ | ||
| 130 | for (i=0; i<length; i++) | ||
| 131 | { | ||
| 132 | j=str[i]; | ||
| 133 | if ((i%32) < 16) | ||
| 134 | { | ||
| 135 | if ((i%16) < 8) | ||
| 136 | (*key1)[i%8]^=(j<<1); | ||
| 137 | else | ||
| 138 | (*key2)[i%8]^=(j<<1); | ||
| 139 | } | ||
| 140 | else | ||
| 141 | { | ||
| 142 | j=((j<<4)&0xf0)|((j>>4)&0x0f); | ||
| 143 | j=((j<<2)&0xcc)|((j>>2)&0x33); | ||
| 144 | j=((j<<1)&0xaa)|((j>>1)&0x55); | ||
| 145 | if ((i%16) < 8) | ||
| 146 | (*key1)[7-(i%8)]^=j; | ||
| 147 | else | ||
| 148 | (*key2)[7-(i%8)]^=j; | ||
| 149 | } | ||
| 150 | } | ||
| 151 | if (length <= 8) memcpy(key2,key1,8); | ||
| 152 | #endif | ||
| 153 | DES_set_odd_parity(key1); | ||
| 154 | DES_set_odd_parity(key2); | ||
| 155 | #ifdef EXPERIMENTAL_STR_TO_STRONG_KEY | ||
| 156 | if(DES_is_weak_key(key1)) | ||
| 157 | (*key1)[7] ^= 0xF0; | ||
| 158 | DES_set_key(key1,&ks); | ||
| 159 | #else | ||
| 160 | DES_set_key_unchecked(key1,&ks); | ||
| 161 | #endif | ||
| 162 | DES_cbc_cksum((const unsigned char*)str,key1,length,&ks,key1); | ||
| 163 | #ifdef EXPERIMENTAL_STR_TO_STRONG_KEY | ||
| 164 | if(DES_is_weak_key(key2)) | ||
| 165 | (*key2)[7] ^= 0xF0; | ||
| 166 | DES_set_key(key2,&ks); | ||
| 167 | #else | ||
| 168 | DES_set_key_unchecked(key2,&ks); | ||
| 169 | #endif | ||
| 170 | DES_cbc_cksum((const unsigned char*)str,key2,length,&ks,key2); | ||
| 171 | OPENSSL_cleanse(&ks,sizeof(ks)); | ||
| 172 | DES_set_odd_parity(key1); | ||
| 173 | DES_set_odd_parity(key2); | ||
| 174 | } | ||
diff --git a/src/lib/libcrypto/des/times/usparc.cc b/src/lib/libcrypto/des/times/usparc.cc index f6ec8e8831..0864285ef6 100644 --- a/src/lib/libcrypto/des/times/usparc.cc +++ b/src/lib/libcrypto/des/times/usparc.cc | |||
| @@ -2,7 +2,7 @@ solaris 2.5.1 usparc 167mhz?? - SC4.0 cc -fast -Xa -xO5 | |||
| 2 | 2 | ||
| 3 | For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts' | 3 | For the ultra sparc, SunC 4.0 cc -fast -Xa -xO5, running 'des_opts' |
| 4 | gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s. | 4 | gives a speed of 475,000 des/s while 'speed' gives 417,000 des/s. |
| 5 | I belive the difference is tied up in optimisation that the compiler | 5 | I believe the difference is tied up in optimisation that the compiler |
| 6 | is able to perform when the code is 'inlined'. For 'speed', the DES | 6 | is able to perform when the code is 'inlined'. For 'speed', the DES |
| 7 | routines are being linked from a library. I'll record the higher | 7 | routines are being linked from a library. I'll record the higher |
| 8 | speed since if performance is everything, you can always inline | 8 | speed since if performance is everything, you can always inline |
diff --git a/src/lib/libcrypto/des/xcbc_enc.c b/src/lib/libcrypto/des/xcbc_enc.c new file mode 100644 index 0000000000..dc0c761b71 --- /dev/null +++ b/src/lib/libcrypto/des/xcbc_enc.c | |||
| @@ -0,0 +1,197 @@ | |||
| 1 | /* crypto/des/xcbc_enc.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 "des_locl.h" | ||
| 60 | |||
| 61 | /* RSA's DESX */ | ||
| 62 | |||
| 63 | #if 0 /* broken code, preserved just in case anyone specifically looks for this */ | ||
| 64 | static unsigned char desx_white_in2out[256]={ | ||
| 65 | 0xBD,0x56,0xEA,0xF2,0xA2,0xF1,0xAC,0x2A,0xB0,0x93,0xD1,0x9C,0x1B,0x33,0xFD,0xD0, | ||
| 66 | 0x30,0x04,0xB6,0xDC,0x7D,0xDF,0x32,0x4B,0xF7,0xCB,0x45,0x9B,0x31,0xBB,0x21,0x5A, | ||
| 67 | 0x41,0x9F,0xE1,0xD9,0x4A,0x4D,0x9E,0xDA,0xA0,0x68,0x2C,0xC3,0x27,0x5F,0x80,0x36, | ||
| 68 | 0x3E,0xEE,0xFB,0x95,0x1A,0xFE,0xCE,0xA8,0x34,0xA9,0x13,0xF0,0xA6,0x3F,0xD8,0x0C, | ||
| 69 | 0x78,0x24,0xAF,0x23,0x52,0xC1,0x67,0x17,0xF5,0x66,0x90,0xE7,0xE8,0x07,0xB8,0x60, | ||
| 70 | 0x48,0xE6,0x1E,0x53,0xF3,0x92,0xA4,0x72,0x8C,0x08,0x15,0x6E,0x86,0x00,0x84,0xFA, | ||
| 71 | 0xF4,0x7F,0x8A,0x42,0x19,0xF6,0xDB,0xCD,0x14,0x8D,0x50,0x12,0xBA,0x3C,0x06,0x4E, | ||
| 72 | 0xEC,0xB3,0x35,0x11,0xA1,0x88,0x8E,0x2B,0x94,0x99,0xB7,0x71,0x74,0xD3,0xE4,0xBF, | ||
| 73 | 0x3A,0xDE,0x96,0x0E,0xBC,0x0A,0xED,0x77,0xFC,0x37,0x6B,0x03,0x79,0x89,0x62,0xC6, | ||
| 74 | 0xD7,0xC0,0xD2,0x7C,0x6A,0x8B,0x22,0xA3,0x5B,0x05,0x5D,0x02,0x75,0xD5,0x61,0xE3, | ||
| 75 | 0x18,0x8F,0x55,0x51,0xAD,0x1F,0x0B,0x5E,0x85,0xE5,0xC2,0x57,0x63,0xCA,0x3D,0x6C, | ||
| 76 | 0xB4,0xC5,0xCC,0x70,0xB2,0x91,0x59,0x0D,0x47,0x20,0xC8,0x4F,0x58,0xE0,0x01,0xE2, | ||
| 77 | 0x16,0x38,0xC4,0x6F,0x3B,0x0F,0x65,0x46,0xBE,0x7E,0x2D,0x7B,0x82,0xF9,0x40,0xB5, | ||
| 78 | 0x1D,0x73,0xF8,0xEB,0x26,0xC7,0x87,0x97,0x25,0x54,0xB1,0x28,0xAA,0x98,0x9D,0xA5, | ||
| 79 | 0x64,0x6D,0x7A,0xD4,0x10,0x81,0x44,0xEF,0x49,0xD6,0xAE,0x2E,0xDD,0x76,0x5C,0x2F, | ||
| 80 | 0xA7,0x1C,0xC9,0x09,0x69,0x9A,0x83,0xCF,0x29,0x39,0xB9,0xE9,0x4C,0xFF,0x43,0xAB, | ||
| 81 | }; | ||
| 82 | |||
| 83 | void DES_xwhite_in2out(const_DES_cblock *des_key, const_DES_cblock *in_white, | ||
| 84 | DES_cblock *out_white) | ||
| 85 | { | ||
| 86 | int out0,out1; | ||
| 87 | int i; | ||
| 88 | const unsigned char *key = &(*des_key)[0]; | ||
| 89 | const unsigned char *in = &(*in_white)[0]; | ||
| 90 | unsigned char *out = &(*out_white)[0]; | ||
| 91 | |||
| 92 | out[0]=out[1]=out[2]=out[3]=out[4]=out[5]=out[6]=out[7]=0; | ||
| 93 | out0=out1=0; | ||
| 94 | for (i=0; i<8; i++) | ||
| 95 | { | ||
| 96 | out[i]=key[i]^desx_white_in2out[out0^out1]; | ||
| 97 | out0=out1; | ||
| 98 | out1=(int)out[i&0x07]; | ||
| 99 | } | ||
| 100 | |||
| 101 | out0=out[0]; | ||
| 102 | out1=out[i]; /* BUG: out-of-bounds read */ | ||
| 103 | for (i=0; i<8; i++) | ||
| 104 | { | ||
| 105 | out[i]=in[i]^desx_white_in2out[out0^out1]; | ||
| 106 | out0=out1; | ||
| 107 | out1=(int)out[i&0x07]; | ||
| 108 | } | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | |||
| 112 | void DES_xcbc_encrypt(const unsigned char *in, unsigned char *out, | ||
| 113 | long length, DES_key_schedule *schedule, | ||
| 114 | DES_cblock *ivec, const_DES_cblock *inw, | ||
| 115 | const_DES_cblock *outw, int enc) | ||
| 116 | { | ||
| 117 | register DES_LONG tin0,tin1; | ||
| 118 | register DES_LONG tout0,tout1,xor0,xor1; | ||
| 119 | register DES_LONG inW0,inW1,outW0,outW1; | ||
| 120 | register const unsigned char *in2; | ||
| 121 | register long l=length; | ||
| 122 | DES_LONG tin[2]; | ||
| 123 | unsigned char *iv; | ||
| 124 | |||
| 125 | in2 = &(*inw)[0]; | ||
| 126 | c2l(in2,inW0); | ||
| 127 | c2l(in2,inW1); | ||
| 128 | in2 = &(*outw)[0]; | ||
| 129 | c2l(in2,outW0); | ||
| 130 | c2l(in2,outW1); | ||
| 131 | |||
| 132 | iv = &(*ivec)[0]; | ||
| 133 | |||
| 134 | if (enc) | ||
| 135 | { | ||
| 136 | c2l(iv,tout0); | ||
| 137 | c2l(iv,tout1); | ||
| 138 | for (l-=8; l>=0; l-=8) | ||
| 139 | { | ||
| 140 | c2l(in,tin0); | ||
| 141 | c2l(in,tin1); | ||
| 142 | tin0^=tout0^inW0; tin[0]=tin0; | ||
| 143 | tin1^=tout1^inW1; tin[1]=tin1; | ||
| 144 | DES_encrypt1(tin,schedule,DES_ENCRYPT); | ||
| 145 | tout0=tin[0]^outW0; l2c(tout0,out); | ||
| 146 | tout1=tin[1]^outW1; l2c(tout1,out); | ||
| 147 | } | ||
| 148 | if (l != -8) | ||
| 149 | { | ||
| 150 | c2ln(in,tin0,tin1,l+8); | ||
| 151 | tin0^=tout0^inW0; tin[0]=tin0; | ||
| 152 | tin1^=tout1^inW1; tin[1]=tin1; | ||
| 153 | DES_encrypt1(tin,schedule,DES_ENCRYPT); | ||
| 154 | tout0=tin[0]^outW0; l2c(tout0,out); | ||
| 155 | tout1=tin[1]^outW1; l2c(tout1,out); | ||
| 156 | } | ||
| 157 | iv = &(*ivec)[0]; | ||
| 158 | l2c(tout0,iv); | ||
| 159 | l2c(tout1,iv); | ||
| 160 | } | ||
| 161 | else | ||
| 162 | { | ||
| 163 | c2l(iv,xor0); | ||
| 164 | c2l(iv,xor1); | ||
| 165 | for (l-=8; l>0; l-=8) | ||
| 166 | { | ||
| 167 | c2l(in,tin0); tin[0]=tin0^outW0; | ||
| 168 | c2l(in,tin1); tin[1]=tin1^outW1; | ||
| 169 | DES_encrypt1(tin,schedule,DES_DECRYPT); | ||
| 170 | tout0=tin[0]^xor0^inW0; | ||
| 171 | tout1=tin[1]^xor1^inW1; | ||
| 172 | l2c(tout0,out); | ||
| 173 | l2c(tout1,out); | ||
| 174 | xor0=tin0; | ||
| 175 | xor1=tin1; | ||
| 176 | } | ||
| 177 | if (l != -8) | ||
| 178 | { | ||
| 179 | c2l(in,tin0); tin[0]=tin0^outW0; | ||
| 180 | c2l(in,tin1); tin[1]=tin1^outW1; | ||
| 181 | DES_encrypt1(tin,schedule,DES_DECRYPT); | ||
| 182 | tout0=tin[0]^xor0^inW0; | ||
| 183 | tout1=tin[1]^xor1^inW1; | ||
| 184 | l2cn(tout0,tout1,out,l+8); | ||
| 185 | xor0=tin0; | ||
| 186 | xor1=tin1; | ||
| 187 | } | ||
| 188 | |||
| 189 | iv = &(*ivec)[0]; | ||
| 190 | l2c(xor0,iv); | ||
| 191 | l2c(xor1,iv); | ||
| 192 | } | ||
| 193 | tin0=tin1=tout0=tout1=xor0=xor1=0; | ||
| 194 | inW0=inW1=outW0=outW1=0; | ||
| 195 | tin[0]=tin[1]=0; | ||
| 196 | } | ||
| 197 | |||
