-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsbox.h
141 lines (138 loc) · 4.49 KB
/
sbox.h
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
Michael Kochell
*/
/*
All sbox calculations are done here, starting with the 48 bit input
*/
unsigned int performSboxCalculation(unsigned long long input);
static const int SBOX_INPUT_SIZE = 6;
static const int NUM_SBOXES = 8;
/*
each 2d array inside is an sbox
numbers were changed to avoid shifting in calculation
for example:
all numbers in s1 are in the bits 28-31
*/
static unsigned int sboxes[8][4][16] =
{
{
//s1
{
3758096384, 1073741824, 3489660928, 268435456, 536870912, 4026531840, 2952790016, 2147483648, 805306368, 2684354560, 1610612736, 3221225472, 1342177280, 2415919104, 0, 1879048192
},
{
0, 4026531840, 1879048192, 1073741824, 3758096384, 536870912, 3489660928, 268435456, 2684354560, 1610612736, 3221225472, 2952790016, 2415919104, 1342177280, 805306368, 2147483648
},
{
1073741824, 268435456, 3758096384, 2147483648, 3489660928, 1610612736, 536870912, 2952790016, 4026531840, 3221225472, 2415919104, 1879048192, 805306368, 2684354560, 1342177280, 0
},
{
4026531840, 3221225472, 2147483648, 536870912, 1073741824, 2415919104, 268435456, 1879048192, 1342177280, 2952790016, 805306368, 3758096384, 2684354560, 0, 1610612736, 3489660928
}
},
//s2
{
{
251658240, 16777216, 134217728, 234881024, 100663296, 184549376, 50331648, 67108864, 150994944, 117440512, 33554432, 218103808, 201326592, 0, 83886080, 167772160
},
{
50331648, 218103808, 67108864, 117440512, 251658240, 33554432, 134217728, 234881024, 201326592, 0, 16777216, 167772160, 100663296, 150994944, 184549376, 83886080
},
{
0, 234881024, 117440512, 184549376, 167772160, 67108864, 218103808, 16777216, 83886080, 134217728, 201326592, 100663296, 150994944, 50331648, 33554432, 251658240
},
{
218103808, 134217728, 167772160, 16777216, 50331648, 251658240, 67108864, 33554432, 184549376, 100663296, 117440512, 201326592, 0, 83886080, 234881024, 150994944
}
},
//s3
{
{
10485760, 0, 9437184, 14680064, 6291456, 3145728, 15728640, 5242880, 1048576, 13631488, 12582912, 7340032, 11534336, 4194304, 2097152, 8388608
},
{
13631488, 7340032, 0, 9437184, 3145728, 4194304, 6291456, 10485760, 2097152, 8388608, 5242880, 14680064, 12582912, 11534336, 15728640, 1048576
},
{
13631488, 6291456, 4194304, 9437184, 8388608, 15728640, 3145728, 0, 11534336, 1048576, 2097152, 12582912, 5242880, 10485760, 14680064, 7340032
},
{
1048576, 10485760, 13631488, 0, 6291456, 9437184, 8388608, 7340032, 4194304, 15728640, 14680064, 3145728, 11534336, 5242880, 2097152, 12582912
}
},
//s4
{
{
458752, 851968, 917504, 196608, 0, 393216, 589824, 655360, 65536, 131072, 524288, 327680, 720896, 786432, 262144, 983040
},
{
851968, 524288, 720896, 327680, 393216, 983040, 0, 196608, 262144, 458752, 131072, 786432, 65536, 655360, 917504, 589824
},
{
655360, 393216, 589824, 0, 786432, 720896, 458752, 851968, 983040, 65536, 196608, 917504, 327680, 131072, 524288, 262144
},
{
196608, 983040, 0, 393216, 655360, 65536, 851968, 524288, 589824, 262144, 327680, 720896, 786432, 458752, 131072, 917504
}
},
//s5
{
{
8192, 49152, 16384, 4096, 28672, 40960, 45056, 24576, 32768, 20480, 12288, 61440, 53248, 0, 57344, 36864
},
{
57344, 45056, 8192, 49152, 16384, 28672, 53248, 4096, 20480, 0, 61440, 40960, 12288, 36864, 32768, 24576
},
{
16384, 8192, 4096, 45056, 40960, 53248, 28672, 32768, 61440, 36864, 49152, 20480, 24576, 12288, 0, 57344
},
{
45056, 32768, 49152, 28672, 4096, 57344, 8192, 53248, 24576, 61440, 0, 36864, 40960, 16384, 20480, 12288
}
},
//s6
{
{
3072, 256, 2560, 3840, 2304, 512, 1536, 2048, 0, 3328, 768, 1024, 3584, 1792, 1280, 2816
},
{
2560, 3840, 1024, 512, 1792, 3072, 2304, 1280, 1536, 256, 3328, 3584, 0, 2816, 768, 2048
},
{
2304, 3584, 3840, 1280, 512, 2048, 3072, 768, 1792, 0, 1024, 2560, 256, 3328, 2816, 1536
},
{
1024, 768, 512, 3072, 2304, 1280, 3840, 2560, 2816, 3584, 256, 1792, 1536, 0, 2048, 3328
}
},
//s7
{
{
64, 176, 32, 224, 240, 0, 128, 208, 48, 192, 144, 112, 80, 160, 96, 16
},
{
208, 0, 176, 112, 64, 144, 16, 160, 224, 48, 80, 192, 32, 240, 128, 96
},
{
16, 64, 176, 208, 192, 48, 112, 224, 160, 240, 96, 128, 0, 80, 144, 32
},
{
96, 176, 208, 128, 16, 64, 160, 112, 144, 80, 0, 240, 224, 32, 48, 192
}
},
//s8
{
{
13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7
},
{
1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2
},
{
7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8
},
{
2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
}
}
};