📄 ibepubkey.c
字号:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
*/
#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "keyobj.h"
#include "ibe.h"
#include "errorctx.h"
/* Gets the key data out of a key object.
*
* @param object The object from which the data is to be extracted.
* @param getInfo The address where the function will deposit the
* pointer to the info.
* @param algorithm Either VOLT_KEY_ALG_IBE_TYPE_1 or
* VOLT_KEY_ALG_BB_TYPE_1, indicating which type of key is to be
* retrieved.
* @return an int, 0 if the function completed successfully or a
* non-zero error code.
*/
static int VOLT_CALLING_CONV VoltKeyGetIBEPublic VOLT_PROTO_LIST ((
VtKeyObject object,
Pointer *getInfo,
unsigned int algorithm
));
int VtKeyParamBFType1IBEPublic (
VtKeyObject object,
Pointer info,
unsigned int flag
)
{
int status;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltKeyParamIBEPublic (
object, info, flag, VOLT_KEY_ALG_IBE_TYPE_1);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, object, status, 0, 0,
(char *)0, "VtKeyParamBFType1IBEPublic", fnctLine, (char *)0)
return (status);
}
int VtKeyParamBBType1IBEPublic (
VtKeyObject object,
Pointer info,
unsigned int flag
)
{
int status;
VOLT_DECLARE_FNCT_LINE (fnctLine)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltKeyParamIBEPublic (
object, info, flag, VOLT_KEY_ALG_BB_TYPE_1);
VOLT_LOG_ERROR_INFO_COMPARE (
status, 0, object, status, 0, 0,
(char *)0, "VtKeyParamBBType1IBEPublic", fnctLine, (char *)0)
return (status);
}
int VoltKeyParamIBEPublic (
VtKeyObject object,
Pointer info,
unsigned int flag,
unsigned int algorithm
)
{
int status;
unsigned int bufferSize, paramAlg;
VoltKeyObject *obj = (VoltKeyObject *)object;
VtBFType1IBEPubKeyInfo *inputInfo = (VtBFType1IBEPubKeyInfo *)info;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltParameterObject *pObj;
VoltBFType1IBEPubKeyData *localData;
unsigned char *buffer = (unsigned char *)0;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
paramAlg = VOLT_PARAM_ALG_BB_TYPE_1;
if (algorithm == VOLT_KEY_ALG_IBE_TYPE_1)
paramAlg = VOLT_PARAM_ALG_IBE_TYPE_1;
do
{
if (flag == VOLT_KEY_GET_TYPE_FLAG)
{
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltKeyGetIBEPublic (object, (Pointer *)info, algorithm);
break;
}
/* Check the flag, it should be VOLT_KEY_SET_TYPE_FLAG.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_TYPE;
if (flag != VOLT_KEY_SET_TYPE_FLAG)
break;
/* Check the keyType in the object, it should be 0.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_SET;
if (obj->keyType != 0)
break;
/* The associated info should be a pointer to a
* VtBFType1IBEPubKeyInfo struct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (info == (Pointer)0)
break;
/* Valid param object?
*/
VOLT_SET_FNCT_LINE (fnctLine)
pObj = (VoltParameterObject *)(inputInfo->ibeParams);
if (pObj == (VoltParameterObject *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (VOLT_OBJECT_TYPE_NOT_EQUAL (pObj, VOLT_OBJECT_TYPE_PARAMETER))
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (pObj->paramData == (Pointer)0)
break;
if ((pObj->paramType & VOLT_PARAM_TYPE_MASK_ALG) != paramAlg)
break;
if ((pObj->paramType & VOLT_PARAM_TYPE_PARAMS) == 0)
break;
if ((pObj->paramType & VOLT_PARAM_TYPE_CONTENTS) == 0)
break;
/* Create a VoltIBEPubKeyInfo struct.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
bufferSize =
sizeof (VoltBFType1IBEPubKeyData) + inputInfo->encodedId.len;
buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
if (buffer == (unsigned char *)0)
break;
Z2Memset (buffer, 0, bufferSize);
localData = (VoltBFType1IBEPubKeyData *)buffer;
localData->encodedId.data = buffer + sizeof (VoltBFType1IBEPubKeyData);
/* Clone the parameter object.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VtCloneObject (
(Pointer)pObj, (Pointer *)&(localData->ibeParams));
if (status != 0)
break;
/* Copy the encoding into the local buffer.
*/
Z2Memcpy (
localData->encodedId.data, inputInfo->encodedId.data,
inputInfo->encodedId.len);
localData->encodedId.len = inputInfo->encodedId.len;
obj->keyType =
algorithm | VOLT_KEY_TYPE_PUBLIC | VOLT_KEY_TYPE_ENCRYPT |
VOLT_KEY_TYPE_DATA;
obj->keyData = (Pointer)localData;
obj->KeyDataDestroy = IBEPubKeyDataDestroy;
status = 0;
} while (0);
/* If everything worked, return 0.
*/
if (status == 0)
return (0);
/* If something went wrong, destroy anything we created.
*/
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR (
libCtx, status, errorType, fnctLine, "VoltKeyParamIBEPublic",
(char *)0)
return (status);
}
static int VoltKeyGetIBEPublic (
VtKeyObject object,
Pointer *getInfo,
unsigned int algorithm
)
{
int status;
VoltKeyObject *obj = (VoltKeyObject *)object;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
/* Is there data?
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if (obj->keyData == (Pointer)0)
break;
/* Make sure the key data is appropriate.
* We can get the public key data out of a private key object as
* well.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
if ((obj->keyType & VOLT_KEY_TYPE_MASK_ASYM_ALG) != algorithm)
break;
if ( ((obj->keyType & VOLT_KEY_TYPE_PRIVATE) == 0) &&
((obj->keyType & VOLT_KEY_TYPE_PUBLIC) == 0) )
break;
/* Is the key data the actual data? If so, we're done.
*/
status = 0;
*getInfo = obj->keyData;
if ((obj->keyType & VOLT_KEY_TYPE_MASK_DATA) == VOLT_KEY_TYPE_DATA)
break;
/* The data is not available, does the object have a GetData
* function?
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_GET_INFO_UNAVAILABLE;
*getInfo = (Pointer)0;
if (obj->GetKeyData == (VGetKeyData)0)
break;
/* Call the Get function.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = obj->GetKeyData ((VtKeyObject)obj, getInfo);
} while (0);
VOLT_LOG_ERROR_COMPARE (
status, libCtx, status, errorType, fnctLine,
"VoltKeyGetIBEPublic", (char *)0)
return (status);
}
void IBEPubKeyDataDestroy (
Pointer obj,
Pointer ctx
)
{
VoltObject *voltObj = (VoltObject *)obj;
VoltLibCtx *libCtx;
VoltBFType1IBEPubKeyData *localData = (VoltBFType1IBEPubKeyData *)ctx;
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
VtDestroyParameterObject (&(localData->ibeParams));
Z2Free (localData);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -