summaryrefslogtreecommitdiffstats
path: root/secure/lib/libdes/doPC2
blob: fa5cf74cf71319dbedb4ad3ea923009b91e623e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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);
		}
	}
OpenPOWER on IntegriCloud