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

📄 ibeenctype.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
字号:
/* Copyright 2003-2004, 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);
}

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);
}

⌨️ 快捷键说明

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