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.

1841 lines
57 KiB

  1. //************************************************************************
  2. // Microsoft Corporation
  3. // Copyright(c) Microsoft Corp., 1990-1992
  4. //
  5. //
  6. // Revision history:
  7. // 5/5/94 Created gurdeep
  8. //
  9. //************************************************************************
  10. //#define COMP_12K
  11. #include "wan.h"
  12. #define __FILE_SIG__ COMPRESS_FILESIG
  13. //#define DEBUG
  14. CONST
  15. unsigned long lookup_array1[256] = {
  16. 0, 10276755, 20553510, 30830265,
  17. 41107020, 51383775, 61660530, 71937285,
  18. 82214040, 92490795, 102767550, 113044305,
  19. 123321060, 133597815, 143874570, 154151325,
  20. 164428080, 174704835, 184981590, 195258345,
  21. 205535100, 215811855, 226088610, 236365365,
  22. 246642120, 256918875, 267195630, 277472385,
  23. 287749140, 298025895, 308302650, 318579405,
  24. 328856160, 339132915, 349409670, 359686425,
  25. 369963180, 380239935, 390516690, 400793445,
  26. 411070200, 421346955, 431623710, 441900465,
  27. 452177220, 462453975, 472730730, 483007485,
  28. 493284240, 503560995, 513837750, 524114505,
  29. 534391260, 544668015, 554944770, 565221525,
  30. 575498280, 585775035, 596051790, 606328545,
  31. 616605300, 626882055, 637158810, 647435565,
  32. 657712320, 667989075, 678265830, 688542585,
  33. 698819340, 709096095, 719372850, 729649605,
  34. 739926360, 750203115, 760479870, 770756625,
  35. 781033380, 791310135, 801586890, 811863645,
  36. 822140400, 832417155, 842693910, 852970665,
  37. 863247420, 873524175, 883800930, 894077685,
  38. 904354440, 914631195, 924907950, 935184705,
  39. 945461460, 955738215, 966014970, 976291725,
  40. 986568480, 996845235, 1007121990, 1017398745,
  41. 1027675500, 1037952255, 1048229010, 1058505765,
  42. 1068782520, 1079059275, 1089336030, 1099612785,
  43. 1109889540, 1120166295, 1130443050, 1140719805,
  44. 1150996560, 1161273315, 1171550070, 1181826825,
  45. 1192103580, 1202380335, 1212657090, 1222933845,
  46. 1233210600, 1243487355, 1253764110, 1264040865,
  47. 1274317620, 1284594375, 1294871130, 1305147885,
  48. 1315424640, 1325701395, 1335978150, 1346254905,
  49. 1356531660, 1366808415, 1377085170, 1387361925,
  50. 1397638680, 1407915435, 1418192190, 1428468945,
  51. 1438745700, 1449022455, 1459299210, 1469575965,
  52. 1479852720, 1490129475, 1500406230, 1510682985,
  53. 1520959740, 1531236495, 1541513250, 1551790005,
  54. 1562066760, 1572343515, 1582620270, 1592897025,
  55. 1603173780, 1613450535, 1623727290, 1634004045,
  56. 1644280800, 1654557555, 1664834310, 1675111065,
  57. 1685387820, 1695664575, 1705941330, 1716218085,
  58. 1726494840, 1736771595, 1747048350, 1757325105,
  59. 1767601860, 1777878615, 1788155370, 1798432125,
  60. 1808708880, 1818985635, 1829262390, 1839539145,
  61. 1849815900, 1860092655, 1870369410, 1880646165,
  62. 1890922920, 1901199675, 1911476430, 1921753185,
  63. 1932029940, 1942306695, 1952583450, 1962860205,
  64. 1973136960, 1983413715, 1993690470, 2003967225,
  65. 2014243980, 2024520735, 2034797490, 2045074245,
  66. 2055351000, 2065627755, 2075904510, 2086181265,
  67. 2096458020, 2106734775, 2117011530, 2127288285,
  68. 2137565040, 2147841795, 2158118550, 2168395305,
  69. 2178672060, 2188948815, 2199225570, 2209502325,
  70. 2219779080, 2230055835, 2240332590, 2250609345,
  71. 2260886100, 2271162855, 2281439610, 2291716365,
  72. 2301993120, 2312269875, 2322546630, 2332823385,
  73. 2343100140, 2353376895, 2363653650, 2373930405,
  74. 2384207160, 2394483915, 2404760670, 2415037425,
  75. 2425314180, 2435590935, 2445867690, 2456144445,
  76. 2466421200, 2476697955, 2486974710, 2497251465,
  77. 2507528220, 2517804975, 2528081730, 2538358485,
  78. 2548635240, 2558911995, 2569188750, 2579465505,
  79. 2589742260, 2600019015, 2610295770, 2620572525
  80. };
  81. /*
  82. for i = 0 to 255,
  83. lookup_array2[i] = lookup_array1[i] << 8;
  84. */
  85. CONST
  86. unsigned long lookup_array2[256] = {
  87. 0, 2630849280, 966731264, 3597580544,
  88. 1933462528, 269344512, 2900193792, 1236075776,
  89. 3866925056, 2202807040, 538689024, 3169538304,
  90. 1505420288, 4136269568, 2472151552, 808033536,
  91. 3438882816, 1774764800, 110646784, 2741496064,
  92. 1077378048, 3708227328, 2044109312, 379991296,
  93. 3010840576, 1346722560, 3977571840, 2313453824,
  94. 649335808, 3280185088, 1616067072, 4246916352,
  95. 2582798336, 918680320, 3549529600, 1885411584,
  96. 221293568, 2852142848, 1188024832, 3818874112,
  97. 2154756096, 490638080, 3121487360, 1457369344,
  98. 4088218624, 2424100608, 759982592, 3390831872,
  99. 1726713856, 62595840, 2693445120, 1029327104,
  100. 3660176384, 1996058368, 331940352, 2962789632,
  101. 1298671616, 3929520896, 2265402880, 601284864,
  102. 3232134144, 1568016128, 4198865408, 2534747392,
  103. 870629376, 3501478656, 1837360640, 173242624,
  104. 2804091904, 1139973888, 3770823168, 2106705152,
  105. 442587136, 3073436416, 1409318400, 4040167680,
  106. 2376049664, 711931648, 3342780928, 1678662912,
  107. 14544896, 2645394176, 981276160, 3612125440,
  108. 1948007424, 283889408, 2914738688, 1250620672,
  109. 3881469952, 2217351936, 553233920, 3184083200,
  110. 1519965184, 4150814464, 2486696448, 822578432,
  111. 3453427712, 1789309696, 125191680, 2756040960,
  112. 1091922944, 3722772224, 2058654208, 394536192,
  113. 3025385472, 1361267456, 3992116736, 2327998720,
  114. 663880704, 3294729984, 1630611968, 4261461248,
  115. 2597343232, 933225216, 3564074496, 1899956480,
  116. 235838464, 2866687744, 1202569728, 3833419008,
  117. 2169300992, 505182976, 3136032256, 1471914240,
  118. 4102763520, 2438645504, 774527488, 3405376768,
  119. 1741258752, 77140736, 2707990016, 1043872000,
  120. 3674721280, 2010603264, 346485248, 2977334528,
  121. 1313216512, 3944065792, 2279947776, 615829760,
  122. 3246679040, 1582561024, 4213410304, 2549292288,
  123. 885174272, 3516023552, 1851905536, 187787520,
  124. 2818636800, 1154518784, 3785368064, 2121250048,
  125. 457132032, 3087981312, 1423863296, 4054712576,
  126. 2390594560, 726476544, 3357325824, 1693207808,
  127. 29089792, 2659939072, 995821056, 3626670336,
  128. 1962552320, 298434304, 2929283584, 1265165568,
  129. 3896014848, 2231896832, 567778816, 3198628096,
  130. 1534510080, 4165359360, 2501241344, 837123328,
  131. 3467972608, 1803854592, 139736576, 2770585856,
  132. 1106467840, 3737317120, 2073199104, 409081088,
  133. 3039930368, 1375812352, 4006661632, 2342543616,
  134. 678425600, 3309274880, 1645156864, 4276006144,
  135. 2611888128, 947770112, 3578619392, 1914501376,
  136. 250383360, 2881232640, 1217114624, 3847963904,
  137. 2183845888, 519727872, 3150577152, 1486459136,
  138. 4117308416, 2453190400, 789072384, 3419921664,
  139. 1755803648, 91685632, 2722534912, 1058416896,
  140. 3689266176, 2025148160, 361030144, 2991879424,
  141. 1327761408, 3958610688, 2294492672, 630374656,
  142. 3261223936, 1597105920, 4227955200, 2563837184,
  143. 899719168, 3530568448, 1866450432, 202332416,
  144. 2833181696, 1169063680, 3799912960, 2135794944,
  145. 471676928, 3102526208, 1438408192, 4069257472,
  146. 2405139456, 741021440, 3371870720, 1707752704,
  147. 43634688, 2674483968, 1010365952, 3641215232,
  148. 1977097216, 312979200, 2943828480, 1279710464,
  149. 3910559744, 2246441728, 582323712, 3213172992,
  150. 1549054976, 4179904256, 2515786240, 851668224
  151. };
  152. /*
  153. for i = 0 to 255,
  154. lookup_array3[i] = lookup_array1[i] << 16;
  155. */
  156. CONST
  157. unsigned long lookup_array3[256] = {
  158. 0, 3482517504, 2670067712, 1857617920,
  159. 1045168128, 232718336, 3715235840, 2902786048,
  160. 2090336256, 1277886464, 465436672, 3947954176,
  161. 3135504384, 2323054592, 1510604800, 698155008,
  162. 4180672512, 3368222720, 2555772928, 1743323136,
  163. 930873344, 118423552, 3600941056, 2788491264,
  164. 1976041472, 1163591680, 351141888, 3833659392,
  165. 3021209600, 2208759808, 1396310016, 583860224,
  166. 4066377728, 3253927936, 2441478144, 1629028352,
  167. 816578560, 4128768, 3486646272, 2674196480,
  168. 1861746688, 1049296896, 236847104, 3719364608,
  169. 2906914816, 2094465024, 1282015232, 469565440,
  170. 3952082944, 3139633152, 2327183360, 1514733568,
  171. 702283776, 4184801280, 3372351488, 2559901696,
  172. 1747451904, 935002112, 122552320, 3605069824,
  173. 2792620032, 1980170240, 1167720448, 355270656,
  174. 3837788160, 3025338368, 2212888576, 1400438784,
  175. 587988992, 4070506496, 3258056704, 2445606912,
  176. 1633157120, 820707328, 8257536, 3490775040,
  177. 2678325248, 1865875456, 1053425664, 240975872,
  178. 3723493376, 2911043584, 2098593792, 1286144000,
  179. 473694208, 3956211712, 3143761920, 2331312128,
  180. 1518862336, 706412544, 4188930048, 3376480256,
  181. 2564030464, 1751580672, 939130880, 126681088,
  182. 3609198592, 2796748800, 1984299008, 1171849216,
  183. 359399424, 3841916928, 3029467136, 2217017344,
  184. 1404567552, 592117760, 4074635264, 3262185472,
  185. 2449735680, 1637285888, 824836096, 12386304,
  186. 3494903808, 2682454016, 1870004224, 1057554432,
  187. 245104640, 3727622144, 2915172352, 2102722560,
  188. 1290272768, 477822976, 3960340480, 3147890688,
  189. 2335440896, 1522991104, 710541312, 4193058816,
  190. 3380609024, 2568159232, 1755709440, 943259648,
  191. 130809856, 3613327360, 2800877568, 1988427776,
  192. 1175977984, 363528192, 3846045696, 3033595904,
  193. 2221146112, 1408696320, 596246528, 4078764032,
  194. 3266314240, 2453864448, 1641414656, 828964864,
  195. 16515072, 3499032576, 2686582784, 1874132992,
  196. 1061683200, 249233408, 3731750912, 2919301120,
  197. 2106851328, 1294401536, 481951744, 3964469248,
  198. 3152019456, 2339569664, 1527119872, 714670080,
  199. 4197187584, 3384737792, 2572288000, 1759838208,
  200. 947388416, 134938624, 3617456128, 2805006336,
  201. 1992556544, 1180106752, 367656960, 3850174464,
  202. 3037724672, 2225274880, 1412825088, 600375296,
  203. 4082892800, 3270443008, 2457993216, 1645543424,
  204. 833093632, 20643840, 3503161344, 2690711552,
  205. 1878261760, 1065811968, 253362176, 3735879680,
  206. 2923429888, 2110980096, 1298530304, 486080512,
  207. 3968598016, 3156148224, 2343698432, 1531248640,
  208. 718798848, 4201316352, 3388866560, 2576416768,
  209. 1763966976, 951517184, 139067392, 3621584896,
  210. 2809135104, 1996685312, 1184235520, 371785728,
  211. 3854303232, 3041853440, 2229403648, 1416953856,
  212. 604504064, 4087021568, 3274571776, 2462121984,
  213. 1649672192, 837222400, 24772608, 3507290112,
  214. 2694840320, 1882390528, 1069940736, 257490944,
  215. 3740008448, 2927558656, 2115108864, 1302659072,
  216. 490209280, 3972726784, 3160276992, 2347827200,
  217. 1535377408, 722927616, 4205445120, 3392995328,
  218. 2580545536, 1768095744, 955645952, 143196160,
  219. 3625713664, 2813263872, 2000814080, 1188364288,
  220. 375914496, 3858432000, 3045982208, 2233532416,
  221. 1421082624, 608632832, 4091150336, 3278700544
  222. };
  223. /*
  224. The key for the multiplicative hash function consists of 3 unsigned
  225. characters. They are composed (logically) by concatenating them i.e.
  226. the composed key = 2^16*c2 + 2^8*c2 + c3 and fits in 24 bits. The
  227. composed key is not actually computed here as we use the components
  228. to directly compute the hash function.
  229. The multiplicative hash function consists of taking the higher order
  230. 12 bits (2^12 = 4096) of the lower order 24 bits of the product
  231. key * Multiplier where
  232. Multiplier = floor(A * pow(2.0, (double) w));
  233. double A = 0.6125423371; (chosen according to Knuth)
  234. w = 24 (the key's width in bits)
  235. The algorithm for this is in Cormen/Leiserson/Rivest.
  236. To do the multplication efficiently, the product c*Multiplier is
  237. precomputed and stored in lookup_array1 (for all 256 possible c's).
  238. lookup_array2 and lookup_array3 contain the same data as lookup_array1
  239. but shifted left 8 and 16 bits respectively.
  240. MultHash1 is the mult hashing function. MultHash0 contains an older
  241. (slower but less space-efficient) version of the same function.
  242. */
  243. #define MULTHASH1(c1,c2,c3) \
  244. ((lookup_array1[c1]+ \
  245. lookup_array2[c2]+ \
  246. lookup_array3[c3] ) & 0x00fff000) >> 12
  247. /*
  248. USHORT xorlookup1 [256] = {
  249. 0x110, 0x120, 0x130, 0x140, 0x150, 0x160, 0x170, 0x180, // 0-7
  250. 0x190, 0x1a0, 0x1b0, 0x1c0, 0x1d0, 0x1e0, 0x1f0, 0x100, // 8-15
  251. 0x210, 0x220, 0x230, 0x240, 0x250, 0x260, 0x270, 0x280, // 16-23
  252. 0x290, 0x2a0, 0x2b0, 0x2c0, 0x2d0, 0x2e0, 0x2f0, 0x200, // 24-31
  253. 0x310, 0x320, 0x330, 0x340, 0x350, 0x360, 0x370, 0x380, // 32-39
  254. 0x390, 0x3a0, 0x3b0, 0x3c0, 0x3d0, 0x3e0, 0x3f0, 0x300, // 40-47
  255. 0x410, 0x420, 0x430, 0x440, 0x450, 0x460, 0x470, 0x480, // 48-55
  256. 0x490, 0x4a0, 0x4b0, 0x4c0, 0x4d0, 0x4e0, 0x4f0, 0x400, // 56-63
  257. 0x510, 0x520, 0x530, 0x540, 0x550, 0x560, 0x570, 0x580, // 64-71
  258. 0x590, 0x5a0, 0x5b0, 0x5c0, 0x5d0, 0x5e0, 0x5f0, 0x500, // 72-79
  259. 0x610, 0x620, 0x630, 0x640, 0x650, 0x660, 0x670, 0x680, // 80-87
  260. 0x690, 0x6a0, 0x6b0, 0x6c0, 0x6d0, 0x6e0, 0x6f0, 0x600, // 88-95
  261. 0x710, 0x720, 0x730, 0x740, 0x750, 0x760, 0x770, 0x780, // 96-103
  262. 0x790, 0x7a0, 0x7b0, 0x7c0, 0x7d0, 0x7e0, 0x7f0, 0x700, // 104-111
  263. 0x810, 0x820, 0x830, 0x840, 0x850, 0x860, 0x870, 0x880, // 112-119
  264. 0x890, 0x8a0, 0x8b0, 0x8c0, 0x8d0, 0x8e0, 0x8f0, 0x800, // 120-127
  265. 0x910, 0x920, 0x930, 0x940, 0x950, 0x960, 0x970, 0x980, // 128-135
  266. 0x990, 0x9a0, 0x9b0, 0x9c0, 0x9d0, 0x9e0, 0x9f0, 0x900, // 136-143
  267. 0xa10, 0xa20, 0xa30, 0xa40, 0xa50, 0xa60, 0xa70, 0xa80, // 144-151
  268. 0xa90, 0xaa0, 0xab0, 0xac0, 0xad0, 0xae0, 0xaf0, 0xa00, // 152-159
  269. 0xb10, 0xb20, 0xb30, 0xb40, 0xb50, 0xb60, 0xb70, 0xb80, // 160-167
  270. 0xb90, 0xba0, 0xbb0, 0xbc0, 0xbd0, 0xbe0, 0xbf0, 0xb00, // 168-175
  271. 0xc10, 0xc20, 0xc30, 0xc40, 0xc50, 0xc60, 0xc70, 0xc80, // 176-183
  272. 0xc90, 0xca0, 0xcb0, 0xcc0, 0xcd0, 0xce0, 0xcf0, 0xc00, // 184-191
  273. 0xd10, 0xd20, 0xd30, 0xd40, 0xd50, 0xd60, 0xd70, 0xd80, // 192-199
  274. 0xd90, 0xda0, 0xdb0, 0xdc0, 0xdd0, 0xde0, 0xdf0, 0xd00, // 200-207
  275. 0xe10, 0xe20, 0xe30, 0xe40, 0xe50, 0xe60, 0xe70, 0xe80, // 208-215
  276. 0xe90, 0xea0, 0xeb0, 0xec0, 0xed0, 0xee0, 0xef0, 0xe00, // 216-223
  277. 0xf10, 0xf20, 0xf30, 0xf40, 0xf50, 0xf60, 0xf70, 0xf80, // 224-231
  278. 0xf90, 0xfa0, 0xfb0, 0xfc0, 0xfd0, 0xfe0, 0xff0, 0xf00, // 232-239
  279. 0x010, 0x020, 0x030, 0x040, 0x050, 0x060, 0x070, 0x080, // 240-247
  280. 0x090, 0x0a0, 0x0b0, 0x0c0, 0x0d0, 0x0e0, 0x0f0, 0x000 }; // 248-255
  281. USHORT xorlookup2 [256] = {
  282. 0x101, 0x201, 0x301, 0x401, 0x501, 0x601, 0x701, 0x801, // 0-7
  283. 0x901, 0xa01, 0xb01, 0xc01, 0xd01, 0xe01, 0xf01, 0x001, // 8-15
  284. 0x102, 0x202, 0x302, 0x402, 0x502, 0x602, 0x702, 0x802, // 16-23
  285. 0x902, 0xa02, 0xb02, 0xc02, 0xd02, 0xe02, 0xf02, 0x002, // 24-31
  286. 0x103, 0x203, 0x303, 0x403, 0x503, 0x603, 0x703, 0x803, // 32-39
  287. 0x903, 0xa03, 0xb03, 0xc03, 0xd03, 0xe03, 0xf03, 0x003, // 40-47
  288. 0x104, 0x204, 0x304, 0x404, 0x504, 0x604, 0x704, 0x804, // 48-55
  289. 0x904, 0xa04, 0xb04, 0xc04, 0xd04, 0xe04, 0xf04, 0x004, // 56-63
  290. 0x105, 0x205, 0x305, 0x405, 0x505, 0x605, 0x705, 0x805, // 64-71
  291. 0x905, 0xa05, 0xb05, 0xc05, 0xd05, 0xe05, 0xf05, 0x005, // 72-79
  292. 0x106, 0x206, 0x306, 0x406, 0x506, 0x606, 0x706, 0x806, // 80-87
  293. 0x906, 0xa06, 0xb06, 0xc06, 0xd06, 0xe06, 0xf06, 0x006, // 88-95
  294. 0x107, 0x207, 0x307, 0x407, 0x507, 0x607, 0x707, 0x807, // 96-103
  295. 0x907, 0xa07, 0xb07, 0xc07, 0xd07, 0xe07, 0xf07, 0x007, // 104-111
  296. 0x108, 0x208, 0x308, 0x408, 0x508, 0x608, 0x708, 0x808, // 112-119
  297. 0x908, 0xa08, 0xb08, 0xc08, 0xd08, 0xe08, 0xf08, 0x008, // 120-127
  298. 0x109, 0x209, 0x309, 0x409, 0x509, 0x609, 0x709, 0x809, // 128-135
  299. 0x909, 0xa09, 0xb09, 0xc09, 0xd09, 0xe09, 0xf09, 0x009, // 136-143
  300. 0x10a, 0x20a, 0x30a, 0x40a, 0x50a, 0x60a, 0x70a, 0x80a, // 144-151
  301. 0x90a, 0xa0a, 0xb0a, 0xc0a, 0xd0a, 0xe0a, 0xf0a, 0x00a, // 152-159
  302. 0x10b, 0x20b, 0x30b, 0x40b, 0x50b, 0x60b, 0x70b, 0x80b, // 160-167
  303. 0x90b, 0xa0b, 0xb0b, 0xc0b, 0xd0b, 0xe0b, 0xf0b, 0x00b, // 168-175
  304. 0x10c, 0x20c, 0x30c, 0x40c, 0x50c, 0x60c, 0x70c, 0x80c, // 176-183
  305. 0x90c, 0xa0c, 0xb0c, 0xc0c, 0xd0c, 0xe0c, 0xf0c, 0x00c, // 184-191
  306. 0x10d, 0x20d, 0x30d, 0x40d, 0x50d, 0x60d, 0x70d, 0x80d, // 192-199
  307. 0x90d, 0xa0d, 0xb0d, 0xc0d, 0xd0d, 0xe0d, 0xf0d, 0x00d, // 200-207
  308. 0x10e, 0x20e, 0x30e, 0x40e, 0x50e, 0x60e, 0x70e, 0x80e, // 208-215
  309. 0x90e, 0xa0e, 0xb0e, 0xc0e, 0xd0e, 0xe0e, 0xf0e, 0x00e, // 216-223
  310. 0x10f, 0x20f, 0x30f, 0x40f, 0x50f, 0x60f, 0x70f, 0x80f, // 224-231
  311. 0x90f, 0xa0f, 0xb0f, 0xc0f, 0xd0f, 0xe0f, 0xf0f, 0x00f, // 232-239
  312. 0x000, 0x200, 0x300, 0x400, 0x500, 0x600, 0x700, 0x800, // 240-247
  313. 0x900, 0xa00, 0xb00, 0xc00, 0xd00, 0xe00, 0xf00, 0x100 }; // 248-255
  314. */
  315. /* Bitptrs point to the current byte. The current bit (i.e. next bit to be
  316. * stored) is masked off by the bit entry. When this reaches zero, it is
  317. * reset to 0x80 and the next byte is set up. The bytes are filled MSBit
  318. * first. */
  319. /* Starts and sets the first byte to zero for the bitptr. */
  320. #define bitptr_init(s) pbyte = s; byte=0; bit = 16;
  321. /* Sets up the byte part of the bitptr so that it is pointing to the byte after
  322. * the byte which had the last bit put into it. */
  323. #define bitptr_end() if (bit != 16) *pbyte++=(UCHAR)(byte >> 8);
  324. /* Goes to the next bit, and byte if necessary. */
  325. #define bitptr_next() \
  326. if (bit < 10) { \
  327. *pbyte++=(UCHAR)(byte >> 8); \
  328. byte <<= 8; \
  329. bit = 16; \
  330. } else \
  331. bit-- ;
  332. /*
  333. #define bitptr_next() \
  334. bit--; \
  335. if (bit < 9) { \
  336. *pbyte++=(UCHAR)(byte >> 8); \
  337. byte <<= 8; \
  338. bit = 16; \
  339. }
  340. */
  341. /* Advances to the next bit, and byte if necessary, readjusting the bit. */
  342. #define bitptr_advance() \
  343. if (bit < 9) { \
  344. *pbyte++=(UCHAR)(byte >> 8); \
  345. bit+=8; \
  346. byte <<= 8; \
  347. }
  348. /* BIT I/O FUNCTIONS *********************************************************/
  349. /* These routines output most-significant-bit-first and the input will return
  350. * them MSB first, too. */
  351. /* Outputs a one bit in the bit stream. */
  352. #define out_bit_1() bit--; byte |= (1 << bit); bitptr_advance();
  353. #define out_bit_0() bitptr_next();
  354. /* TestBit; output 1 if that bit is set */
  355. //#define tb(b,w,n) if ((w) & (n)) *pbyte |= bit; bitptr_next(b);
  356. #define out_bits_2(w) bit-=2; byte|=(w << bit); bitptr_advance();
  357. #define out_bits_3(w) bit-=3; byte|=(w << bit); bitptr_advance();
  358. #define out_bits_4(w) bit-=4; byte|=(w << bit); bitptr_advance();
  359. #define out_bits_5(w) bit-=5; byte|=(w << bit); bitptr_advance();
  360. #define out_bits_6(w) bit-=6; byte|=(w << bit); bitptr_advance();
  361. #define out_bits_7(w) bit-=7; byte|=(w << bit); bitptr_advance();
  362. // #define out_bits_8(w) bit-=8; byte|=(w << bit); bit+=8; *pbyte++=(UCHAR)(byte >> 8); byte <<= 8;
  363. #define out_bits_8(w) byte|=(w << (bit-8)); *pbyte++=(UCHAR)(byte >> 8); byte <<= 8;
  364. /*
  365. #define out_bits_9(w) \
  366. if (bit > 9) { \
  367. bit-=9; byte|=(w << bit); \
  368. *pbyte++=(UCHAR)(byte >> 8);\
  369. bit+=8; \
  370. byte <<= 8; \
  371. } else { \
  372. bit=16; byte |= w; \
  373. *pbyte++=(UCHAR)(byte >> 8); *pbyte++=(UCHAR)(byte); byte=0; \
  374. }
  375. */
  376. #define out_bits_9(w) \
  377. if (bit > 9) { \
  378. byte|=(w << (bit-9)); \
  379. *pbyte++=(UCHAR)(byte >> 8);\
  380. bit--; \
  381. byte <<= 8; \
  382. } else { \
  383. bit=16; byte |= w; \
  384. *pbyte++=(UCHAR)(byte >> 8); *pbyte++=(UCHAR)(byte); byte=0; \
  385. }
  386. #define out_bits_10(w) \
  387. if (bit > 10) { \
  388. bit-=10; byte |= (w << bit); *pbyte++ = (UCHAR)(byte >> 8); bit+=8; byte <<=8; \
  389. } else { \
  390. out_bits_2((w >> 8)); \
  391. out_bits_8((w & 0xFF)); \
  392. }
  393. //
  394. // Weird effect - if out_bits_9 used instead of out_bits_8,
  395. // it's faster! if (bit == 11) is faster than if (bit != 11).
  396. //
  397. #define out_bits_11(w) \
  398. if (bit > 11) { \
  399. bit-=11; byte |= (w << bit); *pbyte++ = (UCHAR)(byte >> 8); bit+=8; byte <<=8; \
  400. } else { \
  401. if (bit == 11) { \
  402. bit=16; byte |= w; \
  403. *pbyte++=(UCHAR)(byte >> 8); *pbyte++=(UCHAR)(byte); byte=0; \
  404. } else { \
  405. bit=11-bit; \
  406. byte|=(w >> bit); \
  407. *pbyte++=(UCHAR)(byte >> 8); *pbyte++=(UCHAR)(byte); \
  408. bit=16-bit; \
  409. byte=(w << bit); \
  410. } \
  411. }
  412. #define out_bits_12(w) \
  413. if (bit > 12) { \
  414. bit-=12; byte |= (w << bit); *pbyte++ = (UCHAR)(byte >> 8); bit+=8; byte <<=8; \
  415. } else { \
  416. out_bits_4((w >> 8)); \
  417. out_bits_8((w & 0xFF)); \
  418. }
  419. #define out_bits_13(w) \
  420. if (bit > 13) { \
  421. bit-=13; byte |= (w << bit); *pbyte++ = (UCHAR)(byte >> 8); bit+=8; byte <<=8; \
  422. } else { \
  423. out_bits_5((w >> 8)); \
  424. out_bits_8((w & 0xFF)); \
  425. }
  426. #define out_bits_14(w) \
  427. if (bit > 14) { \
  428. bit-=14; byte |= (w << bit); *pbyte++ = (UCHAR)(byte >> 8); bit+=8; byte <<=8; \
  429. } else { \
  430. out_bits_6((w >> 8)); \
  431. out_bits_8((w & 0xFF)); \
  432. }
  433. #define out_reserve_4() \
  434. bit-=4; bitptr_advance();
  435. /* Starts the given bit pointer */
  436. #define inbit_start(s) pbyte = s; bit = 16; byte=(*pbyte << 8) + *(pbyte+1); pbyte++;
  437. #define inbit_end() if (bit != 16) pbyte++;
  438. #define in_bit_next() if (bit < 9) { \
  439. bit=16; \
  440. byte <<=8; \
  441. byte |= *(++pbyte); \
  442. }
  443. #define in_bit_advance() if (bit < 9) { \
  444. bit+=8; \
  445. byte <<=8; \
  446. byte |= *(++pbyte); \
  447. }
  448. /* Returns non-zero in bitset if the next bit in the stream is a 1. */
  449. #define in_bit() bit--; bitset = (byte >> bit) & 1; in_bit_next()
  450. #define in_bits_2(w) bit-=2; w = (byte >> bit) & 0x03;\
  451. in_bit_advance();
  452. #define in_bits_3(w) bit-=3; w = (byte >> bit) & 0x07;\
  453. in_bit_advance();
  454. #define in_bits_4(w) bit-=4; w = (byte >> bit) & 0x0F;\
  455. in_bit_advance();
  456. #define in_bits_5(w) bit-=5; w = (byte >> bit) & 0x1F;\
  457. in_bit_advance();
  458. #define in_bits_6(w) bit-=6; w = (byte >> bit) & 0x3F;\
  459. in_bit_advance();
  460. #define in_bits_7(w) bit-=7; w = (byte >> bit) & 0x7F;\
  461. in_bit_advance();
  462. #define in_bits_8(w) bit-=8; w = (byte >> bit) & 0xFF;\
  463. bit+=8; byte <<=8; byte |= *(++pbyte);
  464. #define in_bits_9(w) bit-=9; w = (byte >> bit) & 0x1FF; \
  465. bit+=8; byte <<=8; byte |= *(++pbyte); \
  466. in_bit_advance();
  467. #define in_bits_10(w) if (bit > 10) { \
  468. bit-=10; w = (byte >> bit) & 0x3FF; \
  469. bit+=8; byte <<=8; byte |= *(++pbyte); \
  470. } else { \
  471. in_bits_2(bitset); \
  472. in_bits_8(w); \
  473. w= w + (bitset << 8); \
  474. }
  475. #define in_bits_11(w) if (bit > 11) { \
  476. bit-=11; w = (byte >> bit) & 0x7FF; \
  477. bit+=8; byte <<=8; byte |= *(++pbyte); \
  478. } else { \
  479. in_bits_3(bitset); \
  480. in_bits_8(w); \
  481. w= w + (bitset << 8); \
  482. }
  483. #define in_bits_12(w) if (bit > 12) { \
  484. bit-=12; w = (byte >> bit) & 0xFFF; \
  485. bit+=8; byte <<=8; byte |= *(++pbyte); \
  486. } else { \
  487. in_bits_4(bitset); \
  488. in_bits_8(w); \
  489. w= w + (bitset << 8); \
  490. }
  491. #define in_bits_13(w)\
  492. if (bit > 13) { \
  493. bit-=13; w = (byte >> bit) & 0x1FFF; \
  494. bit+=8; byte <<=8; byte |= *(++pbyte); \
  495. } else { \
  496. in_bits_5(bitset); \
  497. in_bits_8(w); \
  498. w=w + (bitset << 8); \
  499. }
  500. #define in_bits_14(w)\
  501. if (bit > 14) { \
  502. bit-=14; w = (byte >> bit) & 0x3FFF; \
  503. bit+=8; byte <<=8; byte |= *(++pbyte); \
  504. } else { \
  505. in_bits_6(bitset); \
  506. in_bits_8(w); \
  507. w=w + (bitset << 8); \
  508. }
  509. UCHAR SHApad1[40] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  510. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  511. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
  512. 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
  513. UCHAR SHApad2[40] = {0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
  514. 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
  515. 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2,
  516. 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2, 0xF2};
  517. PUCHAR ClntSSrvR = "On the client side, this is the send key; on the server side, it is the receive key.";
  518. PUCHAR ClntRSrvS = "On the client side, this is the receive key; on the server side, it is the send key.";
  519. #define ECP_STRING_LEN strlen(ClntSSrvR)
  520. #ifdef DEBUG
  521. char
  522. ChPrint(UCHAR b)
  523. {
  524. if (isprint(b))
  525. return (char)b;
  526. else
  527. return '.';
  528. }
  529. #endif
  530. //* compress()
  531. //
  532. // Function: Main compression function.
  533. //
  534. // Parameters:
  535. // IN CurrentBuffer -> points to NDIS_WAN_PACKET with data to compress
  536. // OUT CompOutBuffer -> points to NDIS_WAN_PACKET to compress data to
  537. // IN CurrentLength -> points to Length of data to compress
  538. // IN context -> connection compress context
  539. //
  540. // Returns: Nothing
  541. //
  542. // WARNING: CODE IS HIGHLY OPTIMIZED FOR TIME.
  543. //
  544. //
  545. UCHAR
  546. compress (UCHAR *CurrentBuffer, UCHAR *CompOutBuffer, ULONG *CurrentLength, SendContext *context)
  547. {
  548. int copylen ;
  549. int bit;
  550. int byte;
  551. int backptr ;
  552. int cbMatch;
  553. int hashvalue ;
  554. int lookup1 ;
  555. UCHAR *matchptr ;
  556. UCHAR *pbyte;
  557. UCHAR *historyptr ;
  558. UCHAR *currentptr ;
  559. UCHAR *endptr ;
  560. UCHAR hashchar1;
  561. UCHAR hashchar2;
  562. UCHAR hashchar3;
  563. int literal ;
  564. UCHAR status=0; // return flags
  565. PUCHAR currentbuf ;
  566. // Will this packet fit at the end of the history buffer?
  567. //
  568. if (((context->CurrentIndex + *CurrentLength) >= (HISTORY_MAX - 1 )) ||
  569. (context->CurrentIndex == 0)) {
  570. context->CurrentIndex = 0; // Index into the history
  571. status |= PACKET_AT_FRONT;
  572. }
  573. //
  574. // we no longer need to save the non compressed data - tonybe 01-12-95
  575. //
  576. // RtlMoveMemory(context->CompressBuffer, CurrentBuffer, *CurrentLength) ;
  577. // Start out the bit pointing output
  578. //
  579. bitptr_init(CompOutBuffer);
  580. //
  581. // We are now compressing into an output buffer - tonybe 01-12-95
  582. //
  583. // bitptr_init(CurrentBuffer);
  584. historyptr = context->History + context->CurrentIndex ;
  585. currentptr = CurrentBuffer;
  586. //
  587. // we are now compressing from the currentbuffer - tonybe 01-12-95
  588. //
  589. // currentptr = context->CompressBuffer ;
  590. endptr = currentptr + *CurrentLength - 1;
  591. while (currentptr < (endptr-2)) {
  592. *historyptr++ = hashchar1 = *currentptr++ ;
  593. hashchar2 = *currentptr ;
  594. hashchar3 = *(currentptr+1) ;
  595. // "fast" hash function
  596. // hashvalue = (int)hashchar1 ^ xorlookup1[hashchar2] ^ xorlookup2[hashchar3];
  597. hashvalue = MULTHASH1(hashchar1, hashchar2, hashchar3) ;
  598. matchptr = context->History + context->HashTable[hashvalue] ;
  599. if (matchptr != (historyptr - 1))
  600. context->HashTable[hashvalue] = (USHORT)(historyptr - context->History) ;
  601. if (context->ValidHistory < historyptr)
  602. context->ValidHistory = historyptr ;
  603. if (matchptr != context->History &&
  604. *(matchptr-1) == hashchar1 && *matchptr == hashchar2 &&
  605. *(matchptr+1) == hashchar3 && matchptr != (historyptr - 1) &&
  606. matchptr != historyptr && (matchptr+1) <= context->ValidHistory) {
  607. backptr = ((int)(historyptr - matchptr)) & (HISTORY_SIZE - 1) ;
  608. *historyptr++ = hashchar2 ; // copy the other 2 chars
  609. *historyptr++ = hashchar3 ; // copy the other 2 chars
  610. currentptr +=2 ;
  611. cbMatch = 3 ; // length of match
  612. matchptr +=2 ; // we have already matched 3
  613. while ((*matchptr == *currentptr) && (currentptr < endptr) && (matchptr <= context->ValidHistory)) {
  614. matchptr++ ;
  615. *historyptr++ = *currentptr++ ;
  616. cbMatch++ ;
  617. }
  618. // First output the backpointer
  619. //
  620. if (backptr >= 320) {
  621. backptr -= 320 ;
  622. out_bits_8((0xc000 + backptr) >> 8) ; // 110 + 13 bits
  623. out_bits_8((backptr)) ;
  624. } else if (backptr < 64) { // 1111 + 6 bits
  625. backptr += 0x3c0 ;
  626. out_bits_10(backptr);
  627. } else {
  628. backptr += (0xE00 - 64); // 1110 + 8 bits
  629. out_bits_12(backptr);
  630. }
  631. // output the length of the match encoding
  632. //
  633. switch (cbMatch) {
  634. case 3:
  635. out_bit_0(); // length of 3 - most common
  636. break;
  637. case 4:
  638. out_bits_4(8);
  639. break;
  640. case 5:
  641. out_bits_4(9);
  642. break;
  643. case 6:
  644. out_bits_4(10);
  645. break;
  646. case 7:
  647. out_bits_4(11);
  648. break;
  649. case 8:
  650. out_bits_6(48);
  651. break;
  652. case 9:
  653. out_bits_6(49);
  654. break;
  655. case 10:
  656. out_bits_6(50);
  657. break;
  658. case 11:
  659. out_bits_6(51);
  660. break;
  661. case 12:
  662. out_bits_6(52);
  663. break;
  664. case 13:
  665. out_bits_6(53);
  666. break;
  667. case 14:
  668. out_bits_6(54);
  669. break;
  670. case 15:
  671. out_bits_6(55);
  672. break;
  673. case 16:
  674. out_bits_8(0xe0);
  675. break;
  676. case 17:
  677. out_bits_8(0xe1);
  678. break;
  679. case 18:
  680. out_bits_8(0xe2);
  681. break;
  682. case 19:
  683. out_bits_8(0xe3);
  684. break;
  685. case 20:
  686. out_bits_8(0xe4);
  687. break;
  688. case 21:
  689. out_bits_8(0xe5);
  690. break;
  691. case 22:
  692. out_bits_8(0xe6);
  693. break;
  694. case 23:
  695. out_bits_8(0xe7);
  696. break;
  697. case 24:
  698. out_bits_8(0xe8);
  699. break;
  700. case 25:
  701. out_bits_8(0xe9);
  702. break;
  703. case 26:
  704. out_bits_8(0xea);
  705. break;
  706. case 27:
  707. out_bits_8(0xeb);
  708. break;
  709. case 28:
  710. out_bits_8(0xec);
  711. break;
  712. case 29:
  713. out_bits_8(0xed);
  714. break;
  715. case 30:
  716. out_bits_8(0xee);
  717. break;
  718. case 31:
  719. out_bits_8(0xef);
  720. break;
  721. default:
  722. if (cbMatch < 64) {
  723. out_bits_4(0xF) ;
  724. cbMatch -= 32 ;
  725. out_bits_6(cbMatch) ;
  726. }
  727. else if (cbMatch < 128) {
  728. out_bits_5(0x1F) ;
  729. cbMatch -= 64 ;
  730. out_bits_7(cbMatch) ;
  731. }
  732. else if (cbMatch < 256) {
  733. out_bits_6(0x3F) ;
  734. cbMatch -= 128 ;
  735. out_bits_8(cbMatch) ;
  736. }
  737. else if (cbMatch < 512) {
  738. out_bits_7(0x7F) ;
  739. cbMatch -= 256 ;
  740. out_bits_9(cbMatch) ;
  741. }
  742. else if (cbMatch < 1024) {
  743. out_bits_8(0xFF) ;
  744. cbMatch -= 512 ;
  745. out_bits_10(cbMatch) ;
  746. }
  747. else if (cbMatch < 2048) {
  748. out_bits_9(0x1FF) ;
  749. cbMatch -= 1024 ;
  750. out_bits_11(cbMatch) ;
  751. }
  752. else if (cbMatch < 4096) {
  753. out_bits_10(0x3FF) ;
  754. cbMatch -= 2048 ;
  755. out_bits_12(cbMatch) ;
  756. }
  757. else if (cbMatch < 8192) {
  758. out_bits_11(0x7FF) ;
  759. cbMatch -= 4096 ;
  760. out_bits_13(cbMatch) ;
  761. }
  762. else { // 8192 and greater
  763. out_bits_12(0xFFF) ;
  764. cbMatch -= 8192 ;
  765. out_bits_14(cbMatch) ;
  766. }
  767. break ;
  768. }
  769. } else { // encode a literal
  770. // temp=literallookup[context->History[i-1]] ;
  771. literal= hashchar1 ;
  772. if (literal & 0x80) {
  773. literal += 0x80;
  774. out_bits_9(literal) ;
  775. } else {
  776. out_bits_8(literal) ;
  777. }
  778. }
  779. } // while
  780. // get any remaining chars as literals
  781. while (currentptr <= endptr) {
  782. // temp=literallookup[context->History[i-1]] ;
  783. literal=*currentptr ;
  784. if (literal & 0x80) {
  785. literal += 0x80;
  786. out_bits_9(literal) ;
  787. } else {
  788. out_bits_8(literal) ;
  789. }
  790. *historyptr++ = *currentptr++ ;
  791. }
  792. bitptr_end() ;
  793. // Check if we had expansion instead of compression
  794. //
  795. if ((ULONG)(pbyte - CompOutBuffer) > *CurrentLength) { // expansion.
  796. //
  797. // We don't need to do this copy since we can just signal the outside world
  798. // that compression did not take place and the valid data is still in the
  799. // current buffer
  800. //
  801. // RtlMoveMemory(CompOutBuffer, CurrentBuffer, *CurrentLength) ;
  802. memset (context->History, 0, sizeof(context->History)) ;
  803. memset (context->HashTable, 0, sizeof(context->HashTable)) ;
  804. #ifdef COMP_12K
  805. status = 0 ;
  806. #else
  807. status = PACKET_FLUSHED;
  808. #endif
  809. context->CurrentIndex = HISTORY_SIZE+1 ; // this forces a start over next time
  810. } else { // compression successful
  811. *CurrentLength = (ULONG)(pbyte - CompOutBuffer);
  812. //
  813. // the compressed data is now in CompOutBuffer - tonybe 01-12-95
  814. //
  815. // *CurrentLength = pbyte - CurrentBuffer ;
  816. status |= PACKET_COMPRESSED ;
  817. context->CurrentIndex = (int)(historyptr - context->History) ;
  818. }
  819. return(status);
  820. }
  821. //* getcontextsizes()
  822. //
  823. // Function: Returns size of send and receive context blocks
  824. //
  825. // Parameters: OUT send -> sizeof(SendContext)
  826. // OUT recv -> sizeof(RecvContext)
  827. //
  828. // Returns: Nothing
  829. //
  830. //*
  831. void
  832. getcontextsizes (long *send, long *recv)
  833. {
  834. *send = sizeof(SendContext) ;
  835. *recv = sizeof(RecvContext) ;
  836. }
  837. //* initsendcontext()
  838. //
  839. // Function: Initialize SendContext block
  840. //
  841. // Parameters: IN context -> connection compress context
  842. //
  843. // Returns: Nothing
  844. //
  845. //*
  846. void
  847. initsendcontext (SendContext *context)
  848. {
  849. context->CurrentIndex = 0; // Index into the history
  850. context->ValidHistory = 0 ; // reset valid history
  851. memset (context->HashTable, 0, sizeof(context->HashTable)) ;
  852. memset (context->History, 0, sizeof(context->HashTable)) ;
  853. }
  854. //* initrecvcontext()
  855. //
  856. // Function: Initialize RecvContext block
  857. //
  858. // Parameters: IN context -> connection decompress context
  859. //
  860. // Returns: Nothing
  861. //
  862. //*
  863. void
  864. initrecvcontext (RecvContext *context)
  865. {
  866. context->CurrentPtr = context->History ;
  867. #if DBG
  868. context->DebugFence = DEBUG_FENCE_VALUE;
  869. #endif
  870. memset (context->History, 0, sizeof(context->History)) ;
  871. }
  872. //* decompress()
  873. //
  874. // Function: de-compression function.
  875. //
  876. // Parameters: IN inbuf -> points to data to be uncompressed
  877. // IN inlen -> length of data
  878. // IN start -> flag indicating whether to start with a clean history buffer
  879. // OUT output-> decompressed data
  880. // OUT outlen-> lenght of decompressed data
  881. // IN context -> connection decompress context
  882. //
  883. // Returns: TRUE if decompress was successful
  884. // FALSE if it wasnt
  885. //
  886. // WARNING: CODE IS HIGHLY OPTIMIZED FOR TIME.
  887. //
  888. //*
  889. int
  890. decompress(
  891. UCHAR *inbuf,
  892. int inlen,
  893. int start,
  894. UCHAR **output,
  895. int *outlen,
  896. RecvContext *context)
  897. {
  898. UCHAR *inend; // When we know we're done decompressing
  899. UCHAR *outstart; // Remember where in dbuf we started
  900. UCHAR *current;
  901. int backptr; // Back pointer for copy items
  902. int length; // Where to copy from in dbuf
  903. UCHAR *s1, *s2;
  904. int bitset;
  905. int bit;
  906. int byte;
  907. UCHAR *pbyte;
  908. UCHAR *historyend = context->History + HISTORY_SIZE ;
  909. inend = inbuf + inlen ;
  910. //
  911. // Start out looking at the first bit
  912. //
  913. inbit_start(inbuf);
  914. if (start) // start over clean?
  915. context->CurrentPtr = current = context->History ;
  916. else
  917. current = context->CurrentPtr ;
  918. //
  919. // Save our starting position
  920. //
  921. outstart = current;
  922. //
  923. // Decompress until we run out of input
  924. //
  925. while (pbyte < inend) {
  926. //
  927. // Jump on what to do with these three bits.
  928. //
  929. in_bits_3(length);
  930. switch (length) {
  931. case 0:
  932. in_bits_5(length) ;
  933. goto LITERAL ;
  934. case 1:
  935. in_bits_5(length) ;
  936. length += 32 ;
  937. goto LITERAL ;
  938. case 2:
  939. in_bits_5(length) ;
  940. length += 64 ;
  941. goto LITERAL ;
  942. case 3:
  943. in_bits_5(length) ;
  944. length += 96 ;
  945. goto LITERAL ;
  946. case 4:
  947. in_bits_6(length) ;
  948. length +=128 ;
  949. goto LITERAL ;
  950. case 5:
  951. in_bits_6(length) ;
  952. length +=192 ;
  953. goto LITERAL ;
  954. case 6:
  955. in_bits_13 (backptr) ; // 110 - 14 bit offset
  956. backptr+=320 ;
  957. break ;
  958. case 7:
  959. in_bit() ;
  960. if (bitset) {
  961. in_bits_6(backptr) ;
  962. } else {
  963. in_bits_8(backptr) ;
  964. backptr+=64 ;
  965. }
  966. break ;
  967. }
  968. //
  969. // If we reach here, it's a copy item
  970. //
  971. //
  972. // Now get the length
  973. //
  974. in_bit() ; // 1st length bit
  975. if (!bitset) {
  976. length = 3 ;
  977. goto DONE ;
  978. }
  979. in_bit() ; // 2nd length bit
  980. if (!bitset) {
  981. in_bits_2 (length) ;
  982. length += 4 ;
  983. goto DONE ;
  984. }
  985. in_bit() ; // 3rd length bit
  986. if (!bitset) {
  987. in_bits_3 (length) ;
  988. length += 8 ;
  989. goto DONE ;
  990. }
  991. in_bit() ; // 4th length bit
  992. if (!bitset) {
  993. in_bits_4 (length) ;
  994. length += 16 ;
  995. goto DONE ;
  996. }
  997. in_bit() ; // 5th length bit
  998. if (!bitset) {
  999. in_bits_5 (length) ;
  1000. length += 32 ;
  1001. goto DONE ;
  1002. }
  1003. in_bit() ; // 6th length bit
  1004. if (!bitset) {
  1005. in_bits_6 (length) ;
  1006. length += 64 ;
  1007. goto DONE ;
  1008. }
  1009. in_bit() ; // 7th length bit
  1010. if (!bitset) {
  1011. in_bits_7 (length) ;
  1012. length += 128 ;
  1013. goto DONE ;
  1014. }
  1015. in_bit() ; // 8th length bit
  1016. if (!bitset) {
  1017. in_bits_8 (length) ;
  1018. length += 256 ;
  1019. goto DONE ;
  1020. }
  1021. in_bit() ; // 9th length bit
  1022. if (!bitset) {
  1023. in_bits_9 (length) ;
  1024. length += 512 ;
  1025. goto DONE ;
  1026. }
  1027. in_bit() ; // 10th length bit
  1028. if (!bitset) {
  1029. in_bits_10 (length) ;
  1030. length += 1024 ;
  1031. goto DONE ;
  1032. }
  1033. //
  1034. // length cannot be greater than max packets size which is 1500
  1035. //
  1036. #if DBG
  1037. DbgPrint("NDISWAN: RAS Decompressor problem1: Possible data corruption\n");
  1038. #endif
  1039. return FALSE ;
  1040. DONE:
  1041. //
  1042. // Turn the backptr into an index location
  1043. //
  1044. #ifdef COMP_12K
  1045. s2 = current - backptr ;
  1046. #else
  1047. s2 = context->History + (((current - context->History) - backptr) & (HISTORY_SIZE -1)) ;
  1048. #endif
  1049. s1 = current;
  1050. current += length;
  1051. // if we are past the end of the history this is a bad sign: abort decompression
  1052. //
  1053. if (current >= historyend) {
  1054. #if DBG
  1055. DbgPrint("NDISWAN: RAS Decompressor problem2: Possible data corruption\n");
  1056. #endif
  1057. return FALSE ;
  1058. }
  1059. // loop unrolled to handle lenght>backptr case
  1060. //
  1061. *s1=*s2;
  1062. *(s1+1)=*(s2+1);
  1063. s1+=2;
  1064. s2+=2;
  1065. length-=2;
  1066. //
  1067. // copy all the bytes
  1068. //
  1069. while (length) {
  1070. *s1++=*s2++;
  1071. length--;
  1072. }
  1073. //
  1074. // We have another copy item, and no literals
  1075. //
  1076. continue;
  1077. LITERAL:
  1078. //
  1079. // We have a literal
  1080. //
  1081. if (current >= historyend) {
  1082. #if DBG
  1083. DbgPrint("NDISWAN: RAS Decompressor problem3: Possible data corruption\n");
  1084. #endif
  1085. return FALSE ;
  1086. }
  1087. //*current++ = literallookup[length];
  1088. *current++ = (UCHAR)length;
  1089. } // while loop
  1090. // End case:
  1091. //
  1092. if (current >= historyend) {
  1093. #if DBG
  1094. DbgPrint("NDISWAN: RAS Decompressor problem4: Possible data corruption\n");
  1095. #endif
  1096. return FALSE ;
  1097. }
  1098. if ((bit == 16) && (pbyte == inend)) {
  1099. *current++ = *(pbyte -1) ;
  1100. }
  1101. #if DBG
  1102. if (context->DebugFence != DEBUG_FENCE_VALUE) {
  1103. DbgPrint("Decompression Error!\n");
  1104. DbgPrint("context %p, current %p, outstart %p\n", context, current, outstart);
  1105. DbgPrint("inbuf %p, inlength %d, start %p\n", inbuf, inlen, start);
  1106. DbgBreakPoint();
  1107. }
  1108. #endif
  1109. *outlen = (int)(current - outstart) ; // the length of decompressed data
  1110. *output = context->CurrentPtr ;
  1111. context->CurrentPtr = current ;
  1112. return TRUE ;
  1113. }
  1114. //
  1115. // This function uses the 16 byte user session key and the 8 byte
  1116. // challenge to create an intial 16 byte encryption session key.
  1117. //
  1118. VOID
  1119. GetStartKeyFromSHA(
  1120. PCRYPTO_INFO CryptoInfo,
  1121. PUCHAR Challenge
  1122. )
  1123. {
  1124. UCHAR Digest[A_SHA_DIGEST_LEN];
  1125. UCHAR SessionKeyChallenge[MAX_USERSESSIONKEY_SIZE + MAX_CHALLENGE_SIZE];
  1126. NdisZeroMemory(Digest, A_SHA_DIGEST_LEN);
  1127. //
  1128. // Copy the start session key
  1129. //
  1130. NdisMoveMemory(SessionKeyChallenge,
  1131. CryptoInfo->StartKey,
  1132. MAX_USERSESSIONKEY_SIZE);
  1133. //
  1134. // Append the challenge
  1135. //
  1136. NdisMoveMemory((PUCHAR)(SessionKeyChallenge + MAX_USERSESSIONKEY_SIZE),
  1137. Challenge,
  1138. MAX_CHALLENGE_SIZE);
  1139. //
  1140. // SHAInit(context)
  1141. // SHAUpdate(context, sessionkey, sessionkeylength)
  1142. // SHAUpdate(context, sessionkeychallenge, sessionkeylength + challengelength)
  1143. // SHAFinal(context, digest)
  1144. //
  1145. // Start key is the first 16 bytes of the digest.
  1146. //
  1147. A_SHAInit(CryptoInfo->Context);
  1148. A_SHAUpdate(CryptoInfo->Context,
  1149. CryptoInfo->StartKey,
  1150. MAX_USERSESSIONKEY_SIZE);
  1151. A_SHAUpdate(CryptoInfo->Context,
  1152. SessionKeyChallenge,
  1153. MAX_USERSESSIONKEY_SIZE + MAX_CHALLENGE_SIZE);
  1154. A_SHAFinal(CryptoInfo->Context,
  1155. Digest);
  1156. NdisMoveMemory(CryptoInfo->StartKey,
  1157. Digest,
  1158. CryptoInfo->SessionKeyLength);
  1159. NdisMoveMemory(CryptoInfo->SessionKey,
  1160. Digest,
  1161. CryptoInfo->SessionKeyLength);
  1162. }
  1163. VOID
  1164. GetNewKeyFromSHA(
  1165. PCRYPTO_INFO CryptoInfo
  1166. )
  1167. {
  1168. UCHAR Digest[A_SHA_DIGEST_LEN];
  1169. NdisZeroMemory(Digest, A_SHA_DIGEST_LEN);
  1170. A_SHAInit(CryptoInfo->Context);
  1171. A_SHAUpdate(CryptoInfo->Context,
  1172. CryptoInfo->StartKey,
  1173. CryptoInfo->SessionKeyLength);
  1174. A_SHAUpdate(CryptoInfo->Context,
  1175. SHApad1,
  1176. 40);
  1177. A_SHAUpdate(CryptoInfo->Context,
  1178. CryptoInfo->SessionKey,
  1179. CryptoInfo->SessionKeyLength);
  1180. A_SHAUpdate(CryptoInfo->Context,
  1181. SHApad2,
  1182. 40);
  1183. A_SHAFinal(CryptoInfo->Context,
  1184. Digest);
  1185. NdisMoveMemory(CryptoInfo->SessionKey,
  1186. Digest,
  1187. CryptoInfo->SessionKeyLength);
  1188. }
  1189. VOID
  1190. GetMasterKey(
  1191. PCRYPTO_INFO CryptoInfo,
  1192. PUCHAR NTResponse
  1193. )
  1194. {
  1195. UCHAR Digest[A_SHA_DIGEST_LEN];
  1196. PVOID Context;
  1197. NdisZeroMemory(Digest, A_SHA_DIGEST_LEN);
  1198. Context = CryptoInfo->Context;
  1199. A_SHAInit(Context);
  1200. #ifdef DEBUG_CCP
  1201. {
  1202. PUCHAR Key;
  1203. Key = CryptoInfo->StartKey;
  1204. DbgPrint("GMK-UserSessionKey: %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n",
  1205. Key[0],Key[1],Key[2],Key[3],
  1206. Key[4],Key[5],Key[6],Key[7],
  1207. Key[8],Key[9],Key[10],Key[11],
  1208. Key[12],Key[13],Key[14],Key[15]);
  1209. Key = NTResponse;
  1210. DbgPrint("GMK-NTResponse: %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n",
  1211. Key[0],Key[1],Key[2],Key[3],
  1212. Key[4],Key[5],Key[6],Key[7],
  1213. Key[8],Key[9],Key[10],Key[11],
  1214. Key[12],Key[13],Key[14],Key[15]);
  1215. DbgPrint(" %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n",
  1216. Key[16],Key[17],Key[18],Key[19],
  1217. Key[20],Key[21],Key[22],Key[23]);
  1218. }
  1219. #endif
  1220. A_SHAUpdate(Context,
  1221. CryptoInfo->StartKey,
  1222. MAX_USERSESSIONKEY_SIZE);
  1223. A_SHAUpdate(Context,
  1224. NTResponse,
  1225. MAX_NT_RESPONSE);
  1226. A_SHAUpdate(Context,
  1227. "This is the MPPE Master Key",
  1228. 27);
  1229. A_SHAFinal(Context, Digest);
  1230. NdisMoveMemory(CryptoInfo->StartKey,
  1231. Digest,
  1232. MAX_USERSESSIONKEY_SIZE);
  1233. #ifdef DEBUG_CCP
  1234. {
  1235. PUCHAR Key;
  1236. Key = CryptoInfo->StartKey;
  1237. DbgPrint("MasterKey: %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n",
  1238. Key[0],Key[1],Key[2],Key[3],
  1239. Key[4],Key[5],Key[6],Key[7],
  1240. Key[8],Key[9],Key[10],Key[11],
  1241. Key[12],Key[13],Key[14],Key[15]);
  1242. }
  1243. #endif
  1244. }
  1245. VOID
  1246. GetAsymetricStartKey(
  1247. PCRYPTO_INFO CryptoInfo,
  1248. BOOLEAN IsSend
  1249. )
  1250. {
  1251. UCHAR Digest[A_SHA_DIGEST_LEN];
  1252. PVOID Context;
  1253. PUCHAR s;
  1254. NdisZeroMemory(Digest, A_SHA_DIGEST_LEN);
  1255. Context = CryptoInfo->Context;
  1256. if (IsSend) {
  1257. if (CryptoInfo->Flags & CRYPTO_IS_SERVER) {
  1258. s = ClntRSrvS;
  1259. } else {
  1260. s = ClntSSrvR;
  1261. }
  1262. } else {
  1263. if (CryptoInfo->Flags & CRYPTO_IS_SERVER) {
  1264. s = ClntSSrvR;
  1265. } else {
  1266. s = ClntRSrvS;
  1267. }
  1268. }
  1269. #ifdef DEBUG_CCP
  1270. {
  1271. PUCHAR Key;
  1272. Key = CryptoInfo->StartKey;
  1273. DbgPrint("GASK-StartKey: %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n",
  1274. Key[0],Key[1],Key[2],Key[3],
  1275. Key[4],Key[5],Key[6],Key[7],
  1276. Key[8],Key[9],Key[10],Key[11],
  1277. Key[12],Key[13],Key[14],Key[15]);
  1278. DbgPrint("GASK-String: %s\n", s);
  1279. }
  1280. #endif
  1281. A_SHAInit(Context);
  1282. A_SHAUpdate(Context,
  1283. CryptoInfo->StartKey,
  1284. MAX_USERSESSIONKEY_SIZE);
  1285. A_SHAUpdate(Context,SHApad1,40);
  1286. A_SHAUpdate(Context,s,strlen(s));
  1287. A_SHAUpdate(Context,SHApad2,40);
  1288. A_SHAFinal(Context,Digest);
  1289. NdisMoveMemory(CryptoInfo->StartKey,
  1290. Digest,
  1291. CryptoInfo->SessionKeyLength);
  1292. NdisMoveMemory(CryptoInfo->SessionKey,
  1293. Digest,
  1294. CryptoInfo->SessionKeyLength);
  1295. #ifdef DEBUG_CCP
  1296. {
  1297. PUCHAR Key;
  1298. Key = CryptoInfo->StartKey;
  1299. DbgPrint("%s %s AsymetricKey: %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x\n",
  1300. (CryptoInfo->Flags & CRYPTO_IS_SERVER) ? "Server" : "Client",
  1301. (IsSend) ? "Send" : "Recv",
  1302. Key[0],Key[1],Key[2],Key[3],
  1303. Key[4],Key[5],Key[6],Key[7],
  1304. Key[8],Key[9],Key[10],Key[11],
  1305. Key[12],Key[13],Key[14],Key[15]);
  1306. }
  1307. #endif
  1308. }
  1309. /* Copyright (C) RSA Data Security, Inc. created 1993. This is an
  1310. unpublished work protected as such under copyright law. This work
  1311. contains proprietary, confidential, and trade secret information of
  1312. RSA Data Security, Inc. Use, disclosure or reproduction without the
  1313. express written authorization of RSA Data Security, Inc. is
  1314. prohibited.
  1315. */
  1316. /* SHA initialization. Begins an SHA operation, writing a new context.
  1317. */
  1318. void A_SHAInitCommon (context)
  1319. A_SHA_COMM_CTX *context;
  1320. {
  1321. context->count[0] = context->count[1] = 0;
  1322. /* Load magic initialization constants.
  1323. */
  1324. context->state[0] = 0x67452301;
  1325. context->state[1] = 0xefcdab89;
  1326. context->state[2] = 0x98badcfe;
  1327. context->state[3] = 0x10325476;
  1328. context->state[4] = 0xc3d2e1f0;
  1329. }
  1330. /* SHA block update operation. Continues an SHA message-digest
  1331. operation, processing another message block, and updating the
  1332. context.
  1333. */
  1334. void A_SHAUpdateCommon (context, partIn, partInLen, Transform)
  1335. A_SHA_COMM_CTX *context;
  1336. unsigned char *partIn;
  1337. ULONG partInLen;
  1338. A_SHA_TRANSFORM *Transform;
  1339. {
  1340. unsigned int bufferLen;
  1341. /* Compute length of buffer */
  1342. bufferLen = (unsigned int)(context->count[1] & 0x3f);
  1343. /* Update number of bytes */
  1344. if ((context->count[1] += partInLen) < partInLen)
  1345. context->count[0]++;
  1346. /* If previous input in buffer, buffer new input and transform if
  1347. possible.
  1348. */
  1349. if (bufferLen > 0 && bufferLen + partInLen >= 64) {
  1350. NdisMoveMemory(context->buffer+bufferLen, partIn, 64-bufferLen);
  1351. partIn += (64-bufferLen);
  1352. partInLen -= (64-bufferLen);
  1353. (*Transform) (context->state, context->buffer);
  1354. bufferLen = 0;
  1355. }
  1356. /* Transform directly from input.
  1357. */
  1358. while (partInLen >= 64) {
  1359. (*Transform) (context->state, partIn);
  1360. partIn += 64;
  1361. partInLen -= 64;
  1362. }
  1363. /* Buffer remaining input */
  1364. NdisMoveMemory((context->buffer+bufferLen), partIn, partInLen);
  1365. }
  1366. /* SHA finalization. Ends an SHA message-digest operation, writing
  1367. the message digest and zeroizing the context.
  1368. */
  1369. void A_SHAFinalCommon (context, digest, Transform)
  1370. A_SHA_COMM_CTX *context;
  1371. unsigned char digest[A_SHA_DIGEST_LEN];
  1372. A_SHA_TRANSFORM *Transform;
  1373. {
  1374. ULONG bitCount[2];
  1375. unsigned char pad[72];
  1376. unsigned int padLen;
  1377. /* Compute padding: 80 00 00 ... 00 00 <bit count>
  1378. */
  1379. padLen = 64 - (unsigned int)(context->count[1] & 0x3f);
  1380. if (padLen <= 8)
  1381. padLen += 64;
  1382. pad[0] = 0x80;
  1383. NdisZeroMemory(pad+1, padLen-7);
  1384. bitCount[0] = (context->count[0] << 3) | (context->count[1] >> 29);
  1385. bitCount[1] = context->count[1] << 3;
  1386. ByteReverse ((UNALIGNED ULONG*)(pad+padLen-8), bitCount, 2);
  1387. /* Digest padding */
  1388. A_SHAUpdateCommon (context, pad, padLen, Transform);
  1389. /* Store digest */
  1390. ByteReverse ((UNALIGNED ULONG*)digest, context->state, 5);
  1391. /* Restart the context */
  1392. A_SHAInitCommon (context);
  1393. }
  1394. void A_SHAInit (A_SHA_CTX *context)
  1395. {
  1396. A_SHAInitCommon (&context->commonContext);
  1397. }
  1398. void A_SHAUpdate (context, partIn, partInLen)
  1399. A_SHA_CTX *context;
  1400. unsigned char *partIn;
  1401. unsigned int partInLen;
  1402. {
  1403. A_SHAUpdateCommon (&context->commonContext, partIn, partInLen, SHATransform);
  1404. }
  1405. void A_SHAFinal (context, digest)
  1406. A_SHA_CTX *context;
  1407. unsigned char digest[A_SHA_DIGEST_LEN];
  1408. {
  1409. A_SHAFinalCommon (&context->commonContext, digest, SHATransform);
  1410. }
  1411. void SHATransform (state, block)
  1412. ULONG state[5];
  1413. unsigned char block[64];
  1414. {
  1415. ULONG a = state[0], b = state[1], c = state[2], d = state[3],
  1416. e = state[4], x[80];
  1417. ByteReverse (x, (ULONG*)block, 16);
  1418. SHAExpand (x);
  1419. /* Round 1 */
  1420. FF (a, b, c, d, e, x[ 0]);
  1421. FF (e, a, b, c, d, x[ 1]);
  1422. FF (d, e, a, b, c, x[ 2]);
  1423. FF (c, d, e, a, b, x[ 3]);
  1424. FF (b, c, d, e, a, x[ 4]);
  1425. FF (a, b, c, d, e, x[ 5]);
  1426. FF (e, a, b, c, d, x[ 6]);
  1427. FF (d, e, a, b, c, x[ 7]);
  1428. FF (c, d, e, a, b, x[ 8]);
  1429. FF (b, c, d, e, a, x[ 9]);
  1430. FF (a, b, c, d, e, x[10]);
  1431. FF (e, a, b, c, d, x[11]);
  1432. FF (d, e, a, b, c, x[12]);
  1433. FF (c, d, e, a, b, x[13]);
  1434. FF (b, c, d, e, a, x[14]);
  1435. FF (a, b, c, d, e, x[15]);
  1436. FF (e, a, b, c, d, x[16]);
  1437. FF (d, e, a, b, c, x[17]);
  1438. FF (c, d, e, a, b, x[18]);
  1439. FF (b, c, d, e, a, x[19]);
  1440. /* Round 2 */
  1441. GG (a, b, c, d, e, x[20]);
  1442. GG (e, a, b, c, d, x[21]);
  1443. GG (d, e, a, b, c, x[22]);
  1444. GG (c, d, e, a, b, x[23]);
  1445. GG (b, c, d, e, a, x[24]);
  1446. GG (a, b, c, d, e, x[25]);
  1447. GG (e, a, b, c, d, x[26]);
  1448. GG (d, e, a, b, c, x[27]);
  1449. GG (c, d, e, a, b, x[28]);
  1450. GG (b, c, d, e, a, x[29]);
  1451. GG (a, b, c, d, e, x[30]);
  1452. GG (e, a, b, c, d, x[31]);
  1453. GG (d, e, a, b, c, x[32]);
  1454. GG (c, d, e, a, b, x[33]);
  1455. GG (b, c, d, e, a, x[34]);
  1456. GG (a, b, c, d, e, x[35]);
  1457. GG (e, a, b, c, d, x[36]);
  1458. GG (d, e, a, b, c, x[37]);
  1459. GG (c, d, e, a, b, x[38]);
  1460. GG (b, c, d, e, a, x[39]);
  1461. /* Round 3 */
  1462. HH (a, b, c, d, e, x[40]);
  1463. HH (e, a, b, c, d, x[41]);
  1464. HH (d, e, a, b, c, x[42]);
  1465. HH (c, d, e, a, b, x[43]);
  1466. HH (b, c, d, e, a, x[44]);
  1467. HH (a, b, c, d, e, x[45]);
  1468. HH (e, a, b, c, d, x[46]);
  1469. HH (d, e, a, b, c, x[47]);
  1470. HH (c, d, e, a, b, x[48]);
  1471. HH (b, c, d, e, a, x[49]);
  1472. HH (a, b, c, d, e, x[50]);
  1473. HH (e, a, b, c, d, x[51]);
  1474. HH (d, e, a, b, c, x[52]);
  1475. HH (c, d, e, a, b, x[53]);
  1476. HH (b, c, d, e, a, x[54]);
  1477. HH (a, b, c, d, e, x[55]);
  1478. HH (e, a, b, c, d, x[56]);
  1479. HH (d, e, a, b, c, x[57]);
  1480. HH (c, d, e, a, b, x[58]);
  1481. HH (b, c, d, e, a, x[59]);
  1482. /* Round 4 */
  1483. II (a, b, c, d, e, x[60]);
  1484. II (e, a, b, c, d, x[61]);
  1485. II (d, e, a, b, c, x[62]);
  1486. II (c, d, e, a, b, x[63]);
  1487. II (b, c, d, e, a, x[64]);
  1488. II (a, b, c, d, e, x[65]);
  1489. II (e, a, b, c, d, x[66]);
  1490. II (d, e, a, b, c, x[67]);
  1491. II (c, d, e, a, b, x[68]);
  1492. II (b, c, d, e, a, x[69]);
  1493. II (a, b, c, d, e, x[70]);
  1494. II (e, a, b, c, d, x[71]);
  1495. II (d, e, a, b, c, x[72]);
  1496. II (c, d, e, a, b, x[73]);
  1497. II (b, c, d, e, a, x[74]);
  1498. II (a, b, c, d, e, x[75]);
  1499. II (e, a, b, c, d, x[76]);
  1500. II (d, e, a, b, c, x[77]);
  1501. II (c, d, e, a, b, x[78]);
  1502. II (b, c, d, e, a, x[79]);
  1503. state[0] += a;
  1504. state[1] += b;
  1505. state[2] += c;
  1506. state[3] += d;
  1507. state[4] += e;
  1508. /* Zeroize potentially sensitive information.
  1509. */
  1510. NdisZeroMemory((void *)x, sizeof (x));
  1511. }
  1512. /* Expands x[0..15] into x[16..79], according to the recurrence
  1513. x[i] = x[i-3] ^ x[i-8] ^ x[i-14] ^ x[i-16].
  1514. */
  1515. void SHAExpand (x)
  1516. ULONG x[80];
  1517. {
  1518. unsigned int i;
  1519. ULONG tmp;
  1520. for (i = 16; i < 80; i++)
  1521. {
  1522. tmp = x[i-3] ^ x[i-8] ^ x[i-14] ^ x[i-16];
  1523. x[i] = (tmp << 1) | (tmp >> 31);
  1524. }
  1525. }
  1526. VOID
  1527. ByteReverse(
  1528. UNALIGNED ULONG *Out,
  1529. ULONG *In,
  1530. ULONG Count
  1531. )
  1532. {
  1533. ULONG i;
  1534. ULONG Value;
  1535. for (i = 0; i < Count; i++) {
  1536. Value = (ULONG)(In[i] << 16) | (In[i] >> 16);
  1537. Out[i] = ((Value & 0xFF00FF00L) >> 8) | ((Value & 0x00FF00FFL) << 8);
  1538. }
  1539. }