⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bbparamtype.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 3 页
字号:
      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 = VoltBBGetYCoordFromX (
        libCtx, mpCtx, 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 = VoltBBGetXCoordFromY (
        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, "VoltBBCopyPoint", fnctLine, (char *)0)

  return (status);
}

static void FreePointData (
   VoltLibCtx *libCtx,
   VtBBType1IBEPoint *thePoint
   )
{
  if ( (libCtx == (VoltLibCtx *)0) || (thePoint == (VtBBType1IBEPoint *)0) )
    return;

  if (thePoint->xCoord.data != (unsigned char *)0)
    Z2Free (thePoint->xCoord.data);
  if (thePoint->yCoord.data != (unsigned char *)0)
    Z2Free (thePoint->yCoord.data);
  Z2Memset (thePoint, 0, sizeof (VtBBType1IBEPoint));
}

void BBType1IBEParamDataDestroy (
   Pointer paramObj,
   Pointer ctx
   )
{
  VoltParameterObject *obj;
  VoltLibCtx *libCtx;
  VoltBBType1IBEParams *theParams;

  /* Is there anything to destroy?
   */
  if ( (paramObj == (Pointer)0) || (ctx == (Pointer)0) )
    return;

  obj = (VoltParameterObject *)paramObj;
  libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
  theParams = (VoltBBType1IBEParams *)ctx;

  VoltReleaseBbCtx (libCtx, &(theParams->bbCtx));

  /* The master secrets, if present, were allocated as one buffer.
   */
  if (theParams->masterSecretAlpha.data != (unsigned char *)0)
    Z2Free (theParams->masterSecretAlpha.data);
  if (theParams->secretStruct != (Pointer)0)
    Z2Free (theParams->secretStruct);

  Z2Free (ctx);
}

int BBType1IBECopyParams (
   Pointer sourceParamObj,
   Pointer destParamObj
   )
{
  int status;
  unsigned int bufferSize;
  VoltParameterObject *src = (VoltParameterObject *)sourceParamObj;
  VoltParameterObject *dest = (VoltParameterObject *)destParamObj;
  VoltLibCtx *libCtx = (VoltLibCtx *)(src->voltObject.libraryCtx);
  VoltBBType1IBEParams *srcParams, *destParams;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    dest->paramType = src->paramType;
    dest->CopyParams = src->CopyParams;
    dest->GetParamData = src->GetParamData;
    dest->ParamDataDestroy = src->ParamDataDestroy;

    /* If there's no paramData, we're done.
     */
    if (src->paramData == (Pointer)0)
      break;

    /* Is the paramData data or a handle?
     * If a handle, we should not be in this code.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_GET;
    if ((src->paramType & VOLT_PARAM_TYPE_MASK_DATA) != VOLT_PARAM_TYPE_DATA)
      break;

    /* Just call the Set function to copy the data.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VoltSetBBParams (
      (VtParameterObject)dest, (VtBBType1IBEParamInfo *)(src->paramData));
    if (status != 0)
      break;

    /* If there are master secrets in the source, copy them. If not,
     * we're done.
     */
    srcParams = (VoltBBType1IBEParams *)(src->paramData);
    if (srcParams->masterSecretAlpha.data == (unsigned char *)0)
      break;

    destParams = (VoltBBType1IBEParams *)(dest->paramData);
    bufferSize =
      srcParams->masterSecretAlpha.len +
      srcParams->masterSecretBeta.len +
      srcParams->masterSecretGamma.len;
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    destParams->masterSecretAlpha.data = (unsigned char *)Z2Malloc (
      bufferSize, VOLT_MEMORY_SENSITIVE);
    if (destParams->masterSecretAlpha.data == (unsigned char *)0)
      break;

    Z2Memset (destParams->masterSecretAlpha.data, 0, bufferSize);

    /* Copy src to dest.
     */
    Z2Memcpy (
      destParams->masterSecretAlpha.data, srcParams->masterSecretAlpha.data,
      srcParams->masterSecretAlpha.len);
    destParams->masterSecretAlpha.len = srcParams->masterSecretAlpha.len;

    destParams->masterSecretBeta.data =
      destParams->masterSecretAlpha.data + destParams->masterSecretAlpha.len;
    Z2Memcpy (
      destParams->masterSecretBeta.data, srcParams->masterSecretBeta.data,
      srcParams->masterSecretBeta.len);
    destParams->masterSecretBeta.len = srcParams->masterSecretBeta.len;

    destParams->masterSecretGamma.data =
      destParams->masterSecretBeta.data + destParams->masterSecretBeta.len;
    Z2Memcpy (
      destParams->masterSecretGamma.data, srcParams->masterSecretGamma.data,
      srcParams->masterSecretGamma.len);
    destParams->masterSecretGamma.len = srcParams->masterSecretGamma.len;

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_INFO_COMPARE (
    status, 0, sourceParamObj, status, 0, errorType,
    (char *)0, "BBType1IBECopyParams", fnctLine, (char *)0)

  return (status);
}

int VoltBuildIBEParamsFromBbCtx (
   VoltLibCtx *libCtx,
   bb1_context_t *bbCtx,
   VtBBType1IBEParamInfo **theParams
   )
{
  int status;
  unsigned int primePLen, subprimeQLen, bufferSize, offset;
  unsigned char *buffer = (unsigned char *)0;
  VtBBType1IBEParamInfo *localParams;
  bb1_parameters_simple_t *bbPars = (bb1_parameters_simple_t *)0;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Get the data into an bbPars struct, this is clearer than the
     * bbCtx.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = bb1ParsNew (bbCtx, &bbPars);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = bb1ContextExportToIcPars (bbPars, bbCtx);
    if (status != 0)
      break;

    /* Get the primePLen and subprimeQLen.
     */
    primePLen = (unsigned int)zSizeInBase (bbPars->p, 2);
    primePLen = (primePLen + 7) / 8;
    subprimeQLen = (unsigned int)zSizeInBase (bbPars->order, 2);
    subprimeQLen = (subprimeQLen + 7) / 8;

    /* Make sure the lengths are correct.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_INPUT;
    if ((unsigned int)(bbPars->gSize) != (primePLen + 1))
      break;
    if ((unsigned int)(bbPars->g1Size) != (primePLen + 1))
      break;
    if ((unsigned int)(bbPars->g2Size) != (primePLen + 1))
      break;
    if ((unsigned int)(bbPars->g3Size) != (primePLen + 1))
      break;

    /* Now that we have the prime and subprime lengths, we can determine
     * the total length. We need
     *   sizeof (VtBBType1IBEParamInfo)
     *    primeP (primePLen)
     *    subPrimeQ (subprimeQLen)
     *    basePointG (2 coordinates, 2 * primePLen)
     *    pubPointAlpha (2 coordinates, 2 * primePlen)
     *    pubPointBeta (2 coordinates, 2 * primePlen)
     *    pubPointGamma (2 coordinates, 2 * primePlen)
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    bufferSize =
      sizeof (VtBBType1IBEParamInfo) + (9 * primePLen) + subprimeQLen;
    buffer = (unsigned char *)Z2Malloc (bufferSize, 0);
    if (buffer == (unsigned char *)0)
      break;
    Z2Memset (buffer, 0, bufferSize);

    /* Locate the pointers.
     */
    localParams = (VtBBType1IBEParamInfo *)buffer;
    offset = sizeof (VtBBType1IBEParamInfo);
    localParams->primeP.data = buffer + offset;
    localParams->primeP.len = primePLen;
    offset += primePLen;
    localParams->subprimeQ.data = buffer + offset;
    localParams->subprimeQ.len = subprimeQLen;
    offset += subprimeQLen;
    localParams->basePointG.xCoord.data = buffer + offset;
    offset += primePLen;
    localParams->basePointG.yCoord.data = buffer + offset;
    offset += primePLen;
    localParams->pubPointAlpha.xCoord.data = buffer + offset;
    offset += primePLen;
    localParams->pubPointAlpha.yCoord.data = buffer + offset;
    offset += primePLen;
    localParams->pubPointBeta.xCoord.data = buffer + offset;
    offset += primePLen;
    localParams->pubPointBeta.yCoord.data = buffer + offset;
    offset += primePLen;
    localParams->pubPointGamma.xCoord.data = buffer + offset;
    offset += primePLen;
    localParams->pubPointGamma.yCoord.data = buffer + offset;

    /* Now get the values into the buffers.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = zRawEncode (
      (void *)(localParams->primeP.data), primePLen, bbPars->p);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = zRawEncode (
      (void *)(localParams->subprimeQ.data), subprimeQLen, bbPars->order);
    if (status != 0)
      break;

    Z2Memcpy (
      localParams->basePointG.xCoord.data, bbPars->g + 1,
      bbPars->gSize - 1);
    localParams->basePointG.xCoord.len =
      (unsigned int)(bbPars->gSize - 1);

    /* The bbPars g is actually only the x-coordinate. Call this
     * routine to get y.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = bfCalculatePointY (
      localParams->basePointG.yCoord.data, primePLen,
      &(localParams->basePointG.yCoord.len),
      bbPars->g, bbPars->gSize, bbCtx->bfCtx);
    if (status != 0)
      break;

    Z2Memcpy (
      localParams->pubPointAlpha.xCoord.data, bbPars->g1 + 1, primePLen);
    localParams->pubPointAlpha.xCoord.len =
      (unsigned int)(bbPars->g1Size - 1);

    /* The bbPars pub points are actually only the x-coordinate. Call
     * this routine to get y.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = bfCalculatePointY (
      localParams->pubPointAlpha.yCoord.data, primePLen,
      &(localParams->pubPointAlpha.yCoord.len),
      bbPars->g1, bbPars->g1Size, bbCtx->bfCtx);
    if (status != 0)
      break;

    Z2Memcpy (
      localParams->pubPointBeta.xCoord.data, bbPars->g2 + 1, primePLen);
    localParams->pubPointBeta.xCoord.len =
      (unsigned int)(bbPars->g2Size - 1);

    VOLT_SET_FNCT_LINE (fnctLine)
    status = bfCalculatePointY (
      localParams->pubPointBeta.yCoord.data, primePLen,
      &(localParams->pubPointBeta.yCoord.len),
      bbPars->g2, bbPars->g2Size, bbCtx->bfCtx);
    if (status != 0)
      break;

    Z2Memcpy (
      localParams->pubPointGamma.xCoord.data, bbPars->g3 + 1, primePLen);
    localParams->pubPointGamma.xCoord.len =
      (unsigned int)(bbPars->g3Size - 1);

    VOLT_SET_FNCT_LINE (fnctLine)
    status = bfCalculatePointY (
      localParams->pubPointGamma.yCoord.data, primePLen,
      &(localParams->pubPointGamma.yCoord.len),
      bbPars->g3, bbPars->g3Size, bbCtx->bfCtx);
    if (status != 0)
      break;

    /* Everything worked, return the address of the params.
     */
    *theParams = localParams;

  } while (0);

  if (bbPars != (bb1_parameters_simple_t *)0)
    bb1ParsDel (bbPars);

  /* If no error, we're done.
   */
  if (status == 0)
    return (0);

  /* If there was an error, free any memory we allocated.
   */
  if (buffer != (unsigned char *)0)
    Z2Free (buffer);

  VOLT_LOG_ERROR_INFO (
    libCtx, 0, status, 0, errorType,
    (char *)0, "BBType1IBECopyParams", fnctLine, (char *)0)

  return (status);
}

void VoltDemolishBBIBEParams (
   VoltLibCtx *libCtx,
   VtBBType1IBEParamInfo **theParams
   )
{
  /* Is there anything to demolish?
   */
  if (*theParams == (VtBBType1IBEParamInfo *)0)
    return;

  /* To build the struct, we allocated one block.
   */
  Z2Free (*theParams);
}

int VoltGetBbCtxFromIBEParams (
   VoltLibCtx *libCtx,
   VtMpIntCtx mpIntCtx,
   VtBBType1IBEParamInfo *paramInfo,
   unsigned int accelCount,
   unsigned char *accelG,
   unsigned char *accelG1,
   unsigned char *accelG3,
   bb1_context_t **bbCtx
   )
{
  int status, status2;
  int cacheLockAcquired = 0;
  unsigned int saveFlag, fake, primeLen, bufferSize, offset, refLen;
  unsigned char *refBuf = (unsigned char *)0;
  unsigned char *buffer = (unsigned char *)0;
  VoltMpIntCtx *mpCtx = (VoltMpIntCtx *)mpIntCtx;
  bb1_parameters_simple_t bbParams;
  bb1_context_t *newCtx = (bb1_context_t *)0;
  VoltIBECacheCtx *ibeCache = (VoltIBECacheCtx *)0;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  Z2Memset (&bbParams, 0, sizeof (bb1_parameters_simple_t));

  /* Initialize the saveFlag to 0. That means we should save the
   * created bbCtx in the cache. If any point's x coordinate is
   * missing, set saveFlag to nonzero, which means don't save the bbCtx
   * in the cache.
   */
  saveFlag = 0;

  do
  {
    /* If there's no param info, the caller just wanted a new bbCtx.
     */
    if (paramInfo != (VtBBType1IBEParamInfo *)0)
    {
      /* Get the IBE cache, if there is one.
       */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -