Пример #1
0
void report_can_do(const char *param)
{
     bench_problem *p;
     p = problem_parse(param);
     ovtpvt("#%c\n", can_do(p) ? 't' : 'f');
     problem_destroy(p);
}
Пример #2
0
int		solve(int queens[92][8], int nb_queens, int cfg)
{
	int i;

	i = -1;
	if (nb_queens >= 8)
	{
		while (++i < 8)
			ft_putchar(queens[cfg][i] + 48);
		ft_putchar('\n');
		return (cfg++);
	}
	else
	{
		i = 0;
		while (++i <= 8)
		{
			if (can_do(queens[cfg], nb_queens, i))
			{
				queens[cfg][nb_queens] = i;
				cfg = solve(queens, nb_queens + 1, cfg);
			}
		}
	}
	return (cfg);
}
Пример #3
0
void setup(struct problem *p)
{
     BENCH_ASSERT(can_do(p));

     /* Call FFT once to initialize things before benchmarking: */
     doit(1, p);
}
Пример #4
0
bool
verify(
    context& d, buffer_view_t signature, buffer_view_t hvalue, hash_t halgo) {
    if (type_of(d) != pk_t::rsa && !can_do(d, pk_t::ecdsa))
        throw exceptions::support_error{};

    check_crypt_size_of(d, hvalue);

    int ret = mbedtls_pk_verify(
        &d.pk_,
        to_native(halgo),
        hvalue.data(),
        hvalue.size(),
        signature.data(),
        signature.size());

    // TODO: check when to report other errors
    switch (ret) {
    case 0:
        return true;

    case MBEDTLS_ERR_PK_BAD_INPUT_DATA:
    case MBEDTLS_ERR_PK_TYPE_MISMATCH:
        throw exception{ret, "failed to verify the signature"};
        break;
    default:
        break;
    }

    return false;
}
Пример #5
0
size_t
max_crypt_size(const context& d) {
    // padding / header data (11 bytes for PKCS#1 v1.5 padding).
    if (type_of(d) == pk_t::rsa)
        return key_length(d) - 11;

#if defined(MBEDTLS_ECDSA_C)
    else if (can_do(d, pk_t::ecdsa))
        return (size_t)MBEDTLS_ECDSA_MAX_LEN;
#endif

    throw exceptions::support_error{};
}
Пример #6
0
void speed(const char *param)
{
     double *t;
     int iter, k;
     bench_problem *p;
     double tmin, y;

     t = (double *) bench_malloc(time_repeat * sizeof(double));

     p = problem_parse(param);
     BENCH_ASSERT(can_do(p));
     problem_alloc(p);
     problem_zero(p);

     timer_start();
     setup(p);
     p->setup_time = timer_stop();

 start_over:
     for (iter = 1; iter < (1<<30); iter *= 2) {
	  tmin = 1.0e20;
	  for (k = 0; k < time_repeat; ++k) {
	       timer_start();
	       doit(iter, p);
	       y = timer_stop();
	       if (y < 0) /* yes, it happens */
		    goto start_over;
	       t[k] = y;
	       if (y < tmin)
		    tmin = y;
	  }
	  
	  if (tmin >= time_min)
	       goto done;
     }

     goto start_over; /* this also happens */

 done:
     done(p);

     for (k = 0; k < time_repeat; ++k) {
	  t[k] /= iter;
     }

     report(p, t, time_repeat);

     problem_destroy(p);
     bench_free(t);
     return;
}
Пример #7
0
void setup(struct problem *p)
{
     int n, zero = 0;

     BENCH_ASSERT(can_do(p));

     switch (p->rank) {
     case 1:
	  {
	       n = p->n[0];

	       if (p->kind == PROBLEM_COMPLEX) {
		    /*
		     * example code says that wsave consists of 3 * n
		     * locations, but the code dumps core for n == 4
		     */
		    WSAVE = bench_malloc((3 * n + 4) * sizeof(bench_real));
		    if (SINGLE_PRECISION)
			 CFFT1D(p->in, &n, &zero, WSAVE);
		    else
			 ZFFT1D(p->in, &n, &zero, WSAVE);
	       } else {
		    WSAVE = bench_malloc((4 * n) * sizeof(bench_real));

		    if (p->sign == -1) {
			 if (SINGLE_PRECISION)
			      SCFFT1D(p->in, &n, &zero, WSAVE);
			 else
			      DZFFT1D(p->in, &n, &zero, WSAVE);
		    } else {
			 if (SINGLE_PRECISION)
			      CSFFT1D(p->in, &n, &zero, WSAVE);
			 else
			      ZDFFT1D(p->in, &n, &zero, WSAVE);
		    }
	       }
	       break;
	  }
     case 2:
	  /* nothing to do */
	  break;
     default:
	  BENCH_ASSERT(0);
     }
}
Пример #8
0
void setup(struct problem *p)
{
     int n;
 
     BENCH_ASSERT(can_do(p));
     n = p->n[0];
 
     if (p->kind == PROBLEM_COMPLEX) {
	  Wv = CWv(alloc)(n);
	  Wk = CWk(alloc)(n);
     } else {
	  if (p->sign == -1)
	       Wv = RWv(alloc)(n);
	  else
	       Wv = HWv(alloc)(n);
	  Wk = RWk(alloc)(n);
     }
}
Пример #9
0
void setup(struct problem *p)
{
     int ni;
     int nj;
     int stride1 = 1;

     BENCH_ASSERT(can_do(p));
     ni = p->n[1];
     nj = p->n[0];
 
     if (p->kind == PROBLEM_COMPLEX) {
	  if (SINGLE_PRECISION) 
	       CFFT_INIT_2D(&ni, &nj, &fsc, &stride1);
	  else	       
	       ZFFT_INIT_2D(&ni, &nj, &fsz, &stride1);
     } else {
	  if (SINGLE_PRECISION) 
	       SFFT_INIT_2D(&ni, &nj, &fss, &stride1);
	  else	       
	       DFFT_INIT_2D(&ni, &nj, &fsd, &stride1);
     }
}
Пример #10
0
buffer_t
sign(context& d, buffer_view_t hvalue, hash_t halgo) {
    if (type_of(d) != pk_t::rsa && !can_do(d, pk_t::ecdsa))
        throw exceptions::support_error{};

    check_crypt_size_of(d, hvalue);

    size_t   olen = 32 + max_crypt_size(d);
    buffer_t output(olen, '\0');
    mbedcrypto_c_call(
        mbedtls_pk_sign,
        &d.pk_,
        to_native(halgo),
        hvalue.data(),
        hvalue.size(),
        to_ptr(output),
        &olen,
        rnd_generator::maker,
        &d.rnd_);

    output.resize(olen);
    return output;
}
Пример #11
0
void setup(struct problem *p)
{
     BENCH_ASSERT(can_do(p));
}
Пример #12
0
void setup(struct problem *p)
{
     m = log_2(p->n[0]) / 2;
     BENCH_ASSERT(can_do(p));
     F77_FUNC(inir4, INIR4)(&m);
}
Пример #13
0
void speed(const char *param, int setup_only)
{
     double *t;
     int iter = 0, k;
     bench_problem *p;
     double tmin, y;

     t = (double *) bench_malloc(time_repeat * sizeof(double));

     for (k = 0; k < time_repeat; ++k) 
	  t[k] = 0;

     p = problem_parse(param);
     BENCH_ASSERT(can_do(p));
     if (!no_speed_allocation) {
	  problem_alloc(p);
	  problem_zero(p);
     }

     timer_start(LIBBENCH_TIMER);
     setup(p);
     p->setup_time = bench_cost_postprocess(timer_stop(LIBBENCH_TIMER));

     /* reset the input to zero again, because the planner in paranoid
	mode sets it to random values, thus making the benchmark
	diverge. */
     if (!no_speed_allocation) 
	  problem_zero(p);
     
     if (setup_only)
	  goto done;

 start_over:
     for (iter = 1; iter < (1<<30); iter *= 2) {
	  tmin = 1.0e20;
	  for (k = 0; k < time_repeat; ++k) {
	       timer_start(LIBBENCH_TIMER);
	       doit(iter, p);
	       y = bench_cost_postprocess(timer_stop(LIBBENCH_TIMER));
	       if (y < 0) /* yes, it happens */
		    goto start_over;
	       t[k] = y;
	       if (y < tmin)
		    tmin = y;
	  }
	  
	  if (tmin >= time_min)
	       goto done;
     }

     goto start_over; /* this also happens */

 done:
     done(p);

     if (iter) 
	  for (k = 0; k < time_repeat; ++k) 
	       t[k] /= iter;
     else
	  for (k = 0; k < time_repeat; ++k) 
	       t[k] = 0;

     report(p, t, time_repeat);

     if (!no_speed_allocation)
	  problem_destroy(p);
     bench_free(t);
     return;
}
Пример #14
0
void setup(struct problem *p)
{
     int isig = 0; /* indicates initialization call */

     BENCH_ASSERT(can_do(p));

     switch (p->rank) {
	 case 2: n2 = p->n[0]; n1 = p->n[1]; break;
	 case 3: n3 = p->n[0]; n2 = p->n[1]; n1 = p->n[2]; break;
	 case 4: n4 = p->n[0]; n3 = p->n[1]; n2 = p->n[2]; n1 = p->n[3]; break;
     }
     if (p->kind == PROBLEM_COMPLEX)
	  ldn1 = n1;
     else
	  ldn1 = n1 + 2;

     w1 = (int *) bench_malloc(sizeof(int) *
			       ((p->kind == PROBLEM_REAL ? 6 : 4) * n1 + 14));
     if (iopt == 1 && p->rank == 3)
	  w2 = (int *) bench_malloc(sizeof(int) * (4*n2*(n1+1) + 14));
     else
	  w2 = (int *) bench_malloc(sizeof(int) * (4*n2 + 14));
     w3 = (int *) bench_malloc(sizeof(int) * (4*n3 + 14));
     w4 = (int *) bench_malloc(sizeof(int) * (4*n4 + 14));
     iwork = (int *) bench_malloc(sizeof(int) * MAX2(n1,MAX2(n2,MAX2(n3,n4))));
     
     if (p->kind == PROBLEM_COMPLEX) {
	  switch (p->rank) {
	      case 2:
		   C2FFT((bench_complex*) p->in, &ldn1, &n1, &n2,
			 w1, w2, &isig, &iord, iwork, &ierr);
		   break;
	      case 3:
		   C3FFT((bench_complex*) p->in, &ldn1, &n1, &n2, &n3,
			 w1, w2, w3, &iopt, &isig, &iord, iwork, &ierr);
		   break;
	      case 4:
		   C4FFT((bench_complex*) p->in,
			 &ldn1, &n2, &n1, &n2, &n3, &n4,
			 w1, w2, w3, w4, &isig, &iord, iwork, &ierr);
		   break;
	  }
     }
     else /* PROBLEM_REAL */ {
	  switch (p->rank) {
	      case 2:
		   R2FFT((bench_complex*) p->in, &ldn1, &n1, &n2,
			 w1, w2, &isig, &iord, iwork, &ierr);
		   break;
	      case 3:
		   R3FFT((bench_complex*) p->in, &ldn1, &n1, &n2, &n3,
			 w1, w2, w3, &iopt, &isig, &iord, iwork, &ierr);
		   break;
	      case 4:
		   R4FFT((bench_complex*) p->in,
			 &ldn1, &n2, &n1, &n2, &n3, &n4,
			 w1, w2, w3, w4, &isig, &iord, iwork, &ierr);
		   break;
	  }
     }
     BENCH_ASSERT(ierr == 0);
}