예제 #1
0
파일: bootrom.c 프로젝트: HackLinux/bootrom
/* very slow but ultra simple modular multiplication r=a*b mod m */
static void tr_modmul(BIG a[],BIG b[],BIG m[],BIG r[])
{
	int i;
	BIG c;
	tr_zero(r);
	for (i=RSABITS-1;i>=0;i--)
	{
		c=tr_shift(r);
		if (tr_bit(i,b))
		{	
			if (c || tr_compare(r,m)>=0) tr_sub(m,r);
			c=tr_add(a,r);
		}
		if (c || tr_compare(r,m)>=0) tr_sub(m,r);
	}
}
예제 #2
0
파일: tr_pcc.c 프로젝트: psul26/DPA_C
void
tr_pcc_consolidate (tr_pcc_context ctx, int mode)
{
  double n, nb, vary;
  int i;

  if (ctx->cnt != ctx->ny)
    {
      error (__func__, "missing %d Y realizations", ctx->ny - ctx->cnt);
    }
  if (ctx->nr < 2)
    {
      error (__func__, "not enough realizations (%d, min 2)", ctx->nr);
    }
  n = (double) (ctx->nr);
  tr_scalar_mul (ctx->l, ctx->tmp1, ctx->x2, n);	/* TMP1 = N.X2 */
  tr_sqr (ctx->l, ctx->tmp2, ctx->x);	/* TMP2 = X^2 */
  tr_sub (ctx->l, ctx->tmp1, ctx->tmp1, ctx->tmp2);	/* TMP1 = N.X2-X^2 */
  if ((mode == UNBIASED) || (mode == SQUAREUNBIASED))
    {
      nb = n / (n - 1.0);
      nb = nb * nb;
      tr_scalar_mul (ctx->l, ctx->tmp1, ctx->tmp1, nb);
      /* TMP1 = (N/(N-1))^2.(N.X2-X^2) */
    }
  if ((mode != SQUAREBIASED) && (mode != SQUAREUNBIASED))
    {
      tr_sqrt (ctx->l, ctx->tmp1, ctx->tmp1);
    }
  for (i = 0; i < ctx->ny; i++)
    {
      tr_scalar_mul (ctx->l, ctx->tmp2, ctx->xy[i], n);	/* TMP2 = N.XY */
      tr_scalar_mul (ctx->l, ctx->tmp3, ctx->x, ctx->y[i]);	/* TMP3 = X.Y */
      tr_sub (ctx->l, ctx->tmp2, ctx->tmp2, ctx->tmp3);	/* TMP2 = N.XY-X.Y */
      vary = n * ctx->y2[i] - ctx->y[i] * ctx->y[i];
      if ((mode == SQUAREBIASED) || (mode == SQUAREUNBIASED))
	{
	  tr_sqr (ctx->l, ctx->tmp2, ctx->tmp2);
	}
      else
	{
	  vary = sqrt (vary);
	}
      tr_div (ctx->l, ctx->tmp2, ctx->tmp2, ctx->tmp1);
      tr_scalar_div (ctx->l, ctx->pcc[i], ctx->tmp2, vary);
    }
}