Example #1
0
int
main (int argc, char **argv)
{
  unsigned long i, k;
  struct timespec runtime;
  timing_t start, end;

  startup();

  memset (&runtime, 0, sizeof (runtime));

  unsigned long iters, res;

  TIMING_INIT (res);

  iters = 1000 * res;

  for (int v = 0; v < NUM_VARIANTS; v++)
    {
      /* Run for approximately DURATION seconds.  */
      clock_gettime (CLOCK_MONOTONIC_RAW, &runtime);
      runtime.tv_sec += DURATION;

      double d_total_i = 0;
      timing_t total = 0, max = 0, min = 0x7fffffffffffffff;
      while (1)
	{
	  for (i = 0; i < NUM_SAMPLES (v); i++)
	    {
	      uint64_t cur;
	      TIMING_NOW (start);
	      for (k = 0; k < iters; k++)
		BENCH_FUNC (v, i);
	      TIMING_NOW (end);

	      TIMING_DIFF (cur, start, end);

	      if (cur > max)
		max = cur;

	      if (cur < min)
		min = cur;

	      TIMING_ACCUM (total, cur);

	      d_total_i += iters;
	    }
	  struct timespec curtime;

	  memset (&curtime, 0, sizeof (curtime));
	  clock_gettime (CLOCK_MONOTONIC_RAW, &curtime);
	  if (TIMESPEC_AFTER (curtime, runtime))
	    goto done;
	}

      double d_total_s;
      double d_iters;

    done:
      d_total_s = total;
      d_iters = iters;

      TIMING_PRINT_STATS (VARIANT (v), d_total_s, d_iters, d_total_i, max,
			  min);
    }

  return 0;
}
Example #2
0
int
main (int argc, char **argv)
{
  unsigned long i, k;
  struct timespec runtime;
  timing_t start, end;
  bool detailed = false;
  json_ctx_t json_ctx;

  if (argc == 2 && !strcmp (argv[1], "-d"))
    detailed = true;

  bench_start ();

  memset (&runtime, 0, sizeof (runtime));

  unsigned long iters, res;

#ifdef BENCH_INIT
  BENCH_INIT ();
#endif
  TIMING_INIT (res);

  iters = 1000 * res;

  json_init (&json_ctx, 2, stdout);

  /* Begin function.  */
  json_attr_object_begin (&json_ctx, FUNCNAME);

  for (int v = 0; v < NUM_VARIANTS; v++)
    {
      /* Run for approximately DURATION seconds.  */
      clock_gettime (CLOCK_MONOTONIC_RAW, &runtime);
      runtime.tv_sec += DURATION;

      double d_total_i = 0;
      timing_t total = 0, max = 0, min = 0x7fffffffffffffff;
      int64_t c = 0;
      while (1)
	{
	  for (i = 0; i < NUM_SAMPLES (v); i++)
	    {
	      uint64_t cur;
	      TIMING_NOW (start);
	      for (k = 0; k < iters; k++)
		BENCH_FUNC (v, i);
	      TIMING_NOW (end);

	      TIMING_DIFF (cur, start, end);

	      if (cur > max)
		max = cur;

	      if (cur < min)
		min = cur;

	      TIMING_ACCUM (total, cur);
	      /* Accumulate timings for the value.  In the end we will divide
	         by the total iterations.  */
	      RESULT_ACCUM (cur, v, i, c * iters, (c + 1) * iters);

	      d_total_i += iters;
	    }
	  c++;
	  struct timespec curtime;

	  memset (&curtime, 0, sizeof (curtime));
	  clock_gettime (CLOCK_MONOTONIC_RAW, &curtime);
	  if (TIMESPEC_AFTER (curtime, runtime))
	    goto done;
	}

      double d_total_s;
      double d_iters;

    done:
      d_total_s = total;
      d_iters = iters;

      /* Begin variant.  */
      json_attr_object_begin (&json_ctx, VARIANT (v));

      json_attr_double (&json_ctx, "duration", d_total_s);
      json_attr_double (&json_ctx, "iterations", d_total_i);
      json_attr_double (&json_ctx, "max", max / d_iters);
      json_attr_double (&json_ctx, "min", min / d_iters);
      json_attr_double (&json_ctx, "mean", d_total_s / d_total_i);

      if (detailed)
	{
	  json_array_begin (&json_ctx, "timings");

	  for (int i = 0; i < NUM_SAMPLES (v); i++)
	    json_element_double (&json_ctx, RESULT (v, i));

	  json_array_end (&json_ctx);
	}

      /* End variant.  */
      json_attr_object_end (&json_ctx);
    }

  /* End function.  */
  json_attr_object_end (&json_ctx);

  return 0;
}
Example #3
0
int
main (int argc, char **argv)
{
  timing_t cur;
  size_t iters = 0, num_threads = 1;
  unsigned long res;
  json_ctx_t json_ctx;
  double d_total_s, d_total_i;
  struct sigaction act;

  if (argc == 1)
    num_threads = 1;
  else if (argc == 2)
    {
      long ret;

      errno = 0;
      ret = strtol(argv[1], NULL, 10);

      if (errno || ret == 0)
	usage(argv[0]);

      num_threads = ret;
    }
  else
    usage(argv[0]);

  init_random_values ();

  json_init (&json_ctx, 0, stdout);

  json_document_begin (&json_ctx);

  json_attr_string (&json_ctx, "timing_type", TIMING_TYPE);

  json_attr_object_begin (&json_ctx, "functions");

  json_attr_object_begin (&json_ctx, "malloc");

  json_attr_object_begin (&json_ctx, "");

  TIMING_INIT (res);

  (void) res;

  memset (&act, 0, sizeof (act));
  act.sa_handler = &alarm_handler;

  sigaction (SIGALRM, &act, NULL);

  alarm (BENCHMARK_DURATION);

  cur = do_benchmark (num_threads, &iters);

  struct rusage usage;
  getrusage(RUSAGE_SELF, &usage);

  d_total_s = cur;
  d_total_i = iters;

  json_attr_double (&json_ctx, "duration", d_total_s);
  json_attr_double (&json_ctx, "iterations", d_total_i);
  json_attr_double (&json_ctx, "time_per_iteration", d_total_s / d_total_i);
  json_attr_double (&json_ctx, "max_rss", usage.ru_maxrss);

  json_attr_double (&json_ctx, "threads", num_threads);
  json_attr_double (&json_ctx, "min_size", MIN_ALLOCATION_SIZE);
  json_attr_double (&json_ctx, "max_size", MAX_ALLOCATION_SIZE);
  json_attr_double (&json_ctx, "random_seed", RAND_SEED);

  json_attr_object_end (&json_ctx);

  json_attr_object_end (&json_ctx);

  json_attr_object_end (&json_ctx);

  json_document_end (&json_ctx);

  return 0;
}
int main(int argc, char *argv[]) {
	libless_t env;
	libless_params_t parameters;
	libless_master_t master_key;
	libless_partial_t partial_key;
	libless_secret_t secret;
	libless_public_t public_key;
	libless_private_t private_key;
	libless_ciphertext_t encrypted;
	unsigned char id[] = { 'u', 's', 'e', 'r' };
	unsigned char data[] = { 'm', 'e', 's', 's', 'a', 'g', 'e', '\0' };
	unsigned char data2[8];
	int data2_len;
	int code;

	TIMING_INIT();

	code = LIBLESS_ERROR;

	libless_init(&env);
	libless_parameters_init(&parameters);
	libless_master_init(&master_key);
	libless_partial_init(&partial_key);
	libless_secret_init(&secret);
	libless_public_init(&public_key);
	libless_private_init(&private_key);
	libless_ciphertext_init(&encrypted);

	TIMING_BEFORE();

	TRY(libless_encryption_setup(&env, &parameters, &master_key), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_setup);

	printf("System parameters and master key generated.\n");

	TIMING_BEFORE();

	TRY(libless_encryption_extract(&env, &partial_key, id, 4, master_key,
					parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_encryption_extract);

	printf("Partial private key extracted.\n");

	TIMING_BEFORE();

	TRY(libless_encryption_set_secret(&env, &secret, parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_encryption_set_secret);

	printf("Secret value set.\n");

	TIMING_BEFORE();

	TRY(libless_encryption_set_public(&env, &public_key, secret, parameters),
			goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_encryption_set_public);

	printf("Public key set.\n");

	TIMING_BEFORE();

	TRY(libless_encryption_set_private(&env, &private_key, secret, partial_key,
					parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_encryption_set_private);

	printf("Private key set.\n");

	TIMING_BEFORE();

	TRY(libless_encrypt(&env, &encrypted, data, sizeof(data), id, 4, public_key,
					parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_encrypt);

	TIMING_BEFORE();

	TRY(libless_decrypt(&env, data2, &data2_len, encrypted, private_key,
					parameters), goto end);

	ASSERT(memcmp(data, data2, data2_len) == 0 &&
			data2_len == sizeof(data), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_decrypt);

	printf("Ciphertext decrypted: %s.\n", data2);

	code = LIBLESS_OK;
  end:
	if (code == LIBLESS_ERROR) {
		printf("Test failed.\n");
	}
	else {
		printf("Test succeded.\n");
	}
	libless_ciphertext_clean(&encrypted);
	libless_private_clean(&private_key);
	libless_partial_clean(&partial_key);
	libless_secret_clean(&secret);
	libless_public_clean(&public_key);
	libless_master_clean(&master_key);
	libless_parameters_clean(&parameters);
	libless_clean(&env);
}
int main(int argc, char *argv[]) {
	libless_t env;
	libless_params_t parameters;
	libless_master_t master_key;
	libless_partial_t partial_key;
	libless_secret_t secret;
	libless_public_t public_key;
	libless_private_t private_key;
	libless_aggregate_t aggregate;
	unsigned char id[] = { 'u', 's', 'e', 'r' };
	unsigned char data[] = { 'm', 'e', 's', 's', 'a', 'g', 'e', '\0' };
	int verified;
	int code;

	TIMING_INIT();

	code = LIBLESS_ERROR;

	libless_init(&env);
	libless_parameters_init(&parameters);
	libless_master_init(&master_key);
	libless_partial_init(&partial_key);
	libless_secret_init(&secret);
	libless_public_init(&public_key);
	libless_private_init(&private_key);

	TRY(libless_aggregate_init(&aggregate, N), goto end);

	TIMING_BEFORE();

	TRY(libless_aggregate_setup(&env, &parameters, &master_key), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_aggregate_setup);

	printf("System parameters and master key generated.\n");

	TIMING_BEFORE();

	TRY(libless_aggregate_extract(&env, &partial_key, id, 4, master_key,
					parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_aggregate_extract);

	printf("Partial private key extracted.\n");

	TIMING_BEFORE();

	TRY(libless_aggregate_set_secret(&env, &secret, parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_aggregate_set_secret);

	printf("Secret value set.\n");

	TIMING_BEFORE();

	TRY(libless_aggregate_set_public(&env, &public_key, secret, parameters),
			goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_aggregate_set_public);

	printf("Public key set.\n");

	TIMING_BEFORE();

	TRY(libless_aggregate_set_private(&env, &private_key, secret, partial_key,
					parameters), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE(libless_aggregate_set_private);

	printf("Private key set.\n");

	TIMING_BEFORE();

	TRY(libless_aggregate_batch_sign(&env, &aggregate, id, 4, public_key,
					private_key, parameters, data, sizeof(data)), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE_N(libless_aggregate_batch_sign, N);

	TIMING_BEFORE();

	verified = 0;
	TRY(libless_aggregate_batch_verify(&env, &verified, aggregate, id, 4,
					public_key, parameters, data, sizeof(data)), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE_N(libless_aggregate_batch_verify, N);

	ASSERT(verified, goto end);

	printf("Signature verified.\n");

	TIMING_BEFORE();

	verified = 0;
	TRY(libless_aggregate_verify(&env, &verified, aggregate, id, 4,
					public_key, parameters, data, sizeof(data)), goto end);

	TIMING_AFTER();
	TIMING_COMPUTE_N(libless_aggregate_verify,N);

	ASSERT(verified, goto end);

	printf("Signature verified.\n");

	code = LIBLESS_OK;
end:
	if (code == LIBLESS_ERROR) {
		printf("Test failed.\n");
	}
	else {
		printf("Test succeded.\n");
	}

	libless_aggregate_clean(&aggregate);
	libless_private_clean(&private_key);
	libless_partial_clean(&partial_key);
	libless_secret_clean(&secret);
	libless_public_clean(&public_key);
	libless_master_clean(&master_key);
	libless_parameters_clean(&parameters);
	libless_clean(&env);
}