Beispiel #1
0
int
main (int argc, char **argv)
{
  int sg, rg;
  rs = rv = se = sc = sv = n = sg = rg = eg = 0;
  ptr<schnorr_gen> sgt;
  setprogname (argv[0]);
  random_update ();
  int m = 10;
  
  for (int i = 0; i < m; i++) {
    startt ();
    sgt = schnorr_gen::rgen (1024);
    sg += stopt ();
    startt ();
    rabin_priv sk = rabin_keygen (1024);
    rg += stopt ();
    test_key_encrypt (sk, sgt->csk, sgt->ssk);
  }
  /*
  warnx << "n: " << n << "\n"
	<< "Rabin sign:       " << rs / n << "\n"
        << "Rabin verify:     " << rv / n << "\n"
        << "Schnorr Endorse:  " << se / n << "\n"
        << "Schnorr Complete: " << sc / n << "\n"
        << "Schnorr Verify:   " << sv / n << "\n"
	<< "Rabin generate:   " << rg / m << "\n"
	<< "Schnorr generate: " << sg / m << "\n"
	<< "Schnorr Ephem Gn: " << eg / n << "\n";
  */
  return 0;
}
Beispiel #2
0
void
test_key_encrypt (rabin_priv &sk, schnorr_clnt_priv *scp,
		  schnorr_srv_priv *ssp)
{
  for (int i = 0; i < 10; i++) {
    size_t len = 512;
    wmstr wmsg (len);
    rnd.getbytes (wmsg, len);
    str msg = wmsg;

    startt ();
    ref<ephem_key_pair> ekp = scp->make_ephem_key_pair ();
    eg += stopt ();

    startt ();
    bigint rab = sk.sign (msg);
    rs += stopt ();

    startt();
    if (!sk.verify (msg, rab)) {
      panic << "verify failed.\n";
    }
    rv += stopt ();

    int bitno = rnd.getword () % mpz_sizeinbase2 (&rab);
    rab.setbit (bitno, !rab.getbit (bitno));
    if (sk.verify (msg, rab)) {
      panic << "verify should have failed\n";
    }

    bigint r_srv, s_srv, r, s;
    startt ();
    if (!ssp->endorse_signature (&r_srv, &s_srv, msg, ekp->public_half ())) {
      panic << "cannot endorse\n";
    }
    se += stopt ();
    startt ();
    if (!scp->complete_signature (&r, &s, msg, ekp->public_half (),
				  ekp->private_half (), r_srv, s_srv)) {
      panic << "cannot complete sig\n";
    }
    sc += stopt ();
    
    startt ();
    if (!scp->verify (msg, r, s)) {
      panic << "verify failed\n";
    }
    sv += stopt ();
    bitno = rnd.getword () % mpz_sizeinbase2 (&s);
    s.setbit (bitno, !s.getbit (bitno));
    if (scp->verify (msg, r, s))
      panic << "verify should have failed.\n";

    /*
    warn << "Success: " << i << "\n";
    */
    n++;
  }
}
Beispiel #3
0
int main(int argc , char *argv[]) 
{
    int i, k, num_comb, hr, min, sec, generate_input_file;
    int num_tested, current_winner, resume, num_functions, testing;
    char *input_file = NULL;
    char *interrupt_file = NULL;
    float current;
    double *results = NULL, *unfiltered = NULL, *outliers = NULL;
    ADCL_Attribute *ADCL_param_attributes = NULL;
    ADCL_Attrset ADCL_param_attrset;
    ADCL_Fnctset ADCL_param_fnctset;
    ADCL_Topology ADCL_param_topo;
    ADCL_Request ADCL_param_request;

    /* options */
    static struct option long_opts[] = 
    {
        { "verbose",              no_argument, NULL, 'v' },
        { "status",               no_argument, NULL, 's' },
        { "debug",                no_argument, NULL, 'd' },
        { "silent",               no_argument, NULL, 'n' },

        { "params",               required_argument, NULL, 'p' },
        { "test",                 required_argument, NULL, 't' },
        { "test_path",            required_argument, NULL, 'w' },
        { "message_length",       required_argument, NULL, 'l' }, 
        { "hostfile",             required_argument, NULL, 'h' },
        { "mca",                  required_argument, NULL, 'm' },
        { "format",               required_argument, NULL, 'f' },
        { "out",                  required_argument, NULL, 'o' },
        { "backup",               required_argument, NULL, 'b' },
        { "resume",               required_argument, NULL, 'r' },
        { "collective_operation", required_argument, NULL, 'c' },
        { "number_of_processes",  required_argument, NULL, 'a' },
        { "operation",            required_argument, NULL, 'e' },
        { "generate_input_file",  required_argument, NULL, 'x' },
        { NULL, 0, NULL, 0 }
    };

    startt();
    stop_signal = 0;

    verbose = 1;
    status = 0;
    debug = 0;
    mca_args_len = 0;
    hostf = NULL;
    test = 0;
    test_path = NULL;
    msg_size = NULL;
    output_dir = NULL;
    resume = 0;
    time(&stamp);
    op_num = -1;
    num_proc = NULL;
    operation = NULL;
    testing = 1;
    generate_input_file = 0;

    tests_names[0] = strdup("Netpipe");
    tests_names[1] = strdup("SKaMPI");
    tests_names[2] = strdup("NPB");
    tests_names[3] = strdup("latency_io");
    tests_names[4] = strdup("noncontig");
    tests_names[5] = strdup("mpi_tile_io");

    if (SUCCESS != set_mca_options (argc, argv)) 
    {
        fprintf(stderr, "Invalid mca options");
        exit(1);
    }

    if (SUCCESS != get_result_files (argc, argv)) 
    {
        fprintf(stderr, "Invalid result files");
        exit(1);
    }

    while (-1 != (i = getopt_long (argc, 
                                   argv, 
                                   "p:t:w:vsndl:m:h:g:o:f:r:b:c:a:e:x:",
                                   long_opts, 
                                   NULL))) 
    {
        switch (i) 
        {
        case 'p':
            input_file = strdup (optarg);
            break;
        case 'r':
            resume = 1;
            interrupt_file = strdup (optarg);
            break;
        case 'b':
            interrupt_file = strdup (optarg);
            break;
        case 'f':
            if (strcasecmp (optarg, "XML")) 
            {
                output = XML;
            }
            else 
            {
                output = TEXT;
            }
            break;
        case 'v':
            verbose = 1;
            break;
        case 's':
            status = 1;
            break;
        case 'n':
            break;
        case 'd':
            debug = 1;
            break;
        case 't':
            if ( !strcasecmp (optarg,"Netpipe")) {
                test = OTPO_TEST_NETPIPE;
            }
            else if ( !strcasecmp (optarg,"skampi")) {
                test = OTPO_TEST_SKAMPI;
            }
            else if ( !strcasecmp (optarg,"NPB")) {
                test = OTPO_TEST_NPB;
            }
            else if ( !strcasecmp (optarg,"latency_io")) {
                test = OTPO_TEST_LATENCY_IO;
            }
            else if ( !strcasecmp (optarg,"noncontig")) {
                test = OTPO_TEST_NONCONTIG;
            }
            else if ( !strcasecmp (optarg,"mpi_tile_io")) {
                test = OTPO_TEST_MPI_TILE_IO;
            }
            else {
                printf ("Invalid Test Name\n");
                exit (1);
            }
            break;
        case 'w':
            test_path = strdup (optarg);
            break;
        case 'l':
            msg_size = strdup (optarg);
            if (optarg[0] != '0' && atoi (optarg) == 0) 
            {
                printf ("Invalid Message Size\n");
                exit (1);
            }
            break;
        case 'm':
            break;
        case 'h':
            hostf = strdup (optarg);
            break;
        case 'o':
            output_dir = strdup (optarg);
            break;
        case 'c':
            op_num =  atoi(optarg);
            break;
        case 'a':
            num_proc = strdup(optarg);
            break;
        case 'e':
            operation = strdup (optarg);
            break;
        case 'x':
            generate_input_file = 1;
            break;
        default: 
            print_usage();
            exit (1);
        }
    }

    if (generate_input_file) {
        otpo_generate_input_file ();
        return 0;
    }

    if (NULL == input_file)
    {
        printf ("You need an input file that contains the parameters\n");
        print_usage();
        exit (1);
    }

    if (NULL == test_path)
    {
        printf ("You need to specify the path to the test u want to execute\n");
        print_usage();
        exit (1);
    }

    if (NULL == output_dir)
    {
        output_dir = strdup ("results");
    }

    if (NULL == interrupt_file)
    {
        interrupt_file = strdup ("interrupt.txt");
    }

    if (NULL == msg_size)
    {
        msg_size = strdup ("1024");
    }

    if (0 == test)
    {
        test = OTPO_TEST_NETPIPE;
    }
    
    if (NULL == num_proc) 
    {
        num_proc = strdup ("2");
    }

    if (OTPO_TEST_SKAMPI == test) 
    {
        if (op_num < 0 || op_num > 11) {
            printf("Invalid Collective Operation number!");
            exit(1);
        }
        if (NULL == operation) {
            operation = strdup ("MPI_MAX");
        }
    }
    else if (OTPO_TEST_LATENCY_IO == test) {
        if (op_num < 1 || op_num > 17) {
            printf("Invalid IO MODE");
            exit(1);
        }
    }

    if (verbose || debug)
    {
        printf ("I will read the Parameter from %s\n", input_file);
        printf ("I will write the intermediate results to %s/result%ld\n", 
                output_dir,stamp);
        printf ("In case I detect an interrupt, I will write my data to %s\n", 
                interrupt_file);
        printf ("The Test case will be using %s, with %s byte messages\n",
                tests_names[test],msg_size); 

        if(OTPO_TEST_SKAMPI == test)
        {
            printf("I will use the operation of number %d with %s number of processes\n", 
                   op_num, num_proc);
        }
    }

    if(OTPO_TEST_SKAMPI == test)
    {
        create_skampi_ipfile();
    }

    /* read file to get number of parameters */
    if (0 == (num_parameters = otpo_get_num_parameters (input_file))) 
    {
        printf ("File contains no Data\n");
        exit (0);
    }
    if (debug) 
    {
        printf ("Read %d parameters\n",num_parameters);
    }

    /* structure that hold all the parameter info */
    list_params = (struct otpo_param_list_t *)
        malloc(sizeof(struct otpo_param_list_t) * num_parameters);
    if (NULL == list_params) 
    {
        fprintf (stderr,"Malloc Failed...\n");
        exit (1);
    }

    /* initialize list_params */
    if (SUCCESS != otpo_initialize_list (input_file))
    {
        exit (1);
    }

    /* fake MPI_init , does nothing*/
    MPI_Init (&argc, &argv);    
    ADCL_Init ();
    
    if (debug)
    {
        otpo_dump_list ();       
    }
    
    /* allocating the list of ADCL attributes */
    ADCL_param_attributes = (ADCL_Attribute *)malloc(sizeof(ADCL_Attribute) 
                                                     * num_parameters);
    if( NULL == ADCL_param_attributes ) 
    {
        fprintf (stderr,"Malloc Failed...\n");
        exit (1);
    }
    
    if (SUCCESS != otpo_populate_attributes (ADCL_param_attributes))
    {
        exit(1);
    }
    ADCL_Attrset_create (num_parameters, ADCL_param_attributes, &ADCL_param_attrset);

    /* total number of combinations */
    num_comb = get_num_combinations ();

    if (FAIL == (num_comb = otpo_populate_function_set (ADCL_param_attrset, num_comb, 
                                                        &ADCL_param_fnctset)))
    {
        exit(1);
    }

    if (debug) 
    {
        printf("Number of possible combinations: %d\n",num_comb);
    }

    ADCL_Topology_create_generic (0, 0, NULL, NULL, NULL, NULL, ADCL_DIRECTION_BOTH,
                                  MPI_COMM_WORLD, &ADCL_param_topo);

    ADCL_Request_create (ADCL_VECTOR_NULL, ADCL_param_topo, ADCL_param_fnctset, 
                         &ADCL_param_request);

    signal(SIGINT, handler);
    signal(SIGHUP, handler);
    signal(SIGTERM, handler);

    /* Start the Tests */
    num_tested=0;
    if (1 == resume) 
    {
        printf("Reading data to Resume...\n");
        if (SUCCESS != otpo_read_interrupt_data (interrupt_file, &num_tested, &results))
        {
            fprintf (stderr, "Can't Restore Data\n");
            exit (1);
        }
        if (debug)
        {
            printf("%d combinations left\n", num_comb-num_tested);
        }
        unfiltered = (double *)malloc(sizeof(double)*num_tested);
        outliers = (double *)malloc(sizeof(double)*num_tested);
        if (NULL == unfiltered || NULL == outliers) 
        {
            fprintf (stderr,"Malloc Failed...\n");
            exit (1);
        }
        for (k=0 ; k<num_tested ; k++) 
        {
            unfiltered[k] = results[k];
            outliers[k] = 0.0;
        }
        ADCL_Request_restore_status (ADCL_param_request, num_tested,
                                     results, unfiltered, outliers);
        if (NULL != results)
        {
            free (results);
        }
        if (NULL != unfiltered)
        {
            free (unfiltered);
        }
        if (NULL != outliers)
        {
            free (outliers);
        }
    }
    current = (float)num_tested;
    if (resume)
    {
        current--;
    }
    /* we execute till num_comb + 1, because ADCL requires to execute one more 
       to switch into the decision state. The last function executed is the 
       winner function 
    */
    for (i=num_tested ; (i<num_comb+1) && testing ; i++) 
    {
        if (status || verbose || debug) 
        {
            if (i >= current)
            {
                printf ("Completed: %d%\r",(int)( (i/(float)num_comb) * 100 ));
                fflush(stdout);
                current += num_comb/100.0; 
            }
        }
        if (0 == stop_signal)
        {
            ADCL_Request_start (ADCL_param_request);
            ADCL_Request_get_state(ADCL_param_request, &testing);
        }
        else if (1 == stop_signal && 1 < i)
        {
            printf ("Backing up Data...\n");
            ADCL_Request_save_status (ADCL_param_request, &num_tested,
                                      &results, &unfiltered, &outliers,
                                      &current_winner);

            if (SUCCESS != otpo_write_interrupt_data (num_tested, results, 
                                                      current_winner, interrupt_file))
            {
                fprintf(stderr,"Couldn't Backup Data, Quiting...\n");
                exit(1);
            }
            if (NULL != results)
            {
                free (results);
            }
            if (NULL != unfiltered)
            {
                free (unfiltered);
            }
            if (NULL != outliers)
            {
                free (outliers);
            }
            exit(1);
        }
        else if (1 == stop_signal)
        {
            exit(1);
        }
    }
    
    /* Output the results */
    if (SUCCESS != otpo_write_results (ADCL_param_request,
                                       &num_functions))
    {
        exit(1);
    }
    
    /* Output the results- seperate*/ 
    if (SUCCESS != otpo_analyze_results (num_functions))
    {
        exit(1);
    }
    
    ADCL_Request_free (&ADCL_param_request);
    ADCL_Topology_free (&ADCL_param_topo);
    ADCL_Fnctset_free (&ADCL_param_fnctset);
    ADCL_Attrset_free (&ADCL_param_attrset);
    for (i=0 ; i<num_parameters ; i++) 
    {
        ADCL_Attribute_free (&ADCL_param_attributes[i]);
    }
    ADCL_Finalize();
    MPI_Finalize();

    if (NULL != input_file) 
    {
        free (input_file);
    }
    if (NULL != output_dir) 
    {
        free (output_dir);
    }
    if (NULL != interrupt_file) 
    {
        free (interrupt_file);
    }
    otpo_free_list_params_objects();
    if (NULL != list_params) 
    {
        free (list_params);
    }
    if (NULL != msg_size) 
    {
        free (msg_size);
    }
    for (i=0 ; i<mca_args_len ; i++)
    {   
        if (NULL != mca_args[i])
            free (mca_args[i]);
    }
    if (NULL != mca_args)
    { 
        free (mca_args);
    }
    if (NULL != hostf) 
    {
        free (hostf);
    }
    if(OTPO_TEST_SKAMPI == test)
    {
        if (NULL != operation) 
        {
            free (operation);
        }
    }    

    if (NULL != num_proc) 
    {
        free (num_proc);
    }
    stopt();
    
    sec = 0;
    hr = 0;
    min = 0;
    sec = gettime();    
if (3600 <= sec)
    {
        hr = sec/3600;
        sec = sec%3600;
    }
    if (60 <= sec)
    {
        min = sec/60;
        sec = sec%60;
    }
    printf ("Time Elapsed: %d hrs %d min %d sec\n", hr, min, (int)sec);
    return 0;
}
Beispiel #4
0
int 
main (int argc, char *argv[])
{
  setprogname (argv[0]);
  if (argc != 2)
    usage ();
  str s = file2str (argv[1]);

  if (!s)
    fatal << "cannot open file: " << argv[1];

  u_int niter = 10;
  u_int osz = 0;
  u_int32_t tot = 0;
  mstr *outbuf = NULL;

  u_int slen = s.len ();
  u_int out_avail = u_int ((slen / 1000) * 1001) + 16;

  for (u_int i = 0; i < niter; i++) {

    if (outbuf)
      delete outbuf;
    outbuf = New mstr (out_avail);

    warn << "+ starting compression\n";
    startt ();
    osz = go (s, outbuf, out_avail); 
    u_int t = stopt ();
    warn << "- ending compression (time=" << t << ")\n";
    tot += t;
    
  }

  outbuf->setlen (osz);

  //
  // write out the buffer once, just to make sure we were getting reasonable
  // data output (and not some bullshit)
  //
  u_int i = 0;
  do {
    int rc = write (1, outbuf->cstr () + i, min<u_int> (2048, osz - i));
    if (rc < 0)
      panic ("write error!\n");
    i += rc;
  } while (i < osz);

  u_int64_t bw = osz / 1024;
  bw *= 1000000;
  bw /= tot;
  bw *= niter;


  warn ("Input: %d bytes\n"
	"Output: %d bytes\n"
	"Iterations: %d\n"
	"Usecs Total: %d\n"
	"Compression ratio * 1000: %d\n"
	"Throughput (kB/sec): %d\n",
	slen, osz, niter, tot, osz * 1000 / slen, u_int32_t (bw));

}