summaryrefslogtreecommitdiff
path: root/crypto/bf
diff options
context:
space:
mode:
Diffstat (limited to 'crypto/bf')
-rw-r--r--crypto/bf/Makefile.ssl19
-rw-r--r--crypto/bf/Makefile.uni27
-rw-r--r--crypto/bf/asm/b-win32.asm1568
-rw-r--r--crypto/bf/asm/bf-586.pl136
-rw-r--r--crypto/bf/asm/bf-686.pl128
-rw-r--r--crypto/bf/asm/bx86unix.cpp965
-rw-r--r--crypto/bf/asm/readme13
-rw-r--r--crypto/bf/bf_cbc.c10
-rw-r--r--crypto/bf/bf_cfb64.c6
-rw-r--r--crypto/bf/bf_ecb.c9
-rw-r--r--crypto/bf/bf_enc.c207
-rw-r--r--crypto/bf/bf_locl.h2
-rw-r--r--crypto/bf/bf_locl.org2
-rw-r--r--crypto/bf/bf_ofb64.c4
-rw-r--r--crypto/bf/bf_opts.c347
-rw-r--r--crypto/bf/bf_pi.h2
-rw-r--r--crypto/bf/bf_skey.c6
-rw-r--r--crypto/bf/bfs.cpp67
-rw-r--r--crypto/bf/bfspeed.c26
-rw-r--r--crypto/bf/bftest.c22
-rw-r--r--crypto/bf/blowfish.h6
21 files changed, 2781 insertions, 791 deletions
diff --git a/crypto/bf/Makefile.ssl b/crypto/bf/Makefile.ssl
index 1a44992a1a..236671f238 100644
--- a/crypto/bf/Makefile.ssl
+++ b/crypto/bf/Makefile.ssl
@@ -25,8 +25,8 @@ TEST=bftest.c
APPS=
LIB=$(TOP)/libcrypto.a
-LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cbc.c bf_cfb64.c bf_ofb64.c
-LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cbc.o bf_cfb64.o bf_ofb64.o
+LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cfb64.c bf_ofb64.c
+LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cfb64.o bf_ofb64.o
SRC= $(LIBSRC)
@@ -46,23 +46,26 @@ lib: $(LIBOBJ)
@touch lib
# elf
-asm/bx86-elf.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86-elf.o: asm/bx86unix.cpp
$(CPP) -DELF asm/bx86unix.cpp | as -o asm/bx86-elf.o
# solaris
-asm/bx86-sol.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86-sol.o: asm/bx86unix.cpp
$(CC) -E -DSOL asm/bx86unix.cpp | sed 's/^#.*//' > asm/bx86-sol.s
as -o asm/bx86-sol.o asm/bx86-sol.s
rm -f asm/bx86-sol.s
# a.out
-asm/bx86-out.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86-out.o: asm/bx86unix.cpp
$(CPP) -DOUT asm/bx86unix.cpp | as -o asm/bx86-out.o
# bsdi
-asm/bx86bsdi.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86bsdi.o: asm/bx86unix.cpp
$(CPP) -DBSDI asm/bx86unix.cpp | as -o asm/bx86bsdi.o
+asm/bx86unix.cpp:
+ (cd asm; perl bf-586.pl cpp >bx86unix.cpp)
+
files:
perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO
@@ -73,10 +76,6 @@ links:
$(TOP)/util/mklink.sh ../../include $(EXHEADER)
$(TOP)/util/mklink.sh ../../test $(TEST)
$(TOP)/util/mklink.sh ../../apps $(APPS)
- /bin/rm -f asm/x86ms.pl asm/x86unix.pl
- $(TOP)/util/point.sh ../../perlasm/x86ms.pl asm/x86ms.pl
- $(TOP)/util/point.sh ../../perlasm/x86unix.pl asm/x86unix.pl
-
install:
@for i in $(EXHEADER) ; \
diff --git a/crypto/bf/Makefile.uni b/crypto/bf/Makefile.uni
index 8517295475..9ba5b0c854 100644
--- a/crypto/bf/Makefile.uni
+++ b/crypto/bf/Makefile.uni
@@ -7,6 +7,8 @@
# make x86-solaris
# make x86-bdsi
+DIR= bf
+TOP= .
# use BF_PTR2 for intel boxes,
# BF_PTR for sparc and MIPS/SGI
# use nothing for Alpha and HP.
@@ -42,14 +44,14 @@ MANDIR=/usr/local/man
MAN1=1
MAN3=3
SHELL=/bin/sh
-LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cbc.o bf_cfb64.o bf_ofb64.o
-LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cbc.c bf_cfb64.c bf_ofb64.c
+LIBOBJ=bf_skey.o bf_ecb.o $(BF_ENC) bf_cfb64.o bf_ofb64.o
+LIBSRC=bf_skey.c bf_ecb.c bf_enc.c bf_cfb64.c bf_ofb64.c
GENERAL=Makefile Makefile.ssl Makefile.uni asm bf_locl.org README \
COPYRIGHT blowfish.doc INSTALL
-
-TESTING= bftest bfspeed
-TESTING_SRC=bftest.c bfspeed.c
+
+TESTING= bftest bfspeed bf_opts
+TESTING_SRC=bftest.c bfspeed.c bf_opts.c
HEADERS=bf_locl.h blowfish.h bf_pi.h
ALL= $(GENERAL) $(TESTING_SRC) $(LIBSRC) $(HEADERS)
@@ -77,23 +79,26 @@ x86-bsdi:
$(MAKE) BF_ENC='asm/bx86bsdi.o' CC=$(CC) CFLAGS="-DBSDI $(OPTS) $(CFLAG)" all
# elf
-asm/bx86-elf.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86-elf.o: asm/bx86unix.cpp
$(CPP) -DELF asm/bx86unix.cpp | $(AS) -o asm/bx86-elf.o
# solaris
-asm/bx86-sol.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86-sol.o: asm/bx86unix.cpp
$(CC) -E -DSOL asm/bx86unix.cpp | sed 's/^#.*//' > asm/bx86-sol.s
as -o asm/bx86-sol.o asm/bx86-sol.s
rm -f asm/bx86-sol.s
# a.out
-asm/bx86-out.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86-out.o: asm/bx86unix.cpp
$(CPP) -DOUT asm/bx86unix.cpp | $(AS) -o asm/bx86-out.o
# bsdi
-asm/bx86bsdi.o: asm/bx86-cpp.s asm/bx86unix.cpp
+asm/bx86bsdi.o: asm/bx86unix.cpp
$(CPP) -DBSDI asm/bx86unix.cpp | $(AS) -o asm/bx86bsdi.o
+asm/bx86unix.cpp:
+ (cd asm; perl bf-586.pl cpp >bx86unix.cpp)
+
test: all
./bftest
@@ -110,6 +115,9 @@ bftest: bftest.o $(BLIB)
bfspeed: bfspeed.o $(BLIB)
$(CC) $(CFLAGS) -o bfspeed bfspeed.o $(BLIB)
+bf_opts: bf_opts.o $(BLIB)
+ $(CC) $(CFLAGS) -o bf_opts bf_opts.o $(BLIB)
+
tags:
ctags $(TESTING_SRC) $(LIBBF)
@@ -157,4 +165,5 @@ install: $(BLIB)
cp blowfish.h $(INCDIR)/blowfish.h; \
chmod 644 $(INCDIR)/blowfish.h; \
fi
+
# DO NOT DELETE THIS LINE -- make depend depends on it.
diff --git a/crypto/bf/asm/b-win32.asm b/crypto/bf/asm/b-win32.asm
index bef272eebb..138c99d0aa 100644
--- a/crypto/bf/asm/b-win32.asm
+++ b/crypto/bf/asm/b-win32.asm
@@ -1,662 +1,906 @@
- ; Don't even think of reading this code
- ; It was automatically generated by bf586.pl
- ; Which is a perl program used to generate the x86 assember for
- ; any of elf, a.out, Win32, or Solaris
- ; It can be found in SSLeay 0.7.0+
- ; eric <eay@cryptsoft.com>
- ;
- TITLE bfx86xxxx.asm
- .386
-.model FLAT
-_TEXT SEGMENT
-PUBLIC _BF_encrypt
-_BF_encrypt PROC NEAR
- push ebp
- push ebx
- push esi
- push edi
- ;
- ; Load the 2 words
- mov eax, DWORD PTR 20[esp]
- mov ecx, DWORD PTR [eax]
- mov edx, DWORD PTR 4[eax]
- ;
- ; P pointer, s and enc flag
- mov edi, DWORD PTR 24[esp]
- xor eax, eax
- xor ebx, ebx
- mov ebp, DWORD PTR 28[esp]
- cmp ebp, 0
- je $L000start_decrypt
- xor ecx, DWORD PTR [edi]
- ;
- ; Round 0
- ror ecx, 16
- mov esi, DWORD PTR 4[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 1
- ror edx, 16
- mov esi, DWORD PTR 8[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 2
- ror ecx, 16
- mov esi, DWORD PTR 12[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 3
- ror edx, 16
- mov esi, DWORD PTR 16[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 4
- ror ecx, 16
- mov esi, DWORD PTR 20[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 5
- ror edx, 16
- mov esi, DWORD PTR 24[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 6
- ror ecx, 16
- mov esi, DWORD PTR 28[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 7
- ror edx, 16
- mov esi, DWORD PTR 32[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 8
- ror ecx, 16
- mov esi, DWORD PTR 36[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 9
- ror edx, 16
- mov esi, DWORD PTR 40[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 10
- ror ecx, 16
- mov esi, DWORD PTR 44[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 11
- ror edx, 16
- mov esi, DWORD PTR 48[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 12
- ror ecx, 16
- mov esi, DWORD PTR 52[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 13
- ror edx, 16
- mov esi, DWORD PTR 56[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 14
- ror ecx, 16
- mov esi, DWORD PTR 60[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 15
- ror edx, 16
- mov esi, DWORD PTR 64[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- xor edx, DWORD PTR 68[edi]
- mov eax, DWORD PTR 20[esp]
- mov DWORD PTR [eax],edx
- mov DWORD PTR 4[eax],ecx
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-$L000start_decrypt:
- xor ecx, DWORD PTR 68[edi]
- ;
- ; Round 16
- ror ecx, 16
- mov esi, DWORD PTR 64[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 15
- ror edx, 16
- mov esi, DWORD PTR 60[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 14
- ror ecx, 16
- mov esi, DWORD PTR 56[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 13
- ror edx, 16
- mov esi, DWORD PTR 52[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 12
- ror ecx, 16
- mov esi, DWORD PTR 48[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 11
- ror edx, 16
- mov esi, DWORD PTR 44[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 10
- ror ecx, 16
- mov esi, DWORD PTR 40[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 9
- ror edx, 16
- mov esi, DWORD PTR 36[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 8
- ror ecx, 16
- mov esi, DWORD PTR 32[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 7
- ror edx, 16
- mov esi, DWORD PTR 28[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 6
- ror ecx, 16
- mov esi, DWORD PTR 24[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 5
- ror edx, 16
- mov esi, DWORD PTR 20[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 4
- ror ecx, 16
- mov esi, DWORD PTR 16[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 3
- ror edx, 16
- mov esi, DWORD PTR 12[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- ;
- ; Round 2
- ror ecx, 16
- mov esi, DWORD PTR 8[edi]
- mov al, ch
- mov bl, cl
- ror ecx, 16
- xor edx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, ch
- mov bl, cl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor edx, esi
- ;
- ; Round 1
- ror edx, 16
- mov esi, DWORD PTR 4[edi]
- mov al, dh
- mov bl, dl
- ror edx, 16
- xor ecx, esi
- mov esi, DWORD PTR 72[eax*4+edi]
- mov ebp, DWORD PTR 1096[ebx*4+edi]
- mov al, dh
- mov bl, dl
- add esi, ebp
- mov eax, DWORD PTR 2120[eax*4+edi]
- xor esi, eax
- mov ebp, DWORD PTR 3144[ebx*4+edi]
- add esi, ebp
- xor eax, eax
- xor ecx, esi
- xor edx, DWORD PTR [edi]
- mov eax, DWORD PTR 20[esp]
- mov DWORD PTR [eax],edx
- mov DWORD PTR 4[eax],ecx
- pop edi
- pop esi
- pop ebx
- pop ebp
- ret
-_BF_encrypt ENDP
-_TEXT ENDS
-END
+ ; Don't even think of reading this code
+ ; It was automatically generated by bf-586.pl
+ ; Which is a perl program used to generate the x86 assember for
+ ; any of elf, a.out, BSDI,Win32, or Solaris
+ ; eric <eay@cryptsoft.com>
+ ;
+ TITLE bf-586.asm
+ .486
+.model FLAT
+_TEXT SEGMENT
+PUBLIC _BF_encrypt
+
+_BF_encrypt PROC NEAR
+ ;
+ push ebp
+ push ebx
+ mov ebx, DWORD PTR 12[esp]
+ mov ebp, DWORD PTR 16[esp]
+ push esi
+ push edi
+ ; Load the 2 words
+ mov edi, DWORD PTR [ebx]
+ mov esi, DWORD PTR 4[ebx]
+ xor eax, eax
+ mov ebx, DWORD PTR [ebp]
+ xor ecx, ecx
+ xor edi, ebx
+ ;
+ ; Round 0
+ mov edx, DWORD PTR 4[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 1
+ mov edx, DWORD PTR 8[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 2
+ mov edx, DWORD PTR 12[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 3
+ mov edx, DWORD PTR 16[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 4
+ mov edx, DWORD PTR 20[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 5
+ mov edx, DWORD PTR 24[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 6
+ mov edx, DWORD PTR 28[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 7
+ mov edx, DWORD PTR 32[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 8
+ mov edx, DWORD PTR 36[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 9
+ mov edx, DWORD PTR 40[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 10
+ mov edx, DWORD PTR 44[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 11
+ mov edx, DWORD PTR 48[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 12
+ mov edx, DWORD PTR 52[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 13
+ mov edx, DWORD PTR 56[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 14
+ mov edx, DWORD PTR 60[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 15
+ mov edx, DWORD PTR 64[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ ; Load parameter 0 (16) enc=1
+ mov eax, DWORD PTR 20[esp]
+ xor edi, ebx
+ mov edx, DWORD PTR 68[ebp]
+ xor esi, edx
+ mov DWORD PTR 4[eax],edi
+ mov DWORD PTR [eax],esi
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+_BF_encrypt ENDP
+_TEXT ENDS
+_TEXT SEGMENT
+PUBLIC _BF_decrypt
+
+_BF_decrypt PROC NEAR
+ ;
+ push ebp
+ push ebx
+ mov ebx, DWORD PTR 12[esp]
+ mov ebp, DWORD PTR 16[esp]
+ push esi
+ push edi
+ ; Load the 2 words
+ mov edi, DWORD PTR [ebx]
+ mov esi, DWORD PTR 4[ebx]
+ xor eax, eax
+ mov ebx, DWORD PTR 68[ebp]
+ xor ecx, ecx
+ xor edi, ebx
+ ;
+ ; Round 16
+ mov edx, DWORD PTR 64[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 15
+ mov edx, DWORD PTR 60[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 14
+ mov edx, DWORD PTR 56[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 13
+ mov edx, DWORD PTR 52[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 12
+ mov edx, DWORD PTR 48[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 11
+ mov edx, DWORD PTR 44[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 10
+ mov edx, DWORD PTR 40[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 9
+ mov edx, DWORD PTR 36[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 8
+ mov edx, DWORD PTR 32[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 7
+ mov edx, DWORD PTR 28[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 6
+ mov edx, DWORD PTR 24[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 5
+ mov edx, DWORD PTR 20[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 4
+ mov edx, DWORD PTR 16[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 3
+ mov edx, DWORD PTR 12[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor edi, ebx
+ ;
+ ; Round 2
+ mov edx, DWORD PTR 8[ebp]
+ mov ebx, edi
+ xor esi, edx
+ shr ebx, 16
+ mov edx, edi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ xor eax, eax
+ xor esi, ebx
+ ;
+ ; Round 1
+ mov edx, DWORD PTR 4[ebp]
+ mov ebx, esi
+ xor edi, edx
+ shr ebx, 16
+ mov edx, esi
+ mov al, bh
+ and ebx, 255
+ mov cl, dh
+ and edx, 255
+ mov eax, DWORD PTR 72[eax*4+ebp]
+ mov ebx, DWORD PTR 1096[ebx*4+ebp]
+ add ebx, eax
+ mov eax, DWORD PTR 2120[ecx*4+ebp]
+ xor ebx, eax
+ mov edx, DWORD PTR 3144[edx*4+ebp]
+ add ebx, edx
+ ; Load parameter 0 (1) enc=0
+ mov eax, DWORD PTR 20[esp]
+ xor edi, ebx
+ mov edx, DWORD PTR [ebp]
+ xor esi, edx
+ mov DWORD PTR 4[eax],edi
+ mov DWORD PTR [eax],esi
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+_BF_decrypt ENDP
+_TEXT ENDS
+_TEXT SEGMENT
+PUBLIC _BF_cbc_encrypt
+
+_BF_cbc_encrypt PROC NEAR
+ ;
+ push ebp
+ push ebx
+ push esi
+ push edi
+ mov ebp, DWORD PTR 28[esp]
+ ; getting iv ptr from parameter 4
+ mov ebx, DWORD PTR 36[esp]
+ mov esi, DWORD PTR [ebx]
+ mov edi, DWORD PTR 4[ebx]
+ push edi
+ push esi
+ push edi
+ push esi
+ mov ebx, esp
+ mov esi, DWORD PTR 36[esp]
+ mov edi, DWORD PTR 40[esp]
+ ; getting encrypt flag from parameter 5
+ mov ecx, DWORD PTR 56[esp]
+ ; get and push parameter 3
+ mov eax, DWORD PTR 48[esp]
+ push eax
+ push ebx
+ cmp ecx, 0
+ jz $L000decrypt
+ and ebp, 4294967288
+ mov eax, DWORD PTR 8[esp]
+ mov ebx, DWORD PTR 12[esp]
+ jz $L001encrypt_finish
+L002encrypt_loop:
+ mov ecx, DWORD PTR [esi]
+ mov edx, DWORD PTR 4[esi]
+ xor eax, ecx
+ xor ebx, edx
+ bswap eax
+ bswap ebx
+ mov DWORD PTR 8[esp],eax
+ mov DWORD PTR 12[esp],ebx
+ call _BF_encrypt
+ mov eax, DWORD PTR 8[esp]
+ mov ebx, DWORD PTR 12[esp]
+ bswap eax
+ bswap ebx
+ mov DWORD PTR [edi],eax
+ mov DWORD PTR 4[edi],ebx
+ add esi, 8
+ add edi, 8
+ sub ebp, 8
+ jnz L002encrypt_loop
+$L001encrypt_finish:
+ mov ebp, DWORD PTR 52[esp]
+ and ebp, 7
+ jz $L003finish
+ xor ecx, ecx
+ xor edx, edx
+ mov ebp, DWORD PTR $L004cbc_enc_jmp_table[ebp*4]
+ jmp ebp
+L005ej7:
+ mov dh, BYTE PTR 6[esi]
+ shl edx, 8
+L006ej6:
+ mov dh, BYTE PTR 5[esi]
+L007ej5:
+ mov dl, BYTE PTR 4[esi]
+L008ej4:
+ mov ecx, DWORD PTR [esi]
+ jmp $L009ejend
+L010ej3:
+ mov ch, BYTE PTR 2[esi]
+ shl ecx, 8
+L011ej2:
+ mov ch, BYTE PTR 1[esi]
+L012ej1:
+ mov cl, BYTE PTR [esi]
+$L009ejend:
+ xor eax, ecx
+ xor ebx, edx
+ bswap eax
+ bswap ebx
+ mov DWORD PTR 8[esp],eax
+ mov DWORD PTR 12[esp],ebx
+ call _BF_encrypt
+ mov eax, DWORD PTR 8[esp]
+ mov ebx, DWORD PTR 12[esp]
+ bswap eax
+ bswap ebx
+ mov DWORD PTR [edi],eax
+ mov DWORD PTR 4[edi],ebx
+ jmp $L003finish
+$L000decrypt:
+ and ebp, 4294967288
+ mov eax, DWORD PTR 16[esp]
+ mov ebx, DWORD PTR 20[esp]
+ jz $L013decrypt_finish
+L014decrypt_loop:
+ mov eax, DWORD PTR [esi]
+ mov ebx, DWORD PTR 4[esi]
+ bswap eax
+ bswap ebx
+ mov DWORD PTR 8[esp],eax
+ mov DWORD PTR 12[esp],ebx
+ call _BF_decrypt
+ mov eax, DWORD PTR 8[esp]
+ mov ebx, DWORD PTR 12[esp]
+ bswap eax
+ bswap ebx
+ mov ecx, DWORD PTR 16[esp]
+ mov edx, DWORD PTR 20[esp]
+ xor ecx, eax
+ xor edx, ebx
+ mov eax, DWORD PTR [esi]
+ mov ebx, DWORD PTR 4[esi]
+ mov DWORD PTR [edi],ecx
+ mov DWORD PTR 4[edi],edx
+ mov DWORD PTR 16[esp],eax
+ mov DWORD PTR 20[esp],ebx
+ add esi, 8
+ add edi, 8
+ sub ebp, 8
+ jnz L014decrypt_loop
+$L013decrypt_finish:
+ mov ebp, DWORD PTR 52[esp]
+ and ebp, 7
+ jz $L003finish
+ mov eax, DWORD PTR [esi]
+ mov ebx, DWORD PTR 4[esi]
+ bswap eax
+ bswap ebx
+ mov DWORD PTR 8[esp],eax
+ mov DWORD PTR 12[esp],ebx
+ call _BF_decrypt
+ mov eax, DWORD PTR 8[esp]
+ mov ebx, DWORD PTR 12[esp]
+ bswap eax
+ bswap ebx
+ mov ecx, DWORD PTR 16[esp]
+ mov edx, DWORD PTR 20[esp]
+ xor ecx, eax
+ xor edx, ebx
+ mov eax, DWORD PTR [esi]
+ mov ebx, DWORD PTR 4[esi]
+L015dj7:
+ ror edx, 16
+ mov BYTE PTR 6[edi],dl
+ shr edx, 16
+L016dj6:
+ mov BYTE PTR 5[edi],dh
+L017dj5:
+ mov BYTE PTR 4[edi],dl
+L018dj4:
+ mov DWORD PTR [edi],ecx
+ jmp $L019djend
+L020dj3:
+ ror ecx, 16
+ mov BYTE PTR 2[edi],cl
+ shl ecx, 16
+L021dj2:
+ mov BYTE PTR 1[esi],ch
+L022dj1:
+ mov BYTE PTR [esi], cl
+$L019djend:
+ jmp $L003finish
+$L003finish:
+ mov ecx, DWORD PTR 60[esp]
+ add esp, 24
+ mov DWORD PTR [ecx],eax
+ mov DWORD PTR 4[ecx],ebx
+ pop edi
+ pop esi
+ pop ebx
+ pop ebp
+ ret
+$L004cbc_enc_jmp_table:
+ DD 0
+ DD L012ej1
+ DD L011ej2
+ DD L010ej3
+ DD L008ej4
+ DD L007ej5
+ DD L006ej6
+ DD L005ej7
+L023cbc_dec_jmp_table:
+ DD 0
+ DD L022dj1
+ DD L021dj2
+ DD L020dj3
+ DD L018dj4
+ DD L017dj5
+ DD L016dj6
+ DD L015dj7
+_BF_cbc_encrypt ENDP
+_TEXT ENDS
+END
diff --git a/crypto/bf/asm/bf-586.pl b/crypto/bf/asm/bf-586.pl
new file mode 100644
index 0000000000..252abb710d
--- /dev/null
+++ b/crypto/bf/asm/bf-586.pl
@@ -0,0 +1,136 @@
+#!/usr/local/bin/perl
+
+push(@INC,"perlasm","../../perlasm");
+require "x86asm.pl";
+require "cbc.pl";
+
+&asm_init($ARGV[0],"bf-586.pl");
+
+$BF_ROUNDS=16;
+$BF_OFF=($BF_ROUNDS+2)*4;
+$L="edi";
+$R="esi";
+$P="ebp";
+$tmp1="eax";
+$tmp2="ebx";
+$tmp3="ecx";
+$tmp4="edx";
+
+&BF_encrypt("BF_encrypt",1);
+&BF_encrypt("BF_decrypt",0);
+&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1);
+&asm_finish();
+
+sub BF_encrypt
+ {
+ local($name,$enc)=@_;
+
+ &function_begin_B($name,"");
+
+ &comment("");
+
+ &push("ebp");
+ &push("ebx");
+ &mov($tmp2,&wparam(0));
+ &mov($P,&wparam(1));
+ &push("esi");
+ &push("edi");
+
+ &comment("Load the 2 words");
+ &mov($L,&DWP(0,$tmp2,"",0));
+ &mov($R,&DWP(4,$tmp2,"",0));
+
+ &xor( $tmp1, $tmp1);
+
+ # encrypting part
+
+ if ($enc)
+ {
+ &mov($tmp2,&DWP(0,$P,"",0));
+ &xor( $tmp3, $tmp3);
+
+ &xor($L,$tmp2);
+ for ($i=0; $i<$BF_ROUNDS; $i+=2)
+ {
+ &comment("");
+ &comment("Round $i");
+ &BF_ENCRYPT($i+1,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,1);
+
+ &comment("");
+ &comment("Round ".sprintf("%d",$i+1));
+ &BF_ENCRYPT($i+2,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,1);
+ }
+ # &mov($tmp1,&wparam(0)); In last loop
+ &mov($tmp4,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
+ }
+ else
+ {
+ &mov($tmp2,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
+ &xor( $tmp3, $tmp3);
+
+ &xor($L,$tmp2);
+ for ($i=$BF_ROUNDS; $i>0; $i-=2)
+ {
+ &comment("");
+ &comment("Round $i");
+ &BF_ENCRYPT($i,$R,$L,$P,$tmp1,$tmp2,$tmp3,$tmp4,0);
+ &comment("");
+ &comment("Round ".sprintf("%d",$i-1));
+ &BF_ENCRYPT($i-1,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,0);
+ }
+ # &mov($tmp1,&wparam(0)); In last loop
+ &mov($tmp4,&DWP(0,$P,"",0));
+ }
+
+ &xor($R,$tmp4);
+ &mov(&DWP(4,$tmp1,"",0),$L);
+
+ &mov(&DWP(0,$tmp1,"",0),$R);
+ &function_end($name);
+ }
+
+sub BF_ENCRYPT
+ {
+ local($i,$L,$R,$P,$tmp1,$tmp2,$tmp3,$tmp4,$enc)=@_;
+
+ &mov( $tmp4, &DWP(&n2a($i*4),$P,"",0)); # for next round
+
+ &mov( $tmp2, $R);
+ &xor( $L, $tmp4);
+
+ &shr( $tmp2, 16);
+ &mov( $tmp4, $R);
+
+ &movb( &LB($tmp1), &HB($tmp2)); # A
+ &and( $tmp2, 0xff); # B
+
+ &movb( &LB($tmp3), &HB($tmp4)); # C
+ &and( $tmp4, 0xff); # D
+
+ &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
+ &mov( $tmp2, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
+
+ &add( $tmp2, $tmp1);
+ &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp3,4));
+
+ &xor( $tmp2, $tmp1);
+ &mov( $tmp4, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp4,4));
+
+ &add( $tmp2, $tmp4);
+ if (($enc && ($i != 16)) || ((!$enc) && ($i != 1)))
+ { &xor( $tmp1, $tmp1); }
+ else
+ {
+ &comment("Load parameter 0 ($i) enc=$enc");
+ &mov($tmp1,&wparam(0));
+ } # In last loop
+
+ &xor( $L, $tmp2);
+ # delay
+ }
+
+sub n2a
+ {
+ sprintf("%d",$_[0]);
+ }
+
diff --git a/crypto/bf/asm/bf-686.pl b/crypto/bf/asm/bf-686.pl
new file mode 100644
index 0000000000..7a62f67161
--- /dev/null
+++ b/crypto/bf/asm/bf-686.pl
@@ -0,0 +1,128 @@
+#!/usr/local/bin/perl
+#!/usr/local/bin/perl
+
+push(@INC,"perlasm","../../perlasm");
+require "x86asm.pl";
+require "cbc.pl";
+
+&asm_init($ARGV[0],"bf-686.pl");
+
+$BF_ROUNDS=16;
+$BF_OFF=($BF_ROUNDS+2)*4;
+$L="ecx";
+$R="edx";
+$P="edi";
+$tot="esi";
+$tmp1="eax";
+$tmp2="ebx";
+$tmp3="ebp";
+
+&des_encrypt("BF_encrypt",1);
+&des_encrypt("BF_decrypt",0);
+&cbc("BF_cbc_encrypt","BF_encrypt","BF_decrypt",1,4,5,3,-1,-1);
+
+&asm_finish();
+
+&file_end();
+
+sub des_encrypt
+ {
+ local($name,$enc)=@_;
+
+ &function_begin($name,"");
+
+ &comment("");
+ &comment("Load the 2 words");
+ &mov("eax",&wparam(0));
+ &mov($L,&DWP(0,"eax","",0));
+ &mov($R,&DWP(4,"eax","",0));
+
+ &comment("");
+ &comment("P pointer, s and enc flag");
+ &mov($P,&wparam(1));
+
+ &xor( $tmp1, $tmp1);
+ &xor( $tmp2, $tmp2);
+
+ # encrypting part
+
+ if ($enc)
+ {
+ &xor($L,&DWP(0,$P,"",0));
+ for ($i=0; $i<$BF_ROUNDS; $i+=2)
+ {
+ &comment("");
+ &comment("Round $i");
+ &BF_ENCRYPT($i+1,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
+
+ &comment("");
+ &comment("Round ".sprintf("%d",$i+1));
+ &BF_ENCRYPT($i+2,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
+ }
+ &xor($R,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
+
+ &mov("eax",&wparam(0));
+ &mov(&DWP(0,"eax","",0),$R);
+ &mov(&DWP(4,"eax","",0),$L);
+ &function_end_A($name);
+ }
+ else
+ {
+ &xor($L,&DWP(($BF_ROUNDS+1)*4,$P,"",0));
+ for ($i=$BF_ROUNDS; $i>0; $i-=2)
+ {
+ &comment("");
+ &comment("Round $i");
+ &BF_ENCRYPT($i,$R,$L,$P,$tot,$tmp1,$tmp2,$tmp3);
+ &comment("");
+ &comment("Round ".sprintf("%d",$i-1));
+ &BF_ENCRYPT($i-1,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3);
+ }
+ &xor($R,&DWP(0,$P,"",0));
+
+ &mov("eax",&wparam(0));
+ &mov(&DWP(0,"eax","",0),$R);
+ &mov(&DWP(4,"eax","",0),$L);
+ &function_end_A($name);
+ }
+
+ &function_end_B($name);
+ }
+
+sub BF_ENCRYPT
+ {
+ local($i,$L,$R,$P,$tot,$tmp1,$tmp2,$tmp3)=@_;
+
+ &rotr( $R, 16);
+ &mov( $tot, &DWP(&n2a($i*4),$P,"",0));
+
+ &movb( &LB($tmp1), &HB($R));
+ &movb( &LB($tmp2), &LB($R));
+
+ &rotr( $R, 16);
+ &xor( $L, $tot);
+
+ &mov( $tot, &DWP(&n2a($BF_OFF+0x0000),$P,$tmp1,4));
+ &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0400),$P,$tmp2,4));
+
+ &movb( &LB($tmp1), &HB($R));
+ &movb( &LB($tmp2), &LB($R));
+
+ &add( $tot, $tmp3);
+ &mov( $tmp1, &DWP(&n2a($BF_OFF+0x0800),$P,$tmp1,4)); # delay
+
+ &xor( $tot, $tmp1);
+ &mov( $tmp3, &DWP(&n2a($BF_OFF+0x0C00),$P,$tmp2,4));
+
+ &add( $tot, $tmp3);
+ &xor( $tmp1, $tmp1);
+
+ &xor( $L, $tot);
+ # delay
+ }
+
+sub n2a
+ {
+ sprintf("%d",$_[0]);
+ }
+
diff --git a/crypto/bf/asm/bx86unix.cpp b/crypto/bf/asm/bx86unix.cpp
index dcb10d23dd..cdaa269378 100644
--- a/crypto/bf/asm/bx86unix.cpp
+++ b/crypto/bf/asm/bx86unix.cpp
@@ -1,24 +1,37 @@
+/* Run the C pre-processor over this file with one of the following defined
+ * ELF - elf object files,
+ * OUT - a.out object files,
+ * BSDI - BSDI style a.out object files
+ * SOL - Solaris style elf
+ */
-#define TYPE(a,b) .type a,b
-#define SIZE(a,b) .size a,b
+#define TYPE(a,b) .type a,b
+#define SIZE(a,b) .size a,b
+
+#if defined(OUT) || defined(BSDI)
+#define BF_encrypt _BF_encrypt
+#define BF_decrypt _BF_decrypt
+#define BF_cbc_encrypt _BF_cbc_encrypt
+
+#endif
#ifdef OUT
-#define OK 1
-#define BF_encrypt _BF_encrypt
-#define ALIGN 4
+#define OK 1
+#define ALIGN 4
#endif
#ifdef BSDI
-#define OK 1
-#define BF_encrypt _BF_encrypt
-#define ALIGN 4
+#define OK 1
+#define ALIGN 4
#undef SIZE
#undef TYPE
+#define SIZE(a,b)
+#define TYPE(a,b)
#endif
#if defined(ELF) || defined(SOL)
-#define OK 1
-#define ALIGN 16
+#define OK 1
+#define ALIGN 16
#endif
#ifndef OK
@@ -29,5 +42,935 @@ SOL - solaris systems, which are elf with strange comment lines
BSDI - a.out with a very primative version of as.
#endif
-#include "bx86-cpp.s"
+/* Let the Assembler begin :-) */
+ /* Don't even think of reading this code */
+ /* It was automatically generated by bf-586.pl */
+ /* Which is a perl program used to generate the x86 assember for */
+ /* any of elf, a.out, BSDI,Win32, or Solaris */
+ /* eric <eay@cryptsoft.com> */
+
+ .file "bf-586.s"
+ .version "01.01"
+gcc2_compiled.:
+.text
+ .align ALIGN
+.globl BF_encrypt
+ TYPE(BF_encrypt,@function)
+BF_encrypt:
+
+ pushl %ebp
+ pushl %ebx
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ebp
+ pushl %esi
+ pushl %edi
+ /* Load the 2 words */
+ movl (%ebx), %edi
+ movl 4(%ebx), %esi
+ xorl %eax, %eax
+ movl (%ebp), %ebx
+ xorl %ecx, %ecx
+ xorl %ebx, %edi
+
+ /* Round 0 */
+ movl 4(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 1 */
+ movl 8(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 2 */
+ movl 12(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 3 */
+ movl 16(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 4 */
+ movl 20(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 5 */
+ movl 24(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 6 */
+ movl 28(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 7 */
+ movl 32(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 8 */
+ movl 36(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 9 */
+ movl 40(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 10 */
+ movl 44(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 11 */
+ movl 48(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 12 */
+ movl 52(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 13 */
+ movl 56(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 14 */
+ movl 60(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 15 */
+ movl 64(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ /* Load parameter 0 (16) enc=1 */
+ movl 20(%esp), %eax
+ xorl %ebx, %edi
+ movl 68(%ebp), %edx
+ xorl %edx, %esi
+ movl %edi, 4(%eax)
+ movl %esi, (%eax)
+ popl %edi
+ popl %esi
+ popl %ebx
+ popl %ebp
+ ret
+.BF_encrypt_end:
+ SIZE(BF_encrypt,.BF_encrypt_end-BF_encrypt)
+.ident "BF_encrypt"
+.text
+ .align ALIGN
+.globl BF_decrypt
+ TYPE(BF_decrypt,@function)
+BF_decrypt:
+
+ pushl %ebp
+ pushl %ebx
+ movl 12(%esp), %ebx
+ movl 16(%esp), %ebp
+ pushl %esi
+ pushl %edi
+ /* Load the 2 words */
+ movl (%ebx), %edi
+ movl 4(%ebx), %esi
+ xorl %eax, %eax
+ movl 68(%ebp), %ebx
+ xorl %ecx, %ecx
+ xorl %ebx, %edi
+
+ /* Round 16 */
+ movl 64(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 15 */
+ movl 60(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 14 */
+ movl 56(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 13 */
+ movl 52(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 12 */
+ movl 48(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 11 */
+ movl 44(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 10 */
+ movl 40(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 9 */
+ movl 36(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 8 */
+ movl 32(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 7 */
+ movl 28(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 6 */
+ movl 24(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 5 */
+ movl 20(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 4 */
+ movl 16(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 3 */
+ movl 12(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %edi
+
+ /* Round 2 */
+ movl 8(%ebp), %edx
+ movl %edi, %ebx
+ xorl %edx, %esi
+ shrl $16, %ebx
+ movl %edi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ xorl %eax, %eax
+ xorl %ebx, %esi
+
+ /* Round 1 */
+ movl 4(%ebp), %edx
+ movl %esi, %ebx
+ xorl %edx, %edi
+ shrl $16, %ebx
+ movl %esi, %edx
+ movb %bh, %al
+ andl $255, %ebx
+ movb %dh, %cl
+ andl $255, %edx
+ movl 72(%ebp,%eax,4),%eax
+ movl 1096(%ebp,%ebx,4),%ebx
+ addl %eax, %ebx
+ movl 2120(%ebp,%ecx,4),%eax
+ xorl %eax, %ebx
+ movl 3144(%ebp,%edx,4),%edx
+ addl %edx, %ebx
+ /* Load parameter 0 (1) enc=0 */
+ movl 20(%esp), %eax
+ xorl %ebx, %edi
+ movl (%ebp), %edx
+ xorl %edx, %esi
+ movl %edi, 4(%eax)
+ movl %esi, (%eax)
+ popl %edi
+ popl %esi
+ popl %ebx
+ popl %ebp
+ ret
+.BF_decrypt_end:
+ SIZE(BF_decrypt,.BF_decrypt_end-BF_decrypt)
+.ident "BF_decrypt"
+.text
+ .align ALIGN
+.globl BF_cbc_encrypt
+ TYPE(BF_cbc_encrypt,@function)
+BF_cbc_encrypt:
+ pushl %ebp
+ pushl %ebx
+ pushl %esi
+ pushl %edi
+ movl 28(%esp), %ebp
+ /* getting iv ptr from parameter 4 */
+ movl 36(%esp), %ebx
+ movl (%ebx), %esi
+ movl 4(%ebx), %edi
+ pushl %edi
+ pushl %esi
+ pushl %edi
+ pushl %esi
+ movl %esp, %ebx
+ movl 36(%esp), %esi
+ movl 40(%esp), %edi
+ /* getting encrypt flag from parameter 5 */
+ movl 56(%esp), %ecx
+ /* get and push parameter 3 */
+ movl 48(%esp), %eax
+ pushl %eax
+ pushl %ebx
+ cmpl $0, %ecx
+ jz .L000decrypt
+ andl $4294967288, %ebp
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+ jz .L001encrypt_finish
+.L002encrypt_loop:
+ movl (%esi), %ecx
+ movl 4(%esi), %edx
+ xorl %ecx, %eax
+ xorl %edx, %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl %eax, 8(%esp)
+ movl %ebx, 12(%esp)
+ call BF_encrypt
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl %eax, (%edi)
+ movl %ebx, 4(%edi)
+ addl $8, %esi
+ addl $8, %edi
+ subl $8, %ebp
+ jnz .L002encrypt_loop
+.L001encrypt_finish:
+ movl 52(%esp), %ebp
+ andl $7, %ebp
+ jz .L003finish
+ xorl %ecx, %ecx
+ xorl %edx, %edx
+ movl .L004cbc_enc_jmp_table(,%ebp,4),%ebp
+ jmp *%ebp
+.L005ej7:
+ movb 6(%esi), %dh
+ sall $8, %edx
+.L006ej6:
+ movb 5(%esi), %dh
+.L007ej5:
+ movb 4(%esi), %dl
+.L008ej4:
+ movl (%esi), %ecx
+ jmp .L009ejend
+.L010ej3:
+ movb 2(%esi), %ch
+ sall $8, %ecx
+.L011ej2:
+ movb 1(%esi), %ch
+.L012ej1:
+ movb (%esi), %cl
+.L009ejend:
+ xorl %ecx, %eax
+ xorl %edx, %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl %eax, 8(%esp)
+ movl %ebx, 12(%esp)
+ call BF_encrypt
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl %eax, (%edi)
+ movl %ebx, 4(%edi)
+ jmp .L003finish
+.align ALIGN
+.L000decrypt:
+ andl $4294967288, %ebp
+ movl 16(%esp), %eax
+ movl 20(%esp), %ebx
+ jz .L013decrypt_finish
+.L014decrypt_loop:
+ movl (%esi), %eax
+ movl 4(%esi), %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl %eax, 8(%esp)
+ movl %ebx, 12(%esp)
+ call BF_decrypt
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl 16(%esp), %ecx
+ movl 20(%esp), %edx
+ xorl %eax, %ecx
+ xorl %ebx, %edx
+ movl (%esi), %eax
+ movl 4(%esi), %ebx
+ movl %ecx, (%edi)
+ movl %edx, 4(%edi)
+ movl %eax, 16(%esp)
+ movl %ebx, 20(%esp)
+ addl $8, %esi
+ addl $8, %edi
+ subl $8, %ebp
+ jnz .L014decrypt_loop
+.L013decrypt_finish:
+ movl 52(%esp), %ebp
+ andl $7, %ebp
+ jz .L003finish
+ movl (%esi), %eax
+ movl 4(%esi), %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl %eax, 8(%esp)
+ movl %ebx, 12(%esp)
+ call BF_decrypt
+ movl 8(%esp), %eax
+ movl 12(%esp), %ebx
+.byte 15
+.byte 200 /* bswapl %eax */
+.byte 15
+.byte 203 /* bswapl %ebx */
+ movl 16(%esp), %ecx
+ movl 20(%esp), %edx
+ xorl %eax, %ecx
+ xorl %ebx, %edx
+ movl (%esi), %eax
+ movl 4(%esi), %ebx
+.L015dj7:
+ rorl $16, %edx
+ movb %dl, 6(%edi)
+ shrl $16, %edx
+.L016dj6:
+ movb %dh, 5(%edi)
+.L017dj5:
+ movb %dl, 4(%edi)
+.L018dj4:
+ movl %ecx, (%edi)
+ jmp .L019djend
+.L020dj3:
+ rorl $16, %ecx
+ movb %cl, 2(%edi)
+ sall $16, %ecx
+.L021dj2:
+ movb %ch, 1(%esi)
+.L022dj1:
+ movb %cl, (%esi)
+.L019djend:
+ jmp .L003finish
+.align ALIGN
+.L003finish:
+ movl 60(%esp), %ecx
+ addl $24, %esp
+ movl %eax, (%ecx)
+ movl %ebx, 4(%ecx)
+ popl %edi
+ popl %esi
+ popl %ebx
+ popl %ebp
+ ret
+.align ALIGN
+.L004cbc_enc_jmp_table:
+ .long 0
+ .long .L012ej1
+ .long .L011ej2
+ .long .L010ej3
+ .long .L008ej4
+ .long .L007ej5
+ .long .L006ej6
+ .long .L005ej7
+.align ALIGN
+.L023cbc_dec_jmp_table:
+ .long 0
+ .long .L022dj1
+ .long .L021dj2
+ .long .L020dj3
+ .long .L018dj4
+ .long .L017dj5
+ .long .L016dj6
+ .long .L015dj7
+.BF_cbc_encrypt_end:
+ SIZE(BF_cbc_encrypt,.BF_cbc_encrypt_end-BF_cbc_encrypt)
+.ident "desasm.pl"
diff --git a/crypto/bf/asm/readme b/crypto/bf/asm/readme
index 71e4bb2d5d..2385fa3812 100644
--- a/crypto/bf/asm/readme
+++ b/crypto/bf/asm/readme
@@ -1,3 +1,10 @@
-If you want more of an idea of how this all works,
-have a read of the readme file in SSLeay/crypto/des/asm.
-SSLeay can be found at ftp://ftp.psy.uq.oz.au/pub/Crypto/SSL.
+There are blowfish assembler generation scripts.
+bf-586.pl version is for the pentium and
+bf-686.pl is my original version, which is faster on the pentium pro.
+
+When using a bf-586.pl, the pentium pro/II is %8 slower than using
+bf-686.pl. When using a bf-686.pl, the pentium is %16 slower
+than bf-586.pl
+
+So the default is bf-586.pl
+
diff --git a/crypto/bf/bf_cbc.c b/crypto/bf/bf_cbc.c
index 3d05d27cf1..e0fa9ad763 100644
--- a/crypto/bf/bf_cbc.c
+++ b/crypto/bf/bf_cbc.c
@@ -1,5 +1,5 @@
/* crypto/bf/bf_cbc.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -85,7 +85,7 @@ int encrypt;
tin1^=tout1;
tin[0]=tin0;
tin[1]=tin1;
- BF_encrypt(tin,ks,BF_ENCRYPT);
+ BF_encrypt(tin,ks);
tout0=tin[0];
tout1=tin[1];
l2n(tout0,out);
@@ -98,7 +98,7 @@ int encrypt;
tin1^=tout1;
tin[0]=tin0;
tin[1]=tin1;
- BF_encrypt(tin,ks,BF_ENCRYPT);
+ BF_encrypt(tin,ks);
tout0=tin[0];
tout1=tin[1];
l2n(tout0,out);
@@ -118,7 +118,7 @@ int encrypt;
n2l(in,tin1);
tin[0]=tin0;
tin[1]=tin1;
- BF_encrypt(tin,ks,BF_DECRYPT);
+ BF_decrypt(tin,ks);
tout0=tin[0]^xor0;
tout1=tin[1]^xor1;
l2n(tout0,out);
@@ -132,7 +132,7 @@ int encrypt;
n2l(in,tin1);
tin[0]=tin0;
tin[1]=tin1;
- BF_encrypt(tin,ks,BF_DECRYPT);
+ BF_decrypt(tin,ks);
tout0=tin[0]^xor0;
tout1=tin[1]^xor1;
l2nn(tout0,tout1,out,l+8);
diff --git a/crypto/bf/bf_cfb64.c b/crypto/bf/bf_cfb64.c
index 92fc68261b..f9c66e7ced 100644
--- a/crypto/bf/bf_cfb64.c
+++ b/crypto/bf/bf_cfb64.c
@@ -1,5 +1,5 @@
/* crypto/bf/bf_cfb64.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -88,7 +88,7 @@ int encrypt;
{
n2l(iv,v0); ti[0]=v0;
n2l(iv,v1); ti[1]=v1;
- BF_encrypt((BF_LONG *)ti,schedule,BF_ENCRYPT);
+ BF_encrypt((BF_LONG *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2n(t,iv);
t=ti[1]; l2n(t,iv);
@@ -108,7 +108,7 @@ int encrypt;
{
n2l(iv,v0); ti[0]=v0;
n2l(iv,v1); ti[1]=v1;
- BF_encrypt((BF_LONG *)ti,schedule,BF_ENCRYPT);
+ BF_encrypt((BF_LONG *)ti,schedule);
iv=(unsigned char *)ivec;
t=ti[0]; l2n(t,iv);
t=ti[1]; l2n(t,iv);
diff --git a/crypto/bf/bf_ecb.c b/crypto/bf/bf_ecb.c
index 7840352dc3..6d16360bd9 100644
--- a/crypto/bf/bf_ecb.c
+++ b/crypto/bf/bf_ecb.c
@@ -1,5 +1,5 @@
/* crypto/bf/bf_ecb.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -64,7 +64,7 @@
* CAMBRIDGE SECURITY WORKSHOP, CAMBRIDGE, U.K., DECEMBER 9-11, 1993)
*/
-char *BF_version="BlowFish part of SSLeay 0.8.1b 29-Jun-1998";
+char *BF_version="BlowFish part of SSLeay 0.9.0b 29-Jun-1998";
char *BF_options()
{
@@ -87,7 +87,10 @@ int encrypt;
n2l(in,l); d[0]=l;
n2l(in,l); d[1]=l;
- BF_encrypt(d,ks,encrypt);
+ if (encrypt)
+ BF_encrypt(d,ks);
+ else
+ BF_decrypt(d,ks);
l=d[0]; l2n(l,out);
l=d[1]; l2n(l,out);
l=d[0]=d[1]=0;
diff --git a/crypto/bf/bf_enc.c b/crypto/bf/bf_enc.c
index 9bcc2169ce..66a8604c59 100644
--- a/crypto/bf/bf_enc.c
+++ b/crypto/bf/bf_enc.c
@@ -1,5 +1,5 @@
/* crypto/bf/bf_enc.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -69,10 +69,9 @@ If you set BF_ROUNDS to some value other than 16 or 20, you will have
to modify the code.
#endif
-void BF_encrypt(data,key,encrypt)
+void BF_encrypt(data,key)
BF_LONG *data;
BF_KEY *key;
-int encrypt;
{
register BF_LONG l,r,*p,*s;
@@ -81,60 +80,162 @@ int encrypt;
l=data[0];
r=data[1];
- if (encrypt)
- {
- l^=p[0];
- BF_ENC(r,l,s,p[ 1]);
- BF_ENC(l,r,s,p[ 2]);
- BF_ENC(r,l,s,p[ 3]);
- BF_ENC(l,r,s,p[ 4]);
- BF_ENC(r,l,s,p[ 5]);
- BF_ENC(l,r,s,p[ 6]);
- BF_ENC(r,l,s,p[ 7]);
- BF_ENC(l,r,s,p[ 8]);
- BF_ENC(r,l,s,p[ 9]);
- BF_ENC(l,r,s,p[10]);
- BF_ENC(r,l,s,p[11]);
- BF_ENC(l,r,s,p[12]);
- BF_ENC(r,l,s,p[13]);
- BF_ENC(l,r,s,p[14]);
- BF_ENC(r,l,s,p[15]);
- BF_ENC(l,r,s,p[16]);
+ l^=p[0];
+ BF_ENC(r,l,s,p[ 1]);
+ BF_ENC(l,r,s,p[ 2]);
+ BF_ENC(r,l,s,p[ 3]);
+ BF_ENC(l,r,s,p[ 4]);
+ BF_ENC(r,l,s,p[ 5]);
+ BF_ENC(l,r,s,p[ 6]);
+ BF_ENC(r,l,s,p[ 7]);
+ BF_ENC(l,r,s,p[ 8]);
+ BF_ENC(r,l,s,p[ 9]);
+ BF_ENC(l,r,s,p[10]);
+ BF_ENC(r,l,s,p[11]);
+ BF_ENC(l,r,s,p[12]);
+ BF_ENC(r,l,s,p[13]);
+ BF_ENC(l,r,s,p[14]);
+ BF_ENC(r,l,s,p[15]);
+ BF_ENC(l,r,s,p[16]);
#if BF_ROUNDS == 20
- BF_ENC(r,l,s,p[17]);
- BF_ENC(l,r,s,p[18]);
- BF_ENC(r,l,s,p[19]);
- BF_ENC(l,r,s,p[20]);
+ BF_ENC(r,l,s,p[17]);
+ BF_ENC(l,r,s,p[18]);
+ BF_ENC(r,l,s,p[19]);
+ BF_ENC(l,r,s,p[20]);
#endif
- r^=p[BF_ROUNDS+1];
- }
- else
- {
- l^=p[BF_ROUNDS+1];
+ r^=p[BF_ROUNDS+1];
+
+ data[1]=l&0xffffffffL;
+ data[0]=r&0xffffffffL;
+ }
+
+#ifndef BF_DEFAULT_OPTIONS
+
+void BF_decrypt(data,key)
+BF_LONG *data;
+BF_KEY *key;
+ {
+ register BF_LONG l,r,*p,*s;
+
+ p=key->P;
+ s= &(key->S[0]);
+ l=data[0];
+ r=data[1];
+
+ l^=p[BF_ROUNDS+1];
#if BF_ROUNDS == 20
- BF_ENC(r,l,s,p[20]);
- BF_ENC(l,r,s,p[19]);
- BF_ENC(r,l,s,p[18]);
- BF_ENC(l,r,s,p[17]);
+ BF_ENC(r,l,s,p[20]);
+ BF_ENC(l,r,s,p[19]);
+ BF_ENC(r,l,s,p[18]);
+ BF_ENC(l,r,s,p[17]);
#endif
- BF_ENC(r,l,s,p[16]);
- BF_ENC(l,r,s,p[15]);
- BF_ENC(r,l,s,p[14]);
- BF_ENC(l,r,s,p[13]);
- BF_ENC(r,l,s,p[12]);
- BF_ENC(l,r,s,p[11]);
- BF_ENC(r,l,s,p[10]);
- BF_ENC(l,r,s,p[ 9]);
- BF_ENC(r,l,s,p[ 8]);
- BF_ENC(l,r,s,p[ 7]);
- BF_ENC(r,l,s,p[ 6]);
- BF_ENC(l,r,s,p[ 5]);
- BF_ENC(r,l,s,p[ 4]);
- BF_ENC(l,r,s,p[ 3]);
- BF_ENC(r,l,s,p[ 2]);
- BF_ENC(l,r,s,p[ 1]);
- r^=p[0];
- }
+ BF_ENC(r,l,s,p[16]);
+ BF_ENC(l,r,s,p[15]);
+ BF_ENC(r,l,s,p[14]);
+ BF_ENC(l,r,s,p[13]);
+ BF_ENC(r,l,s,p[12]);
+ BF_ENC(l,r,s,p[11]);
+ BF_ENC(r,l,s,p[10]);
+ BF_ENC(l,r,s,p[ 9]);
+ BF_ENC(r,l,s,p[ 8]);
+ BF_ENC(l,r,s,p[ 7]);
+ BF_ENC(r,l,s,p[ 6]);
+ BF_ENC(l,r,s,p[ 5]);
+ BF_ENC(r,l,s,p[ 4]);
+ BF_ENC(l,r,s,p[ 3]);
+ BF_ENC(r,l,s,p[ 2]);
+ BF_ENC(l,r,s,p[ 1]);
+ r^=p[0];
+
data[1]=l&0xffffffffL;
data[0]=r&0xffffffffL;
}
+
+void BF_cbc_encrypt(in, out, length, ks, iv, encrypt)
+unsigned char *in;
+unsigned char *out;
+long length;
+BF_KEY *ks;
+unsigned char *iv;
+int encrypt;
+ {
+ register BF_LONG tin0,tin1;
+ register BF_LONG tout0,tout1,xor0,xor1;
+ register long l=length;
+ BF_LONG tin[2];
+
+ if (encrypt)
+ {
+ n2l(iv,tout0);
+ n2l(iv,tout1);
+ iv-=8;
+ for (l-=8; l>=0; l-=8)
+ {
+ n2l(in,tin0);
+ n2l(in,tin1);
+ tin0^=tout0;
+ tin1^=tout1;
+ tin[0]=tin0;
+ tin[1]=tin1;
+ BF_encrypt(tin,ks);
+ tout0=tin[0];
+ tout1=tin[1];
+ l2n(tout0,out);
+ l2n(tout1,out);
+ }
+ if (l != -8)
+ {
+ n2ln(in,tin0,tin1,l+8);
+ tin0^=tout0;
+ tin1^=tout1;
+ tin[0]=tin0;
+ tin[1]=tin1;
+ BF_encrypt(tin,ks);
+ tout0=tin[0];
+ tout1=tin[1];
+ l2n(tout0,out);
+ l2n(tout1,out);
+ }
+ l2n(tout0,iv);
+ l2n(tout1,iv);
+ }
+ else
+ {
+ n2l(iv,xor0);
+ n2l(iv,xor1);
+ iv-=8;
+ for (l-=8; l>=0; l-=8)
+ {
+ n2l(in,tin0);
+ n2l(in,tin1);
+ tin[0]=tin0;
+ tin[1]=tin1;
+ BF_decrypt(tin,ks);
+ tout0=tin[0]^xor0;
+ tout1=tin[1]^xor1;
+ l2n(tout0,out);
+ l2n(tout1,out);
+ xor0=tin0;
+ xor1=tin1;
+ }
+ if (l != -8)
+ {
+ n2l(in,tin0);
+ n2l(in,tin1);
+ tin[0]=tin0;
+ tin[1]=tin1;
+ BF_decrypt(tin,ks);
+ tout0=tin[0]^xor0;
+ tout1=tin[1]^xor1;
+ l2nn(tout0,tout1,out,l+8);
+ xor0=tin0;
+ xor1=tin1;
+ }
+ l2n(xor0,iv);
+ l2n(xor1,iv);
+ }
+ tin0=tin1=tout0=tout1=xor0=xor1=0;
+ tin[0]=tin[1]=0;
+ }
+
+#endif
diff --git a/crypto/bf/bf_locl.h b/crypto/bf/bf_locl.h
index 592ece99a4..a5663de8ca 100644
--- a/crypto/bf/bf_locl.h
+++ b/crypto/bf/bf_locl.h
@@ -87,9 +87,7 @@
#elif defined( __sgi ) /* Newer MIPS */
# define BF_PTR
#elif defined( i386 ) /* x86 boxes, should be gcc */
-# define BF_PTR2
#elif defined( _MSC_VER ) /* x86 boxes, Visual C */
-# define BF_PTR2
#endif /* Systems-specific speed defines */
#undef c2l
diff --git a/crypto/bf/bf_locl.org b/crypto/bf/bf_locl.org
index 592ece99a4..a5663de8ca 100644
--- a/crypto/bf/bf_locl.org
+++ b/crypto/bf/bf_locl.org
@@ -87,9 +87,7 @@
#elif defined( __sgi ) /* Newer MIPS */
# define BF_PTR
#elif defined( i386 ) /* x86 boxes, should be gcc */
-# define BF_PTR2
#elif defined( _MSC_VER ) /* x86 boxes, Visual C */
-# define BF_PTR2
#endif /* Systems-specific speed defines */
#undef c2l
diff --git a/crypto/bf/bf_ofb64.c b/crypto/bf/bf_ofb64.c
index e95aca5310..5d844ac760 100644
--- a/crypto/bf/bf_ofb64.c
+++ b/crypto/bf/bf_ofb64.c
@@ -1,5 +1,5 @@
/* crypto/bf/bf_ofb64.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -92,7 +92,7 @@ int *num;
{
if (n == 0)
{
- BF_encrypt((BF_LONG *)ti,schedule,BF_ENCRYPT);
+ BF_encrypt((BF_LONG *)ti,schedule);
dp=(char *)d;
t=ti[0]; l2n(t,dp);
t=ti[1]; l2n(t,dp);
diff --git a/crypto/bf/bf_opts.c b/crypto/bf/bf_opts.c
new file mode 100644
index 0000000000..5cfa60c537
--- /dev/null
+++ b/crypto/bf/bf_opts.c
@@ -0,0 +1,347 @@
+/* crypto/bf/bf_opts.c */
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
+ * All rights reserved.
+ *
+ * This package is an SSL implementation written
+ * by Eric Young (eay@cryptsoft.com).
+ * The implementation was written so as to conform with Netscapes SSL.
+ *
+ * This library is free for commercial and non-commercial use as long as
+ * the following conditions are aheared to. The following conditions
+ * apply to all code found in this distribution, be it the RC4, RSA,
+ * lhash, DES, etc., code; not just the SSL code. The SSL documentation
+ * included with this distribution is covered by the same copyright terms
+ * except that the holder is Tim Hudson (tjh@cryptsoft.com).
+ *
+ * Copyright remains Eric Young's, and as such any Copyright notices in
+ * the code are not to be removed.
+ * If this package is used in a product, Eric Young should be given attribution
+ * as the author of the parts of the library used.
+ * This can be in the form of a textual message at program startup or
+ * in documentation (online or textual) provided with the package.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * "This product includes cryptographic software written by
+ * Eric Young (eay@cryptsoft.com)"
+ * The word 'cryptographic' can be left out if the rouines from the library
+ * being used are not cryptographic related :-).
+ * 4. If you include any Windows specific code (or a derivative thereof) from
+ * the apps directory (application code) you must include an acknowledgement:
+ * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * The licence and distribution terms for any publically available version or
+ * derivative of this code cannot be changed. i.e. this code cannot simply be
+ * copied and put under another distribution licence
+ * [including the GNU Public Licence.]
+ */
+
+/* define PART1, PART2, PART3 or PART4 to build only with a few of the options.
+ * This is for machines with 64k code segment size restrictions. */
+
+#ifndef MSDOS
+#define TIMES
+#endif
+
+#include <stdio.h>
+#ifndef MSDOS
+#include <unistd.h>
+#else
+#include <io.h>
+extern void exit();
+#endif
+#include <signal.h>
+#ifndef VMS
+#ifndef _IRIX
+#include <time.h>
+#endif
+#ifdef TIMES
+#include <sys/types.h>
+#include <sys/times.h>
+#endif
+#else /* VMS */
+#include <types.h>
+struct tms {
+ time_t tms_utime;
+ time_t tms_stime;
+ time_t tms_uchild; /* I dunno... */
+ time_t tms_uchildsys; /* so these names are a guess :-) */
+ }
+#endif
+#ifndef TIMES
+#include <sys/timeb.h>
+#endif
+
+#ifdef sun
+#include <limits.h>
+#include <sys/param.h>
+#endif
+
+#include "blowfish.h"
+
+#define BF_DEFAULT_OPTIONS
+
+#undef BF_ENC
+#define BF_encrypt BF_encrypt_normal
+#undef HEADER_BF_LOCL_H
+#include "bf_enc.c"
+
+#define BF_PTR
+#undef BF_PTR2
+#undef BF_ENC
+#undef BF_encrypt
+#define BF_encrypt BF_encrypt_ptr
+#undef HEADER_BF_LOCL_H
+#include "bf_enc.c"
+
+#undef BF_PTR
+#define BF_PTR2
+#undef BF_ENC
+#undef BF_encrypt
+#define BF_encrypt BF_encrypt_ptr2
+#undef HEADER_BF_LOCL_H
+#include "bf_enc.c"
+
+/* The following if from times(3) man page. It may need to be changed */
+#ifndef HZ
+# ifndef CLK_TCK
+# ifndef _BSD_CLK_TCK_ /* FreeBSD fix */
+# ifndef VMS
+# define HZ 100.0
+# else /* VMS */
+# define HZ 100.0
+# endif
+# else /* _BSD_CLK_TCK_ */
+# define HZ ((double)_BSD_CLK_TCK_)
+# endif
+# else /* CLK_TCK */
+# define HZ ((double)CLK_TCK)
+# endif
+#endif
+
+#define BUFSIZE ((long)1024)
+long run=0;
+
+#ifndef NOPROTO
+double Time_F(int s);
+#else
+double Time_F();
+#endif
+
+#ifdef SIGALRM
+#if defined(__STDC__) || defined(sgi)
+#define SIGRETTYPE void
+#else
+#define SIGRETTYPE int
+#endif
+
+#ifndef NOPROTO
+SIGRETTYPE sig_done(int sig);
+#else
+SIGRETTYPE sig_done();
+#endif
+
+SIGRETTYPE sig_done(sig)
+int sig;
+ {
+ signal(SIGALRM,sig_done);
+ run=0;
+#ifdef LINT
+ sig=sig;
+#endif
+ }
+#endif
+
+#define START 0
+#define STOP 1
+
+double Time_F(s)
+int s;
+ {
+ double ret;
+#ifdef TIMES
+ static struct tms tstart,tend;
+
+ if (s == START)
+ {
+ times(&tstart);
+ return(0);
+ }
+ else
+ {
+ times(&tend);
+ ret=((double)(tend.tms_utime-tstart.tms_utime))/HZ;
+ return((ret == 0.0)?1e-6:ret);
+ }
+#else /* !times() */
+ static struct timeb tstart,tend;
+ long i;
+
+ if (s == START)
+ {
+ ftime(&tstart);
+ return(0);
+ }
+ else
+ {
+ ftime(&tend);
+ i=(long)tend.millitm-(long)tstart.millitm;
+ ret=((double)(tend.time-tstart.time))+((double)i)/1000.0;
+ return((ret == 0.0)?1e-6:ret);
+ }
+#endif
+ }
+
+#ifdef SIGALRM
+#define print_name(name) fprintf(stderr,"Doing %s's for 10 seconds\n",name); alarm(10);
+#else
+#define print_name(name) fprintf(stderr,"Doing %s %ld times\n",name,cb);
+#endif
+
+#define time_it(func,name,index) \
+ print_name(name); \
+ Time_F(START); \
+ for (count=0,run=1; COND(cb); count+=4) \
+ { \
+ unsigned long d[2]; \
+ func(d,&sch); \
+ func(d,&sch); \
+ func(d,&sch); \
+ func(d,&sch); \
+ } \
+ tm[index]=Time_F(STOP); \
+ fprintf(stderr,"%ld %s's in %.2f second\n",count,name,tm[index]); \
+ tm[index]=((double)COUNT(cb))/tm[index];
+
+#define print_it(name,index) \
+ fprintf(stderr,"%s bytes per sec = %12.2f (%5.1fuS)\n",name, \
+ tm[index]*8,1.0e6/tm[index]);
+
+int main(argc,argv)
+int argc;
+char **argv;
+ {
+ long count;
+ static unsigned char buf[BUFSIZE];
+ static char key[16]={ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0,
+ 0x12,0x34,0x56,0x78,0x9a,0xbc,0xde,0xf0};
+ BF_KEY sch;
+ double d,tm[16],max=0;
+ int rank[16];
+ char *str[16];
+ int max_idx=0,i,num=0,j;
+#ifndef SIGALARM
+ long ca,cb,cc,cd,ce;
+#endif
+
+ for (i=0; i<12; i++)
+ {
+ tm[i]=0.0;
+ rank[i]=0;
+ }
+
+#ifndef TIMES
+ fprintf(stderr,"To get the most acurate results, try to run this\n");
+ fprintf(stderr,"program when this computer is idle.\n");
+#endif
+
+ BF_set_key(&sch,16,key);
+
+#ifndef SIGALRM
+ fprintf(stderr,"First we calculate the approximate speed ...\n");
+ count=10;
+ do {
+ long i;
+ unsigned long data[2];
+
+ count*=2;
+ Time_F(START);
+ for (i=count; i; i--)
+ BF_encrypt(data,&sch);
+ d=Time_F(STOP);
+ } while (d < 3.0);
+ ca=count;
+ cb=count*3;
+ cc=count*3*8/BUFSIZE+1;
+ cd=count*8/BUFSIZE+1;
+
+ ce=count/20+1;
+#define COND(d) (count != (d))
+#define COUNT(d) (d)
+#else
+#define COND(c) (run)
+#define COUNT(d) (count)
+ signal(SIGALRM,sig_done);
+ alarm(10);
+#endif
+
+ time_it(BF_encrypt_normal, "BF_encrypt_normal ", 0);
+ time_it(BF_encrypt_ptr, "BF_encrypt_ptr ", 1);
+ time_it(BF_encrypt_ptr2, "BF_encrypt_ptr2 ", 2);
+ num+=3;
+
+ str[0]="<nothing>";
+ print_it("BF_encrypt_normal ",0);
+ max=tm[0];
+ max_idx=0;
+ str[1]="ptr ";
+ print_it("BF_encrypt_ptr ",1);
+ if (max < tm[1]) { max=tm[1]; max_idx=1; }
+ str[2]="ptr2 ";
+ print_it("BF_encrypt_ptr2 ",2);
+ if (max < tm[2]) { max=tm[2]; max_idx=2; }
+
+ printf("options BF ecb/s\n");
+ printf("%s %12.2f 100.0%%\n",str[max_idx],tm[max_idx]);
+ d=tm[max_idx];
+ tm[max_idx]= -2.0;
+ max= -1.0;
+ for (;;)
+ {
+ for (i=0; i<3; i++)
+ {
+ if (max < tm[i]) { max=tm[i]; j=i; }
+ }
+ if (max < 0.0) break;
+ printf("%s %12.2f %4.1f%%\n",str[j],tm[j],tm[j]/d*100.0);
+ tm[j]= -2.0;
+ max= -1.0;
+ }
+
+ switch (max_idx)
+ {
+ case 0:
+ printf("-DBF_DEFAULT_OPTIONS\n");
+ break;
+ case 1:
+ printf("-DBF_PTR\n");
+ break;
+ case 2:
+ printf("-DBF_PTR2\n");
+ break;
+ }
+ exit(0);
+#if defined(LINT) || defined(MSDOS)
+ return(0);
+#endif
+ }
diff --git a/crypto/bf/bf_pi.h b/crypto/bf/bf_pi.h
index f5918b361e..417b935538 100644
--- a/crypto/bf/bf_pi.h
+++ b/crypto/bf/bf_pi.h
@@ -1,5 +1,5 @@
/* crypto/bf/bf_pi.h */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
diff --git a/crypto/bf/bf_skey.c b/crypto/bf/bf_skey.c
index 18ea37f7cc..86574c0acc 100644
--- a/crypto/bf/bf_skey.c
+++ b/crypto/bf/bf_skey.c
@@ -1,5 +1,5 @@
/* crypto/bf/bf_skey.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -103,7 +103,7 @@ unsigned char *data;
in[1]=0L;
for (i=0; i<(BF_ROUNDS+2); i+=2)
{
- BF_encrypt(in,key,BF_ENCRYPT);
+ BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
@@ -111,7 +111,7 @@ unsigned char *data;
p=key->S;
for (i=0; i<4*256; i+=2)
{
- BF_encrypt(in,key,BF_ENCRYPT);
+ BF_encrypt(in,key);
p[i ]=in[0];
p[i+1]=in[1];
}
diff --git a/crypto/bf/bfs.cpp b/crypto/bf/bfs.cpp
new file mode 100644
index 0000000000..272ed2f978
--- /dev/null
+++ b/crypto/bf/bfs.cpp
@@ -0,0 +1,67 @@
+//
+// gettsc.inl
+//
+// gives access to the Pentium's (secret) cycle counter
+//
+// This software was written by Leonard Janke (janke@unixg.ubc.ca)
+// in 1996-7 and is entered, by him, into the public domain.
+
+#if defined(__WATCOMC__)
+void GetTSC(unsigned long&);
+#pragma aux GetTSC = 0x0f 0x31 "mov [edi], eax" parm [edi] modify [edx eax];
+#elif defined(__GNUC__)
+inline
+void GetTSC(unsigned long& tsc)
+{
+ asm volatile(".byte 15, 49\n\t"
+ : "=eax" (tsc)
+ :
+ : "%edx", "%eax");
+}
+#elif defined(_MSC_VER)
+inline
+void GetTSC(unsigned long& tsc)
+{
+ unsigned long a;
+ __asm _emit 0fh
+ __asm _emit 31h
+ __asm mov a, eax;
+ tsc=a;
+}
+#endif
+
+#include <stdio.h>
+#include <stdlib.h>
+#include "blowfish.h"
+
+void main(int argc,char *argv[])
+ {
+ BF_KEY key;
+ unsigned long s1,s2,e1,e2;
+ unsigned long data[2];
+ int i,j;
+
+ for (j=0; j<6; j++)
+ {
+ for (i=0; i<1000; i++) /**/
+ {
+ BF_encrypt(&data[0],&key);
+ GetTSC(s1);
+ BF_encrypt(&data[0],&key);
+ BF_encrypt(&data[0],&key);
+ BF_encrypt(&data[0],&key);
+ GetTSC(e1);
+ GetTSC(s2);
+ BF_encrypt(&data[0],&key);
+ BF_encrypt(&data[0],&key);
+ BF_encrypt(&data[0],&key);
+ BF_encrypt(&data[0],&key);
+ GetTSC(e2);
+ BF_encrypt(&data[0],&key);
+ }
+
+ printf("blowfish %d %d (%d)\n",
+ e1-s1,e2-s2,((e2-s2)-(e1-s1)));
+ }
+ }
+
diff --git a/crypto/bf/bfspeed.c b/crypto/bf/bfspeed.c
index ee20bd00f7..640d820dd3 100644
--- a/crypto/bf/bfspeed.c
+++ b/crypto/bf/bfspeed.c
@@ -1,5 +1,5 @@
/* crypto/bf/bfspeed.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -217,7 +217,7 @@ char **argv;
count*=2;
Time_F(START);
for (i=count; i; i--)
- BF_encrypt(data,&sch,BF_ENCRYPT);
+ BF_encrypt(data,&sch);
d=Time_F(STOP);
} while (d < 3.0);
ca=count/512;
@@ -235,10 +235,15 @@ char **argv;
#endif
Time_F(START);
- for (count=0,run=1; COND(ca); count++)
+ for (count=0,run=1; COND(ca); count+=4)
+ {
+ BF_set_key(&sch,16,key);
+ BF_set_key(&sch,16,key);
BF_set_key(&sch,16,key);
+ BF_set_key(&sch,16,key);
+ }
d=Time_F(STOP);
- printf("%ld blowfish set_key's in %.2f seconds\n",count,d);
+ printf("%ld BF_set_key's in %.2f seconds\n",count,d);
a=((double)COUNT(ca))/d;
#ifdef SIGALRM
@@ -248,11 +253,14 @@ char **argv;
printf("Doing BF_encrypt %ld times\n",cb);
#endif
Time_F(START);
- for (count=0,run=1; COND(cb); count++)
+ for (count=0,run=1; COND(cb); count+=4)
{
BF_LONG data[2];
- BF_encrypt(data,&sch,BF_ENCRYPT);
+ BF_encrypt(data,&sch);
+ BF_encrypt(data,&sch);
+ BF_encrypt(data,&sch);
+ BF_encrypt(data,&sch);
}
d=Time_F(STOP);
printf("%ld BF_encrypt's in %.2f second\n",count,d);
@@ -275,9 +283,9 @@ char **argv;
count,BUFSIZE,d);
c=((double)COUNT(cc)*BUFSIZE)/d;
- printf("blowfish set_key per sec = %12.2f (%7.1fuS)\n",a,1.0e6/a);
- printf("Blowfish raw ecb bytes per sec = %12.2f (%7.1fuS)\n",b,8.0e6/b);
- printf("Blowfish cbc bytes per sec = %12.2f (%7.1fuS)\n",c,8.0e6/c);
+ printf("Blowfish set_key per sec = %12.3f (%9.3fuS)\n",a,1.0e6/a);
+ printf("Blowfish raw ecb bytes per sec = %12.3f (%9.3fuS)\n",b,8.0e6/b);
+ printf("Blowfish cbc bytes per sec = %12.3f (%9.3fuS)\n",c,8.0e6/c);
exit(0);
#if defined(LINT) || defined(MSDOS)
return(0);
diff --git a/crypto/bf/bftest.c b/crypto/bf/bftest.c
index 2c678e418b..9266cf813a 100644
--- a/crypto/bf/bftest.c
+++ b/crypto/bf/bftest.c
@@ -1,5 +1,5 @@
/* crypto/bf/bftest.c */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -71,13 +71,13 @@ char *bf_key[2]={
/* big endian */
BF_LONG bf_plain[2][2]={
- {0x424c4f57,0x46495348},
- {0xfedcba98,0x76543210}
+ {0x424c4f57L,0x46495348L},
+ {0xfedcba98L,0x76543210L}
};
BF_LONG bf_cipher[2][2]={
- {0x324ed0fe,0xf413a203},
- {0xcc91732b,0x8022f684}
+ {0x324ed0feL,0xf413a203L},
+ {0xcc91732bL,0x8022f684L}
};
/************/
@@ -317,8 +317,8 @@ static int print_test_data()
printf("\niv[8] = ");
for (j=0; j<8; j++)
printf("%02X",cbc_iv[j]);
- printf("\ndata[%d] = '%s'",strlen(cbc_data)+1,cbc_data);
- printf("\ndata[%d] = ",strlen(cbc_data)+1);
+ printf("\ndata[%d] = '%s'",(int)strlen(cbc_data)+1,cbc_data);
+ printf("\ndata[%d] = ",(int)strlen(cbc_data)+1);
for (j=0; j<strlen(cbc_data)+1; j++)
printf("%02X",cbc_data[j]);
printf("\n");
@@ -329,13 +329,13 @@ static int print_test_data()
printf("\n");
printf("cfb64 cipher text\n");
- printf("cipher[%d]= ",strlen(cbc_data)+1);
+ printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
for (j=0; j<strlen(cbc_data)+1; j++)
printf("%02X",cfb64_ok[j]);
printf("\n");
printf("ofb64 cipher text\n");
- printf("cipher[%d]= ",strlen(cbc_data)+1);
+ printf("cipher[%d]= ",(int)strlen(cbc_data)+1);
for (j=0; j<strlen(cbc_data)+1; j++)
printf("%02X",ofb64_ok[j]);
printf("\n");
@@ -358,7 +358,7 @@ static int test()
data[0]=bf_plain[n][0];
data[1]=bf_plain[n][1];
- BF_encrypt(data,&key,BF_ENCRYPT);
+ BF_encrypt(data,&key);
if (memcmp(&(bf_cipher[n][0]),&(data[0]),8) != 0)
{
printf("BF_encrypt error encrypting\n");
@@ -373,7 +373,7 @@ static int test()
printf("\n");
}
- BF_encrypt(&(data[0]),&key,BF_DECRYPT);
+ BF_decrypt(&(data[0]),&key);
if (memcmp(&(bf_plain[n][0]),&(data[0]),8) != 0)
{
printf("BF_encrypt error decrypting\n");
diff --git a/crypto/bf/blowfish.h b/crypto/bf/blowfish.h
index 24ec818218..c4a8085a29 100644
--- a/crypto/bf/blowfish.h
+++ b/crypto/bf/blowfish.h
@@ -1,5 +1,5 @@
/* crypto/bf/blowfish.h */
-/* Copyright (C) 1995-1997 Eric Young (eay@cryptsoft.com)
+/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
* This package is an SSL implementation written
@@ -86,7 +86,8 @@ typedef struct bf_key_st
void BF_set_key(BF_KEY *key, int len, unsigned char *data);
void BF_ecb_encrypt(unsigned char *in,unsigned char *out,BF_KEY *key,
int enc);
-void BF_encrypt(BF_LONG *data,BF_KEY *key,int enc);
+void BF_encrypt(BF_LONG *data,BF_KEY *key);
+void BF_decrypt(BF_LONG *data,BF_KEY *key);
void BF_cbc_encrypt(unsigned char *in, unsigned char *out, long length,
BF_KEY *ks, unsigned char *iv, int enc);
void BF_cfb64_encrypt(unsigned char *in, unsigned char *out, long length,
@@ -100,6 +101,7 @@ char *BF_options(void);
void BF_set_key();
void BF_ecb_encrypt();
void BF_encrypt();
+void BF_decrypt();
void BF_cbc_encrypt();
void BF_cfb64_encrypt();
void BF_ofb64_encrypt();