Esempio n. 1
0
//Refer to apps_sfdl_gen/insertion_sort_q_cons.h for constants to use in this exogenous
//check.
bool insertion_sort_qProverExo::exogenous_check(const mpz_t* input, const mpq_t* input_q,
    int num_inputs, const mpz_t* output, const mpq_t* output_q, int num_outputs, mpz_t prime) {
  bool lists_equal = true;

#ifdef ENABLE_EXOGENOUS_CHECKING
  mpq_t *output_q_recomputed;
  alloc_init_vec(&output_q_recomputed, num_inputs);

  // call baseline to compute output
  baseline(input_q, num_inputs, output_q_recomputed, num_outputs);

  mpz_t *output_recomputed;
  alloc_init_vec(&output_recomputed, num_outputs);

  convert_to_z(num_outputs, output_recomputed, output_q_recomputed, prime);

  for(int j = 0; j < num_outputs; j++) {
    if (mpz_cmp(output[j], output_recomputed[j]) == 0)
      continue;
    else
      lists_equal = false;
  }
  clear_vec(num_outputs, output_recomputed);
  clear_vec(num_outputs, output_q_recomputed);

#else
  gmp_printf("Exogeneous checking disabled\n");
  lists_equal = true;
#endif
  return lists_equal;
};
Esempio n. 2
0
// cost of field addition
// cost of generating a random number
void measure_plaintext_ops() {
    int size_input = 1000000;

    mpz_t *vec1, *vec2, *vec3;

    alloc_init_vec(&vec1, size_input);
    alloc_init_vec(&vec2, size_input);
    alloc_init_vec(&vec3, size_input);
    // cost of a field multiplication followed by a field addition
    measure_field_mult(size_input, vec1, vec2, vec3, 128, prime_128);
    measure_field_mult(size_input, vec1, vec2, vec3, 192, prime_192);
    measure_field_mult(size_input, vec1, vec2, vec3, 220, prime_220);

    // cost of a regular multiplication followed by an addition
    measure_mult(size_input, vec1, vec2, vec3, 32, 32);
    measure_mult(size_input, vec1, vec2, vec3, 128, 32);
    measure_mult(size_input, vec1, vec2, vec3, 192, 32);
    measure_mult(size_input, vec1, vec2, vec3, 220, 32);
    measure_mult(size_input, vec1, vec2, vec3, 128, 128);
    measure_mult(size_input, vec1, vec2, vec3, 192, 192);
    measure_mult(size_input, vec1, vec2, vec3, 220, 220);

    measure_div(size_input, vec1, vec2, vec3, 128, 128, prime_128);
    measure_div(size_input, vec1, vec2, vec3, 220, 220, prime_220);

    // cost of generating pseudorandom numbers
    measure_rand(size_input, vec1, 128, prime_128);
    measure_rand(size_input, vec1, 192, prime_192);
    measure_rand(size_input, vec1, 220, prime_220);

    // cleanup
    clear_vec(size_input, vec1);
    clear_vec(size_input, vec2);
    clear_vec(size_input, vec3);
}
Esempio n. 3
0
Verifier::~Verifier(void) {
#if NONINTERACTIVE == 0
  clear_vec(batch_size * num_repetitions, c_values);
  clear_vec(num_repetitions * num_lin_pcp_queries, f_con_coins);
#endif
  clear_scalar(a);
  clear_scalar(f_s);

  mpz_clear(prime);

  delete v;
  delete curl;
}
Esempio n. 4
0
//Refer to apps_sfdl_gen/bisect_sfdl_cons.h for constants to use in this exogenous
//check.
bool bisect_sfdlProverExo::exogenous_check(const mpz_t* input, const mpq_t* input_q,
    int input_size, const mpz_t* output, const mpq_t* output_q, int output_size, mpz_t prime) {

  bool success = true;
#ifdef ENABLE_EXOGENOUS_CHECKING
  int m = bisect_sfdl_cons::m;

  mpq_t* buffer;
  alloc_init_vec(&buffer, m + m);

  baseline(input_q, input_size, buffer, output_size);

  mpq_t* a = buffer;
  mpq_t* b = buffer + m;

  for(int i = 0; i < m; i++) {
    success &= mpq_equal(a[i], output_q[i]);
    success &= mpq_equal(b[i], output_q[i+m]);
  }

  clear_vec(m+m, buffer);

#else
  gmp_printf("Exogeneous checking disabled\n");
#endif
  return success;
};
Esempio n. 5
0
/* void vit_dec_reset(void)
 *  Resets the decoder for new message
 *  -another part that is hardcoded so needs to be changed for more states
 *  -sets up decoder with assumption that initial state is 0,0
 */
void vit_dec_reset() {
	isOddRec = FALSE;
//	int i;
//	for(i = 0; i < NUM_STATES; i++) {
//		pm[i] = NUM_STATES+1;
//		clear_vec(paths[i]);
//	}
	pm[0] = 0;
	pm[1] = NUM_STATES+1;
	pm[2] = NUM_STATES+1;
	pm[3] = NUM_STATES+1;
	clear_vec(paths[0]);
	clear_vec(paths[1]);
	clear_vec(paths[2]);
	clear_vec(paths[3]);
}
Esempio n. 6
0
//Testing Function
void vit_dec(bv_t dest, bv_t src) {
	//printf("%d\n", Trellis[0][2]);

  clear_vec(dest);

  short i;
  short num_bits = src->num_bits;

  vit_dec_reset();

  // for each bit in src, find the ML set of paths ending at each state
  i = num_bits-1;
  while(i >= 0) {
	  if(puncturedRec && isOddRec) {
		  //printf("m = %d\n", get_bit(src,i));
		  vit_dec_bmh(get_bit(src,i));
		  i--;
	  }
	  else {
		  //printf("m = %d\n", get(src,i-1,i));
		  vit_dec_bmh(get(src,i-1,i));
		  i -= 2;
	  }
	  //vit_dec_ACS();
  }

  //choose ML path based on node with smallest accumulated pm
  vit_dec_get(dest);

}
Esempio n. 7
0
bool kmapdset_iterator_impl_base::find_pos(const void* k1, const void* k2, bool bulk, const char* func)
{
	PortableDataOutput<AutoGrownMemIO> oKey1, oKey2;
	m_owner->save_key1(oKey1, k1);
	m_owner->save_key2(oKey2, k2);
	DBT tk1; memset(&tk1, 0, sizeof(DBT)); tk1.data = oKey1.begin(); tk1.size = oKey1.tell();
	DBT tk2; memset(&tk2, 0, sizeof(DBT)); tk2.data = oKey2.begin(); tk2.size = oKey2.tell();
	m_ret = m_curp->get(m_curp, &tk1, &tk2, DB_GET_BOTH);
	if (0 == m_ret)
	{
		if (bulk) {
			m_ret = m_curp->get(m_curp, &tk1, &m_bulk, DB_CURRENT|DB_MULTIPLE);
			if (0 == m_ret) {
				bulk_load(&tk1);
				return true;
			}
		} else {
			clear_vec();
			load_key1(tk1.data, tk1.size);
			push_back(tk2.data, tk2.size);
			return true;
		}
	}
	else if (DB_NOTFOUND == m_ret)
	{
		return false;
	}
	string_appender<> oss;
	oss << db_strerror(m_ret)
		<< "... at: " << func
		<< "\n"
		;
	throw std::runtime_error(oss.str());
}
Esempio n. 8
0
File: main.cpp Progetto: Ryzh/voc
void merge_vec_to_file(const QVector<word_t*>& vec, const QString& filename)
{
	QVector<word_t*> target_vec;
	load_file_to_vec(target_vec, filename);
	merge_vec_to_vec(vec, target_vec);
	save_vec_to_file(target_vec, filename);

	// memory cleanup
	clear_vec(target_vec);
}
Esempio n. 9
0
//Refer to apps_sfdl_gen/fannkuch_cons.h for constants to use in this exogenous
//check.
bool fannkuchProverExo::exogenous_check(const mpz_t* input, const mpq_t* input_q,
                                        int input_size, const mpz_t* output, const mpq_t* output_q, int output_size, mpz_t prime) {
  bool success = true;
#ifdef ENABLE_EXOGENOUS_CHECKING
  mpq_t *output_recomputed;
  alloc_init_vec(&output_recomputed, 1);

  baseline(input_q, input_size, output_recomputed, output_size);
  success = mpq_class(output_recomputed[0]) == mpq_class(output_q[0]);
  clear_vec(1, output_recomputed);
#else
  gmp_printf("Exogeneous checking disabled");
#endif
  return success;
};
Esempio n. 10
0
//Refer to apps_sfdl_gen/dna_align_cons.h for constants to use in this exogenous
//check.
bool dna_alignProverExo::exogenous_check(const mpz_t* input, const mpq_t* input_q,
    int num_inputs, const mpz_t* output, const mpq_t* output_q, int num_outputs, mpz_t prime) {

#ifdef ENABLE_EXOGENOUS_CHECKING
  mpq_t *output_recomputed;
  alloc_init_vec(&output_recomputed, num_outputs);
  for (int i=0; i<num_outputs; i++)
    mpq_set(output_recomputed[i], output_q[i]);

  baseline(input_q, num_inputs, output_recomputed, num_outputs);
  bool match = mpz_get_ui(mpq_numref(output_recomputed[0]));

  clear_vec(num_outputs, output_recomputed);
  return match;
#else
  cout<<"Exogeneous checking disabled"<<endl;
  return true;
#endif
};
//Refer to apps_sfdl_gen/mr_bstore_dotp_map_cons.h for constants to use when generating input.
void mr_bstore_dotp_mapVerifierInpGenHw::create_input(mpq_t* input_q, int num_inputs)
{
  mpz_t *exo_input;
  alloc_init_vec(&exo_input, 2*SIZE_INPUT);

  v->get_random_vec_priv(2*SIZE_INPUT, exo_input, 32);
  MapperIn mapper_in;
  for (int i=0; i<SIZE_INPUT; i++) {
    mapper_in.vec_a[i] = mpz_get_ui(exo_input[i]);
    mapper_in.vec_b[i] = mpz_get_ui(exo_input[SIZE_INPUT+i]);
  }

  hash_t digest;
  export_exo_inputs(&mapper_in, sizeof(MapperIn), &digest);

  for (int i=0; i<num_inputs; i++) {
    mpz_set_ui(mpq_numref(input_q[i]), digest.bit[i]);
  }
  clear_vec(2*SIZE_INPUT, exo_input);
}
Esempio n. 12
0
//Refer to apps_sfdl_gen/tolling_cons.h for constants to use in this exogenous
//check.
bool tollingProverExo::exogenous_check(const mpz_t* input, const mpq_t* input_q,
                                       int num_inputs, const mpz_t* output, const mpq_t* output_q, int num_outputs, mpz_t prime) {

    bool passed_test = true;
#ifdef ENABLE_EXOGENOUS_CHECKING
    mpq_t *output_recomputed;
    alloc_init_vec(&output_recomputed, num_outputs);
    baseline(input_q, num_inputs, output_recomputed, num_outputs);

    for(int i = 0; i < num_outputs; i++) {
        if (mpq_equal(output_recomputed[i], output_q[i]) == 0) {
            passed_test = false;
            break;
        }
    }
    clear_vec(num_outputs, output_recomputed);
#else
    gmp_printf("<Exogenous check disabled>\n");
#endif
    return passed_test;
};
Esempio n. 13
0
ZComputationVerifier::~ZComputationVerifier() {
    clear_scalar(A_tau);
    clear_scalar(B_tau);
    clear_scalar(C_tau);
    clear_vec(size_input+size_output, input);
    clear_vec(size_input, input_q);
    clear_vec(size_f2_vec, set_v);

    clear_vec(num_repetitions * num_lin_pcp_queries, f_answers);
    clear_vec(expansion_factor, temp_arr);
    clear_vec(expansion_factor, temp_arr2);

    clear_scalar(temp);
    clear_scalar(temp2);
    clear_scalar(temp3);
    clear_scalar(lhs);
    clear_scalar(rhs);
    clear_vec(NUM_REPS_PCP, d_star);
    clear_scalar(omega);
}
Esempio n. 14
0
void kmapdset_iterator_impl_base::bulk_load(DBT* tk1)
{
	NARK_RT_assert(0 == m_ret, std::logic_error);
	load_key1(tk1->data, tk1->size);
	clear_vec();
	int ret;
	do {
		void  *bptr, *data;
		DB_MULTIPLE_INIT(bptr, &m_bulk);
		assert(NULL != bptr);
		for (;;)
		{
			size_t size = 0;
			DB_MULTIPLE_NEXT(bptr, &m_bulk, data, size);
			if (nark_likely(NULL != bptr))
				this->push_back(data, size);
			else
				break;
		}
		ret = m_curp->get(m_curp, tk1, &m_bulk, DB_MULTIPLE|DB_NEXT_DUP);
	} while (0 == ret);
}
Esempio n. 15
0
void ZComputationVerifier::create_plain_queries() {
    clear_vec(size_f1_vec*expansion_factor, f1_commitment);
    clear_vec(size_f2_vec*expansion_factor, f2_commitment);

    m_plainq.begin_with_init();
    // keeps track of #filled coins
    int f_con_filled = -1;
    int query_id;

    for (int rho=0; rho<num_repetitions; rho++) {
        if (rho == 0) m_plainq.begin_with_init();
        else m_plainq.begin_with_history();

        // create linearity test queries
        query_id = 1;
        for (int i=0; i<NUM_REPS_LIN; i++) {
            v->create_lin_test_queries(size_f1_vec, f1_q1, f1_q2, f1_q3, f1_consistency,
                                       f_con_filled, f_con_coins, prime);

            f_con_filled += 3;

            v->create_lin_test_queries(size_f2_vec, f2_q1, f2_q2, f2_q3, f2_consistency,
                                       f_con_filled, f_con_coins, prime);

            f_con_filled += 3;

            //TODO: can be folded into a function
            /*
            snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
            dump_vector(size_f1_vec, f1_q1, scratch_str);
            send_file(scratch_str);


            snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
            dump_vector(size_f1_vec, f1_q2, scratch_str);
            send_file(scratch_str);

            // don't dump, but increment query_id
            query_id++;
            //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
            //dump_vector(size_f1_vec, f1_q3, scratch_str);
            //send_file(scratch_str);

            snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
            dump_vector(size_f2_vec, f2_q1, scratch_str);
            send_file(scratch_str);

            snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
            dump_vector(size_f2_vec, f2_q2, scratch_str);
            send_file(scratch_str);

            query_id++;
            //snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
            //dump_vector(size_f2_vec, f2_q3, scratch_str);
            //send_file(scratch_str);
            */

            // use one of the linearity queries as self correction queries
            if (i == 0) {
                for (int i=0; i<size_f1_vec; i++)
                    mpz_set(f1_q4[i], f1_q1[i]);

                for (int i=0; i<size_f2_vec; i++)
                    mpz_set(f2_q4[i], f2_q1[i]);
            }
        }

        for (int i=0; i<n+1; i++) {
            mpz_set_ui(eval_poly_A[i], 0);
            mpz_set_ui(eval_poly_B[i], 0);
            mpz_set_ui(eval_poly_C[i], 0);
        }

        // create zquad correction queries: create q9, q10, q11, and q12
        v->create_div_corr_test_queries(n, size_f1_vec, size_f2_vec, f1_q1, f1_q2, f1_q3, f2_q1, f_con_coins, f_con_filled, f1_consistency, f_con_coins, f_con_filled+3, f2_consistency, f1_q4, f2_q4, d_star[rho], num_aij, num_bij, num_cij, set_v, poly_A, poly_B, poly_C, eval_poly_A, eval_poly_B, eval_poly_C, prime);

        f_con_filled += 4;

        int base = rho * (1 + size_input + size_output);
        mpz_set(A_tau_io[base+0], eval_poly_A[0]);
        mpz_set(B_tau_io[base+0], eval_poly_B[0]);
        mpz_set(C_tau_io[base+0], eval_poly_C[0]);

        for (int i=0; i<size_input+size_output; i++) {
            mpz_set(A_tau_io[base+1+i], eval_poly_A[1+n_prime+i]);
            mpz_set(B_tau_io[base+1+i], eval_poly_B[1+n_prime+i]);
            mpz_set(C_tau_io[base+1+i], eval_poly_C[1+n_prime+i]);
        }

        /*
        snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
        dump_vector(size_f1_vec, f1_q1, scratch_str);
        send_file(scratch_str);

        snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
        dump_vector(size_f1_vec, f1_q2, scratch_str);
        send_file(scratch_str);

        snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
        dump_vector(size_f1_vec, f1_q3, scratch_str);
        send_file(scratch_str);

        snprintf(scratch_str, BUFLEN-1, "q%d_qquery_r_%d", query_id++, rho);
        dump_vector(size_f2_vec, f2_q1, scratch_str);
        send_file(scratch_str);
        */
    }

    dump_vector(size_f1_vec, f1_consistency, (char *)"f1_consistency_query");
    send_file((char *)"f1_consistency_query");

    dump_vector(size_f2_vec, f2_consistency, (char *)"f2_consistency_query");
    send_file((char *)"f2_consistency_query");
    m_plainq.end();

    // cleanup time
    clear_vec(n+1, eval_poly_A);
    clear_vec(n+1, eval_poly_B);
    clear_vec(n+1, eval_poly_C);
    clear_vec(size_f1_vec, f1_consistency);
    clear_vec(size_f2_vec, f2_consistency);

    for (int i=0; i<num_aij; i++)
        clear_scalar(poly_A[i].coefficient);

    for (int i=0; i<num_bij; i++)
        clear_scalar(poly_B[i].coefficient);

    for (int i=0; i<num_cij; i++)
        clear_scalar(poly_C[i].coefficient);

    free(poly_A);
    free(poly_B);
    free(poly_C);

    clear_vec(size_f1_vec, f1_q1);
    clear_vec(size_f1_vec, f1_q2);
    clear_vec(size_f1_vec, f1_q3);
    clear_vec(size_f1_vec, f1_q4);
    clear_vec(size_f2_vec, f2_q1);
    clear_vec(size_f2_vec, f2_q2);
    clear_vec(size_f2_vec, f2_q3);
    clear_vec(size_f2_vec, f2_q4);

    // Ginger's codebase did some run test part of work in plain query
    // creation; so the base class calls with history;
    m_runtests.reset();
}
Esempio n. 16
0
/** void setupDecoder(void)
/  Uses the current Convolutional Encoder to generate
/  the appropriate tables for an efficient Viterbi decoder
/  Should be called in main() before interrupt initialized
*/
void setupDecoder() {

	setPuncturing(FALSE);

	int i;
	int j;
	bv_t a = malloc (sizeof(struct bitvec));
	bv_new(a, 1);
	bv_t b = malloc (sizeof(struct bitvec));
	bv_new(b, 1);

	//*** this finds the properties of each state
	//generate the trellis (messages produced by state transitions)
	//generate decoding given two states
	for(i = 0; i < NUM_STATES; i++) {
		  for(j = 0; j < NUM_STATES; j++) {
			Trellis[i][j] = -1;
			Decode[i][j] = -1;
			if(j < 2)
				InverseTransitions[i][j] = -1;
		  }
	}
	// Trellis[0][0] = Trellis[1][2] = 0;
	// Trellis[1][0] = Trellis[0][2] = 3;
	// Trellis[2][1] = Trellis[3][3] = 1;
	// Trellis[3][1] = Trellis[2][3] = 2;

	for(i = 0; i < NUM_STATES; i++) {
		clear_vec(a);
		clear_vec(b);

		//get message and next state for input 0
		setState(i);
		encode(a,0);
		Transitions[i][0] = getState();
		if(InverseTransitions[getState()][0] == -1)
			InverseTransitions[getState()][0] = i;
		else
			InverseTransitions[getState()][1] = i;
		Trellis[i][getState()] = get(a,0,1);
		Decode[i][getState()] = 0;

		//get message and next state for input 1
		setState(i);
		encode(b,1);
		Transitions[i][1] = getState();
		if(InverseTransitions[getState()][0] == -1)
			InverseTransitions[getState()][0] = i;
		else
			InverseTransitions[getState()][1] = i;
		Trellis[i][getState()] = get(b,0,1);
		Decode[i][getState()] = 1;

		//initialize the decoded survivor paths
		paths[i] = malloc(sizeof(struct bitvec));
		bv_new(paths[i], 32);
		paths_next[i] = malloc (sizeof(struct bitvec));
		bv_new(paths_next[i], 32);

	}

	// for(i = 0; i < NUM_CODES; i++) {
	// 	  for(j = 0; j < 2; j++) {
	// 		printf("%d: %d -> %d \n", Decode[i][Transitions[i][j]], i, Transitions[i][j]);
	// 	  }
	// }
	// for(i = 0; i < NUM_CODES; i++) {
	// 	  for(j = 0; j < 2; j++) {
	// 		  printf("%d: %d -> %d \n", Decode[InverseTransitions[i][j]][i], InverseTransitions[i][j], i);
	// 	  }
	// }
	for(i = 0; i < NUM_CODES; i++) {
		for(j = 0; j < NUM_CODES; j++) {
		  printf("%d ", Trellis[i][j]);
		}

		printf("\n");
	}

	printf("Hamming distance \n");
	//pre-generate hamming distances for all messages
	for(i = 0; i < NUM_CODES; i++) {
		  load(a,i);
		  for(j = 0; j < NUM_CODES; j++) {
		    load(b,j);
		    HammingDistance[i][j] = hammingDistance(a,b);
		    printf("%d ", HammingDistance[i][j]);
		  }
		  printf("\n");
	}
	
	//reset the encoder and decoder
	clearState();
	vit_dec_reset();

	bv_free(a);
	bv_free(b);
	free(a);
	free(b);

	//set puncturing (only accomodates 2/3 puncture)
	setPuncturing(puncturedRec);
}