📄 ibeprikey.c
字号:
newPrivatePoint.yCoord.data, newPrivatePoint.yCoord.len);
localData->bfKeyInfo.privatePoint.yCoord.len =
newPrivatePoint.yCoord.len;
}
else
{
localData->bbKeyInfo.privatePointD0.isInfinity =
bbInfo->privatePointD0.isInfinity;
Z2Memcpy (
localData->bbKeyInfo.privatePointD0.xCoord.data,
newPrivatePointD0.xCoord.data, newPrivatePointD0.xCoord.len);
localData->bbKeyInfo.privatePointD0.xCoord.len =
newPrivatePointD0.xCoord.len;
Z2Memcpy (
localData->bbKeyInfo.privatePointD0.yCoord.data,
newPrivatePointD0.yCoord.data, newPrivatePointD0.yCoord.len);
localData->bbKeyInfo.privatePointD0.yCoord.len =
newPrivatePointD0.yCoord.len;
localData->bbKeyInfo.privatePointD1.isInfinity =
bbInfo->privatePointD1.isInfinity;
Z2Memcpy (
localData->bbKeyInfo.privatePointD1.xCoord.data,
newPrivatePointD1.xCoord.data, newPrivatePointD1.xCoord.len);
localData->bbKeyInfo.privatePointD1.xCoord.len =
newPrivatePointD1.xCoord.len;
Z2Memcpy (
localData->bbKeyInfo.privatePointD1.yCoord.data,
newPrivatePointD1.yCoord.data, newPrivatePointD1.yCoord.len);
localData->bbKeyInfo.privatePointD1.yCoord.len =
newPrivatePointD1.yCoord.len;
}
obj->keyType =
algorithm | VOLT_KEY_TYPE_PRIVATE |
VOLT_KEY_TYPE_ENCRYPT | VOLT_KEY_TYPE_DATA;
obj->keyData = (Pointer)localData;
obj->KeyDataDestroy = IBEPriKeyDataDestroy;
status = 0;
} while (0);
if (newPrivatePoint.xCoord.data != (unsigned char *)0)
Z2Free (newPrivatePoint.xCoord.data);
if (newPrivatePoint.yCoord.data != (unsigned char *)0)
Z2Free (newPrivatePoint.yCoord.data);
if (newPrivatePointD0.xCoord.data != (unsigned char *)0)
Z2Free (newPrivatePointD0.xCoord.data);
if (newPrivatePointD0.yCoord.data != (unsigned char *)0)
Z2Free (newPrivatePointD0.yCoord.data);
if (newPrivatePointD1.xCoord.data != (unsigned char *)0)
Z2Free (newPrivatePointD1.xCoord.data);
if (newPrivatePointD1.yCoord.data != (unsigned char *)0)
Z2Free (newPrivatePointD1.yCoord.data);
/* If everything worked, return 0.
*/
if (status == 0)
return (0);
/* If something went wrong, destroy anything we created.
*/
VtDestroyParameterObject (¶mClone);
if (buffer != (unsigned char *)0)
Z2Free (buffer);
VOLT_LOG_ERROR (
libCtx, status, errorType, fnctLine, "VtKeyParamIBEPrivate", (char *)0)
return (status);
}
static int VoltKeyGetIBEPrivate (
VtKeyObject object,
Pointer *getInfo,
unsigned int algorithm
)
{
int status;
VoltKeyObject *obj = (VoltKeyObject *)object;
VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
VoltIBEPriKeyData *priKeyData;
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.
*/
VOLT_SET_FNCT_LINE (fnctLine)
if ((obj->keyType & VOLT_KEY_TYPE_MASK_ASYM_ALG) != algorithm)
break;
if ((obj->keyType & VOLT_KEY_TYPE_PRIVATE) == 0)
break;
/* Is the key data the actual data? If so, we're done.
*/
status = 0;
if ((obj->keyType & VOLT_KEY_TYPE_MASK_DATA) == VOLT_KEY_TYPE_DATA)
{
priKeyData = (VoltIBEPriKeyData *)(obj->keyData);
*getInfo = (Pointer)&(priKeyData->bbKeyInfo);
if (algorithm == VOLT_KEY_ALG_IBE_TYPE_1)
*getInfo = (Pointer)&(priKeyData->bfKeyInfo);
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,
"VoltKeyGetIBEPrivate", (char *)0)
return (status);
}
int VoltBFCopyPoint (
VoltLibCtx *libCtx,
VoltMpIntCtx *mpCtx,
VtBFType1IBEParamInfo *paramInfo,
VtBFType1IBEPoint *oldPoint,
VtBFType1IBEPoint *newPoint
)
{
int status;
unsigned int primeLen, theXLen;
unsigned char *theX;
VOLT_DECLARE_ERROR_TYPE (errorType)
VOLT_DECLARE_FNCT_LINE (fnctLine)
do
{
primeLen = paramInfo->curve.primeP.len;
/* Because the x-coordinate might contain an extra byte, copy the
* pointer to a variable we can adjust.
*/
theX = oldPoint->xCoord.data;
theXLen = oldPoint->xCoord.len;
/* This function rejects infinity.
*/
VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (oldPoint->isInfinity != 0)
break;
/* Allocate space to hold the computed or copied x and y.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_MEMORY;
newPoint->yCoord.data = (unsigned char *)Z2Malloc (
primeLen, VOLT_MEMORY_SENSITIVE);
if (newPoint->yCoord.data == (unsigned char *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
newPoint->xCoord.data = (unsigned char *)Z2Malloc (
primeLen, VOLT_MEMORY_SENSITIVE);
if (newPoint->xCoord.data == (unsigned char *)0)
break;
/* If there is no y-coordinate, compute it.
*/
if (oldPoint->yCoord.data == (unsigned char *)0)
{
/* We can't compute y without the x. And it must be in the
* appropriate format.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (theX == (unsigned char *)0)
break;
VOLT_SET_FNCT_LINE (fnctLine)
if (theXLen > (primeLen + 1))
break;
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetYCoordFromX (
libCtx, mpCtx, (bf_context_t *)0, paramInfo, theX, theXLen,
newPoint->yCoord.data, primeLen, &(newPoint->yCoord.len));
if (status != 0)
break;
/* At this point, we know that the x-coordinate is one byte too
* long, we need to copy everything after the first byte.
*/
theX++;
theXLen--;
}
else
{
/* The y-coordinate is given, just copy it.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (oldPoint->yCoord.len > primeLen)
break;
Z2Memcpy (
newPoint->yCoord.data, oldPoint->yCoord.data, oldPoint->yCoord.len);
newPoint->yCoord.len = oldPoint->yCoord.len;
}
/* If there is no x-coordinate, compute it.
*/
if (theX == (unsigned char *)0)
{
/* If we got this far, then the y-coordinate was not NULL. If it
* had been NULL, and the x-coordinate was NULL, then there would
* have been an error.
*/
VOLT_SET_ERROR_TYPE (errorType, 0)
VOLT_SET_FNCT_LINE (fnctLine)
status = VoltGetXCoordFromY (
libCtx, mpCtx, paramInfo, oldPoint->yCoord.data, oldPoint->yCoord.len,
newPoint->xCoord.data, primeLen, &(newPoint->xCoord.len));
if (status != 0)
break;
}
else
{
/* The x-coordinate is given, just copy it.
*/
VOLT_SET_FNCT_LINE (fnctLine)
status = VT_ERROR_INVALID_ASSOCIATED_INFO;
if (theXLen > primeLen)
break;
Z2Memcpy (newPoint->xCoord.data, theX, theXLen);
newPoint->xCoord.len = theXLen;
}
status = 0;
} while (0);
VOLT_LOG_ERROR_INFO_COMPARE (
status, libCtx, 0, status, 0, errorType,
(char *)0, "VoltBFCopyPoint", fnctLine, (char *)0)
return (status);
}
void IBEPriKeyDataDestroy (
Pointer obj,
Pointer ctx
)
{
VoltObject *voltObj = (VoltObject *)obj;
VoltLibCtx *libCtx;
VoltIBEPriKeyData *localData = (VoltIBEPriKeyData *)ctx;
if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
return;
libCtx = (VoltLibCtx *)(voltObj->libraryCtx);
VtDestroyParameterObject (&(localData->bfKeyInfo.ibeParams));
Z2Free (localData);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -