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

📄 saread.c

📁 IBE是一种非对称密码技术
💻 C
📖 第 1 页 / 共 5 页
字号:
        &readCtx->mBufferTypeInfo, &readCtx->mInputStream);
      if (status != 0)
        break;
      VT_ASSERT(readCtx->mInputStream != (VtStreamObject)0);
      readCtx->mDestroyInputStream = 1;
    }
  }
  while (0);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
     fnctLine,"VoltSecureArchiveReadInit", (unsigned char*)0)
    
  return status;
}

static int VoltSecureArchiveReadUpdate(
   VtSecureArchiveObject secureArchiveObj,
   unsigned char *input,
   unsigned int inputLen,
   unsigned int *bytesRead,
   unsigned char *output,
   unsigned int bufferSize,
   unsigned int *outputLen
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureArchiveReadLocalCtx* readCtx;
  VtStreamSize readSize;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)

  VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  libCtx = secureArchiveObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);

  if (bytesRead != (unsigned int*)0)
    *bytesRead = 0;
  if (outputLen != (unsigned int*)0)
    *outputLen = 0;
  
  do
  {
    /* If the current entry type is such that we're expecting output, then
     * (at least for this impl) there can't be any more input data, and there
     * must be an output buffer into which we'll put the data.
     */
    if ((readCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX) ||
      (readCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE) ||
      (readCtx->mCurrentEntryType == VT_SECURE_ARCHIVE_CURRENT_ENTRY_INSECURE))
    {
      if ((input != (unsigned char*)0) || (inputLen > 0))
      {
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_INVALID_CALL_ORDER;
        break;
      }
      
      if (outputLen == (unsigned int*)0)
      {
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NULL_ARG;
        break;
      }
    }
    
    switch (readCtx->mCurrentEntryType)
    {
      case VT_SECURE_ARCHIVE_CURRENT_ENTRY_NONE:
      
        /* VT_SECURE_ARCHIVE_CURRENT_ENTRY_NONE is the initial current
         * entry type for the secure archive object. The first thing the
         * caller must do is set the input data for the secure archive.
         * This can be done by either setting the input stream explicitly
         * using the input stream param, or by reading in the data with
         * a series of update calls. If this is being called with the
         * current entry not having been specified, then we assume the
         * caller is trying to stream in the input data, so it's an error
         * if there's no input specified. Presumably, this is because the
         * caller has begun to try to output some entry data without
         * specifying a current entry, which is why we return the invalid
         * entry error.
         */
        if (input == (unsigned char*)0)
        {
          VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VT_ERROR_INVALID_SECURE_ARCHIVE_ENTRY;
          break;
        }
        
        VT_ASSERT(readCtx->mInputStream != (VtStreamObject)0);
        
        /* Write the input data out to the input stream */
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtStreamWrite(readCtx->mInputStream, input, inputLen);
        if (status != 0)
          break;
          
        *bytesRead = inputLen;
        
        break;
      
      case VT_SECURE_ARCHIVE_CURRENT_ENTRY_INDEX:
        
        if (readCtx->mIndexDataStream == (VtStreamObject)0)
        {
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VoltSecureArchiveDecryptIndex(secureArchiveObj);
          if (status != 0)
            break;
          
          VT_ASSERT(readCtx->mIndexDataStream != (VtStreamObject)0);
        }
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtStreamRead(readCtx->mIndexDataStream, output,
          bufferSize, &readSize);
        if (status != 0)
          break;
          
        *outputLen = readSize;
          
        break;
        
      case VT_SECURE_ARCHIVE_CURRENT_ENTRY_SECURE:
        
        if (readCtx->mOutputStream == (VtStreamObject)0)
        {
          VOLT_SET_FNCT_LINE(fnctLine)
          status = VoltSecureArchiveDecryptSecureEntry(secureArchiveObj);
          if (status != 0)
            break;
          
          VT_ASSERT(readCtx->mOutputStream != (VtStreamObject)0);
        }
        
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtStreamRead(readCtx->mOutputStream, output,
          bufferSize, &readSize);
        if (status != 0)
          break;
        
        *outputLen = readSize;
        
        break;
        
      case VT_SECURE_ARCHIVE_CURRENT_ENTRY_INSECURE:
      
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VtArchiveReadUpdate(readCtx->mArchive,
          (const unsigned char*)0, 0, output, bufferSize,
          outputLen);
        if ((status == 0) && (*outputLen == 0))
          status = VT_ERROR_END_OF_STREAM;
        break;
        
      default:
      
        VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_INVALID_SECURE_ARCHIVE_ENTRY;
        break;
    }
  }
  while (0);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
     fnctLine,"VoltSecureArchiveReadUpdate", (unsigned char*)0)
    
  return status;
}

static int VoltSecureArchiveReadFinal(
   VtSecureArchiveObject secureArchiveObj
)
{
  /* Doesn't need to do anything currently */
  return 0;
}

static int VoltSecureArchiveVerify(
   VtSecureArchiveObject secureArchiveObj,
   VtPolicyCtx policyCtx,
   VtStorageCtx storageCtx,
   VtTransportCtx transportCtx,
   VtCertVerifyCtx certVerifyCtx,
   Pointer verifyCtxInfo,
   VtVerifyFailureList vfyFailList,
   unsigned int *verifyResult
)
{
  int status = 0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VoltSecureArchiveReadLocalCtx* readCtx;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)

  VT_ASSERT(secureArchiveObj != (VoltSecureArchiveObject*)0);
  
  VOLT_SET_ERROR_TYPE(errorType, 0)
  
  libCtx = secureArchiveObj->voltObject.libraryCtx;
  VT_ASSERT(libCtx != (VtLibCtx)0);
  readCtx = (VoltSecureArchiveReadLocalCtx*) secureArchiveObj->localCtx;
  VT_ASSERT(readCtx != (VoltSecureArchiveReadLocalCtx*)0);

  do
  {
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtPkcs7VerifyAll(readCtx->mSignedData, policyCtx,
      storageCtx, transportCtx, certVerifyCtx, verifyCtxInfo,
      vfyFailList, verifyResult);
  }
  while (0);
  
  VOLT_LOG_ERROR_COMPARE(status, libCtx, status, errorType,
     fnctLine, "VoltSecureArchiveVerify", (unsigned char*)0)
    
  return status;
}

int VtSecureArchiveImplRead(
   VtSecureArchiveObject* obj,
   Pointer associatedInfo,
   unsigned int flags
)
{
  int status = 0;  
  VoltSecureArchiveObject* secureArchiveObj;  
  VoltSecureArchiveReadLocalCtx* readCtx = (VoltSecureArchiveReadLocalCtx*)0;
  VtLibCtx libCtx = (VtLibCtx)0;
  VtReadSecureArchiveInfo* readInfo = (VtReadSecureArchiveInfo*)associatedInfo;
  VtDerCoder** coders = (VtDerCoder**)0;
  unsigned int coderCount = 0;
  VtIdentitySchemaDecode** decoders = (VtIdentitySchemaDecode**)0;
  unsigned int decoderCount = 0;
  VtDERCoderArray* coderArray;
  VtSchemaDecodeArray* decoderArray;
  VtMpIntCtx mpIntCtx = (VtMpIntCtx)0;
  unsigned int i;
  VOLT_DECLARE_FNCT_LINE(fnctLine)
  VOLT_DECLARE_ERROR_TYPE(errorType)
  
  VT_ASSERT(obj != (VtSecureArchiveObject*)0);
  VT_ASSERT(*obj != (VtSecureArchiveObject)0);
  
  do
  {
    VOLT_SET_ERROR_TYPE(errorType, VT_ERROR_TYPE_PRIMARY)

    if ((obj == (VtSecureArchiveObject*)0) ||
        (*obj == (VtSecureArchiveObject)0))
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_NULL_ARG;
      break;
    }
    
    secureArchiveObj = (VoltSecureArchiveObject*)(*obj);
    libCtx = secureArchiveObj->voltObject.libraryCtx;
    VT_ASSERT(libCtx != (VtLibCtx)0);
    
    if (flags != VOLT_SECURE_ARCHIVE_SET_TYPE_FLAG)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
	    status = VT_ERROR_INVALID_TYPE;
	    break;
    }
    
    readCtx = (VoltSecureArchiveReadLocalCtx*)
      Z3Malloc(sizeof(VoltSecureArchiveReadLocalCtx));
    if (readCtx == (VoltSecureArchiveReadLocalCtx*)0)
    {
      VOLT_SET_FNCT_LINE(fnctLine)
      status = VT_ERROR_MEMORY;
      break;
    }
    
    Z2Memset(readCtx, 0, sizeof(VoltSecureArchiveReadLocalCtx));
    
    if (readInfo != (VtReadSecureArchiveInfo*)0)
    {
      coders = readInfo->derCoders;
      coderCount = readInfo->derCoderCount;
      decoders = readInfo->decoders;
      decoderCount = readInfo->decoderCount;
      mpIntCtx = readInfo->mpCtx;
	    if ((mpIntCtx != (VtMpIntCtx)0) &&
	        VOLT_OBJECT_TYPE_NOT_EQUAL(mpIntCtx, VOLT_OBJECT_TYPE_MP_INT_CTX))
	    {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_INVALID_MP_INT_CTX;
		    break;
		  }
    }
    
    if ((coders == (VtDerCoder**)0) || (coderCount == 0))
    {
      coderArray = (VtDERCoderArray*) VoltGetLibCtxInfo(libCtx,
        VOLT_LIB_CTX_INFO_TYPE_DER_CODERS);

      if (coderArray == (VtDERCoderArray *)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NO_DER_CODERS;
        break;
      }
      coders = coderArray->derCoders;
      coderCount = coderArray->derCoderCount;
    }
    
    if ((decoders == (VtIdentitySchemaDecode**)0) || (decoderCount == 0))
    {
      decoderArray = (VtSchemaDecodeArray*) VoltGetLibCtxInfo(libCtx,
        VOLT_LIB_CTX_INFO_TYPE_SCHEMA_DECODES);

      if (decoderArray == (VtSchemaDecodeArray *)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NO_SCHEMA_DECODERS;
        break;
      }
      
      decoders = decoderArray->decoders;
      decoderCount = decoderArray->decoderCount;
    }
    
    if (mpIntCtx == (VtMpIntCtx)0)
    {
      mpIntCtx = (VtMpIntCtx) VoltGetLibCtxInfo(libCtx,
         VOLT_LIB_CTX_INFO_TYPE_MP_CTX);

      if (mpIntCtx == (VtMpIntCtx)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_NO_MATH_LIBRARY;
        break;
      }
    }

    if (coderCount > 0)
    {
      readCtx->mCoders = (VtDerCoder**)
        Z3Malloc(coderCount * sizeof(VtDerCoder*));
      if (readCtx->mCoders == (VtDerCoder**)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_MEMORY;
        break;
      }
      for (i = 0; i < coderCount; i++)
        readCtx->mCoders[i] = coders[i];
        
      readCtx->mCoderCount = coderCount;
    }
    
    if (decoderCount > 0)
    {
      readCtx->mDecoders = (VtIdentitySchemaDecode**)
        Z3Malloc(decoderCount * sizeof(VtIdentitySchemaDecode*));
      if (readCtx->mDecoders == (VtIdentitySchemaDecode**)0)
      {
        VOLT_SET_FNCT_LINE(fnctLine)
        status = VT_ERROR_MEMORY;
        break;
      }
      for (i = 0; i < decoderCount; i++)
        readCtx->mDecoders[i] = decoders[i];
        
      readCtx->mDecoderCount = decoderCount;
    }
    
    VOLT_SET_FNCT_LINE(fnctLine)
    status = VtCloneObject((Pointer)mpIntCtx, (Pointer*)&readCtx->mMpIntCtx);
    if (status != 0)
      break;

    VOLT_SET_ERROR_TYPE(errorType, 0)

    readCtx->mBufferTypeInfo.bufferType = VT_BUFFER_TYPE_MEMORY;
    readCtx->mCurrentEntryType = VT_SECURE_ARCHIVE_CURRENT_ENTRY_NONE;
    
    secureArchiveObj->localCtx = (Pointer) readCtx;
    secureArchiveObj->SetParam = VoltSecureArchiveReadSetParam;
    secureArchiveObj->GetParam = VoltSecureArchiveReadGetParam;
    secureArchiveObj->ReadInit = VoltSecureArchiveReadInit;
    secureArchiveObj->ReadUpdate = VoltSecureArchiveReadUpdate;
    secureArchiveObj->ReadFinal = VoltSecureArchiveReadFinal;
    secureArchiveObj->Verify = VoltSecureArchiveVerify;
    secureArchiveObj->LocalCtxDestroy = VoltSecureArchiveReadLocalCtxDestroy;
  }
  while(0);  

  if (status != 0)
  {
    VoltSecureArchiveReadLocalCtxDestroy((Pointer)secureArchiveObj, (Pointer)readCtx);
    
    VOLT_LOG_ERROR(libCtx, status, errorType,
      fnctLine, "VtSecureArchiveImplRead", (char *)0)
  }
    
  return status;
}

⌨️ 快捷键说明

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