Horizon Official Technical Documentation
DES Class Reference

#include <DES.hpp>

Public Member Functions

void decryptBlock (BIT64 *block)
 
void decrypt (unsigned char *data, size_t size)
 
void roundFunction (BIT64 *src)
 DES round function. XORs src[0..3] with TP(SBOX(E(src[4..7]))). More...
 
void SBOX (BIT64 *src)
 
void E (BIT64 *src)
 Expansion (E). Expands upper four 8-bits (32b) into eight 6-bits (48b). More...
 
void TP (BIT64 *src)
 Transposition (P-BOX). More...
 
void IP (BIT64 *src)
 Initial permutation (IP). More...
 
void FP (BIT64 *src)
 Final permutation (IP^-1). More...
 

Member Function Documentation

◆ decrypt()

void DES::decrypt ( unsigned char *  data,
size_t  size 
)
216{
217 BIT64* p = (BIT64*)data;
218 size_t i;
219
220 for (i = 0; i*8 < size; i += 8)
221 decryptBlock(p);
222}
void decryptBlock(BIT64 *block)
Definition: DES.cpp:208
One 64-bit block.
Definition: DES.hpp:42

References decryptBlock().

+ Here is the call graph for this function:

◆ decryptBlock()

void DES::decryptBlock ( BIT64 block)
209{
210 IP(block);
211 roundFunction(block);
212 FP(block);
213}
void roundFunction(BIT64 *src)
DES round function. XORs src[0..3] with TP(SBOX(E(src[4..7]))).
Definition: DES.cpp:194
void IP(BIT64 *src)
Initial permutation (IP).
Definition: DES.cpp:76
void FP(BIT64 *src)
Final permutation (IP^-1).
Definition: DES.cpp:104

References FP(), IP(), and roundFunction().

Referenced by GRF::decodeFull(), GRF::decodeHeader(), and decrypt().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ E()

void DES::E ( BIT64 src)

Expansion (E). Expands upper four 8-bits (32b) into eight 6-bits (48b).

55{
56 BIT64 tmp = { { 0 } };
57
58 tmp.b[0] = ((src->b[7]<<5) | (src->b[4]>>3)) & 0x3f; // ..0 vutsr
59 tmp.b[1] = ((src->b[4]<<1) | (src->b[5]>>7)) & 0x3f; // ..srqpo n
60 tmp.b[2] = ((src->b[4]<<5) | (src->b[5]>>3)) & 0x3f; // ..o nmlkj
61 tmp.b[3] = ((src->b[5]<<1) | (src->b[6]>>7)) & 0x3f; // ..kjihg f
62 tmp.b[4] = ((src->b[5]<<5) | (src->b[6]>>3)) & 0x3f; // ..g fedcb
63 tmp.b[5] = ((src->b[6]<<1) | (src->b[7]>>7)) & 0x3f; // ..cba98 7
64 tmp.b[6] = ((src->b[6]<<5) | (src->b[7]>>3)) & 0x3f; // ..8 76543
65 tmp.b[7] = ((src->b[7]<<1) | (src->b[4]>>7)) & 0x3f; // ..43210 v
66
67 *src = tmp;
68}
uint8_t b[8]
Definition: DES.hpp:42

References BIT64::b.

Referenced by roundFunction().

+ Here is the caller graph for this function:

◆ FP()

void DES::FP ( BIT64 src)

Final permutation (IP^-1).

105{
106 BIT64 tmp = {{0}};
107
108 std::vector<uint8_t> fp_table = {
109 40, 8, 48, 16, 56, 24, 64, 32,
110 39, 7, 47, 15, 55, 23, 63, 31,
111 38, 6, 46, 14, 54, 22, 62, 30,
112 37, 5, 45, 13, 53, 21, 61, 29,
113 36, 4, 44, 12, 52, 20, 60, 28,
114 35, 3, 43, 11, 51, 19, 59, 27,
115 34, 2, 42, 10, 50, 18, 58, 26,
116 33, 1, 41, 9, 49, 17, 57, 25,
117 };
118
119 size_t i;
120 for( i = 0; i < fp_table.size(); ++i )
121 {
122 uint8_t j = fp_table.at(i) - 1;
123 if (src->b[(j >> 3) & 7] & mask[j & 7])
124 tmp .b[(i >> 3) & 7] |= mask[i & 7];
125 }
126
127 *src = tmp;
128}
static const uint8_t mask[8]
Bitmask for accessing individual bits of a byte.
Definition: DES.cpp:71

References BIT64::b, and mask.

Referenced by decryptBlock().

+ Here is the caller graph for this function:

◆ IP()

void DES::IP ( BIT64 src)

Initial permutation (IP).

77{
78 BIT64 tmp = {{0}};
79
80 std::vector<uint8_t> ip_table = {
81 58, 50, 42, 34, 26, 18, 10, 2,
82 60, 52, 44, 36, 28, 20, 12, 4,
83 62, 54, 46, 38, 30, 22, 14, 6,
84 64, 56, 48, 40, 32, 24, 16, 8,
85 57, 49, 41, 33, 25, 17, 9, 1,
86 59, 51, 43, 35, 27, 19, 11, 3,
87 61, 53, 45, 37, 29, 21, 13, 5,
88 63, 55, 47, 39, 31, 23, 15, 7,
89 };
90
91 size_t i;
92 for( i = 0; i < ip_table.size(); ++i )
93 {
94 uint8_t j = ip_table.at(i) - 1;
95 if (src->b[(j >> 3) & 7] & mask[j & 7])
96 tmp.b[(i >> 3) & 7] |= mask[i & 7];
97 }
98
99 *src = tmp;
100}

References BIT64::b, and mask.

Referenced by decryptBlock().

+ Here is the caller graph for this function:

◆ roundFunction()

void DES::roundFunction ( BIT64 src)

DES round function. XORs src[0..3] with TP(SBOX(E(src[4..7]))).

195{
196 BIT64 tmp = *src;
197 E(&tmp);
198 SBOX(&tmp);
199 TP(&tmp);
200
201 src->b[0] ^= tmp.b[4];
202 src->b[1] ^= tmp.b[5];
203 src->b[2] ^= tmp.b[6];
204 src->b[3] ^= tmp.b[7];
205}
void TP(BIT64 *src)
Transposition (P-BOX).
Definition: DES.cpp:167
void SBOX(BIT64 *src)
Definition: DES.cpp:130
void E(BIT64 *src)
Expansion (E). Expands upper four 8-bits (32b) into eight 6-bits (48b).
Definition: DES.cpp:54

References BIT64::b, E(), SBOX(), and TP().

Referenced by decryptBlock().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ SBOX()

void DES::SBOX ( BIT64 src)
131{
132 BIT64 tmp = {{0}};
133
134 std::vector<std::vector<uint8_t>> s_table = {
135 {
136 0xef, 0x03, 0x41, 0xfd, 0xd8, 0x74, 0x1e, 0x47, 0x26, 0xef, 0xfb, 0x22, 0xb3, 0xd8, 0x84, 0x1e,
137 0x39, 0xac, 0xa7, 0x60, 0x62, 0xc1, 0xcd, 0xba, 0x5c, 0x96, 0x90, 0x59, 0x05, 0x3b, 0x7a, 0x85,
138 0x40, 0xfd, 0x1e, 0xc8, 0xe7, 0x8a, 0x8b, 0x21, 0xda, 0x43, 0x64, 0x9f, 0x2d, 0x14, 0xb1, 0x72,
139 0xf5, 0x5b, 0xc8, 0xb6, 0x9c, 0x37, 0x76, 0xec, 0x39, 0xa0, 0xa3, 0x05, 0x52, 0x6e, 0x0f, 0xd9,
140 },{
141 0xa7, 0xdd, 0x0d, 0x78, 0x9e, 0x0b, 0xe3, 0x95, 0x60, 0x36, 0x36, 0x4f, 0xf9, 0x60, 0x5a, 0xa3,
142 0x11, 0x24, 0xd2, 0x87, 0xc8, 0x52, 0x75, 0xec, 0xbb, 0xc1, 0x4c, 0xba, 0x24, 0xfe, 0x8f, 0x19,
143 0xda, 0x13, 0x66, 0xaf, 0x49, 0xd0, 0x90, 0x06, 0x8c, 0x6a, 0xfb, 0x91, 0x37, 0x8d, 0x0d, 0x78,
144 0xbf, 0x49, 0x11, 0xf4, 0x23, 0xe5, 0xce, 0x3b, 0x55, 0xbc, 0xa2, 0x57, 0xe8, 0x22, 0x74, 0xce,
145 },{
146 0x2c, 0xea, 0xc1, 0xbf, 0x4a, 0x24, 0x1f, 0xc2, 0x79, 0x47, 0xa2, 0x7c, 0xb6, 0xd9, 0x68, 0x15,
147 0x80, 0x56, 0x5d, 0x01, 0x33, 0xfd, 0xf4, 0xae, 0xde, 0x30, 0x07, 0x9b, 0xe5, 0x83, 0x9b, 0x68,
148 0x49, 0xb4, 0x2e, 0x83, 0x1f, 0xc2, 0xb5, 0x7c, 0xa2, 0x19, 0xd8, 0xe5, 0x7c, 0x2f, 0x83, 0xda,
149 0xf7, 0x6b, 0x90, 0xfe, 0xc4, 0x01, 0x5a, 0x97, 0x61, 0xa6, 0x3d, 0x40, 0x0b, 0x58, 0xe6, 0x3d,
150 },{
151 0x4d, 0xd1, 0xb2, 0x0f, 0x28, 0xbd, 0xe4, 0x78, 0xf6, 0x4a, 0x0f, 0x93, 0x8b, 0x17, 0xd1, 0xa4,
152 0x3a, 0xec, 0xc9, 0x35, 0x93, 0x56, 0x7e, 0xcb, 0x55, 0x20, 0xa0, 0xfe, 0x6c, 0x89, 0x17, 0x62,
153 0x17, 0x62, 0x4b, 0xb1, 0xb4, 0xde, 0xd1, 0x87, 0xc9, 0x14, 0x3c, 0x4a, 0x7e, 0xa8, 0xe2, 0x7d,
154 0xa0, 0x9f, 0xf6, 0x5c, 0x6a, 0x09, 0x8d, 0xf0, 0x0f, 0xe3, 0x53, 0x25, 0x95, 0x36, 0x28, 0xcb,
155 }
156 };
157
158 size_t i;
159 for (i = 0; i < s_table.size(); ++i) {
160 tmp.b[i] = (s_table.at(i).at(src->b[i*2+0]) & 0xf0) | (s_table.at(i).at(src->b[i*2+1]) & 0x0f);
161 }
162
163 *src = tmp;
164}

References BIT64::b.

Referenced by roundFunction().

+ Here is the caller graph for this function:

◆ TP()

void DES::TP ( BIT64 src)

Transposition (P-BOX).

168{
169 BIT64 tmp = { { 0 } };
170
171 std::vector<uint8_t> tp_table = {
172 16, 7, 20, 21,
173 29, 12, 28, 17,
174 1, 15, 23, 26,
175 5, 18, 31, 10,
176 2, 8, 24, 14,
177 32, 27, 3, 9,
178 19, 13, 30, 6,
179 22, 11, 4, 25,
180 };
181
182 size_t i;
183 for (i = 0; i < tp_table.size(); ++i) {
184 uint8_t j = tp_table.at(i) - 1;
185 if (src->b[(j >> 3) + 0] & mask[j & 7])
186 tmp .b[(i >> 3) + 4] |= mask[i & 7];
187 }
188
189 *src = tmp;
190}

References BIT64::b, and mask.

Referenced by roundFunction().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: