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

📄 codersize.c

📁 voltage 公司提供的一个开发Ibe的工具包
💻 C
字号:
/* Copyright 2003-2005, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "securemail.h"
#include "base64.h"

int VoltCopyGetEncodeDecodeSize (
   VtAlgorithmObject coder,
   VtRandomObject random,
   unsigned int flagEncodeDecode,
   unsigned char *dataToProcess,
   unsigned int dataToProcessLen,
   unsigned int *processedDataLen
   )
{
  *processedDataLen = dataToProcessLen;
  return (VT_ERROR_BUFFER_TOO_SMALL);
}

int VoltBase64GetEncodeDecodeSize (
   VtAlgorithmObject coder,
   VtRandomObject random,
   unsigned int flagEncodeDecode,
   unsigned char *dataToProcess,
   unsigned int dataToProcessLen,
   unsigned int *processedDataLen
   )
{
  int status;
  unsigned int totalLen, blockCount, extra, padLen;
  VoltAlgorithmObject *obj = (VoltAlgorithmObject *)coder;
  VoltEncodeClassCtx *encodeCtx = (VoltEncodeClassCtx *)(obj->classCtx);
  VoltBase64Ctx *base64Ctx = (VoltBase64Ctx *)(encodeCtx->localEncodeCtx);

  status = VT_ERROR_BUFFER_TOO_SMALL;
  switch (flagEncodeDecode)
  {
    default:
      status = VT_ERROR_INVALID_CALL_ORDER;
      break;

    case VOLT_CALLER_ENCODE_UPDATE:
      /* For every binary block of input, there will be one base64
       * block.
       */
      totalLen = dataToProcessLen + encodeCtx->unprocessedDataLen;
      blockCount = totalLen / encodeCtx->plainBlockSize;
      *processedDataLen = blockCount * encodeCtx->codedBlockSize;
      break;

    case VOLT_CALLER_ENCODE_FINAL:
      /* For every binary block of input, there will be one base64
       * block.
       */
      totalLen = dataToProcessLen + encodeCtx->unprocessedDataLen;
      blockCount = totalLen / encodeCtx->plainBlockSize;
      *processedDataLen = blockCount * encodeCtx->codedBlockSize;

      /* For any extra left over, we'll "pad" to a multiple of three
       * and the final output will be 4 bytes for every three.
       * Then we'll add the required number of "=" characters.
       * We'll also need the line feed at the end.
       */
      extra = totalLen - (blockCount * encodeCtx->plainBlockSize);
      if (extra == 0)
        break;

      padLen = extra % 3;
      if (padLen != 0)
        padLen = 3 - padLen;
      extra += padLen;
      extra = (extra / 3) * 4;
      (*processedDataLen) += (extra + base64Ctx->newLineLen);
      break;

    case VOLT_CALLER_DECODE_UPDATE:
      /* For every 4 bytes of input, there are 3 bytes of output.
       * Actually, there are new line characters that should not be
       * considered part of the total length, however, we're not going
       * to search for them, so we'll use 3/4 * dataToProcessLen. This
       * will produce a number that may be too large.
       */
      totalLen = dataToProcessLen + base64Ctx->converterLen;
      *processedDataLen = (totalLen / 4) * 3;
      break;

    case VOLT_CALLER_DECODE_FINAL:
      /* For every 4 bytes of input, there are 3 bytes of output.
       * Actually, there are new line characters that should not be
       * considered part of the total length, however, we're not going
       * to search for them, so we'll use 3/4 * dataToProcessLen. This
       * will produce a number that may be too large.
       * For Final, the total length of valid characters must be a
       * multiple of 4. If not, there will be an error (if checking).
       * But we don't know yet how many of the characters are invalid,
       * so we'll use the same formula.
       * If there are any leftovers, we may want to deal with them, so
       * find a "padded" length (the + 3).
       */
      totalLen = dataToProcessLen + base64Ctx->converterLen;
      *processedDataLen = ((totalLen + 3) / 4) * 3;
  }

  return (status);
}

⌨️ 快捷键说明

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