亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? gmpwrap.c

?? IBE是一種非對稱密碼技術
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */
#include "vibe.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "mpint.h"
#include "gmpwrap.h"
#include "gmp.h"
#include "errorctx.h"

int GMPWrapCreateMpInt (
   Pointer mpIntCtx,
   VoltMpInt **newInt
   )
{
  int status;
#if VOLT_ALIGNMENT != 1
  unsigned int pad;
#endif
  unsigned int bufferSize, offset;
  unsigned char *buffer = (unsigned char *)0;
  VoltMpIntCtx *mpCtx = (VoltMpIntCtx *)mpIntCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(mpCtx->voltObject.libraryCtx);
  VoltMpInt *mpInt;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* Allocate space for the VoltMpInt and mpz_t.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    bufferSize = sizeof (VoltMpInt) + sizeof (mpz_t);
#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 (VoltMpInt), pad)
    bufferSize += pad;
#endif
    buffer = (unsigned char *)Z2Malloc (bufferSize, VOLT_MEMORY_SENSITIVE);
    if (buffer == (unsigned char *)0)
      break;
    Z2Memset (buffer, 0, bufferSize);

    /* Position the pointers.
     */
    mpInt = (VoltMpInt *)buffer;
    offset = sizeof (VoltMpInt);
#if VOLT_ALIGNMENT != 1
    offset += pad;
#endif
    mpInt->mpInt = (Pointer)(buffer + offset);

    mpInt->mpCtx = (VtMpIntCtx)mpCtx;

    mpz_init ((mpz_ptr)(mpInt->mpInt));

    *newInt = (VoltMpInt *)mpInt;

    status = 0;

  } while (0);

  /* If successful, just return.
   */
  if (status == 0)
    return (0);

  /* If error, free memory.
   */
  if (buffer != (unsigned char *)0)
    Z2Free (buffer);

  VOLT_LOG_ERROR (
    libCtx, status, VT_ERROR_TYPE_PRIMARY, fnctLine,
    "GMPWrapCreateMpInt", (char *)0)

  return (status);
}

int GMPWrapDestroyMpInt (
   VoltMpInt **theInt
   )
{
  VoltMpIntCtx *mpCtx;
  VoltLibCtx *libCtx;

  /* Call the clear function for the mpz, then free up the MpInt's
   * memory.
   */
  if (theInt == (VoltMpInt **)0)
    return (0);
  if (*theInt == (VoltMpInt *)0)
    return (0);

  mpz_clear ((mpz_ptr)((*theInt)->mpInt));

  mpCtx = (VoltMpIntCtx *)((*theInt)->mpCtx);
  libCtx = (VoltLibCtx *)(mpCtx->voltObject.libraryCtx);

  Z2Free (*theInt);

  *theInt = (VoltMpInt *)0;

  return (0);
}

int GMPWrapOctetStringToMpInt (
   unsigned int sign,
   unsigned char *sourceOctetString,
   unsigned int sourceOctetStringLen,
   VoltMpInt *destInt
   )
{
  int status;
  unsigned int index, bitSize;
  mpz_ptr mpzTarget;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* If NULL, we can't log an error, no libCtx.
   */
  if (destInt == (VoltMpInt *)0)
    return (VT_ERROR_NULL_ARG);

  do
  {
    /* Check the arguments.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_NULL_ARG;
    if (sourceOctetString == (unsigned char *)0)
      break;
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_INPUT_LENGTH;
    if (sourceOctetStringLen == 0)
      break;

    /* GMP can set an MpInt only with unsigned ints or strings. We'll
     * use the unsigned int version. Set the initial value with an
     * unsigned int, then add in successive values.
     * The input Int may not have enough space allocated, so to avoid
     * repeated realloc's, set the value to 1, shift left by the required
     * amount, set back to 0 and start adding.
     */
    bitSize = sourceOctetStringLen << 3;
    mpzTarget = (mpz_ptr)(destInt->mpInt);
    mpz_set_ui (mpzTarget, 1);
    mpz_mul_2exp (mpzTarget, mpzTarget, bitSize);
    mpz_set_ui (mpzTarget, 0);

    /* For each byte in the octetString (except the low order byte),
     * add to the intermediate value, then multiply by 256 (a "shift
     * left" by 8). Don't do the last in this loop, because we just
     * want to add that one in, no shift.
     */
    for (index = 0; index < (sourceOctetStringLen - 1); ++index)
    {
      mpz_add_ui (
        mpzTarget, mpzTarget, (unsigned int)(sourceOctetString[index]));
      mpz_mul_2exp (mpzTarget, mpzTarget, 8);
    }
    mpz_add_ui (
      mpzTarget, mpzTarget, (unsigned int)(sourceOctetString[index]));

    /* We just added the number as a positive value. If sign is not
     * positive, negate.
     */
    if (sign != 0)
      mpz_neg (mpzTarget, mpzTarget);

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_COMPARE (
    status, destInt->mpCtx->voltObject.libraryCtx, status,
    VT_ERROR_TYPE_PRIMARY, fnctLine, "GMPWrapOctetStringToMpInt", (char *)0)

  return (status);
}

int GMPWrapIntToMpInt (
   int signCheck,
   int sourceValue,
   VoltMpInt *destInt
   )
{
  /* Check the arguments.
   * Can't log an error if NULL, no libCtx.
   */
  if (destInt == (VoltMpInt *)0)
    return (VT_ERROR_NULL_ARG);

  if (signCheck == 0)
  {
    mpz_set_ui ((mpz_ptr)(destInt->mpInt), sourceValue);
    return (0);
  }

  mpz_set_si ((mpz_ptr)(destInt->mpInt), sourceValue);

  return (0);
}

int GMPWrapMpIntToInt (
   VoltMpInt *sourceInt,
   int signCheck,
   int *destValue
   )
{
  int status;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* If NULL, we can't log an error, no libCtx.
   */
  if (sourceInt == (VoltMpInt *)0)
    return (VT_ERROR_NULL_ARG);

  do
  {
    /* Check the arguments.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_NULL_ARG;
    if (destValue == (int *)0)
      break;

    *destValue = 0;

    status = VT_ERROR_MP_INT_RANGE;

    /* If signCheck != 0, then return a signed integer.
     */
    if (signCheck != 0)
    {
      /* Check to see if the value will fit into a signed int.
       */
      VOLT_SET_FNCT_LINE (fnctLine)
      if (mpz_fits_sint_p ((mpz_ptr)(sourceInt->mpInt)) == 0)
        break;

      *destValue = mpz_get_si ((mpz_ptr)(sourceInt->mpInt));

      status = 0;
      break;
    }

    /* The caller wants to get the value as an unsigned int. Check to
     * see if the value will fit into an unsigned int.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    if (mpz_fits_uint_p ((mpz_ptr)(sourceInt->mpInt)) == 0)
      break;

    *destValue = (int)mpz_get_ui ((mpz_ptr)(sourceInt->mpInt));

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_COMPARE (
    status, sourceInt->mpCtx->voltObject.libraryCtx, status,
    VT_ERROR_TYPE_PRIMARY, fnctLine, "GMPWrapMpIntToInt", (char *)0)

  return (status);
}

int GMPWrapMpIntToMpInt (
   VoltMpInt *sourceInt,
   VoltMpInt *destInt
   )
{
  /* Check the arguments.
   * If NULL, can't log, no libCtx.
   * We could check for one NULL, the other not, but this is the kind
   * of error an app expects not to log.
   */
  if ( (sourceInt == (VoltMpInt *)0) || (destInt == (VoltMpInt *)0) )
    return (VT_ERROR_NULL_ARG);

  mpz_set ((mpz_ptr)(destInt->mpInt), (mpz_ptr)(sourceInt->mpInt));

  return (0);
}

int GMPWrapMpIntToOctetString (
   VoltMpInt *sourceInt,
   unsigned int *sign,
   unsigned char *destBuf,
   unsigned int bufferSize,
   unsigned int *destLen
   )
{
  int status, getSign;
  unsigned int octLen, wordCount, index, indexO, indexW, increment;
  mp_limb_t currWord;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* If NULL, we can't log an error, no libCtx.
   */
  if (sourceInt == (VoltMpInt *)0)
    return (VT_ERROR_NULL_ARG);

  do
  {
    /* Check the arguments.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_NULL_ARG;
    if ( (sign == (unsigned int *)0) || (destLen == (unsigned int *)0) )
      break;

    if (destBuf == (unsigned char *)0)
      bufferSize = 0;

    /* Get the sign, use octLen as a temp.
     */
    getSign = (unsigned int)mpz_sgn ((mpz_ptr)(sourceInt->mpInt));
    *sign = 1;
    if (getSign >= 0)
      *sign = 0;

    /* How big does the buffer need to be?
     */
    octLen = (unsigned int)mpz_sizeinbase ((mpz_ptr)(sourceInt->mpInt), 2);
    octLen = (octLen + 7) / 8;

    /* Is the buffer big enough?
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_BUFFER_TOO_SMALL;
    *destLen = octLen;
    if (bufferSize < octLen)
      break;

    /* Get each word from the mpz and shift and mask to get individual
     * octets.
     */
    wordCount = (unsigned int)mpz_size ((mpz_ptr)(sourceInt->mpInt));
    increment = sizeof (mp_limb_t);

    /* Start with the low order bytes/words.
     */
    indexO = octLen - 1;
    indexW = 1;

    /* For all but the most significant word, grab all the bytes out of
     * each word.
     */
    while (indexW < wordCount)
    {
      currWord = mpz_getlimbn ((mpz_ptr)(sourceInt->mpInt), indexW - 1);
      indexW++;
      for (index = 0; index < increment; ++index)
      {
        destBuf[indexO] = (unsigned char)(currWord & 0xff);
        currWord >>= 8;
        indexO--;
      }
    }

    /* The last word may not be an entire word.
     */
    index = indexO + 1;
    currWord = mpz_getlimbn ((mpz_ptr)(sourceInt->mpInt), indexW - 1);
    for (; index > 0; index--)
    {
      destBuf[indexO] = (unsigned char)(currWord & 0xff);
      currWord >>= 8;
      indexO--;
    }

    status = 0;

  } while (0);

  VOLT_LOG_ERROR_COMPARE (
    status, sourceInt->mpCtx->voltObject.libraryCtx, status,
    VT_ERROR_TYPE_PRIMARY, fnctLine, "GMPWrapMpIntToOctetString", (char *)0)

  return (status);
}

int GMPWrapCompare (
   VoltMpInt *leftInt,
   VoltMpInt *rightInt,
   int *result
   )
{
  int gmpResult;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* Check the arguments.
   * If NULL, can't log, no libCtx.
   * We could check for one NULL, the other not, but this is the kind
   * of error an app expects not to log.
   */
  if ( (leftInt == (VoltMpInt *)0) ||
       (rightInt == (VoltMpInt *)0) )
    return (VT_ERROR_NULL_ARG);

  VOLT_SET_FNCT_LINE (fnctLine)
  if (result != (int *)0)
  {
    gmpResult = mpz_cmp (
      (mpz_ptr)(leftInt->mpInt), (mpz_ptr)(rightInt->mpInt));
    *result = 0;
    if (gmpResult < 0)
      *result = -1;
    else if (gmpResult > 0)
      *result = 1;

    return (0);
  }

  VOLT_LOG_ERROR (
    leftInt->mpCtx->voltObject.libraryCtx, VT_ERROR_NULL_ARG,
    VT_ERROR_TYPE_PRIMARY, fnctLine, "GMPWrapCompare", (char *)0)

  return (VT_ERROR_NULL_ARG);
}

int GMPWrapEvenOddZeroPositiveNegative (
   VoltMpInt *theInt,
   int *result
   )
{
  int retVal, theSign;
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* Check the arguments.
   * If NULL, can't log, no libCtx.
   */
  if (theInt == (VoltMpInt *)0)
    return (VT_ERROR_NULL_ARG);

  VOLT_SET_FNCT_LINE (fnctLine)
  if (result != (int *)0)
  {
    /* mpz_sgn returns 0 if 0, 1 if positive, -1 if negative.
     */
    *result = 0;
    theSign = mpz_sgn ((mpz_ptr)(theInt->mpInt));
    if (theSign == 0)
      return (0);

    /* mpz_tstbit returns 0 or 1, depending on what the bit at the given
     * bit position is.
     */
    retVal = mpz_tstbit ((mpz_ptr)(theInt->mpInt), 0);
    if (retVal == 0)
      retVal = 2;
    if (theSign < 0)
      retVal = -retVal;

    *result = retVal;
    return (0);
  }

  VOLT_LOG_ERROR (
    theInt->mpCtx->voltObject.libraryCtx, VT_ERROR_NULL_ARG,
    VT_ERROR_TYPE_PRIMARY, fnctLine, "GMPWrapEvenOddZeroPositiveNegative",
    (char *)0)

  return (VT_ERROR_NULL_ARG);
}

int GMPWrapGetBitLength (
   VoltMpInt *theInt,
   unsigned int *bitLen
   )
{

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91精品国产综合久久国产大片| 精品一区二区三区av| 色欧美乱欧美15图片| 一级精品视频在线观看宜春院| 色婷婷激情久久| 日韩影院精彩在线| 欧美va在线播放| 国产不卡高清在线观看视频| 国产日本亚洲高清| 97精品国产露脸对白| 亚洲444eee在线观看| 欧美va亚洲va在线观看蝴蝶网| 激情图区综合网| 国产精品精品国产色婷婷| 91亚洲国产成人精品一区二三| 亚洲一卡二卡三卡四卡| 日韩美一区二区三区| 成人少妇影院yyyy| 亚洲不卡av一区二区三区| 精品日韩成人av| 99视频精品全部免费在线| 亚洲成人一二三| 国产欧美一区二区在线| 欧美亚洲国产bt| 国精品**一区二区三区在线蜜桃| 国产精品福利影院| 555夜色666亚洲国产免| 韩国三级在线一区| 一区二区三区精品在线| 2019国产精品| 欧美日本精品一区二区三区| 国产成人在线看| 日韩中文字幕麻豆| 国产精品久久久一本精品| 欧美精品自拍偷拍动漫精品| 播五月开心婷婷综合| 美腿丝袜亚洲一区| 一区二区三区日本| 久久久国产精华| 欧美日韩另类国产亚洲欧美一级| 国产成人激情av| 久久99国内精品| 一区二区在线观看视频| 久久久欧美精品sm网站 | 91福利精品视频| 国模无码大尺度一区二区三区| 亚洲一区成人在线| 亚洲视频精选在线| 国产欧美日韩精品a在线观看| 在线影院国内精品| av电影一区二区| 国产福利一区二区三区视频| 三级成人在线视频| 亚洲在线成人精品| 中文字幕一区二区不卡| 久久伊99综合婷婷久久伊| 欧美日韩国产首页| 91福利精品第一导航| av一区二区三区四区| 国产精品影音先锋| 精品系列免费在线观看| 秋霞国产午夜精品免费视频| 亚瑟在线精品视频| 亚洲一级二级三级| 亚洲综合免费观看高清完整版| 中文字幕一区二区三区蜜月| 国产日韩综合av| 久久久久久97三级| 欧美高清在线精品一区| 国产欧美精品一区aⅴ影院| 久久亚洲精华国产精华液| 欧美刺激午夜性久久久久久久| 7777精品伊人久久久大香线蕉经典版下载| 色综合中文字幕国产| 风流少妇一区二区| 国产精品一二三区| 成人丝袜高跟foot| 91免费看`日韩一区二区| 99久久久久久| 欧美性视频一区二区三区| 欧美在线free| 欧美午夜精品一区| 欧美一区二区三区视频在线观看| 欧美高清视频在线高清观看mv色露露十八| 欧美性猛交一区二区三区精品| 色噜噜久久综合| 欧美三级日韩三级国产三级| 欧美日韩亚洲另类| 欧美电视剧免费观看| 久久精品一区二区| 中文av字幕一区| 一区二区三区免费| 免费不卡在线观看| 国产aⅴ精品一区二区三区色成熟| 国产成人aaa| 一本色道久久综合狠狠躁的推荐 | 婷婷中文字幕一区三区| 日本系列欧美系列| 国产69精品久久777的优势| 99国产精品久久久久| 91成人免费在线视频| 欧美一级淫片007| 国产亚洲欧美中文| 亚洲乱码国产乱码精品精可以看| 亚洲国产综合色| 国产在线一区观看| 色先锋久久av资源部| 日韩一区二区免费在线观看| 国产精品麻豆网站| 亚洲18影院在线观看| 国产成人久久精品77777最新版本 国产成人鲁色资源国产91色综 | 国产精品国产三级国产普通话99 | 在线观看www91| 日韩精品专区在线影院重磅| 国产精品成人免费在线| 午夜精品久久久久久久99樱桃| 精品系列免费在线观看| 91麻豆免费观看| 日韩精品一区二区三区三区免费 | 日韩丝袜美女视频| 亚洲色图清纯唯美| 男女男精品网站| 91免费视频网| 26uuu国产电影一区二区| 亚洲视频中文字幕| 国产在线国偷精品产拍免费yy| 91社区在线播放| 亚洲精品一区二区在线观看| 伊人婷婷欧美激情| 成人天堂资源www在线| 欧美成人r级一区二区三区| 亚洲免费观看高清| 国产美女在线精品| 欧美剧情片在线观看| 亚洲欧洲三级电影| 国产一区二区福利视频| 在线成人免费观看| 亚洲精品第1页| 成人性生交大片免费看视频在线| 欧美日本精品一区二区三区| 亚洲人成人一区二区在线观看 | 欧美tickling网站挠脚心| 亚洲精品一二三四区| 国产精品一区二区三区乱码| 91精品啪在线观看国产60岁| 亚洲精品自拍动漫在线| 成人美女在线视频| xnxx国产精品| 久久99精品久久久久久久久久久久| 欧美日韩视频专区在线播放| 亚洲区小说区图片区qvod| 粉嫩蜜臀av国产精品网站| 精品久久久久久最新网址| 美女网站在线免费欧美精品| 欧美日本乱大交xxxxx| 亚洲国产精品久久人人爱| 在线亚洲一区二区| 亚洲人快播电影网| 色妹子一区二区| 亚洲美女视频在线观看| 91网站最新网址| 亚洲欧美日韩中文字幕一区二区三区 | 91精品1区2区| 成人免费一区二区三区在线观看| 国产高清精品网站| 国产日韩欧美a| 成人精品免费视频| 中文字幕一区av| 99久久综合精品| 中文字幕一区在线观看视频| 成人av资源站| 亚洲欧美aⅴ...| 欧美性欧美巨大黑白大战| 亚洲 欧美综合在线网络| 91精品久久久久久久91蜜桃| 美女尤物国产一区| 久久久不卡网国产精品二区| 国产精品亚洲а∨天堂免在线| 欧美经典三级视频一区二区三区| 丁香啪啪综合成人亚洲小说| 国产精品久久看| 欧美在线观看一区二区| 日本亚洲电影天堂| 国产亚洲欧美在线| 91看片淫黄大片一级| 亚洲一区二区三区三| 91麻豆精品久久久久蜜臀| 国内国产精品久久| 国产精品欧美经典| 91九色最新地址| 六月丁香综合在线视频| 国产欧美精品一区二区色综合朱莉 | 精品免费国产二区三区| 成人午夜视频在线观看| 亚洲一区二区欧美日韩 | 国产日韩一级二级三级| 色综合久久88色综合天天免费| 亚洲国产成人av好男人在线观看| 日韩欧美一区在线观看| 成人aaaa免费全部观看|