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.

196 lines
4.8 KiB

  1. //************************************************************************
  2. // Microsoft Corporation
  3. // Copyright(c) Microsoft Corp., 1994
  4. //
  5. //
  6. // Revision history:
  7. // 5/5/94 Created gurdeep
  8. //
  9. // This file uses 4 space tabs
  10. //************************************************************************
  11. #ifdef COMP_12K
  12. #define HISTORY_SIZE 16000
  13. #else
  14. #define HISTORY_SIZE (8192U) // Maximum back-pointer value, also used
  15. #endif
  16. #define MAX_HASH_OFFSET 60000
  17. #define HISTORY_MAX (HISTORY_SIZE -1) // Maximum back-pointer value, also used
  18. #define HASH_TABLE_SIZE 4096
  19. #define MAX_BACK_PTR 8511
  20. #define MAX_COMPRESSFRAME_SIZE 1600
  21. struct SendContext {
  22. int CurrentIndex ; // how far into the history buffer we are
  23. PUCHAR ValidHistory ; // how much of history is valid
  24. USHORT HashOffset;
  25. ULONG BundleFlags;
  26. // UCHAR CompressBuffer[MAX_COMPRESSFRAME_SIZE] ;
  27. USHORT HashTable[HASH_TABLE_SIZE];
  28. UCHAR History [1] ;
  29. } ;
  30. typedef struct SendContext SendContext ;
  31. struct RecvContext {
  32. #if DBG
  33. #define DEBUG_FENCE_VALUE 0xABABABAB
  34. ULONG DebugFence;
  35. #endif
  36. UCHAR *CurrentPtr ; // how far into the history buffer we are
  37. ULONG BundleFlags;
  38. ULONG HistorySize;
  39. UCHAR History [1] ;
  40. } ;
  41. typedef struct RecvContext RecvContext ;
  42. // Prototypes
  43. //
  44. UCHAR
  45. compress (
  46. UCHAR *CurrentBuffer,
  47. UCHAR *CompOutBuffer,
  48. ULONG *CurrentLength,
  49. SendContext *context);
  50. //UCHAR
  51. //compress (
  52. // UCHAR *CurrentBuffer,
  53. // ULONG *CurrentLength,
  54. // SendContext *context);
  55. int
  56. decompress (
  57. UCHAR *inbuf,
  58. int inlen,
  59. int start,
  60. UCHAR **output,
  61. int *outlen,
  62. RecvContext *context) ;
  63. void initsendcontext (SendContext *) ;
  64. void initrecvcontext (RecvContext *) ;
  65. VOID
  66. GetStartKeyFromSHA(
  67. PCRYPTO_INFO CryptoInfo,
  68. PUCHAR Challenge
  69. );
  70. VOID
  71. GetNewKeyFromSHA(
  72. PCRYPTO_INFO CryptoInfo
  73. );
  74. VOID
  75. GetMasterKey(
  76. PCRYPTO_INFO CryptoInfo,
  77. PUCHAR NTResponse
  78. );
  79. VOID
  80. GetAsymetricStartKey(
  81. PCRYPTO_INFO CryptoInfo,
  82. BOOLEAN IsSend
  83. );
  84. //
  85. // Other defines
  86. //
  87. #define COMPRESSION_PADDING 4
  88. #define PACKET_FLUSHED 0x80
  89. #define PACKET_AT_FRONT 0x40
  90. #define PACKET_COMPRESSED 0x20
  91. #define PACKET_ENCRYPTED 0x10
  92. /* Copyright (C) RSA Data Security, Inc. created 1993. This is an
  93. unpublished work protected as such under copyright law. This work
  94. contains proprietary, confidential, and trade secret information of
  95. RSA Data Security, Inc. Use, disclosure or reproduction without the
  96. express written authorization of RSA Data Security, Inc. is
  97. prohibited.
  98. */
  99. #define A_SHA_DIGEST_LEN 20
  100. typedef struct {
  101. ULONG state[5]; /* state (ABCDE) */
  102. ULONG count[2]; /* number of UCHARs, msb first */
  103. unsigned char buffer[64]; /* input buffer */
  104. } A_SHA_COMM_CTX;
  105. typedef void (A_SHA_TRANSFORM) (ULONG [5], unsigned char [64]);
  106. void A_SHAInitCommon (A_SHA_COMM_CTX *);
  107. void A_SHAUpdateCommon(A_SHA_COMM_CTX *, UCHAR *, ULONG, A_SHA_TRANSFORM *);
  108. void A_SHAFinalCommon(A_SHA_COMM_CTX *, UCHAR[A_SHA_DIGEST_LEN],
  109. A_SHA_TRANSFORM *);
  110. VOID ByteReverse(UNALIGNED ULONG* Out, ULONG* In, ULONG Count);
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. typedef struct {
  115. ULONG FinishFlag;
  116. UCHAR HashVal[A_SHA_DIGEST_LEN];
  117. A_SHA_COMM_CTX commonContext;
  118. } A_SHA_CTX;
  119. void A_SHAInit(A_SHA_CTX *);
  120. void A_SHAUpdate(A_SHA_CTX *, unsigned char *, unsigned int);
  121. void A_SHAFinal(A_SHA_CTX *, unsigned char [A_SHA_DIGEST_LEN]);
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. /* F, G, H and I are basic SHA functions.
  126. */
  127. #define F(x, y, z) (((x) & (y)) | ((~x) & (z)))
  128. #define G(x, y, z) ((x) ^ (y) ^ (z))
  129. #define H(x, y, z) (((x) & (y)) | ((x) & (z)) | ((y) & (z)))
  130. #define I(x, y, z) ((x) ^ (y) ^ (z))
  131. /* ROTATE_LEFT rotates x left n bits.
  132. */
  133. #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n))))
  134. /* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4.
  135. */
  136. #define ROUND(a, b, c, d, e, x, F, k) { \
  137. (e) += ROTATE_LEFT ((a), 5) + F ((b), (c), (d)) + (x) + k; \
  138. (b) = ROTATE_LEFT ((b), 30); \
  139. }
  140. #define FF(a, b, c, d, e, x) ROUND (a, b, c, d, e, x, F, 0x5a827999);
  141. #define GG(a, b, c, d, e, x) ROUND (a, b, c, d, e, x, G, 0x6ed9eba1);
  142. #define HH(a, b, c, d, e, x) ROUND (a, b, c, d, e, x, H, 0x8f1bbcdc);
  143. #define II(a, b, c, d, e, x) ROUND (a, b, c, d, e, x, I, 0xca62c1d6);
  144. void SHATransform(ULONG [5], unsigned char [64]);
  145. void SHAExpand(ULONG [80]);