freeotfecontext.h
来自「文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2」· C头文件 代码 · 共 313 行
H
313 行
// Description:
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW: http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//
#ifndef _FreeOTFEContext_H
#define _FreeOTFEContext_H 1
// This *must* be early, in order to prevent problems with ntddstor.h
#include "FreeOTFEAPITypes.h"
#ifdef WINCE
#include <Diskio.h> // Required for DISK_INFO
#include <Storemgr.h> // Required for STORAGEDEVICEINFO
#include "FreeOTFE4PDARegistry.h" // Required for REGDETAILS_ACTIVE
#include "FreeOTFE4PDAHashAPI.h" // Required for hash function type
#include "FreeOTFE4PDACypherAPI.h" // Required for hash function type
#else
//#include <windef.h> // Required for DWORD
//#include <Winioctl.h> // Required for DISK_GEOMETRY
#include <ntdddisk.h> // Required for DISK_GEOMETRY
#include "IFSRelated.h" // Requird for PSECURITY_CLIENT_CONTEXT
#endif
#include "FreeOTFEPlatform.h"
#include "FreeOTFEHashAPICommon.h" // Required for HASH
#include "FreeOTFECypherAPICommon.h" // Required for CYPHER
// =========================================================================
// Type definitions
typedef struct _MODULE_DETAILS_HASH {
#ifdef WINCE
WCHAR* DeviceName;
#else
UNICODE_STRING DeviceName;
#endif
GUID HashGUID;
// IV Hash device handle
#ifdef WINCE
HINSTANCE Lib;
#else
PFILE_OBJECT FileObject;
PDEVICE_OBJECT DeviceObject;
#endif
// IV Hash device internal details
HASH Details;
#ifdef WINCE
PHashDLLFnHash FnHash;
#else
PDataHashFn FnHash;
#endif
} MODULE_DETAILS_HASH, *PMODULE_DETAILS_HASH;
typedef struct _MODULE_DETAILS_CYPHER {
#ifdef WINCE
WCHAR* DeviceName;
#else
UNICODE_STRING DeviceName;
#endif
GUID CypherGUID;
// IV cypher device handle
#ifdef WINCE
HINSTANCE Lib;
#else
PFILE_OBJECT FileObject;
PDEVICE_OBJECT DeviceObject;
#endif
// IV cypher device internal details
CYPHER Details;
#ifdef WINCE
PCypherDLLFnEncryptWithASCII FnEncrypt;
PCypherDLLFnDecryptWithASCII FnDecrypt;
#else
PDataEncryptFn FnEncrypt;
PDataDecryptFn FnDecrypt;
#endif
} MODULE_DETAILS_CYPHER, *PMODULE_DETAILS_CYPHER;
typedef struct _DEVICE_EXTENSION {
// ------------------------------------------------------
// Disk device items ONLY
// Flag if a volume is mounted or not
FREEOTFEBOOL Mounted;
// Flag if a volume is being dismounted or not
// i.e. This flag determines if any more IRPs should be queued for
// the thread or not. If set, no further IRPs will be accepted
FREEOTFEBOOL DismountPending;
// Mount source (e.g. the volume file is a partition or file)
MOUNT_SOURCE MountSource;
// Filename of any mounted volume
#ifdef WINCE
WCHAR* zzFilename;
#else
UNICODE_STRING zzFilename;
#endif
// Handle to the volume file
HANDLE FileHandle;
// Flag if file attributes have been stored (e.g. FALSE for partitions, etc)
FREEOTFEBOOL FileAttributesStored;
#ifdef WINCE
// If stored, the file attributes
DWORD FileAttributes;
// Flag if file timestamps have been stored (e.g. FALSE for partitions, etc)
FREEOTFEBOOL FileTimestampsStored;
// If stored, the file timestamps
FILETIME CreationTime;
FILETIME LastAccessTime;
FILETIME LastWriteTime;
#else
// If stored, the file timestamps/attributes when opened
FILE_BASIC_INFORMATION FileAttributes;
#endif
// Start of encrypted data within the file
// Note: We don't need to store the end offset, as this can be determined by using the
// DiskGrometry/DiskSize members
LARGE_INTEGER DataOffset;
// Simulated disk geometry
LARGE_INTEGER PartitionSize;
#ifdef WINCE
DISK_INFO DiskGeometry;
#else
DISK_GEOMETRY DiskGeometry;
#endif
LARGE_INTEGER DiskSize;
#ifndef WINCE
// Count of hidden sectors (if any)
ULONG HiddenSectors;
#endif
// The "sector size" in which blocks should actually be read/written to the volume
// file/partition
ULONG FileSectorSize;
// DataOffset % DiskGeometry->SectorSize
ULONG DataOffsetModVirtualSectorSize;
// Encryption block size
// This *should* always be set to the sector size of the emulated device, but isn't always
// (e.g. Linux ISO images have an emulated 2048 byte sector size, but encrypt in 512 byte
// blocks)
ULONG EncryptionBlockSize;
// Readonly flag
FREEOTFEBOOL ReadOnly;
#ifdef WINCE
// Storage device info (i.e. the type of device emulated)
STORAGEDEVICEINFO StorageDeviceInfo;
#else
// Storage media type (i.e. the type of device emulated)
STORAGE_MEDIA_TYPE StorageMediaType;
#endif
// Prevent media removal; for removable disks only
FREEOTFEBOOL PreventMediaRemoval;
// Sector IV generation method
SECTOR_IV_GEN_METHOD SectorIVGenMethod;
// -----
// IV Hash device ID
MODULE_DETAILS_HASH IVHash;
// -----
// IV cypher device ID
MODULE_DETAILS_CYPHER IVCypher;
// -----
// Main cypher device ID
MODULE_DETAILS_CYPHER MainCypher;
// -----
// Key to be used for encryption/decryption
ULONG MasterKeyLength; // This value is in *bits*
unsigned char *MasterKey;
// MasterKeyASCII is the ASCII representation of MasterKey
// This is stored as all AES candidates use this format for supplying
// their keys (blame NIST for that...)
unsigned char *MasterKeyASCII; // Hex ASCIIZ nibbles
// Key to be used for ESSIV generation (*if* *required*)
ULONG ESSIVKeyLength; // This value is in *bits*
unsigned char *ESSIVKey;
// ESSIVKeyASCII is the ASCII representation of ESSIVKey
// This is stored as all AES candidates use this format for supplying
// their keys (blame NIST for that...)
unsigned char *ESSIVKeyASCII; // Hex ASCIIZ nibbles
// Volume IV to be used to encrypt/decrypt each sector
ULONG VolumeIVLength; // This value is in *bits*
unsigned char *VolumeIV;
// -----
// Various flags
unsigned int VolumeFlags;
// Metadata
// This is used to store arbitary user-mode data when the volume is mounted.
// This data will be returned whenever the status is the disk is returned
ULONG MetaDataLength; // This value is in *bytes*
unsigned char *MetaData;
// ------------------------------------------------------
// ------------------------------------------------------
// ------------------------------------------------------
#ifdef WINCE
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++
// WinCE specific
// Mutex...
LPCRITICAL_SECTION CriticalSection;
// Number of times opened
DWORD OpenCount;
// Registry info...
// From MSDN:
// "The initialization function can read and create new values in the
// Active key; however, it is not permitted to access the key after the
// initialization function returns."
// - so we store it's contents here.
REGDETAILS_ACTIVE RegdetailsActive;
// Mountpoint (also in registry)
WCHAR* Mountpoint;
// Handle to device, as returned to the user app by ActivateDeviceEx(...)
HANDLE UserSpaceDeviceHandle;
#else
// ++++++++++++++++++++++++++++++++++++++++++++++++++++++
// PC specific
// Allow differentiation between the main device and disk devices
FREEOTFEBOOL IsMainDevice;
// Device's name
UNICODE_STRING zzDeviceName;
// ------------------------------------------------------
// Main device items ONLY
// Symbolic link name
UNICODE_STRING zzSymbolicLinkName;
// Security context for volume file handle
PSECURITY_CLIENT_CONTEXT ClientContext;
// File object of volume file handle
PFILE_OBJECT FileObject;
// ------------------------------------------------------
// Thread/IRP queue related items follow
// Flag to signal that the thread should terminate
FREEOTFEBOOL TerminateThread;
// The device's IRP processing thread
PETHREAD ThreadObject;
// Irps waiting to be processed are queued here
LIST_ENTRY PendingIRPQueue;
// SpinLock to protect access to the queue
KSPIN_LOCK IRPQueueLock;
IO_CSQ CancelSafeQueue;
KSEMAPHORE IRPQueueSemaphore;
#endif
} DEVICE_EXTENSION, *PDEVICE_EXTENSION;
// xxx - get rid of the above for this
#define DEVICE_CONTEXT DEVICE_EXTENSION
// =========================================================================
// =========================================================================
// =========================================================================
#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?