diff options
Diffstat (limited to 'lib/libcrypto/cast')
-rw-r--r-- | lib/libcrypto/cast/Makefile.ssl | 51 | ||||
-rw-r--r-- | lib/libcrypto/cast/Makefile.uni | 3 | ||||
-rw-r--r-- | lib/libcrypto/cast/asm/c-win32.asm | 117 | ||||
-rw-r--r-- | lib/libcrypto/cast/asm/cast-586.pl | 267 | ||||
-rw-r--r-- | lib/libcrypto/cast/asm/cx86unix.cpp | 1010 | ||||
-rw-r--r-- | lib/libcrypto/cast/c_cfb64.c | 25 | ||||
-rw-r--r-- | lib/libcrypto/cast/c_ecb.c | 14 | ||||
-rw-r--r-- | lib/libcrypto/cast/c_enc.c | 43 | ||||
-rw-r--r-- | lib/libcrypto/cast/c_ofb64.c | 16 | ||||
-rw-r--r-- | lib/libcrypto/cast/c_skey.c | 11 | ||||
-rw-r--r-- | lib/libcrypto/cast/cast.h | 36 | ||||
-rw-r--r-- | lib/libcrypto/cast/cast_lcl.h | 20 | ||||
-rw-r--r-- | lib/libcrypto/cast/cast_s.h | 16 | ||||
-rw-r--r-- | lib/libcrypto/cast/cast_spd.c | 59 | ||||
-rw-r--r-- | lib/libcrypto/cast/castopts.c | 61 | ||||
-rw-r--r-- | lib/libcrypto/cast/casts.cpp | 2 | ||||
-rw-r--r-- | lib/libcrypto/cast/casttest.c | 183 |
17 files changed, 457 insertions, 1477 deletions
diff --git a/lib/libcrypto/cast/Makefile.ssl b/lib/libcrypto/cast/Makefile.ssl index 0143827ae5d..cc040576ae6 100644 --- a/lib/libcrypto/cast/Makefile.ssl +++ b/lib/libcrypto/cast/Makefile.ssl @@ -8,9 +8,11 @@ CC= cc CPP= $(CC) -E INCLUDES= CFLAG=-g +INSTALL_PREFIX= +OPENSSLDIR= /usr/local/ssl INSTALLTOP=/usr/local/ssl MAKE= make -f Makefile.ssl -MAKEDEPEND= makedepend -f Makefile.ssl +MAKEDEPEND= $(TOP)/util/domd $(TOP) MAKEFILE= Makefile.ssl AR= ar r @@ -45,7 +47,7 @@ all: lib lib: $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/util/ranlib.sh $(LIB) + $(RANLIB) $(LIB) @touch lib # elf @@ -64,26 +66,25 @@ asm/cx86-out.o: asm/cx86unix.cpp # bsdi asm/cx86bsdi.o: asm/cx86unix.cpp - $(CPP) -DBSDI asm/cx86unix.cpp | as -o asm/cx86bsdi.o + $(CPP) -DBSDI asm/cx86unix.cpp | sed 's/ :/:/' | as -o asm/cx86bsdi.o -asm/cx86unix.cpp: - (cd asm; perl cast-586.pl cpp >cx86unix.cpp) +asm/cx86unix.cpp: asm/cast-586.pl + (cd asm; $(PERL) cast-586.pl cpp $(PROCESSOR) >cx86unix.cpp) files: - perl $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO + $(PERL) $(TOP)/util/files.pl Makefile.ssl >> $(TOP)/MINFO links: - /bin/rm -f Makefile - $(TOP)/util/point.sh Makefile.ssl Makefile ; - $(TOP)/util/mklink.sh ../../include $(EXHEADER) - $(TOP)/util/mklink.sh ../../test $(TEST) - $(TOP)/util/mklink.sh ../../apps $(APPS) + @$(TOP)/util/point.sh Makefile.ssl Makefile + @$(PERL) $(TOP)/util/mklink.pl ../../include/openssl $(EXHEADER) + @$(PERL) $(TOP)/util/mklink.pl ../../test $(TEST) + @$(PERL) $(TOP)/util/mklink.pl ../../apps $(APPS) install: @for i in $(EXHEADER) ; \ do \ - (cp $$i $(INSTALLTOP)/include/$$i; \ - chmod 644 $(INSTALLTOP)/include/$$i ); \ + (cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i; \ + chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/include/openssl/$$i ); \ done; tags: @@ -95,15 +96,29 @@ lint: lint -DLINT $(INCLUDES) $(SRC)>fluff depend: - $(MAKEDEPEND) $(INCLUDES) $(PROGS) $(LIBSRC) + $(MAKEDEPEND) $(INCLUDES) $(DEPFLAG) $(PROGS) $(LIBSRC) dclean: - perl -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new + $(PERL) -pe 'if (/^# DO NOT DELETE THIS LINE/) {print; exit(0);}' $(MAKEFILE) >Makefile.new mv -f Makefile.new $(MAKEFILE) clean: - /bin/rm -f *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff - -errors: + rm -f asm/cx86unix.cpp *.o asm/*.o *.obj lib tags core .pure .nfs* *.old *.bak fluff # DO NOT DELETE THIS LINE -- make depend depends on it. + +c_cfb64.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_cfb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_cfb64.o: cast_lcl.h +c_ecb.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_ecb.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_ecb.o: ../../include/openssl/opensslv.h cast_lcl.h +c_enc.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_enc.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_enc.o: cast_lcl.h +c_ofb64.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_ofb64.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_ofb64.o: cast_lcl.h +c_skey.o: ../../include/openssl/cast.h ../../include/openssl/e_os.h +c_skey.o: ../../include/openssl/e_os2.h ../../include/openssl/opensslconf.h +c_skey.o: cast_lcl.h cast_s.h diff --git a/lib/libcrypto/cast/Makefile.uni b/lib/libcrypto/cast/Makefile.uni index 780073e75b9..a5870897cfa 100644 --- a/lib/libcrypto/cast/Makefile.uni +++ b/lib/libcrypto/cast/Makefile.uni @@ -24,6 +24,7 @@ MAKE= make MAKEDEPEND= makedepend MAKEFILE= Makefile.uni AR= ar r +RANLIB= ranlib CAST_ENC=c_enc.o # or use @@ -55,7 +56,7 @@ all: $(LIB) $(TEST) $(APPS) $(LIB): $(LIBOBJ) $(AR) $(LIB) $(LIBOBJ) - sh $(TOP)/ranlib.sh $(LIB) + $(RANLIB) $(LIB) # elf asm/cx86-elf.o: asm/cx86unix.cpp $(CPP) -DELF asm/cx86unix.cpp | as -o asm/cx86-elf.o diff --git a/lib/libcrypto/cast/asm/c-win32.asm b/lib/libcrypto/cast/asm/c-win32.asm index a1d8a2671a0..ba78a3c69c5 100644 --- a/lib/libcrypto/cast/asm/c-win32.asm +++ b/lib/libcrypto/cast/asm/c-win32.asm @@ -25,6 +25,9 @@ _CAST_encrypt PROC NEAR ; Load the 2 words mov edi, DWORD PTR [ebx] mov esi, DWORD PTR 4[ebx] + ; Get short key flag + mov eax, DWORD PTR 128[ebp] + push eax xor eax, eax ; round 0 mov edx, DWORD PTR [ebp] @@ -278,6 +281,10 @@ _CAST_encrypt PROC NEAR mov ebx, DWORD PTR _CAST_S_table3[edx*4] sub ecx, ebx xor esi, ecx + ; test short key flag + pop edx + or edx, edx + jnz $L000cast_enc_done ; round 12 mov edx, DWORD PTR 96[ebp] mov ecx, DWORD PTR 100[ebp] @@ -361,9 +368,10 @@ _CAST_encrypt PROC NEAR sub ecx, ebx mov ebx, DWORD PTR _CAST_S_table3[edx*4] add ecx, ebx - mov eax, DWORD PTR 20[esp] xor esi, ecx +$L000cast_enc_done: nop + mov eax, DWORD PTR 20[esp] mov DWORD PTR 4[eax],edi mov DWORD PTR [eax],esi pop edi @@ -391,6 +399,10 @@ _CAST_decrypt PROC NEAR ; Load the 2 words mov edi, DWORD PTR [ebx] mov esi, DWORD PTR 4[ebx] + ; Get short key flag + mov eax, DWORD PTR 128[ebp] + or eax, eax + jnz $L001cast_dec_skip xor eax, eax ; round 15 mov edx, DWORD PTR 120[ebp] @@ -476,6 +488,7 @@ _CAST_decrypt PROC NEAR mov ebx, DWORD PTR _CAST_S_table3[edx*4] add ecx, ebx xor esi, ecx +$L001cast_dec_skip: ; round 11 mov edx, DWORD PTR 88[ebp] mov ecx, DWORD PTR 92[ebp] @@ -727,9 +740,9 @@ _CAST_decrypt PROC NEAR sub ecx, ebx mov ebx, DWORD PTR _CAST_S_table3[edx*4] add ecx, ebx - mov eax, DWORD PTR 20[esp] xor esi, ecx nop + mov eax, DWORD PTR 20[esp] mov DWORD PTR 4[eax],edi mov DWORD PTR [eax],esi pop edi @@ -767,12 +780,12 @@ _CAST_cbc_encrypt PROC NEAR push eax push ebx cmp ecx, 0 - jz $L000decrypt + jz $L002decrypt and ebp, 4294967288 mov eax, DWORD PTR 8[esp] mov ebx, DWORD PTR 12[esp] - jz $L001encrypt_finish -L002encrypt_loop: + jz $L003encrypt_finish +L004encrypt_loop: mov ecx, DWORD PTR [esi] mov edx, DWORD PTR 4[esi] xor eax, ecx @@ -791,35 +804,35 @@ L002encrypt_loop: add esi, 8 add edi, 8 sub ebp, 8 - jnz L002encrypt_loop -$L001encrypt_finish: + jnz L004encrypt_loop +$L003encrypt_finish: mov ebp, DWORD PTR 52[esp] and ebp, 7 - jz $L003finish + jz $L005finish xor ecx, ecx xor edx, edx - mov ebp, DWORD PTR $L004cbc_enc_jmp_table[ebp*4] + mov ebp, DWORD PTR $L006cbc_enc_jmp_table[ebp*4] jmp ebp -L005ej7: +L007ej7: xor edx, edx mov dh, BYTE PTR 6[esi] shl edx, 8 -L006ej6: +L008ej6: mov dh, BYTE PTR 5[esi] -L007ej5: +L009ej5: mov dl, BYTE PTR 4[esi] -L008ej4: +L010ej4: mov ecx, DWORD PTR [esi] - jmp $L009ejend -L010ej3: + jmp $L011ejend +L012ej3: mov ch, BYTE PTR 2[esi] xor ecx, ecx shl ecx, 8 -L011ej2: +L013ej2: mov ch, BYTE PTR 1[esi] -L012ej1: +L014ej1: mov cl, BYTE PTR [esi] -$L009ejend: +$L011ejend: xor eax, ecx xor ebx, edx bswap eax @@ -833,13 +846,13 @@ $L009ejend: bswap ebx mov DWORD PTR [edi],eax mov DWORD PTR 4[edi],ebx - jmp $L003finish -$L000decrypt: + jmp $L005finish +$L002decrypt: and ebp, 4294967288 mov eax, DWORD PTR 16[esp] mov ebx, DWORD PTR 20[esp] - jz $L013decrypt_finish -L014decrypt_loop: + jz $L015decrypt_finish +L016decrypt_loop: mov eax, DWORD PTR [esi] mov ebx, DWORD PTR 4[esi] bswap eax @@ -864,11 +877,11 @@ L014decrypt_loop: add esi, 8 add edi, 8 sub ebp, 8 - jnz L014decrypt_loop -$L013decrypt_finish: + jnz L016decrypt_loop +$L015decrypt_finish: mov ebp, DWORD PTR 52[esp] and ebp, 7 - jz $L003finish + jz $L005finish mov eax, DWORD PTR [esi] mov ebx, DWORD PTR 4[esi] bswap eax @@ -886,28 +899,28 @@ $L013decrypt_finish: xor edx, ebx mov eax, DWORD PTR [esi] mov ebx, DWORD PTR 4[esi] -L015dj7: +L017dj7: ror edx, 16 mov BYTE PTR 6[edi],dl shr edx, 16 -L016dj6: +L018dj6: mov BYTE PTR 5[edi],dh -L017dj5: +L019dj5: mov BYTE PTR 4[edi],dl -L018dj4: +L020dj4: mov DWORD PTR [edi],ecx - jmp $L019djend -L020dj3: + jmp $L021djend +L022dj3: ror ecx, 16 mov BYTE PTR 2[edi],cl shl ecx, 16 -L021dj2: +L023dj2: mov BYTE PTR 1[esi],ch -L022dj1: +L024dj1: mov BYTE PTR [esi], cl -$L019djend: - jmp $L003finish -$L003finish: +$L021djend: + jmp $L005finish +$L005finish: mov ecx, DWORD PTR 60[esp] add esp, 24 mov DWORD PTR [ecx],eax @@ -917,24 +930,24 @@ $L003finish: pop ebx pop ebp ret -$L004cbc_enc_jmp_table: +$L006cbc_enc_jmp_table: DD 0 - DD L012ej1 - DD L011ej2 - DD L010ej3 - DD L008ej4 - DD L007ej5 - DD L006ej6 - DD L005ej7 -L023cbc_dec_jmp_table: + DD L014ej1 + DD L013ej2 + DD L012ej3 + DD L010ej4 + DD L009ej5 + DD L008ej6 + DD L007ej7 +L025cbc_dec_jmp_table: DD 0 - DD L022dj1 - DD L021dj2 - DD L020dj3 - DD L018dj4 - DD L017dj5 - DD L016dj6 - DD L015dj7 + DD L024dj1 + DD L023dj2 + DD L022dj3 + DD L020dj4 + DD L019dj5 + DD L018dj6 + DD L017dj7 _CAST_cbc_encrypt ENDP _TEXT ENDS END diff --git a/lib/libcrypto/cast/asm/cast-586.pl b/lib/libcrypto/cast/asm/cast-586.pl index d0be004c995..6be0bfe5724 100644 --- a/lib/libcrypto/cast/asm/cast-586.pl +++ b/lib/libcrypto/cast/asm/cast-586.pl @@ -1,4 +1,4 @@ -#!/usr/bin/perl +#!/usr/local/bin/perl # define for pentium pro friendly version $ppro=1; @@ -7,7 +7,7 @@ push(@INC,"perlasm","../../perlasm"); require "x86asm.pl"; require "cbc.pl"; -&asm_init($ARGV[0],"cast-586.pl"); +&asm_init($ARGV[0],"cast-586.pl",$ARGV[$#ARGV] eq "386"); $CAST_ROUNDS=16; $L="edi"; @@ -32,136 +32,145 @@ $S4="CAST_S_table3"; &asm_finish(); -sub CAST_encrypt - { - local($name,$enc)=@_; +sub CAST_encrypt { + local($name,$enc)=@_; - local($win_ex)=<<"EOF"; + local($win_ex)=<<"EOF"; EXTERN _CAST_S_table0:DWORD EXTERN _CAST_S_table1:DWORD EXTERN _CAST_S_table2:DWORD EXTERN _CAST_S_table3:DWORD EOF - &main'external_label( - "CAST_S_table0", - "CAST_S_table1", - "CAST_S_table2", - "CAST_S_table3", - ); - - &function_begin_B($name,$win_ex); - - &comment(""); - - &push("ebp"); - &push("ebx"); - &mov($tmp2,&wparam(0)); - &mov($K,&wparam(1)); - &push("esi"); - &push("edi"); - - &comment("Load the 2 words"); - &mov($L,&DWP(0,$tmp2,"",0)); - &mov($R,&DWP(4,$tmp2,"",0)); - - &xor( $tmp3, $tmp3); - - # encrypting part - - if ($enc) - { - &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); - } - else - { - &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); - &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4,1); - } - - &nop(); - &mov(&DWP(4,$tmp3,"",0),$L); - &mov(&DWP(0,$tmp3,"",0),$R); - &function_end($name); - } - -sub E_CAST - { - local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4,$lst)=@_; - # Ri needs to have 16 pre added. - - &comment("round $i"); - &mov( $tmp4, &DWP($i*8,$K,"",1)); - - &mov( $tmp1, &DWP($i*8+4,$K,"",1));# must be word - &$OP1( $tmp4, $R); - - &rotl( $tmp4, &LB($tmp1)); - - if ($ppro) - { - &mov( $tmp2, $tmp4); # B - &xor( $tmp1, $tmp1); - - &movb( &LB($tmp1), &HB($tmp4)); # A - &and( $tmp2, 0xff); - - &shr( $tmp4, 16); # - &xor( $tmp3, $tmp3); - } - else - { - &mov( $tmp2, $tmp4); # B - &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD - - &shr( $tmp4, 16); # - &and( $tmp2, 0xff); - } - - &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD - &and( $tmp4, 0xff); # D - - &mov( $tmp1, &DWP($S1,"",$tmp1,4)); - &mov( $tmp2, &DWP($S2,"",$tmp2,4)); - - &$OP2( $tmp1, $tmp2); - &mov( $tmp2, &DWP($S3,"",$tmp3,4)); - - &$OP3( $tmp1, $tmp2); - &mov( $tmp2, &DWP($S4,"",$tmp4,4)); - - &$OP1( $tmp1, $tmp2); - &mov($tmp3,&wparam(0)) if $lst; - # XXX - - &xor( $L, $tmp1); - # XXX - } + &main::external_label( + "CAST_S_table0", + "CAST_S_table1", + "CAST_S_table2", + "CAST_S_table3", + ); + + &function_begin_B($name,$win_ex); + + &comment(""); + + &push("ebp"); + &push("ebx"); + &mov($tmp2,&wparam(0)); + &mov($K,&wparam(1)); + &push("esi"); + &push("edi"); + + &comment("Load the 2 words"); + &mov($L,&DWP(0,$tmp2,"",0)); + &mov($R,&DWP(4,$tmp2,"",0)); + + &comment('Get short key flag'); + &mov($tmp3,&DWP(128,$K,"",0)); + if($enc) { + &push($tmp3); + } else { + &or($tmp3,$tmp3); + &jnz(&label('cast_dec_skip')); + } + + &xor($tmp3, $tmp3); + + # encrypting part + + if ($enc) { + &E_CAST( 0,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 1,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 2,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 3,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 4,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 5,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 6,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 7,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 8,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 9,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(10,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(11,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &comment('test short key flag'); + &pop($tmp4); + &or($tmp4,$tmp4); + &jnz(&label('cast_enc_done')); + &E_CAST(12,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(13,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(14,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(15,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + } else { + &E_CAST(15,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(14,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(13,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(12,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &set_label('cast_dec_skip'); + &E_CAST(11,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST(10,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 9,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 8,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 7,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 6,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 5,$S,$L,$R,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 4,$S,$R,$L,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 3,$S,$L,$R,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 2,$S,$R,$L,$K,@F3,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 1,$S,$L,$R,$K,@F2,$tmp1,$tmp2,$tmp3,$tmp4); + &E_CAST( 0,$S,$R,$L,$K,@F1,$tmp1,$tmp2,$tmp3,$tmp4); + } + + &set_label('cast_enc_done') if $enc; +# Why the nop? - Ben 17/1/99 + &nop(); + &mov($tmp3,&wparam(0)); + &mov(&DWP(4,$tmp3,"",0),$L); + &mov(&DWP(0,$tmp3,"",0),$R); + &function_end($name); +} + +sub E_CAST { + local($i,$S,$L,$R,$K,$OP1,$OP2,$OP3,$tmp1,$tmp2,$tmp3,$tmp4)=@_; + # Ri needs to have 16 pre added. + + &comment("round $i"); + &mov( $tmp4, &DWP($i*8,$K,"",1)); + + &mov( $tmp1, &DWP($i*8+4,$K,"",1)); + &$OP1( $tmp4, $R); + + &rotl( $tmp4, &LB($tmp1)); + + if ($ppro) { + &mov( $tmp2, $tmp4); # B + &xor( $tmp1, $tmp1); + + &movb( &LB($tmp1), &HB($tmp4)); # A + &and( $tmp2, 0xff); + + &shr( $tmp4, 16); # + &xor( $tmp3, $tmp3); + } else { + &mov( $tmp2, $tmp4); # B + &movb( &LB($tmp1), &HB($tmp4)); # A # BAD BAD BAD + + &shr( $tmp4, 16); # + &and( $tmp2, 0xff); + } + + &movb( &LB($tmp3), &HB($tmp4)); # C # BAD BAD BAD + &and( $tmp4, 0xff); # D + + &mov( $tmp1, &DWP($S1,"",$tmp1,4)); + &mov( $tmp2, &DWP($S2,"",$tmp2,4)); + + &$OP2( $tmp1, $tmp2); + &mov( $tmp2, &DWP($S3,"",$tmp3,4)); + + &$OP3( $tmp1, $tmp2); + &mov( $tmp2, &DWP($S4,"",$tmp4,4)); + + &$OP1( $tmp1, $tmp2); + # XXX + + &xor( $L, $tmp1); + # XXX +} + diff --git a/lib/libcrypto/cast/asm/cx86unix.cpp b/lib/libcrypto/cast/asm/cx86unix.cpp deleted file mode 100644 index 035692a5af7..00000000000 --- a/lib/libcrypto/cast/asm/cx86unix.cpp +++ /dev/null @@ -1,1010 +0,0 @@ -/* 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 - -#if defined(OUT) || defined(BSDI) -#define CAST_S_table0 _CAST_S_table0 -#define CAST_S_table1 _CAST_S_table1 -#define CAST_S_table2 _CAST_S_table2 -#define CAST_S_table3 _CAST_S_table3 -#define CAST_encrypt _CAST_encrypt -#define CAST_S_table0 _CAST_S_table0 -#define CAST_S_table1 _CAST_S_table1 -#define CAST_S_table2 _CAST_S_table2 -#define CAST_S_table3 _CAST_S_table3 -#define CAST_decrypt _CAST_decrypt -#define CAST_cbc_encrypt _CAST_cbc_encrypt - -#endif - -#ifdef OUT -#define OK 1 -#define ALIGN 4 -#endif - -#ifdef BSDI -#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 -#endif - -#ifndef OK -You need to define one of -ELF - elf systems - linux-elf, NetBSD and DG-UX -OUT - a.out systems - linux-a.out and FreeBSD -SOL - solaris systems, which are elf with strange comment lines -BSDI - a.out with a very primative version of as. -#endif - -/* Let the Assembler begin :-) */ - /* Don't even think of reading this code */ - /* It was automatically generated by cast-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 "cast-586.s" - .version "01.01" -gcc2_compiled.: -.text - .align ALIGN -.globl CAST_encrypt - TYPE(CAST_encrypt,@function) -CAST_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 - /* round 0 */ - movl (%ebp), %edx - movl 4(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 1 */ - movl 8(%ebp), %edx - movl 12(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 2 */ - movl 16(%ebp), %edx - movl 20(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 3 */ - movl 24(%ebp), %edx - movl 28(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 4 */ - movl 32(%ebp), %edx - movl 36(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 5 */ - movl 40(%ebp), %edx - movl 44(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 6 */ - movl 48(%ebp), %edx - movl 52(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 7 */ - movl 56(%ebp), %edx - movl 60(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 8 */ - movl 64(%ebp), %edx - movl 68(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 9 */ - movl 72(%ebp), %edx - movl 76(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 10 */ - movl 80(%ebp), %edx - movl 84(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 11 */ - movl 88(%ebp), %edx - movl 92(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 12 */ - movl 96(%ebp), %edx - movl 100(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 13 */ - movl 104(%ebp), %edx - movl 108(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 14 */ - movl 112(%ebp), %edx - movl 116(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 15 */ - movl 120(%ebp), %edx - movl 124(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - movl 20(%esp), %eax - xorl %ecx, %esi - nop - movl %edi, 4(%eax) - movl %esi, (%eax) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.CAST_encrypt_end: - SIZE(CAST_encrypt,.CAST_encrypt_end-CAST_encrypt) -.ident "CAST_encrypt" -.text - .align ALIGN -.globl CAST_decrypt - TYPE(CAST_decrypt,@function) -CAST_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 - /* round 15 */ - movl 120(%ebp), %edx - movl 124(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 14 */ - movl 112(%ebp), %edx - movl 116(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 13 */ - movl 104(%ebp), %edx - movl 108(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 12 */ - movl 96(%ebp), %edx - movl 100(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 11 */ - movl 88(%ebp), %edx - movl 92(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 10 */ - movl 80(%ebp), %edx - movl 84(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 9 */ - movl 72(%ebp), %edx - movl 76(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 8 */ - movl 64(%ebp), %edx - movl 68(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 7 */ - movl 56(%ebp), %edx - movl 60(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 6 */ - movl 48(%ebp), %edx - movl 52(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %esi - /* round 5 */ - movl 40(%ebp), %edx - movl 44(%ebp), %ecx - subl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %edi - /* round 4 */ - movl 32(%ebp), %edx - movl 36(%ebp), %ecx - xorl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %esi - /* round 3 */ - movl 24(%ebp), %edx - movl 28(%ebp), %ecx - addl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - xorl %ecx, %edi - /* round 2 */ - movl 16(%ebp), %edx - movl 20(%ebp), %ecx - subl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - addl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - subl %ebx, %ecx - xorl %ecx, %esi - /* round 1 */ - movl 8(%ebp), %edx - movl 12(%ebp), %ecx - xorl %esi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - subl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - addl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - xorl %ebx, %ecx - xorl %ecx, %edi - /* round 0 */ - movl (%ebp), %edx - movl 4(%ebp), %ecx - addl %edi, %edx - roll %cl, %edx - movl %edx, %ebx - xorl %ecx, %ecx - movb %dh, %cl - andl $255, %ebx - shrl $16, %edx - xorl %eax, %eax - movb %dh, %al - andl $255, %edx - movl CAST_S_table0(,%ecx,4),%ecx - movl CAST_S_table1(,%ebx,4),%ebx - xorl %ebx, %ecx - movl CAST_S_table2(,%eax,4),%ebx - subl %ebx, %ecx - movl CAST_S_table3(,%edx,4),%ebx - addl %ebx, %ecx - movl 20(%esp), %eax - xorl %ecx, %esi - nop - movl %edi, 4(%eax) - movl %esi, (%eax) - popl %edi - popl %esi - popl %ebx - popl %ebp - ret -.CAST_decrypt_end: - SIZE(CAST_decrypt,.CAST_decrypt_end-CAST_decrypt) -.ident "CAST_decrypt" -.text - .align ALIGN -.globl CAST_cbc_encrypt - TYPE(CAST_cbc_encrypt,@function) -CAST_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 CAST_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: - xorl %edx, %edx - 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 - xorl %ecx, %ecx - 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 CAST_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 CAST_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 CAST_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 -.CAST_cbc_encrypt_end: - SIZE(CAST_cbc_encrypt,.CAST_cbc_encrypt_end-CAST_cbc_encrypt) -.ident "desasm.pl" diff --git a/lib/libcrypto/cast/c_cfb64.c b/lib/libcrypto/cast/c_cfb64.c index c46c375f756..514c005c325 100644 --- a/lib/libcrypto/cast/c_cfb64.c +++ b/lib/libcrypto/cast/c_cfb64.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include <openssl/cast.h> #include "cast_lcl.h" /* The input and output encrypted as though 64bit cfb mode is being @@ -64,14 +64,9 @@ * 64bit block we have used is contained in *num; */ -void CAST_cfb64_encrypt(in, out, length, schedule, ivec, num, encrypt) -unsigned char *in; -unsigned char *out; -long length; -CAST_KEY *schedule; -unsigned char *ivec; -int *num; -int encrypt; +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num, int enc) { register CAST_LONG v0,v1,t; register int n= *num; @@ -79,8 +74,8 @@ int encrypt; CAST_LONG ti[2]; unsigned char *iv,c,cc; - iv=(unsigned char *)ivec; - if (encrypt) + iv=ivec; + if (enc) { while (l--) { @@ -89,10 +84,10 @@ int encrypt; n2l(iv,v0); ti[0]=v0; n2l(iv,v1); ti[1]=v1; CAST_encrypt((CAST_LONG *)ti,schedule); - iv=(unsigned char *)ivec; + iv=ivec; t=ti[0]; l2n(t,iv); t=ti[1]; l2n(t,iv); - iv=(unsigned char *)ivec; + iv=ivec; } c= *(in++)^iv[n]; *(out++)=c; @@ -109,10 +104,10 @@ int encrypt; n2l(iv,v0); ti[0]=v0; n2l(iv,v1); ti[1]=v1; CAST_encrypt((CAST_LONG *)ti,schedule); - iv=(unsigned char *)ivec; + iv=ivec; t=ti[0]; l2n(t,iv); t=ti[1]; l2n(t,iv); - iv=(unsigned char *)ivec; + iv=ivec; } cc= *(in++); c=iv[n]; diff --git a/lib/libcrypto/cast/c_ecb.c b/lib/libcrypto/cast/c_ecb.c index f0f2f4df0ed..33182f2b712 100644 --- a/lib/libcrypto/cast/c_ecb.c +++ b/lib/libcrypto/cast/c_ecb.c @@ -56,22 +56,20 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include <openssl/cast.h> #include "cast_lcl.h" +#include <openssl/opensslv.h> -char *CAST_version="CAST part of SSLeay 0.9.0b 29-Jun-1998"; +char *CAST_version="CAST" OPENSSL_VERSION_PTEXT; -void CAST_ecb_encrypt(in, out, ks, encrypt) -unsigned char *in; -unsigned char *out; -CAST_KEY *ks; -int encrypt; +void CAST_ecb_encrypt(const unsigned char *in, unsigned char *out, + CAST_KEY *ks, int enc) { CAST_LONG l,d[2]; n2l(in,l); d[0]=l; n2l(in,l); d[1]=l; - if (encrypt) + if (enc) CAST_encrypt(d,ks); else CAST_decrypt(d,ks); diff --git a/lib/libcrypto/cast/c_enc.c b/lib/libcrypto/cast/c_enc.c index d998dd4953e..0fe2cffeccf 100644 --- a/lib/libcrypto/cast/c_enc.c +++ b/lib/libcrypto/cast/c_enc.c @@ -56,12 +56,10 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include <openssl/cast.h> #include "cast_lcl.h" -void CAST_encrypt(data,key) -CAST_LONG *data; -CAST_KEY *key; +void CAST_encrypt(CAST_LONG *data, CAST_KEY *key) { register CAST_LONG l,r,*k,t; @@ -81,18 +79,19 @@ CAST_KEY *key; E_CAST( 9,k,r,l,+,^,-); E_CAST(10,k,l,r,^,-,+); E_CAST(11,k,r,l,-,+,^); - E_CAST(12,k,l,r,+,^,-); - E_CAST(13,k,r,l,^,-,+); - E_CAST(14,k,l,r,-,+,^); - E_CAST(15,k,r,l,+,^,-); + if(!key->short_key) + { + E_CAST(12,k,l,r,+,^,-); + E_CAST(13,k,r,l,^,-,+); + E_CAST(14,k,l,r,-,+,^); + E_CAST(15,k,r,l,+,^,-); + } data[1]=l&0xffffffffL; data[0]=r&0xffffffffL; } -void CAST_decrypt(data,key) -CAST_LONG *data; -CAST_KEY *key; +void CAST_decrypt(CAST_LONG *data, CAST_KEY *key) { register CAST_LONG l,r,*k,t; @@ -100,10 +99,13 @@ CAST_KEY *key; l=data[0]; r=data[1]; - E_CAST(15,k,l,r,+,^,-); - E_CAST(14,k,r,l,-,+,^); - E_CAST(13,k,l,r,^,-,+); - E_CAST(12,k,r,l,+,^,-); + if(!key->short_key) + { + E_CAST(15,k,l,r,+,^,-); + E_CAST(14,k,r,l,-,+,^); + E_CAST(13,k,l,r,^,-,+); + E_CAST(12,k,r,l,+,^,-); + } E_CAST(11,k,l,r,-,+,^); E_CAST(10,k,r,l,^,-,+); E_CAST( 9,k,l,r,+,^,-); @@ -121,20 +123,15 @@ CAST_KEY *key; data[0]=r&0xffffffffL; } -void CAST_cbc_encrypt(in, out, length, ks, iv, encrypt) -unsigned char *in; -unsigned char *out; -long length; -CAST_KEY *ks; -unsigned char *iv; -int encrypt; +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + CAST_KEY *ks, unsigned char *iv, int enc) { register CAST_LONG tin0,tin1; register CAST_LONG tout0,tout1,xor0,xor1; register long l=length; CAST_LONG tin[2]; - if (encrypt) + if (enc) { n2l(iv,tout0); n2l(iv,tout1); diff --git a/lib/libcrypto/cast/c_ofb64.c b/lib/libcrypto/cast/c_ofb64.c index 2aad2d6d969..fd0469a62fa 100644 --- a/lib/libcrypto/cast/c_ofb64.c +++ b/lib/libcrypto/cast/c_ofb64.c @@ -56,20 +56,16 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include <openssl/cast.h> #include "cast_lcl.h" /* The input and output encrypted as though 64bit ofb mode is being * used. The extra state information to record how much of the * 64bit block we have used is contained in *num; */ -void CAST_ofb64_encrypt(in, out, length, schedule, ivec, num) -unsigned char *in; -unsigned char *out; -long length; -CAST_KEY *schedule; -unsigned char *ivec; -int *num; +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num) { register CAST_LONG v0,v1,t; register int n= *num; @@ -80,7 +76,7 @@ int *num; unsigned char *iv; int save=0; - iv=(unsigned char *)ivec; + iv=ivec; n2l(iv,v0); n2l(iv,v1); ti[0]=v0; @@ -105,7 +101,7 @@ int *num; { v0=ti[0]; v1=ti[1]; - iv=(unsigned char *)ivec; + iv=ivec; l2n(v0,iv); l2n(v1,iv); } diff --git a/lib/libcrypto/cast/c_skey.c b/lib/libcrypto/cast/c_skey.c index 2fc3363dcd0..acf2c3eeb51 100644 --- a/lib/libcrypto/cast/c_skey.c +++ b/lib/libcrypto/cast/c_skey.c @@ -56,7 +56,7 @@ * [including the GNU Public Licence.] */ -#include "cast.h" +#include <openssl/cast.h> #include "cast_lcl.h" #include "cast_s.h" @@ -72,10 +72,7 @@ #define S6 CAST_S_table6 #define S7 CAST_S_table7 -void CAST_set_key(key,len,data) -CAST_KEY *key; -int len; -unsigned char *data; +void CAST_set_key(CAST_KEY *key, int len, unsigned char *data) { CAST_LONG x[16]; CAST_LONG z[16]; @@ -88,6 +85,10 @@ unsigned char *data; if (len > 16) len=16; for (i=0; i<len; i++) x[i]=data[i]; + if(len <= 10) + key->short_key=1; + else + key->short_key=0; K= &k[0]; X[0]=((x[ 0]<<24)|(x[ 1]<<16)|(x[ 2]<<8)|x[ 3])&0xffffffffL; diff --git a/lib/libcrypto/cast/cast.h b/lib/libcrypto/cast/cast.h index 528cb7c8244..6cc5e8aa8cf 100644 --- a/lib/libcrypto/cast/cast.h +++ b/lib/libcrypto/cast/cast.h @@ -63,6 +63,10 @@ extern "C" { #endif +#ifdef NO_CAST +#error CAST is disabled. +#endif + #define CAST_ENCRYPT 1 #define CAST_DECRYPT 0 @@ -74,33 +78,23 @@ extern "C" { typedef struct cast_key_st { CAST_LONG data[32]; + int short_key; /* Use reduced rounds for short key */ } CAST_KEY; -#ifndef NOPROTO void CAST_set_key(CAST_KEY *key, int len, unsigned char *data); -void CAST_ecb_encrypt(unsigned char *in,unsigned char *out,CAST_KEY *key, - int enc); +void CAST_ecb_encrypt(const unsigned char *in,unsigned char *out,CAST_KEY *key, + int enc); void CAST_encrypt(CAST_LONG *data,CAST_KEY *key); void CAST_decrypt(CAST_LONG *data,CAST_KEY *key); -void CAST_cbc_encrypt(unsigned char *in, unsigned char *out, long length, - CAST_KEY *ks, unsigned char *iv, int enc); -void CAST_cfb64_encrypt(unsigned char *in, unsigned char *out, long length, - CAST_KEY *schedule, unsigned char *ivec, int *num, int enc); -void CAST_ofb64_encrypt(unsigned char *in, unsigned char *out, long length, - CAST_KEY *schedule, unsigned char *ivec, int *num); - -#else - -void CAST_set_key(); -void CAST_ecb_encrypt(); -void CAST_encrypt(); -void CAST_decrypt(); -void CAST_cbc_encrypt(); -void CAST_cfb64_encrypt(); -void CAST_ofb64_encrypt(); - -#endif +void CAST_cbc_encrypt(const unsigned char *in, unsigned char *out, long length, + CAST_KEY *ks, unsigned char *iv, int enc); +void CAST_cfb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num, int enc); +void CAST_ofb64_encrypt(const unsigned char *in, unsigned char *out, + long length, CAST_KEY *schedule, unsigned char *ivec, + int *num); #ifdef __cplusplus } diff --git a/lib/libcrypto/cast/cast_lcl.h b/lib/libcrypto/cast/cast_lcl.h index 6587952a969..83cf382a914 100644 --- a/lib/libcrypto/cast/cast_lcl.h +++ b/lib/libcrypto/cast/cast_lcl.h @@ -60,6 +60,9 @@ #include <stdlib.h> #endif + +#include "openssl/e_os.h" /* OPENSSL_EXTERN */ + #undef c2l #define c2l(c,l) (l =((unsigned long)(*((c)++))) , \ l|=((unsigned long)(*((c)++)))<< 8L, \ @@ -213,12 +216,11 @@ } #endif -extern CAST_LONG CAST_S_table0[256]; -extern CAST_LONG CAST_S_table1[256]; -extern CAST_LONG CAST_S_table2[256]; -extern CAST_LONG CAST_S_table3[256]; -extern CAST_LONG CAST_S_table4[256]; -extern CAST_LONG CAST_S_table5[256]; -extern CAST_LONG CAST_S_table6[256]; -extern CAST_LONG CAST_S_table7[256]; - +OPENSSL_EXTERN CAST_LONG CAST_S_table0[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table1[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table2[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table3[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table4[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table5[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table6[256]; +OPENSSL_EXTERN CAST_LONG CAST_S_table7[256]; diff --git a/lib/libcrypto/cast/cast_s.h b/lib/libcrypto/cast/cast_s.h index 8fe01521490..9af28972c51 100644 --- a/lib/libcrypto/cast/cast_s.h +++ b/lib/libcrypto/cast/cast_s.h @@ -55,7 +55,7 @@ * copied and put under another distribution licence * [including the GNU Public Licence.] */ -CAST_LONG CAST_S_table0[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table0[256]={ 0x30fb40d4,0x9fa0ff0b,0x6beccd2f,0x3f258c7a, 0x1e213f2f,0x9c004dd3,0x6003e540,0xcf9fc949, 0xbfd4af27,0x88bbbdb5,0xe2034090,0x98d09675, @@ -121,7 +121,7 @@ CAST_LONG CAST_S_table0[256]={ 0x1a69e783,0x02cc4843,0xa2f7c579,0x429ef47d, 0x427b169c,0x5ac9f049,0xdd8f0f00,0x5c8165bf, }; -CAST_LONG CAST_S_table1[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table1[256]={ 0x1f201094,0xef0ba75b,0x69e3cf7e,0x393f4380, 0xfe61cf7a,0xeec5207a,0x55889c94,0x72fc0651, 0xada7ef79,0x4e1d7235,0xd55a63ce,0xde0436ba, @@ -187,7 +187,7 @@ CAST_LONG CAST_S_table1[256]={ 0x43d79572,0x7e6dd07c,0x06dfdf1e,0x6c6cc4ef, 0x7160a539,0x73bfbe70,0x83877605,0x4523ecf1, }; -CAST_LONG CAST_S_table2[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table2[256]={ 0x8defc240,0x25fa5d9f,0xeb903dbf,0xe810c907, 0x47607fff,0x369fe44b,0x8c1fc644,0xaececa90, 0xbeb1f9bf,0xeefbcaea,0xe8cf1950,0x51df07ae, @@ -253,7 +253,7 @@ CAST_LONG CAST_S_table2[256]={ 0xf7baefd5,0x4142ed9c,0xa4315c11,0x83323ec5, 0xdfef4636,0xa133c501,0xe9d3531c,0xee353783, }; -CAST_LONG CAST_S_table3[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table3[256]={ 0x9db30420,0x1fb6e9de,0xa7be7bef,0xd273a298, 0x4a4f7bdb,0x64ad8c57,0x85510443,0xfa020ed1, 0x7e287aff,0xe60fb663,0x095f35a1,0x79ebf120, @@ -319,7 +319,7 @@ CAST_LONG CAST_S_table3[256]={ 0x7ae5290c,0x3cb9536b,0x851e20fe,0x9833557e, 0x13ecf0b0,0xd3ffb372,0x3f85c5c1,0x0aef7ed2, }; -CAST_LONG CAST_S_table4[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table4[256]={ 0x7ec90c04,0x2c6e74b9,0x9b0e66df,0xa6337911, 0xb86a7fff,0x1dd358f5,0x44dd9d44,0x1731167f, 0x08fbf1fa,0xe7f511cc,0xd2051b00,0x735aba00, @@ -385,7 +385,7 @@ CAST_LONG CAST_S_table4[256]={ 0xe822fe15,0x88570983,0x750e6249,0xda627e55, 0x5e76ffa8,0xb1534546,0x6d47de08,0xefe9e7d4, }; -CAST_LONG CAST_S_table5[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table5[256]={ 0xf6fa8f9d,0x2cac6ce1,0x4ca34867,0xe2337f7c, 0x95db08e7,0x016843b4,0xeced5cbc,0x325553ac, 0xbf9f0960,0xdfa1e2ed,0x83f0579d,0x63ed86b9, @@ -451,7 +451,7 @@ CAST_LONG CAST_S_table5[256]={ 0xa2d762cf,0x49c92f54,0x38b5f331,0x7128a454, 0x48392905,0xa65b1db8,0x851c97bd,0xd675cf2f, }; -CAST_LONG CAST_S_table6[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table6[256]={ 0x85e04019,0x332bf567,0x662dbfff,0xcfc65693, 0x2a8d7f6f,0xab9bc912,0xde6008a1,0x2028da1f, 0x0227bce7,0x4d642916,0x18fac300,0x50f18b82, @@ -517,7 +517,7 @@ CAST_LONG CAST_S_table6[256]={ 0x518f36b2,0x84b1d370,0x0fedce83,0x878ddada, 0xf2a279c7,0x94e01be8,0x90716f4b,0x954b8aa3, }; -CAST_LONG CAST_S_table7[256]={ +OPENSSL_GLOBAL CAST_LONG CAST_S_table7[256]={ 0xe216300d,0xbbddfffc,0xa7ebdabd,0x35648095, 0x7789f8b7,0xe6c1121b,0x0e241600,0x052ce8b5, 0x11a9cfb0,0xe5952f11,0xece7990a,0x9386d174, diff --git a/lib/libcrypto/cast/cast_spd.c b/lib/libcrypto/cast/cast_spd.c index ab75e65386b..c0726906c20 100644 --- a/lib/libcrypto/cast/cast_spd.c +++ b/lib/libcrypto/cast/cast_spd.c @@ -59,19 +59,17 @@ /* 11-Sep-92 Andrew Daviel Support for Silicon Graphics IRIX added */ /* 06-Apr-92 Luke Brennan Support for VMS and add extra signal calls */ -#ifndef MSDOS +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include <stdio.h> -#ifndef MSDOS -#include <unistd.h> -#else -#include <io.h> -extern int exit(); -#endif + +#include <openssl/e_os2.h> +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include <signal.h> -#ifndef VMS #ifndef _IRIX #include <time.h> #endif @@ -79,34 +77,31 @@ extern int exit(); #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 :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include <sys/timeb.h> #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include <limits.h> #include <sys/param.h> #endif -#include "cast.h" +#include <openssl/cast.h> /* The following if from times(3) man page. It may need to be changed */ #ifndef HZ #ifndef CLK_TCK -#ifndef VMS -#define HZ 100.0 -#else /* VMS */ #define HZ 100.0 -#endif #else /* CLK_TCK */ #define HZ ((double)CLK_TCK) #endif @@ -115,12 +110,7 @@ struct tms { #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) || defined(_AIX) #define SIGRETTYPE void @@ -128,14 +118,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -148,8 +132,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -185,9 +168,7 @@ int s; #endif } -int main(argc,argv) -int argc; -char **argv; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/lib/libcrypto/cast/castopts.c b/lib/libcrypto/cast/castopts.c index 68cf5a4a60b..642e9725af6 100644 --- a/lib/libcrypto/cast/castopts.c +++ b/lib/libcrypto/cast/castopts.c @@ -59,19 +59,17 @@ /* 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 +#if !defined(MSDOS) && (!defined(VMS) || defined(__DECC)) #define TIMES #endif #include <stdio.h> -#ifndef MSDOS -#include <unistd.h> -#else -#include <io.h> -extern void exit(); -#endif + +#include <openssl/e_os2.h> +#include OPENSSL_UNISTD_IO +OPENSSL_DECLARE_EXIT + #include <signal.h> -#ifndef VMS #ifndef _IRIX #include <time.h> #endif @@ -79,25 +77,26 @@ extern void exit(); #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 :-) */ - } + +/* Depending on the VMS version, the tms structure is perhaps defined. + The __TMS macro will show if it was. If it wasn't defined, we should + undefine TIMES, since that tells the rest of the program how things + should be handled. -- Richard Levitte */ +#if defined(VMS) && defined(__DECC) && !defined(__TMS) +#undef TIMES #endif + #ifndef TIMES #include <sys/timeb.h> #endif -#ifdef sun +#if defined(sun) || defined(__ultrix) +#define _POSIX_SOURCE #include <limits.h> #include <sys/param.h> #endif -#include "cast.h" +#include <openssl/cast.h> #define CAST_DEFAULT_OPTIONS @@ -136,11 +135,7 @@ struct tms { #ifndef HZ # ifndef CLK_TCK # ifndef _BSD_CLK_TCK_ /* FreeBSD fix */ -# ifndef VMS -# define HZ 100.0 -# else /* VMS */ -# define HZ 100.0 -# endif +# define HZ 100.0 # else /* _BSD_CLK_TCK_ */ # define HZ ((double)_BSD_CLK_TCK_) # endif @@ -152,12 +147,7 @@ struct tms { #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 @@ -165,14 +155,8 @@ double Time_F(); #define SIGRETTYPE int #endif -#ifndef NOPROTO SIGRETTYPE sig_done(int sig); -#else -SIGRETTYPE sig_done(); -#endif - -SIGRETTYPE sig_done(sig) -int sig; +SIGRETTYPE sig_done(int sig) { signal(SIGALRM,sig_done); run=0; @@ -185,8 +169,7 @@ int sig; #define START 0 #define STOP 1 -double Time_F(s) -int s; +double Time_F(int s) { double ret; #ifdef TIMES @@ -247,9 +230,7 @@ int s; 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; +int main(int argc, char **argv) { long count; static unsigned char buf[BUFSIZE]; diff --git a/lib/libcrypto/cast/casts.cpp b/lib/libcrypto/cast/casts.cpp index bac7be2c9c1..8d7bd468d22 100644 --- a/lib/libcrypto/cast/casts.cpp +++ b/lib/libcrypto/cast/casts.cpp @@ -32,7 +32,7 @@ void GetTSC(unsigned long& tsc) #include <stdio.h> #include <stdlib.h> -#include "cast.h" +#include <openssl/cast.h> void main(int argc,char *argv[]) { diff --git a/lib/libcrypto/cast/casttest.c b/lib/libcrypto/cast/casttest.c index 8b009bc2492..3244b119e95 100644 --- a/lib/libcrypto/cast/casttest.c +++ b/lib/libcrypto/cast/casttest.c @@ -59,9 +59,17 @@ #include <stdio.h> #include <string.h> #include <stdlib.h> -#include "cast.h" -/* #define FULL_TEST */ +#ifdef NO_CAST +int main(int argc, char *argv[]) +{ + printf("No CAST support\n"); + return(0); +} +#else +#include <openssl/cast.h> + +#define FULL_TEST unsigned char k[16]={ 0x01,0x23,0x45,0x67,0x12,0x34,0x56,0x78, @@ -70,7 +78,7 @@ unsigned char k[16]={ unsigned char in[8]={ 0x01,0x23,0x45,0x67,0x89,0xAB,0xCD,0xEF}; -int k_len[3]={16,10}; +int k_len[3]={16,10,5}; unsigned char c[3][8]={ {0x23,0x8B,0x4F,0xE5,0x84,0x7E,0x44,0xB2}, {0xEB,0x6A,0x71,0x1A,0x2C,0x02,0x27,0x1B}, @@ -120,104 +128,103 @@ static unsigned char cfb_cipher64[CFB_TEST_SIZE]={ }; #endif -int main(argc,argv) -int argc; -char *argv[]; - { +int main(int argc, char *argv[]) + { #ifdef FULL_TEST - long l; - CAST_KEY key_b; + long l; + CAST_KEY key_b; #endif - int i,z,err=0; - CAST_KEY key; + int i,z,err=0; + CAST_KEY key; - for (z=0; z<1; z++) - { + for (z=0; z<3; z++) + { CAST_set_key(&key,k_len[z],k); CAST_ecb_encrypt(in,out,&key,CAST_ENCRYPT); if (memcmp(out,&(c[z][0]),8) != 0) - { - printf("ecb cast error encrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",c[z][i]); - err=20; - printf("\n"); - } + { + printf("ecb cast error encrypting for keysize %d\n",k_len[z]*8); + printf("got :"); + for (i=0; i<8; i++) + printf("%02X ",out[i]); + printf("\n"); + printf("expected:"); + for (i=0; i<8; i++) + printf("%02X ",c[z][i]); + err=20; + printf("\n"); + } CAST_ecb_encrypt(out,out,&key,CAST_DECRYPT); if (memcmp(out,in,8) != 0) - { - printf("ecb cast error decrypting\n"); - printf("got :"); - for (i=0; i<8; i++) - printf("%02X ",out[i]); - printf("\n"); - printf("expected:"); - for (i=0; i<8; i++) - printf("%02X ",in[i]); - printf("\n"); - err=3; - } + { + printf("ecb cast error decrypting for keysize %d\n",k_len[z]*8); + printf("got :"); + for (i=0; i<8; i++) + printf("%02X ",out[i]); + printf("\n"); + printf("expected:"); + for (i=0; i<8; i++) + printf("%02X ",in[i]); + printf("\n"); + err=3; + } } - if (err == 0) printf("ecb cast5 ok\n"); + if (err == 0) + printf("ecb cast5 ok\n"); #ifdef FULL_TEST - { - unsigned char out_a[16],out_b[16]; - static char *hex="0123456789ABCDEF"; - - printf("This test will take some time...."); - fflush(stdout); - memcpy(out_a,in_a,sizeof(in_a)); - memcpy(out_b,in_b,sizeof(in_b)); - i=1; - - for (l=0; l<1000000L; l++) - { - CAST_set_key(&key_b,16,out_b); - CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); - CAST_set_key(&key,16,out_a); - CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); - CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); - if ((l & 0xffff) == 0xffff) - { - printf("%c",hex[i&0x0f]); - fflush(stdout); - i++; - } - } - - if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || + { + unsigned char out_a[16],out_b[16]; + static char *hex="0123456789ABCDEF"; + + printf("This test will take some time...."); + fflush(stdout); + memcpy(out_a,in_a,sizeof(in_a)); + memcpy(out_b,in_b,sizeof(in_b)); + i=1; + + for (l=0; l<1000000L; l++) + { + CAST_set_key(&key_b,16,out_b); + CAST_ecb_encrypt(&(out_a[0]),&(out_a[0]),&key_b,CAST_ENCRYPT); + CAST_ecb_encrypt(&(out_a[8]),&(out_a[8]),&key_b,CAST_ENCRYPT); + CAST_set_key(&key,16,out_a); + CAST_ecb_encrypt(&(out_b[0]),&(out_b[0]),&key,CAST_ENCRYPT); + CAST_ecb_encrypt(&(out_b[8]),&(out_b[8]),&key,CAST_ENCRYPT); + if ((l & 0xffff) == 0xffff) + { + printf("%c",hex[i&0x0f]); + fflush(stdout); + i++; + } + } + + if ( (memcmp(out_a,c_a,sizeof(c_a)) != 0) || (memcmp(out_b,c_b,sizeof(c_b)) != 0)) - { - printf("\n"); - printf("Error\n"); - - printf("A out ="); - for (i=0; i<16; i++) printf("%02X ",out_a[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_a[i]); - printf("\n"); - - printf("B out ="); - for (i=0; i<16; i++) printf("%02X ",out_b[i]); - printf("\nactual="); - for (i=0; i<16; i++) printf("%02X ",c_b[i]); - printf("\n"); - } - else - printf(" ok\n"); - } + { + printf("\n"); + printf("Error\n"); + + printf("A out ="); + for (i=0; i<16; i++) printf("%02X ",out_a[i]); + printf("\nactual="); + for (i=0; i<16; i++) printf("%02X ",c_a[i]); + printf("\n"); + + printf("B out ="); + for (i=0; i<16; i++) printf("%02X ",out_b[i]); + printf("\nactual="); + for (i=0; i<16; i++) printf("%02X ",c_b[i]); + printf("\n"); + } + else + printf(" ok\n"); + } #endif - exit(err); - return(err); - } - + exit(err); + return(err); + } +#endif |