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.

282 lines
5.8 KiB

  1. /*++
  2. Copyright (c) 1994-1997 Microsoft Corporation
  3. Module Name:
  4. tssec.h
  5. Abstract:
  6. contains data definitions required for tshare data encryption.
  7. Author:
  8. Madan Appiah (madana) 30-Dec-1997
  9. Environment:
  10. User Mode - Win32
  11. Revision History:
  12. --*/
  13. #ifndef _TSSEC_H_
  14. #define _TSSEC_H_
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif // __cplusplus
  18. #ifdef OS_WIN16
  19. #define RSA32API
  20. typedef unsigned long ULONG;
  21. typedef ULONG FAR* LPULONG;
  22. #define UNALIGNED
  23. #endif // OS_WIN16
  24. #include <rc4.h>
  25. #define RANDOM_KEY_LENGTH 32 // size of a client/server random key
  26. #define MAX_SESSION_KEY_SIZE 16 // max size of a session key
  27. #define PRE_MASTER_SECRET_LEN 48 // size of a pre-master key
  28. #define SEC_MAX_USERNAME 256 // size of username
  29. #define MAX_SIGNKEY_SIZE 20 // maximum size of a signing key
  30. #define MAX_FIPS_SESSION_KEY_SIZE 24 // maximum size of a session key
  31. #define MAX_SIGN_SIZE 8 // maximum size of signed data
  32. #define DES3_KEYLEN 21 // size of 3des key
  33. #define FIPS_BLOCK_LEN 8 // block size for FIPS
  34. #define CLIENT_RANDOM_MAX_SIZE 512
  35. #define UPDATE_SESSION_KEY_COUNT (1024 * 4)
  36. // update session key after this many encryptions.
  37. #define DATA_SIGNATURE_SIZE 8
  38. // size of the data signature that sent accross.
  39. /****************************************************************************/
  40. /* Encryption levels - bit field. */
  41. /****************************************************************************/
  42. #define SM_40BIT_ENCRYPTION_FLAG 0x01
  43. #define SM_128BIT_ENCRYPTION_FLAG 0x02
  44. #define SM_56BIT_ENCRYPTION_FLAG 0x08
  45. #define SM_FIPS_ENCRYPTION_FLAG 0x10
  46. typedef struct _RANDOM_KEYS_PAIR {
  47. BYTE clientRandom[RANDOM_KEY_LENGTH];
  48. BYTE serverRandom[RANDOM_KEY_LENGTH];
  49. } RANDOM_KEYS_PAIR, FAR *LPRANDOM_KEYS_PAIR;
  50. typedef enum _CryptMethod {
  51. Encrypt,
  52. Decrypt
  53. } CryptMethod;
  54. //
  55. // Autoreconnection specific security structures
  56. // These are defined here because they are not necessarily RDP
  57. // specific. Although the PDU's wrapping these packets will
  58. // be protocol specific.
  59. //
  60. // Server to client ARC packet
  61. #define ARC_SC_SECURITY_TOKEN_LEN 16
  62. typedef struct _ARC_SC_PRIVATE_PACKET {
  63. ULONG cbLen;
  64. ULONG Version;
  65. ULONG LogonId;
  66. BYTE ArcRandomBits[ARC_SC_SECURITY_TOKEN_LEN];
  67. } ARC_SC_PRIVATE_PACKET, *PARC_SC_PRIVATE_PACKET;
  68. #define ARC_CS_SECURITY_TOKEN_LEN 16
  69. typedef struct _ARC_CS_PRIVATE_PACKET {
  70. ULONG cbLen;
  71. ULONG Version;
  72. ULONG LogonId;
  73. BYTE SecurityVerifier[ARC_CS_SECURITY_TOKEN_LEN];
  74. } ARC_CS_PRIVATE_PACKET, *PARC_CS_PRIVATE_PACKET;
  75. BOOL
  76. MakeSessionKeys(
  77. LPRANDOM_KEYS_PAIR pKeyPair,
  78. LPBYTE pbEncryptKey,
  79. struct RC4_KEYSTRUCT FAR *prc4EncryptKey,
  80. LPBYTE pbDecryptKey,
  81. struct RC4_KEYSTRUCT FAR *prc4DecryptKey,
  82. LPBYTE pbMACSaltKey,
  83. DWORD dwKeyStrength,
  84. LPDWORD pdwKeyLength,
  85. DWORD dwEncryptionLevel
  86. );
  87. BOOL
  88. UpdateSessionKey(
  89. LPBYTE pbStartKey,
  90. LPBYTE pbCurrentKey,
  91. DWORD dwKeyStrength,
  92. DWORD dwKeyLength,
  93. struct RC4_KEYSTRUCT FAR *prc4Key,
  94. DWORD dwEncryptionLevel
  95. );
  96. BOOL
  97. EncryptData(
  98. DWORD dwEncryptionLevel,
  99. LPBYTE pSessionKey,
  100. struct RC4_KEYSTRUCT FAR *prc4EncryptKey,
  101. DWORD dwKeyLength,
  102. LPBYTE pbData,
  103. DWORD dwDataLen,
  104. LPBYTE pbMACSaltKey,
  105. LPBYTE pbSignature,
  106. BOOL fCheckSumEncryptedData,
  107. DWORD dwEncryptionCount
  108. );
  109. BOOL
  110. DecryptData(
  111. DWORD dwEncryptionLevel,
  112. LPBYTE pSessionKey,
  113. struct RC4_KEYSTRUCT FAR *prc4DecryptKey,
  114. DWORD dwKeyLength,
  115. LPBYTE pbData,
  116. DWORD dwDataLen,
  117. LPBYTE pbMACSaltKey,
  118. LPBYTE pbSignature,
  119. BOOL fCheckSumCipherText,
  120. DWORD dwDecryptionCount
  121. );
  122. //
  123. // RNG init/term functions for DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH
  124. //
  125. VOID
  126. TSRNG_Initialize(
  127. );
  128. VOID
  129. TSRNG_Shutdown(
  130. );
  131. //
  132. // RNG bit gathering function i.e all the work happens here
  133. //
  134. // Params:
  135. // pbRandomKey - where to place the random bits
  136. // dwRandomKeyLen - size in bytes of pbRandomKey
  137. //
  138. // Returns
  139. // Success flag
  140. //
  141. BOOL
  142. TSRNG_GenerateRandomBits(
  143. LPBYTE pbRandomKey,
  144. DWORD dwRandomKeyLen
  145. );
  146. #ifndef NO_INCLUDE_LICENSING
  147. BOOL
  148. GetServerCert(
  149. LPBYTE FAR *ppServerCertBlob,
  150. LPDWORD pdwServerCertLen
  151. );
  152. BOOL
  153. UnpackServerCert(
  154. LPBYTE pbCert,
  155. DWORD dwCertLen,
  156. PHydra_Server_Cert pServerCert
  157. );
  158. BOOL
  159. ValidateServerCert(
  160. PHydra_Server_Cert pServerCert
  161. );
  162. #endif // NO_INCLUDE_LICENSING
  163. BOOL
  164. EncryptClientRandom(
  165. LPBYTE pbSrvPublicKey,
  166. DWORD dwSrvPublicKey,
  167. LPBYTE pbRandomKey,
  168. DWORD dwRandomKeyLen,
  169. LPBYTE pbEncRandomKey,
  170. LPDWORD pdwEncRandomKey
  171. );
  172. BOOL
  173. DecryptClientRandom(
  174. LPBYTE pbEncRandomKey,
  175. DWORD dwEncRandomKeyLen,
  176. LPBYTE pbRandomKey,
  177. LPDWORD pdwRandomKeyLen
  178. );
  179. BOOL EncryptDecryptLocalData(
  180. LPBYTE pbData,
  181. DWORD dwDataLen
  182. );
  183. BOOL EncryptDecryptLocalData50(
  184. LPBYTE pbData,
  185. DWORD dwDataLen,
  186. LPBYTE pbSalt,
  187. DWORD dwSaltLen
  188. );
  189. BOOL
  190. TSCAPI_GenerateRandomBits(
  191. LPBYTE pbRandomBits,
  192. DWORD cbLen
  193. );
  194. //
  195. // remove (or comment) the following definition to disable the MSRC4.
  196. //
  197. // #define USE_MSRC4
  198. #ifdef USE_MSRC4
  199. VOID
  200. msrc4_key(
  201. struct RC4_KEYSTRUCT FAR *pKS,
  202. DWORD dwLen,
  203. LPBYTE pbKey);
  204. VOID
  205. msrc4(
  206. struct RC4_KEYSTRUCT FAR *pKS,
  207. DWORD dwLen,
  208. LPBYTE pbuf);
  209. #else // USE_MSRC4
  210. #define msrc4_key rc4_key
  211. #define msrc4 rc4
  212. #endif // USE_MSRC4
  213. BOOL
  214. FindIsFrenchSystem(
  215. VOID
  216. );
  217. #ifdef __cplusplus
  218. }
  219. #endif // __cplusplus
  220. #endif // _TSSEC_H_