Leaked source code of windows server 2003
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.

777 lines
23 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. ccp.c
  5. Abstract:
  6. Author:
  7. Thomas J. Dimitri (TommyD) 29-March-1994
  8. Environment:
  9. Revision History:
  10. --*/
  11. #include "wan.h"
  12. #ifdef ALLOC_PRAGMA
  13. #pragma alloc_text(INIT, WanInitECP)
  14. #pragma alloc_text(INIT, WanInitVJ)
  15. #endif
  16. #define __FILE_SIG__ CCP_FILESIG
  17. NDIS_STATUS
  18. AllocateEncryptMemory(
  19. PCRYPTO_INFO CryptoInfo
  20. );
  21. NDIS_STATUS
  22. AllocateCompressMemory(
  23. PBUNDLECB BundleCB
  24. );
  25. NTSTATUS
  26. AllocateCryptoMSChapV1(
  27. PBUNDLECB BundleCB,
  28. PCOMPRESS_INFO CompInfo,
  29. PCRYPTO_INFO CryptoInfo,
  30. BOOLEAN IsSend
  31. );
  32. NTSTATUS
  33. AllocateCryptoMSChapV2(
  34. PBUNDLECB BundleCB,
  35. PCOMPRESS_INFO CompInfo,
  36. PCRYPTO_INFO CryptoInfo,
  37. BOOLEAN IsSend
  38. );
  39. #ifdef EAP_ON
  40. NTSTATUS
  41. AllocateCryptoEap(
  42. PBUNDLECB BundleCB,
  43. PCOMPRESS_INFO CompInfo,
  44. PCRYPTO_INFO CryptoInfo,
  45. BOOLEAN IsSend
  46. );
  47. #endif
  48. NPAGED_LOOKASIDE_LIST EncryptCtxList; // List of free encryption contexts
  49. NPAGED_LOOKASIDE_LIST CachedKeyList; // List of free encryption contexts
  50. #ifdef ENCRYPT_128BIT
  51. NPAGED_LOOKASIDE_LIST CachedKeyListLong; // List of free encryption contexts
  52. #endif
  53. VOID
  54. WanInitECP(
  55. VOID
  56. )
  57. {
  58. NdisInitializeNPagedLookasideList(&EncryptCtxList,
  59. NULL,
  60. NULL,
  61. 0,
  62. ENCRYPTCTX_SIZE,
  63. ENCRYPTCTX_TAG,
  64. 0);
  65. NdisInitializeNPagedLookasideList(&CachedKeyList,
  66. NULL,
  67. NULL,
  68. 0,
  69. glCachedKeyCount * (sizeof(USHORT) + MAX_SESSIONKEY_SIZE),
  70. CACHEDKEY_TAG,
  71. 0);
  72. #ifdef ENCRYPT_128BIT
  73. NdisInitializeNPagedLookasideList(&CachedKeyListLong,
  74. NULL,
  75. NULL,
  76. 0,
  77. glCachedKeyCount * (sizeof(USHORT) + MAX_USERSESSIONKEY_SIZE),
  78. CACHEDKEY_TAG,
  79. 0);
  80. #endif
  81. }
  82. VOID
  83. WanDeleteECP(
  84. VOID
  85. )
  86. {
  87. NdisDeleteNPagedLookasideList(&EncryptCtxList);
  88. NdisDeleteNPagedLookasideList(&CachedKeyList);
  89. #ifdef ENCRYPT_128BIT
  90. NdisDeleteNPagedLookasideList(&CachedKeyListLong);
  91. #endif
  92. }
  93. //
  94. // Assumes the endpoint lock is held
  95. //
  96. NTSTATUS
  97. WanAllocateECP(
  98. PBUNDLECB BundleCB,
  99. PCOMPRESS_INFO CompInfo,
  100. PCRYPTO_INFO CryptoInfo,
  101. BOOLEAN IsSend
  102. )
  103. {
  104. NTSTATUS Status = STATUS_SUCCESS;
  105. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanAllocateECP: Enter"));
  106. //
  107. // Is encryption enabled?
  108. //
  109. #ifdef ENCRYPT_128BIT
  110. if ((CompInfo->MSCompType &
  111. (NDISWAN_ENCRYPTION | NDISWAN_40_ENCRYPTION |
  112. NDISWAN_56_ENCRYPTION | NDISWAN_128_ENCRYPTION))) {
  113. #else
  114. if ((CompInfo->MSCompType &
  115. (NDISWAN_ENCRYPTION | NDISWAN_40_ENCRYPTION |
  116. NDISWAN_56_ENCRYPTION))) {
  117. #endif
  118. if (CryptoInfo->Context == NULL) {
  119. Status = AllocateEncryptMemory(CryptoInfo);
  120. if (Status != NDIS_STATUS_SUCCESS) {
  121. NdisWanDbgOut(DBG_FAILURE, DBG_CCP, ("Can't allocate encryption key!"));
  122. return(STATUS_INSUFFICIENT_RESOURCES);
  123. }
  124. }
  125. do
  126. {
  127. CryptoInfo->Flags |=
  128. (CompInfo->Flags & CCP_IS_SERVER) ? CRYPTO_IS_SERVER : 0;
  129. if (CompInfo->AuthType == AUTH_USE_MSCHAPV1) {
  130. Status = AllocateCryptoMSChapV1(BundleCB,
  131. CompInfo,
  132. CryptoInfo,
  133. IsSend);
  134. } else if (CompInfo->AuthType == AUTH_USE_MSCHAPV2) {
  135. Status = AllocateCryptoMSChapV2(BundleCB,
  136. CompInfo,
  137. CryptoInfo,
  138. IsSend);
  139. #ifdef EAP_ON
  140. } else if (CompInfo->AuthType == AUTH_USE_EAP) {
  141. Status = AllocateCryptoEap(BundleCB,
  142. CompInfo,
  143. CryptoInfo,
  144. IsSend);
  145. #endif
  146. } else {
  147. Status = STATUS_UNSUCCESSFUL;
  148. break;
  149. }
  150. if (!IsSend && CryptoInfo->CachedKeyBuffer == NULL) {
  151. #ifdef DBG_ECP
  152. DbgPrint("NDISWAN: CompInfo = %p\n", CompInfo);
  153. DbgPrint("NDISWAN: CryptoInfo = %p\n", CryptoInfo);
  154. DbgPrint("NDISWAN: MSCompType = %0x\n", CompInfo->MSCompType);
  155. DbgPrint("NDISWAN: Flags = %0x\n", CryptoInfo->Flags);
  156. DbgPrint("NDISWAN: SessionKeyLength = %d\n", CryptoInfo->SessionKeyLength);
  157. #endif
  158. #ifdef ENCRYPT_128BIT
  159. if ((CompInfo->MSCompType & NDISWAN_128_ENCRYPTION))
  160. {
  161. CryptoInfo->CachedKeyBuffer = NdisAllocateFromNPagedLookasideList(&CachedKeyListLong);
  162. }
  163. else
  164. #endif
  165. {
  166. CryptoInfo->CachedKeyBuffer = NdisAllocateFromNPagedLookasideList(&CachedKeyList);
  167. }
  168. if (CryptoInfo->CachedKeyBuffer == NULL) {
  169. NdisWanDbgOut(DBG_FAILURE, DBG_CCP, ("Can't allocate cached key array!"));
  170. Status = STATUS_INSUFFICIENT_RESOURCES;
  171. break;
  172. }
  173. else
  174. {
  175. CryptoInfo->pCurrKey = (PCACHED_KEY)CryptoInfo->CachedKeyBuffer;
  176. CryptoInfo->pLastKey = (PCACHED_KEY)((PUCHAR) CryptoInfo->CachedKeyBuffer +
  177. (glCachedKeyCount - 1) * (sizeof(USHORT)+ CryptoInfo->SessionKeyLength));
  178. NdisFillMemory(CryptoInfo->CachedKeyBuffer,
  179. glCachedKeyCount * (sizeof(USHORT)+ CryptoInfo->SessionKeyLength),
  180. 0xff);
  181. }
  182. }
  183. } while(FALSE);
  184. if (Status != STATUS_SUCCESS) {
  185. if (CryptoInfo->Context != NULL) {
  186. NdisFreeToNPagedLookasideList(&EncryptCtxList,
  187. CryptoInfo->Context);
  188. //
  189. // Clear so we know it is deallocated
  190. //
  191. CryptoInfo->Context =
  192. CryptoInfo->RC4Key= NULL;
  193. }
  194. if (CryptoInfo->CachedKeyBuffer != NULL) {
  195. #ifdef ENCRYPT_128BIT
  196. if ((CompInfo->MSCompType & NDISWAN_128_ENCRYPTION))
  197. {
  198. NdisFreeToNPagedLookasideList(&CachedKeyListLong, CryptoInfo->CachedKeyBuffer);
  199. }
  200. else
  201. #endif
  202. {
  203. NdisFreeToNPagedLookasideList(&CachedKeyList, CryptoInfo->CachedKeyBuffer);
  204. }
  205. CryptoInfo->CachedKeyBuffer = NULL;
  206. CryptoInfo->pCurrKey = CryptoInfo->pLastKey = NULL;
  207. }
  208. NdisWanDbgOut(DBG_FAILURE, DBG_CCP, ("Failed allocating Crypto Status %x!", Status));
  209. return (Status);
  210. }
  211. //
  212. // Next packet out is flushed
  213. //
  214. BundleCB->Flags |= RECV_PACKET_FLUSH;
  215. }
  216. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanAllocateECP: Exit"));
  217. return(Status);
  218. }
  219. //
  220. // Assumes the endpoint lock is held
  221. //
  222. VOID
  223. WanDeallocateECP(
  224. PBUNDLECB BundleCB,
  225. PCOMPRESS_INFO CompInfo,
  226. PCRYPTO_INFO CryptoInfo
  227. )
  228. {
  229. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanDeallocateECP: Enter"));
  230. //
  231. // Deallocate encryption keys.
  232. //
  233. if (CryptoInfo->Context != NULL) {
  234. NdisFreeToNPagedLookasideList(&EncryptCtxList,
  235. CryptoInfo->Context);
  236. //
  237. // Clear so we know it is deallocated
  238. //
  239. CryptoInfo->Context =
  240. CryptoInfo->RC4Key= NULL;
  241. }
  242. if (CryptoInfo->CachedKeyBuffer != NULL) {
  243. #ifdef ENCRYPT_128BIT
  244. if ((CompInfo->MSCompType & NDISWAN_128_ENCRYPTION))
  245. {
  246. NdisFreeToNPagedLookasideList(&CachedKeyListLong, CryptoInfo->CachedKeyBuffer);
  247. }
  248. else
  249. #endif
  250. {
  251. NdisFreeToNPagedLookasideList(&CachedKeyList, CryptoInfo->CachedKeyBuffer);
  252. }
  253. CryptoInfo->CachedKeyBuffer = NULL;
  254. CryptoInfo->pCurrKey = CryptoInfo->pLastKey = NULL;
  255. }
  256. //
  257. // Clear the encrption bits
  258. //
  259. #ifdef ENCRYPT_128BIT
  260. CompInfo->MSCompType &= ~(NDISWAN_ENCRYPTION | NDISWAN_40_ENCRYPTION |
  261. NDISWAN_56_ENCRYPTION | NDISWAN_128_ENCRYPTION);
  262. #else
  263. CompInfo->MSCompType &= ~(NDISWAN_ENCRYPTION | NDISWAN_40_ENCRYPTION |
  264. NDISWAN_56_ENCRYPTION);
  265. #endif
  266. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanDeallocateCCP: Exit"));
  267. }
  268. NTSTATUS
  269. AllocateCryptoMSChapV1(
  270. PBUNDLECB BundleCB,
  271. PCOMPRESS_INFO CompInfo,
  272. PCRYPTO_INFO CryptoInfo,
  273. BOOLEAN IsSend
  274. )
  275. {
  276. if (CompInfo->MSCompType & NDISWAN_ENCRYPTION) {
  277. //
  278. // For legacy encryption we use the 8 byte LMSessionKey
  279. // for initiali encryption session key. The first 256
  280. // packets will be sent using this without any salt
  281. // (the first 256 packets are using 64 bit encryption).
  282. // After the first 256 we will always salt the first 3
  283. // bytes of the encryption key so that we are doing 40
  284. // bit encryption.
  285. //
  286. CryptoInfo->SessionKeyLength = MAX_SESSIONKEY_SIZE;
  287. NdisMoveMemory(CryptoInfo->StartKey,
  288. CompInfo->LMSessionKey,
  289. CryptoInfo->SessionKeyLength);
  290. NdisMoveMemory(CryptoInfo->SessionKey,
  291. CryptoInfo->StartKey,
  292. CryptoInfo->SessionKeyLength);
  293. } else if (CompInfo->MSCompType &
  294. (NDISWAN_40_ENCRYPTION | NDISWAN_56_ENCRYPTION)) {
  295. CryptoInfo->SessionKeyLength = MAX_SESSIONKEY_SIZE;
  296. //
  297. // For our new 40/56 bit encryption we will use SHA on the
  298. // 8 byte LMSessionKey to derive our intial 8 byte
  299. // encryption session key.
  300. //
  301. NdisMoveMemory(CryptoInfo->StartKey,
  302. CompInfo->LMSessionKey,
  303. CryptoInfo->SessionKeyLength);
  304. NdisMoveMemory(CryptoInfo->SessionKey,
  305. CompInfo->LMSessionKey,
  306. CryptoInfo->SessionKeyLength);
  307. GetNewKeyFromSHA(CryptoInfo);
  308. if (CompInfo->MSCompType & NDISWAN_40_ENCRYPTION) {
  309. //
  310. // Set the first 3 bytes to reduce to
  311. // 40 bits of random key
  312. //
  313. CryptoInfo->SessionKey[0] = 0xD1;
  314. CryptoInfo->SessionKey[1] = 0x26;
  315. CryptoInfo->SessionKey[2] = 0x9E;
  316. } else {
  317. //
  318. // Set the first byte to reduce to
  319. // 56 bits of random key
  320. //
  321. CryptoInfo->SessionKey[0] = 0xD1;
  322. }
  323. #ifdef ENCRYPT_128BIT
  324. } else if (CompInfo->MSCompType & NDISWAN_128_ENCRYPTION) {
  325. CryptoInfo->SessionKeyLength = MAX_USERSESSIONKEY_SIZE;
  326. //
  327. // For our new 128 bit encryption we will use SHA on the
  328. // 16 byte NTUserSessionKey and the 8 byte Challenge to
  329. // derive our the intial 128 bit encryption session key.
  330. //
  331. NdisMoveMemory(CryptoInfo->StartKey,
  332. CompInfo->UserSessionKey,
  333. MAX_USERSESSIONKEY_SIZE);
  334. GetStartKeyFromSHA(CryptoInfo, CompInfo->Challenge);
  335. GetNewKeyFromSHA(CryptoInfo);
  336. #endif
  337. }
  338. //
  339. // Initialize the rc4 send table
  340. //
  341. NdisWanDbgOut(DBG_TRACE, DBG_CCP,
  342. ("RC4 encryption KeyLength %d", CryptoInfo->SessionKeyLength));
  343. NdisWanDbgOut(DBG_TRACE, DBG_CCP,
  344. ("RC4 encryption Key %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
  345. CryptoInfo->SessionKey[0],
  346. CryptoInfo->SessionKey[1],
  347. CryptoInfo->SessionKey[2],
  348. CryptoInfo->SessionKey[3],
  349. CryptoInfo->SessionKey[4],
  350. CryptoInfo->SessionKey[5],
  351. CryptoInfo->SessionKey[6],
  352. CryptoInfo->SessionKey[7],
  353. CryptoInfo->SessionKey[8],
  354. CryptoInfo->SessionKey[9],
  355. CryptoInfo->SessionKey[10],
  356. CryptoInfo->SessionKey[11],
  357. CryptoInfo->SessionKey[12],
  358. CryptoInfo->SessionKey[13],
  359. CryptoInfo->SessionKey[14],
  360. CryptoInfo->SessionKey[15]));
  361. rc4_key(CryptoInfo->RC4Key,
  362. CryptoInfo->SessionKeyLength,
  363. CryptoInfo->SessionKey);
  364. return (STATUS_SUCCESS);
  365. }
  366. NTSTATUS
  367. AllocateCryptoMSChapV2(
  368. PBUNDLECB BundleCB,
  369. PCOMPRESS_INFO CompInfo,
  370. PCRYPTO_INFO CryptoInfo,
  371. BOOLEAN IsSend
  372. )
  373. {
  374. NdisMoveMemory(CryptoInfo->StartKey,
  375. CompInfo->UserSessionKey,
  376. sizeof(CryptoInfo->StartKey));
  377. if (CompInfo->MSCompType & NDISWAN_ENCRYPTION) {
  378. return(STATUS_UNSUCCESSFUL);
  379. } else if (CompInfo->MSCompType &
  380. (NDISWAN_40_ENCRYPTION | NDISWAN_56_ENCRYPTION)) {
  381. CryptoInfo->SessionKeyLength = MAX_SESSIONKEY_SIZE;
  382. #ifdef ENCRYPT_128BIT
  383. } else if (CompInfo->MSCompType & NDISWAN_128_ENCRYPTION) {
  384. CryptoInfo->SessionKeyLength = MAX_USERSESSIONKEY_SIZE;
  385. #endif
  386. }
  387. GetMasterKey(CryptoInfo, CompInfo->NTResponse);
  388. //
  389. // Setup the first key
  390. //
  391. GetAsymetricStartKey(CryptoInfo, IsSend);
  392. GetNewKeyFromSHA(CryptoInfo);
  393. if (CompInfo->MSCompType & NDISWAN_40_ENCRYPTION) {
  394. //
  395. // Set the first 3 bytes to reduce to
  396. // 40 bits of random key
  397. //
  398. CryptoInfo->SessionKey[0] = 0xD1;
  399. CryptoInfo->SessionKey[1] = 0x26;
  400. CryptoInfo->SessionKey[2] = 0x9E;
  401. } else if (CompInfo->MSCompType & NDISWAN_56_ENCRYPTION) {
  402. //
  403. // Set the first byte to reduce to
  404. // 56 bits of random key
  405. //
  406. CryptoInfo->SessionKey[0] = 0xD1;
  407. }
  408. //
  409. // Initialize the rc4 send table
  410. //
  411. NdisWanDbgOut(DBG_TRACE, DBG_CCP,
  412. ("RC4 encryption KeyLength %d", CryptoInfo->SessionKeyLength));
  413. NdisWanDbgOut(DBG_TRACE, DBG_CCP,
  414. ("RC4 encryption Key %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
  415. CryptoInfo->SessionKey[0],CryptoInfo->SessionKey[1],
  416. CryptoInfo->SessionKey[2],CryptoInfo->SessionKey[3],
  417. CryptoInfo->SessionKey[4],CryptoInfo->SessionKey[5],
  418. CryptoInfo->SessionKey[6],CryptoInfo->SessionKey[7],
  419. CryptoInfo->SessionKey[8],CryptoInfo->SessionKey[9],
  420. CryptoInfo->SessionKey[10],CryptoInfo->SessionKey[11],
  421. CryptoInfo->SessionKey[12],CryptoInfo->SessionKey[13],
  422. CryptoInfo->SessionKey[14],CryptoInfo->SessionKey[15]));
  423. rc4_key(CryptoInfo->RC4Key,
  424. CryptoInfo->SessionKeyLength,
  425. CryptoInfo->SessionKey);
  426. return (STATUS_SUCCESS);
  427. }
  428. #ifdef EAP_ON
  429. NTSTATUS
  430. AllocateCryptoEap(
  431. PBUNDLECB BundleCB,
  432. PCOMPRESS_INFO CompInfo,
  433. PCRYPTO_INFO CryptoInfo,
  434. BOOLEAN IsSend
  435. )
  436. {
  437. ULONG KeySize;
  438. KeySize = CompInfo->EapKeyLength;
  439. if (CompInfo->MSCompType & NDISWAN_ENCRYPTION) {
  440. return(STATUS_UNSUCCESSFUL);
  441. } else if (CompInfo->MSCompType &
  442. (NDISWAN_40_ENCRYPTION | NDISWAN_56_ENCRYPTION)) {
  443. //
  444. // Might need to pad this out. Spec calls for padding
  445. // at the left (front) of the value
  446. //
  447. CryptoInfo->SessionKeyLength = MAX_SESSIONKEY_SIZE;
  448. #ifdef ENCRYPT_128BIT
  449. } else if (CompInfo->MSCompType & NDISWAN_128_ENCRYPTION) {
  450. //
  451. // Might need to pad this out. Spec calls for padding
  452. // at the left (front) of the value
  453. //
  454. CryptoInfo->SessionKeyLength = MAX_USERSESSIONKEY_SIZE;
  455. #endif
  456. }
  457. NdisMoveMemory(CryptoInfo->StartKey,
  458. CompInfo->EapKey,
  459. CryptoInfo->SessionKeyLength);
  460. NdisMoveMemory(CryptoInfo->SessionKey,
  461. CryptoInfo->StartKey,
  462. CryptoInfo->SessionKeyLength);
  463. GetNewKeyFromSHA(CryptoInfo);
  464. if (CompInfo->MSCompType & NDISWAN_40_ENCRYPTION) {
  465. //
  466. // Set the first 3 bytes to reduce to
  467. // 40 bits of random key
  468. //
  469. CryptoInfo->SessionKey[0] = 0xD1;
  470. CryptoInfo->SessionKey[1] = 0x26;
  471. CryptoInfo->SessionKey[2] = 0x9E;
  472. } else if (CompInfo->MSCompType & NDISWAN_56_ENCRYPTION) {
  473. //
  474. // Set the first byte to reduce to
  475. // 56 bits of random key
  476. //
  477. CryptoInfo->SessionKey[0] = 0xD1;
  478. }
  479. //
  480. // Initialize the rc4 send table
  481. //
  482. NdisWanDbgOut(DBG_TRACE, DBG_CCP,
  483. ("RC4 encryption KeyLength %d", CryptoInfo->SessionKeyLength));
  484. NdisWanDbgOut(DBG_TRACE, DBG_CCP,
  485. ("RC4 encryption Key %.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x%.2x",
  486. CryptoInfo->SessionKey[0],CryptoInfo->SessionKey[1],
  487. CryptoInfo->SessionKey[2],CryptoInfo->SessionKey[3],
  488. CryptoInfo->SessionKey[4],CryptoInfo->SessionKey[5],
  489. CryptoInfo->SessionKey[6],CryptoInfo->SessionKey[7],
  490. CryptoInfo->SessionKey[8],CryptoInfo->SessionKey[9],
  491. CryptoInfo->SessionKey[10],CryptoInfo->SessionKey[11],
  492. CryptoInfo->SessionKey[12],CryptoInfo->SessionKey[13],
  493. CryptoInfo->SessionKey[14],CryptoInfo->SessionKey[15]));
  494. rc4_key(CryptoInfo->RC4Key,
  495. CryptoInfo->SessionKeyLength,
  496. CryptoInfo->SessionKey);
  497. return (STATUS_SUCCESS);
  498. }
  499. #endif
  500. NTSTATUS
  501. WanAllocateCCP(
  502. PBUNDLECB BundleCB,
  503. PCOMPRESS_INFO CompInfo,
  504. BOOLEAN IsSend
  505. )
  506. {
  507. NTSTATUS Status = STATUS_SUCCESS;
  508. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanAllocateCCP: Enter"));
  509. if (CompInfo->MSCompType & NDISWAN_COMPRESSION) {
  510. ULONG CompressSend;
  511. ULONG CompressRecv;
  512. //
  513. // Get compression context sizes
  514. //
  515. if(BundleCB->SendCompInfo.MSCompType & NDISWAN_HISTORY_LESS)
  516. {
  517. CompressSend = sizeof(SendContext);
  518. }
  519. else
  520. {
  521. CompressSend = sizeof(SendContext) + HISTORY_SIZE;
  522. }
  523. if(BundleCB->RecvCompInfo.MSCompType & NDISWAN_HISTORY_LESS)
  524. {
  525. CompressRecv = sizeof(RecvContext) + glMRRU;
  526. }
  527. else
  528. {
  529. CompressRecv = sizeof(RecvContext) + HISTORY_SIZE;
  530. }
  531. if (IsSend) {
  532. if (BundleCB->SendCompressContext == NULL) {
  533. NdisWanAllocateMemory(&BundleCB->SendCompressContext, CompressSend, COMPCTX_TAG);
  534. //
  535. // If we can't allocate memory the machine is toast.
  536. // Forget about freeing anything up.
  537. //
  538. if (BundleCB->SendCompressContext == NULL) {
  539. NdisWanDbgOut(DBG_FAILURE, DBG_CCP, ("Can't allocate compression!"));
  540. return(STATUS_INSUFFICIENT_RESOURCES);
  541. }
  542. }
  543. ((SendContext*)BundleCB->SendCompressContext)->BundleFlags =
  544. (BundleCB->SendCompInfo.MSCompType & NDISWAN_HISTORY_LESS) ? DO_HISTORY_LESS : 0;
  545. initsendcontext (BundleCB->SendCompressContext);
  546. } else {
  547. if (BundleCB->RecvCompressContext == NULL) {
  548. NdisWanAllocateMemory(&BundleCB->RecvCompressContext, CompressRecv, COMPCTX_TAG);
  549. //
  550. // If we can't allocate memory the machine is toast.
  551. // Forget about freeing anything up.
  552. //
  553. if (BundleCB->RecvCompressContext == NULL) {
  554. NdisWanDbgOut(DBG_FAILURE, DBG_CCP, ("Can't allocate decompression"));
  555. return(STATUS_INSUFFICIENT_RESOURCES);
  556. }
  557. }
  558. if(BundleCB->RecvCompInfo.MSCompType & NDISWAN_HISTORY_LESS)
  559. {
  560. ((RecvContext*)BundleCB->RecvCompressContext)->BundleFlags = DO_HISTORY_LESS;
  561. ((RecvContext*)BundleCB->RecvCompressContext)->HistorySize = glMRRU;
  562. }
  563. else
  564. {
  565. ((RecvContext*)BundleCB->RecvCompressContext)->BundleFlags = 0;
  566. ((RecvContext*)BundleCB->RecvCompressContext)->HistorySize = HISTORY_SIZE;
  567. }
  568. //
  569. // Initialize the decompression history table
  570. //
  571. initrecvcontext (BundleCB->RecvCompressContext);
  572. }
  573. Status = STATUS_SUCCESS;
  574. //
  575. // Next packet out is flushed
  576. //
  577. BundleCB->Flags |= RECV_PACKET_FLUSH;
  578. }
  579. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanAllocateCCP: Exit"));
  580. return (Status);
  581. }
  582. VOID
  583. WanDeallocateCCP(
  584. PBUNDLECB BundleCB,
  585. PCOMPRESS_INFO CompInfo,
  586. BOOLEAN IsSend
  587. )
  588. {
  589. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanDeallocateCCP: Enter"));
  590. if (IsSend) {
  591. if (BundleCB->SendCompressContext != NULL) {
  592. NdisWanFreeMemory(BundleCB->SendCompressContext);
  593. BundleCB->SendCompressContext= NULL;
  594. }
  595. } else {
  596. if (BundleCB->RecvCompressContext != NULL) {
  597. NdisWanFreeMemory(BundleCB->RecvCompressContext);
  598. BundleCB->RecvCompressContext= NULL;
  599. }
  600. }
  601. //
  602. // Clear the compression bits
  603. //
  604. CompInfo->MSCompType &= ~NDISWAN_COMPRESSION;
  605. NdisWanDbgOut(DBG_TRACE, DBG_CCP, ("WanDeallocateCCP: Exit"));
  606. }
  607. NDIS_STATUS
  608. AllocateEncryptMemory(
  609. PCRYPTO_INFO CryptoInfo
  610. )
  611. {
  612. PUCHAR Mem;
  613. Mem =
  614. NdisAllocateFromNPagedLookasideList(&EncryptCtxList);
  615. if (Mem == NULL) {
  616. return (NDIS_STATUS_FAILURE);
  617. }
  618. NdisZeroMemory(Mem, ENCRYPTCTX_SIZE);
  619. CryptoInfo->Context = Mem;
  620. Mem += (sizeof(A_SHA_CTX) + sizeof(PVOID));
  621. CryptoInfo->RC4Key = Mem;
  622. (ULONG_PTR)CryptoInfo->RC4Key &= ~((ULONG_PTR)sizeof(PVOID)-1);
  623. return(NDIS_STATUS_SUCCESS);
  624. }