freeotfecyphernull.c
来自「文件驱动加密,功能强大,可产生加密分区,支持AES,MD2,MD4,MD5MD2」· C语言 代码 · 共 212 行
C
212 行
// Description:
// By Sarah Dean
// Email: sdean12@sdean12.org
// WWW: http://www.FreeOTFE.org/
//
// -----------------------------------------------------------------------------
//
#ifndef WINCE
#include <ntddk.h>
#endif
#include "FreeOTFECypherNull.h"
#include "FreeOTFECypherImpl.h"
#include "FreeOTFECypherAPICommon.h"
#ifdef WINCE
#include "FreeOTFE4PDACypherDriver.h" // Required for DRIVER_CYPHER_VERSION
#else
#include "FreeOTFECypherDriver.h" // Required for DRIVER_CYPHER_VERSION
#endif
#include "FreeOTFEPlatform.h"
#include "FreeOTFEDebug.h"
#include "FreeOTFElib.h"
// =========================================================================
// Cypher driver init function
// driverInfo - The structure to be initialized
NTSTATUS
ImpCypherDriverExtDetailsInit(
IN OUT CYPHER_DRIVER_INFO* driverInfo
)
{
NTSTATUS status = STATUS_SUCCESS;
int idx = -1;
DEBUGOUTCYPHERIMPL(DEBUGLEV_ENTER, (TEXT("ImpCypherDriverExtDetailsInit\n")));
// -- POPULATE DRIVER IDENTIFICATION --
FREEOTFE_MEMZERO(driverInfo->DriverTitle, sizeof(driverInfo->DriverTitle));
FREEOTFE_MEMCPY(
driverInfo->DriverTitle,
DRIVER_TITLE,
strlen(DRIVER_TITLE)
);
driverInfo->DriverGUID = DRIVER_GUID;
driverInfo->DriverVersionID = DRIVER_CYPHER_VERSION;
// -- POPULATE cyphers SUPPORTED --
driverInfo->CypherDetails = FREEOTFE_MEMALLOC((sizeof(CYPHER) * CYPHERS_SUPPORTED));
driverInfo->CypherCount = CYPHERS_SUPPORTED;
// -- Null --
idx++;
FREEOTFE_MEMZERO(driverInfo->CypherDetails[idx].Title, MAX_CYPHER_TITLE);
FREEOTFE_MEMCPY(
driverInfo->CypherDetails[idx].Title,
DRIVER_CIPHER_TITLE_NULL,
strlen(DRIVER_CIPHER_TITLE_NULL)
);
driverInfo->CypherDetails[idx].Mode = CYPHER_MODE_NONE;
driverInfo->CypherDetails[idx].KeySize = 0;
driverInfo->CypherDetails[idx].BlockSize = -1;
driverInfo->CypherDetails[idx].VersionID = DRIVER_CYPHER_IMPL_VERSION;
driverInfo->CypherDetails[idx].CypherGUID = CIPHER_GUID_NULL;
DEBUGOUTCYPHERIMPL(DEBUGLEV_EXIT, (TEXT("ImpCypherDriverExtDetailsInit\n")));
return status;
}
// =========================================================================
// Cypher driver cleardown function
// driverInfo - The structure to be cleared down
NTSTATUS
ImpCypherDriverExtDetailsCleardown(
IN OUT CYPHER_DRIVER_INFO* driverInfo
)
{
NTSTATUS status = STATUS_SUCCESS;
DEBUGOUTCYPHERIMPL(DEBUGLEV_ENTER, (TEXT("ImpCypherDriverExtDetailsCleardown\n")));
if (driverInfo->CypherDetails != NULL)
{
FREEOTFE_FREE(driverInfo->CypherDetails);
}
driverInfo->CypherDetails = NULL;
driverInfo->CypherCount = 0;
DEBUGOUTCYPHERIMPL(DEBUGLEV_EXIT, (TEXT("ImpCypherDriverExtDetailsCleardown\n")));
return status;
}
// =========================================================================
// Encryption function
// Note: CyphertextLength must be set to the size of the CyphertextData buffer on
// entry; on exit, this will be set to the size of the buffer used.
NTSTATUS
ImpCypherEncryptData(
IN GUID* CypherGUID,
IN int KeyLength, // In bits
IN char *Key,
IN char *KeyASCII, // ASCII representation of "Key"
IN int IVLength, // In bits
IN char *IV,
IN int PlaintextLength, // In bytes
IN char *PlaintextData,
OUT char *CyphertextData
)
{
NTSTATUS status = STATUS_SUCCESS;
DEBUGOUTCYPHERIMPL(DEBUGLEV_ENTER, (TEXT("ImpCypherEncryptData\n")));
if (!(IsEqualGUID(&CIPHER_GUID_NULL, CypherGUID)))
{
status = STATUS_INVALID_PARAMETER;
}
else
{
if ( (IV == NULL) && (IVLength != 0) )
{
// Sanity check failed...
DEBUGOUTCYPHERIMPL(DEBUGLEV_INFO, (TEXT("Inconsistant: NULL passed as %d bit long IV\n"), IVLength));
status = STATUS_INVALID_PARAMETER;
}
else
{
FREEOTFE_MEMCPY(
CyphertextData,
PlaintextData,
PlaintextLength
);
}
}
DEBUGOUTCYPHERIMPL(DEBUGLEV_EXIT, (TEXT("ImpCypherEncryptData\n")));
return status;
}
// =========================================================================
// Decryption function
// Note: PlaintextLength must be set to the size of the PlaintextData buffer on
// entry; on exit, this will be set to the size of the buffer used.
NTSTATUS
ImpCypherDecryptData(
IN GUID* CypherGUID,
IN int KeyLength, // In bits
IN char *Key,
IN char *KeyASCII, // ASCII representation of "Key"
IN int IVLength, // In bits
IN char *IV,
IN int CyphertextLength, // In bytes
IN char *CyphertextData,
OUT char *PlaintextData
)
{
NTSTATUS status = STATUS_SUCCESS;
DEBUGOUTCYPHERIMPL(DEBUGLEV_ENTER, (TEXT("ImpCypherDecryptData\n")));
if (!(IsEqualGUID(&CIPHER_GUID_NULL, CypherGUID)))
{
status = STATUS_INVALID_PARAMETER;
}
else
{
if ( (IV == NULL) && (IVLength != 0) )
{
// Sanity check failed...
DEBUGOUTCYPHERIMPL(DEBUGLEV_INFO, (TEXT("Inconsistant: NULL passed as %d bit long IV\n"), IVLength));
status = STATUS_INVALID_PARAMETER;
}
else
{
FREEOTFE_MEMCPY(
PlaintextData,
CyphertextData,
CyphertextLength
);
}
}
DEBUGOUTCYPHERIMPL(DEBUGLEV_EXIT, (TEXT("ImpCypherDecryptData\n")));
return status;
}
// =========================================================================
// =========================================================================
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?