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

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關(guān)于我們
? 蟲蟲下載站

?? rabinmiller.c

?? IBE是一種非對稱密碼技術(shù)
?? C
?? 第 1 頁 / 共 2 頁
字號:
/* Copyright 2003-2006, Voltage Security, all rights reserved.
 */

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

/* Get a random value to use in the prime test. This function will
 * digest the primeCandidate along with the current contents of the
 * buffer to get some random bytes. This is used so that we don't need
 * to obtain random bytes from the PRNG. THis is necessary so we can
 * pass FIPS tests.
 * <p>The random values generated using this technique are to be used
 * only for getting random values used in testing primes. It must
 * generate new values each time.
 */
static int VOLT_CALLING_CONV GetRandomValue VOLT_PROTO_LIST ((
   VoltLibCtx *libCtx,
   VoltMpIntCtx *mpCtx,
   VoltMpInt *primeCandidate,
   unsigned char *buffer,
   unsigned int bufferLen
));

int VoltGeneratePrimeRabinMiller (
   unsigned int primeSizeBits,
   unsigned int leadingBits,
   unsigned int iterationCount,
   unsigned int oneRandom,
   VtRandomObject random,
   VoltSurrenderCtx *surrCtx,
   unsigned int surrFlag,
   unsigned int *callNumber,
   VoltMpInt *relativePrime,
   VoltMpInt *prime
   )
{
  int status, count;
  unsigned int bufferSize, index, sieveSize, isPrime, relPrime;
  unsigned int bitMask, bitSet0, bitSet1, increment, callNum;
  unsigned char *buffer = (unsigned char *)0;
  unsigned char *sieve = (unsigned char *)0;
  VoltMpIntCtx *mpCtx = (VoltMpIntCtx *)(prime->mpCtx);
  VoltLibCtx *libCtx = (VoltLibCtx *)(mpCtx->voltObject.libraryCtx);
  VoltMpInt *mpIncrement = (VoltMpInt *)0;
  VoltMpInt *temp1 = (VoltMpInt *)0;
  VoltMpInt *temp2 = (VoltMpInt *)0;
  unsigned int firstPrimes[100] = FIRST_100_ODD_PRIMES;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* This function accepts only 1 or 2 as valid leadingBits values.
   */
  if (leadingBits != 1)
    leadingBits = 2;

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

  do
  {
    /* Semi arbitrary limit on the size of the prime.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_INVALID_INPUT_LENGTH;
    if (primeSizeBits <= 32)
      break;

    /* Create a buffer of the appropriate size. We'll fill it with
     * random bytes and use that as a starting point.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    bufferSize = (primeSizeBits + 7) / 8;
    buffer = (unsigned char *)Z2Malloc (bufferSize, VOLT_MEMORY_SENSITIVE);
    if (buffer == (unsigned char *)0)
      break;

    /* Create a mask for the first byte. Depending on the bit length,
     * we may want to trim some bits off the top.
     * Then make sure the msbit is set. Create a value to OR with the
     * first byte that will set the msbit.
     * Finally, create a value to OR with the second byte. If the
     * caller wants the two most significant bits set, and the bit
     * length is such that the second most significant bit appears in
     * the second byte, set that bit.
     */
    bitSet0 = primeSizeBits % 8;
    bitSet1 = 0;
    if (bitSet0 == 0)
    {
      bitSet0 = 0x80;
      if (leadingBits == 2)
        bitSet0 = 0xc0;
      bitMask = 0xff;
    }
    else if (bitSet0 == 1)
    {
      bitSet0 = 1;
      if (leadingBits == 2)
        bitSet1 = 0x80;
      bitMask = 1;
    }
    else
    {
      bitMask = 0xff >> (8 - bitSet0);
      increment = bitSet0 - leadingBits;
      bitSet0 = 1;
      if (leadingBits == 2)
        bitSet0 = 3;
      bitSet0 = (bitSet0 << increment);
    }

    /* Create a sieve buffer.
     */
    VOLT_SET_FNCT_LINE (fnctLine)
    sieveSize = VOLT_SIEVE_SIZE;
    sieve = (unsigned char *)Z2Malloc (sieveSize, VOLT_MEMORY_SENSITIVE);
    if (sieve == (unsigned char *)0)
      break;

    /* We'll need the increment as an MpInt later on.
     */
    VOLT_SET_ERROR_TYPE (errorType, 0)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = mpCtx->CreateMpInt ((Pointer)mpCtx, &mpIncrement);
    if (status != 0)
      break;

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

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

    count = 0;
    isPrime = 1;
    relPrime = 1;
    do
    {
      callNum++;
      VOLT_CALL_SURRENDER (surrCtx, surrFlag, 0, callNum)

      if ( (count == 0) || (oneRandom == 0) )
      {
        /* Generate random bytes of the appropriate bit length.
         */
        VOLT_SET_ERROR_TYPE (errorType, 0)
        VOLT_SET_FNCT_LINE (fnctLine)
        status = VtGenerateRandomBytes (random, buffer, bufferSize);
        if (status != 0)
          break;

        /* Make sure the msbytes are set properly.
         */
        buffer[0] &= (unsigned char)bitMask;
        buffer[0] |= (unsigned char)bitSet0;
        buffer[1] |= (unsigned char)bitSet1;

        /* Set the lsbit to guarantee it is odd.
         */
        buffer[bufferSize - 1] |= 1;

        /* Set the MpInt to this value.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
          status = mpCtx->OctetStringToMpInt (0, buffer, bufferSize, prime);
        if (status != 0)
          break;
      }
      else
      {
        /* If this is not the first loop, and if the caller wants one
         * random, just add increment to get the next number after the
         * previously tested value.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->IntToMpInt (0, increment, mpIncrement);
        if (status != 0)
          break;

        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->Add (prime, mpIncrement, prime);
        if (status != 0)
          break;
      }

      /* Create the sieve for this candidate.
       */
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VoltSieveCandidate (
        prime, firstPrimes, 100, sieve, sieveSize);
      if (status != 0)
        break;

      /* Now run Rabin-Miller on numbers that fell through the sieve.
       */
      increment = 0;
      for (index = 0; index < sieveSize; ++index)
      {
        if (sieve[index] != 0)
        {
          increment += 2;
          continue;
        }

        /* Add increment to prime, this is the number we want to check.
         */
        VOLT_SET_FNCT_LINE (fnctLine)
        status = mpCtx->IntToMpInt (0, increment, mpIncrement);
        if (status != 0)
          break;

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

        if (relativePrime != (VoltMpInt *)0)
        {
          VOLT_SET_FNCT_LINE (fnctLine)
          status = VoltCheckRelativePrime (
            mpCtx, relativePrime, prime, temp1, temp2, &relPrime);
          if (status != 0)
            break;
        }

        /* If TRUE (non zero), the two numbers pass the relative
         * prime test, continue. If FALSE (zero) the two numbers fail
         * the test, move on.
         */
        if (relPrime != 0)
        {
          callNum++;
          VOLT_CALL_SURRENDER (surrCtx, surrFlag, 0, callNum)

          VOLT_SET_FNCT_LINE (fnctLine)
          status = VoltRabinMillerTest (
            prime, primeSizeBits, iterationCount, random, &isPrime);
          if (status != 0)
            break;

          /* If this came back prime, we're done.
           */
          if (isPrime != 0)
            break;
        }

        /* Reset increment.
         */
        increment = 2;
      }
      if (status != 0)
        break;

      if (isPrime != 0)
        break;

      /* The Rabin-Miller test indicates that none of the numbers that
       * fell through the sieve were prime, get a new random starting
       * point. But first, don't run this test forever.  Try up to 100
       * times. Actually, it will almost certainly pass eventually,
       * but put the count in there just to be safe.
       */
      VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
      VOLT_SET_FNCT_LINE (fnctLine)
      status = VT_ERROR_NO_PRIME_FOUND;
      count++;
      if (count > 100)
        break;

    } while (1);

  } while (0);

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

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

  if (sieve != (unsigned char *)0)
    Z2Free (sieve);

  mpCtx->DestroyMpInt (&mpIncrement);
  mpCtx->DestroyMpInt (&temp1);
  mpCtx->DestroyMpInt (&temp2);

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

  return (status);
}

/* The Rabin-Miller algorithm as described in FIPS 186-2.
 * Step 1. Set i = 1 and n >= 50.
 * Step 2. Set w = the integer to be tested,
 *             w = 1 + (2^a)m, where m is odd and 2^a is the largest
 *             power of 2 dividing w - 1.
 * Step 3. Generate a random integer b in the range 1 < b < w.
 * Step 4. Set j = 0 and z = b^m mod w.
 * Step 5. If j = 0 and z = 1, or if z = w - 1, go to step 9.
 * Step 6. If j > 0 and z = 1, go to step 8.
 * Step 7. j = j + 1. If j < a, set z = z^2 mod w and go to step 5.
 * Step 8. w is not prime. Stop.
 * Step 9. If i < n, set i = i + 1 and go to step 3. Otherwise,
 *         w is probably prime.
 */
int VoltRabinMillerTest (
   VoltMpInt *primeCandidate,
   unsigned int primeSizeBits,
   unsigned int iterationCount,
   VtRandomObject random,
   unsigned int *isPrime
   )
{
  int status, compareResult;
  unsigned int index, count, expo, bufferSize, value;
  unsigned char *buffer = (unsigned char *)0;
  VoltMpIntCtx *mpCtx = (VoltMpIntCtx *)(primeCandidate->mpCtx);
  VoltLibCtx *libCtx = (VoltLibCtx *)(mpCtx->voltObject.libraryCtx);
  VoltMpInt *candidateMinusOne = (VoltMpInt *)0;
  VoltMpInt *mVal = (VoltMpInt *)0;
  VoltMpInt *zVal = (VoltMpInt *)0;
  VoltMpInt *randVal = (VoltMpInt *)0;
  VOLT_DECLARE_ERROR_TYPE (errorType)
  VOLT_DECLARE_FNCT_LINE (fnctLine)

  /* Init the isPrime return to not prime, change it if it passes the
   * tests.
   */
  *isPrime = 0;

  do
  {
    /* Create a buffer big enough to hold the random values we'll
     * generate as part of the test.
     * The random values must be < the prime candidate. So set the
     * length in bytes to be primeSizeBits / 8. If the bit size is a
     * multiple of 8, the buffer size will be the same byte size as the
     * prime. If the bit size is not a multiple of 8, then the buffer
     * size will be one byte shorter than the byte size of the prime.
     * If the byte size is smaller, then the random value we generate
     * will be smaller. If the byte size is the same, then the random
     * value we generate might be bigger than the prime. If the byte
     * size is the same, that means the bit length is a multiple of 8
     * which means the most significant bit of the most significant
     * byte of the prime is set. So if we clear the most significant
     * bit of the most significant byte of the random value, it will be
     * < the prime.
     */
    VOLT_SET_ERROR_TYPE (errorType, VT_ERROR_TYPE_PRIMARY)
    VOLT_SET_FNCT_LINE (fnctLine)
    status = VT_ERROR_MEMORY;
    bufferSize = primeSizeBits / 8;
    buffer = (unsigned char *)Z2Malloc (bufferSize, VOLT_MEMORY_SENSITIVE);
    if (buffer == (unsigned char *)0)
      break;
    Z2Memset (buffer, 0, bufferSize);

?? 快捷鍵說明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
91福利在线观看| 国产一区二区三区免费| 欧美一区二区三区不卡| 久久精品国产免费| 国产精品久久久久7777按摩| 欧美少妇一区二区| 国产成人综合在线观看| 国产精品电影一区二区| 欧美电影一区二区三区| 国产风韵犹存在线视精品| 亚洲欧美日韩国产综合在线| 337p粉嫩大胆噜噜噜噜噜91av| 色婷婷激情综合| 国产99精品国产| 精品在线免费视频| 蜜桃精品在线观看| 亚洲第一搞黄网站| 日韩毛片一二三区| 中文字幕av一区二区三区| 精品盗摄一区二区三区| 69久久夜色精品国产69蝌蚪网| 91九色最新地址| 99精品国产91久久久久久 | 国产精品女上位| 精品国产乱子伦一区| 日韩小视频在线观看专区| 欧美日本一区二区三区| 色欧美片视频在线观看在线视频| 成人精品鲁一区一区二区| 国产一区激情在线| 精品一区二区三区av| 久久精品久久精品| 免费成人在线播放| 老司机一区二区| 激情都市一区二区| 国产一区二区日韩精品| 国产一区二区福利视频| 国产美女主播视频一区| 国产麻豆一精品一av一免费| 精品一区二区三区在线播放| 狠狠色丁香久久婷婷综合丁香| 青青草伊人久久| 久久精品国产网站| 国产中文一区二区三区| 国产精品1区2区| 粉嫩13p一区二区三区| 国产69精品久久99不卡| 国产69精品久久99不卡| 99久久综合国产精品| 91免费看片在线观看| 色妹子一区二区| 欧美日韩一区视频| 欧美精品在线观看一区二区| 91精品久久久久久久久99蜜臂 | 国产欧美一区二区三区在线老狼| 日韩精品一区二区三区在线| 精品国产乱码久久久久久闺蜜| 精品精品国产高清a毛片牛牛| 久久亚洲二区三区| 一区在线观看免费| 亚洲成在线观看| 麻豆91免费看| 成人精品一区二区三区四区| 色综合久久99| 日韩一级片在线播放| 久久久精品tv| 91麻豆国产香蕉久久精品| 欧美日韩午夜在线视频| 日韩三级在线免费观看| 亚洲国产成人午夜在线一区 | 国产精品国产三级国产三级人妇 | 国产精品久久久久一区二区三区 | 亚洲少妇30p| 亚洲最色的网站| 精品中文字幕一区二区小辣椒| 大尺度一区二区| 欧美日韩一二三| 久久夜色精品国产欧美乱极品| 国产精品第13页| 日韩不卡一二三区| 成人永久免费视频| 欧美色偷偷大香| 久久精品男人天堂av| 亚洲一区二区三区四区在线观看| 蜜臀久久久久久久| 99久久久精品| 亚洲精品一区二区三区影院| 亚洲欧美在线观看| 久久精品国产秦先生| 色悠久久久久综合欧美99| 日韩视频在线观看一区二区| 1000精品久久久久久久久| 免费成人你懂的| 在线视频一区二区三| 国产午夜精品一区二区| 丝袜亚洲另类欧美| av亚洲精华国产精华精华| 91精品麻豆日日躁夜夜躁| 亚洲品质自拍视频| 国产裸体歌舞团一区二区| 欧美日韩亚洲国产综合| 综合久久久久综合| 国产在线看一区| 91精品欧美综合在线观看最新| 国产精品女主播av| 国产在线视频一区二区三区| 欧美精品色综合| 亚洲男女毛片无遮挡| 福利视频网站一区二区三区| 日韩欧美一级在线播放| 亚洲成人综合在线| 91在线国产福利| 国产日韩欧美一区二区三区综合| 青青青爽久久午夜综合久久午夜| 91国产免费观看| 国产精品久久久久影院老司| 国产乱子伦视频一区二区三区| 91精品福利在线一区二区三区| 亚洲免费在线视频| 成人av网站在线| 国产喂奶挤奶一区二区三区| 青青草一区二区三区| 欧美精品高清视频| 亚洲成人av福利| 91精彩视频在线观看| 国产精品久久夜| 成人a免费在线看| 国产精品18久久久久久久久久久久 | 成人福利视频在线看| 国产日韩欧美精品一区| 国产伦精品一区二区三区在线观看| 欧美一级日韩不卡播放免费| 日韩在线一区二区| 91精品欧美久久久久久动漫| 五月综合激情日本mⅴ| 欧美日韩高清一区二区不卡| 婷婷国产在线综合| 欧美一二三区在线观看| 奇米色777欧美一区二区| 欧美一级二级三级乱码| 久久精品国产在热久久| xf在线a精品一区二区视频网站| 美女视频网站黄色亚洲| 精品国产亚洲一区二区三区在线观看| 美女视频黄免费的久久 | 一区二区三区高清| 91福利视频久久久久| 亚洲国产美国国产综合一区二区| 在线亚洲+欧美+日本专区| 天堂成人免费av电影一区| 欧美一区二区三区的| 精品一区二区日韩| 亚洲国产精品国自产拍av| a4yy欧美一区二区三区| 亚洲综合精品久久| 欧美一区在线视频| 国产一区二区福利视频| 18欧美乱大交hd1984| 欧美日韩精品三区| 加勒比av一区二区| 中文字幕在线观看一区二区| 欧美在线一二三| 琪琪久久久久日韩精品| 国产欧美一区二区精品婷婷| 色综合久久久久综合体| 免费观看一级特黄欧美大片| 欧美国产精品一区二区| 在线区一区二视频| 蜜臀av一区二区在线观看| 国产午夜精品一区二区三区嫩草| av日韩在线网站| 日韩福利视频导航| 欧美国产激情一区二区三区蜜月| 91麻豆免费在线观看| 日本一道高清亚洲日美韩| 国产亚洲精品aa| 在线免费不卡电影| 激情丁香综合五月| 亚洲精品日产精品乱码不卡| 欧美va亚洲va国产综合| 99精品欧美一区| 麻豆成人久久精品二区三区小说| 最新国产成人在线观看| 日韩欧美一区中文| 色婷婷狠狠综合| 国内精品视频666| 亚洲一卡二卡三卡四卡无卡久久| 久久综合九色综合97_久久久| 欧美在线观看视频一区二区三区| 激情五月婷婷综合网| 亚洲午夜精品在线| 中文字幕欧美日韩一区| 日韩天堂在线观看| 欧日韩精品视频| 国产精品一区二区在线播放| 亚洲va国产va欧美va观看| 国产精品久久久久久久久果冻传媒| 欧美精品亚洲一区二区在线播放| caoporn国产精品| 国产综合色产在线精品|