diff options
Diffstat (limited to 'secure/lib/libdes/doPC2')
-rw-r--r-- | secure/lib/libdes/doPC2 | 94 |
1 files changed, 94 insertions, 0 deletions
diff --git a/secure/lib/libdes/doPC2 b/secure/lib/libdes/doPC2 new file mode 100644 index 0000000..fa5cf74 --- /dev/null +++ b/secure/lib/libdes/doPC2 @@ -0,0 +1,94 @@ +#!/usr/local/bin/perl + +@PC2_C=(14,17,11,24, 1, 5, + 3,28,15, 6,21,10, + 23,19,12, 4,26, 8, + 16, 7,27,20,13, 2, + ); + +@PC2_D=(41,52,31,37,47,55, + 30,40,51,45,33,48, + 44,49,39,56,34,53, + 46,42,50,36,29,32, + ); + +$i=0; +foreach (@PC2_C) { + $_--; +# printf "%2d,",$_; + $C{$_}=$i; + ++$i; +# print "\n" if ((($i) % 8) == 0); + } +$i=0; +#print "\n"; +foreach (@PC2_D) { + $_-=28; + $_--; +# printf "%2d,",$_; + $D{$_}=$i; + $i++; +# print "\n" if ((($i) % 8) == 0); + } + +#print "\n"; +foreach $i (0 .. 27) + { + $_=$C{$i}; +# printf "%2d,",$_; + $i++; +# print "\n" if ((($i) % 8) == 0); + } +#print "\n"; + +#print "\n"; +foreach $i (0 .. 27) + { + $_=$D{$i}; +# printf "%2d,",$_; + $i++; +# print "\n" if ((($i) % 8) == 0); + } +#print "\n"; + +print "static ulong skb[8][64]={\n"; +&doit("C",*C, 0, 1, 2, 3, 4, 5); +&doit("C",*C, 6, 7, 9,10,11,12); +&doit("C",*C,13,14,15,16,18,19); +&doit("C",*C,20,22,23,25,26,27); + +&doit("D",*D, 0, 1, 2, 3, 4, 5); +&doit("D",*D, 7, 8,10,11,12,13); +&doit("D",*D,15,16,17,18,19,20); +&doit("D",*D,21,22,23,24,26,27); +print "};\n"; + +sub doit + { + local($l,*A,@b)=@_; + local(@out); + + printf("/* for $l bits (numbered as per FIPS 46) %d %d %d %d %d %d */\n", + $b[0]+1, $b[1]+1, $b[2]+1, $b[3]+1, $b[4]+1, $b[5]+1); + for ($i=0; $i<64; $i++) + { + $out[$i]=0; + $j=1; +#print "\n"; + for ($k=0; $k<6; $k++) + { + $l=$A{$b[$k]}; +#print"$l - "; + if ((1<<$k) & $i) + { + $ll=int($l/6)*8+($l%6); + $out[$i]|=1<<($ll); + } + } + $pp=$out[$i]; + $pp=($pp&0xff0000ff)| (($pp&0x00ff0000)>>8)| + (($pp&0x0000ff00)<<8); + printf("0x%08X,",$pp); + print "\n" if (($i+1) % 4 == 0); + } + } |