ReactOS 0.4.15-dev-7958-gcd0bb1a
crypt_des.c File Reference
#include "windef.h"
#include "crypt.h"
Include dependency graph for crypt_des.c:

Go to the source code of this file.

Macros

#define CLRBIT(STR, IDX)   ( (STR)[(IDX)/8] &= ~(0x01 << (7 - ((IDX)%8))) )
 
#define SETBIT(STR, IDX)   ( (STR)[(IDX)/8] |= (0x01 << (7 - ((IDX)%8))) )
 
#define GETBIT(STR, IDX)   (( ((STR)[(IDX)/8]) >> (7 - ((IDX)%8)) ) & 0x01)
 

Functions

static void Permute (unsigned char *dst, const unsigned char *src, const unsigned char *map, const int mapsize)
 
static void KeyShiftLeft (unsigned char *key, const int numbits)
 
static void KeyShiftRight (unsigned char *key, const int numbits)
 
static void sbox (unsigned char *dst, const unsigned char *src)
 
static void xor (unsigned char *dst, const unsigned char *a, const unsigned char *b, const int count)
 
unsigned charCRYPT_DEShash (unsigned char *dst, const unsigned char *key, const unsigned char *src)
 
unsigned charCRYPT_DESunhash (unsigned char *dst, const unsigned char *key, const unsigned char *src)
 

Variables

static const unsigned char InitialPermuteMap [64]
 
static const unsigned char KeyPermuteMap [56]
 
static const unsigned char KeyRotation [16]
 
static const unsigned char KeyCompression [48]
 
static const unsigned char DataExpansion [48]
 
static const unsigned char SBox [8][64]
 
static const unsigned char PBox [32]
 
static const unsigned char FinalPermuteMap [64]
 

Macro Definition Documentation

◆ CLRBIT

#define CLRBIT (   STR,
  IDX 
)    ( (STR)[(IDX)/8] &= ~(0x01 << (7 - ((IDX)%8))) )

Definition at line 149 of file crypt_des.c.

◆ GETBIT

#define GETBIT (   STR,
  IDX 
)    (( ((STR)[(IDX)/8]) >> (7 - ((IDX)%8)) ) & 0x01)

Definition at line 151 of file crypt_des.c.

◆ SETBIT

#define SETBIT (   STR,
  IDX 
)    ( (STR)[(IDX)/8] |= (0x01 << (7 - ((IDX)%8))) )

Definition at line 150 of file crypt_des.c.

Function Documentation

◆ CRYPT_DEShash()

unsigned char * CRYPT_DEShash ( unsigned char dst,
const unsigned char key,
const unsigned char src 
)

Definition at line 259 of file crypt_des.c.

260{
261 int i;
262 unsigned char K[7];
263 unsigned char D[8];
264
265 Permute( K, key, KeyPermuteMap, 7 );
267
268 for (i = 0; i < 16; i++)
269 {
270 int j;
271 unsigned char *L = D;
272 unsigned char *R = &(D[4]);
273 unsigned char Rexp[6];
274 unsigned char Rn[4];
275 unsigned char SubK[6];
276
278 Permute( SubK, K, KeyCompression, 6 );
279
280 Permute( Rexp, R, DataExpansion, 6 );
281 xor( Rexp, Rexp, SubK, 6 );
282
283 sbox( Rn, Rexp );
284 Permute( Rexp, Rn, PBox, 4 );
285 xor( Rn, L, Rexp, 4 );
286
287 for (j = 0; j < 4; j++)
288 {
289 L[j] = R[j];
290 R[j] = Rn[j];
291 }
292 }
293
295
296 return dst;
297}
#define D(d)
Definition: builtin.c:4557
static const unsigned char DataExpansion[48]
Definition: crypt_des.c:67
static const unsigned char PBox[32]
Definition: crypt_des.c:129
static void KeyShiftLeft(unsigned char *key, const int numbits)
Definition: crypt_des.c:169
static void sbox(unsigned char *dst, const unsigned char *src)
Definition: crypt_des.c:227
static const unsigned char KeyPermuteMap[56]
Definition: crypt_des.c:43
static void Permute(unsigned char *dst, const unsigned char *src, const unsigned char *map, const int mapsize)
Definition: crypt_des.c:153
static void xor(unsigned char *dst, const unsigned char *a, const unsigned char *b, const int count)
Definition: crypt_des.c:251
static const unsigned char FinalPermuteMap[64]
Definition: crypt_des.c:137
static const unsigned char InitialPermuteMap[64]
Definition: crypt_des.c:31
static const unsigned char KeyRotation[16]
Definition: crypt_des.c:54
static const unsigned char KeyCompression[48]
Definition: crypt_des.c:57
GLenum src
Definition: glext.h:6340
GLenum GLenum dst
Definition: glext.h:6340
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250
#define L(x)
Definition: ntvdm.h:50
#define R(b, x)
Definition: sha2.c:134
Definition: copy.c:22

Referenced by CRYPT_LMhash(), SystemFunction001(), SystemFunction003(), SystemFunction004(), SystemFunction008(), SystemFunction012(), and SystemFunction024().

◆ CRYPT_DESunhash()

unsigned char * CRYPT_DESunhash ( unsigned char dst,
const unsigned char key,
const unsigned char src 
)

Definition at line 299 of file crypt_des.c.

300{
301 int i;
302 unsigned char K[7];
303 unsigned char D[8];
304
305 Permute( K, key, KeyPermuteMap, 7 );
307
308 for (i = 0; i < 16; i++)
309 {
310 int j;
311 unsigned char *L = D;
312 unsigned char *R = &(D[4]);
313 unsigned char Rexp[6];
314 unsigned char Rn[4];
315 unsigned char SubK[6];
316
317 Permute( SubK, K, KeyCompression, 6 );
318
319 Permute( Rexp, R, DataExpansion, 6 );
320 xor( Rexp, Rexp, SubK, 6 );
321
322 sbox( Rn, Rexp );
323 Permute( Rexp, Rn, PBox, 4 );
324 xor( Rn, L, Rexp, 4 );
325
326 for (j = 0; j < 4; j++)
327 {
328 L[j] = R[j];
329 R[j] = Rn[j];
330 }
331
332 KeyShiftRight( K, KeyRotation[15 - i] );
333 }
334
336
337 return dst;
338}
static void KeyShiftRight(unsigned char *key, const int numbits)
Definition: crypt_des.c:198

Referenced by SystemFunction002(), SystemFunction005(), SystemFunction013(), and SystemFunction025().

◆ KeyShiftLeft()

static void KeyShiftLeft ( unsigned char key,
const int  numbits 
)
static

Definition at line 169 of file crypt_des.c.

170{
171 int i;
172 unsigned char keep = key[0];
173
174 for (i = 0; i < numbits; i++)
175 {
176 int j;
177
178 for (j = 0; j < 7; j++)
179 {
180 if (j && (key[j] & 0x80))
181 key[j-1] |= 0x01;
182 key[j] <<= 1;
183 }
184
185 if (GETBIT( key, 27 ))
186 {
187 CLRBIT( key, 27 );
188 SETBIT( key, 55 );
189 }
190
191 if (keep & 0x80)
192 SETBIT( key, 27 );
193
194 keep <<= 1;
195 }
196}
#define SETBIT(STR, IDX)
Definition: crypt_des.c:150
#define GETBIT(STR, IDX)
Definition: crypt_des.c:151
#define CLRBIT(STR, IDX)
Definition: crypt_des.c:149

Referenced by CRYPT_DEShash().

◆ KeyShiftRight()

static void KeyShiftRight ( unsigned char key,
const int  numbits 
)
static

Definition at line 198 of file crypt_des.c.

199{
200 int i;
201 unsigned char keep = key[6];
202
203 for (i = 0; i < numbits; i++)
204 {
205 int j;
206
207 for (j = 6; j >= 0; j--)
208 {
209 if (j!=6 && (key[j] & 0x01))
210 key[j+1] |= 0x80;
211 key[j] >>= 1;
212 }
213
214 if (GETBIT( key, 28 ))
215 {
216 CLRBIT( key, 28 );
217 SETBIT( key, 0 );
218 }
219
220 if (keep & 0x01)
221 SETBIT( key, 28 );
222
223 keep >>= 1;
224 }
225}

Referenced by CRYPT_DESunhash().

◆ Permute()

static void Permute ( unsigned char dst,
const unsigned char src,
const unsigned char map,
const int  mapsize 
)
static

Definition at line 153 of file crypt_des.c.

154{
155 int bitcount, i;
156
157 for (i = 0; i < mapsize; i++)
158 dst[i] = 0;
159
160 bitcount = mapsize * 8;
161
162 for (i = 0; i < bitcount; i++)
163 {
164 if (GETBIT( src, map[i] ))
165 SETBIT( dst, i );
166 }
167}
Definition: _map.h:48
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint GLenum GLenum GLenum GLint GLuint GLenum GLenum GLfloat GLenum GLfloat GLenum GLint mapsize
Definition: glfuncs.h:262

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ sbox()

static void sbox ( unsigned char dst,
const unsigned char src 
)
static

Definition at line 227 of file crypt_des.c.

228{
229 int i;
230
231 for (i = 0; i < 4; i++)
232 dst[i] = 0;
233
234 for (i = 0; i < 8; i++)
235 {
236 int j, Snum, bitnum;
237
238 for (Snum = j = 0, bitnum = (i * 6); j < 6; j++, bitnum++)
239 {
240 Snum <<= 1;
241 Snum |= GETBIT( src, bitnum );
242 }
243
244 if (0 == (i%2))
245 dst[i/2] |= ((SBox[i][Snum]) << 4);
246 else
247 dst[i/2] |= SBox[i][Snum];
248 }
249}
static const unsigned char SBox[8][64]
Definition: crypt_des.c:77

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ xor()

static void xor ( unsigned char dst,
const unsigned char a,
const unsigned char b,
const int  count 
)
static

Definition at line 251 of file crypt_des.c.

252{
253 int i;
254
255 for (i = 0; i < count; i++)
256 dst[i] = a[i] ^ b[i];
257}
GLuint GLuint GLsizei count
Definition: gl.h:1545
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by crc32(), CRYPT_DEShash(), CRYPT_DESunhash(), MyAppendUnicodeToString_(), MyInitUnicodeString(), RtlAppendUnicodeToString(), UDFCheckZeroBuf(), UDFCrc(), UDFDissectName(), UDFGetExtentLength(), UDFGetMappingLength(), UDFIsIllegalChar(), UDFPhysLbaToPart(), UDFUnicodeCksum(), UDFUnicodeCksum150(), and WCacheGetSortedListIndex().

Variable Documentation

◆ DataExpansion

const unsigned char DataExpansion[48]
static
Initial value:
=
{
31, 0, 1, 2, 3, 4, 3, 4,
5, 6, 7, 8, 7, 8, 9, 10,
11, 12, 11, 12, 13, 14, 15, 16,
15, 16, 17, 18, 19, 20, 19, 20,
21, 22, 23, 24, 23, 24, 25, 26,
27, 28, 27, 28, 29, 30, 31, 0
}

Definition at line 67 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ FinalPermuteMap

const unsigned char FinalPermuteMap[64]
static
Initial value:
=
{
7, 39, 15, 47, 23, 55, 31, 63,
6, 38, 14, 46, 22, 54, 30, 62,
5, 37, 13, 45, 21, 53, 29, 61,
4, 36, 12, 44, 20, 52, 28, 60,
3, 35, 11, 43, 19, 51, 27, 59,
2, 34, 10, 42, 18, 50, 26, 58,
1, 33, 9, 41, 17, 49, 25, 57,
0, 32, 8, 40, 16, 48, 24, 56
}

Definition at line 137 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ InitialPermuteMap

const unsigned char InitialPermuteMap[64]
static
Initial value:
=
{
57, 49, 41, 33, 25, 17, 9, 1,
59, 51, 43, 35, 27, 19, 11, 3,
61, 53, 45, 37, 29, 21, 13, 5,
63, 55, 47, 39, 31, 23, 15, 7,
56, 48, 40, 32, 24, 16, 8, 0,
58, 50, 42, 34, 26, 18, 10, 2,
60, 52, 44, 36, 28, 20, 12, 4,
62, 54, 46, 38, 30, 22, 14, 6
}

Definition at line 31 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ KeyCompression

const unsigned char KeyCompression[48]
static
Initial value:
=
{
13, 16, 10, 23, 0, 4, 2, 27,
14, 5, 20, 9, 22, 18, 11, 3,
25, 7, 15, 6, 26, 19, 12, 1,
40, 51, 30, 36, 46, 54, 29, 39,
50, 44, 32, 47, 43, 48, 38, 55,
33, 52, 45, 41, 49, 35, 28, 31
}

Definition at line 57 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ KeyPermuteMap

const unsigned char KeyPermuteMap[56]
static
Initial value:
=
{
49, 42, 35, 28, 21, 14, 7, 0,
50, 43, 36, 29, 22, 15, 8, 1,
51, 44, 37, 30, 23, 16, 9, 2,
52, 45, 38, 31, 55, 48, 41, 34,
27, 20, 13, 6, 54, 47, 40, 33,
26, 19, 12, 5, 53, 46, 39, 32,
25, 18, 11, 4, 24, 17, 10, 3,
}

Definition at line 43 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ KeyRotation

const unsigned char KeyRotation[16]
static
Initial value:
=
{ 1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 }

Definition at line 54 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ PBox

const unsigned char PBox[32]
static
Initial value:
=
{
15, 6, 19, 20, 28, 11, 27, 16,
0, 14, 22, 25, 4, 17, 30, 9,
1, 7, 23, 13, 31, 26, 2, 8,
18, 12, 29, 5, 21, 10, 3, 24
}

Definition at line 129 of file crypt_des.c.

Referenced by CRYPT_DEShash(), and CRYPT_DESunhash().

◆ SBox

const unsigned char SBox[8][64]
static

Definition at line 77 of file crypt_des.c.

Referenced by sbox().