Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

813 lines
16 KiB

  1. /*++
  2. Copyright (c) 1987-1994 Microsoft Corporation
  3. Module Name:
  4. arapdes.c
  5. Abstract:
  6. This module implements the ARAP-specific authentication that is called in
  7. by the subauthentication package if the protocol type is ARAP.
  8. This code is adapted from fcr's des code
  9. Author:
  10. Shirish Koti 28-Feb-97
  11. Revisions:
  12. --*/
  13. /*
  14. * Sofware DES functions
  15. * written 12 Dec 1986 by Phil Karn, KA9Q; large sections adapted from
  16. * the 1977 public-domain program by Jim Gillogly
  17. */
  18. // #include "compiler.h"
  19. #include <windows.h>
  20. //#include <ntddk.h>
  21. //#include <ntdef.h>
  22. //#define NULL 0
  23. unsigned long byteswap();
  24. CRITICAL_SECTION ArapDesLock;
  25. VOID
  26. des_done(
  27. IN VOID
  28. );
  29. VOID
  30. des_setkey(
  31. IN PCHAR key // 64 bits (will use only 56)
  32. );
  33. VOID
  34. des_endes(
  35. IN PCHAR block
  36. );
  37. VOID
  38. des_dedes(
  39. IN PCHAR block
  40. );
  41. static
  42. VOID
  43. permute(
  44. IN PCHAR inblock, // result into outblock,64 bits
  45. IN CHAR perm[16][16][8], // 2K bytes defining perm.
  46. IN PCHAR outblock // result into outblock,64 bits
  47. );
  48. static
  49. VOID
  50. round(
  51. IN int num,
  52. IN unsigned long *block
  53. );
  54. static long f (unsigned long r, unsigned char subkey[8]);
  55. static
  56. VOID
  57. perminit(
  58. IN CHAR perm[16][16][8],
  59. IN CHAR p[64]
  60. );
  61. static int spinit();
  62. PCHAR
  63. des_pw_bitshift(
  64. IN PCHAR pw
  65. );
  66. PCHAR
  67. des_pw_bitshift_lowbit(
  68. IN PCHAR pw
  69. );
  70. //
  71. // Tables defined in the Data Encryption Standard documents */
  72. //
  73. //
  74. // initial permutation IP
  75. //
  76. static char ip[] =
  77. {
  78. 58, 50, 42, 34, 26, 18, 10, 2,
  79. 60, 52, 44, 36, 28, 20, 12, 4,
  80. 62, 54, 46, 38, 30, 22, 14, 6,
  81. 64, 56, 48, 40, 32, 24, 16, 8,
  82. 57, 49, 41, 33, 25, 17, 9, 1,
  83. 59, 51, 43, 35, 27, 19, 11, 3,
  84. 61, 53, 45, 37, 29, 21, 13, 5,
  85. 63, 55, 47, 39, 31, 23, 15, 7
  86. };
  87. //
  88. // final permutation IP^-1
  89. //
  90. static char fp[] =
  91. {
  92. 40, 8, 48, 16, 56, 24, 64, 32,
  93. 39, 7, 47, 15, 55, 23, 63, 31,
  94. 38, 6, 46, 14, 54, 22, 62, 30,
  95. 37, 5, 45, 13, 53, 21, 61, 29,
  96. 36, 4, 44, 12, 52, 20, 60, 28,
  97. 35, 3, 43, 11, 51, 19, 59, 27,
  98. 34, 2, 42, 10, 50, 18, 58, 26,
  99. 33, 1, 41, 9, 49, 17, 57, 25
  100. };
  101. /* expansion operation matrix
  102. * This is for reference only; it is unused in the code
  103. * as the f() function performs it implicitly for speed
  104. */
  105. #ifdef notdef
  106. static char ei[] =
  107. {
  108. 32, 1, 2, 3, 4, 5,
  109. 4, 5, 6, 7, 8, 9,
  110. 8, 9, 10, 11, 12, 13,
  111. 12, 13, 14, 15, 16, 17,
  112. 16, 17, 18, 19, 20, 21,
  113. 20, 21, 22, 23, 24, 25,
  114. 24, 25, 26, 27, 28, 29,
  115. 28, 29, 30, 31, 32, 1
  116. };
  117. #endif
  118. //
  119. // permuted choice table (key)
  120. //
  121. static char pc1[] =
  122. {
  123. 57, 49, 41, 33, 25, 17, 9,
  124. 1, 58, 50, 42, 34, 26, 18,
  125. 10, 2, 59, 51, 43, 35, 27,
  126. 19, 11, 3, 60, 52, 44, 36,
  127. 63, 55, 47, 39, 31, 23, 15,
  128. 7, 62, 54, 46, 38, 30, 22,
  129. 14, 6, 61, 53, 45, 37, 29,
  130. 21, 13, 5, 28, 20, 12, 4
  131. };
  132. //
  133. // number left rotations of pc1
  134. //
  135. static char totrot[] =
  136. {
  137. 1,2,4,6,8,10,12,14,15,17,19,21,23,25,27,28
  138. };
  139. //
  140. // permuted choice key (table)
  141. //
  142. static char pc2[] =
  143. {
  144. 14, 17, 11, 24, 1, 5,
  145. 3, 28, 15, 6, 21, 10,
  146. 23, 19, 12, 4, 26, 8,
  147. 16, 7, 27, 20, 13, 2,
  148. 41, 52, 31, 37, 47, 55,
  149. 30, 40, 51, 45, 33, 48,
  150. 44, 49, 39, 56, 34, 53,
  151. 46, 42, 50, 36, 29, 32
  152. };
  153. //
  154. // The (in)famous S-boxes
  155. //
  156. static char si[8][64] =
  157. {
  158. //
  159. // S1
  160. //
  161. 14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
  162. 0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
  163. 4, 1, 14, 8, 13, 6, 2, 11, 15, 12, 9, 7, 3, 10, 5, 0,
  164. 15, 12, 8, 2, 4, 9, 1, 7, 5, 11, 3, 14, 10, 0, 6, 13,
  165. //
  166. // S2
  167. //
  168. 15, 1, 8, 14, 6, 11, 3, 4, 9, 7, 2, 13, 12, 0, 5, 10,
  169. 3, 13, 4, 7, 15, 2, 8, 14, 12, 0, 1, 10, 6, 9, 11, 5,
  170. 0, 14, 7, 11, 10, 4, 13, 1, 5, 8, 12, 6, 9, 3, 2, 15,
  171. 13, 8, 10, 1, 3, 15, 4, 2, 11, 6, 7, 12, 0, 5, 14, 9,
  172. //
  173. // S3
  174. //
  175. 10, 0, 9, 14, 6, 3, 15, 5, 1, 13, 12, 7, 11, 4, 2, 8,
  176. 13, 7, 0, 9, 3, 4, 6, 10, 2, 8, 5, 14, 12, 11, 15, 1,
  177. 13, 6, 4, 9, 8, 15, 3, 0, 11, 1, 2, 12, 5, 10, 14, 7,
  178. 1, 10, 13, 0, 6, 9, 8, 7, 4, 15, 14, 3, 11, 5, 2, 12,
  179. //
  180. // S4
  181. //
  182. 7, 13, 14, 3, 0, 6, 9, 10, 1, 2, 8, 5, 11, 12, 4, 15,
  183. 13, 8, 11, 5, 6, 15, 0, 3, 4, 7, 2, 12, 1, 10, 14, 9,
  184. 10, 6, 9, 0, 12, 11, 7, 13, 15, 1, 3, 14, 5, 2, 8, 4,
  185. 3, 15, 0, 6, 10, 1, 13, 8, 9, 4, 5, 11, 12, 7, 2, 14,
  186. //
  187. // S5
  188. //
  189. 2, 12, 4, 1, 7, 10, 11, 6, 8, 5, 3, 15, 13, 0, 14, 9,
  190. 14, 11, 2, 12, 4, 7, 13, 1, 5, 0, 15, 10, 3, 9, 8, 6,
  191. 4, 2, 1, 11, 10, 13, 7, 8, 15, 9, 12, 5, 6, 3, 0, 14,
  192. 11, 8, 12, 7, 1, 14, 2, 13, 6, 15, 0, 9, 10, 4, 5, 3,
  193. //
  194. // S6
  195. //
  196. 12, 1, 10, 15, 9, 2, 6, 8, 0, 13, 3, 4, 14, 7, 5, 11,
  197. 10, 15, 4, 2, 7, 12, 9, 5, 6, 1, 13, 14, 0, 11, 3, 8,
  198. 9, 14, 15, 5, 2, 8, 12, 3, 7, 0, 4, 10, 1, 13, 11, 6,
  199. 4, 3, 2, 12, 9, 5, 15, 10, 11, 14, 1, 7, 6, 0, 8, 13,
  200. //
  201. // S7
  202. //
  203. 4, 11, 2, 14, 15, 0, 8, 13, 3, 12, 9, 7, 5, 10, 6, 1,
  204. 13, 0, 11, 7, 4, 9, 1, 10, 14, 3, 5, 12, 2, 15, 8, 6,
  205. 1, 4, 11, 13, 12, 3, 7, 14, 10, 15, 6, 8, 0, 5, 9, 2,
  206. 6, 11, 13, 8, 1, 4, 10, 7, 9, 5, 0, 15, 14, 2, 3, 12,
  207. //
  208. // S8
  209. //
  210. 13, 2, 8, 4, 6, 15, 11, 1, 10, 9, 3, 14, 5, 0, 12, 7,
  211. 1, 15, 13, 8, 10, 3, 7, 4, 12, 5, 6, 11, 0, 14, 9, 2,
  212. 7, 11, 4, 1, 9, 12, 14, 2, 0, 6, 10, 13, 15, 3, 5, 8,
  213. 2, 1, 14, 7, 4, 10, 8, 13, 15, 12, 9, 0, 3, 5, 6, 11
  214. };
  215. //
  216. // 32-bit permutation function P used on the output of the S-boxes
  217. //
  218. static char p32i[] =
  219. {
  220. 16, 7, 20, 21,
  221. 29, 12, 28, 17,
  222. 1, 15, 23, 26,
  223. 5, 18, 31, 10,
  224. 2, 8, 24, 14,
  225. 32, 27, 3, 9,
  226. 19, 13, 30, 6,
  227. 22, 11, 4, 25
  228. };
  229. //
  230. // End of DES-defined tables
  231. //
  232. //
  233. // Lookup tables initialized once only at startup by desinit()
  234. //
  235. static long (*sp)[64]; // Combined S and P boxes
  236. static char (*iperm)[16][8]; // Initial and final permutations
  237. static char (*fperm)[16][8];
  238. //
  239. // 8 6-bit subkeys for each of 16 rounds, initialized by setkey()
  240. //
  241. static unsigned char (*kn)[8];
  242. //
  243. // bit 0 is left-most in byte
  244. //
  245. static int bytebit[] =
  246. {
  247. 0200,0100,040,020,010,04,02,01
  248. };
  249. static int nibblebit[] =
  250. {
  251. 010,04,02,01
  252. };
  253. static int desmode;
  254. /* Allocate space and initialize DES lookup arrays
  255. * mode == 0: standard Data Encryption Algorithm
  256. * mode == 1: DEA without initial and final permutations for speed
  257. * mode == 2: DEA without permutations and with 128-byte key (completely
  258. * independent subkeys for each round)
  259. */
  260. des_init(mode)
  261. int mode;
  262. {
  263. if(sp != NULL)
  264. {
  265. // Already initialized
  266. return 0;
  267. }
  268. desmode = mode;
  269. sp = (long (*)[64])LocalAlloc(LMEM_FIXED, (sizeof(long) * 8 * 64));
  270. if(sp == NULL)
  271. {
  272. return -1;
  273. }
  274. spinit();
  275. kn = (unsigned char (*)[8])LocalAlloc(LMEM_FIXED, (sizeof(char) * 8 * 16));
  276. if(kn == NULL)
  277. {
  278. LocalFree((char *)sp);
  279. return -1;
  280. }
  281. if(mode == 1 || mode == 2) // No permutations
  282. return 0;
  283. iperm = (char (*)[16][8])
  284. LocalAlloc(LMEM_FIXED, (sizeof(char) * 16 * 16 * 8));
  285. if(iperm == NULL)
  286. {
  287. LocalFree((char *)sp);
  288. LocalFree((char *)kn);
  289. return -1;
  290. }
  291. perminit(iperm,ip);
  292. fperm = (char (*)[16][8])
  293. LocalAlloc(LMEM_FIXED, (sizeof(char) * 16 * 16 * 8));
  294. if(fperm == NULL)
  295. {
  296. LocalFree((char *)sp);
  297. LocalFree((char *)kn);
  298. LocalFree((char *)iperm);
  299. return -1;
  300. }
  301. perminit(fperm,fp);
  302. return 0;
  303. }
  304. //
  305. // Free up storage used by DES
  306. //
  307. VOID
  308. des_done(
  309. IN VOID
  310. )
  311. {
  312. if(sp == NULL)
  313. return; // Already done
  314. LocalFree((char *)sp);
  315. LocalFree((char *)kn);
  316. if(iperm != NULL)
  317. LocalFree((char *)iperm);
  318. if(fperm != NULL)
  319. LocalFree((char *)fperm);
  320. sp = NULL;
  321. iperm = NULL;
  322. fperm = NULL;
  323. kn = NULL;
  324. }
  325. //
  326. // Set key (initialize key schedule array)
  327. //
  328. VOID
  329. des_setkey(
  330. IN PCHAR key // 64 bits (will use only 56)
  331. )
  332. {
  333. char pc1m[56]; /* place to modify pc1 into */
  334. char pcr[56]; /* place to rotate pc1 into */
  335. register int i,j,l;
  336. int m;
  337. /* In mode 2, the 128 bytes of subkey are set directly from the
  338. * user's key, allowing him to use completely independent
  339. * subkeys for each round. Note that the user MUST specify a
  340. * full 128 bytes.
  341. *
  342. * I would like to think that this technique gives the NSA a real
  343. * headache, but I'm not THAT naive.
  344. */
  345. if(desmode == 2)
  346. {
  347. for(i=0;i<16;i++)
  348. for(j=0;j<8;j++)
  349. kn[i][j] = *key++;
  350. return;
  351. }
  352. //
  353. // Clear key schedule
  354. //
  355. for (i=0; i<16; i++)
  356. for (j=0; j<8; j++)
  357. kn[i][j]=0;
  358. for (j=0; j<56; j++) /* convert pc1 to bits of key */
  359. {
  360. l=pc1[j]-1; /* integer bit location */
  361. m = l & 07; /* find bit */
  362. pc1m[j]=(key[l>>3] & /* find which key byte l is in */
  363. bytebit[m]) /* and which bit of that byte */
  364. ? 1 : 0; /* and store 1-bit result */
  365. }
  366. for (i=0; i<16; i++) /* key chunk for each iteration */
  367. {
  368. for (j=0; j<56; j++) /* rotate pc1 the right amount */
  369. pcr[j] = pc1m[(l=j+totrot[i])<(j<28? 28 : 56) ? l: l-28];
  370. /* rotate left and right halves independently */
  371. for (j=0; j<48; j++)
  372. { /* select bits individually */
  373. /* check bit that goes to kn[j] */
  374. if (pcr[pc2[j]-1])
  375. {
  376. /* mask it in if it's there */
  377. l= j % 6;
  378. kn[i][j/6] |= bytebit[l] >> 2;
  379. }
  380. }
  381. }
  382. }
  383. //
  384. // In-place encryption of 64-bit block
  385. //
  386. VOID
  387. des_endes(
  388. IN PCHAR block
  389. )
  390. {
  391. register int i;
  392. unsigned long work[2]; /* Working data storage */
  393. long tmp;
  394. permute(block,iperm,(char *)work); /* Initial Permutation */
  395. work[0] = byteswap(work[0]);
  396. work[1] = byteswap(work[1]);
  397. /* Do the 16 rounds */
  398. for (i=0; i<16; i++)
  399. round(i,work);
  400. /* Left/right half swap */
  401. tmp = work[0];
  402. work[0] = work[1];
  403. work[1] = tmp;
  404. work[0] = byteswap(work[0]);
  405. work[1] = byteswap(work[1]);
  406. permute((char *)work,fperm,block); /* Inverse initial permutation */
  407. }
  408. //
  409. // In-place decryption of 64-bit block
  410. //
  411. VOID
  412. des_dedes(
  413. IN PCHAR block
  414. )
  415. {
  416. register int i;
  417. unsigned long work[2]; /* Working data storage */
  418. long tmp;
  419. permute(block,iperm,(char *)work); /* Initial permutation */
  420. work[0] = byteswap(work[0]);
  421. work[1] = byteswap(work[1]);
  422. /* Left/right half swap */
  423. tmp = work[0];
  424. work[0] = work[1];
  425. work[1] = tmp;
  426. /* Do the 16 rounds in reverse order */
  427. for (i=15; i >= 0; i--)
  428. round(i,work);
  429. work[0] = byteswap(work[0]);
  430. work[1] = byteswap(work[1]);
  431. permute((char *)work,fperm,block); /* Inverse initial permutation */
  432. }
  433. PCHAR
  434. des_pw_bitshift(
  435. IN PCHAR pw
  436. )
  437. {
  438. static char pws[8];
  439. int i;
  440. /* key is null padded */
  441. for (i = 0; i < 8; i++)
  442. pws[i] = 0;
  443. /* parity bit is always zero (this seem bogus) */
  444. for (i = 0; i < 8 && pw[i]; i++)
  445. pws[i] = pw[i] << 1;
  446. return pws;
  447. }
  448. PCHAR
  449. des_pw_bitshift_lowbit(
  450. IN PCHAR pw
  451. )
  452. {
  453. static char pws[8];
  454. int i;
  455. /* key is null padded */
  456. for (i = 0; i < 8; i++)
  457. pws[i] = 0;
  458. // In case of RandNum authentication, we need to drop the low bit!
  459. for (i = 0; i < 8 && pw[i]; i++)
  460. {
  461. pws[i] = (pw[i] & 0x7F);
  462. }
  463. return pws;
  464. }
  465. //
  466. // Permute inblock with perm
  467. //
  468. static
  469. VOID
  470. permute(
  471. IN PCHAR inblock, // result into outblock,64 bits
  472. IN CHAR perm[16][16][8], // 2K bytes defining perm.
  473. IN PCHAR outblock // result into outblock,64 bits
  474. )
  475. {
  476. register int i,j;
  477. register char *ib, *ob; /* ptr to input or output block */
  478. register char *p, *q;
  479. if(perm == NULL)
  480. {
  481. /* No permutation, just copy */
  482. for(i=8; i!=0; i--)
  483. *outblock++ = *inblock++;
  484. return;
  485. }
  486. /* Clear output block */
  487. for (i=8, ob = outblock; i != 0; i--)
  488. *ob++ = 0;
  489. ib = inblock;
  490. for (j = 0; j < 16; j += 2, ib++) /* for each input nibble */
  491. {
  492. ob = outblock;
  493. p = perm[j][(*ib >> 4) & 017];
  494. q = perm[j + 1][*ib & 017];
  495. for (i = 8; i != 0; i--) /* and each output byte */
  496. {
  497. *ob++ |= *p++ | *q++; /* OR the masks together*/
  498. }
  499. }
  500. }
  501. //
  502. // Do one DES cipher round
  503. //
  504. static
  505. VOID
  506. round(
  507. IN int num, // i.e. the num-th one
  508. IN unsigned long *block
  509. )
  510. {
  511. long f();
  512. /* The rounds are numbered from 0 to 15. On even rounds
  513. * the right half is fed to f() and the result exclusive-ORs
  514. * the left half; on odd rounds the reverse is done.
  515. */
  516. if(num & 1)
  517. {
  518. block[1] ^= f(block[0],kn[num]);
  519. } else
  520. {
  521. block[0] ^= f(block[1],kn[num]);
  522. }
  523. }
  524. //
  525. // The nonlinear function f(r,k), the heart of DES
  526. //
  527. static
  528. long
  529. f(r,subkey)
  530. unsigned long r; /* 32 bits */
  531. unsigned char subkey[8]; /* 48-bit key for this round */
  532. {
  533. register unsigned long rval,rt;
  534. #ifdef TRACE
  535. unsigned char *cp;
  536. int i;
  537. printf("f(%08lx, %02x %02x %02x %02x %02x %02x %02x %02x) = ",
  538. r,
  539. subkey[0], subkey[1], subkey[2],
  540. subkey[3], subkey[4], subkey[5],
  541. subkey[6], subkey[7]);
  542. #endif
  543. /* Run E(R) ^ K through the combined S & P boxes
  544. * This code takes advantage of a convenient regularity in
  545. * E, namely that each group of 6 bits in E(R) feeding
  546. * a single S-box is a contiguous segment of R.
  547. */
  548. rt = (r >> 1) | ((r & 1) ? 0x80000000 : 0);
  549. rval = 0;
  550. rval |= sp[0][((rt >> 26) ^ *subkey++) & 0x3f];
  551. rval |= sp[1][((rt >> 22) ^ *subkey++) & 0x3f];
  552. rval |= sp[2][((rt >> 18) ^ *subkey++) & 0x3f];
  553. rval |= sp[3][((rt >> 14) ^ *subkey++) & 0x3f];
  554. rval |= sp[4][((rt >> 10) ^ *subkey++) & 0x3f];
  555. rval |= sp[5][((rt >> 6) ^ *subkey++) & 0x3f];
  556. rval |= sp[6][((rt >> 2) ^ *subkey++) & 0x3f];
  557. rt = (r << 1) | ((r & 0x80000000) ? 1 : 0);
  558. rval |= sp[7][(rt ^ *subkey) & 0x3f];
  559. #ifdef TRACE
  560. printf(" %08lx\n",rval);
  561. #endif
  562. return rval;
  563. }
  564. //
  565. // initialize a perm array
  566. //
  567. static
  568. VOID
  569. perminit(
  570. IN CHAR perm[16][16][8], // 64-bit, either init or final
  571. IN CHAR p[64]
  572. )
  573. {
  574. register int l, j, k;
  575. int i,m;
  576. /* Clear the permutation array */
  577. for (i=0; i<16; i++)
  578. for (j=0; j<16; j++)
  579. for (k=0; k<8; k++)
  580. perm[i][j][k]=0;
  581. for (i=0; i<16; i++) /* each input nibble position */
  582. for (j = 0; j < 16; j++)/* each possible input nibble */
  583. for (k = 0; k < 64; k++)/* each output bit position */
  584. { l = p[k] - 1; /* where does this bit come from*/
  585. if ((l >> 2) != i) /* does it come from input posn?*/
  586. continue; /* if not, bit k is 0 */
  587. if (!(j & nibblebit[l & 3]))
  588. continue; /* any such bit in input? */
  589. m = k & 07; /* which bit is this in the byte*/
  590. perm[i][j][k>>3] |= bytebit[m];
  591. }
  592. }
  593. //
  594. // Initialize the lookup table for the combined S and P boxes
  595. //
  596. static int
  597. spinit()
  598. {
  599. char pbox[32];
  600. int p,i,s,j,rowcol;
  601. long val;
  602. /* Compute pbox, the inverse of p32i.
  603. * This is easier to work with
  604. */
  605. for(p=0;p<32;p++)
  606. {
  607. for(i=0;i<32;i++)
  608. {
  609. if(p32i[i]-1 == p)
  610. {
  611. pbox[p] = (char)i;
  612. break;
  613. }
  614. }
  615. }
  616. for(s = 0; s < 8; s++)
  617. { /* For each S-box */
  618. for(i=0; i<64; i++)
  619. { /* For each possible input */
  620. val = 0;
  621. /* The row number is formed from the first and last
  622. * bits; the column number is from the middle 4
  623. */
  624. rowcol = (i & 32) | ((i & 1) ? 16 : 0) | ((i >> 1) & 0xf);
  625. for(j=0;j<4;j++)
  626. { /* For each output bit */
  627. if(si[s][rowcol] & (8 >> j))
  628. {
  629. val |= 1L << (31 - pbox[4*s + j]);
  630. }
  631. }
  632. sp[s][i] = val;
  633. #ifdef DEBUG
  634. printf("sp[%d][%2d] = %08lx\n",s,i,sp[s][i]);
  635. #endif
  636. }
  637. }
  638. return(0);
  639. }
  640. /* Byte swap a long */
  641. static
  642. unsigned long
  643. byteswap(x)
  644. unsigned long x;
  645. {
  646. register char *cp,tmp;
  647. cp = (char *)&x;
  648. tmp = cp[3];
  649. cp[3] = cp[0];
  650. cp[0] = tmp;
  651. tmp = cp[2];
  652. cp[2] = cp[1];
  653. cp[1] = tmp;
  654. return x;
  655. }
  656. VOID
  657. DoTheDESEncrypt(
  658. IN OUT PCHAR ChallengeBuf
  659. )
  660. {
  661. des_endes(ChallengeBuf);
  662. }
  663. VOID
  664. DoTheDESDecrypt(
  665. IN OUT PCHAR ChallengeBuf
  666. )
  667. {
  668. des_dedes(ChallengeBuf);
  669. }
  670. VOID
  671. DoDesInit(
  672. IN PCHAR pClrTxtPwd,
  673. IN BOOLEAN DropHighBit // do we need to drop high bit in key-generation?
  674. )
  675. {
  676. des_init(0);
  677. if (DropHighBit)
  678. {
  679. des_setkey(des_pw_bitshift(pClrTxtPwd));
  680. }
  681. else
  682. {
  683. des_setkey(des_pw_bitshift_lowbit(pClrTxtPwd));
  684. }
  685. }
  686. VOID
  687. DoDesEnd(
  688. IN VOID
  689. )
  690. {
  691. des_done();
  692. }