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

📄 opensslbntype.c

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

int VtMpIntImplOpenSSL (
   VtMpIntCtx *mpCtx,
   Pointer info,
   unsigned int flag
   )
{
  int status;
  VoltMpIntCtx *ctx = (VoltMpIntCtx *)(*mpCtx);
  BN_CTX *bnCtx = (BN_CTX *)0;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Check the flag, it should be VOLT_MP_CTX_SET_TYPE_FLAG.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_TYPE;
    if (flag != VOLT_MP_CTX_SET_TYPE_FLAG)
      break;

    /* The associated info should be NULL pointer.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_ASSOCIATED_INFO;
    if (info != (Pointer)0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    bnCtx = BN_CTX_new ();
    if (bnCtx == (BN_CTX *)0)
      break;

    /* Set the fields of the mpCtx.
     */
    ctx->MpIntImpl = VtMpIntImplOpenSSL;
    ctx->CreateMpInt = OpenSSLBnWrapCreateMpInt;
    ctx->DestroyMpInt = OpenSSLBnWrapDestroyMpInt;
    ctx->OctetStringToMpInt = OpenSSLBnWrapOctetStringToMpInt;
    ctx->IntToMpInt = OpenSSLBnWrapIntToMpInt;
    ctx->MpIntToMpInt = OpenSSLBnWrapMpIntToMpInt;
    ctx->MpIntToOctetString = OpenSSLBnWrapMpIntToOctetString;
    ctx->MpIntToInt = OpenSSLBnWrapMpIntToInt;
    ctx->Compare = OpenSSLBnWrapCompare;
    ctx->EvenOddZeroPositiveNegative =
      OpenSSLBnWrapEvenOddZeroPositiveNegative;
    ctx->GetBitLength = OpenSSLBnWrapGetBitLength;
    ctx->SetBit = OpenSSLBnWrapSetBit;
    ctx->GetBit = OpenSSLBnWrapGetBit;
    ctx->ShiftLeftBits = OpenSSLBnWrapShiftLeftBits;
    ctx->ShiftRightBits = OpenSSLBnWrapShiftRightBits;
    ctx->Add = OpenSSLBnWrapAdd;
    ctx->Subtract = OpenSSLBnWrapSubtract;
    ctx->Multiply = OpenSSLBnWrapMultiply;
    ctx->Square = OpenSSLBnWrapSquare;
    ctx->Divide = OpenSSLBnWrapDivide;
    ctx->ModReduce = OpenSSLBnWrapModReduce;
    ctx->ModInvert = OpenSSLBnWrapModInvert;
    ctx->ModExp = OpenSSLBnWrapModExp;
    /* OpenSSL does not supply a CRT function, use the Volt version.
     */
    ctx->ModExpCRT = VoltModExpCRT;
    /* This implementation has no GeneratePrime.
     */

    ctx->localCtx = (Pointer)bnCtx;
    ctx->LocalCtxDestroy = OpenSSLBnWrapLocalCtxDestroy;

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_COMPARE (
    status, ctx->voltObject.libraryCtx, status, VT_ERROR_TYPE_PRIMARY,
    fnctLine, "VtMpIntImplOpenSSL", (char *)0)

  return (status);
}

void OpenSSLBnWrapLocalCtxDestroy (
   Pointer obj,
   Pointer ctx
   )
{
  /* Anything to destroy?
   */
  if ( (obj == (Pointer)0) || (ctx == (Pointer)0) )
    return;

  BN_CTX_free ((BN_CTX *)ctx);
}

⌨️ 快捷键说明

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