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.

426 lines
7.8 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Abstract:
  4. This module contains the common header information for the EFS
  5. DLL.
  6. Author:
  7. Robert Gu (robertg) 08-Dec-1996
  8. Enviroment:
  9. Kernel Mode Only
  10. Revision History:
  11. --*/
  12. #ifndef EFSRTL_H
  13. #define EFSRTL_H
  14. #include "efs.h"
  15. #include "efsext.h"
  16. #define EFS_IV 0x169119629891ad13
  17. #define EFS_AES_IVL 0x5816657be9161312
  18. #define EFS_AES_IVH 0x1989adbe44918961
  19. //#define ENCRYPT 0
  20. //#define DECRYPT 1
  21. #define CHUNK_SIZE 512
  22. #define EFS_MAX_LENGTH 256*1024
  23. //
  24. // Status of EFS context.
  25. //
  26. // Processing Status
  27. //
  28. #define NO_FURTHER_PROCESSING 0x00000000
  29. #define NEW_FILE_EFS_REQUIRED 0x00000001
  30. #define NEW_DIR_EFS_REQUIRED 0x00000002
  31. #define VERIFY_USER_REQUIRED 0x00000004
  32. #define TURN_ON_BIT_ONLY 0x00000008
  33. #define NO_OPEN_CACHE_CHECK 0x40000000
  34. #define TURN_ON_ENCRYPTION_BIT 0x80000000
  35. #define ACTION_REQUIRED 0x0fffffff
  36. //
  37. //
  38. //
  39. #define SYSTEM_IS_READONLY 0x00000001
  40. //
  41. // Error Status
  42. //
  43. #define CREATE_EFS_FAIL 0x00000100
  44. #define OPEN_EFS_FAIL 0x00000200
  45. #define WRITE_EFS_FAIL 0x00000400
  46. #define OUT_OF_MEMORY 0x00000800
  47. #define EFS_FORMAT_ERROR 0x00001000
  48. #define NTOFS_EXCEPTION 0x00002000
  49. //
  50. // Information Status
  51. //
  52. #define EFS_READ_SUCCESSFUL 0x00010000
  53. //
  54. // Stream Create Status
  55. //
  56. #define STRING_NEW_OR_EXIST_MASK 0x000f0000
  57. #define FILE_DIR_TYPE 0x0000000f
  58. #define FILE_NEW 0x00000001
  59. #define FILE_EXISTING 0x00000002
  60. #define DIRECTORY_NEW 0x00000004
  61. #define DIRECTORY_EXISTING 0x00000008
  62. #define STREAM_NEW 0x00010000
  63. #define STREAM_EXISTING 0x00020000
  64. //
  65. // Encryption flag
  66. //
  67. #define FILE_ENCRYPTED 0x00000002
  68. #define STREAM_ENCRYPTED 0x00000001
  69. //
  70. // The EFS FSCTL Input data buffer.
  71. //
  72. typedef struct _FSCTL_INPUT {
  73. ULONG PlainSubCode;
  74. ULONG EfsFsCode;
  75. ULONG CipherSubCode;
  76. UCHAR EfsFsData[1];
  77. } FSCTL_INPUT, *PFSCTL_INPUT;
  78. typedef struct _GENERAL_FS_DATA {
  79. UCHAR Sk1[DES_KEYSIZE];
  80. ULONG Hdl1;
  81. ULONG Hdl2;
  82. UCHAR Sk2[DES_KEYSIZE];
  83. ULONG Hdl3;
  84. ULONG Hdl4;
  85. UCHAR EfsData[1];
  86. } GENERAL_FS_DATA, *PGENERAL_FS_DATA;
  87. typedef struct _EFS_STREAM {
  88. ULONG Length;
  89. ULONG Status;
  90. UCHAR Private[1];
  91. } EFS_STREAM, *PEFS_STREAM;
  92. //
  93. // Function prototypes
  94. //
  95. typedef VOID ( * EfsEncFunc)(
  96. IN PUCHAR InBuffer,
  97. OUT PUCHAR OutBuffer,
  98. IN PUCHAR IV,
  99. IN PKEY_BLOB KeyBlob,
  100. IN LONG Length
  101. );
  102. typedef VOID ( * EfsDecFunc)(
  103. IN OUT PUCHAR Buffer,
  104. IN PUCHAR IV,
  105. IN PKEY_BLOB KeyBlob,
  106. IN LONG Length
  107. );
  108. VOID
  109. EFSDesEnc(
  110. IN PUCHAR InBuffer,
  111. OUT PUCHAR OutBuffer,
  112. IN PUCHAR IV,
  113. IN PKEY_BLOB KeyBlob,
  114. IN LONG Length
  115. );
  116. VOID
  117. EFSDesDec(
  118. IN OUT PUCHAR Buffer,
  119. IN PUCHAR IV,
  120. IN PKEY_BLOB KeyBlob,
  121. IN LONG Length
  122. );
  123. VOID
  124. EFSDesXEnc(
  125. IN PUCHAR InBuffer,
  126. OUT PUCHAR OutBuffer,
  127. IN PUCHAR IV,
  128. IN PKEY_BLOB KeyBlob,
  129. IN LONG Length
  130. );
  131. VOID
  132. EFSDesXDec(
  133. IN OUT PUCHAR Buffer,
  134. IN PUCHAR IV,
  135. IN PKEY_BLOB KeyBlob,
  136. IN LONG Length
  137. );
  138. VOID
  139. EFSDes3Enc(
  140. IN PUCHAR InBuffer,
  141. OUT PUCHAR OutBuffer,
  142. IN PUCHAR IV,
  143. IN PKEY_BLOB KeyBlob,
  144. IN LONG Length
  145. );
  146. VOID
  147. EFSDes3Dec(
  148. IN OUT PUCHAR Buffer,
  149. IN PUCHAR IV,
  150. IN PKEY_BLOB KeyBlob,
  151. IN LONG Length
  152. );
  153. VOID
  154. EFSAesEnc(
  155. IN PUCHAR InBuffer,
  156. OUT PUCHAR OutBuffer,
  157. IN PUCHAR IV,
  158. IN PKEY_BLOB KeyBlob,
  159. IN LONG Length
  160. );
  161. VOID
  162. EFSAesDec(
  163. IN OUT PUCHAR Buffer,
  164. IN PUCHAR IV,
  165. IN PKEY_BLOB KeyBlob,
  166. IN LONG Length
  167. );
  168. VOID
  169. EfsEncryptKeyFsData(
  170. IN PVOID DataBuffer,
  171. IN ULONG DataLength,
  172. IN ULONG DataEncOffset,
  173. IN ULONG RefdataEncOffset,
  174. IN ULONG RefdataEncLength
  175. );
  176. NTSTATUS
  177. EfsOpenFile(
  178. IN OBJECT_HANDLE FileHdl,
  179. IN OBJECT_HANDLE ParentDir OPTIONAL,
  180. IN PIO_STACK_LOCATION IrpSp,
  181. IN ULONG FileDirFlag,
  182. IN ULONG SystemState,
  183. IN PIRP_CONTEXT IrpContext,
  184. IN PDEVICE_OBJECT VolDo,
  185. IN PVOID PfileKeyContext,
  186. IN OUT PVOID *PContext,
  187. IN OUT PULONG PContextLength,
  188. IN OUT PVOID *PCreateContext,
  189. IN OUT PBOOLEAN Reserved
  190. );
  191. NTSTATUS
  192. EfsFileControl(
  193. IN PVOID PInputBuffer,
  194. IN ULONG InputDataLength,
  195. OUT PVOID POutputBuffer OPTIONAL,
  196. IN OUT PULONG OutputBufferLength,
  197. IN ULONG EncryptionFlag,
  198. IN ULONG AccessFlag,
  199. IN ULONG SystemState,
  200. IN ULONG FsControlCode,
  201. IN OBJECT_HANDLE FileHdl,
  202. IN PIRP_CONTEXT IrpContext,
  203. IN PDEVICE_OBJECT VolDo,
  204. IN ATTRIBUTE_HANDLE Stream,
  205. IN OUT PVOID *PContext,
  206. IN OUT PULONG PContextLength
  207. );
  208. NTSTATUS
  209. EfsRead(
  210. IN OUT PUCHAR Buffer,
  211. IN PLARGE_INTEGER Offset,
  212. IN ULONG BufferSize,
  213. IN PVOID Context
  214. );
  215. NTSTATUS
  216. EfsWrite(
  217. IN PUCHAR InBuffer, //Do we need in and out buffer?
  218. OUT PUCHAR OutBuffer,
  219. IN PLARGE_INTEGER Offset,
  220. IN ULONG BufferSize,
  221. IN PUCHAR Context
  222. );
  223. VOID
  224. EfsFreeContext(
  225. IN OUT PVOID *PContext
  226. );
  227. NTSTATUS
  228. EfsMountVolumn(
  229. IN PDEVICE_OBJECT VolDo,
  230. IN PDEVICE_OBJECT RealDevice
  231. );
  232. VOID
  233. EfsDismountVolumn(
  234. IN PDEVICE_OBJECT DeviceObject
  235. );
  236. NTSTATUS
  237. EfsReadEfsData(
  238. IN OBJECT_HANDLE FileHdl,
  239. IN PIRP_CONTEXT IrpContext,
  240. OUT PVOID *EfsStreamData,
  241. OUT PULONG PEfsStreamLength,
  242. OUT PULONG Information
  243. );
  244. BOOLEAN
  245. EfsVerifyGeneralFsData(
  246. IN PUCHAR DataOffset,
  247. IN ULONG InputDataLength
  248. );
  249. BOOLEAN
  250. EfsVerifyKeyFsData(
  251. IN PUCHAR DataOffset,
  252. IN ULONG InputDataLength
  253. );
  254. NTSTATUS
  255. EfsDeleteEfsData(
  256. IN OBJECT_HANDLE FileHdl,
  257. IN PIRP_CONTEXT IrpContext
  258. );
  259. NTSTATUS
  260. EfsSetEncrypt(
  261. IN PUCHAR InputData,
  262. IN ULONG InputDataLength,
  263. IN ULONG EncryptionFlag,
  264. IN OBJECT_HANDLE FileHdl,
  265. IN PIRP_CONTEXT IrpContext,
  266. IN OUT PVOID *Context,
  267. IN OUT PULONG PContextLength
  268. );
  269. NTSTATUS
  270. EfsEncryptStream(
  271. IN PUCHAR InputData,
  272. IN ULONG InputDataLength,
  273. IN ULONG EncryptionFlag,
  274. IN OBJECT_HANDLE FileHdl,
  275. IN PIRP_CONTEXT IrpContext,
  276. IN OUT PVOID *Context,
  277. IN OUT PULONG PContextLength
  278. );
  279. NTSTATUS
  280. EfsEncryptFile(
  281. IN PUCHAR InputData,
  282. IN ULONG InputDataLength,
  283. IN ULONG EncryptionFlag,
  284. IN OBJECT_HANDLE FileHdl,
  285. IN PIRP_CONTEXT IrpContext,
  286. IN OUT PVOID *Context
  287. );
  288. NTSTATUS
  289. EfsDecryptStream(
  290. IN PUCHAR InputData,
  291. IN ULONG InputDataLength,
  292. IN ULONG EncryptionFlag,
  293. IN OBJECT_HANDLE FileHdl,
  294. IN PIRP_CONTEXT IrpContext,
  295. IN OUT PVOID *Context,
  296. IN OUT PULONG PContextLength
  297. );
  298. NTSTATUS
  299. EfsDecryptFile(
  300. IN PUCHAR InputData,
  301. IN ULONG InputDataLength,
  302. IN OBJECT_HANDLE FileHdl,
  303. IN PIRP_CONTEXT IrpContext
  304. );
  305. NTSTATUS
  306. EfsEncryptDir(
  307. IN PUCHAR InputData,
  308. IN ULONG InputDataLength,
  309. IN ULONG EncryptionFlag,
  310. IN OBJECT_HANDLE FileHdl,
  311. IN PIRP_CONTEXT IrpContext
  312. );
  313. NTSTATUS
  314. EfsModifyEfsState(
  315. IN ULONG FunctionCode,
  316. IN PUCHAR InputData,
  317. IN ULONG InputDataLength,
  318. IN OBJECT_HANDLE FileHdl,
  319. IN PIRP_CONTEXT IrpContext
  320. );
  321. ULONG
  322. GetEfsStreamOffset(
  323. IN PUCHAR InputData
  324. );
  325. NTSTATUS
  326. SetEfsData(
  327. PUCHAR InputData,
  328. IN ULONG InputDataLength,
  329. IN ULONG SystemState,
  330. IN OBJECT_HANDLE FileHdl,
  331. IN PIRP_CONTEXT IrpContext,
  332. IN OUT PVOID *PContext,
  333. IN OUT PULONG PContextLength
  334. );
  335. BOOLEAN
  336. EfsFindInCache(
  337. IN GUID *EfsId,
  338. IN PTOKEN_USER UserId
  339. );
  340. NTSTATUS
  341. EfsRefreshCache(
  342. IN GUID *EfsId,
  343. IN PTOKEN_USER UserId
  344. );
  345. BOOLEAN
  346. SkipCheckStream(
  347. IN PIO_STACK_LOCATION IrpSp,
  348. IN PVOID efsStreamData
  349. );
  350. #endif