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

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

?? dsapgimpl.c

?? IBE是一種非對稱密碼技術
?? C
字號:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */

#include "vibecrypto.h"
#include "environment.h"
#include "base.h"
#include "libctx.h"
#include "paramobj.h"
#include "dsa.h"
#include "mpint.h"
#include "prime.h"
#include "surrender.h"
#include "errorctx.h"

int DSAGenerateParameters (
   VtParameterObject paramObj,
   VtRandomObject random
   )
{
  int status;
  unsigned int seedLen, counter, callNumber;
  VoltParameterObject *obj = (VoltParameterObject *)paramObj;
  VoltDsaParamGenCtx *dsaParamGenCtx =
    (VoltDsaParamGenCtx *)(obj->localGenerateCtx);
  VtRandomObject randomToUse;
  VoltMpIntCtx *mpCtx = obj->mpCtx;
  VoltLibCtx *libCtx = (VoltLibCtx *)(obj->voltObject.libraryCtx);
  VoltMpInt *primeP = (VoltMpInt *)0;
  VoltMpInt *subprimeQ = (VoltMpInt *)0;
  VoltMpInt *baseG = (VoltMpInt *)0;
  VoltMpInt *hVal = (VoltMpInt *)0;
  VoltSurrenderCtx *surrCtx = (VoltSurrenderCtx *)0;
  unsigned char SEED[20];
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  do
  {
    /* If the object already contains parameters, error.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_PARAM_OBJ;
    if (obj->paramData != (Pointer)0)
      break;

    /* If there's a surrender ctx, call the Surrender function.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_GET_OBJECT_SURR_CTX (surrCtx, obj);
    VOLT_CALL_SURRENDER (surrCtx, VT_SURRENDER_FNCT_DSA_PARAM_GEN, 0, 1)

    /* If there's no random object, get one from the libCtx.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_NO_RANDOM_OBJECT;
    randomToUse = random;
    if (random == (VtRandomObject)0)
    {
      randomToUse = (VtRandomObject)VoltGetLibCtxInfo (
        (VtLibCtx)libCtx, VOLT_LIB_CTX_INFO_TYPE_RANDOM);

      if (randomToUse == (VtRandomObject)0)
        break;
    }

    /* Make sure the random object is valid.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_RANDOM_OBJ;
    if (VOLT_OBJECT_TYPE_NOT_EQUAL (randomToUse, VOLT_OBJECT_TYPE_RANDOM))
      break;

    /* Create the MPInt's.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &primeP);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &subprimeQ);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &baseG);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &hVal);
    if (status != 0)
      break;

    /* General purpose PQG gen to share with DH.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    callNumber = 1;
    status = VoltGeneratePQGFips186 (
      mpCtx, surrCtx, VT_SURRENDER_FNCT_DSA_PARAM_GEN, &callNumber,
      dsaParamGenCtx->primeSizeBits, 160, randomToUse,
      primeP, subprimeQ, baseG, hVal, SEED, &seedLen, &counter);
    if (status != 0)
      break;

    /* If that succeeded, set the object with the values.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = AddDSAParametersMpInt (
      obj, primeP, subprimeQ, baseG, hVal, SEED, seedLen, counter);
    if (status != 0)
      break;

    /* If there's a surrender ctx, call it for the last time.
     */
    VOLT_CALL_SURRENDER (surrCtx, VT_SURRENDER_FNCT_DSA_PARAM_GEN, 0, 0)

  } while (0);

  mpCtx->DestroyMpInt (&hVal);
  Z2Memset (SEED, 0, sizeof (SEED));

  /* If successful, we're done.
   */
  if (status == 0)
    return (0);

  /* If error, clean up some things.
   */
  if (mpCtx != (VoltMpIntCtx *)0)
  {
    mpCtx->DestroyMpInt (&primeP);
    mpCtx->DestroyMpInt (&subprimeQ);
    mpCtx->DestroyMpInt (&baseG);
  }

  VOLT_LOG_ERROR (
    (VtLibCtx)libCtx, status, errorType, fnctLine,
    "DSAGenerateParameters", (char *)0)

  return (status);
}

int VoltGeneratePQGFips186 (
   VoltMpIntCtx *mpCtx,
   VoltSurrenderCtx *surrCtx,
   unsigned int surrFlag,
   unsigned int *callNumber,
   unsigned int primeSizeBits,
   unsigned int subprimeSizeBits,
   VtRandomObject random,
   VoltMpInt *primeP,
   VoltMpInt *subprimeQ,
   VoltMpInt *baseG,
   VoltMpInt *hVal,
   unsigned char *SEED,
   unsigned int *seedLen,
   unsigned int *count
   )
{
  int status;
  unsigned int bufSize, counter, offset, kVal, nVal, totalLen, digestLen;
  unsigned int bufOffset, bitMask, bitSet, isPrime, msbit, callNum;
  unsigned char *buffer = (unsigned char *)0;
  unsigned char *seedCopy, *digest;
  VoltLibCtx *libCtx = (VoltLibCtx *)(mpCtx->voltObject.libraryCtx);
  VtAlgorithmObject sha1 = (VtAlgorithmObject)0;
  VoltMpInt *remainder = (VoltMpInt *)0;
  VoltMpInt *expo = (VoltMpInt *)0;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  callNum = 1;
  if (callNumber != (unsigned int *)0)
    callNum = *callNumber;

  do
  {
    /* For now, the toolkit supports only 1024-bit DSA prime p and
     * 160-bit subprime q.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_PARAM_LENGTH;
    if ( (primeSizeBits != 1024) || (subprimeSizeBits != 160) )
      break;

    /* We'll need this later on.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VtCreateAlgorithmObject (
      (VtLibCtx)libCtx, VtAlgorithmImplSHA1, (Pointer)0, &sha1);
    if (status != 0)
      break;

    /* We'll also need some masking values to make sure the appropriate
     * high order bits are set or not set depending on the prime size.
     */
    bitSet = primeSizeBits % 8;
    if (bitSet == 0)
      bitSet = 8;
    bitMask = 0xff >> (8 - bitSet);
    /* Make sure the msbit is set. Create a value to OR with the first
     * byte that will set the msbit.
     */
    bitSet = 1 << (bitSet - 1);

    /* FIPS specifies L - 1 = n*160 + b, where L is the bit length of
     * the primeP.
     */
    nVal = primeSizeBits / subprimeSizeBits;

    /* For this implementation, the seedLen is the number of bytes
     * needed to hold subprimeSizeBits.
     */
    *seedLen = (subprimeSizeBits + 7) / 8;

    /* Create the mpInt's we'll need.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &remainder);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &expo);
    if (status != 0)
      break;

    /* Use baseG as a temp to subtract 1 later on.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->IntToMpInt (0, 1, baseG);
    if (status != 0)
      break;

    /* After we find the subprime, we'll need a buffer to hold the
     * primeP starting point. While we're at it, allocate space for
     * a copy of SEED that we'll be able to manipulate, and a digest
     * buffer.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    bufSize = (primeSizeBits + 7) / 8;
    buffer = (unsigned char *)Z2Malloc (
      bufSize + *seedLen + 20, VOLT_MEMORY_SENSITIVE);
    if (buffer == (unsigned char *)0)
      break;

    seedCopy = buffer + bufSize;
    digest = seedCopy + *seedLen;

    /* This is the beginning of the total loop: find subprimeQ and
     * primeP.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    do
    {
      callNum++;
      VOLT_CALL_SURRENDER (surrCtx, surrFlag, 0, callNum)

      /* Steps 1 - 5: Generate the subprime. (See the comments in
       * VoltGeneratePrimeFips for more on steps 1 - 5.
       */

      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltGeneratePrimeFips (
        subprimeSizeBits, random, SEED, seedLen, subprimeQ);
      if (status != 0)
        break;

      /* Step 6: counter = 0, offset = 2
       */
      counter = 0;
      offset = 2;

      /* This is the beginning of the inner loop: find primeP based on
       * the given subprimeQ.
       */
      do
      {
        callNum++;
        VOLT_CALL_SURRENDER (surrCtx, surrFlag, 0, callNum)

        /* Step 7: Build the primeP starting point by digesting SEED along
         * with the offset and a count as many times as necessary to
         * generate the appropriate number of bytes.
         */
        Z2Memcpy (seedCopy, SEED, *seedLen);
        totalLen = bufSize;
        kVal = 0;
        bufOffset = bufSize;

        VoltAddValueToBuffer (seedCopy, *seedLen, offset - 1); 
        do
        {
          /* Compute SEED + offset + kVal.
           */
          VoltAddValueToBuffer (seedCopy, *seedLen, 1); 
          kVal++;

          /* Digest this value.
           */
          VOLT_SET_FNCT_LINE (fnctLine)
          status = VtDigestInit (sha1);
          if (status != 0)
            break;

          VOLT_SET_FNCT_LINE (fnctLine)
          status = VtDigestFinal (
            sha1, seedCopy, *seedLen, digest, 20, &digestLen);
          if (status != 0)
            break;

          if (digestLen > totalLen)
            digestLen = totalLen;

          /* "Prepend" the current digest. This is the part of step 8
           * that builds W.
           */
          bufOffset -= digestLen;
          totalLen  -= digestLen;
          Z2Memcpy (buffer + bufOffset, digest + (20 - digestLen), digestLen);

        } while (totalLen > 0);
        if (status != 0)
          break;

        /* Finish step 8, compute X.
         */

        /* The FIPS technique actually specifies that W is a value of
         * length primeSizeBits - 1, so we need to clear the most
         * significant bit of the buffer to get the appropriate W. But
         * then we're going to add that bit in to get X, which is
         * W + (2 ^ (primeSizeBits - 1)). So at this point, just make
         * sure the most significant bit is set.
         */
        buffer[0] &= (unsigned char)bitMask;
        buffer[0] |= (unsigned char)bitSet;

        /* Step 9: c = X mod 2q, p = X - (c - 1)
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->OctetStringToMpInt (0, buffer, bufSize, primeP);
        if (status != 0)
          break;

        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->Add (subprimeQ, subprimeQ, expo);
        if (status != 0)
          break;

        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->ModReduce (primeP, expo, remainder);
        if (status != 0)
          break;

        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->Subtract (remainder, baseG, remainder);
        if (status != 0)
          break;

        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->Subtract (primeP, remainder, primeP);
        if (status != 0)
          break;

        /* Step 10: is primeP < 2 ^ (primeSizeBits - 1).
         * In other words, is the most significant bit still set?
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->GetBit (primeP, primeSizeBits - 1, &msbit);
        if (status == VT_ERROR_MP_INT_RANGE)
          status = 0;
        if (status != 0)
          break;

        /* Continuing Step 10, if the bit is set, move on to step 11.
         */
        if (msbit != 0)
        {
          /* Step 11: Is primeP actually prime?
           */
          VOLT_SET_FNCT_LINE (fnctLine)
          status = VoltRabinMillerTest (
            primeP, primeSizeBits, VOLT_RABIN_MILLER_COUNT_186_2,
            random, &isPrime);
          if (status != 0)
            break;

          /* Step 12: If the value is prime, move on to step 15.
           */
          if (isPrime != 0)
            break;
        }

        /* Step 13: The candidate "failed", either the msbit was not set
         * after the subtraction or it was not prime. Update counter and
         * offset.
         */
        counter++;
        offset += (nVal + 1);

        /* Step 14: If counter >= 4096, find a new subprimeQ.
         */
        if (counter >= 4096)
          break;

        /* Step 14: If counter < 4096, try another primeP.
         */

      } while (1);
      if (status != 0)
        break;

      /* At this point, we exited the inner loop because either we
       * found a prime or the counter hit 4096. If isPrime is not 0, we
       * found a prime.
       */
      if (isPrime != 0)
        break;

    } while (1);
    if (status != 0)
      break;

    /* If we reach this point, we have a subprimeQ and a primeP. The
     * SEED buffer contains the seed we used and counter is set to the
     * value we'll need to return at the address given by the count arg.
     */
    *count = counter;

    /* Now that we have p and q, compute g. It is
     *    g = h ^ ((p-1)/q)
     * where h is a random number.
     */

    /* Find (p-1) / q
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->MpIntToMpInt (primeP, expo);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->SetBit (expo, 0, 0);
    if (status != 0)
      break;

    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->Divide (expo, subprimeQ, expo, remainder);
    if (status != 0)
      break;

    /* Generate a random h < p.
     */
    do
    {
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VtGenerateRandomBytes (random, buffer, bufSize);
      if (status != 0)
        break;
      buffer[0] = 2; 

      VOLT_SET_FNCT_LINE (fnctLine)
      status = mpCtx->OctetStringToMpInt (0, buffer, /**/1/*/bufSize/*/, hVal); /* FIX */
      if (status != 0)
        break;

      /* compute g
       */
      VOLT_SET_FNCT_LINE (fnctLine)
      status = mpCtx->ModExp (hVal, expo, primeP, baseG);
      if (status != 0)
        break;

      /* Make sure baseG is not a small number.
       */
      VOLT_SET_FNCT_LINE (fnctLine)
      status = mpCtx->MpIntToInt (baseG, 1, &msbit);
      /* If status is 0, the g computed fit into an unsigned int,
       * that's small, try again with new random material.
       */
      if (status == 0)
        continue;

      /* If status is VT_ERROR_MP_INT_RANGE, the number is big enough, we're
       * done. Make sure status is 0.
       * If status was some other error, pass it along.
       */
      if (status == VT_ERROR_MP_INT_RANGE)
        status = 0;

      break;
    } while (1);

  } while (0);

  if (callNumber != (unsigned int *)0)
    *callNumber = callNum;
  if (buffer != (unsigned char *)0)
    Z2Free (buffer);

  mpCtx->DestroyMpInt (&remainder);
  mpCtx->DestroyMpInt (&expo);
  VtDestroyAlgorithmObject (&sha1);

  VOLT_LOG_ERROR_COMPARE (
    status, (VtLibCtx)libCtx, status, errorType, fnctLine,
    "VoltGeneratePQGFips186", (char *)0)

  return (status);
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
国产一区三区三区| 国产丝袜在线精品| 欧美成人综合网站| 国产亚洲污的网站| 亚洲另类色综合网站| 91福利视频久久久久| 欧美三区在线视频| 国产亚洲午夜高清国产拍精品 | 久久精品国产一区二区| 国产精品亚洲第一| 91精品福利在线| 日韩欧美一级二级三级久久久| 国产欧美一区二区精品仙草咪| 亚洲精品国产精华液| 久久www免费人成看片高清| 成人国产亚洲欧美成人综合网| 欧美性猛片aaaaaaa做受| 欧美videossexotv100| 中文字幕一区二区三区蜜月| 性久久久久久久| 成人中文字幕在线| 日韩一级免费观看| 亚洲男女毛片无遮挡| 开心九九激情九九欧美日韩精美视频电影 | 成人一区在线观看| 欧美日韩三级一区二区| 欧美激情中文字幕一区二区| 午夜精品久久久久| 91丨porny丨国产| 2020国产成人综合网| 亚洲一区中文在线| 成人午夜又粗又硬又大| 91精品国产高清一区二区三区蜜臀| 国产精品国产三级国产普通话蜜臀 | 国产美女视频一区| 欧美久久婷婷综合色| 18成人在线观看| 激情五月播播久久久精品| 欧美色窝79yyyycom| 国产精品久久久一本精品| 蜜桃视频一区二区三区在线观看 | 亚洲欧美偷拍三级| 国产精品一品二品| 欧美一区二区三区免费观看视频| 亚洲免费av高清| 高清国产一区二区| 精品国产污网站| 热久久免费视频| 欧美精品免费视频| 亚洲一区二区三区影院| 99re在线精品| 国产精品久久夜| 国产成人免费高清| 久久久99精品免费观看不卡| 蜜臀av一级做a爰片久久| 91豆麻精品91久久久久久| 国产精品人成在线观看免费 | 国产精品女同一区二区三区| 麻豆一区二区在线| 日韩一区二区在线观看视频播放| 亚洲一级二级在线| 色综合久久中文综合久久牛| 国产欧美视频一区二区| 国产一区二区三区在线观看免费视频 | 亚洲欧洲99久久| 成人午夜又粗又硬又大| 国产亚洲成aⅴ人片在线观看| 美女免费视频一区二区| 欧美一区二区国产| 日本最新不卡在线| 日韩一级精品视频在线观看| 欧美日韩国产另类一区| 亚洲一区中文日韩| 欧美日韩一区 二区 三区 久久精品| 亚洲色图视频免费播放| 91在线视频观看| 一区二区三区在线播| 日本道精品一区二区三区| 亚洲综合在线视频| 欧美午夜精品一区| 亚洲地区一二三色| 日韩一级在线观看| 国产福利精品导航| 日本一区二区成人| k8久久久一区二区三区| 亚洲视频免费在线观看| 欧美综合亚洲图片综合区| 首页综合国产亚洲丝袜| 精品乱码亚洲一区二区不卡| 国产裸体歌舞团一区二区| 日本一区二区三区在线不卡| a美女胸又www黄视频久久| 亚洲色图色小说| 欧美丰满少妇xxxbbb| 黄色资源网久久资源365| 国产欧美一区二区精品忘忧草| eeuss影院一区二区三区| 亚洲美女一区二区三区| 欧美日本精品一区二区三区| 麻豆国产欧美日韩综合精品二区| 欧美精品一区二区三区高清aⅴ| 国产成人精品一区二区三区四区 | av资源站一区| 亚洲美女区一区| 制服丝袜一区二区三区| 国精产品一区一区三区mba桃花 | 97se狠狠狠综合亚洲狠狠| 亚洲高清久久久| 久久这里都是精品| 99re这里只有精品视频首页| 亚洲成人激情综合网| 久久精品夜色噜噜亚洲a∨| 色偷偷一区二区三区| 免费精品99久久国产综合精品| 久久久午夜电影| 99这里只有精品| 日本怡春院一区二区| 国产精品久久久久久久浪潮网站| 欧美在线视频日韩| 狠狠色丁香婷综合久久| 亚洲男人的天堂av| 26uuu亚洲| 91成人在线观看喷潮| 国产老妇另类xxxxx| 亚洲国产一区视频| 久久久精品综合| 欧美日韩亚州综合| 成人91在线观看| 伦理电影国产精品| 亚洲激情图片小说视频| 久久久久久久久久久久电影| 欧美三级欧美一级| 成人夜色视频网站在线观看| 日韩成人一级大片| 亚洲婷婷在线视频| 久久久久国产精品麻豆| 欧美性做爰猛烈叫床潮| 福利一区福利二区| 日本视频中文字幕一区二区三区| 成人欧美一区二区三区1314| 欧美精品一区二区不卡| 欧美日韩aaa| 91色在线porny| 国产高清无密码一区二区三区| 天天综合网 天天综合色| 亚洲欧洲日产国产综合网| 26uuu成人网一区二区三区| 欧美日韩一区二区三区不卡| 成人91在线观看| 国产福利一区二区三区视频在线| 青青青爽久久午夜综合久久午夜| 亚洲精品久久久蜜桃| 日本一区二区视频在线| 精品国产露脸精彩对白| 91精品国产综合久久香蕉麻豆 | 亚洲国产乱码最新视频| 亚洲色图制服丝袜| 国产精品灌醉下药二区| 久久蜜桃av一区精品变态类天堂| 宅男噜噜噜66一区二区66| 在线精品国精品国产尤物884a| 成人一道本在线| 国产iv一区二区三区| 国产精品一区二区免费不卡| 久久国内精品视频| 另类小说图片综合网| 日本不卡的三区四区五区| 午夜欧美视频在线观看 | 91精品欧美久久久久久动漫| 欧美自拍偷拍一区| 色婷婷精品久久二区二区蜜臀av| 成人精品免费视频| 成人午夜激情影院| 成人精品小蝌蚪| 成人av电影在线观看| 成人高清在线视频| 99在线精品观看| www.亚洲色图.com| 94-欧美-setu| 色噜噜狠狠色综合欧洲selulu| 色狠狠一区二区| 色狠狠av一区二区三区| 一本久久a久久精品亚洲| 欧洲av在线精品| 欧美天堂一区二区三区| 欧美三级日韩三级| 欧美一级久久久久久久大片| 欧美一区二区三区啪啪| 日韩一区二区三区免费观看| 日韩欧美在线观看一区二区三区| 日韩欧美黄色影院| 精品91自产拍在线观看一区| 国产偷国产偷精品高清尤物| 国产精品网友自拍| 国产精品美女久久久久久久| 国产精品的网站| 亚洲一区欧美一区| 日本亚洲最大的色成网站www| 精品一区二区三区免费| 国产精品一区二区无线|