?? ibeenctype.c
字號:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "algobj.h"
#include "cipher.h"
#include "ibe.h"
#include "mpint.h"
#include "errorctx.h"
int VtAlgorithmImplBFType1IBE (
VtAlgorithmObject *object,
Pointer info,
unsigned int flag
)
{
int status;
#if VOLT_ALIGNMENT != 1
unsigned int pad;
#endif
unsigned int bufferSize, offset;
VoltAlgorithmObject *obj = (VoltAlgorithmObject *)(*object);
VoltLibCtx *libCtx;
unsigned char *buffer = (unsigned char *)0;
VoltCipherClassCtx *cipherCtx;
VoltBFType1IBECtx *ibeCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Check the flag, it should be VOLT_ALG_SET_TYPE_FLAG.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_ALG_SET_TYPE_FLAG)
break;
/* Check the class of the object. It should be 0 (not yet set).
* This SetType is not allowed when an object is already set.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (obj->algClass != 0)
break;
/* The associated info should be a NULL pointer.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info != (Pointer)0)
break;
libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
/* Allocate enough space for a CipherCtx and an IBEPubEncCtx.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = sizeof (VoltCipherClassCtx) + sizeof (VoltBFType1IBECtx);
#if VOLT_ALIGNMENT != 1
/* If the alignment is 1, there's no need to pad. If not, compute
* the pad length.
*/
VOLT_COMPUTE_ALIGN_PAD (VOLT_ALIGNMENT, sizeof (VoltCipherClassCtx), pad)
bufferSize += pad;
#endif
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
/* Locate the pointers.
*/
cipherCtx = (VoltCipherClassCtx *)buffer;
offset = sizeof (VoltCipherClassCtx);
#if VOLT_ALIGNMENT != 1
offset += pad;
#endif
ibeCtx = (VoltBFType1IBECtx *)(buffer + offset);
/* Populate the object and contexts.
*/
obj->algClass = VOLT_CLASS_CIPHER;
obj->classCtx = (Pointer)cipherCtx;
obj->ClassCtxDestroy = BFType1IBEClassCtxDestroy;
cipherCtx->GetOutputSize = BFType1IBEGetOutputSize;
cipherCtx->EncryptInit = BFType1IBEPubEncryptInit;
cipherCtx->EncryptUpdate = BFType1IBEPubEncryptUpdate;
cipherCtx->WrapKey = VoltDefaultWrapSymKey;
cipherCtx->DecryptInit = BFType1IBEPriDecryptInit;
cipherCtx->DecryptUpdate = BFType1IBEPriDecryptUpdate;
cipherCtx->UnwrapKey = VoltDefaultUnwrapSymKey;
cipherCtx->localCipherCtx = (Pointer)ibeCtx;
cipherCtx->setState = VOLT_CIPHER_SET_STATE_COMPLETE;
status = 0;
} while (0);
/* If everything worked, return 0.
*/
if (status == 0)
return (0);
/* If something went wrong, destroy anything we created and indicate
* that this object is not usable.
*/
obj->state = VOLT_STATE_ERROR;
VOLT_LOG_ERROR (
obj->voltObject.libraryCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
"VtAlgorithmImplBFType1IBE", (char *)0)
return (status);
}
int VtAlgorithmImplBBType1IBE (
VtAlgorithmObject *object,
Pointer info,
unsigned int flag
)
{
int status;
#if VOLT_ALIGNMENT != 1
unsigned int pad;
#endif
unsigned int bufferSize, offset;
VoltAlgorithmObject *obj = (VoltAlgorithmObject *)(*object);
VoltLibCtx *libCtx;
unsigned char *buffer = (unsigned char *)0;
VoltCipherClassCtx *cipherCtx;
VoltBBType1IBECtx *ibeCtx;
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Check the flag, it should be VOLT_ALG_SET_TYPE_FLAG.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_ALG_SET_TYPE_FLAG)
break;
/* Check the class of the object. It should be 0 (not yet set).
* This SetType is not allowed when an object is already set.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (obj->algClass != 0)
break;
/* The associated info should be a NULL pointer.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info != (Pointer)0)
break;
libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
/* Allocate enough space for a CipherCtx and an VoltBBType1IBECtx.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize = sizeof (VoltCipherClassCtx) + sizeof (VoltBBType1IBECtx);
#if VOLT_ALIGNMENT != 1
/* If the alignment is 1, there's no need to pad. If not, compute
* the pad length.
*/
VOLT_COMPUTE_ALIGN_PAD (VOLT_ALIGNMENT, sizeof (VoltCipherClassCtx), pad)
bufferSize += pad;
#endif
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
/* Locate the pointers.
*/
cipherCtx = (VoltCipherClassCtx *)buffer;
offset = sizeof (VoltCipherClassCtx);
#if VOLT_ALIGNMENT != 1
offset += pad;
#endif
ibeCtx = (VoltBBType1IBECtx *)(buffer + offset);
/* Populate the object and contexts.
*/
obj->algClass = VOLT_CLASS_CIPHER;
obj->classCtx = (Pointer)cipherCtx;
obj->ClassCtxDestroy = BBType1IBEClassCtxDestroy;
cipherCtx->GetOutputSize = BBType1IBEGetOutputSize;
cipherCtx->EncryptInit = BBType1IBEPubEncryptInit;
cipherCtx->EncryptUpdate = BBType1IBEPubEncryptUpdate;
cipherCtx->WrapKey = VoltDefaultWrapSymKey;
cipherCtx->DecryptInit = BBType1IBEPriDecryptInit;
cipherCtx->DecryptUpdate = BBType1IBEPriDecryptUpdate;
cipherCtx->UnwrapKey = VoltDefaultUnwrapSymKey;
cipherCtx->localCipherCtx = (Pointer)ibeCtx;
cipherCtx->setState = VOLT_CIPHER_SET_STATE_COMPLETE;
status = 0;
} while (0);
/* If everything worked, return 0.
*/
if (status == 0)
return (0);
/* If something went wrong, destroy anything we created and indicate
* that this object is not usable.
*/
obj->state = VOLT_STATE_ERROR;
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, *object, status, 0, VT_ERROR_TYPE_PRIMARY,
(char *)0, "VtAlgorithmImplBBType1IBE", fnctLine, (char *)0)
return (status);
}
void BFType1IBEClassCtxDestroy (
Pointer algObj,
Pointer ctx
)
{
VoltAlgorithmObject *obj = (VoltAlgorithmObject *)algObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltCipherClassCtx *cipherCtx = (VoltCipherClassCtx *)ctx;
VoltBFType1IBECtx *ibeCtx;
/* Is there anything to destroy?
*/
if (ctx == (Pointer)0)
return;
ibeCtx = (VoltBFType1IBECtx *)(cipherCtx->localCipherCtx);
VoltReleaseBfCtx (libCtx, &(ibeCtx->bfCtx));
if (ibeCtx->encodedId.data != (unsigned char *)0)
Z2Free (ibeCtx->encodedId.data);
if (ibeCtx->privateValue.data != (unsigned char *)0)
Z2Free (ibeCtx->privateValue.data);
if (ibeCtx->processedData.data != (unsigned char *)0)
Z2Free (ibeCtx->processedData.data);
Z2Free (ctx);
}
void BBType1IBEClassCtxDestroy (
Pointer algObj,
Pointer ctx
)
{
VoltAlgorithmObject *obj = (VoltAlgorithmObject *)algObj;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltCipherClassCtx *cipherCtx = (VoltCipherClassCtx *)ctx;
VoltBBType1IBECtx *ibeCtx;
/* Is there anything to destroy?
*/
if (ctx == (Pointer)0)
return;
ibeCtx = (VoltBBType1IBECtx *)(cipherCtx->localCipherCtx);
VoltReleaseBbCtx (libCtx, &(ibeCtx->bbCtx));
if (ibeCtx->encodedId.data != (unsigned char *)0)
Z2Free (ibeCtx->encodedId.data);
if (ibeCtx->privateValue.data != (unsigned char *)0)
Z2Free (ibeCtx->privateValue.data);
if (ibeCtx->processedData.data != (unsigned char *)0)
Z2Free (ibeCtx->processedData.data);
Z2Free (ctx);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號