9 #define ROTL28(rs, sh) ((((rs) << (sh)) | ((rs) >> (28 - (sh)))) & 0x0FFFFFFF)
10 #define ROTR28(rs, sh) ((((rs) >> (sh)) | ((rs) << (28 - (sh)))) & 0x0FFFFFFF)
11 #define ROTL(rs, sh) (((rs) << (sh)) | ((rs) >> (32 - (sh))))
12 #define ROTR(rs, sh) (((rs) >> (sh)) | ((rs) << (32 - (sh))))
16 0x01010400, 0x00000000, 0x00010000, 0x01010404, 0x01010004, 0x00010404, 0x00000004, 0x00010000,
17 0x00000400, 0x01010400, 0x01010404, 0x00000400, 0x01000404, 0x01010004, 0x01000000, 0x00000004,
18 0x00000404, 0x01000400, 0x01000400, 0x00010400, 0x00010400, 0x01010000, 0x01010000, 0x01000404,
19 0x00010004, 0x01000004, 0x01000004, 0x00010004, 0x00000000, 0x00000404, 0x00010404, 0x01000000,
20 0x00010000, 0x01010404, 0x00000004, 0x01010000, 0x01010400, 0x01000000, 0x01000000, 0x00000400,
21 0x01010004, 0x00010000, 0x00010400, 0x01000004, 0x00000400, 0x00000004, 0x01000404, 0x00010404,
22 0x01010404, 0x00010004, 0x01010000, 0x01000404, 0x01000004, 0x00000404, 0x00010404, 0x01010400,
23 0x00000404, 0x01000400, 0x01000400, 0x00000000, 0x00010004, 0x00010400, 0x00000000, 0x01010004
27 0x80108020, 0x80008000, 0x00008000, 0x00108020, 0x00100000, 0x00000020, 0x80100020, 0x80008020,
28 0x80000020, 0x80108020, 0x80108000, 0x80000000, 0x80008000, 0x00100000, 0x00000020, 0x80100020,
29 0x00108000, 0x00100020, 0x80008020, 0x00000000, 0x80000000, 0x00008000, 0x00108020, 0x80100000,
30 0x00100020, 0x80000020, 0x00000000, 0x00108000, 0x00008020, 0x80108000, 0x80100000, 0x00008020,
31 0x00000000, 0x00108020, 0x80100020, 0x00100000, 0x80008020, 0x80100000, 0x80108000, 0x00008000,
32 0x80100000, 0x80008000, 0x00000020, 0x80108020, 0x00108020, 0x00000020, 0x00008000, 0x80000000,
33 0x00008020, 0x80108000, 0x00100000, 0x80000020, 0x00100020, 0x80008020, 0x80000020, 0x00100020,
34 0x00108000, 0x00000000, 0x80008000, 0x00008020, 0x80000000, 0x80100020, 0x80108020, 0x00108000
38 0x00000208, 0x08020200, 0x00000000, 0x08020008, 0x08000200, 0x00000000, 0x00020208, 0x08000200,
39 0x00020008, 0x08000008, 0x08000008, 0x00020000, 0x08020208, 0x00020008, 0x08020000, 0x00000208,
40 0x08000000, 0x00000008, 0x08020200, 0x00000200, 0x00020200, 0x08020000, 0x08020008, 0x00020208,
41 0x08000208, 0x00020200, 0x00020000, 0x08000208, 0x00000008, 0x08020208, 0x00000200, 0x08000000,
42 0x08020200, 0x08000000, 0x00020008, 0x00000208, 0x00020000, 0x08020200, 0x08000200, 0x00000000,
43 0x00000200, 0x00020008, 0x08020208, 0x08000200, 0x08000008, 0x00000200, 0x00000000, 0x08020008,
44 0x08000208, 0x00020000, 0x08000000, 0x08020208, 0x00000008, 0x00020208, 0x00020200, 0x08000008,
45 0x08020000, 0x08000208, 0x00000208, 0x08020000, 0x00020208, 0x00000008, 0x08020008, 0x00020200
49 0x00802001, 0x00002081, 0x00002081, 0x00000080, 0x00802080, 0x00800081, 0x00800001, 0x00002001,
50 0x00000000, 0x00802000, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00800080, 0x00800001,
51 0x00000001, 0x00002000, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002001, 0x00002080,
52 0x00800081, 0x00000001, 0x00002080, 0x00800080, 0x00002000, 0x00802080, 0x00802081, 0x00000081,
53 0x00800080, 0x00800001, 0x00802000, 0x00802081, 0x00000081, 0x00000000, 0x00000000, 0x00802000,
54 0x00002080, 0x00800080, 0x00800081, 0x00000001, 0x00802001, 0x00002081, 0x00002081, 0x00000080,
55 0x00802081, 0x00000081, 0x00000001, 0x00002000, 0x00800001, 0x00002001, 0x00802080, 0x00800081,
56 0x00002001, 0x00002080, 0x00800000, 0x00802001, 0x00000080, 0x00800000, 0x00002000, 0x00802080
60 0x00000100, 0x02080100, 0x02080000, 0x42000100, 0x00080000, 0x00000100, 0x40000000, 0x02080000,
61 0x40080100, 0x00080000, 0x02000100, 0x40080100, 0x42000100, 0x42080000, 0x00080100, 0x40000000,
62 0x02000000, 0x40080000, 0x40080000, 0x00000000, 0x40000100, 0x42080100, 0x42080100, 0x02000100,
63 0x42080000, 0x40000100, 0x00000000, 0x42000000, 0x02080100, 0x02000000, 0x42000000, 0x00080100,
64 0x00080000, 0x42000100, 0x00000100, 0x02000000, 0x40000000, 0x02080000, 0x42000100, 0x40080100,
65 0x02000100, 0x40000000, 0x42080000, 0x02080100, 0x40080100, 0x00000100, 0x02000000, 0x42080000,
66 0x42080100, 0x00080100, 0x42000000, 0x42080100, 0x02080000, 0x00000000, 0x40080000, 0x42000000,
67 0x00080100, 0x02000100, 0x40000100, 0x00080000, 0x00000000, 0x40080000, 0x02080100, 0x40000100
71 0x20000010, 0x20400000, 0x00004000, 0x20404010, 0x20400000, 0x00000010, 0x20404010, 0x00400000,
72 0x20004000, 0x00404010, 0x00400000, 0x20000010, 0x00400010, 0x20004000, 0x20000000, 0x00004010,
73 0x00000000, 0x00400010, 0x20004010, 0x00004000, 0x00404000, 0x20004010, 0x00000010, 0x20400010,
74 0x20400010, 0x00000000, 0x00404010, 0x20404000, 0x00004010, 0x00404000, 0x20404000, 0x20000000,
75 0x20004000, 0x00000010, 0x20400010, 0x00404000, 0x20404010, 0x00400000, 0x00004010, 0x20000010,
76 0x00400000, 0x20004000, 0x20000000, 0x00004010, 0x20000010, 0x20404010, 0x00404000, 0x20400000,
77 0x00404010, 0x20404000, 0x00000000, 0x20400010, 0x00000010, 0x00004000, 0x20400000, 0x00404010,
78 0x00004000, 0x00400010, 0x20004010, 0x00000000, 0x20404000, 0x20000000, 0x00400010, 0x20004010
82 0x00200000, 0x04200002, 0x04000802, 0x00000000, 0x00000800, 0x04000802, 0x00200802, 0x04200800,
83 0x04200802, 0x00200000, 0x00000000, 0x04000002, 0x00000002, 0x04000000, 0x04200002, 0x00000802,
84 0x04000800, 0x00200802, 0x00200002, 0x04000800, 0x04000002, 0x04200000, 0x04200800, 0x00200002,
85 0x04200000, 0x00000800, 0x00000802, 0x04200802, 0x00200800, 0x00000002, 0x04000000, 0x00200800,
86 0x04000000, 0x00200800, 0x00200000, 0x04000802, 0x04000802, 0x04200002, 0x04200002, 0x00000002,
87 0x00200002, 0x04000000, 0x04000800, 0x00200000, 0x04200800, 0x00000802, 0x00200802, 0x04200800,
88 0x00000802, 0x04000002, 0x04200802, 0x04200000, 0x00200800, 0x00000000, 0x00000002, 0x04200802,
89 0x00000000, 0x00200802, 0x04200000, 0x00000800, 0x04000002, 0x04000800, 0x00000800, 0x00200002
93 0x10001040, 0x00001000, 0x00040000, 0x10041040, 0x10000000, 0x10001040, 0x00000040, 0x10000000,
94 0x00040040, 0x10040000, 0x10041040, 0x00041000, 0x10041000, 0x00041040, 0x00001000, 0x00000040,
95 0x10040000, 0x10000040, 0x10001000, 0x00001040, 0x00041000, 0x00040040, 0x10040040, 0x10041000,
96 0x00001040, 0x00000000, 0x00000000, 0x10040040, 0x10000040, 0x10001000, 0x00041040, 0x00040000,
97 0x00041040, 0x00040000, 0x10041000, 0x00001000, 0x00000040, 0x10040040, 0x00001000, 0x00041040,
98 0x10001000, 0x00000040, 0x10000040, 0x10040000, 0x10040040, 0x10000000, 0x00040000, 0x10001040,
99 0x00000000, 0x10041040, 0x00040040, 0x10000040, 0x10040000, 0x10001000, 0x10001040, 0x00000000,
100 0x10041040, 0x00041000, 0x00041000, 0x00001040, 0x00001040, 0x00040040, 0x10000000, 0x10041000
104 -1, 0x3b, 0x33, 0x2b, 0x03, 0x0b, 0x13, 0x1b,
105 -1, 0x3a, 0x32, 0x2a, 0x02, 0x0a, 0x12, 0x1a,
106 -1, 0x39, 0x31, 0x29, 0x01, 0x09, 0x11, 0x19,
107 -1, 0x38, 0x30, 0x28, 0x00, 0x08, 0x10, 0x18,
108 -1, 0x37, 0x2f, 0x27, 0x23, 0x07, 0x0f, 0x17,
109 -1, 0x36, 0x2e, 0x26, 0x22, 0x06, 0x0e, 0x16,
110 -1, 0x35, 0x2d, 0x25, 0x21, 0x05, 0x0d, 0x15,
111 -1, 0x34, 0x2c, 0x24, 0x20, 0x04, 0x0c, 0x14
117 ut32 perm = ((*keylo >> 4) ^ *keyhi) & 0x0F0F0F0F;
119 *keylo ^= (perm << 4);
120 perm = ((*keyhi >> 16) ^ *keylo) & 0x0000FFFF;
122 *keyhi ^= (perm << 16);
123 perm = ((*keylo >> 2) ^ *keyhi) & 0x33333333;
125 *keylo ^= (perm << 2);
126 perm = ((*keyhi >> 16) ^ *keylo) & 0x0000FFFF;
128 *keyhi ^= (perm << 16);
129 perm = ((*keylo >> 1) ^ *keyhi) & 0x55555555;
131 *keylo ^= (perm << 1);
132 perm = ((*keyhi >> 8) ^ *keylo) & 0x00FF00FF;
134 *keyhi ^= (perm << 8);
135 perm = ((*keylo >> 1) ^ *keyhi) & 0x55555555;
137 *keylo ^= (perm << 1);
138 perm = (*keylo << 8) | ((*keyhi >> 20) & 0x000000F0);
139 *keylo = ((*keyhi << 20) & 0x0FF00000);
140 *keylo |= ((*keyhi << 4) & 0x000FF000);
141 *keylo |= ((*keyhi >> 12) & 0x00000FF0);
142 *keylo |= ((*keyhi >> 28) & 0x0000000F);
157 for (
size_t i = 0;
i < 64;
i++) {
166 *keylo =
out & 0xffffffff;
175 ut32 perm = ((
lo >> 4) ^
hi) & 0x0F0F0F0F;
178 perm = ((
lo >> 16) ^
hi) & 0x0000FFFF;
181 perm = ((
hi >> 2) ^
lo) & 0x33333333;
184 perm = ((
hi >> 8) ^
lo) & 0x00FF00FF;
187 perm = ((
lo >> 1) ^
hi) & 0x55555555;
201 ut32 perm = ((
lo >> 1) ^
hi) & 0x55555555;
204 perm = ((
hi >> 8) ^
lo) & 0x00FF00FF;
207 perm = ((
hi >> 2) ^
lo) & 0x33333333;
210 perm = ((
lo >> 16) ^
hi) & 0x0000FFFF;
213 perm = ((
lo >> 4) ^
hi) & 0x0F0F0F0F;
228 if (
i == 0 ||
i == 1 ||
i == 8 ||
i == 15) {
229 *deskeylo =
ROTL28(*deskeylo, 1);
230 *deskeyhi =
ROTL28(*deskeyhi, 1);
232 *deskeylo =
ROTL28(*deskeylo, 2);
233 *deskeyhi =
ROTL28(*deskeyhi, 2);
236 if (
i == 0 ||
i == 1 ||
i == 8 ||
i == 15) {
237 *deskeylo =
ROTR28(*deskeylo, 1);
238 *deskeyhi =
ROTR28(*deskeyhi, 1);
240 *deskeylo =
ROTR28(*deskeylo, 2);
241 *deskeyhi =
ROTR28(*deskeyhi, 2);
249 *keylo = ((deslo << 4) & 0x24000000) | ((deslo << 28) & 0x10000000) |
250 ((deslo << 14) & 0x08000000) | ((deslo << 18) & 0x02080000) |
251 ((deslo << 6) & 0x01000000) | ((deslo << 9) & 0x00200000) |
252 ((deslo >> 1) & 0x00100000) | ((deslo << 10) & 0x00040000) |
253 ((deslo << 2) & 0x00020000) | ((deslo >> 10) & 0x00010000) |
254 ((deshi >> 13) & 0x00002000) | ((deshi >> 4) & 0x00001000) |
255 ((deshi << 6) & 0x00000800) | ((deshi >> 1) & 0x00000400) |
256 ((deshi >> 14) & 0x00000200) | ((deshi)&0x00000100) |
257 ((deshi >> 5) & 0x00000020) | ((deshi >> 10) & 0x00000010) |
258 ((deshi >> 3) & 0x00000008) | ((deshi >> 18) & 0x00000004) |
259 ((deshi >> 26) & 0x00000002) | ((deshi >> 24) & 0x00000001);
261 *keyhi = ((deslo << 15) & 0x20000000) | ((deslo << 17) & 0x10000000) |
262 ((deslo << 10) & 0x08000000) | ((deslo << 22) & 0x04000000) |
263 ((deslo >> 2) & 0x02000000) | ((deslo << 1) & 0x01000000) |
264 ((deslo << 16) & 0x00200000) | ((deslo << 11) & 0x00100000) |
265 ((deslo << 3) & 0x00080000) | ((deslo >> 6) & 0x00040000) |
266 ((deslo << 15) & 0x00020000) | ((deslo >> 4) & 0x00010000) |
267 ((deshi >> 2) & 0x00002000) | ((deshi << 8) & 0x00001000) |
268 ((deshi >> 14) & 0x00000808) | ((deshi >> 9) & 0x00000400) |
269 ((deshi)&0x00000200) | ((deshi << 7) & 0x00000100) |
270 ((deshi >> 7) & 0x00000020) | ((deshi >> 3) & 0x00000011) |
271 ((deshi << 2) & 0x00000004) | ((deshi >> 21) & 0x00000002);
288 rz_des_pc2(keylo, keyhi, *deskeylo, *deskeyhi);
296 ut32 perm =
hi ^ (*roundkeylo);
297 lo ^=
sbox2[(perm >> 24) & 0x3F];
298 lo ^=
sbox4[(perm >> 16) & 0x3F];
299 lo ^=
sbox6[(perm >> 8) & 0x3F];
301 perm =
ROTR(
hi, 4) ^ (*roundkeyhi);
302 lo ^=
sbox1[(perm >> 24) & 0x3F];
303 lo ^=
sbox3[(perm >> 16) & 0x3F];
304 lo ^=
sbox5[(perm >> 8) & 0x3F];
const lzma_allocator const uint8_t * in
const lzma_allocator const uint8_t size_t uint8_t * out
static const ut32 sbox8[64]
static const ut32 sbox7[64]
static const ut32 sbox3[64]
static const ut32 sbox6[64]
RZ_API void rz_des_permute_key(ut32 *keylo, ut32 *keyhi)
Apply PC-1.
RZ_API void rz_des_pc2(RZ_OUT ut32 *keylo, RZ_OUT ut32 *keyhi, RZ_IN ut32 deslo, RZ_IN ut32 deshi)
PC-2 permutation of a key.
static const ut32 sbox1[64]
static const ut32 sbox5[64]
RZ_API void rz_des_round_key(int i, RZ_OUT ut32 *keylo, RZ_OUT ut32 *keyhi, RZ_INOUT ut32 *deskeylo, RZ_INOUT ut32 *deskeyhi)
Calculate the final key to be used in a given round.
RZ_API void rz_des_permute_block1(ut32 *blocklo, ut32 *blockhi)
last permutation of the block
RZ_API void rz_des_shift_key(int i, bool decrypt, RZ_INOUT ut32 *deskeylo, RZ_INOUT ut32 *deskeyhi)
Apply the respective shift to the key for a given round.
RZ_API void rz_des_round(RZ_OUT ut32 *buflo, RZ_OUT ut32 *bufhi, RZ_IN ut32 *roundkeylo, RZ_IN ut32 *roundkeyhi)
Apply the cipher function (f)
RZ_API void rz_des_permute_key_inv(ut32 *keylo, ut32 *keyhi)
Inverse of rz_des_permute_key (PC-1)
RZ_API void rz_des_permute_block0(ut32 *blocklo, ut32 *blockhi)
first permutation of the input block
static const ut32 sbox4[64]
static const ut32 sbox2[64]
static const st8 pc1_inv[64]
#define rz_return_if_fail(expr)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()