diff options
Diffstat (limited to 'crypto/des')
-rw-r--r-- | crypto/des/Makefile.ssl | 16 | ||||
-rw-r--r-- | crypto/des/asm/crypt586.pl | 45 | ||||
-rw-r--r-- | crypto/des/asm/des-586.pl | 49 |
3 files changed, 59 insertions, 51 deletions
diff --git a/crypto/des/Makefile.ssl b/crypto/des/Makefile.ssl index ebf0806b64..aedfbb4cb4 100644 --- a/crypto/des/Makefile.ssl +++ b/crypto/des/Makefile.ssl @@ -67,19 +67,27 @@ des: des.o cbc3_enc.o lib # elf asm/dx86-elf.o: asm/dx86unix.cpp - $(CPP) -DELF -x c asm/dx86unix.cpp | as -o asm/dx86-elf.o + $(CPP) -DELF \ + `(echo $(CFLAGS) | egrep -ie '-[fK]PIC') > /dev/null 2>&1 && echo -DPIC`\ + -x c asm/dx86unix.cpp | as -o asm/dx86-elf.o asm/yx86-elf.o: asm/yx86unix.cpp - $(CPP) -DELF -x c asm/yx86unix.cpp | as -o asm/yx86-elf.o + $(CPP) -DELF \ + `(echo $(CFLAGS) | egrep -ie '-[fK]PIC') > /dev/null 2>&1 && echo -DPIC`\ + -x c asm/yx86unix.cpp | as -o asm/yx86-elf.o # solaris asm/dx86-sol.o: asm/dx86unix.cpp - $(CC) -E -DSOL asm/dx86unix.cpp | sed 's/^#.*//' > asm/dx86-sol.s + $(CC) -E -DSOL \ + `(echo $(CFLAGS) | egrep -ie '-[fK]PIC') > /dev/null 2>&1 && echo -DPIC`\ + asm/dx86unix.cpp | sed 's/^#.*//' > asm/dx86-sol.s as -o asm/dx86-sol.o asm/dx86-sol.s rm -f asm/dx86-sol.s asm/yx86-sol.o: asm/yx86unix.cpp - $(CC) -E -DSOL asm/yx86unix.cpp | sed 's/^#.*//' > asm/yx86-sol.s + $(CC) -E -DSOL \ + `(echo $(CFLAGS) | egrep -ie '-[fK]PIC') > /dev/null 2>&1 && echo -DPIC`\ + asm/yx86unix.cpp | sed 's/^#.*//' > asm/yx86-sol.s as -o asm/yx86-sol.o asm/yx86-sol.s rm -f asm/yx86-sol.s diff --git a/crypto/des/asm/crypt586.pl b/crypto/des/asm/crypt586.pl index 3d41d82f69..51fb3ddf26 100644 --- a/crypto/des/asm/crypt586.pl +++ b/crypto/des/asm/crypt586.pl @@ -26,11 +26,17 @@ sub fcrypt_body &comment(""); &comment("Load the 2 words"); - $ks="ebp"; + $trans="ebp"; &xor( $L, $L); &xor( $R, $R); - &mov($ks,&wparam(1)); + + # PIC-ification:-) + if ($cpp) { &picmeup("edx","DES_SPtrans"); } + else { &lea("edx",&DWP("DES_SPtrans")); } + &push("edx"); # becomes &swtmp(1) + # + &mov($trans,&wparam(1)); # reloaded with DES_SPtrans in D_ENCRYPT &push(&DWC(25)); # add a variable @@ -39,11 +45,11 @@ sub fcrypt_body { &comment(""); &comment("Round $i"); - &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); + &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); &comment(""); &comment("Round ".sprintf("%d",$i+1)); - &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); + &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx"); } &mov("ebx", &swtmp(0)); &mov("eax", $L); @@ -61,14 +67,14 @@ sub fcrypt_body &mov(&DWP(0,"edx","",0),"eax"); &mov(&DWP(4,"edx","",0),$L); - &pop("ecx"); # remove variable + &add("esp",8); # remove variables &function_end($name); } sub D_ENCRYPT { - local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; + local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; &mov( $u, &wparam(2)); # 2 &mov( $t, $R); @@ -85,9 +91,9 @@ sub D_ENCRYPT &shl( $tmp2, 16); # 1 &xor( $u, $tmp1); # 2 &xor( $t, $tmp2); # 2 - &mov( $tmp1, &DWP(&n2a($S*4),$ks,"",0)); # 2 + &mov( $tmp1, &DWP(&n2a($S*4),$trans,"",0)); # 2 &xor( $u, $tmp1); - &mov( $tmp2, &DWP(&n2a(($S+1)*4),$ks,"",0)); # 2 + &mov( $tmp2, &DWP(&n2a(($S+1)*4),$trans,"",0)); # 2 &xor( $u, $R); &xor( $t, $R); &xor( $t, $tmp2); @@ -99,31 +105,28 @@ sub D_ENCRYPT &movb( &LB($tmp1), &LB($u) ); &movb( &LB($tmp2), &HB($u) ); &rotr( $t, 4 ); - &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); + &mov( $trans, &swtmp(1)); + &xor( $L, &DWP(" ",$trans,$tmp1,0)); &movb( &LB($tmp1), &LB($t) ); - &xor( $L, $ks); - &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); - &xor( $L, $ks); + &xor( $L, &DWP("0x200",$trans,$tmp2,0)); &movb( &LB($tmp2), &HB($t) ); &shr( $u, 16); - &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); - &xor( $L, $ks); + &xor( $L, &DWP("0x100",$trans,$tmp1,0)); &movb( &LB($tmp1), &HB($u) ); &shr( $t, 16); - &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); - &xor( $L, $ks); - &mov( $ks, &wparam(1)); + &xor( $L, &DWP("0x300",$trans,$tmp2,0)); &movb( &LB($tmp2), &HB($t) ); &and( $u, "0xff" ); &and( $t, "0xff" ); - &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); + &mov( $tmp1, &DWP("0x600",$trans,$tmp1,0)); &xor( $L, $tmp1); - &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); + &mov( $tmp1, &DWP("0x700",$trans,$tmp2,0)); &xor( $L, $tmp1); - &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); + &mov( $tmp1, &DWP("0x400",$trans,$u,0)); &xor( $L, $tmp1); - &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); + &mov( $tmp1, &DWP("0x500",$trans,$t,0)); &xor( $L, $tmp1); + &mov( $trans, &wparam(1)); } sub n2a diff --git a/crypto/des/asm/des-586.pl b/crypto/des/asm/des-586.pl index 0d08e8a3a9..7a58869289 100644 --- a/crypto/des/asm/des-586.pl +++ b/crypto/des/asm/des-586.pl @@ -40,7 +40,7 @@ sub DES_encrypt &comment(""); &comment("Load the 2 words"); - $ks="ebp"; + $trans="ebp"; if ($do_ip) { @@ -72,7 +72,11 @@ sub DES_encrypt &rotl($L,3); } - &mov( $ks, &wparam(1) ); + # PIC-ification:-) + if ($cpp) { &picmeup($trans,"DES_SPtrans"); } + else { &lea($trans,&DWP("DES_SPtrans")); } + + &mov( "ecx", &wparam(1) ); &cmp("ebx","0"); &je(&label("start_decrypt")); @@ -80,11 +84,11 @@ sub DES_encrypt { &comment(""); &comment("Round $i"); - &D_ENCRYPT($i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); + &D_ENCRYPT($i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); &comment(""); &comment("Round ".sprintf("%d",$i+1)); - &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); + &D_ENCRYPT($i+1,$R,$L,($i+1)*2,$trans,"eax","ebx","ecx","edx"); } &jmp(&label("end")); @@ -94,10 +98,10 @@ sub DES_encrypt { &comment(""); &comment("Round $i"); - &D_ENCRYPT(15-$i,$L,$R,$i*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); + &D_ENCRYPT(15-$i,$L,$R,$i*2,$trans,"eax","ebx","ecx","edx"); &comment(""); &comment("Round ".sprintf("%d",$i-1)); - &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$ks,"DES_SPtrans","eax","ebx","ecx","edx"); + &D_ENCRYPT(15-$i+1,$R,$L,($i-1)*2,$trans,"eax","ebx","ecx","edx"); } &set_label("end"); @@ -134,43 +138,36 @@ sub DES_encrypt sub D_ENCRYPT { - local($r,$L,$R,$S,$ks,$desSP,$u,$tmp1,$tmp2,$t)=@_; + local($r,$L,$R,$S,$trans,$u,$tmp1,$tmp2,$t)=@_; - &mov( $u, &DWP(&n2a($S*4),$ks,"",0)); + &mov( $u, &DWP(&n2a($S*4),$tmp2,"",0)); &xor( $tmp1, $tmp1); - &mov( $t, &DWP(&n2a(($S+1)*4),$ks,"",0)); + &mov( $t, &DWP(&n2a(($S+1)*4),$tmp2,"",0)); &xor( $u, $R); + &xor( $tmp2, $tmp2); &xor( $t, $R); &and( $u, "0xfcfcfcfc" ); &and( $t, "0xcfcfcfcf" ); &movb( &LB($tmp1), &LB($u) ); &movb( &LB($tmp2), &HB($u) ); &rotr( $t, 4 ); - &mov( $ks, &DWP(" $desSP",$tmp1,"",0)); + &xor( $L, &DWP(" ",$trans,$tmp1,0)); &movb( &LB($tmp1), &LB($t) ); - &xor( $L, $ks); - &mov( $ks, &DWP("0x200+$desSP",$tmp2,"",0)); - &xor( $L, $ks); ###### + &xor( $L, &DWP("0x200",$trans,$tmp2,0)); &movb( &LB($tmp2), &HB($t) ); &shr( $u, 16); - &mov( $ks, &DWP("0x100+$desSP",$tmp1,"",0)); - &xor( $L, $ks); ###### + &xor( $L, &DWP("0x100",$trans,$tmp1,0)); &movb( &LB($tmp1), &HB($u) ); &shr( $t, 16); - &mov( $ks, &DWP("0x300+$desSP",$tmp2,"",0)); - &xor( $L, $ks); - &mov( $ks, &wparam(1) ); + &xor( $L, &DWP("0x300",$trans,$tmp2,0)); &movb( &LB($tmp2), &HB($t) ); &and( $u, "0xff" ); &and( $t, "0xff" ); - &mov( $tmp1, &DWP("0x600+$desSP",$tmp1,"",0)); - &xor( $L, $tmp1); - &mov( $tmp1, &DWP("0x700+$desSP",$tmp2,"",0)); - &xor( $L, $tmp1); - &mov( $tmp1, &DWP("0x400+$desSP",$u,"",0)); - &xor( $L, $tmp1); - &mov( $tmp1, &DWP("0x500+$desSP",$t,"",0)); - &xor( $L, $tmp1); + &xor( $L, &DWP("0x600",$trans,$tmp1,0)); + &xor( $L, &DWP("0x700",$trans,$tmp2,0)); + &mov( $tmp2, &wparam(1) ); + &xor( $L, &DWP("0x400",$trans,$u,0)); + &xor( $L, &DWP("0x500",$trans,$t,0)); } sub n2a |