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.

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