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.

223 lines
7.7 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // File: cmsecure.h
  4. //
  5. // Module: CMSECURE.LIB
  6. //
  7. // Synopsis: This header describes the functionality available in the cmsecure
  8. // library.
  9. //
  10. // Copyright (c) 1996-1999 Microsoft Corporation
  11. //
  12. // Author: henryt Created 05/21/97
  13. //
  14. //+----------------------------------------------------------------------------
  15. #ifndef _CMSECURE_INC_
  16. #define _CMSECURE_INC_
  17. #include <windows.h>
  18. //************************************************************************
  19. // define's
  20. //************************************************************************
  21. //
  22. // the encryption types that cmsecure currently supports
  23. //
  24. #define CMSECURE_ET_NOT_ENCRYPTED 0 // 0x0000
  25. #define CMSECURE_ET_RC2 1 // 0x0001
  26. #define CMSECURE_ET_STREAM_CIPHER 2 // 0x0002
  27. #define CMSECURE_ET_CBC_CIPHER 3 // 0x0003
  28. //
  29. // Extended codes for UNICODE designation
  30. // Note: The encryption logic will not know anything about these new codes
  31. // they are designed for book-keeping by the calling modules, which will
  32. // have to do the appropiate conversions based on the calling context/OS
  33. //
  34. #define CMSECURE_ET_NOT_ENCRYPTED_U 128 // 0x0080
  35. #define CMSECURE_ET_RC2_U 129 // 0x0081
  36. #define CMSECURE_ET_STREAM_CIPHER_U 130 // 0x0082
  37. #define CMSECURE_ET_CBC_CIPHER_U 131 // 0x0083
  38. #define CMSECURE_ET_MASK_U 128 // 0x0080
  39. #define CMSECURE_ET_RANDOM_KEY_MASK 256 // 0x0100 uses a randomly generated key
  40. #define CMSECURE_ET_USE_SECOND_RND_KEY 512 // 0x1000 uses the second blob key
  41. //
  42. // structures, typdef's
  43. //
  44. typedef LPVOID (*PFN_CMSECUREALLOC)(DWORD);
  45. typedef void (*PFN_CMSECUREFREE)(LPVOID);
  46. //
  47. // externs
  48. //
  49. //
  50. // function prototypes
  51. //
  52. /*
  53. #ifdef __cplusplus
  54. extern "C" {
  55. #endif
  56. */
  57. // cmsecure.cpp
  58. BOOL
  59. InitSecure(
  60. BOOL fFastEncryption = FALSE // default is more secure
  61. );
  62. void
  63. DeInitSecure(
  64. void
  65. );
  66. BOOL
  67. EncryptData(
  68. IN LPBYTE pbData, // Data to be encrypted
  69. IN DWORD dwDataLength, // Length of data in bytes
  70. OUT LPBYTE *ppbEncryptedData, // Encrypted secret key will be stored here(memory will be allocated)
  71. OUT LPDWORD pdwEncrytedBufferLen, // Length of this buffer
  72. OUT LPDWORD pEncryptionType, // type of the encryption used
  73. IN PFN_CMSECUREALLOC pfnAlloc, // memory allocator(if NULL, then the default is used.
  74. // Win32 - HeapAlloc(GetProcessHeap(), ...)
  75. IN PFN_CMSECUREFREE pfnFree, // memory deallocator(if NULL, then the default is used.
  76. // Win32 - HeapFree(GetProcessHeap(), ...)
  77. IN LPSTR pszUserKey // Registry key to store encrypted key for passwords
  78. );
  79. BOOL
  80. DecryptData(
  81. IN LPBYTE pbEncryptedData, // Encrypted data
  82. IN DWORD dwEncrytedDataLen, // Length of encrypted data
  83. OUT LPBYTE *ppbData, // Decrypted Data will be stored here(memory will be allocated)
  84. OUT LPDWORD pdwDataBufferLength, // Length of the above buffer in bytes
  85. IN DWORD dwEncryptionType, // encryption type for decryption
  86. IN PFN_CMSECUREALLOC pfnAlloc, // memory allocator(if NULL, then the default is used.
  87. // Win32 - HeapAlloc(GetProcessHeap(), ...)
  88. IN PFN_CMSECUREFREE pfnFree, // memory deallocator(if NULL, then the default is used.
  89. // Win32 - HeapFree(GetProcessHeap(), ...)
  90. IN LPSTR pszUserKey // Registry key to store encrypted key for passwords
  91. );
  92. BOOL
  93. EncryptString(
  94. IN LPSTR pszToEncrypt, // String to be encrypted (Ansi)
  95. IN LPSTR pszUserKey, // Key to use for Encryption
  96. OUT LPBYTE * ppbEncryptedData, // Encrypted secret key will be stored here(memory will be allocated)
  97. OUT LPDWORD pdwEncrytedBufferLen, // Length of this buffer
  98. IN PFN_CMSECUREALLOC pfnAlloc, // memory allocator(if NULL, then the default is used.
  99. // Win32 - HeapAlloc(GetProcessHeap(), ...)
  100. IN PFN_CMSECUREFREE pfnFree // memory deallocator(if NULL, then the default is used.
  101. // Win32 - HeapFree(GetProcessHeap(), ...)
  102. );
  103. BOOL
  104. DecryptString(
  105. IN LPBYTE pbEncryptedData, // Encrypted data
  106. IN DWORD dwEncrytedDataLen, // Length of encrypted data
  107. IN LPSTR pszUserKey, // Registry key to store encrypted key for passwords
  108. OUT LPBYTE * ppbData, // Decrypted Data will be stored here
  109. OUT LPDWORD pdwDataBufferLength, // Length of the above buffer in bytes
  110. IN PFN_CMSECUREALLOC pfnAlloc, // memory allocator(if NULL, then the default is used.
  111. // Win32 - HeapAlloc(GetProcessHeap(), ...)
  112. IN PFN_CMSECUREFREE pfnFree // memory deallocator(if NULL, then the default is used.
  113. // Win32 - HeapFree(GetProcessHeap(), ...)
  114. );
  115. //+---------------------------------------------------------------------------
  116. //
  117. // Function: AnsiToUnicodePcs
  118. //
  119. // Synopsis: Wrapper to encapsulate translating a standard crypt type value
  120. // into its equivalent for UNICODE systems.
  121. //
  122. // Arguments: IN DWORD dwCrypt - The code to be converted
  123. //
  124. // Returns: Converted code
  125. //
  126. // History: nickball Created 06/02/99
  127. //
  128. //----------------------------------------------------------------------------
  129. inline DWORD AnsiToUnicodePcs(IN DWORD dwCrypt)
  130. {
  131. return (dwCrypt | CMSECURE_ET_MASK_U);
  132. }
  133. //+---------------------------------------------------------------------------
  134. //
  135. // Function: UnicodeToAnsiPcs
  136. //
  137. // Synopsis: Wrapper to encapsulate translating a UNICODE crypt type value
  138. // into its equivalent standard ANSI crypt type.
  139. //
  140. // Arguments: IN DWORD dwCrypt - The code to be converted
  141. //
  142. // Returns: Converted code
  143. //
  144. // History: nickball Created 06/02/99
  145. //
  146. //----------------------------------------------------------------------------
  147. inline DWORD UnicodeToAnsiPcs(IN DWORD dwCrypt)
  148. {
  149. return (dwCrypt & (~CMSECURE_ET_MASK_U));
  150. }
  151. //+---------------------------------------------------------------------------
  152. //
  153. // Function: IsUnicodePcs
  154. //
  155. // Synopsis: Wrapper to encapsulate determining if a crypt type has UNICODE
  156. // designation.
  157. //
  158. // Arguments: IN DWORD dwCrypt - The code to be converted
  159. //
  160. // Returns: TRUE if UNICODE designation
  161. //
  162. // History: nickball Created 06/02/99
  163. //
  164. //----------------------------------------------------------------------------
  165. inline BOOL IsUnicodePcs(IN DWORD dwCrypt)
  166. {
  167. return (!!(dwCrypt & CMSECURE_ET_MASK_U)); // !! == (BOOL)
  168. }
  169. //+---------------------------------------------------------------------------
  170. //
  171. // Function: IsAnsiPcs
  172. //
  173. // Synopsis: Wrapper to encapsulate determining if a crypt type has Ansi
  174. // designation.
  175. //
  176. // Arguments: IN DWORD dwCrypt - The code to be converted
  177. //
  178. // Returns: TRUE if Ansi designation
  179. //
  180. // History: nickball Created 06/02/99
  181. //
  182. //----------------------------------------------------------------------------
  183. inline BOOL IsAnsiPcs(IN DWORD dwCrypt)
  184. {
  185. return (!(dwCrypt & CMSECURE_ET_MASK_U));
  186. }
  187. /*
  188. #ifdef __cplusplus
  189. }
  190. #endif
  191. */
  192. #endif // _CMSECURE_INC_