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.

276 lines
5.3 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 UPDATE_SESSION_KEY_COUNT (1024 * 4)
  30. // update session key after this many encryptions.
  31. #define DATA_SIGNATURE_SIZE 8
  32. // size of the data signature that sent accross.
  33. /****************************************************************************/
  34. /* Encryption levels - bit field. */
  35. /****************************************************************************/
  36. #define SM_40BIT_ENCRYPTION_FLAG 0x01
  37. #define SM_128BIT_ENCRYPTION_FLAG 0x02
  38. #define SM_56BIT_ENCRYPTION_FLAG 0x08
  39. typedef struct _RANDOM_KEYS_PAIR {
  40. BYTE clientRandom[RANDOM_KEY_LENGTH];
  41. BYTE serverRandom[RANDOM_KEY_LENGTH];
  42. } RANDOM_KEYS_PAIR, FAR *LPRANDOM_KEYS_PAIR;
  43. //
  44. // Autoreconnection specific security structures
  45. // These are defined here because they are not necessarily RDP
  46. // specific. Although the PDU's wrapping these packets will
  47. // be protocol specific.
  48. //
  49. // Server to client ARC packet
  50. #define ARC_SC_SECURITY_TOKEN_LEN 16
  51. typedef struct _ARC_SC_PRIVATE_PACKET {
  52. ULONG cbLen;
  53. ULONG Version;
  54. ULONG LogonId;
  55. BYTE ArcRandomBits[ARC_SC_SECURITY_TOKEN_LEN];
  56. } ARC_SC_PRIVATE_PACKET, *PARC_SC_PRIVATE_PACKET;
  57. #define ARC_CS_SECURITY_TOKEN_LEN 16
  58. typedef struct _ARC_CS_PRIVATE_PACKET {
  59. ULONG cbLen;
  60. ULONG Version;
  61. ULONG LogonId;
  62. BYTE SecurityVerifier[ARC_CS_SECURITY_TOKEN_LEN];
  63. } ARC_CS_PRIVATE_PACKET, *PARC_CS_PRIVATE_PACKET;
  64. BOOL
  65. MakeSessionKeys(
  66. LPRANDOM_KEYS_PAIR pKeyPair,
  67. LPBYTE pbEncryptKey,
  68. struct RC4_KEYSTRUCT FAR *prc4EncryptKey,
  69. LPBYTE pbDecryptKey,
  70. struct RC4_KEYSTRUCT FAR *prc4DecryptKey,
  71. LPBYTE pbMACSaltKey,
  72. DWORD dwKeyStrength,
  73. LPDWORD pdwKeyLength,
  74. DWORD dwEncryptionLevel
  75. );
  76. BOOL
  77. UpdateSessionKey(
  78. LPBYTE pbStartKey,
  79. LPBYTE pbCurrentKey,
  80. DWORD dwKeyStrength,
  81. DWORD dwKeyLength,
  82. struct RC4_KEYSTRUCT FAR *prc4Key,
  83. DWORD dwEncryptionLevel
  84. );
  85. BOOL
  86. EncryptData(
  87. DWORD dwEncryptionLevel,
  88. LPBYTE pSessionKey,
  89. struct RC4_KEYSTRUCT FAR *prc4EncryptKey,
  90. DWORD dwKeyLength,
  91. LPBYTE pbData,
  92. DWORD dwDataLen,
  93. LPBYTE pbMACSaltKey,
  94. LPBYTE pbSignature,
  95. BOOL fCheckSumEncryptedData,
  96. DWORD dwEncryptionCount
  97. );
  98. BOOL
  99. DecryptData(
  100. DWORD dwEncryptionLevel,
  101. LPBYTE pSessionKey,
  102. struct RC4_KEYSTRUCT FAR *prc4DecryptKey,
  103. DWORD dwKeyLength,
  104. LPBYTE pbData,
  105. DWORD dwDataLen,
  106. LPBYTE pbMACSaltKey,
  107. LPBYTE pbSignature,
  108. BOOL fCheckSumCipherText,
  109. DWORD dwDecryptionCount
  110. );
  111. //
  112. // RNG init/term functions for DLL_PROCESS_ATTACH, DLL_PROCESS_DETACH
  113. //
  114. VOID
  115. TSRNG_Initialize(
  116. );
  117. VOID
  118. TSRNG_Shutdown(
  119. );
  120. //
  121. // RNG bit gathering function i.e all the work happens here
  122. //
  123. // Params:
  124. // pbRandomKey - where to place the random bits
  125. // dwRandomKeyLen - size in bytes of pbRandomKey
  126. //
  127. // Returns
  128. // Success flag
  129. //
  130. BOOL
  131. TSRNG_GenerateRandomBits(
  132. LPBYTE pbRandomKey,
  133. DWORD dwRandomKeyLen
  134. );
  135. #ifndef NO_INCLUDE_LICENSING
  136. BOOL
  137. GetServerCert(
  138. LPBYTE FAR *ppServerCertBlob,
  139. LPDWORD pdwServerCertLen
  140. );
  141. VOID
  142. InitRandomGenerator(
  143. VOID);
  144. BOOL
  145. GenerateRandomKey(
  146. LPBYTE pbRandomKey,
  147. DWORD dwRandomKeyLen
  148. );
  149. BOOL
  150. UnpackServerCert(
  151. LPBYTE pbCert,
  152. DWORD dwCertLen,
  153. PHydra_Server_Cert pServerCert
  154. );
  155. BOOL
  156. ValidateServerCert(
  157. PHydra_Server_Cert pServerCert
  158. );
  159. #endif // NO_INCLUDE_LICENSING
  160. BOOL
  161. EncryptClientRandom(
  162. LPBYTE pbSrvPublicKey,
  163. DWORD dwSrvPublicKey,
  164. LPBYTE pbRandomKey,
  165. DWORD dwRandomKeyLen,
  166. LPBYTE pbEncRandomKey,
  167. LPDWORD pdwEncRandomKey
  168. );
  169. BOOL
  170. DecryptClientRandom(
  171. LPBYTE pbEncRandomKey,
  172. DWORD dwEncRandomKeyLen,
  173. LPBYTE pbRandomKey,
  174. LPDWORD pdwRandomKeyLen
  175. );
  176. BOOL EncryptDecryptLocalData(
  177. LPBYTE pbData,
  178. DWORD dwDataLen
  179. );
  180. BOOL EncryptDecryptLocalData50(
  181. LPBYTE pbData,
  182. DWORD dwDataLen,
  183. LPBYTE pbSalt,
  184. DWORD dwSaltLen
  185. );
  186. void PortableEncode(LPBYTE pbData,
  187. DWORD dwDataLen);
  188. void PortableEncode50(LPBYTE pbData,
  189. DWORD dwDataLen,
  190. LPBYTE pbSalt,
  191. DWORD dwSaltLength);
  192. //
  193. // remove (or comment) the following definition to disable the MSRC4.
  194. //
  195. // #define USE_MSRC4
  196. #ifdef USE_MSRC4
  197. VOID
  198. msrc4_key(
  199. struct RC4_KEYSTRUCT FAR *pKS,
  200. DWORD dwLen,
  201. LPBYTE pbKey);
  202. VOID
  203. msrc4(
  204. struct RC4_KEYSTRUCT FAR *pKS,
  205. DWORD dwLen,
  206. LPBYTE pbuf);
  207. #else // USE_MSRC4
  208. #define msrc4_key rc4_key
  209. #define msrc4 rc4
  210. #endif // USE_MSRC4
  211. BOOL
  212. FindIsFrenchSystem(
  213. VOID
  214. );
  215. #ifdef __cplusplus
  216. }
  217. #endif // __cplusplus
  218. #endif // _TSSEC_H_