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

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

?? bn.c

?? 用VC實(shí)現(xiàn)的一個(gè)RSA加密算法
?? C
?? 第 1 頁(yè) / 共 5 頁(yè)
字號(hào):
#include "bn.h"

#ifdef BNCORE_C

//save data from mp_int to char
void
dump_mp_int_to_char (mp_int * b, int max, char * c)
{
	char buf[512];
	int len, x, y = 0, i;

	if ((int) mp_to_unsigned_bin (b, (unsigned char *)buf) == 0)
	{

		len = (int) mp_unsigned_bin_size (b);

		for (x = 0, i = 0; x < (int)max; x++, i++)
		{
			////printf ("%02X", buf[len - 1 - x]);
			if (x < (int)(max - len))
			{
				//printf ("00");
				c[i] = (char) 0x00;
			}
			else
			{
				//printf ("%d:%02X\t", i, buf[y]);
				c[i] = (char)buf[y];
				y++;
			}
		}
	}
}

/* Known optimal configurations

 CPU                    /Compiler     /MUL CUTOFF/SQR CUTOFF
-------------------------------------------------------------
 Intel P4 Northwood     /GCC v3.4.1   /        88/       128/LTM 0.32 ;-)
 AMD Athlon64           /GCC v3.4.4   /        80/       120/LTM 0.35
 
*/

int     KARATSUBA_MUL_CUTOFF = 80,      /* Min. number of digits before Karatsuba multiplication is used. */
        KARATSUBA_SQR_CUTOFF = 120,     /* Min. number of digits before Karatsuba squaring is used. */
        
        TOOM_MUL_CUTOFF      = 350,      /* no optimal values of these are known yet so set em high */
        TOOM_SQR_CUTOFF      = 400; 
#endif


void mp_int_word_dump(mp_int *b, int max)
{
	unsigned char buf[256];
	int len,x,y=0;

	(void)mp_to_unsigned_bin(b, buf);
	len = mp_unsigned_bin_size(b);
   
	for (x = 0; x < max; x++)
	{
		//printf ("%02X", buf[len - 1 - x]);
		if (x < (max-len))
			printf ("00");
		else
		{
			printf ("%02X", (unsigned int)buf[y]);
			y++;
		}
		if ((x & 3) == 3)
		{
			printf ("\n");
		}
	}
	if ((x & 3)>0)
	{
		while ((x++ & 3)>0)
		{
			printf ("00");
		}
		printf ("\n");
	}
	else if (len == 0)
	{
		printf ("00000000\n");
	}
}



#ifdef BN_ERROR_C

static const struct {
     int code;
     char *msg;
} msgs[] = {
     { MP_OKAY, "Successful" },
     { MP_MEM,  "Out of heap" },
     { MP_VAL,  "Value out of range" }
};

/* return a char * string for a given code */
char *mp_error_to_string(int code)
{
   int x;

   /* scan the lookup table for the given message */
   for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) {
       if (msgs[x].code == code) {
          return msgs[x].msg;
       }
   }

   /* generic reply for invalid code */
   return "Invalid error code";
}

#endif


#ifdef BN_FAST_MP_INVMOD_C

/* computes the modular inverse via binary extended euclidean algorithm, 
 * that is c = 1/a mod b 
 *
 * Based on slow invmod except this is optimized for the case where b is 
 * odd as per HAC Note 14.64 on pp. 610
 */
int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
{
  mp_int  x, y, u, v, B, D;
  int     res, neg;

  /* 2. [modified] b must be odd   */
  if (mp_iseven (b) == 1) {
    return MP_VAL;
  }

  /* init all our temps */
  if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
     return res;
  }

  /* x == modulus, y == value to invert */
  if ((res = mp_copy (b, &x)) != MP_OKAY) {
    goto LBL_ERR;
  }

  /* we need y = |a| */
  if ((res = mp_mod (a, b, &y)) != MP_OKAY) {
    goto LBL_ERR;
  }

  /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
  if ((res = mp_copy (&x, &u)) != MP_OKAY) {
    goto LBL_ERR;
  }
  if ((res = mp_copy (&y, &v)) != MP_OKAY) {
    goto LBL_ERR;
  }
  mp_set (&D, 1);

top:
  /* 4.  while u is even do */
  while (mp_iseven (&u) == 1) {
    /* 4.1 u = u/2 */
    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
      goto LBL_ERR;
    }
    /* 4.2 if B is odd then */
    if (mp_isodd (&B) == 1) {
      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
        goto LBL_ERR;
      }
    }
    /* B = B/2 */
    if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
      goto LBL_ERR;
    }
  }

  /* 5.  while v is even do */
  while (mp_iseven (&v) == 1) {
    /* 5.1 v = v/2 */
    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
      goto LBL_ERR;
    }
    /* 5.2 if D is odd then */
    if (mp_isodd (&D) == 1) {
      /* D = (D-x)/2 */
      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
        goto LBL_ERR;
      }
    }
    /* D = D/2 */
    if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
      goto LBL_ERR;
    }
  }

  /* 6.  if u >= v then */
  if (mp_cmp (&u, &v) != MP_LT) {
    /* u = u - v, B = B - D */
    if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
      goto LBL_ERR;
    }

    if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
      goto LBL_ERR;
    }
  } else {
    /* v - v - u, D = D - B */
    if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
      goto LBL_ERR;
    }

    if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
      goto LBL_ERR;
    }
  }

  /* if not zero goto step 4 */
  if (mp_iszero (&u) == 0) {
    goto top;
  }

  /* now a = C, b = D, gcd == g*v */

  /* if v != 1 then there is no inverse */
  if (mp_cmp_d (&v, 1) != MP_EQ) {
    res = MP_VAL;
    goto LBL_ERR;
  }

  /* b is now the inverse */
  neg = a->sign;
  while (D.sign == MP_NEG) {
    if ((res = mp_add (&D, b, &D)) != MP_OKAY) {
      goto LBL_ERR;
    }
  }
  mp_exch (&D, c);
  c->sign = neg;
  res = MP_OKAY;

LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
  return res;
}
#endif


#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C

/* computes xR**-1 == x (mod N) via Montgomery Reduction
 *
 * This is an optimized implementation of montgomery_reduce
 * which uses the comba method to quickly calculate the columns of the
 * reduction.
 *
 * Based on Algorithm 14.32 on pp.601 of HAC.
*/
int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
{
  int     ix, res, olduse;
  mp_word W[MP_WARRAY];

  /* get old used count */
  olduse = x->used;

  /* grow a as required */
  if (x->alloc < n->used + 1) {
    if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) {
      return res;
    }
  }

  /* first we have to get the digits of the input into
   * an array of double precision words W[...]
   */
  {
    register mp_word *_W;
    register mp_digit *tmpx;

    /* alias for the W[] array */
    _W   = W;

    /* alias for the digits of  x*/
    tmpx = x->dp;

    /* copy the digits of a into W[0..a->used-1] */
    for (ix = 0; ix < x->used; ix++) {
      *_W++ = *tmpx++;
    }

    /* zero the high words of W[a->used..m->used*2] */
    for (; ix < n->used * 2 + 1; ix++) {
      *_W++ = 0;
    }
  }

  /* now we proceed to zero successive digits
   * from the least significant upwards
   */
  for (ix = 0; ix < n->used; ix++) {
    /* mu = ai * m' mod b
     *
     * We avoid a double precision multiplication (which isn't required)
     * by casting the value down to a mp_digit.  Note this requires
     * that W[ix-1] have  the carry cleared (see after the inner loop)
     */
    register mp_digit mu;
    mu = (mp_digit) (((W[ix] & MP_MASK) * rho) & MP_MASK);

    /* a = a + mu * m * b**i
     *
     * This is computed in place and on the fly.  The multiplication
     * by b**i is handled by offseting which columns the results
     * are added to.
     *
     * Note the comba method normally doesn't handle carries in the
     * inner loop In this case we fix the carry from the previous
     * column since the Montgomery reduction requires digits of the
     * result (so far) [see above] to work.  This is
     * handled by fixing up one carry after the inner loop.  The
     * carry fixups are done in order so after these loops the
     * first m->used words of W[] have the carries fixed
     */
    {
      register int iy;
      register mp_digit *tmpn;
      register mp_word *_W;

      /* alias for the digits of the modulus */
      tmpn = n->dp;

      /* Alias for the columns set by an offset of ix */
      _W = W + ix;

      /* inner loop */
      for (iy = 0; iy < n->used; iy++) {
          *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++);
      }
    }

    /* now fix carry for next digit, W[ix+1] */
    W[ix + 1] += W[ix] >> ((mp_word) DIGIT_BIT);
  }

  /* now we have to propagate the carries and
   * shift the words downward [all those least
   * significant digits we zeroed].
   */
  {
    register mp_digit *tmpx;
    register mp_word *_W, *_W1;

    /* nox fix rest of carries */

    /* alias for current word */
    _W1 = W + ix;

    /* alias for next word, where the carry goes */
    _W = W + ++ix;

    for (; ix <= n->used * 2 + 1; ix++) {
      *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT);
    }

    /* copy out, A = A/b**n
     *
     * The result is A/b**n but instead of converting from an
     * array of mp_word to mp_digit than calling mp_rshd
     * we just copy them in the right order
     */

    /* alias for destination word */
    tmpx = x->dp;

    /* alias for shifted double precision result */
    _W = W + n->used;

    for (ix = 0; ix < n->used + 1; ix++) {
      *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK));
    }

    /* zero oldused digits, if the input a was larger than
     * m->used+1 we'll have to clear the digits
     */
    for (; ix < olduse; ix++) {
      *tmpx++ = 0;
    }
  }

  /* set the max used and clamp */
  x->used = n->used + 1;
  mp_clamp (x);

  /* if A >= m then A = A - m */
  if (mp_cmp_mag (x, n) != MP_LT) {
    return s_mp_sub (x, n, x);
  }
  return MP_OKAY;
}
#endif


#ifdef BN_FAST_S_MP_MUL_DIGS_C

/* Fast (comba) multiplier
 *
 * This is the fast column-array [comba] multiplier.  It is 
 * designed to compute the columns of the product first 
 * then handle the carries afterwards.  This has the effect 
 * of making the nested loops that compute the columns very
 * simple and schedulable on super-scalar processors.
 *
 * This has been modified to produce a variable number of 
 * digits of output so if say only a half-product is required 
 * you don't have to compute the upper half (a feature 
 * required for fast Barrett reduction).
 *
 * Based on Algorithm 14.12 on pp.595 of HAC.
 *
 */
int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
{
  int     olduse, res, pa, ix, iz;
  mp_digit W[MP_WARRAY];
  register mp_word  _W;

  /* grow the destination as required */
  if (c->alloc < digs) {
    if ((res = mp_grow (c, digs)) != MP_OKAY) {
      return res;
    }
  }

  /* number of output digits to produce */
  pa = MIN(digs, a->used + b->used);

  /* clear the carry */
  _W = 0;
  for (ix = 0; ix < pa; ix++) { 
      int      tx, ty;
      int      iy;
      mp_digit *tmpx, *tmpy;

      /* get offsets into the two bignums */
      ty = MIN(b->used-1, ix);
      tx = ix - ty;

      /* setup temp aliases */
      tmpx = a->dp + tx;
      tmpy = b->dp + ty;

      /* this is the number of times the loop will iterrate, essentially 
         while (tx++ < a->used && ty-- >= 0) { ... }
       */
      iy = MIN(a->used-tx, ty+1);

      /* execute loop */
      for (iz = 0; iz < iy; ++iz) {
         _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);

      }

      /* store term */
      W[ix] = ((mp_digit)_W) & MP_MASK;

      /* make next carry */
      _W = _W >> ((mp_word)DIGIT_BIT);
  }

  /* store final carry */
  W[ix] = (mp_digit)(_W & MP_MASK);

  /* setup dest */
  olduse  = c->used;
  c->used = pa;

  {
    register mp_digit *tmpc;
    tmpc = c->dp;
    for (ix = 0; ix < pa+1; ix++) {
      /* now extract the previous digit [below the carry] */
      *tmpc++ = W[ix];
    }

    /* clear unused digits [that existed in the old copy of c] */
    for (; ix < olduse; ix++) {
      *tmpc++ = 0;
    }
  }
  mp_clamp (c);
  return MP_OKAY;
}
#endif


#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C

/* this is a modified version of fast_s_mul_digs that only produces
 * output digits *above* digs.  See the comments for fast_s_mul_digs
 * to see how it works.
 *
 * This is used in the Barrett reduction since for one of the multiplications
 * only the higher digits were needed.  This essentially halves the work.
 *
 * Based on Algorithm 14.12 on pp.595 of HAC.
 */
int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
{
  int     olduse, res, pa, ix, iz;
  mp_digit W[MP_WARRAY];
  mp_word  _W;

  /* grow the destination as required */
  pa = a->used + b->used;
  if (c->alloc < pa) {
    if ((res = mp_grow (c, pa)) != MP_OKAY) {
      return res;
    }
  }

  /* number of output digits to produce */
  pa = a->used + b->used;
  _W = 0;
  for (ix = digs; ix < pa; ix++) { 
      int      tx, ty, iy;
      mp_digit *tmpx, *tmpy;

      /* get offsets into the two bignums */
      ty = MIN(b->used-1, ix);
      tx = ix - ty;

      /* setup temp aliases */
      tmpx = a->dp + tx;
      tmpy = b->dp + ty;

      /* this is the number of times the loop will iterrate, essentially its 
         while (tx++ < a->used && ty-- >= 0) { ... }
       */
      iy = MIN(a->used-tx, ty+1);

      /* execute loop */
      for (iz = 0; iz < iy; iz++) {
         _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
      }

      /* store term */
      W[ix] = ((mp_digit)_W) & MP_MASK;

      /* make next carry */
      _W = _W >> ((mp_word)DIGIT_BIT);
  }
  
  /* store final carry */
  W[ix] = (mp_digit)(_W & MP_MASK);

  /* setup dest */
  olduse  = c->used;
  c->used = pa;

  {
    register mp_digit *tmpc;

    tmpc = c->dp + digs;
    for (ix = digs; ix <= pa; ix++) {
      /* now extract the previous digit [below the carry] */
      *tmpc++ = W[ix];
    }

    /* clear unused digits [that existed in the old copy of c] */
    for (; ix < olduse; ix++) {
      *tmpc++ = 0;
    }
  }
  mp_clamp (c);
  return MP_OKAY;
}
#endif


#ifdef BN_FAST_S_MP_SQR_C

/* the jist of squaring...

?? 快捷鍵說(shuō)明

復(fù)制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號(hào) Ctrl + =
減小字號(hào) Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
秋霞国产午夜精品免费视频| 天堂蜜桃一区二区三区 | 偷窥少妇高潮呻吟av久久免费| 精品少妇一区二区三区免费观看| 99久久精品国产观看| 久久aⅴ国产欧美74aaa| 亚洲综合精品久久| 中文字幕不卡在线播放| 日韩免费高清av| 欧美在线高清视频| 99久久久国产精品免费蜜臀| 国产在线播精品第三| 琪琪久久久久日韩精品| 一区二区三区毛片| 国产精品久久久久久久久久久免费看| 日韩精品中文字幕在线不卡尤物 | 日韩高清国产一区在线| 中文字幕欧美一| 国产欧美日本一区二区三区| 日韩欧美一卡二卡| 91麻豆精品国产91久久久资源速度| 99国内精品久久| kk眼镜猥琐国模调教系列一区二区| 玖玖九九国产精品| 美女视频黄a大片欧美| 亚洲www啪成人一区二区麻豆 | 激情小说亚洲一区| 蜜臀久久99精品久久久久久9| 一区二区免费看| 日韩伦理电影网| 国产精品麻豆一区二区| 久久精品视频在线看| 欧美刺激脚交jootjob| 欧美一区二区三区四区五区| 91精品中文字幕一区二区三区| 欧美图片一区二区三区| 欧美视频在线观看一区| 欧美日韩一区二区三区在线| 欧美午夜精品久久久久久孕妇| 91老司机福利 在线| 日本国产一区二区| 欧美综合色免费| 欧美三区在线视频| 欧美二区在线观看| 日韩欧美国产电影| 337p粉嫩大胆色噜噜噜噜亚洲| 久久女同性恋中文字幕| 久久久国产一区二区三区四区小说| 久久久久久97三级| 国产精品天天摸av网| 亚洲欧美二区三区| 午夜精品影院在线观看| 久久精品国产亚洲a| 国产精品一区免费在线观看| 高清在线不卡av| 99久久久国产精品| 欧美亚一区二区| 欧美一区二区私人影院日本| 日韩三级精品电影久久久| 精品久久久久久久久久久久包黑料| 精品美女一区二区三区| 久久久久久久久99精品| 亚洲视频1区2区| 天天色综合天天| 国产一区二区在线电影| 成人精品免费视频| 欧美天堂一区二区三区| 欧美tickle裸体挠脚心vk| 久久久久久久性| 亚洲精品自拍动漫在线| 日本va欧美va瓶| 粉嫩aⅴ一区二区三区四区五区| 一本久道久久综合中文字幕| 69成人精品免费视频| 国产精品天美传媒沈樵| 亚洲国产三级在线| 国产成人丝袜美腿| 欧美日韩精品一区二区天天拍小说| 精品sm捆绑视频| 看片的网站亚洲| 成人a免费在线看| 欧美另类videos死尸| 欧美国产综合一区二区| 香蕉成人啪国产精品视频综合网 | 欧美激情一区在线观看| 亚洲最色的网站| 国产一区二区三区免费播放| 色婷婷久久综合| 精品国产一区久久| 亚洲电影在线播放| 成人av在线影院| 日韩欧美国产一二三区| 亚洲另类在线制服丝袜| 国产一区二区三区精品欧美日韩一区二区三区 | 中文字幕中文乱码欧美一区二区| 天天色天天操综合| 99久久精品免费看| 久久综合久色欧美综合狠狠| 亚洲一区二区视频在线观看| 粉嫩绯色av一区二区在线观看| 欧美乱熟臀69xxxxxx| 国产精品二三区| 九九**精品视频免费播放| 欧美中文字幕亚洲一区二区va在线| 久久夜色精品一区| 日日摸夜夜添夜夜添国产精品| 不卡的看片网站| 久久综合丝袜日本网| 日本美女视频一区二区| 欧美曰成人黄网| 亚洲人成在线观看一区二区| 精品一区二区三区在线播放| 欧美群妇大交群的观看方式| 一区二区三区美女| 91免费观看视频| 久久亚洲一级片| 韩国三级中文字幕hd久久精品| 91精品国产色综合久久久蜜香臀| 亚洲永久免费视频| 91老司机福利 在线| 中文字幕日韩精品一区| 成人小视频在线| 欧美国产激情一区二区三区蜜月| 老司机精品视频在线| 欧美一区二区三区喷汁尤物| 爽好多水快深点欧美视频| 欧美色视频一区| 夜夜精品浪潮av一区二区三区| 99久久777色| 亚洲另类一区二区| 在线视频你懂得一区| 亚洲男人天堂av网| 色悠悠亚洲一区二区| 亚洲三级在线播放| 色哟哟一区二区三区| 樱桃视频在线观看一区| 欧美性受xxxx| 亚洲国产成人porn| 欧美日韩三级视频| 免费观看一级特黄欧美大片| 欧美一区中文字幕| 裸体在线国模精品偷拍| 精品日韩99亚洲| 国产揄拍国内精品对白| 中文久久乱码一区二区| 91在线高清观看| 亚洲综合久久av| 欧美一区二区视频免费观看| 黄页网站大全一区二区| 亚洲高清在线视频| 日韩一区二区视频| 国产一区视频导航| 1区2区3区国产精品| 在线视频一区二区三区| 日本视频一区二区三区| 欧美电影免费观看高清完整版| 国产乱码精品一区二区三区av | 精品粉嫩aⅴ一区二区三区四区 | 欧美喷水一区二区| 麻豆精品一区二区| 国产精品嫩草影院av蜜臀| 91九色02白丝porn| 美女精品一区二区| 国产精品美女www爽爽爽| 91福利国产精品| 狠狠v欧美v日韩v亚洲ⅴ| 国产精品不卡在线| 欧美日韩国产在线观看| 国产一区 二区| 一区二区三区久久久| 精品久久久久av影院| 色综合久久综合网97色综合| 青青草97国产精品免费观看无弹窗版| 久久久久久免费| 欧美唯美清纯偷拍| 国产91富婆露脸刺激对白| 亚洲国产日日夜夜| 欧美激情一区三区| 欧美精品精品一区| 成人午夜视频福利| 秋霞电影网一区二区| 亚洲欧洲日韩av| 欧美草草影院在线视频| 91网上在线视频| 狠狠色丁香婷综合久久| 一区二区三区不卡视频| 久久婷婷久久一区二区三区| 在线观看亚洲一区| 国产盗摄视频一区二区三区| 天堂av在线一区| 亚洲欧美激情插| 国产欧美日产一区| 日韩午夜av电影| 欧美亚洲国产一区二区三区va | 91麻豆精品国产| 91在线精品秘密一区二区| 久草中文综合在线| 亚洲成人精品一区| 亚洲女爱视频在线| 国产精品视频麻豆|