summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/des/doPC1
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libcrypto/des/doPC1')
-rw-r--r--src/lib/libcrypto/des/doPC1110
1 files changed, 110 insertions, 0 deletions
diff --git a/src/lib/libcrypto/des/doPC1 b/src/lib/libcrypto/des/doPC1
new file mode 100644
index 0000000000..096afd8c46
--- /dev/null
+++ b/src/lib/libcrypto/des/doPC1
@@ -0,0 +1,110 @@
1#!/usr/local/bin/perl
2
3@l=(
4 0, 1, 2, 3, 4, 5, 6, 7,
5 8, 9,10,11,12,13,14,15,
6 16,17,18,19,20,21,22,23,
7 24,25,26,27,28,29,30,31
8 );
9@r=(
10 32,33,34,35,36,37,38,39,
11 40,41,42,43,44,45,46,47,
12 48,49,50,51,52,53,54,55,
13 56,57,58,59,60,61,62,63
14 );
15
16require 'shifts.pl';
17
18sub PERM_OP
19 {
20 local(*a,*b,*t,$n,$m)=@_;
21
22 @z=&shift(*a,-$n);
23 @z=&xor(*b,*z);
24 @z=&and(*z,$m);
25 @b=&xor(*b,*z);
26 @z=&shift(*z,$n);
27 @a=&xor(*a,*z);
28 }
29
30sub HPERM_OP2
31 {
32 local(*a,*t,$n,$m)=@_;
33 local(@x,@y,$i);
34
35 @z=&shift(*a,16-$n);
36 @z=&xor(*a,*z);
37 @z=&and(*z,$m);
38 @a=&xor(*a,*z);
39 @z=&shift(*z,$n-16);
40 @a=&xor(*a,*z);
41 }
42
43sub HPERM_OP
44 {
45 local(*a,*t,$n,$m)=@_;
46 local(@x,@y,$i);
47
48 for ($i=0; $i<16; $i++)
49 {
50 $x[$i]=$a[$i];
51 $y[$i]=$a[16+$i];
52 }
53 @z=&shift(*x,-$n);
54 @z=&xor(*y,*z);
55 @z=&and(*z,$m);
56 @y=&xor(*y,*z);
57 @z=&shift(*z,$n);
58 @x=&xor(*x,*z);
59 for ($i=0; $i<16; $i++)
60 {
61 $a[$i]=$x[$i];
62 $a[16+$i]=$y[$i];
63 }
64 }
65
66@L=@l;
67@R=@r;
68
69 print "---\n"; &printit(@R);
70&PERM_OP(*R,*L,*T,4,0x0f0f0f0f);
71 print "---\n"; &printit(@R);
72&HPERM_OP2(*L,*T,-2,0xcccc0000);
73&HPERM_OP2(*R,*T,-2,0xcccc0000);
74 print "---\n"; &printit(@R);
75&PERM_OP(*R,*L,*T,1,0x55555555);
76 print "---\n"; &printit(@R);
77&PERM_OP(*L,*R,*T,8,0x00ff00ff);
78 print "---\n"; &printit(@R);
79&PERM_OP(*R,*L,*T,1,0x55555555);
80 print "---\n"; &printit(@R);
81# &printit(@L);
82 &printit(@R);
83print <<"EOF";
84==============================
8563 55 47 39 31 23 15 7
8662 54 46 38 30 22 14 6
8761 53 45 37 29 21 13 5
8860 52 44 36 -- -- -- --
89
9057 49 41 33 25 17 9 1
9158 50 42 34 26 18 10 2
9259 51 43 35 27 19 11 3
9328 20 12 4 -- -- -- --
94EOF
95exit(1);
96@A=&and(*R,0x000000ff);
97@A=&shift(*A,16);
98@B=&and(*R,0x0000ff00);
99@C=&and(*R,0x00ff0000);
100@C=&shift(*C,-16);
101@D=&and(*L,0xf0000000);
102@D=&shift(*D,-4);
103@A=&or(*A,*B);
104@B=&or(*D,*C);
105@R=&or(*A,*B);
106@L=&and(*L,0x0fffffff);
107
108 &printit(@L);
109 &printit(@R);
110